Open etatara opened 5 months ago
For responding to the Repast interest mailing list: Can read in a CSV like so (from here):
List<String[]> rows = new CSVReader(
new InputStreamReader(new FileInputStream(fileName)))
.readAll()
Replace the Humans agent creation in the Java Zombies model with this.
For the actual example we put in a new demo model, we'd want more attributes.
String fileName = "data/initial_humans.csv";
List<String[]> rows = null;
try {
Reader reader = new InputStreamReader(new FileInputStream(fileName));
CSVReader csvReader = new CSVReader(reader, CSVParser.DEFAULT_SEPARATOR,
CSVParser.DEFAULT_QUOTE_CHARACTER, 1);
rows = csvReader.readAll();
} catch (IOException e) {
e.printStackTrace();
}
for (String[] row : rows) {
int id = Integer.parseInt(row[0]);
int energy = Integer.parseInt(row[1]);
Human h = new Human(space, grid, energy);
context.add(h);
}
Using OpenCSV (https://javadoc.io/doc/au.com.bytecode/opencsv/latest/index.html) update one of the existing demo models to show how to load agents from a CSV file. Predator-Prey might be a good candidate. Should also provide a brief section in the Reference guide.