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

typing correction

parent fb60514b
package species; package species;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; 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 org.openide.util.lookup.ServiceProvider;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.BasinNetwork; import environment.BasinNetwork;
import environment.RiverBasin; import environment.RiverBasin;
import environment.SeaBasin; import environment.SeaBasin;
...@@ -16,15 +19,7 @@ import environment.Time; ...@@ -16,15 +19,7 @@ import environment.Time;
import environment.Time.Season; import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.pilot.Pilot; import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.Miscellaneous;
import org.openide.util.lookup.ServiceProvider;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import miscellaneous.BinomialForSuperIndividualGen; import miscellaneous.BinomialForSuperIndividualGen;
import miscellaneous.Duo;
/** /**
* *
...@@ -32,86 +27,103 @@ import miscellaneous.Duo; ...@@ -32,86 +27,103 @@ 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
*/ */
private long yearOfTheKillings; private long yearOfTheKillings;
/** /**
* the random numbers generator for binomial draws * the random numbers generator for binomial draws
*
* @unit -- * @unit --
*/ */
private transient BinomialForSuperIndividualGen aleaGen; private transient BinomialForSuperIndividualGen aleaGen;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())) System.out.println(
.toXML(new DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin())); (new XStream(new DomDriver())).toXML(new DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin()));
} }
@Override @Override
public void initTransientParameters(Pilot pilot) { public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot); super.initTransientParameters(pilot);
aleaGen = new BinomialForSuperIndividualGen(pilot.getRandomStream()); aleaGen = new BinomialForSuperIndividualGen(pilot.getRandomStream());
} }
@Override @Override
public void doProcess(DiadromousFishGroup group) { public void doProcess(DiadromousFishGroup group) {
Time time = group.getEnvironment().getTime(); Time time = group.getEnvironment().getTime();
...@@ -135,67 +147,80 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -135,67 +147,80 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
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) {
ListIterator<DiadromousFish> fishIterator = fishes.listIterator(); ListIterator<DiadromousFish> fishIterator = fishes.listIterator();
while (fishIterator.hasNext()) { while (fishIterator.hasNext()) {
DiadromousFish fish=fishIterator.next(); DiadromousFish fish = fishIterator.next();
if (fish.isMature()) { if (fish.isMature()) {
// fish with homing // fish with homing
//homingAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), pHoming); // seuil par d�faut fix� � 50 // homingAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(),
homingAmount = aleaGen.getSuccessNumber2(fish.getAmount(), pHoming); // fish.getAmount(), pHoming);
// strayed fish homingAmount = aleaGen.getSuccessNumber(fish.getAmount(), pHoming);
// strayed fish
if (killStrayers == true && time.getYear(group.getPilot()) >= yearOfTheKillings) { if (killStrayers == true && time.getYear(group.getPilot()) >= yearOfTheKillings) {
strayedAmount = 0; strayedAmount = 0;
} } else {
else {
strayedAmount = fish.getAmount() - homingAmount; strayedAmount = fish.getAmount() - homingAmount;
} }
// influence of the fish length on the probability to disperse // influence of the fish length on the probability to disperse
if (strayedAmount != 0) { if (strayedAmount != 0) {
// calcula the weight associated with the fish length in the probabaility to disperse // calcula the weight associated with the fish length in the probabaility to disperse
double weightFishLength = -(alpha2Rep * ((fish.getLength() - meanSpawnersLengthAtRepro) / standardDeviationOfSpawnersLengthAtRepro)); double weightFishLength = -(alpha2Rep * ((fish.getLength() - meanSpawnersLengthAtRepro)
/ standardDeviationOfSpawnersLengthAtRepro));
// 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;
Map<RiverBasin, Double> basinWeightsFromDeparture = new HashMap<RiverBasin, Double>(); Map<RiverBasin, Double> basinWeightsFromDeparture = new HashMap<RiverBasin, Double>();
for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) { for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) {
double accBasinWeight = 1. / (1. + Math.exp(-(entry.getValue() + weightFishLength))); double accBasinWeight = 1.
/ (1. + Math.exp(-(entry.getValue() + 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()
&& group.getPattractive(entry.getKey().getName()) == 0){ && group.getPattractive(entry.getKey().getName()) == 0) {
//TODO use correctely getPaccessible // TODO use correctely getPaccessible
accBasinWeight = 0 ; accBasinWeight = 0;
} }
} }
totalWeight += accBasinWeight; totalWeight += accBasinWeight;
basinWeightsFromDeparture.put (entry.getKey(),accBasinWeight ); basinWeightsFromDeparture.put(entry.getKey(), accBasinWeight);
} }
// sum the deathBasin weight in the list // sum the deathBasin weight in the list
totalWeight = totalWeight + weightOfDeathBasin; totalWeight = totalWeight + weightOfDeathBasin;
// compute sequentially the prob to go into a basin // Afficher le contenu du MAP
for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) {
Iterator<RiverBasin> iterateur = basinWeightsFromDeparture.keySet().iterator();
// Parcourir les clés et afficher les entrées de chaque clé;
while (iterateur.hasNext()) {
RiverBasin key = iterateur.next();
System.out.println(key.getName() + "=>" + basinWeightsFromDeparture.get(key));
}
System.out.println();
// compute sequentially the prob to go into a basin
for (Entry<RiverBasin, Double> entry : basinWeightsPerBasin.get(departure).entrySet()) {
RiverBasin strayerDestination = entry.getKey(); RiverBasin strayerDestination = entry.getKey();
Double weight = entry.getValue(); Double weight = entry.getValue();
probToGo = weight / totalWeight; probToGo = weight / totalWeight;
//amountToGo = Miscellaneous.binomialForSuperIndividual(group.getPilot(), strayedAmount, probToGo); // amountToGo = Miscellaneous.binomialForSuperIndividual(group.getPilot(),
amountToGo = aleaGen.getSuccessNumber2(strayedAmount, probToGo); // strayedAmount, probToGo);
amountToGo = aleaGen.getSuccessNumber(strayedAmount, probToGo);
if (amountToGo > 0) { if (amountToGo > 0) {
strayerDestination.addFish(fish.duplicateWithNewPositionAndAmount(group.getPilot(), strayerDestination, amountToGo), group); strayerDestination.addFish(fish.duplicateWithNewPositionAndAmount(
group.getPilot(), strayerDestination, amountToGo), group);
} }
totalWeight -= weight; totalWeight -= weight;
strayedAmount -= amountToGo; strayedAmount -= amountToGo;
if (strayedAmount <= 0) { if (strayedAmount <= 0) {
//CHECK if it occurs and for which basins // CHECK if it occurs and for which basins
break; break;
} }
} }
...@@ -205,10 +230,10 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di ...@@ -205,10 +230,10 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
if (homingAmount > 0) { if (homingAmount > 0) {
fish.setAmount(homingAmount); fish.setAmount(homingAmount);
fish.setPosition(homingDestination); fish.setPosition(homingDestination);
// retour soit dans le bassin de naissance pour les semelpares // retour soit dans le bassin de naissance pour les semelpares
// soit dans le dernier bassin de reproduction pour les it�ropares // soit dans le dernier bassin de reproduction pour les it�ropares
homingDestination.addFish(fish, group); homingDestination.addFish(fish, group);
} }
// remove fish from the departure basin // remove fish from the departure basin
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