Commit 9ee26c62 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

bugfix in farm reassignation and cleanup

parent ba1854d9
Pipeline #38323 passed with stages
in 3 minutes and 56 seconds
......@@ -19,9 +19,9 @@ public class TransmissionTendancy implements TransmissionStrategy {
// Is the transmission realized with only one successor?
// TODO better with a distribution on number of successors
private double singleSuccessorProba;
private int maxSuccessors;
// Is the transmission realized with an existant farmer (instead of a new)
private double existantSuccessorProba;
private int maxSuccessors;
private Map<String, Map<String, Double>> transitionMatrix;
public TransmissionTendancy() {
......@@ -36,8 +36,6 @@ public class TransmissionTendancy implements TransmissionStrategy {
@Override
public void process(SimulationContext context, List<GeoArea> geoAreas, List<Farmer> farmers, List<Integer> installationsAges, int[] retirements) {
// retrieving farmers that will retire
List<Farmer> retiredFarmers = new ArrayList<>(); // TODO useless?
for (int i = 0; i < retirements.length; i++) {
int nbRetired = retirements[i];
final int age = i;
......@@ -45,15 +43,12 @@ public class TransmissionTendancy implements TransmissionStrategy {
for (int j = 0; j < nbRetired; j++) {
final Farmer retiredFarmer = context.nextObject(ageIFarmers, true);
farmers.remove(retiredFarmer);
retiredFarmers.add(retiredFarmer);
if (context.nextDouble() <= singleSuccessorProba) {
// single successor
processSuccessor(installationsAges, context, farmers, retiredFarmer);
} else { // multiple successors
List<Farmer> successors = new ArrayList<>();
for (int k = 0; k < context.nextInt(2, maxSuccessors); k++) {
//successors.add(context.nextObject(farmers));
Farmer existingFarmer = context.nextObject(successors, false);
existingFarmer = context.nextObject(successors, false);
processSuccessor(installationsAges, context, farmers, retiredFarmer); // new farmer
}
}
......@@ -62,21 +57,20 @@ public class TransmissionTendancy implements TransmissionStrategy {
}
private void processSuccessor(List<Integer> installationsAges, SimulationContext context, List<Farmer> farmers, final Farmer retiredFarmer) {
// single successor
if (installationsAges.isEmpty() || context.nextDouble() <= existantSuccessorProba) {
// existant farmer
Farmer successor = context.nextObject(farmers, false);
patchTransition(retiredFarmer, successor, context);
patchTransition(retiredFarmer, successor, true, context);
} else {
// new farmer
Farmer newFarmer = new Farmer(context.nextObject(installationsAges, true), retiredFarmer.getFarm(), context.setIdFarmer());
patchTransition(retiredFarmer, newFarmer, context);
patchTransition(retiredFarmer, newFarmer, false, context);
}
}
private void patchTransition(final Farmer retiredFarmer, Farmer successor, SimulationContext context) {
private void patchTransition(final Farmer retiredFarmer, Farmer successor, boolean isExistantFarmer, SimulationContext context) {
for (Patch patch : retiredFarmer.getFarm().getPatches()) {
if (retiredFarmer.getFarm() != successor.getFarm()) {
if (isExistantFarmer) {
patch.setFarm(successor.getFarm());
}
String product = context.nextMapObjectWithDistributionInKeysBis(
......
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