Commit 309bb45c authored by camille.poulet's avatar camille.poulet
Browse files

Fish nutrient with Array list and Hashtable implementation

Showing with 236 additions and 171 deletions
+236 -171
/** /**
* patrick.lambert *
* @author Patrick Lambert * @author Camille Poulet, Patrick Lambert
* @copyright Copyright (c) 2018, Irstea * @copyright Copyright (c) 2019, Irstea
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -20,55 +20,93 @@ ...@@ -20,55 +20,93 @@
package species; package species;
import environment.SeaBasin; import environment.SeaBasin;
import environment.Time.Season;
import fr.cemagref.simaqualife.pilot.Pilot; import fr.cemagref.simaqualife.pilot.Pilot;
import species.DiadromousFish.Gender; import species.DiadromousFish.Gender;
import species.DiadromousFish.Stage; import species.DiadromousFish.Stage;
import species.ReproduceAndSurviveAfterReproduction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
/** /**
* *
*/ */
public class FishNutrient {
private double aLWfemalePre = 0.0221; // param�tre "a" de la relation taille/poids avec Lt en cm
private double bLWfemalePre = 2.8147; // param�tre "b" de la relation taille/poids
private double GSIfemalePre =.15;
private double aLWmalePre = 0.0221; // param�tre "a" de la relation taille/poids avec Lt en cm
private double bLWmalePre = 2.8147; // param�tre "b" de la relation taille/poids
private double GSImalePre =.07;
// Si on ne possède pas wT post reproduction /**
* @author camille.poulet
*
*/
public class FishNutrient {
/** /**
* param�tre "a" de la relation taille/poids avec Lt en cm * Main feature for weight computation before spawning i.e. gametes expelling //Voir pour un retour la ligne lors du commentaire
* key gender
* value
* key feature
* value value
*/ */
private double aLWfemalePost = 0.; // param�tre "a" de la relation taille/poids avec Lt en cm private Map <Gender,Map<String, Double>> fishFeatures;
private double bLWfemalePost = 0.; // param�tre "b" de la relation taille/poids
// Si on ne possede pas wT post reproduction
private double aLWfemalePost = 0.;
private double bLWfemalePost = 0.;
private double GSIfemalePost=0.10; private double GSIfemalePost=0.10;
private double aLWmalePost = 0.; // param�tre "a" de la relation taille/poids avec Lt en cm private double aLWmalePost = 0.;
private double bLWmalePost = 0.; // param�tre "b" de la relation taille/poids private double bLWmalePost = 0.;
private double GSImalePost =.07; private double GSImalePost =.07;
//Si on possede WT post reproduction
private double CoeffLossWeight = 0.; // Valeurs de Haskell pour A. sapidissima -- A rechercher pour Alosa alosa
//Valeurs de Haskell pour A. sapidissima -- A rechercher pour Alosa alosa /**
* chemical composition of carcass before gametes expelling (before spawning) i.e. carcass + gonads + gametes
* <key> gender
* <value>
* <key> chemical element
* <value> value
*/
private Map<DiadromousFish.Gender,Map<String,Double>> compoCarcassPreSpawning;
private double compoNpreMale = 2.921; //package permettant la cration d'une table de hachage ie fonctionnant en cl -valeur. Cl unique, mais valeur peut tre associe plusieurs cls;
private double compoPpreMale = 0.662; //La class d'objet Map a pour point faible la taille des donnes stocker. Plus on a de valeur dans la table, plus c'est lourd et lent! Donc, trouver un compromis entre temps de calcul et espace.
private double compoNpreFemale = 2.917; //N'accepte pas la valeur nulle et thread safe i.e. utilisable simultanment par plusieurs lments du programme.
private double compoPpreFemale = 0.725;
private double compoNpostMale = 2.790 ; /**
private double compoPpostMale = 0.961; * chemical composition of carcass after spawning i.e. gonads without gametes
private double compoNpostFemale = 3.216 ; * <key> gender
private double compoPpostFemale = 0.997; * <value>
* <key> chemical element
* <value> value
*/
private Map<DiadromousFish.Gender, Map<String, Double>> compoCarcassPostSpawning;
/**
* chemical composition of gametes
* <key> gender
* <value>
* <key> chemical element
* <value> value
*/
private Map<DiadromousFish.Gender, Map<String,Double>> compoGametes;
private double compoNoocyte =0.0; // For juveniles - Based on Taverny (1991)
private double compoNsperm =0.0;
private double compoPoocyte =0.0;
private double compoPsperm =0.0;
/**
* chemical composition of juveniles
* <key> stage
* <value>
* <key> chemical element
* <value> value
*/
private Map<String,Double> compoJuvenile;
private double aLWjuveniles = -11.942 ; // parametre "a" de la relation taille/poids avec Lt en cm - Traduit la condition
private double bLWjuveniles = 3.0306; // parametre "b" de la relation taille/poids - Coefficient d'allometrie
/** /**
* *
...@@ -76,175 +114,202 @@ public class FishNutrient { ...@@ -76,175 +114,202 @@ public class FishNutrient {
public FishNutrient() { public FishNutrient() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public FishNutrient(double aLWfemalePre, double bLWfemalePre, double gSIfemalePre, double aLWmalePre,
double bLWmalePre, double gSImalePre, double aLWfemalePost, double bLWfemalePost, double gSIfemalePost, /**
double aLWmalePost, double bLWmalePost, double gSImalePost, double coeffLossWeight, double compoNpreMale, * Constructor based on the 5 Map of fish composition
double compoPpreMale, double compoNpreFemale, double compoPpreFemale, double compoNpostMale, * @param fishFeatures
double compoPpostMale, double compoNpostFemale, double compoPpostFemale, double compoNoocyte, * @param compoCarcassPreSpawning
double compoNsperm, double compoPoocyte, double compoPsperm) { * @param compoCarcassPostSpawning
* @param compoGametes
* @param compoJuvenile
*/
public FishNutrient(Map<Gender, Map<String, Double>> fishFeatures,
Map<Gender, Map<String, Double>> compoCarcassPreSpawning,
Map<Gender, Map<String, Double>> compoCarcassPostSpawning, Map<Gender, Map<String, Double>> compoGametes,
Map<String, Double> compoJuvenile,double aLWjuveniles, double bLWjuveniles ) {
super(); super();
this.aLWfemalePre = aLWfemalePre; this.fishFeatures = fishFeatures;
this.bLWfemalePre = bLWfemalePre; this.compoCarcassPreSpawning = compoCarcassPreSpawning;
GSIfemalePre = gSIfemalePre; this.compoCarcassPostSpawning = compoCarcassPostSpawning;
this.aLWmalePre = aLWmalePre; this.compoGametes = compoGametes;
this.bLWmalePre = bLWmalePre; this.compoJuvenile = compoJuvenile;
GSImalePre = gSImalePre; this.aLWjuveniles = aLWjuveniles;
this.aLWfemalePost = aLWfemalePost; this.bLWjuveniles = bLWjuveniles;
this.bLWfemalePost = bLWfemalePost;
GSIfemalePost = gSIfemalePost;
this.aLWmalePost = aLWmalePost;
this.bLWmalePost = bLWmalePost;
GSImalePost = gSImalePost;
CoeffLossWeight = coeffLossWeight;
this.compoNpreMale = compoNpreMale;
this.compoPpreMale = compoPpreMale;
this.compoNpreFemale = compoNpreFemale;
this.compoPpreFemale = compoPpreFemale;
this.compoNpostMale = compoNpostMale;
this.compoPpostMale = compoPpostMale;
this.compoNpostFemale = compoNpostFemale;
this.compoPpostFemale = compoPpostFemale;
this.compoNoocyte = compoNoocyte;
this.compoNsperm = compoNsperm;
this.compoPoocyte = compoPoocyte;
this.compoPsperm = compoPsperm;
} }
/** /**
* compute the N and P fluxes for a single fish (in the super individual) * compute the nutrient fluxes for a single fish (in the super individual)
* that dies after spawning (gametes expelling) * that dies before spawning
* @param fish * @param fish
*/ */
public double[] computeInportNPforDeathBeforeSpawning(DiadromousFish fish) { public Map<String,Double> computeNutrientsInputForDeathBeforeSpawning(DiadromousFish fish, ArrayList<String> nutrientsOfInterest) {
double totalWeightPre;
double [] inportNP = new double[2]; //Declare an array with two coloumns Map<String,Double> nutrientsInput = new Hashtable<String, Double>(); // On crer ici une Map, classe mre des hashtable (Homme = classe mere ie Map//Jules = hashtable)
inportNP[0] = 0; // create the colomn for (String nutrient : nutrientsOfInterest) {
inportNP[1] = 0;
if (fish.getStage()== Stage.MATURE) { if (fish.getStage()== Stage.MATURE) {
if(fish.getGender()== Gender.FEMALE) { double totalWeightPre = fishFeatures.get(fish.getGender()).get("aLW") * Math.pow(fish.getLength(), fishFeatures.get(fish.getGender()).get("bLW"));
totalWeightPre = aLWfemalePre * Math.pow(fish.getLength(), bLWfemalePre);
//totalWeightPost = totalWeightPre * (1-GSIfemalePost)+ totalWeightPost * GSIfemalePost * CoeffLossWeight //totalWeightPost = totalWeightPre * (1-GSIfemalePost)+ totalWeightPost * GSIfemalePost * CoeffLossWeight
inportNP[0] = totalWeightPre * compoNpreFemale; nutrientsInput.put(nutrient, totalWeightPre * compoCarcassPreSpawning.get(fish.getGender()).get(nutrient));
inportNP[1] = totalWeightPre * compoPpreFemale;
} }
else if (fish.getGender()== Gender.MALE) { else {
totalWeightPre = aLWmalePre * Math.pow(fish.getLength(), bLWmalePre); nutrientsInput.put(nutrient, 0.);
//totalWeightPost = totalWeightPre * (1-GSImalePost)+ totalWeightPost * GSImalePost * CoeffLossWeight
inportNP[0] = totalWeightPre * compoNpreMale;
inportNP[1] = totalWeightPre * compoPpreMale;
}
else {
totalWeightPre= Double.NaN;
inportNP[0] = 0.;
inportNP[1] = 0;
} }
} }
return inportNP; return nutrientsInput;
} }
public double[] computeInportNPforDeathAfterSpawning(DiadromousFish fish) { /**
double totalWeightPre, totalWeightPost; * compute the nutrient fluxes for a single fish (in the super individual)
* that dies after spawning (gametes expelling)
* @param fish
* @return nutrientsInput
*/
public Map<String, Double> computeNutrientsInputForDeathAfterSpawning(DiadromousFish fish, ArrayList<String> nutrientsOfInterest) {
Map<String,Double> nutrientsInput = new Hashtable<String,Double>();
for (String nutrient : nutrientsOfInterest) {
double[] inportNP = new double[2]; if (fish.getStage()== Stage.MATURE) {
inportNP[0] = 0.;
inportNP[1] = 0.;
if (fish.getStage() == Stage.MATURE) { double totalWeightPre = fishFeatures.get(fish.getGender()).get("aLW") * Math.pow(fish.getLength(), fishFeatures.get(fish.getGender()).get("bLW"));
if (fish.getGender() == Gender.FEMALE ) { //TODO Fix the new data
totalWeightPre = aLWfemalePre * Math.pow(fish.getLength(), bLWfemalePre); double totalWeightPost = aLWfemalePost * Math.pow(fish.getLength(), bLWfemalePost);
totalWeightPost = aLWfemalePost * Math.pow(fish.getLength(), bLWfemalePost); nutrientsInput.put(nutrient,(totalWeightPre - totalWeightPost) * compoCarcassPostSpawning.get(fish.getGender()).get(nutrient));
//totalWeightPost = totalWeightPre * (1-GSIfemalePost)+ totalWeightPost * GSIfemalePost * CoeffLossWeight
inportNP[0] = totalWeightPost * compoNpostFemale + (totalWeightPre - totalWeightPost) * compoNoocyte;
inportNP[1] = totalWeightPost * compoPpostFemale + (totalWeightPre - totalWeightPost) * compoPoocyte;
}
else if (fish.getGender() == Gender.MALE) {
totalWeightPre = aLWmalePre * Math.pow(fish.getLength(), bLWmalePre);
totalWeightPost = aLWmalePost * Math.pow(fish.getLength(), bLWmalePost);
//totalWeightPost = totalWeightPre * (1-GSImalePost)+ totalWeightPost * GSImalePost * CoeffLossWeight
inportNP[0] = totalWeightPost * compoNpostMale + (totalWeightPre - totalWeightPost) * compoNsperm;
inportNP[1] = totalWeightPost * compoPpostMale + (totalWeightPre - totalWeightPost) * compoPsperm;
} }
else { else {
totalWeightPre = Double.NaN; nutrientsInput.put(nutrient,0.);
totalWeightPost = 0.; }
inportNP[0]=0.;
inportNP[1]=0.;
}
} }
return nutrientsInput;
return inportNP;
} }
public double [] computeInportNPforSurvivalAfterSpawning(DiadromousFish fish) {
double totalWeightPre, totalWeightPost; /**
* compute the nutrient fluxes for a single fish (in the super individual)
double[]inportNP = new double [2]; * that survives after spawning
inportNP[0]= 0; * Map: model output = element of interest ie string + double ie the quantification of this fluxes.
inportNP[1] = 0; * @return nutrientsInput
*/
if (fish.getStage()== Stage.MATURE) { public Map<String,Double>computeNutrientsInputForSurvivalAfterSpawning(DiadromousFish fish, ArrayList<String> nutrientsOfInterest) {
if (fish.getGender()==Gender.FEMALE){
totalWeightPre = aLWfemalePre * Math.pow(fish.getLength(), bLWfemalePre);
totalWeightPost = aLWfemalePost * Math.pow(fish.getLength(), bLWfemalePost);
//totalWeightPost = totalWeightPre * (1-GSImalePost)+ totalWeightPost * GSImalePost * CoeffLossWeight
inportNP[0] = (totalWeightPre - totalWeightPost)* compoNoocyte;
inportNP[1] = (totalWeightPre - totalWeightPost)* compoPoocyte;
}
else if (fish.getGender()== Gender.MALE) {
totalWeightPre = aLWfemalePre * Math.pow(fish.getLength(), bLWmalePre); Map<String,Double> nutrientsInput = new Hashtable<String,Double>();
totalWeightPost = aLWfemalePost * Math.pow(fish.getLength(), bLWmalePost); for (String nutrient: nutrientsOfInterest) {
//totalWeightPost = totalWeightPre * (1-GSImalePost)+ totalWeightPost * GSImalePost * CoeffLossWeight if (fish.getStage()==Stage.MATURE) {
inportNP[0] = (totalWeightPre - totalWeightPost)* compoNsperm;
inportNP[1] = (totalWeightPre - totalWeightPost)* compoPsperm;
double totalWeightPre = fishFeatures.get(fish.getGender()).get("aLW") * Math.pow(fish.getLength(), fishFeatures.get(fish.getGender()).get("bLW"));
//TODO Fix with new data
double totalWeightPost = aLWfemalePost * Math.pow(fish.getLength(), bLWfemalePost);
nutrientsInput.put(nutrient, (totalWeightPre - totalWeightPost) * compoGametes.get(fish.getGender()).get(nutrient));
} }
else { else {
totalWeightPre= Double.NaN; nutrientsInput.put(nutrient,0.);
totalWeightPost = 0.;
inportNP[0] = 0.;
inportNP[1] = 0;
} }
} }
return nutrientsInput;
return inportNP; }
public Map<String,Double> computeNutrientsExportForJuveniles (DiadromousFish juvenileFish, ArrayList<String>nutrientsOfInterest) {
Map<String,Double> nutrientsExport = new Hashtable<String,Double>();
for(String nutrient: nutrientsOfInterest) {
if(juvenileFish.getStage()==Stage.IMMATURE) {
double JuvenileMass = aLWjuveniles * Math.pow(juvenileFish.getLength(), bLWjuveniles);
nutrientsExport.put(nutrient, JuvenileMass * compoJuvenile.get(nutrient));
}
}
return nutrientsExport;
} }
public static void main(String[] args) { public static void main(String[] args) {
FishNutrient fn = new FishNutrient(0.0221, 2.8147, .15, 0.0221, 2.8147, .07, 0., 0., 0.10, 0., 0., 0.07, 0., 2.921, 0.662, 2.917, 0.725, 2.790, 0.961, 3.216, 0.997, 0., 0., 0., 0.); //On lui passe les valeurs utiliss ici dans le programme Map<Gender, Map<String, Double>> aFeaturePreSpawning = new Hashtable<DiadromousFish.Gender, Map<String,Double>>();
SeaBasin basin = new SeaBasin(0,"Bidon",10.,12., 14.,12.); //il faut aller dans "SeaBasin" dans "environement et regarder comment est construit le constructeur. Il lui faut ici un rang, un nom de bassin versant, et des temprature pour chaque saison Map<String,Double> aFeature = new Hashtable<String,Double>();
Pilot pilot = new Pilot (); aFeature.put("aLW",1.2102E-6); // parametre "a" de la relation taille/poids avec Lt en cm - Traduit la condition
DiadromousFish fish = new DiadromousFish (pilot, basin, 40., 1L, Gender.FEMALE); //Idem ici, on regarde comment est construit DiadromousFih et on lui donne les valeur de ce qu'il nous demande. aFeature.put("bLW",3.3429);// parametre "b" de la relation taille/poids - Coefficient d'allometrie
fish.setStage(Stage.MATURE); aFeature.put("GSI",0.15);
double[] np = fn.computeInportNPforDeathAfterSpawning(fish); aFeaturePreSpawning.put(Gender.FEMALE, aFeature);
System.out.println("N = " + np[0]+ "P = "+ np[1]); // on met des + la place des "," car l'ordinateur n'est pas capable detraiter des objets ddiffrent de "String". Or on a un double ici.
aFeature = new Hashtable<String,Double>();
aFeature.put("aLW",2.4386E-6);
aFeature.put("bLW",3.2252);
aFeature.put("GSI",.07);
aFeaturePreSpawning.put(Gender.MALE,aFeature);
System.out.println(aFeaturePreSpawning.toString()); //
// carcass composition for fish before spawning
Map<Gender, Map<String, Double>> aCompoCarcassPreSpawning = new Hashtable<DiadromousFish.Gender,Map<String,Double>>();
Map<String,Double> aCompo = new Hashtable<String,Double>();
aCompo.put("N", 2.917); //On remplit une collection avec un put.
aCompo.put("P", 0.725);
aCompoCarcassPreSpawning.put(Gender.FEMALE,aCompo);
aCompo = new Hashtable<String,Double>();
aCompo.put("N", 2.921);
aCompo.put("P",0.662);
aCompoCarcassPreSpawning.put(Gender.MALE,aCompo);
System.out.println(aCompoCarcassPreSpawning.toString()); //
// carcass composition for fish after spawning
Map<Gender, Map<String, Double>> aCompoCarcassPostSpawning = new Hashtable<DiadromousFish.Gender,Map<String,Double>>();
aCompo = new Hashtable<String,Double>();
aCompo.put("N", 3.216); //On remplit une collection avec un put.
aCompo.put("P", 0.997);
aCompoCarcassPostSpawning.put(Gender.FEMALE,aCompo);
aCompo = new Hashtable<String,Double>();
aCompo.put("N", 2.790);
aCompo.put("P",0.961);
aCompoCarcassPostSpawning.put(Gender.MALE,aCompo);
System.out.println(aCompoCarcassPostSpawning.toString()); //
// carcass composition for fish gametes
Map<Gender, Map<String, Double>> aCompoGametes = new Hashtable<DiadromousFish.Gender,Map<String,Double>>();
aCompo = new Hashtable<String,Double>();
aCompo.put("N", 0.); //On remplit une collection avec un put.
aCompo.put("P", 0.);
aCompoGametes.put(Gender.FEMALE,aCompo);
aCompo = new Hashtable<String,Double>();
aCompo.put("N", 0.);
aCompo.put("P",0.);
aCompoGametes.put(Gender.MALE,aCompo);
System.out.println(aCompoGametes.toString()); //
// carcass composition for juveniles fish
Map<String, Double> aCompoJuveniles = new Hashtable<String,Double>();
aCompoJuveniles.put("N", 0.); //On remplit une collection avec un put.
aCompoJuveniles.put("P", 0.);
System.out.println(aCompoJuveniles.toString());
FishNutrient fn = new FishNutrient(aFeaturePreSpawning, aCompoCarcassPreSpawning, aCompoCarcassPostSpawning, aCompoGametes, aCompoJuveniles,
-11.942, 3.0306);
SeaBasin basin = new SeaBasin(0,"Bidon",10.,12., 14.,12.); //il faut aller dans "SeaBasin" dans "environement et regarder comment est construit le constructeur. Il lui faut ici un rang, un nom de bassin versant, et des temprature pour chaque saison
Pilot pilot = new Pilot ();
DiadromousFish fish = new DiadromousFish (pilot, basin, 40., 1L, Gender.FEMALE); //Idem ici, on regarde comment est construit DiadromousFih et on lui donne les valeur de ce qu'il nous demande.
fish.setStage(Stage.MATURE);
DiadromousFish juvenileFish = new DiadromousFish(pilot,basin,2.0,1L,Gender.UNDIFFERENCIED);
fish.setStage(Stage.IMMATURE);
ArrayList <String> nutrientsOfInterest= new ArrayList <String>();
nutrientsOfInterest.add("N");
nutrientsOfInterest.add("P");
System.out.println(nutrientsOfInterest);
System.out.println("Nutrients Fluxes for death before spawning " + fn.computeNutrientsInputForDeathBeforeSpawning(fish, nutrientsOfInterest).toString());
System.out.println("Nutrients Fluxes for death after spawning " + fn.computeNutrientsInputForDeathAfterSpawning(fish, nutrientsOfInterest).toString());
System.out.println("Nutrients Fluxes for survival " + fn.computeNutrientsInputForSurvivalAfterSpawning(fish, nutrientsOfInterest).toString());
System.out.println("Nutrients Fluxes for juveniles " + fn.computeNutrientsExportForJuveniles(juvenileFish, nutrientsOfInterest).toString());
}
} }
}
Supports Markdown
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