Commit 5fbe2bd5 authored by patrick.lambert's avatar patrick.lambert
Browse files

attemps with an observerd in environment

ne semble pas marche
parent dbeedb58
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import environment.OffshoreBasin.OffshoreBasinFunction;
import fr.cemagref.observation.kernel.ObservablesHandler;
import fr.cemagref.simaqualife.kernel.AquaNismsGroup;
import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters;
import fr.cemagref.simaqualife.pilot.Pilot;
......@@ -31,11 +32,22 @@ public abstract class RIOBasinNetwork extends BasinNetwork {
protected transient Time time;
protected static transient ObservablesHandler cobservable;
public ObservablesHandler getCobservable() {
return cobservable;
}
@Override
@InitTransientParameters
public void initTransientParameters(Pilot pilot) {
time = new Time();
if (cobservable == null) {
cobservable = pilot.addObservable(this.getClass());
}
}
......
......@@ -11,10 +11,9 @@ import org.openide.util.lookup.ServiceProvider;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.RIOBasinNetwork;
import environment.RiverBasin;
import environment.InshoreBasin;
import environment.RIOBasinNetwork;
import environment.RiverBasin;
import environment.Time;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
......@@ -142,7 +141,7 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
for (InshoreBasin departure : group.getEnvironment().getSeaBasins()) {
RiverBasin homingDestination = (RiverBasin) bn.getAssociatedRiverBasin(departure);
RiverBasin homingDestination = bn.getAssociatedRiverBasin(departure);
List<DiadromousFish> fishes = departure.getFishs(group);
if (fishes != null) {
......@@ -249,9 +248,13 @@ public class DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin extends Di
}
}
System.out.println(" total abundance in river basins: " + group.getFishEffective());
System.out.println(
"female spawners: " + group.getFemaleSpawnerEffective() + " \tmale spawners: " + group.getMaleSpawnerEffective());
System.out.println("female spawners: " + group.getFemaleSpawnerEffective() + " \tmale spawners: "
+ group.getMaleSpawnerEffective());
// --------------------------------------------------------------------------------------------------
// update the observers
// ------------------------------------------------------------------------------------------------------
group.getEnvironment().getCobservable().fireChanges(group.getEnvironment(), pilot.getCurrentTime());
}
}
}
package species;
import java.util.List;
import java.util.ListIterator;
import org.openide.util.lookup.ServiceProvider;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.Basin;
import environment.OffshoreBasin;
import environment.RiverBasin;
import environment.Time;
import environment.OffshoreBasin.OffshoreBasinFunction;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import species.DiadromousFish.Stage;
import java.util.List;
import java.util.ListIterator;
import org.geotools.data.FeatureEvent.Type;
import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = AquaNismsGroupProcess.class)
public class MigrateBetweenOffshores extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
/**
* Season to migrate from summering to winteringOffshoreBasin
*/
private Season migrationSeasonToReachWinteringOffshore = Season.AUTOMN;
private Season migrationSeasonToReachWinteringOffshore = Season.AUTOMN;
/**
* Season to migrate from wintering to summeringOffshoreBasin
* Season to migrate from wintering to summeringOffshoreBasin
*/
private Season migrationSeasonToReachSummeringOffshore = Season.SPRING;
private Season migrationSeasonToReachSummeringOffshore = Season.SPRING;
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new MigrateBetweenOffshores()));
System.out.println((new XStream(new DomDriver())).toXML(new MigrateBetweenOffshores()));
}
@Override
public void doProcess(DiadromousFishGroup group) {
Basin destination = null;
Basin destination = null;
if (group.getEnvironment().getTime().getSeason(group.getPilot()) == migrationSeasonToReachWinteringOffshore) {
for (OffshoreBasin summeringOffshoreBasin : group.getEnvironment().getSummeringOffshoreBasins()) {
List<DiadromousFish> fishInSummeringOffshoreBasin = summeringOffshoreBasin.getFishs(group);
......@@ -56,7 +50,8 @@ public class MigrateBetweenOffshores extends AquaNismsGroupProcess<DiadromousFis
DiadromousFish fish = fishIterator.next();
//TODO find a more generic way to memorized a basin which differs from riverBasin (i.e. catadromous fish)
// TODO find a more generic way to memorized a basin which differs from riverBasin (i.e.
// catadromous fish)
destination = ((RiverBasin) fish.getMemorisedBasin()).getConnectedWinteringOffshoreBasin();
fish.setPosition(destination);
......@@ -66,8 +61,12 @@ public class MigrateBetweenOffshores extends AquaNismsGroupProcess<DiadromousFis
}
}
}
}
else if (group.getEnvironment().getTime().getSeason(group.getPilot()) == migrationSeasonToReachSummeringOffshore) {
// --------------------------------------------------------------------------------------------------
// update the observers
// ------------------------------------------------------------------------------------------------------
group.getEnvironment().getCobservable().fireChanges(group.getEnvironment(), pilot.getCurrentTime());
} else if (group.getEnvironment().getTime().getSeason(group.getPilot()) == migrationSeasonToReachSummeringOffshore) {
for (OffshoreBasin winteringOffshoreBasin : group.getEnvironment().getWinteringOffshoreBasins()) {
......@@ -79,7 +78,8 @@ public class MigrateBetweenOffshores extends AquaNismsGroupProcess<DiadromousFis
DiadromousFish fish = fishIterator.next();
//TODO find a more generic way to memorized a basin which differs from riverBasin (i.e. catadromous fish)
// TODO find a more generic way to memorized a basin which differs from riverBasin (i.e.
// catadromous fish)
destination = ((RiverBasin) fish.getMemorisedBasin()).getConnectedSummeringOffshoreBasin();
// add fish with its new position to destination basin
......@@ -90,6 +90,10 @@ public class MigrateBetweenOffshores extends AquaNismsGroupProcess<DiadromousFis
}
}
}
// --------------------------------------------------------------------------------------------------
// update the observers
// ------------------------------------------------------------------------------------------------------
group.getEnvironment().getCobservable().fireChanges(group.getEnvironment(), pilot.getCurrentTime());
}
}
}
\ No newline at end of file
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