Commit 50f80b87 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

List of farms removed from the Simulator (farms are accessed from farmers)

parent 653aa13a
......@@ -3,7 +3,6 @@ package fr.inrae.agriterix.simulator;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
......@@ -11,7 +10,6 @@ import co.nstant.in.cbor.CborBuilder;
import co.nstant.in.cbor.CborEncoder;
import co.nstant.in.cbor.CborException;
import co.nstant.in.cbor.builder.ArrayBuilder;
import co.nstant.in.cbor.builder.MapBuilder;
import com.thoughtworks.xstream.XStream;
import fr.inrae.agriterix.simulator.customConverters.GeoAreaConverter;
......@@ -24,11 +22,10 @@ public class Simulator {
private final List<GeoArea> geoAreas;
private final Flow global;
private final List<Farm> farms;
private final List<Farmer> farmers;
private final List<Dynamics> dynamicsList;
private final String timestamp;
private Parameters parameters;
private final Parameters parameters;
private transient SimulationContext context;
private transient MutableInt timestep;
private transient XStream xstream;
......@@ -36,11 +33,7 @@ public class Simulator {
public Simulator(Parameters parameters, List<Farmer> farmers) {
this.parameters = parameters;
this.geoAreas = new ArrayList<>();
this.farms = new ArrayList<>();
for (Farmer farmer : farmers) {
if (!farms.contains(farmer.getFarm())) {
farms.add(farmer.getFarm());
}
for (Patch patch : farmer.getFarm().getPatches()) {
if (!this.geoAreas.contains(patch.getGeoArea())) {
this.geoAreas.add(patch.getGeoArea());
......@@ -59,7 +52,6 @@ public class Simulator {
public Simulator(Parameters parameters, List<Farm> farms, List<Farmer> farmers) {
this.parameters = parameters;
this.farms = farms;
this.geoAreas = new ArrayList<>();
// FIXME duplicate farm/farmers in constructor
for (Farm farm : farms) {
......@@ -165,13 +157,12 @@ public class Simulator {
this.timestep = new MutableInt(0);
this.context = new SimulationContext(timestep, parameters.getRngSeedIndex());
this.xstream = createXstream();
for (Farm farm : farms) {
for (Patch patch : farm.getPatches()) {
for (Farmer farmer : farmers) {
for (Patch patch : farmer.getFarm().getPatches()) {
patch.getGeoArea().getPatches().add(patch);
patch.setFarmSimple(farm);
patch.setFarmSimple(farmer.getFarm());
}
}
for (Dynamics dynamics : dynamicsList) {
dynamics.setTimeStamp(timestamp);
dynamics.initLogger();
......
......@@ -9,6 +9,7 @@ import org.junit.*;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -42,9 +43,9 @@ public class GeoAreaTest {
farm.addPatch(new Patch(g, 10.4f, CulturalPractice.I, new Product("Blé", Unit.Kg)));
farm.addPatch(new Patch(g, 9.5f, CulturalPractice.O, new Product("Lentille", Unit.Kg)));
farm.addPatch(new Patch(g, 25.3f, CulturalPractice.S, new Product("Chou", Unit.Kg)));
Farmer farmer = new Farmer(30, farm);
Simulator simulator = new Simulator(new Parameters(0, new ArrayList<>()), farms, null);
Simulator simulator = new Simulator(new Parameters(0, new ArrayList<>()), farms, Arrays.asList(farmer));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
simulator.serializeXML(stream);
Simulator simulator2 = Simulator.loadSimulator(new ByteArrayInputStream(stream.toByteArray()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment