Commit 8c61b3dd authored by Lambert Patrick's avatar Lambert Patrick
Browse files

with optimized random draw

parent 016421c6
......@@ -9,10 +9,12 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import miscellaneous.BinomialForSuperIndividualGen;
import miscellaneous.Duo;
import miscellaneous.Miscellaneous;
import miscellaneous.Trio;
......@@ -29,6 +31,7 @@ import org.apache.commons.math3.optim.univariate.UnivariatePointValuePair;
import org.openide.util.lookup.ServiceProvider;
import umontreal.iro.lecuyer.probdist.NormalDist;
import umontreal.iro.lecuyer.randvar.NormalACRGen;
import umontreal.iro.lecuyer.randvar.NormalGen;
import com.thoughtworks.xstream.XStream;
......@@ -67,6 +70,13 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
private boolean displayFluxesOnConsole = true;
private transient NormalGen genNormal;
/**
* the random numbers generator for binomial draws
* @unit --
*/
private transient BinomialForSuperIndividualGen aleaGen;
private transient MortalityFunction mortalityFunction;
......@@ -86,8 +96,11 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
@InitTransientParameters
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
genNormal = new NormalGen( pilot.getRandomStream(),
genNormal = new NormalACRGen( pilot.getRandomStream(),
new NormalDist(0., 1.));
aleaGen = new BinomialForSuperIndividualGen(pilot.getRandomStream());
mortalityFunction=new MortalityFunction();
stockRecruitmentRelationship= new StockRecruitmentRelationship();
}
......@@ -104,7 +117,7 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
public void doProcess(DiadromousFishGroup group) {
Time time = group.getEnvironment().getTime();
if (time.getSeason(group.getPilot()) == reproductionSeason){
List<DiadromousFish> deadFish = new ArrayList<DiadromousFish>();
//List<DiadromousFish> deadFish = new ArrayList<DiadromousFish>();
// a River
List<String> basinList = new ArrayList<String>() ;
basinList.add("Garonne");
......@@ -164,6 +177,7 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// effective temperature for reproduction (priority to the ANG value)
double tempEffectRep;
//CHECK if currentTemp can be removed
double currentTemp = riverBasin.getCurrentTemperature(group.getPilot());
if (Double.isNaN(group.getTempMinRep())){
tempEffectRep = Miscellaneous.temperatureEffect(riverBasin.getCurrentTemperature(group.getPilot()), tempMinRep, tempOptRep, tempMaxRep);
......@@ -203,7 +217,11 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
Map<Integer, Long> ageOfNativeSpawners = new TreeMap<Integer, Long>();
// compute the number of female spawners and keep the origine of the female spawners
for (DiadromousFish fish : fishInBasin){
ListIterator<DiadromousFish> fishIterator = fishInBasin.listIterator();
while (fishIterator.hasNext()) {
DiadromousFish fish = fishIterator.next();
//for (DiadromousFish fish : fishInBasin){
if (fish.isMature()) {
......@@ -253,13 +271,12 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// survival after reproduction (semelparity or iteroparity) of SI (change the amount of the SI)
double biomass = 0.;
survivalAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), survivalRateAfterReproduction);
survivalAmount = aleaGen.getSuccessNumber2(fish.getAmount(), survivalRateAfterReproduction);
// update the amount of fish or kill the fish if survival amount = 0
// compute nutrient fluxes
// update the amount of fish or kill the fish if survival amount = 0
if (survivalAmount > 0) {// SUperindividu est encore vivant mais il perd des effectifs
// --------------------------------------------------------------------------------------- nutrient routine -----------------------------
//Export for one fish survived after spawning (survivalAmount) : excretion + gametes
Map <String, Double> aFluxAfterSurvival = group.getNutrientRoutine().computeNutrientsInputForSurvivalAfterSpawning(fish);
......@@ -287,14 +304,16 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
//compute biomass for dead fish
biomass = group.getNutrientRoutine().getWeight(fish) * (fish.getAmount() - survivalAmount);
totalInputFluxes.get(spawnerOrigin).put("biomass", totalInputFluxes.get(spawnerOrigin).get("biomass") + biomass);
// --------------------------------------------------------------------------------------- nutrient routine -----------------------------
//update the amount of individual in the super-individual
fish.setAmount(survivalAmount);
}
else {
//Le superindividu est mort !!!
deadFish.add(fish);
//deadFish.add(fish);
// --------------------------------------------------------------------------------------- nutrient routine -----------------------------
//Export for fished died after spawning (fish.getAmount): carcasses + excretion + gametes
Map<String, Double> aFluxForDeadFish = group.getNutrientRoutine().computeNutrientsInputForDeathAfterSpawning(fish); //
......@@ -303,7 +322,11 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
put(time.getYear(group.getPilot()), nutrient, fish.getBirthBasin().getName(), riverBasin.getName(), aFluxForDeadFish.get(nutrient) * (fish.getAmount() - survivalAmount));
}
biomass = group.getNutrientRoutine().getWeight(fish) * (fish.getAmount());
totalInputFluxes.get(spawnerOrigin).put("biomass", totalInputFluxes.get(spawnerOrigin).get("biomass") + biomass);
totalInputFluxes.get(spawnerOrigin).put("biomass", totalInputFluxes.get(spawnerOrigin).get("biomass") + biomass);
// --------------------------------------------------------------------------------------- nutrient routine -----------------------------
// remove fish because fish is dead
fishIterator.remove();
}
}
}
......@@ -368,7 +391,7 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// System.out.println("\t"+ riverBasin.getPopulationStatus());
String message;
/*String message;
if (Double.isNaN(riverBasin.getNativeSpawnerMortality()))
message="noSense";
else {
......@@ -386,7 +409,7 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
}
}
}
//System.out.println("\t"+message);
System.out.println("\t"+message);*/
}
// --------------------------------------------------------------------------------------------------
......@@ -513,10 +536,10 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// --------------------------------------------------------------------------------------------------
// Remove deadfish and compute the related nutrient fluxes
// --------------------------------------------------------------------------------------------------
for (DiadromousFish fish : deadFish){
/* for (DiadromousFish fish : deadFish){
group.removeAquaNism(fish);
}
deadFish.clear();
deadFish.clear();*/
// -------------------------------------------------------
// display information
......
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