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

Remove Duo

parent 5ff97121
...@@ -5,6 +5,7 @@ import java.util.List; ...@@ -5,6 +5,7 @@ import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap;
import environment.Basin; import environment.Basin;
import environment.BasinNetwork; import environment.BasinNetwork;
...@@ -28,61 +29,61 @@ import miscellaneous.Duo; ...@@ -28,61 +29,61 @@ import miscellaneous.Duo;
@ServiceProvider(service = AquaNismsGroupProcess.class) @ServiceProvider(service = AquaNismsGroupProcess.class)
public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends DisperseAndMigrateToRiverBasic { public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends DisperseAndMigrateToRiverBasic {
/** /**
* the season when fish migrate to the river to reproduce * the season when fish migrate to the river to reproduce
* @unit * @unit
*/ */
private Season riverMigrationSeason = Season.SPRING; private Season riverMigrationSeason = Season.SPRING;
/** /**
* the homing probalilty during the installation of new populations ( to reach kind of equilibrium) * the homing probalilty during the installation of new populations ( to reach kind of equilibrium)
* @unit * @unit
*/ */
private double pHomingForReachEquil = 1.0; private double pHomingForReachEquil = 1.0;
/** /**
* the homing probalilty after the installation of new populations ( after reaching an equilibrium) * the homing probalilty after the installation of new populations ( after reaching an equilibrium)
* @unit * @unit
*/ */
private double pHomingAfterEquil = 0.8; private double pHomingAfterEquil = 0.8;
/** /**
* Number of year for newly created populations to be installed ( to reach an equilibrium) * Number of year for newly created populations to be installed ( to reach an equilibrium)
* @unit * @unit
*/ */
private long NbYearForInstallPop = 50; private long NbYearForInstallPop = 50;
/** the coefficient associated with the fish size in the logistic function used to calculate the probability to disperse /** the coefficient associated with the fish size in the logistic function used to calculate the probability to disperse
* @unit - * @unit -
*/ */
private double alpha2Rep = 0.; private double alpha2Rep = 0.;
/** /**
* the mean length used to standardize the fish length in the logistic function that calculates the probability to disperse * the mean length used to standardize the fish length in the logistic function that calculates the probability to disperse
* @unit - * @unit -
*/ */
private double meanSpawnersLengthAtRepro = 45.; private double meanSpawnersLengthAtRepro = 45.;
/** /**
* the length standard deviation used to standardize the fish length in the logistic function that calculates the probability to disperse * the length standard deviation used to standardize the fish length in the logistic function that calculates the probability to disperse
* @unit - * @unit -
*/ */
private double standardDeviationOfSpawnersLengthAtRepro = 2.; // for standard core values... private double standardDeviationOfSpawnersLengthAtRepro = 2.; // for standard core values...
/** /**
* the weigth of the death bassin ( for strayers that do not find a catcment) used to calculate the probability to disperse * the weigth of the death bassin ( for strayers that do not find a catcment) used to calculate the probability to disperse
* @unit * @unit
*/ */
private double weightOfDeathBasin = 0.2; private double weightOfDeathBasin = 0.2;
/** /**
* a bollean to kill of the strayers (used to determine if a catchment is a souce or a sink) the year given by yearOfTheKilling * a bollean to kill of the strayers (used to determine if a catchment is a souce or a sink) the year given by yearOfTheKilling
* @unit * @unit
*/ */
private boolean killStrayers; private boolean killStrayers;
/** /**
* the year when the strayers are killed (used to determine if a catchment is a souce or a sink) if killStrayers is true * the year when the strayers are killed (used to determine if a catchment is a souce or a sink) if killStrayers is true
* @unit * @unit
...@@ -115,14 +116,13 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -115,14 +116,13 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
//List<DiadromousFish> newFish = new ArrayList<DiadromousFish>(); //List<DiadromousFish> newFish = new ArrayList<DiadromousFish>();
// creation of the death basin (for the lost strayers) // 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>>(); //List<Duo<DiadromousFish, Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish, Basin>>();
for (SeaBasin departure : group.getEnvironment().getSeaBasins()) { for (SeaBasin departure : group.getEnvironment().getSeaBasins()) {
RiverBasin homingDestination = (RiverBasin) bn.getAssociatedRiverBasin(departure); RiverBasin homingDestination = (RiverBasin) bn.getAssociatedRiverBasin(departure);
List<DiadromousFish> fishes = departure.getFishs(group); List<DiadromousFish> fishes = departure.getFishs(group);
if (fishes != null) { if (fishes != null) {
//for (DiadromousFish fish : fishes) { //for (DiadromousFish fish : fishes) {
...@@ -131,7 +131,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -131,7 +131,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
DiadromousFish fish=fishIterator.next(); DiadromousFish fish=fishIterator.next();
// verify that fish is in a sea basin // verify that fish is in a sea basin
//assert fish.getPosition().getType() == Basin.TypeBassin.SEA; //assert fish.getPosition().getType() == Basin.TypeBassin.SEA;
if (fish.isMature()) { if (fish.isMature()) {
// fish with homing // fish with homing
amountWithHoming = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), pHoming); // seuil par d�faut fix� � 50 amountWithHoming = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), pHoming); // seuil par d�faut fix� � 50
...@@ -156,17 +156,18 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -156,17 +156,18 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
accBasOfFish.add(duo); accBasOfFish.add(duo);
} }
// We fill the weight table // We fill the weight table
double totalWeight = 0.; double totalWeight = 0.;
double probToGo = 0.; double probToGo = 0.;
long amountToGo = 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) { for (Duo<Basin, Double> accBasin : accBasOfFish) {
// total weight for the basin // total weight for the basin
Basin b = accBasin.getFirst(); Basin b = accBasin.getFirst();
Double weight = accBasin.getSecond(); Double weight = accBasin.getSecond();
double accBasinWeight = 1 / (1 + Math.exp(-(weight + weightFishLength))); double accBasinWeight = 1 / (1 + Math.exp(-(weight + weightFishLength)));
// put weight to 0 for unused basins // put weight to 0 for unused basins
if (group.isThereBasinToUpdate()){ if (group.isThereBasinToUpdate()){
if (time.getYear(group.getPilot()) >= group.getYearOfTheUpdate() if (time.getYear(group.getPilot()) >= group.getYearOfTheUpdate()
...@@ -177,28 +178,40 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -177,28 +178,40 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
} }
accBasin.setSecond(accBasinWeight); accBasin.setSecond(accBasinWeight);
totalWeight += 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)); //accBasOfFish.add(new Duo<Basin, Double>(deathBasin, weightOfDeathBasin));
totalWeight = totalWeight + weightOfDeathBasin; totalWeight = totalWeight + weightOfDeathBasin;
// compute sequentially the prob to go into a basin // compute sequentially the prob to go into a basin
for (Duo<Basin, Double> accBasin : accBasOfFish) { for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) {
Basin b = accBasin.getFirst(); RiverBasin strayerDestination = entry.getKey();
Double weight = accBasin.getSecond(); Double weight = entry.getValue();
probToGo = weight / totalWeight; probToGo = weight / totalWeight;
amountToGo = Miscellaneous.binomialForSuperIndividual(group.getPilot(), strayedAmount, probToGo); amountToGo = Miscellaneous.binomialForSuperIndividual(group.getPilot(), strayedAmount, probToGo);
if (amountToGo > 0) { 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); strayerDestination.addFish(fish.duplicateWithNewPositionAndAmount(group.getPilot(), strayerDestination, amountToGo), group);
}
//else{
//TODO add to the cemetery
//deadFish.add(fish.duplicateWithNewPositionAndAmount(accBasin, amountToGo));
//}
} }
totalWeight -= weight; totalWeight -= weight;
strayedAmount -= amountToGo; strayedAmount -= amountToGo;
...@@ -220,7 +233,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -220,7 +233,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
/*else { /*else {
deadFish.add(fish); deadFish.add(fish);
}*/ }*/
fishIterator.remove(); fishIterator.remove();
} }
} }
......
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