Commit 4718ef61 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

Remove Duo

parent 5ff97121
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import environment.Basin;
import environment.BasinNetwork;
......@@ -115,8 +116,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
//List<DiadromousFish> newFish = new ArrayList<DiadromousFish>();
// creation of the death basin (for the lost strayers)
//TODO move as a transient field
Basin deathBasin = new Basin(-1, "deathBasin", 0, 0, 0, 0);
//Basin deathBasin = new Basin(-1, "deathBasin", 0, 0, 0, 0);
//List<Duo<DiadromousFish, Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish, Basin>>();
for (SeaBasin departure : group.getEnvironment().getSeaBasins()) {
......@@ -156,11 +156,12 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
accBasOfFish.add(duo);
}
// We fill the weight table
double totalWeight = 0.;
double probToGo = 0.;
long amountToGo = 0;
// TODO manage the case when AccBasOfFish is empty
/*// TODO manage the case when AccBasOfFish is empty
for (Duo<Basin, Double> accBasin : accBasOfFish) {
// total weight for the basin
Basin b = accBasin.getFirst();
......@@ -177,28 +178,40 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
}
accBasin.setSecond(accBasinWeight);
totalWeight += accBasinWeight;
}*/
Map<RiverBasin, Double> basinWeightsFromDeparture = new TreeMap<RiverBasin, Double>();
for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) {
double accBasinWeight = 1. / (1. + Math.exp(-(entry.getValue() + weightFishLength)));
// put weight to 0 for unused basins
if (group.isThereBasinToUpdate()){
if (time.getYear(group.getPilot()) >= group.getYearOfTheUpdate()
&& group.getPattractive(entry.getKey().getName()) == 0){
//TODO use correctely getPaccessible
accBasinWeight = 0 ;
}
}
totalWeight += accBasinWeight;
basinWeightsFromDeparture.put (entry.getKey(),accBasinWeight );
}
// add the deathBasin in the list
// sum the deathBasin weight in the list
//accBasOfFish.add(new Duo<Basin, Double>(deathBasin, weightOfDeathBasin));
totalWeight = totalWeight + weightOfDeathBasin;
// compute sequentially the prob to go into a basin
for (Duo<Basin, Double> accBasin : accBasOfFish) {
Basin b = accBasin.getFirst();
Double weight = accBasin.getSecond();
for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) {
RiverBasin strayerDestination = entry.getKey();
Double weight = entry.getValue();
probToGo = weight / totalWeight;
amountToGo = Miscellaneous.binomialForSuperIndividual(group.getPilot(), strayedAmount, probToGo);
if (amountToGo > 0) {
if (b.getId() != -1) {
RiverBasin strayerDestination = (RiverBasin) bn.getAssociatedRiverBasin(b);
//RiverBasin strayerDestination = (RiverBasin) bn.getAssociatedRiverBasin(b);
strayerDestination.addFish(fish.duplicateWithNewPositionAndAmount(group.getPilot(), strayerDestination, amountToGo), group);
}
//else{
//TODO add to the cemetery
//deadFish.add(fish.duplicateWithNewPositionAndAmount(accBasin, amountToGo));
//}
}
totalWeight -= weight;
strayedAmount -= amountToGo;
......
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