Commit 2cc28d85 authored by Loris Croce's avatar Loris Croce
Browse files

farmer id generator

parent 2a97bd7f
Pipeline #37885 passed with stages
in 4 minutes and 10 seconds
......@@ -53,7 +53,7 @@ public class Generator {
for (int i = 0; i < population.length; i++) {
for (int j = 0; j < population[i]; j++) {
Farm farm = new Farm(area);
farmers.add(new Farmer(i+18, farm));
farmers.add(new Farmer(i+18, farm, i));
}
}
return farmers;
......
......@@ -6,12 +6,6 @@ public class Farmer {
private Farm farm;
private int id;
public Farmer(int age, Farm farm) {
this.age = age;
this.farm = farm;
//TODO FIXME ID generator
this.id = 42;
}
public Farmer(int age, Farm farm, int id) {
this.age = age;
this.farm = farm;
......
......@@ -11,6 +11,7 @@ public class SimulationContext {
private MutableInt timestep;
private final MRG32k3a randomStream;
private int farmerCount;
public SimulationContext(MutableInt timestep, int rngSeedIndex) {
this.timestep = timestep;
......@@ -19,6 +20,12 @@ public class SimulationContext {
for (int i = 0; i < rngSeedIndex; i++) {
randomStream.resetNextSubstream();
}
farmerCount = 0;
}
public int setIdFarmer() {
farmerCount++;
return farmerCount;
}
public int getTimestep() {
......
......@@ -150,11 +150,11 @@ public class PopulationDynamics extends Dynamics {
}
public Farmer singleNewIdentical(SimulationContext context, Farm farm) {
return new Farmer(context.nextInt(MIN_AGE_TAKEOVER, MAX_AGE_TAKEOVER), farm);
return new Farmer(context.nextInt(MIN_AGE_TAKEOVER, MAX_AGE_TAKEOVER), farm, context.setIdFarmer());
}
public Farmer singleNewDifferent(SimulationContext context, Farm farm) {
Farmer newcomer = new Farmer(context.nextInt(MIN_AGE_TAKEOVER, MAX_AGE_TAKEOVER), farm);
Farmer newcomer = new Farmer(context.nextInt(MIN_AGE_TAKEOVER, MAX_AGE_TAKEOVER), farm, context.setIdFarmer());
List<Patch> patchesChanged = new ArrayList<>();
List<Patch> patchesToRemove = new ArrayList<>();
for (Patch patch : newcomer.getFarm().getPatches()) {
......
......@@ -47,7 +47,7 @@ public class FarmerTest {
for (Patch patch : patches) {
patch.setFarm(farm);
}
Farmer farmer = new Farmer(54, farm);
Farmer farmer = new Farmer(54, farm, 1);
XStream xstream = new XStream();
XStream.setupDefaultSecurity(xstream);
......
......@@ -136,10 +136,10 @@ public class SimulatorMinimalTest {
animalsf4.add(vache, 10.f);
Livestock livestock4 = new Livestock(requiredf4, producedf4, animalsf4);
farm4.setLivestock(livestock4);
Farmer farmer1 = new Farmer(40, farm1);
Farmer farmer2 = new Farmer(50, farm2);
Farmer farmer3 = new Farmer(60, farm3);
Farmer farmer4 = new Farmer(30, farm4);
Farmer farmer1 = new Farmer(40, farm1, 1);
Farmer farmer2 = new Farmer(50, farm2, 2);
Farmer farmer3 = new Farmer(60, farm3, 3);
Farmer farmer4 = new Farmer(30, farm4, 4);
farms.addAll(Arrays.asList(farm1, farm2, farm3, farm4));
farmers.addAll(Arrays.asList(farmer1, farmer2, farmer3, farmer4));
// Dynamics
......
......@@ -82,6 +82,8 @@ public class SimulatorTest {
List<Product> animals = Arrays.asList(new Product("Boeuf", Unit.A), new Product("Mouton", Unit.A),
new Product("Poulet", Unit.A), pouletTag, boeufTag, moutonTag);
int farmerCount = 0;
for (int i = 0; i < GEOAREA_MAX; i++) {
List<Patch> patches = new ArrayList<>();
List<Flow> flows = generateFlows(products, transformed, randomInt(1, FLOW_MAX), s);
......@@ -109,7 +111,7 @@ public class SimulatorTest {
Livestock livestock = new Livestock(required, produced, animalsChosen);
farm.setLivestock(livestock);
farms.add(farm);
Farmer farmer = new Farmer(randomInt(18, 70), farm);
Farmer farmer = new Farmer(randomInt(18, 70), farm, farmerCount++);
farmers.add(farmer);
}
}
......@@ -258,7 +260,7 @@ public class SimulatorTest {
}
//@After
@After
public void cleanup() throws IOException {
Path current = FileSystems.getDefault().getPath("data/out");
Files.walk(current)
......
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