Commit b20c8884 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

code cleaning

parent 4718ef61
......@@ -102,7 +102,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
if (time.getSeason(group.getPilot()) == riverMigrationSeason) {
BasinNetwork bn = group.getEnvironment();
long amountWithHoming, strayedAmount;
long homingAmount, strayedAmount;
// probability of homing
double pHoming;
......@@ -112,13 +112,6 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
pHoming = pHomingAfterEquil;
}
//List<DiadromousFish> deadFish = new ArrayList<DiadromousFish>();
//List<DiadromousFish> newFish = new ArrayList<DiadromousFish>();
// creation of the death basin (for the lost strayers)
//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()) {
RiverBasin homingDestination = (RiverBasin) bn.getAssociatedRiverBasin(departure);
......@@ -129,19 +122,16 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
ListIterator<DiadromousFish> fishIterator = fishes.listIterator();
while (fishIterator.hasNext()) {
DiadromousFish fish=fishIterator.next();
// verify that fish is in a sea basin
//assert fish.getPosition().getType() == Basin.TypeBassin.SEA;
if (fish.isMature()) {
// fish with homing
amountWithHoming = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), pHoming); // seuil par d�faut fix� � 50
homingAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), pHoming); // seuil par d�faut fix� � 50
// strayed fish
if (killStrayers == true && time.getYear(group.getPilot()) >= yearOfTheKillings) {
strayedAmount = 0;
}
else {
strayedAmount = fish.getAmount() - amountWithHoming;
strayedAmount = fish.getAmount() - homingAmount;
}
// influence of the fish length on the probability to disperse
......@@ -149,37 +139,10 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
// calcula the weight associated with the fish length in the probabaility to disperse
double weightFishLength = -(alpha2Rep * ((fish.getLength() - meanSpawnersLengthAtRepro) / standardDeviationOfSpawnersLengthAtRepro));
// upload the weights associated with features of the catchment (accessibility and attractivity)
List<Duo<Basin, Double>> accBasOfFish = new ArrayList<Duo<Basin, Double>>();
for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(fish.getPosition()).entrySet()) {
Duo<Basin, Double> duo = new Duo<Basin, Double>(entry.getKey(), entry.getValue());
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
for (Duo<Basin, Double> accBasin : accBasOfFish) {
// total weight for the basin
Basin b = accBasin.getFirst();
Double weight = accBasin.getSecond();
double accBasinWeight = 1 / (1 + Math.exp(-(weight + weightFishLength)));
// put weight to 0 for unused basins
if (group.isThereBasinToUpdate()){
if (time.getYear(group.getPilot()) >= group.getYearOfTheUpdate()
&& group.getPattractive(b.getName()) == 0){
//TODO use correctely getPaccessible
accBasinWeight = 0 ;
}
}
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)));
......@@ -197,7 +160,6 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
}
// 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
......@@ -208,46 +170,34 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
amountToGo = Miscellaneous.binomialForSuperIndividual(group.getPilot(), strayedAmount, probToGo);
if (amountToGo > 0) {
//RiverBasin strayerDestination = (RiverBasin) bn.getAssociatedRiverBasin(b);
strayerDestination.addFish(fish.duplicateWithNewPositionAndAmount(group.getPilot(), strayerDestination, amountToGo), group);
}
totalWeight -= weight;
strayedAmount -= amountToGo;
if (strayedAmount <= 0) {
//CHECK if it occurs and for which basins
break;
}
}
}
// update fish with homing
if (amountWithHoming > 0) {
fish.setAmount(amountWithHoming);
if (homingAmount > 0) {
fish.setAmount(homingAmount);
fish.setPosition(homingDestination);
// retour soit dans le bassin de naissance pour les semelpares
// soit dans le dernier bassin de reproduction pour les it�ropares
homingDestination.addFish(fish, group);
//fishesToMove.add(new Duo<DiadromousFish, Basin>(fish, bn.getAssociatedRiverBasin(fish.getPosition())));
}
/*else {
deadFish.add(fish);
}*/
// remove fish from the departure basin
fishIterator.remove();
}
}
}
}
/*for (Duo<DiadromousFish, Basin> duo : fishesToMove) {
duo.getFirst().moveTo(group.getPilot(), duo.getSecond(), group);
}
for (DiadromousFish fish : deadFish) {
group.removeAquaNism(fish);
}
for (DiadromousFish fish : newFish) {
group.addAquaNism(fish);
}*/
}
}
}
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