Commit 093f66ba authored by Lambert Patrick's avatar Lambert Patrick
Browse files

typing correction

parent e2596ee1
package environment; package environment;
import fr.cemagref.simaqualife.kernel.AquaNismsGroup;
import fr.cemagref.simaqualife.kernel.spatial.Environment;
import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters;
import fr.cemagref.simaqualife.pilot.Pilot;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import fr.cemagref.simaqualife.kernel.AquaNismsGroup;
import fr.cemagref.simaqualife.kernel.spatial.Environment;
import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters;
import fr.cemagref.simaqualife.pilot.Pilot;
import species.DiadromousFish; import species.DiadromousFish;
public abstract class BasinNetwork extends Environment<Basin, DiadromousFish> { public abstract class BasinNetwork extends Environment<Basin, DiadromousFish> {
protected int nbBasin; protected int nbBasin;
protected int memorySize; // size of all the queues protected int memorySize; // size of all the queues
protected int memorySizeLongQueue; // size of all longer queues protected int memorySizeLongQueue; // size of all longer queues
protected double cVthresholdForFinalStates = 5.; protected double cVthresholdForFinalStates = 5.;
protected double RecruitmentThresholdForFsAndKappa = 50.; protected double RecruitmentThresholdForFsAndKappa = 50.;
protected long yearOfTheBegin = 1800; protected long yearOfTheBegin = 1800;
protected transient Basin[] grid; protected transient Basin[] grid;
protected transient double[][] distanceGrid; protected transient double[][] distanceGrid;
protected transient Time time; protected transient Time time;
@InitTransientParameters
public void initTransientParameters(Pilot pilot) { @InitTransientParameters
time = new Time(); public void initTransientParameters(Pilot pilot) {
} time = new Time();
}
public int getRow(int id) {
return (id % nbBasin); public int getRow(int id) {
} return (id % nbBasin);
}
public int getColumn(int id) {
return ((id - (id % nbBasin)) / nbBasin);
} public int getColumn(int id) {
return ((id - (id % nbBasin)) / nbBasin);
public int getId(int i, int j) { }
return (j * nbBasin + i);
}
public int getId(int i, int j) {
public Basin getAssociatedRiverBasin(Basin basin) { return (j * nbBasin + i);
int i = getRow(basin.getId()); }
return (grid[getId(i, 0)]);
}
public Basin getAssociatedRiverBasin(Basin basin) {
public Basin getAssociatedSeaBasin(Basin basin) { int i = getRow(basin.getId());
int i = getRow(basin.getId()); return (grid[getId(i, 0)]);
return (grid[getId(i, 1)]); }
}
public Basin getAssociatedOffshoreBasin(Basin basin) { public Basin getAssociatedSeaBasin(Basin basin) {
int i = getRow(basin.getId()); int i = getRow(basin.getId());
return (grid[getId(i, 2)]); return (grid[getId(i, 1)]);
} }
@Override
public List<Basin> getNeighbours(Basin basin) { public Basin getAssociatedOffshoreBasin(Basin basin) {
int j = getColumn(basin.getId()); int i = getRow(basin.getId());
if (j == 0) //that means for a river basin return (grid[getId(i, 2)]);
{ }
return null;
} else {
List<Basin> neighbours = new ArrayList<Basin>(nbBasin - 1); @Override
int i = getRow(basin.getId()); public List<Basin> getNeighbours(Basin basin) {
int j = getColumn(basin.getId());
for (int k = 0; k < nbBasin; k++) { if (j == 0) // that means for a river basin
if (k != i) { {
neighbours.add(grid[getId(k, j)]); return null;
} } else {
} List<Basin> neighbours = new ArrayList<Basin>(nbBasin - 1);
return neighbours; int i = getRow(basin.getId());
}
} for (int k = 0; k < nbBasin; k++) {
if (k != i) {
public Map<Basin, Double> getNeighboursWithDistance(Basin basin) { neighbours.add(grid[getId(k, j)]);
int j = getColumn(basin.getId()); }
if (j == 0) //that means for a river basin }
{ return neighbours;
return null; }
} else { }
Map<Basin, Double> neighbours = new TreeMap<Basin, Double>();
int i = getRow(basin.getId());
public Map<Basin, Double> getNeighboursWithDistance(Basin basin) {
for (int k = 0; k < nbBasin; k++) { int j = getColumn(basin.getId());
if (k != i) { if (j == 0) // that means for a river basin
neighbours.put(grid[getId(k, j)], {
distanceGrid[i][k]); return null;
} } else {
} Map<Basin, Double> neighbours = new TreeMap<Basin, Double>();
return neighbours; int i = getRow(basin.getId());
}
} for (int k = 0; k < nbBasin; k++) {
if (k != i) {
public int getNbBasin() { neighbours.put(grid[getId(k, j)], distanceGrid[i][k]);
return nbBasin; }
} }
return neighbours;
public Basin[] getBasins() { }
return grid; }
}
public RiverBasin[] getRiverBasins() { public int getNbBasin() {
RiverBasin[] riverGrid = new RiverBasin[nbBasin]; return nbBasin;
}
for (int i = 0; i < nbBasin; i++) {
riverGrid[i] = (RiverBasin) grid[i];
} public Basin[] getBasins() {
return grid;
return riverGrid; }
}
public SeaBasin[] getSeaBasins() { public RiverBasin getRiverBasin(String basinName) {
SeaBasin[] seaGrid = new SeaBasin[nbBasin]; RiverBasin basin = null;
for (int i = 0; i < nbBasin; i++) {
for (int i = 0; i < nbBasin; i++) { basin = (RiverBasin) grid[i];
seaGrid[i] = (SeaBasin) grid[nbBasin + i]; if (basin.getName().equals(basinName))
} break;
}
return seaGrid; return basin;
} }
public String[] getRiverBasinNames() {
RiverBasin[] riverBasins = getRiverBasins(); public SeaBasin getSeaBasin(String riverBasinName) {
String[] names = new String[riverBasins.length]; RiverBasin riverBasin = null;
for (int i = 0; i < riverBasins.length; i++) { SeaBasin seaBasin = null;
names[i] = riverBasins[i].getName(); for (int i = 0; i < nbBasin; i++) {
} riverBasin = (RiverBasin) grid[i];
return names; if (riverBasin.getName().equals(riverBasinName)) {
} seaBasin = (SeaBasin) grid[nbBasin + i];
break;
public int[] getFinalStates() { }
// TODO ask to Nicolas to be able to use ReflectUtils with arguments }
return seaBasin;
RiverBasin[] riverBasins = getRiverBasins(); }
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i]; public RiverBasin[] getRiverBasins() {
double roundedCV = Math.round(riverBasin.getLastRecruitments().getCoefficientVariation() * 10000.) / 100.; RiverBasin[] riverGrid = new RiverBasin[nbBasin];
if (roundedCV == 0.) {
finalStates[i] = 0; for (int i = 0; i < nbBasin; i++) {
} else if (roundedCV < this.cVthresholdForFinalStates) { riverGrid[i] = (RiverBasin) grid[i];
finalStates[i] = 2; }
} else {
finalStates[i] = 1; return riverGrid;
} }
}
return finalStates;
} public SeaBasin[] getSeaBasins() {
SeaBasin[] seaGrid = new SeaBasin[nbBasin];
public int[] getFinalStatesWithStochasticity() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments for (int i = 0; i < nbBasin; i++) {
seaGrid[i] = (SeaBasin) grid[nbBasin + i];
RiverBasin[] riverBasins = getRiverBasins(); }
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) { return seaGrid;
RiverBasin riverBasin = riverBasins[i]; }
double roundedCV = Math.round(riverBasin.getLastRecruitmentExpectations().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0; public String[] getRiverBasinNames() {
} else if (roundedCV < this.cVthresholdForFinalStates) { RiverBasin[] riverBasins = getRiverBasins();
finalStates[i] = 2; String[] names = new String[riverBasins.length];
} else { for (int i = 0; i < riverBasins.length; i++) {
finalStates[i] = 1; names[i] = riverBasins[i].getName();
} }
} return names;
return finalStates; }
}
public int[] getFinalStatesForKappa() { public int[] getFinalStates() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments // TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins(); RiverBasin[] riverBasins = getRiverBasins();
int[] finalStatesForKappa = new int[riverBasins.length]; int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) { for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i]; RiverBasin riverBasin = riverBasins[i];
if (riverBasin.getLastRecruitments().getMean() <= RecruitmentThresholdForFsAndKappa) { double roundedCV = Math.round(riverBasin.getLastRecruitments().getCoefficientVariation() * 10000.) / 100.;
finalStatesForKappa[i] = 0; if (roundedCV == 0.) {
} else { finalStates[i] = 0;
finalStatesForKappa[i] = 1; } else if (roundedCV < this.cVthresholdForFinalStates) {
} finalStates[i] = 2;
} } else {
return finalStatesForKappa; finalStates[i] = 1;
} }
}
public double[] getMeanLastRecruitments() { return finalStates;
RiverBasin[] riverBasins = getRiverBasins(); }
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastRecruitments().getMean(); public int[] getFinalStatesWithStochasticity() {
} // TODO ask to Nicolas to be able to use ReflectUtils with arguments
return data;
} RiverBasin[] riverBasins = getRiverBasins();
int[] finalStates = new int[riverBasins.length];
public double[] getProbOfNonNulRecruitmentDuringLastYears(){ for (int i = 0; i < riverBasins.length; i++) {
RiverBasin[] riverBasins = getRiverBasins(); RiverBasin riverBasin = riverBasins[i];
double[] data = new double[riverBasins.length]; double roundedCV = Math.round(riverBasin.getLastRecruitmentExpectations().getCoefficientVariation() * 10000.) / 100.;
for (int i = 0; i < riverBasins.length; i++) { if (roundedCV == 0.) {
if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0){ finalStates[i] = 0;
data[i] = 0.001; } else if (roundedCV < this.cVthresholdForFinalStates) {
}else if(riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size()-1)){ finalStates[i] = 2;
data[i] = 0.999; } else {
}else{ finalStates[i] = 1;
data[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() / (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size()); }
} }
} return finalStates;
return data; }
}
public double[] getFinalProbabilityOfPresence(){ // function computed for obtain probability of presence in 2100 for the allis shad case study public int[] getFinalStatesForKappa() {
RiverBasin[] riverBasins = getRiverBasins(); // TODO ask to Nicolas to be able to use ReflectUtils with arguments
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) { RiverBasin[] riverBasins = getRiverBasins();
data[i] = riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().getSum() / riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().size(); int[] finalStatesForKappa = new int[riverBasins.length];
} for (int i = 0; i < riverBasins.length; i++) {
return data; RiverBasin riverBasin = riverBasins[i];
} if (riverBasin.getLastRecruitments().getMean() <= RecruitmentThresholdForFsAndKappa) {
finalStatesForKappa[i] = 0;
public double getMeanLastRecruitmentsBV2() { } else {
RiverBasin[] riverBasins = getRiverBasins(); finalStatesForKappa[i] = 1;
double data = riverBasins[1].getLastRecruitments().getMean(); }
return data; }
} return finalStatesForKappa;
}
public double[] getMeanLastRecruitmentExpectations() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length]; public double[] getMeanLastRecruitments() {
for (int i = 0; i < riverBasins.length; i++) { RiverBasin[] riverBasins = getRiverBasins();
data[i] = riverBasins[i].getLastRecruitmentExpectations().getMean(); double[] data = new double[riverBasins.length];
} for (int i = 0; i < riverBasins.length; i++) {
return data; data[i] = riverBasins[i].getLastRecruitments().getMean();
} }
return data;
public double[] getGeoMeansLastRecsOverProdCaps() { }
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins(); public double[] getProbOfNonNulRecruitmentDuringLastYears() {
double [] geoMeans = new double [riverBasins.length]; RiverBasin[] riverBasins = getRiverBasins();
for (int i = 0; i < riverBasins.length; i++) { double[] data = new double[riverBasins.length];
geoMeans[i] = riverBasins[i].getLastRecsOverProdCaps().getGeometricMean(); for (int i = 0; i < riverBasins.length; i++) {
} if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0) {
return geoMeans; data[i] = 0.001;
} } else if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears()
.getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size() - 1)) {
public double[] getMeanLastPercOfAut() { // give the mean of the last % of autochtone spawners data[i] = 0.999;
RiverBasin[] riverBasins = getRiverBasins(); } else {
double[] data = new double[riverBasins.length]; data[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum()
for (int i = 0; i < riverBasins.length; i++) { / (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size());
data[i] = riverBasins[i].getLastPercentagesOfAutochtones().getMean(); }
} }
return data; return data;
} }
public long[] getYearsOfFirstNonNulRep() {
RiverBasin[] riverBasins = getRiverBasins(); public double[] getFinalProbabilityOfPresence() { // function computed for obtain probability of presence in 2100
long[] data = new long[riverBasins.length]; // for the allis shad case study
for (int i = 0; i < riverBasins.length; i++) { RiverBasin[] riverBasins = getRiverBasins();
data[i] = riverBasins[i].getYearOfFirstNonNulRep(); double[] data = new double[riverBasins.length];
} for (int i = 0; i < riverBasins.length; i++) {
return data; data[i] = riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().getSum()
} / riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().size();
}
public long[] getYearsOfLastNulRep() { return data;
RiverBasin[] riverBasins = getRiverBasins(); }
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfLastNulRep(); public double getMeanLastRecruitmentsBV2() {
} RiverBasin[] riverBasins = getRiverBasins();
return data; double data = riverBasins[1].getLastRecruitments().getMean();
} return data;
}
/**
public double[] getMeanLastRecruitmentExpectations() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastRecruitmentExpectations().getMean();
}
return data;
}
public double[] getGeoMeansLastRecsOverProdCaps() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
double[] geoMeans = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
geoMeans[i] = riverBasins[i].getLastRecsOverProdCaps().getGeometricMean();
}
return geoMeans;
}
public double[] getMeanLastPercOfAut() { // give the mean of the last % of autochtone spawners
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastPercentagesOfAutochtones().getMean();
}
return data;
}
public long[] getYearsOfFirstNonNulRep() {
RiverBasin[] riverBasins = getRiverBasins();
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfFirstNonNulRep();
}
return data;
}
public long[] getYearsOfLastNulRep() {
RiverBasin[] riverBasins = getRiverBasins();
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfLastNulRep();
}
return data;
}
/**
* @return the yearOfTheBegin * @return the yearOfTheBegin
*/ */
public long getYearOfTheBegin() { public long getYearOfTheBegin() {
return yearOfTheBegin; return yearOfTheBegin;
} }
@Override
public void addAquaNism(DiadromousFish fish, AquaNismsGroup group) {
// TODO Auto-generated method stub
}
@Override
public void moveAquaNism(DiadromousFish fish, AquaNismsGroup group, Basin destination) {
// TODO Auto-generated method stub
}
@Override @Override
public void addAquaNism(DiadromousFish fish, AquaNismsGroup group) { public void removeAquaNism(DiadromousFish fish, AquaNismsGroup group) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public void moveAquaNism(DiadromousFish fish, AquaNismsGroup group,
Basin destination) {