'Initializing an array agent attribute from a database
I'm generating agents where two attributes (Modules and Passed_Modules) are arrays. I would like to draw their values from a database reference in the same way as I'm able to do for the scalar attributes. There is no such option, however. How can I initialise these array attributes by drawing from a database?
Here is the option associated with one of the scalar attributes (i.e. HistoricYear):
Scalar attribute has the option to initialise from a database
However, there is no such option for the array attributes (e.g. Modules):
Array attribute does not have this option
Any advice?
Solution 1:[1]
The best option would be to have a function that uses the database values and then returns an array for you to use.
and then the getModules function you have some code that goes through the DB for you and return an array:
int[] result = new int[10];
List<Tuple> rows = selectFrom(module_table).list();
int i = 0;
for (Tuple row : rows) {
result[i](row.get( module_table.modules ));
i ++;
}
return result;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jaco-Ben Vosloo |

