diff --git a/src/main/java/environment/RiverBasin.java b/src/main/java/environment/RiverBasin.java index 388c76ae0a3ba649cba302930075ace6ec06c325..aeec34d2343793d7a2e3ede7927c59d287567e5e 100644 --- a/src/main/java/environment/RiverBasin.java +++ b/src/main/java/environment/RiverBasin.java @@ -106,6 +106,7 @@ public class RiverBasin extends Basin { // private int memorySize; // size of the queue // TODO define as many QueueMemory as populations + private QueueMemory<Double> lastSpawnerNumbersBeforeReproduction; private QueueMemory<Long> lastRecruitments; private QueueMemory<Long> lastRecruitmentExpectations; private QueueMemory<Double> lastProdCapacities; // keep the production capacities of the basin (parameter alpha of @@ -133,7 +134,6 @@ public class RiverBasin extends Basin { protected static transient ObservablesHandler cobservable; - public ObservablesHandler getCobservable() { return cobservable; } @@ -235,6 +235,7 @@ public class RiverBasin extends Basin { this.yearOfLastNulRep = 0; this.type = Basin.BasinType.RIVER; // this.memorySize = memoryAllQueues; + this.lastSpawnerNumbersBeforeReproduction = new QueueMemory<Double>(memorySize); this.lastRecruitments = new QueueMemory<Long>(memorySize); this.lastRecruitmentExpectations = new QueueMemory<Long>(memorySize); this.lastProdCapacities = new QueueMemory<Double>(memorySize); @@ -429,6 +430,14 @@ public class RiverBasin extends Basin { } + /** + * @return the lastSpawnerNumbersBeforeReproduction + */ + public QueueMemory<Double> getLastSpawnerNumbersBeforeReproduction() { + return this.lastSpawnerNumbersBeforeReproduction; + } + + public QueueMemory<Long> getLastRecruitments() { return lastRecruitments; } @@ -453,12 +462,12 @@ public class RiverBasin extends Basin { return numberOfNonNulRecruitmentDuringLastYears; } - /* * public QueueMemory<Double> getFemaleSpawnersForFirstTimeMeanAges() { return * spawnersForFirstTimeMeanAges.get(Gender.FEMALE); } */ + public QueueMemory<Double> getSpawnersForFirstTimeMeanLengths(DiadromousFish.Gender gender) { if (gender == Gender.FEMALE) return femaleSpawnersForFirstTimeMeanLengths; diff --git a/src/main/java/species/AnalyseFishDistribution.java b/src/main/java/species/AnalyseFishDistribution.java index 599198edf0285beb370c5c1a28419c4de72e4418..4ba0ecf382aa49a1b981541b00ffbda65d6e5885 100644 --- a/src/main/java/species/AnalyseFishDistribution.java +++ b/src/main/java/species/AnalyseFishDistribution.java @@ -27,8 +27,6 @@ import com.thoughtworks.xstream.io.xml.DomDriver; import environment.RIOBasinNetwork; import environment.RiverBasin; -import environment.Time; -import environment.Time.Season; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.pilot.Pilot; import miscellaneous.TreeMapForCentile; @@ -39,17 +37,6 @@ import observer.ObservableRecord; */ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { - private Season fishDistributionAnalysisSeason = Season.SPRING; - - private long fishDistributionAnalysisStartYear = 1920; - - private long fishDistributionAnalysisEndYear = 1950; - - private transient List<FishDistributionRecord> records; - - private transient double southernLimit; - private transient double northernLimit; - /** * The minimum number of recruits to consider a basin as populated * @@ -57,53 +44,11 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis */ private int minimumRecruitsForPopulatedBasin = 50; - private class FishDistributionRecord implements ObservableRecord { - @Information(unit = "year") - private long year; - - @Information(unit = "-") - private int southern_basin_id; - @Information(unit = "-") - private String southern_basin_name; - @Information(unit = "°") - private double southern_latitude; - - @Information(unit = "-") - private int northern_basin_id; - @Information(unit = "-") - private String northern_basin_name; - @Information(unit = "°") - private double northern_latitude; - - @Information(unit = "°") - private double centroide_latitude; - - public FishDistributionRecord(long year, int southern_basin_id, String southern_basin_name, double southern_latitude, - int northern_basin_id, String northern_basin_name, double northern_latitude, double centroide_latitude) { - this.year = year; - this.southern_basin_id = southern_basin_id; - this.southern_basin_name = southern_basin_name; - this.southern_latitude = southern_latitude; - this.northern_basin_id = northern_basin_id; - this.northern_basin_name = northern_basin_name; - this.northern_latitude = northern_latitude; - this.centroide_latitude = centroide_latitude; - } - - - @Override - public String toString() { - return "FishDistributionRecord [year=" + this.year + ", southern_basin_id=" + this.southern_basin_id - + ", southern_basin_name=" + this.southern_basin_name + ", southern_latitude=" + this.southern_latitude - + ", northern_basin_id=" + this.northern_basin_id + ", northern_basin_name=" + this.northern_basin_name - + ", northern_latitude=" + this.northern_latitude + ", centroide_latitude=" + this.centroide_latitude + "]"; - } - } + private transient List<FishDistributionRecord> records; - public static void main(String[] args) { - System.out.println((new XStream(new DomDriver())).toXML(new AnalyseFishDistribution())); - } + private transient double southernLimit; + private transient double northernLimit; @Override public void initTransientParameters(Pilot pilot) { @@ -126,76 +71,123 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis if (records == null) initTransientParameters(group.getPilot()); - Time time = group.getEnvironment().getTime(); - if (time.getSeason(group.getPilot()) == fishDistributionAnalysisSeason - & time.getYear(group.getPilot()) >= fishDistributionAnalysisStartYear - & time.getYear(group.getPilot()) <= fishDistributionAnalysisEndYear) { - - // initialise the distribution range - double southernEdge = northernLimit; - double northernEdge = southernLimit; - int southernId = -1; - int northernId = -1; - String southernName = ""; - String northernName = ""; - // initialise for centroid - TreeMapForCentile latitudeEffective = new TreeMapForCentile(); - for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { - - if (riverBasin.getLastRecruitments().getLastItem() > minimumRecruitsForPopulatedBasin) { - // the basin is considerd as populated - - // southern edge - if (riverBasin.getLatitude() < southernEdge) { - // the basin is the new southern edge - southernEdge = riverBasin.getLatitude(); - southernId = riverBasin.getBasin_id(); - southernName = riverBasin.getName(); - } - - // northern edge - if (riverBasin.getLatitude() > southernEdge) { - // the basin is the new northern edge - northernEdge = riverBasin.getLatitude(); - northernId = riverBasin.getBasin_id(); - northernName = riverBasin.getName(); - } - - // for distribution centroide computation - long effective = 0; - for (DiadromousFish fish : riverBasin.getFishs(group)) { - effective += fish.getAmount(); - } - latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective); + // initialise the distribution range + double southernEdge = northernLimit; + double northernEdge = southernLimit; + int southernId = -1; + int northernId = -1; + String southernName = ""; + String northernName = ""; + // initialise for centroid + TreeMapForCentile latitudeEffective = new TreeMapForCentile(); + TreeMapForCentile latitudePresence = new TreeMapForCentile(); + + for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { + + if (riverBasin.getLastRecruitments().getMean() > minimumRecruitsForPopulatedBasin) { + // the river basin is consdered populated + + // NOTE : recruiit number is calulated after thermal tolerance impact + // (which is intreaged in the stock-recruitment relationship) + + // southern edge + if (riverBasin.getLatitude() < southernEdge) { + // the basin is the new southern edge + southernEdge = riverBasin.getLatitude(); + southernId = riverBasin.getBasin_id(); + southernName = riverBasin.getName(); + } + + // northern edge + if (riverBasin.getLatitude() > southernEdge) { + // the basin is the new northern edge + northernEdge = riverBasin.getLatitude(); + northernId = riverBasin.getBasin_id(); + northernName = riverBasin.getName(); } - } - // if the universe is empty - if (southernEdge == northernLimit & northernEdge == southernLimit) { - southernEdge = (northernLimit + southernLimit) / 2.; - northernEdge = southernEdge; - } - // distribution centroide computation - double centroide = latitudeEffective.calculateMedian(); - // add a record - FishDistributionRecord record = new FishDistributionRecord(time.getYear(group.getPilot()), southernId, southernName, - southernEdge, northernId, northernName, northernEdge, centroide); - records.add(record); + // for distribution centroide computation + latitudePresence.putWithAdding(riverBasin.getLatitude(), 1L); + long effective = ((Double) riverBasin.getLastSpawnerNumbersBeforeReproduction().getMean()).longValue(); + latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective); + } + } + // if the universe is empty + if (southernEdge == northernLimit & northernEdge == southernLimit) { + southernEdge = (northernLimit + southernLimit) / 2.; + northernEdge = southernEdge; } + + // distribution centroids computation + double basinCentroid = latitudePresence.calculateMedian(); + double effectiveCentroid = latitudeEffective.calculateMedian(); + + // add a record + FishDistributionRecord record = new FishDistributionRecord(southernId, southernName, southernEdge, northernId, + northernName, northernEdge, basinCentroid, effectiveCentroid); + + records.add(record); } public double[][] exportToR() { - double[][] export = new double[records.size()][4]; - for (int i = 0; i < records.size(); i++) { - export[i][0] = records.get(i).year; - export[i][1] = records.get(i).southern_basin_id; - export[i][2] = records.get(i).northern_basin_id; - export[i][3] = records.get(i).centroide_latitude; + export[i][0] = records.get(i).southern_basin_id; + export[i][1] = records.get(i).northern_basin_id; + export[i][2] = records.get(i).basinCentroid_latitude; + export[i][3] = records.get(i).effectiveCentroid_latitude; } return export; + } + + private class FishDistributionRecord implements ObservableRecord { + + @Information(unit = "-") + private int southern_basin_id; + @Information(unit = "-") + private String southern_basin_name; + @Information(unit = "°") + private double southern_latitude; + + @Information(unit = "-") + private int northern_basin_id; + @Information(unit = "-") + private String northern_basin_name; + @Information(unit = "°") + private double northern_latitude; + + @Information(unit = "°") + private double basinCentroid_latitude; + @Information(unit = "°") + private double effectiveCentroid_latitude; + public FishDistributionRecord(int southern_basin_id, String southern_basin_name, double southern_latitude, + int northern_basin_id, String northern_basin_name, double northern_latitude, double basinCentroid_latitude, + double effectiveCentroid_latitude) { + super(); + this.southern_basin_id = southern_basin_id; + this.southern_basin_name = southern_basin_name; + this.southern_latitude = southern_latitude; + this.northern_basin_id = northern_basin_id; + this.northern_basin_name = northern_basin_name; + this.northern_latitude = northern_latitude; + this.basinCentroid_latitude = basinCentroid_latitude; + this.effectiveCentroid_latitude = effectiveCentroid_latitude; + } + + + @Override + public String toString() { + return "FishDistributionRecord [southern_basin_id=" + this.southern_basin_id + ", southern_basin_name=" + + this.southern_basin_name + ", southern_latitude=" + this.southern_latitude + ", northern_basin_id=" + + this.northern_basin_id + ", northern_basin_name=" + this.northern_basin_name + ", northern_latitude=" + + this.northern_latitude + ", basinCentroide_latitude=" + this.basinCentroid_latitude + + ", effectiveCentroide_latitude=" + this.effectiveCentroid_latitude + "]"; + } + } + + public static void main(String[] args) { + System.out.println((new XStream(new DomDriver())).toXML(new AnalyseFishDistribution())); } } diff --git a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java index a167a802a4deae780bf36362deacde9912b6e157..427ab7f411a1d9d0589ebe1abfc4cce37ece4d8a 100644 --- a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java +++ b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java @@ -1,7 +1,5 @@ package species; -import java.io.BufferedWriter; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; @@ -82,7 +80,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG private transient StockRecruitmentRelationship stockRecruitmentRelationship; // private transient UniformGen genUniform; - public static void main(String[] args) { System.out.println((new XStream(new DomDriver())).toXML(new ReproduceAndSurviveAfterReproductionWithDiagnose())); } @@ -128,7 +125,8 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { // before the party !!!! - double fluxBefore = riverBasin.getSpawnerNumber(); + double fluxBefore = riverBasin.getSpawnerNumberPerGroup(group); + riverBasin.getLastSpawnerNumbersBeforeReproduction().add(fluxBefore); double b, c, alpha, beta, amountPerSuperIndividual, S95, S50; double numberOfFemaleSpawners = 0.; @@ -520,16 +518,16 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG / riverBasin.getLastProdCapacities().getLastItem()); // keep the no null recruitment - if (numberOfAutochtones > 0) { - riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(1.); - riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(1.); - } else { - riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(0.); - riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(0.); - } + // if (numberOfAutochtones > 0) { + riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(1.); + riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(1.); + // } else { + // riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(0.); + // riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(0.); + // } } else { - // stock the last year of null recruitment + // stock the null recruitment of the last year riverBasin.setYearOfLastNulRep(time.getYear(group.getPilot())); riverBasin.getLastRecruitmentExpectations().push((long) 0); riverBasin.getLastRecruitments().push((long) 0); @@ -567,26 +565,18 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG * ";" + riverBasin.getSpawnerNumberPerGroup(group)+ "; " + totalInputFluxes); */ /* - BufferedWriter bW = group.getbWForFluxes(); - if (bW != null) { - try { - for (SpawnerOrigin origin : totalInputFluxes.keySet()) { - bW.write(group.getPilot().getCurrentTime() + "; " + time.getYear(group.getPilot()) + ";" - + time.getSeason(group.getPilot()) + ";" + riverBasin.getName() + ";" + fluxBefore + ";" - + "IMPORT" + ";" + origin); - bW.write(";" + totalInputFluxes.get(origin).get("biomass")); - - for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { - bW.write(";" + totalInputFluxes.get(origin).get(nutrient)); - } - bW.write("\n"); - } - } catch (IOException e) { + * BufferedWriter bW = group.getbWForFluxes(); if (bW != null) { try { for (SpawnerOrigin origin : + * totalInputFluxes.keySet()) { bW.write(group.getPilot().getCurrentTime() + "; " + + * time.getYear(group.getPilot()) + ";" + time.getSeason(group.getPilot()) + ";" + + * riverBasin.getName() + ";" + fluxBefore + ";" + "IMPORT" + ";" + origin); bW.write(";" + + * totalInputFluxes.get(origin).get("biomass")); + * + * for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { bW.write(";" + + * totalInputFluxes.get(origin).get(nutrient)); } bW.write("\n"); } } catch (IOException e) { + * + * e.printStackTrace(); } } + */ - e.printStackTrace(); - } - }*/ - } else { riverBasin.setYearOfLastNulRep(time.getYear(group.getPilot())); } @@ -657,7 +647,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG */ double sigmaZ; // - public void init(double alpha, double beta, double S50, double S95) { this.alpha = alpha; this.beta = beta; @@ -752,7 +741,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG // third: effective of corresponding recruitment List<Trio<Integer, Long, Long>> data; // WHY age as integer - public void init(List<Trio<Integer, Long, Long>> data) { this.data = data; }