Commit 716702b0 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

remoce basinDistancesPerBasin frpm DisperseAndMigrateToRiverBasic

the information is assessible through  getNeighboursDistances()
parent 9eba6e7a
package species;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.openide.util.lookup.ServiceProvider;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.Basin;
import environment.BasinNetwork;
import environment.RiverBasin;
import environment.Time;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import miscellaneous.BinomialForSuperIndividualGen;
import miscellaneous.Miscellaneous;
import org.openide.util.lookup.ServiceProvider;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
@ServiceProvider(service = AquaNismsGroupProcess.class)
public class DisperseAndMigrateToRiver extends DisperseAndMigrateToRiverBasic {
private double pHoming=0.5;
private double pHoming = 0.5;
private Season riverMigrationSeason = Season.SPRING;
private double alpha2Rep = 0.;
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new DisperseAndMigrateToRiver()));
System.out.println((new XStream(new DomDriver())).toXML(new DisperseAndMigrateToRiver()));
}
//TODO need to be corrected to remove fish remove
// TODO need to be corrected to remove fish remove
@Override
public void doProcess(DiadromousFishGroup group) {
if (group.getEnvironment().getTime().getSeason(group.getPilot()) == riverMigrationSeason ){
if (group.getEnvironment().getTime().getSeason(group.getPilot()) == riverMigrationSeason) {
BasinNetwork bn = group.getEnvironment();
double dMaxDispFish = 0.;
long amountWithHoming, strayedAmount;
Map<RiverBasin, Double> distBasOfFish;
Map<Basin, Double> distBasOfFish;
List<DiadromousFish> deadFish = new ArrayList<DiadromousFish>();
List<DiadromousFish> newFish = new ArrayList<DiadromousFish>();
for (DiadromousFish fish : group.getAquaNismsList() ) {
if (fish.isMature()) {
for (DiadromousFish fish : group.getAquaNismsList()) {
if (fish.isMature()) {
// fish with homing
amountWithHoming = BinomialForSuperIndividualGen.getSuccessNumber(group.getPilot(), fish.getAmount(), pHoming); // seuil par d�faut fix� � 50
amountWithHoming = BinomialForSuperIndividualGen.getSuccessNumber(group.getPilot(), fish.getAmount(),
pHoming); // seuil par d�faut fix� � 50
// strayed fish
strayedAmount = fish.getAmount() - amountWithHoming;
// strayed fish
strayedAmount = fish.getAmount() - amountWithHoming;
if (strayedAmount != 0) {
// On r�cup�re les info du poids des bassin par rapport � la position du poisson
Map<Basin,Double> accBasOfFish= new TreeMap<Basin, Double>(basinWeightsPerBasin.get(fish.getPosition()));
//accBasOfFish = accessibleBasinsPerBasin.get(fish.getPosition());
Map<Basin, Double> accBasOfFish = new TreeMap<Basin, Double>(
basinWeightsPerBasin.get(fish.getPosition()));
// accBasOfFish = accessibleBasinsPerBasin.get(fish.getPosition());
// On retire certains bassins si on consid�re une distance max de dispersion
distBasOfFish = basinDistancesPerBasin.get(fish.getPosition());
if (group.getdMaxDisp() != 0){
distBasOfFish = fish.getPosition().getNeighboursDistances();
if (group.getdMaxDisp() != 0) {
// TODO pourquoi distbasoffish peut �tre nul ?
if (distBasOfFish != null){
dMaxDispFish = (group.getdMaxDisp()/group.getLinfVonBert(fish))*fish.getLength();
if (distBasOfFish != null) {
dMaxDispFish = (group.getdMaxDisp() / group.getLinfVonBert(fish)) * fish.getLength();
// load accessible basins
for (Basin surroundingBasin : distBasOfFish.keySet()){
for (Basin surroundingBasin : distBasOfFish.keySet()) {
Double distance = distBasOfFish.get(surroundingBasin);
//System.out.println("pour le poisson " + fish.hashCode() + " situ� dans le bassin " + basin.getName() + " et n� dans le bassin " + fish.getBirthBasin().getName());
//System.out.println("la distance vaut " + distance + " pour le bassin " + surroundingBasin.getName());
// System.out.println("pour le poisson " + fish.hashCode() + " situ� dans le bassin
// " + basin.getName() + " et n� dans le bassin " + fish.getBirthBasin().getName());
// System.out.println("la distance vaut " + distance + " pour le bassin " +
// surroundingBasin.getName());
if (distance >= dMaxDispFish) {
accBasOfFish.remove(surroundingBasin);
}
}
}
}
}
// We fill the weight table
double totalWeight = 0.;
double probToGo = 0.;
long amountToGo = 0;
// TODO Qu'est ce qui se passe si AccBasOfFish est vide... �a beug pas mais c'est pas tr�s clair... donc � v�rifier
for (Basin accBasin : accBasOfFish.keySet()){
// TODO Qu'est ce qui se passe si AccBasOfFish est vide... �a beug pas mais c'est pas tr�s
// clair... donc � v�rifier
for (Basin accBasin : accBasOfFish.keySet()) {
double accBasinWeightLogit = accBasOfFish.get(accBasin) + alpha2Rep * fish.getLength();
double accBasinWeight = 1 / (1 + Math.exp(- accBasinWeightLogit));
double accBasinWeight = 1 / (1 + Math.exp(-accBasinWeightLogit));
accBasOfFish.put(accBasin, accBasinWeight);
totalWeight += accBasinWeight;
}
// compute sequentially the prob to go into a basin
for (Basin accBasin : accBasOfFish.keySet()){
// compute sequentially the prob to go into a basin
for (Basin accBasin : accBasOfFish.keySet()) {
probToGo = accBasOfFish.get(accBasin) / totalWeight;
amountToGo = BinomialForSuperIndividualGen.getSuccessNumber(group.getPilot(), strayedAmount, probToGo);
amountToGo = BinomialForSuperIndividualGen.getSuccessNumber(group.getPilot(), strayedAmount,
probToGo);
if (amountToGo > 0){
newFish.add(fish.duplicateWithNewPositionAndAmount(group.getPilot(), bn.getAssociatedRiverBasin(accBasin), amountToGo));
if (amountToGo > 0) {
newFish.add(fish.duplicateWithNewPositionAndAmount(group.getPilot(),
bn.getAssociatedRiverBasin(accBasin), amountToGo));
}
totalWeight -= accBasOfFish.get(accBasin);
strayedAmount -= amountToGo;
strayedAmount -= amountToGo;
}
}
// update fish with homing
if (amountWithHoming > 0){
if (amountWithHoming > 0) {
fish.setAmount(amountWithHoming);
// 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
fish.moveTo(group.getPilot(), bn.getAssociatedRiverBasin(fish.getPosition()), group);
} else {
......@@ -116,11 +120,11 @@ public class DisperseAndMigrateToRiver extends DisperseAndMigrateToRiverBasic {
}
}
}
for (DiadromousFish fish : deadFish){
for (DiadromousFish fish : deadFish) {
group.removeAquaNism(fish);
}
for (DiadromousFish fish : newFish){
for (DiadromousFish fish : newFish) {
group.addAquaNism(fish);
}
}
......
......@@ -86,40 +86,41 @@ public class DisperseAndMigrateToRiverBasic extends AquaNismsGroupProcess<Diadro
*/
protected transient Map<SeaBasin, Map<RiverBasin, Double>> basinWeightsPerBasin;
/**
* a map associtaing a sea bassin with the distance for each river bassin <key> SeaBasin <value> <key> RiverBasin
* <value> distance between the river Basin and the river basin associated with the sea basin
*/
@Deprecated
protected transient Map<SeaBasin, Map<RiverBasin, Double>> basinDistancesPerBasin;
// @Deprecated
// protected transient Map<SeaBasin, Map<RiverBasin, Double>> basinDistancesPerBasin;
@Override
@InitTransientParameters
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
// calcul les poids des bassins voisins qui ne d�pendent pas des poissons pour chaque SeaBassin
BasinNetwork bn = (BasinNetwork) pilot.getAquaticWorld().getEnvironment();
basinDistancesPerBasin = new TreeMap<SeaBasin, Map<RiverBasin, Double>>();
// calcul les poids des bassins voisins qui ne d�pendent pas des poissons pour chaque SeaBassin
basinWeightsPerBasin = new TreeMap<SeaBasin, Map<RiverBasin, Double>>();
// Compute the weight of each river basin
for (SeaBasin seaBas : bn.getSeaBasins()) {
// compute the distance with between seaBas and all the river basins
Map<RiverBasin, Double> mapDist = new TreeMap<RiverBasin, Double>();
// Compute the weight of each river basin
Map<RiverBasin, Double> mapWeight = new TreeMap<RiverBasin, Double>();
RiverBasin associatedRiverBasin;
for (Entry<Basin, Double> entry : bn.getNeighboursWithDistance(seaBas).entrySet()) {
RiverBasin associatedRiverBasin = (RiverBasin) bn.getAssociatedRiverBasin(entry.getKey());
mapDist.put(associatedRiverBasin, entry.getValue());
for (Entry<Basin, Double> entry : seaBas.getNeighboursDistances().entrySet()) {
associatedRiverBasin = (environment.RiverBasin) entry.getKey();
// RiverBasin associatedRiverBasin = (RiverBasin) bn.getAssociatedRiverBasin(entry.getKey());
double weight = alpha0Rep - alpha1Rep * ((entry.getValue() - meanInterDistance) / standardDeviationInterDistance)
+ alpha3Rep
* ((associatedRiverBasin.getAttractiveSurface() - meanBvSurface) / standardDeviationBvSurface);
mapWeight.put(associatedRiverBasin, weight);
}
basinDistancesPerBasin.put(seaBas, mapDist);
basinWeightsPerBasin.put(seaBas, mapWeight);
}
}
......
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