Isis-fish-data-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
December 2007
- 2 participants
- 8 discussions
Author: bpoussin
Date: 2007-12-21 17:11:11 +0000 (Fri, 21 Dec 2007)
New Revision: 13
Modified:
trunk/simulators/DefaultSimulator.java
Log:
on ne cree pas le resultat non activity s'il n'y a pas de strategie
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2007-12-18 20:22:27 UTC (rev 12)
+++ trunk/simulators/DefaultSimulator.java 2007-12-21 17:11:11 UTC (rev 13)
@@ -141,12 +141,15 @@
populationMonitor.clearCatch();
}
- if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
- MatrixND mat = metierMonitor.getOrCreateNoActivity(date,
+ // only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+ if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
+ MatrixND mat = metierMonitor.getOrCreateNoActivity(date,
ResultName.MATRIX_NO_ACTIVITY,
siMatrix.getStrategies(date),
siMatrix.getMetiers(date));
- resManager.addResult(date, mat);
+ resManager.addResult(date, mat);
+ }
}
//
1
0
Author: bpoussin
Date: 2007-12-18 20:22:27 +0000 (Tue, 18 Dec 2007)
New Revision: 12
Modified:
trunk/scripts/SiMatrix.java
Log:
ajout du throws exception, necessaire pour que ca compile
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2007-12-18 20:17:04 UTC (rev 11)
+++ trunk/scripts/SiMatrix.java 2007-12-18 20:22:27 UTC (rev 12)
@@ -86,7 +86,7 @@
* @param context context simulation
* @return SiMatrix or null if no SiMatrix created for simulation
*/
- public static SiMatrix getSiMatrix(SimulationContext context) {
+ public static SiMatrix getSiMatrix(SimulationContext context) throws TopiaException {
SiMatrix result = (SiMatrix)context.getValue(SiMatrix.class.getName());
if (result == null) {
result = new SiMatrix(context);
1
0
Author: bpoussin
Date: 2007-12-18 20:17:04 +0000 (Tue, 18 Dec 2007)
New Revision: 11
Modified:
trunk/scripts/SiMatrix.java
Log:
Correction erreur de recuperation de SiMatrix null
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2007-12-13 10:46:20 UTC (rev 10)
+++ trunk/scripts/SiMatrix.java 2007-12-18 20:17:04 UTC (rev 11)
@@ -88,6 +88,9 @@
*/
public static SiMatrix getSiMatrix(SimulationContext context) {
SiMatrix result = (SiMatrix)context.getValue(SiMatrix.class.getName());
+ if (result == null) {
+ result = new SiMatrix(context);
+ }
return result;
}
1
0
Author: tchemit
Date: 2007-12-12 15:36:52 +0000 (Wed, 12 Dec 2007)
New Revision: 7
Added:
tags/
Log:
ajout repertoire pour versions futures
1
0
Author: tchemit
Date: 2007-12-12 15:35:12 +0000 (Wed, 12 Dec 2007)
New Revision: 6
Removed:
branches/
Log:
suppression des branches comme demand?\195?\169
1
0
Author: bpoussin
Date: 2007-12-07 19:56:32 +0000 (Fri, 07 Dec 2007)
New Revision: 5
Modified:
trunk/simulators/DefaultSimulator.java
Log:
modification pour la nouvelle gestion des resultats
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2007-12-06 17:51:13 UTC (rev 4)
+++ trunk/simulators/DefaultSimulator.java 2007-12-07 19:56:32 UTC (rev 5)
@@ -57,6 +57,7 @@
import fr.ifremer.isisfish.rule.Rule;
import fr.ifremer.isisfish.simulator.MetierMonitor;
import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.ResultManager;
import fr.ifremer.isisfish.simulator.RuleMonitor;
import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.simulator.SimulationControl;
@@ -87,10 +88,10 @@
Date date = control.getDate();
control.setProgressMax(lastDate);
- ResultStorage resManager = context.getSimulationStorage().getResultStorage();
+ ResultManager resManager = context.getResultManager();
TopiaContext db = context.getDB();
- SiMatrix siMatrix = new SiMatrix(context);
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
GravityModel gravityModel = new GravityModel(context, siMatrix);
PopulationMonitor populationMonitor = context.getPopulationMonitor();
@@ -434,7 +435,7 @@
* @throws IsisFishException
* @throws TopiaException
*/
- private void saveGravityModel(Date date, ResultStorage resManager, GravityModel gravityModel) throws IsisFishException, TopiaException {
+ private void saveGravityModel(Date date, ResultManager resManager, GravityModel gravityModel) throws IsisFishException, TopiaException {
if (resManager.isEnabled(ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL)) {
MatrixND mat = gravityModel.matrixFishingTimePerMonthPerVessel(date);
resManager.addResult(date, mat);
1
0
Author: bpoussin
Date: 2007-12-06 17:51:13 +0000 (Thu, 06 Dec 2007)
New Revision: 4
Modified:
branches/3.1.0/analyseplans/Max.java
Log:
test de commit via isis
Modified: branches/3.1.0/analyseplans/Max.java
===================================================================
--- branches/3.1.0/analyseplans/Max.java 2007-12-05 14:40:21 UTC (rev 3)
+++ branches/3.1.0/analyseplans/Max.java 2007-12-06 17:51:13 UTC (rev 4)
@@ -38,7 +38,6 @@
public int param_max = 10;
-
public String [] necessaryResult = {
// put here all necessary result for this rule
// example:
1
0
r1 - / branches branches/3.1.0 branches/3.1.0/analyseplans branches/3.1.0/exports branches/3.1.0/formules branches/3.1.0/regions branches/3.1.0/regions/DemoRegion branches/3.1.0/rules branches/3.1.0/scripts branches/3.1.0/simulators trunk trunk/3.1.0 trunk/3.1.0/analyseplans trunk/3.1.0/exports trunk/3.1.0/formules trunk/3.1.0/regions trunk/3.1.0/regions/DemoRegion trunk/3.1.0/rules trunk/3.1.0/scripts trunk/3.1.0/simulators
by tchemit@users.labs.libre-entreprise.org 04 Dec '07
by tchemit@users.labs.libre-entreprise.org 04 Dec '07
04 Dec '07
Author: tchemit
Date: 2007-12-04 22:35:33 +0000 (Tue, 04 Dec 2007)
New Revision: 1
Added:
branches/
branches/3.1.0/
branches/3.1.0/analyseplans/
branches/3.1.0/analyseplans/Calibration.java
branches/3.1.0/analyseplans/Max.java
branches/3.1.0/exports/
branches/3.1.0/exports/Abundances.java
branches/3.1.0/exports/Biomasses.java
branches/3.1.0/exports/CapturesNombre.java
branches/3.1.0/exports/CapturesPoids.java
branches/3.1.0/exports/CellsDefinition.java
branches/3.1.0/exports/EffortsMetier.java
branches/3.1.0/exports/MetierZone.java
branches/3.1.0/exports/NonActivite.java
branches/3.1.0/exports/OwnerMargin.java
branches/3.1.0/exports/RegionDefinition.java
branches/3.1.0/exports/RejetsNombre.java
branches/3.1.0/exports/RejetsPoids.java
branches/3.1.0/exports/VesselMargin.java
branches/3.1.0/exports/ZonesDefinition.java
branches/3.1.0/formules/
branches/3.1.0/formules/Emigration/
branches/3.1.0/formules/Growth/
branches/3.1.0/formules/GrowthReverse/
branches/3.1.0/formules/Immigration/
branches/3.1.0/formules/Migration/
branches/3.1.0/formules/Reproduction/
branches/3.1.0/pom.xml
branches/3.1.0/profiles.xml
branches/3.1.0/regions/
branches/3.1.0/regions/DemoRegion/
branches/3.1.0/regions/DemoRegion/data-backup.sql.gz
branches/3.1.0/rules/
branches/3.1.0/rules/Cantonnement.java
branches/3.1.0/rules/CantonnementPreSimu.java
branches/3.1.0/rules/ChangementParamControlablePresimu.java
branches/3.1.0/rules/GraviteCPUE.java
branches/3.1.0/rules/InterdictionEngin.java
branches/3.1.0/rules/InterdictionEnginPreSimu.java
branches/3.1.0/rules/RecrutementLangoustine.java
branches/3.1.0/rules/TACpoids.java
branches/3.1.0/rules/TailleMin.java
branches/3.1.0/scripts/
branches/3.1.0/scripts/GravityModel.java
branches/3.1.0/scripts/ResultName.java
branches/3.1.0/scripts/RuleUtil.java
branches/3.1.0/scripts/SiMatrix.java
branches/3.1.0/simulations/
branches/3.1.0/simulators/
branches/3.1.0/simulators/DefaultSimulator.java
trunk/
trunk/3.1.0/
trunk/3.1.0/analyseplans/
trunk/3.1.0/analyseplans/Calibration.java
trunk/3.1.0/analyseplans/Max.java
trunk/3.1.0/exports/
trunk/3.1.0/exports/Abundances.java
trunk/3.1.0/exports/Biomasses.java
trunk/3.1.0/exports/CapturesNombre.java
trunk/3.1.0/exports/CapturesPoids.java
trunk/3.1.0/exports/CellsDefinition.java
trunk/3.1.0/exports/EffortsMetier.java
trunk/3.1.0/exports/MetierZone.java
trunk/3.1.0/exports/NonActivite.java
trunk/3.1.0/exports/OwnerMargin.java
trunk/3.1.0/exports/RegionDefinition.java
trunk/3.1.0/exports/RejetsNombre.java
trunk/3.1.0/exports/RejetsPoids.java
trunk/3.1.0/exports/VesselMargin.java
trunk/3.1.0/exports/ZonesDefinition.java
trunk/3.1.0/formules/
trunk/3.1.0/formules/Emigration/
trunk/3.1.0/formules/Growth/
trunk/3.1.0/formules/GrowthReverse/
trunk/3.1.0/formules/Immigration/
trunk/3.1.0/formules/Migration/
trunk/3.1.0/formules/Reproduction/
trunk/3.1.0/pom.xml
trunk/3.1.0/profiles.xml
trunk/3.1.0/regions/
trunk/3.1.0/regions/DemoRegion/
trunk/3.1.0/regions/DemoRegion/data-backup.sql.gz
trunk/3.1.0/rules/
trunk/3.1.0/rules/Cantonnement.java
trunk/3.1.0/rules/CantonnementPreSimu.java
trunk/3.1.0/rules/ChangementParamControlablePresimu.java
trunk/3.1.0/rules/GraviteCPUE.java
trunk/3.1.0/rules/InterdictionEngin.java
trunk/3.1.0/rules/InterdictionEnginPreSimu.java
trunk/3.1.0/rules/RecrutementLangoustine.java
trunk/3.1.0/rules/TACpoids.java
trunk/3.1.0/rules/TailleMin.java
trunk/3.1.0/scripts/
trunk/3.1.0/scripts/GravityModel.java
trunk/3.1.0/scripts/ResultName.java
trunk/3.1.0/scripts/RuleUtil.java
trunk/3.1.0/scripts/SiMatrix.java
trunk/3.1.0/simulations/
trunk/3.1.0/simulators/
trunk/3.1.0/simulators/DefaultSimulator.java
Log:
initial version from CVS
Added: branches/3.1.0/analyseplans/Calibration.java
===================================================================
--- branches/3.1.0/analyseplans/Calibration.java (rev 0)
+++ branches/3.1.0/analyseplans/Calibration.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,335 @@
+package analyseplans;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.*;
+import java.util.*;
+
+import org.codelutin.math.matrix.*;
+
+import org.codelutin.topia.*;// pour pouvoir utiliser la methode StringUtil.toDouble()
+import org.codelutin.util.*;// pour pouvoir utiliser la methode StringUtil.toDouble()
+
+import fr.ifremer.isisfish.*;
+import fr.ifremer.isisfish.types.*;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.simulator.AnalysePlan;
+import fr.ifremer.isisfish.simulator.AnalysePlanContext;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Calibration_bidon.java
+ *
+ * Created: 8 mars 2007
+ *
+ * @author <>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-11-02 17:43:14 $
+ * by : $Author: bpoussin $
+ */
+public class Calibration implements AnalysePlan {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Calibration.class);
+
+ enum State {STATE_INIT, STATE_0, STATE_1, STATE_2, STATE_3, STATE_4};
+
+ //parametres de la simu 3 points initiaux d un simplex d ordre 2
+ public Population param_Population = null;
+ public String param_M1 = "1e-5;1e-6";// devient un parametre du plan d analyse
+ public String param_M2 = "2e-4;2e-5";// devient un parametre du plan d analyse
+
+ public String param_M3 = "1e-4;1e-6";// devient un parametre du plan d analyse
+ public String param_pas = "1e-5";// devient un parametre du plan d analyse
+ public String param_nomfichier_debarquements = "";//nom + chemin du fichier contenant les debarquements observes par groupe pour la derniere annee
+
+ protected File debarquementsObserves;
+ protected MatrixND matrixDebarquement;
+
+ protected State state = State.STATE_INIT;
+ protected Experiences experiences = new Experiences();
+
+
+ /**
+ * @return the experiences
+ */
+ public Experiences getExperiences() {
+ return this.experiences;
+ }
+
+ public String [] necessaryResult = {
+ ResultName.MATRIX_LANDING_PER_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur le plan.
+ * @return L'aide ou la description du plan
+ */
+ public String getDescription() throws Exception {
+ return _("Simplexe");
+ }
+
+ /**
+ * Appele au demarrage de la simulation, cette methode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(AnalysePlanContext context) throws Exception {
+ if (param_nomfichier_debarquements==null || "".equals(param_nomfichier_debarquements)){
+ debarquementsObserves = FileUtil.getFile(".*.csv", "fichier csv s�parateur ';'");
+ } else {
+ debarquementsObserves = new File(param_nomfichier_debarquements);
+ }
+// int nbYear = context.getParam().getNumberOfYear();
+ TopiaContext db = context.getParam().getRegion().getStorage().beginTransaction();
+ Population pop = (Population)db.findByTopiaId(param_Population.getTopiaId());
+
+ int nbGroup = pop.sizePopulationGroup();
+ matrixDebarquement = MatrixFactory.getInstance().create(new int[]{nbGroup});
+// List<PopulationGroup> groups = pop.getPopulationGroup();
+// matrixDebarquement = MatrixFactory.getInstance().create(new List[]{groups});
+
+ matrixDebarquement.importCSV(new FileReader(debarquementsObserves),new int []{0});
+ db.closeContext();
+ }
+
+ /**
+ * Call before each simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean beforeSimulation(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception {
+ boolean doNext = true;
+
+ int number = context.getNumber();
+
+ if (number < 3) {
+ String [] M1 = param_M1.split(";");
+ String [] M2 = param_M2.split(";");
+ String [] M3 = param_M3.split(";");
+ double [] q1 = StringUtil.toArrayDouble(M1[0], M2[0], M3[0]);
+ double [] q2 = StringUtil.toArrayDouble(M1[1], M2[1], M3[1]);
+
+ experiences.getExperience(number).q1 = q1[number];
+ experiences.getExperience(number).q2 = q2[number];
+
+ changeDB(experiences.getExperience(number), nextSimulation);
+ } else {
+ double q1 = 0;
+ double q2 = 0;
+
+ double lastCritere = experiences.getExperience(number-1).criteria;
+ double g1 = (experiences.current.get(2).q1 + experiences.current.get(1).q1) / 2.0;
+ double g2 = (experiences.current.get(2).q2 + experiences.current.get(1).q2) / 2.0;
+
+ double worst1 = experiences.current.get(0).q1;
+ double worst2 = experiences.current.get(0).q2;
+
+
+ if (state == State.STATE_INIT) {
+ // on fait la 4eme simulation dans tous les cas
+ state = State.STATE_0;
+ Collections.sort(experiences.current);
+ q1 = 2 * g1 - worst1;
+ q2 = 2 * g2 - worst2;
+ } else if (state == State.STATE_0) {
+ // on fait la 5eme avec des q qui dependent de la 4eme dans le dernier cas
+ if (lastCritere < experiences.current.get(0).criteria) {
+ state = State.STATE_1;
+ q1 = g1 - ( g1 - worst1 ) / 2.0;
+ q2 = g2 - ( g2 - worst2 ) / 2.0;
+ } else if (lastCritere < experiences.current.get(1).criteria) {
+ state = State.STATE_2;
+ q1 = g1 + ( g1 - worst1 ) / 2.0;
+ q2 = g2 + ( g2 - worst2 ) / 2.0;
+ } else if (lastCritere < experiences.current.get(2).criteria) {
+ state = State.STATE_INIT;
+ experiences.current.remove(3);
+ } else { // dernier cas possible: if (lastCritere > experiences.current.get(2).critere) {
+ state = State.STATE_4;
+ q1 = experiences.current.get(3).q1 + g1 - worst1;
+ q2 = experiences.current.get(3).q2 + g2 - worst2;
+ }
+ } else if (state == State.STATE_1) {
+ // la derniere simulation a ete faite
+ if (lastCritere > experiences.current.get(0).criteria) {
+ experiences.current.remove(3);
+ experiences.current.remove(0);
+ } else {
+ // FIXME on supprime les 2 derniere qui vient d'etre faite, on risque donc de boucler
+ experiences.current.remove(4);
+ experiences.current.remove(3);
+ doNext = false;
+ }
+ state = State.STATE_INIT;
+ } else if (state == State.STATE_2) {
+ if (lastCritere > experiences.current.get(0).criteria) {
+ experiences.current.remove(3);
+ experiences.current.remove(0);
+ } else {
+ // FIXME on supprime les 2 derniere qui vient d'etre faite, on risque donc de boucler
+ experiences.current.remove(4);
+ experiences.current.remove(3);
+ doNext = false;
+ }
+ state = State.STATE_INIT;
+ } else if (state == State.STATE_4) {
+ if (lastCritere > experiences.current.get(3).criteria) {
+ experiences.current.remove(3);
+ experiences.current.remove(0);
+ } else {
+ experiences.current.remove(4);
+ experiences.current.remove(0);
+ }
+ state = State.STATE_INIT;
+ }
+
+ experiences.getExperience(number).q1 = q1;
+ experiences.getExperience(number).q2 = q2;
+
+ changeDB(experiences.getExperience(number), nextSimulation);
+ }
+
+ return doNext;
+ }
+
+ /**
+ * Call after each simulation, compute criteria for last simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean afterSimulation(AnalysePlanContext context, SimulationStorage lastSimulation) throws Exception {
+ boolean doNext = true;
+
+ int number = context.getNumber();
+
+ ResultStorage result = lastSimulation.getResultStorage();
+ log.fatal("sim: " + lastSimulation + " result: " + result);
+ MatrixND L = result.getMatrix(param_Population, ResultName.MATRIX_LANDING_PER_MET);
+ L = L.sumOverDim(0);// sum sur les mois, si on ajoute le pas (12) on peut sommer sur les annees
+ L = L.sumOverDim(1);// sum sur les strategies
+ L = L.sumOverDim(3);// sum sur les metiers
+ L = L.sumOverDim(4);// sum sur les zones
+ L = L.reduce(); // supprime les dim qui n ont qu un element
+
+ double crit = 0;
+ for ( MatrixIterator g = L.iterator(); g.hasNext();){
+ g.next();
+ int [] dim = g.getCoordinates();
+ double obs = matrixDebarquement.getValue(dim);
+ double simules = g.getValue();
+ crit += Math.pow(obs-simules, 2);
+ }
+ experiences.getExperience(number).criteria = crit;
+
+ return doNext;
+ }
+
+ /**
+ * Modify nextSimulation database with q1 and q2 in exp.
+ * @param exp
+ * @param nextSimulation
+ * @throws Exception
+ */
+ protected void changeDB(Experience exp, SimulationStorage nextSimulation) throws Exception {
+ TopiaContext db = nextSimulation.getStorage().beginTransaction();//ouvrir un context pour modifier les donnees
+ Population pop = (Population)db.findByTopiaId(param_Population.getTopiaId());
+// autre solution moins efficace:
+// PopulationDAO popDAO = IsisFishDAOHelper.getPopulationDAO(db);
+// Population Nephrops = dao.findByName(param_Population.getName());
+
+ MatrixND c = pop.getCapturability();
+
+ for (MatrixIterator i = c.iterator(); i.hasNext();){
+ i.next();
+
+ Object [] sem = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)sem[0];
+ PopulationSeasonInfo season = (PopulationSeasonInfo)sem[1];
+
+ if (season.getFirstMonth().after(Month.JULY) && group.getId() >=18){ //mois >= aout
+ i.setValue(exp.q2);
+ }
+ else {
+ i.setValue(exp.q1);
+ }
+ }
+ db.commitTransaction();
+ db.closeContext();
+ }
+
+ public class Experiences {
+ /** contains last simplex and potentialy 2 more simulation */
+ protected List<Experience> current = new ArrayList<Experience>();
+ /** contains all experience done */
+ protected List<Experience> history = new ArrayList<Experience>();
+
+ /**
+ * @return the history
+ */
+ public List<Experience> getHistory() {
+ return this.history;
+ }
+
+ /**
+ * return experience requested, if this experience doesn't exist
+ * create it.
+ *
+ * @param i simulation number
+ * @return experience with simulation number fixed if new experience
+ * is returned
+ */
+ public Experience getExperience(int i) {
+ Experience result;
+ if (i<history.size()) {
+ result = history.get(i);
+ } else {
+ result = new Experience();
+ result.simNumber = i;
+ history.add(i, result);
+ current.add(result);
+ }
+ return result;
+ }
+ }
+
+ /**
+ * Use to keep q1, q2 and criteria of simulation
+ * @author poussin
+ */
+ public class Experience implements Comparable {
+ public int simNumber;
+ public double criteria;
+ public double q1;
+ public double q2;
+
+ /**
+ * Permit to order experience, first is experience with smallest criteria
+ */
+ public int compareTo(Object arg0) {
+ Experience other = (Experience)arg0;
+ int result = Double.compare(this.criteria, other.criteria);
+ return result;
+ }
+ }
+
+}
+
Added: branches/3.1.0/analyseplans/Max.java
===================================================================
--- branches/3.1.0/analyseplans/Max.java (rev 0)
+++ branches/3.1.0/analyseplans/Max.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,93 @@
+package analyseplans;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.simulator.AnalysePlan;
+import fr.ifremer.isisfish.simulator.AnalysePlanContext;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Max.java
+ *
+ * Created: 2 mars 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-03-09 15:27:21 $
+ * by : $Author: bpoussin $
+ */
+public class Max implements AnalysePlan {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Max.class);
+
+ public int param_max = 10;
+
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur le plan.
+ * @return L'aide ou la description du plan
+ */
+ public String getDescription() throws Exception {
+ return _("Permit to specify maximum simulation numbers");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(AnalysePlanContext context) throws Exception {
+
+ }
+
+ /**
+ * Call before each simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean beforeSimulation(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception {
+ return true;
+ }
+
+ /**
+ * Call after each simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean afterSimulation(AnalysePlanContext context, SimulationStorage lastSimulation) throws Exception {
+ boolean result = context.getNumber() + 1 < param_max;
+ return result;
+ }
+
+}
Added: branches/3.1.0/exports/Abundances.java
===================================================================
--- branches/3.1.0/exports/Abundances.java (rev 0)
+++ branches/3.1.0/exports/Abundances.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,109 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Abundance.java
+ *
+ * Created: 1 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class Abundances implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Abundances.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_ABUNDANCE
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "Abondances";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les abondances en nombre tableau avec des lignes pop;id;zone;date;nombre.");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_ABUNDANCE);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ PopulationGroup group = (PopulationGroup)sems[1];
+ Zone zone = (Zone)sems[2];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+/*
+writeln("debut export abondances");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var result="";
+
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ writeln("population "+pop.getNom());
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+
+ var matrice=resultats.getMatrix(date,pop, "Abondance");
+ var BadZones=matrice.getSemantics(1);
+ var Zones = new Packages.java.util.ArrayList(BadZones);
+ var BadClasses=matrice.getSemantics(0);
+ var Classes=new Packages.java.util.ArrayList(BadClasses);
+ for(var iz=Zones.iterator(); iz.hasNext();){
+ var z=iz.next();
+ for(var ic=Classes.iterator(); ic.hasNext();){
+ var c = ic.next();
+ result+=pop.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+matrice.getValue(c,z)+"\n";
+ }
+ }
+ }
+}
+writeln("fin export abondances");
+
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/Biomasses.java
===================================================================
--- branches/3.1.0/exports/Biomasses.java (rev 0)
+++ branches/3.1.0/exports/Biomasses.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,110 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Biomasses.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class Biomasses implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Biomasses.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_BIOMASS
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "Biomasses";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les biomasses tableau avec des lignes pop;id;zone;date;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_BIOMASS);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ PopulationGroup group = (PopulationGroup)sems[1];
+ Zone zone = (Zone)sems[2];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+
+
+ /*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+var finsimu=resultats.getLastDate().getDate();
+
+
+var result="";
+writeln("debut export biomasse");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop, "matriceBiomass");
+ var BadZones=matrice.getSemantics(1);
+ var Zones = new Packages.java.util.ArrayList(BadZones);
+ var BadClasses=matrice.getSemantics(0);
+ var Classes=new Packages.java.util.ArrayList(BadClasses);
+ for(var iz=Zones.iterator(); iz.hasNext();){
+ var z=iz.next();
+ for(var ic=Classes.iterator(); ic.hasNext();){
+ var c = ic.next();
+ result+=pop.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+matrice.getValue(c,z)+"\n";
+ }
+ }
+ }
+}
+writeln("fin export biomasse");
+
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/CapturesNombre.java
===================================================================
--- branches/3.1.0/exports/CapturesNombre.java (rev 0)
+++ branches/3.1.0/exports/CapturesNombre.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,118 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * CapturesNombre.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class CapturesNombre implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CapturesNombre.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "CapturesNombre";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les captures en nombre de la simulation. tableau pop;metier;id;zone;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+ /*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+
+writeln("debut de export captures nombre");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop, "matriceCatchPerStrategyMet");
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de CapturesNombre");
+
+
+
+return ""+result;
+
+*/
+ }
+
+}
Added: branches/3.1.0/exports/CapturesPoids.java
===================================================================
--- branches/3.1.0/exports/CapturesPoids.java (rev 0)
+++ branches/3.1.0/exports/CapturesPoids.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,114 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * CapturesPoids.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class CapturesPoids implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CapturesPoids.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "CapturesPoids";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les captures en poids de la simulation. tableau pop;metier;id;zone;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+/*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+writeln("debut de export captures poids");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop, "matriceCatchWeightPerStrategyMet");
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de CapturesPoids");
+return ""+result;
+
+*/
+ }
+
+}
Added: branches/3.1.0/exports/CellsDefinition.java
===================================================================
--- branches/3.1.0/exports/CellsDefinition.java (rev 0)
+++ branches/3.1.0/exports/CellsDefinition.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,65 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+import java.util.List;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * CellsDefinition.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class CellsDefinition implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CellsDefinition.class);
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "MailleDefinition";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export cell's position(longitute/latitute)");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ List<Cell> cells = simulation.getFisheryRegion().getCell();
+
+ for (Cell cell : cells) {
+ out.write(cell + ";" + cell.getLongitude() + ";" + cell.getLatitude() + "\n");
+ }
+ }
+
+}
Added: branches/3.1.0/exports/EffortsMetier.java
===================================================================
--- branches/3.1.0/exports/EffortsMetier.java (rev 0)
+++ branches/3.1.0/exports/EffortsMetier.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,98 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * EffortsMetier.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class EffortsMetier implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(EffortsMetier.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "EffortsMetier";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("retourne un tableau strategie;metier;date;effort");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+ Metier metier = (Metier)sems[2];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ metier.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+/*
+var PDate=Packages.fr.ifremer.nodb.Date;
+writeln("debut de export effort");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+var result="";
+
+var finsimu=resultats.getLastDate().getDate();
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "matriceEffortPerStrategyMet");
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var strat=coordonnees[0];
+ capture=iiterateur.getValue();
+ result+=strat.getName()+";"+metier.getNom()+";"+idate+";"+capture+"\n";
+ }
+}
+
+writeln("fin de EffortMetier");
+return ""+result;
+
+*/
+ }
+
+}
Added: branches/3.1.0/exports/MetierZone.java
===================================================================
--- branches/3.1.0/exports/MetierZone.java (rev 0)
+++ branches/3.1.0/exports/MetierZone.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,73 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * MetierZone.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class MetierZone implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(MetierZone.class);
+
+ public String [] necessaryResult = {
+ ResultName.MATRIX_METIER_ZONE,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "MetierZone";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export zone used by metier during simulation");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, ResultName.MATRIX_METIER_ZONE);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ if (i.getValue() == 1) {
+ Object metier = i.getSemanticsCoordinates()[0];
+ Object zone = i.getSemanticsCoordinates()[1];
+ out.write(metier + ";" + zone + ";" + date.getDate() + "\n");
+ }
+ }
+ }
+ }
+ }
+
+}
Added: branches/3.1.0/exports/NonActivite.java
===================================================================
--- branches/3.1.0/exports/NonActivite.java (rev 0)
+++ branches/3.1.0/exports/NonActivite.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,100 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * NonActivite.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class NonActivite implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(NonActivite.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_NO_ACTIVITY
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "NonActivite";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("retourne un tableau strategie;metier;date;proportion");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_NO_ACTIVITY);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+ Metier metier = (Metier)sems[2];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ metier.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+/*
+var PDate=Packages.fr.ifremer.nodb.Date;
+writeln("debut de export nonActivite");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+var result="";
+
+var finsimu=resultats.getLastDate().getDate();
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "nonActivite");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),"nonActivite"));
+ matrice.mults(0);
+ }
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var strat=coordonnees[0];
+ capture=iiterateur.getValue();
+ result+=strat.getName()+";"+metier.getNom()+";"+idate+";"+capture+"\n";
+ }
+}
+
+writeln("fin de nonActivite");
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/OwnerMargin.java
===================================================================
--- branches/3.1.0/exports/OwnerMargin.java (rev 0)
+++ branches/3.1.0/exports/OwnerMargin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,95 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * OwnerMargin.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class OwnerMargin implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(OwnerMargin.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "PatronProfit";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("cvs out strategy;date;value");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+/*
+var Parametre=sim.getParametre();
+var PDate=Packages.fr.ifremer.nodb.Date;
+var finsimu=resultats.getLastDate().getDate();
+
+
+var result="";
+writeln("debut export ownermargin");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "matriceOwnerMarginOverVariableCostsPerStrategyPerVessel");
+ for(var iiterateur=matrice.iterator(); iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var str=coordonnees[0];
+ result+=str.getName()+";"+idate+";"+iiterateur.getValue()+"\n";
+ }
+}
+writeln("fin export ownermargin");
+
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/RegionDefinition.java
===================================================================
--- branches/3.1.0/exports/RegionDefinition.java (rev 0)
+++ branches/3.1.0/exports/RegionDefinition.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,68 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RegionDefinition.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 10:05:22 $
+ * by : $Author: bpoussin $
+ */
+public class RegionDefinition implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RegionDefinition.class);
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "RegionDefinition";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export region description");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ // NomRegion LatituteMin LatitudeMax LongitudeMin LongitudeMax PasLatitude PasLongitude
+ FisheryRegion region = simulation.getFisheryRegion();
+ out.write(region.getName() + ";"
+ + region.getMinLatitude() + ";"
+ + region.getMaxLatitude() + ";"
+ + region.getMinLongitude() + ";"
+ + region.getMaxLongitude() + ";"
+ + region.getCellLengthLatitude() + ";"
+ + region.getCellLengthLongitude() +
+ "\n");
+ }
+
+}
Added: branches/3.1.0/exports/RejetsNombre.java
===================================================================
--- branches/3.1.0/exports/RejetsNombre.java (rev 0)
+++ branches/3.1.0/exports/RejetsNombre.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,117 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RejetsNombre.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class RejetsNombre implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RejetsNombre.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_DISCARDS_PER_STR_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "RejetsNombre";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+/*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+writeln("debut de export rejets nombre");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop ,"Rejet par metier");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
+ matrice.mults(0);
+ }
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de RejetsNombre");
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/RejetsPoids.java
===================================================================
--- branches/3.1.0/exports/RejetsPoids.java (rev 0)
+++ branches/3.1.0/exports/RejetsPoids.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,116 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RejetsPoids.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class RejetsPoids implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RejetsPoids.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "RejetsPoids";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+/*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+writeln("debut de export rejets poids");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, pop, "Rejet par metier");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
+ matrice.mults(0);
+ }
+ var temp=matrice.sumOverDim(0);
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue()*c.getPoidsMoyen();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de RejetsPoids");
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/VesselMargin.java
===================================================================
--- branches/3.1.0/exports/VesselMargin.java (rev 0)
+++ branches/3.1.0/exports/VesselMargin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,95 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * VesselMargin.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class VesselMargin implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(VesselMargin.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "BateauProfit";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("cvs out strategy;date;value");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ /*
+var Parametre=sim.getParametre();
+var PDate=Packages.fr.ifremer.nodb.Date;
+var finsimu=resultats.getLastDate().getDate();
+
+
+var result="";
+writeln("debut export vesselmargin");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "matriceVesselMarginOverVariableCostsPerStrategyPerVessel");
+ for(var iiterateur=matrice.iterator(); iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var str=coordonnees[0];
+ result+=str.getName()+";"+idate+";"+iiterateur.getValue()+"\n";
+ }
+}
+writeln("fin export vesselmargin");
+
+return ""+result;
+*/
+ }
+
+}
Added: branches/3.1.0/exports/ZonesDefinition.java
===================================================================
--- branches/3.1.0/exports/ZonesDefinition.java (rev 0)
+++ branches/3.1.0/exports/ZonesDefinition.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,70 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+import java.util.List;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * ZonesDefinition.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class ZonesDefinition implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(ZonesDefinition.class);
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "ZonesDefinition";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export cell's zone constitution");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ List<Zone> zones = simulation.getFisheryRegion().getZone();
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ for (Zone zone : zones) {
+ for (Cell cell : zone.getCell()) {
+ out.write(zone + ";" + cell + ";" + date.getDate() + "\n");
+ }
+ }
+ }
+ }
+
+}
Added: branches/3.1.0/pom.xml
===================================================================
--- branches/3.1.0/pom.xml (rev 0)
+++ branches/3.1.0/pom.xml 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!--The version of maven's project object model-->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!--lutinproject.xml-->
+<!--
+ <parent>
+ <groupId>lutinlib</groupId>
+ <artifactId>lutinproject</artifactId>
+ <version>2.2</version>
+ </parent>
+-->
+
+ <!--A unique name for this project-->
+ <groupId>ifremer</groupId>
+ <artifactId>isis-fish-data</artifactId>
+ <name>IsisFish data</name>
+
+ <!--ejb, jar, war...-->
+ <packaging>jar</packaging>
+
+ <!--Version-->
+ <version>3.0.0</version>
+
+ <!--Description-->
+ <description>Data for Isis-fish</description>
+ <inceptionYear>2000</inceptionYear>
+
+ <!--Tracking-->
+ <issueManagement>
+ <url>http://labs.libre-entreprise.org/tracker/?group_id=8</url>
+ </issueManagement>
+
+ <build>
+ <sourceDirectory>${basedir}</sourceDirectory>
+ <plugins>
+ </plugins>
+ </build>
+
+ <!--Librairies-->
+ <dependencies>
+ <dependency>
+ <groupId>ifremer</groupId>
+ <artifactId>isis-fish</artifactId>
+ <version>3.0.10</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <distributionManagement>
+ <site>
+ <id>labs</id>
+ <url>scp://labs.libre-entreprise.org/home/groups/${pom.artifactId}/htdocs/isis-f…</url>
+ </site>
+ </distributionManagement>
+
+</project>
Added: branches/3.1.0/profiles.xml
===================================================================
--- branches/3.1.0/profiles.xml (rev 0)
+++ branches/3.1.0/profiles.xml 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<settings>
+ <!--Definition of profiles-->
+ <profiles>
+ <profile>
+ <id>codelutin-repository</id>
+
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+
+ <properties>
+ <maven.src.dir>${basedir}/src</maven.src.dir>
+ <maven.test.skip>true</maven.test.skip>
+ <maven.compile.source>1.5</maven.compile.source>
+ <maven.compile.target>1.5</maven.compile.target>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>codelutin-lib</id>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>codelutin-plugin</id>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+
+ <!--List of profiles that are active for all builds.-->
+ <activeProfiles>
+ <activeProfile>codelutin-repository</activeProfile>
+ </activeProfiles>
+</settings>
Added: branches/3.1.0/regions/DemoRegion/data-backup.sql.gz
===================================================================
(Binary files differ)
Property changes on: branches/3.1.0/regions/DemoRegion/data-backup.sql.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/3.1.0/rules/Cantonnement.java
===================================================================
--- branches/3.1.0/rules/Cantonnement.java (rev 0)
+++ branches/3.1.0/rules/Cantonnement.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,321 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+
+/**
+ * Cantonnement.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.5 $
+ *
+ * Last update: $Date: 2007-11-02 17:41:41 $
+ * by : $Author: bpoussin $
+ */
+
+/**
+ * Remplace aussi Cantonnement Engin
+ */
+public class Cantonnement extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Cantonnement.class);
+
+ public Zone param_zone = null;
+ public Gear param_gear = null;
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(119);
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_NO_ACTIVITY,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ if(date.before(param_beginDate)) {
+ return false;
+ } else if(date.after(param_endDate)) {
+ return false;
+ }
+
+ if (date.getMonth().before(param_beginMonth)) {
+ return false;
+ } else if (date.getMonth().after(param_endMonth)) {
+ return false;
+ }
+ if (param_gear != null && !param_gear.equals(metier.getGear())) {
+ return false;
+ }
+
+
+ List<Cell> cellMetiers = metier.getMetierSeasonInfo(date.getMonth()).getCells();
+ List<Cell> cells = param_zone.getCell();
+
+ cellMetiers.retainAll(cells);
+
+ boolean result = !Collections.disjoint(cellMetiers, cells);
+ if (result && log.isInfoEnabled()) {
+ log.info("Cantonnement condition true");
+ }
+ return result;
+
+/*
+writeln("condition fermeture zone");
+var mois = p.date.getMois().getNumMois();
+writeln("mois:"+mois);
+if(p.moisDeb>mois || p.moisFin<mois)
+ return false;
+writeln("on est dans l'espace des mois possible");
+//on est dans l'espace des mois possible
+if(p.date.before(p.dateDeb))
+ return false;
+if(p.date.after(p.dateFin))
+ return false;
+
+
+var mailleMetier = p.metier.getSecteurMois(p.date.getMois()).getMaille();
+
+// s'il y a une intersection avec la zone ferme, alors la regle s'applique
+mailleMetier.retainAll(p.mailles);
+var result = mailleMetier.size() != 0;
+
+if(result)
+ writeln("===== Fermeture Zone s'applique ======");
+return result;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ MetierMonitor metierMon = context.getMetierMonitor();
+
+ MetierSeasonInfo infoMetier = metier.getMetierSeasonInfo(date.getMonth());
+
+ List<Cell> cellMetiers = infoMetier.getCells();
+ List<Cell> cells = param_zone.getCell();
+
+ cellMetiers.removeAll(cells);
+
+ if (cellMetiers.size() != 0) {
+ ZoneDAO dao = IsisFishDAOHelper.getZoneDAO(context.getDB());
+
+ //
+ // Create new empty zone for cantonnement
+ //
+ String name = "ZoneCantonnement-" + metier.getName()+ "-" + date.getDate();
+ Zone zoneCantonnement = dao.findByName(name);
+ int cpt=0;
+ while (zoneCantonnement != null) {
+ cpt++;
+ zoneCantonnement = dao.findByName(name + "-" + cpt);
+ }
+ zoneCantonnement = dao.create();
+ if (cpt > 0) {
+ name += "-" + cpt;
+ }
+ zoneCantonnement.setName(name);
+
+ //
+ // Remove prohibited zone and add not prohibited cell to zoneCantonnement
+ //
+ Collection<Zone> zoneMetiers = infoMetier.getZone();
+ for (Iterator<Zone> i=zoneMetiers.iterator(); i.hasNext();) {
+ Zone zone = i.next();
+ // copy list cell to not modify original zone
+ List<Cell> tmpCells = new ArrayList<Cell>(zone.getCell());
+ tmpCells.removeAll(param_zone.getCell());
+
+ zoneCantonnement.addAllCell(tmpCells);
+ i.remove();
+ }
+ ArrayList<Zone> newZone = new ArrayList<Zone>();
+ newZone.add(zoneCantonnement);
+ infoMetier.setZone(newZone);
+ } else {
+ // sinon toute la zone de pratique du metier est incluse dans zone Cantonnement
+ // alors metier devient metier-nonactivite
+
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ MatrixND noActivity = metierMon.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ metierMon.addforbiddenMetier(metier);
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ for(Strategy str : strategies){
+ StrategyMonthInfo info = str.getStrategyMonthInfo(date.getMonth());
+ double prop = info.getProportionMetier(metier);
+ if (prop != 0){
+ noActivity.setValue(str , metier, prop);
+ info.setProportionMetier(metier, 0);
+ }
+ }
+ }
+ // fin de preAction
+
+/*
+writeln("Cantonnement zone Action avant metier:"+p.metier);
+writeln("Les mailles fermees sont:"+p.mailles);
+
+var zoneMetier = p.metier.getSecteurMois(p.date.getMois());
+var mailleMetier = zoneMetier.getMaille().copy();
+mailleMetier.removeAll(p.mailles);
+writeln("inter maille:"+mailleMetier.size());
+// test pour savoir si toute la zone de pratique du metier
+// (reunion de toutes les zones metiers de metier a date)
+// est totalement incluse dans la zone Cantonnement
+if (mailleMetier.size() != 0){ //le cas intersection.length==mailleMetier est dans condition
+ // si toute la zone de pratique du metier n'est pas incluse dans zone Cantonnement
+
+ //creation du nouveau secteur de metier
+ //on v�rifie si le secteur a pas d�j� �t� modifi� par une autre r�gle afin de ne pas avoir de probl�me d'ID
+ var ListeSecteur=MetaSecteurFactory.findAllByKey("MetaCantonnement-"+p.metier.getNom()+"-"+date.getDate(),p.metier.getRegion());
+ if (ListeSecteur.size()!=0){
+ var secteurResult = MetaSecteurFactory.create(zoneMetier.getNom()+"Modif", p.metier.getRegion(), "Secteur creer durant la simulation.");
+ }
+ else{
+ var secteurResult = MetaSecteurFactory.create("MetaCantonnement-"+p.metier.getNom()+"-"+date.getDate(), p.metier.getRegion(), "Secteur creer durant la simulation.");
+ }
+ writeln("nouveau secteur cree:"+secteurResult);
+ var zonesMetier = zoneMetier.getAllSecteur();
+ writeln("zonesMetier:"+zonesMetier);
+ writeln("zonesMetier.size:"+zonesMetier.size());
+
+ for(var i=0; i<zonesMetier.size(); i++){
+ var zonemet = zonesMetier.get(i);
+ writeln("zonemet:"+zonemet);
+ // intersection entre la zeme zone metier a date et zone de Cantonnement
+ var listemailleszonemetier = zonemet.getMaille().copy();
+ var nbMailleZoneMetier = listemailleszonemetier.size();
+ writeln("maille metier:"+listemailleszonemetier);
+ writeln("maille Cantonnement:"+p.mailles);
+ listemailleszonemetier.removeAll(p.mailles);
+ if(0==listemailleszonemetier.size()){
+ //si completement inclus on le supprime
+ //donc on ne le met pas dans le nouveau
+ writeln("on supprime la zone"+zonemet);
+ }
+ else if (listemailleszonemetier.size() != nbMailleZoneMetier) {
+ // si la zone metier n'est pas totalement incluse dans zone de Cantonnement
+ // on reduit la zeme zone metier de cette intersection
+ // pas de modif de la matrice de proportion strmet
+ writeln("on cree une nouvelle zone a partir de:"+zonemet+" avec "+listemailleszonemetier);
+ var simpleSecteur = SecteurSimpleFactory.create("Cantonnement-"+p.metier.getNom()+"-"+zonemet+"-"+date.getDate(), p.metier.getRegion(), "Secteur creer durant la simulation.");
+ simpleSecteur.addAllMaille(listemailleszonemetier);
+ secteurResult.addSecteur(simpleSecteur);
+ writeln("apres addSecteur");
+ }else {
+ //sinon on le met dans le nouveau
+ writeln("On remet tel quelle la zone:"+zonemet);
+ secteurResult.addSecteur(zonemet);
+ }
+ }// fin du for sur les zone metier de la zone de pratique du metier
+ writeln("Zone metier avant"+zoneMetier.getMaille());
+ writeln("Zone metier apres"+secteurResult);
+ writeln("Zone metier apres"+secteurResult.getMaille());
+ p.metier.setSecteurMois(secteurResult, p.date.getMois());
+}
+else {
+ writeln("Toute la zone metier est ferme");
+ // sinon toute la zone de pratique du metier est incluse dans zone Cantonnement
+ // alors metier devient metier-nonactivite
+
+ //on regarde si la matrice nonActivite a �t� cr�e, sinon on la cr�e
+ var matNonActivite=nonActivite.get(p.date);
+ var nonactivite=matNonActivite!=null;
+ if (!nonactivite){
+ matNonActivite=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ nonActivite.put(p.date,matNonActivite);
+ }
+
+ //listes des strategies contenant ce metier et tel que strmet(metier,date)!=0
+ MetiersInterdits.put(new Packages.java.lang.String(p.metier.getNom()),true);
+ var listestrategies=StrategyFactory.findAllByRegion(p.metier.getRegion());
+
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+
+ if (MetiersPosibles.contains(p.metier) ){
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(p.date.getMois());
+ if (InfoMois.getProportionMetier(p.metier)!=0){
+ matNonActivite.setValue(listestrategies.get(i),p.metier,InfoMois.getProportionMetier(p.metier));
+ InfoMois.setProportionMetier(p.metier,new Packages.java.lang.Float(0));
+ }
+ }
+ }
+}// fin du else passage a metier-nonactivite
+writeln("fin Cantonnement zone action avant");
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+}
Added: branches/3.1.0/rules/CantonnementPreSimu.java
===================================================================
--- branches/3.1.0/rules/CantonnementPreSimu.java (rev 0)
+++ branches/3.1.0/rules/CantonnementPreSimu.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,711 @@
+package rules;
+
+import static org.codelutin.i18n.I18n.n_;
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+
+/**
+ * Cantonnement.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class CantonnementPreSimu extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CantonnementPreSimu.class);
+
+ public Zone param_zone = null;
+ public Gear param_gear = null;
+ public boolean param_enginSelective = true;
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>();
+ protected boolean affectNonActivite = false;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_NO_ACTIVITY,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter");
+ }
+
+ private void reportNonActivite(SimulationContext context,
+ List<Strategy> listestrategies, List<Metier> metiers,
+ Metier metier, List<Month> chomageMonth) {
+ for(Strategy strategy : listestrategies) {
+ SetOfVessels SetOfBateau = strategy.getSetOfVessels();
+ EffortDescription effort = SetOfBateau.getPossibleMetiers(metier);
+ if (effort != null){
+ for (Month month : chomageMonth) {
+ StrategyMonthInfo InfoMois = strategy.getStrategyMonthInfo(month);
+//this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+ log.info("debut reportNonActivite");
+ // on regarde si on a d�j� une entr�e pour le mois courant
+ MatrixND matNonActiviteMois=tableNonActivite.get(month);
+ if (matNonActiviteMois == null){
+ matNonActiviteMois = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NO_ACTIVITY,
+ new List[]{listestrategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+ tableNonActivite.put(month, matNonActiviteMois);
+ }
+
+ matNonActiviteMois.setValue(strategy, metier, InfoMois.getProportionMetier(metier));
+ log.info("fin reportNonActivite");
+
+ InfoMois.setProportionMetier(metier, 0);
+ MetierMonitor metierMon = context.getMetierMonitor();
+ metierMon.isLimited(metier, month);
+ metierMon.addforbiddenMetier(metier, month);
+ }
+ }
+ }
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+
+// MetierDAO metierDao = IsisFishDAOHelper.getMetierDAO(context.getDB());
+ ZoneDAO zoneDao = IsisFishDAOHelper.getZoneDAO(context.getDB());
+ MetierSeasonInfoDAO metierSeasonInfoDao = IsisFishDAOHelper.getMetierSeasonInfoDAO(context.getDB());
+
+// List<Metier> metiers = metierDao.findAll();
+ List<Month> SaisonFermee = Month.getMonths(param_beginMonth, param_endMonth);
+ List<Cell> maillefermee = param_zone.getCell();
+
+ FisheryRegion region = RegionStorage.getFisheryRegion(context.getDB());
+ List<Strategy> listestrategies= region.getStrategy();
+ List<Metier> metiers = region.getMetier();
+
+// var SaisonFermee= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+
+
+ for (Metier metier : metiers) {
+ log.info("metier examin� " + metier.getName());
+ if (param_gear != null && !metier.getGear().equals(param_gear)){
+ log.info("l engin du m�tier n est pas concern�");
+ }
+ else {
+ log.info("l engin du m�tier est bien concern�");
+ List<MetierSeasonInfo> saisons = metier.getMetierSeasonInfo();
+ for (MetierSeasonInfo saisonmetier: saisons){
+ int inter = siMatrix.nbCellInter(saisonmetier.getZone(), param_zone);
+ if (inter != 0){
+ List<Cell> MailleMetier = siMatrix.getCells(saisonmetier.getZone());
+
+ // les mailles qui reste dans la zone metier
+ List<Cell> newCellMetier = new ArrayList<Cell>(MailleMetier);
+ newCellMetier.removeAll(maillefermee);
+
+ List<Month> saison=saisonmetier.getMonths();
+ if (saison.containsAll(SaisonFermee)){
+ log.info("il y a bien intersection entre la zone m�tier et le cantonnement pour la saison "+saison.toString());
+ // calcule de la zone restante:
+ boolean ToutFerme=false;
+ boolean DebInclus=saison.contains(param_beginMonth);
+ boolean FinInclus=saison.contains(param_endMonth);
+
+ //creation du nouveau secteur de metier
+ Zone secteurResult = zoneDao.create();
+ secteurResult.setName("MetaCantonnement-" + metier.getName() + "-" + saison.toString());
+ secteurResult.setComment("Secteur cr�� durant la simulation.");
+ // on ajoute les mailles restants de la zone metier dans la zone resultante
+ secteurResult.addAllCell(newCellMetier);
+
+
+ // test pour savoir si toute la zone de pratique du metier
+ // (reunion de toutes les zones metiers de metier a date)
+ // est totalement incluse dans la zone Cantonnement
+ if (newCellMetier.size() != 0){ //le cas intersection.length==mailleMetier est dans condition
+ // si toute la zone de pratique du metier n'est pas incluse dans zone Cantonnement
+ ToutFerme=false;
+ } else {
+ log.info("Toute la zone metier est ferme");
+ ToutFerme=true;
+ }
+
+// 1er cas: la saison m�tier est identique (ou totalement incluse dans la saison ferm�e, dans ce cas l�, on change juste
+// le secteur
+ if (SaisonFermee.containsAll(saison)){
+ log.info("toute la saison metier est incluse dans la saison de fermeture");
+ //si tout est ferm�, on met le metier au ch�mage
+
+ if (ToutFerme==true) {
+ log.info ("toute la zone est ferm�e, le metier passe donc � ch�mage pour cette saison");
+ reportNonActivite(context, listestrategies, metiers, metier, saison);
+
+ } else {
+ log.info("tout n'est pas ferm�e, le secteur de p�che devient " + secteurResult);
+ for (Month month : SaisonFermee){
+ metier.getMetierSeasonInfo(month).clearZone();
+ metier.getMetierSeasonInfo(month).addZone(secteurResult);
+ }
+ }
+ }
+
+// 2�me cas de figure: moisDeb est inclus mais pas moisFin (ou alors c'est le dernier mois)
+ else if (DebInclus && ((!FinInclus) || param_endMonth.equals(saison.get(saison.size()-1)))) {
+ log.info ("il y a intersection de la saison de fermeture avec la saison m�tier de " + param_beginMonth + " � " + saison.get(saison.size()-1));
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ log.info ("toute la zone m�tier est ferm�e");
+ List<Month> chomageMonth = new ArrayList<Month>(SaisonFermee);
+ chomageMonth.retainAll(saison);
+ log.info ("de "+chomageMonth.get(0)+" a "+ chomageMonth.get(chomageMonth.size()-1)+ ", le metier est donc mis au chomage");
+
+ reportNonActivite(context, listestrategies, metiers, metier, chomageMonth);
+ } else {
+ //on commence par cr�e les nouvelles saisons
+// var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,saison.getLastMois().getNumMois());
+// var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+ saisonmetier.setLastMonth(param_beginMonth.previous());
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison= metierSeasonInfoDao.create();
+ NouvelInfoSaison.setMetier(metier);
+ NouvelInfoSaison.setFirstMonth(param_beginMonth);
+ NouvelInfoSaison.setLastMonth(saison.get(saison.size()-1));
+ NouvelInfoSaison.addZone(secteurResult);
+ NouvelInfoSaison.setComment("saison cr�e pendant la simulation") ;
+
+ metier.addMetierSeasonInfo(NouvelInfoSaison);
+ log.info ("de "+saison.get(0)+" � "+param_beginMonth.previous()+" le metier peche en "+saisonmetier.getZone());
+ log.info ("de "+param_beginMonth+" � "+saison.get(saison.size()-1)+" le metier peche en "+secteurResult);
+ }
+ }
+// 3�me cas de figure: moisFin est inclus mais pas moisDeb (ou alors il est �gal au premier mois)
+ else if (((!DebInclus) || param_beginMonth.equals(saison.get(0))) && FinInclus) {
+ log.info ("il y a intersection de la saison de fermeture avec la saison m�tier de "+param_beginMonth+" � "+saison.get(saison.size()-1));
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ log.info ("toute la zone est fermee");
+ List<Month> chomageMonth = new ArrayList<Month>(SaisonFermee);
+ chomageMonth.retainAll(saison);
+ reportNonActivite(context, listestrategies, metiers, metier, chomageMonth);
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ saisonmetier.setFirstMonth(param_endMonth.next());
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison= metierSeasonInfoDao.create();
+ NouvelInfoSaison.setMetier(metier);
+ NouvelInfoSaison.setFirstMonth(saison.get(0));
+ NouvelInfoSaison.setLastMonth(param_endMonth);
+ NouvelInfoSaison.addZone(secteurResult);
+ NouvelInfoSaison.setComment("saison cr�e pendant la simulation") ;
+
+ metier.addMetierSeasonInfo(NouvelInfoSaison);
+ log.info ("de "+saison.get(0)+" � "+param_endMonth+" le metier peche en "+secteurResult);
+ log.info ("de "+param_endMonth.next()+" � "+saison.get(saison.size()-1)+" le metier peche en "+saisonmetier.getZone());
+ }
+ }
+
+// dernier cas de figure: les deux sont inclus et sont diff�rents des bornes
+ else {
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ log.info("toute la zone m�tier est ferm�e");
+ reportNonActivite(context, listestrategies, metiers, metier, SaisonFermee);
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+// var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+// var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+// var NouvelleSaison3=new Packages.fr.ifremer.nodb.Saison(moisFin+1,saison.getLastMois().getNumMois());
+//
+ saisonmetier.setFirstMonth(param_beginMonth.previous());
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison = metierSeasonInfoDao.create();
+ NouvelInfoSaison.setMetier(metier);
+ NouvelInfoSaison.setFirstMonth(param_beginMonth);
+ NouvelInfoSaison.setLastMonth(param_endMonth);
+ NouvelInfoSaison.addZone(secteurResult);
+ NouvelInfoSaison.setComment("saison cr�e pendant la simulation") ;
+ metier.addMetierSeasonInfo(NouvelInfoSaison);
+
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison2 = metierSeasonInfoDao.create();
+ NouvelInfoSaison2.setMetier(metier);
+ NouvelInfoSaison2.setFirstMonth(param_endMonth.next());
+ NouvelInfoSaison2.setLastMonth(saison.get(saison.size()-1));
+ NouvelInfoSaison2.setZone(saisonmetier.getZone());
+ NouvelInfoSaison2.setComment("saison cr�e pendant la simulation") ;
+ metier.addMetierSeasonInfo(NouvelInfoSaison2);
+
+ log.info ("de "+saison.get(0)+" � "+param_beginMonth.previous()+" le metier peche en "+saisonmetier.getZone());
+ log.info ("de "+param_beginMonth+" � "+param_endMonth+" le metier peche en "+secteurResult);
+ log.info ("de "+param_endMonth.next()+" � "+saison.get(saison.size()-1)+" le metier peche en "+saisonmetier.getZone());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ this.p = new Object();
+ this.p.paramRegle = this.param;
+ this.p.tableNonActivite=new Packages.java.util.HashMap();
+ this.p.affectNonActivite=false;
+
+
+ var enginselectif=this.param.getValue("EnginSelective");//entrez le nom de l'engin ferm�e ou non si pas de s�lection sur engin
+ var moisDeb=this.param.getValue("moisDeb"); //entrez le mois debut de fermeture
+ var moisFin=this.param.getValue("moisFin");//entrez le mois de fin de fermeture
+
+
+
+ var ZoneFermee=this.param.getValue("zone");
+ writeln("bla");
+ if (enginselectif) {var EnginInterdit=this.param.getValue("engin");} else {var EnginInterdit=MetierFactory.findByNom("nonActivite").getEngin();}
+ var RegionSimu=ZoneFermee.getRegion();
+ var ListeMetiers=MetierFactory.findAllByRegion(RegionSimu);
+ var MoisDeb=new Packages.fr.ifremer.nodb.Mois(moisDeb);
+ var MoisFin=new Packages.fr.ifremer.nodb.Mois(moisFin);
+ var SaisonFermee= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+
+
+
+ for (var imetier = ListeMetiers.iterator() ; imetier.hasNext();){
+ var metier=imetier.next();
+ writeln ("metier examin� "+metier.getNom());
+ if ((!metier.getEngin().equals(EnginInterdit)) && enginselectif){
+ writeln("l engin du m�tier n est pas concern�");
+ }
+ else {
+ writeln("l engin du m�tier est bien concern�");
+ var ListeSaisons = metier.getInfoSaison();
+ for (var isaisonmetier = ListeSaisons.iterator() ; isaisonmetier.hasNext();){
+ var saisonmetier=isaisonmetier.next();
+ var maillefermee=ZoneFermee.getMaille();
+ var MailleMetier=saisonmetier.getSecteur().getMaille().copy();
+ MailleMetier.retainAll(maillefermee);
+
+ if (MailleMetier.size()!=0){
+ MailleMetier=saisonmetier.getSecteur().getMaille().copy();
+ var saison=saisonmetier.getSaison();
+ if (saison.contains(SaisonFermee)){
+ writeln("il y a bien intersection entre la zone m�tier et le cantonnement pour la saison "+saison.toString());
+// calcule de la zone restante:
+ var ToutFerme=false;
+ var DebInclus=saison.contains(MoisDeb);
+ var FinInclus=saison.contains(MoisFin);
+ MailleMetier.removeAll(maillefermee);
+ writeln("inter maille:"+MailleMetier.size());
+ // test pour savoir si toute la zone de pratique du metier
+ // (reunion de toutes les zones metiers de metier a date)
+ // est totalement incluse dans la zone Cantonnement
+
+ if (MailleMetier.size() != 0){ //le cas intersection.length==mailleMetier est dans condition
+ // si toute la zone de pratique du metier n'est pas incluse dans zone Cantonnement
+
+ ToutFerme=false;
+
+ //creation du nouveau secteur de metier
+ //on v�rifie si le secteur a pas d�j� �t� modifi� par une autre r�gle afin de ne pas avoir de probl�me d'ID
+ var ListeSecteur=MetaSecteurFactory.findAllByKey("MetaCantonnement-"+metier.getNom()+saison.toString(), RegionSimu);
+ if (ListeSecteur.size()!=0){
+ var secteurResult = MetaSecteurFactory.create(saisonmetier.getSecteur().getNom()+"Modif", RegionSimu, "Secteur cr�� durant la simulation.");
+ }
+ else{
+ var secteurResult = MetaSecteurFactory.create("MetaCantonnement-"+metier.getNom()+saison.toString(),RegionSimu, "Secteur cr�� durant la simulation.");
+ }
+
+ writeln("nouveau secteur cree:"+secteurResult);
+ var zonesMetier = saisonmetier.getSecteur().getAllSecteur();
+ writeln("zonesMetier:"+zonesMetier);
+ writeln("zonesMetier.size:"+zonesMetier.size());
+
+ for(var i=0; i<zonesMetier.size(); i++){
+ var zonemet = zonesMetier.get(i);
+ writeln("zonemet:"+zonemet);
+ // intersection entre la zeme zone metier a date et zone de Cantonnement
+ var listemailleszonemetier = zonemet.getMaille().copy();
+ var nbMailleZoneMetier = listemailleszonemetier.size();
+ writeln("maille metier:"+listemailleszonemetier);
+ writeln("maille Cantonnement:"+maillefermee);
+ listemailleszonemetier.removeAll(maillefermee);
+ if(0==listemailleszonemetier.size()){
+ //si completement inclus on le supprime
+ //donc on ne le met pas dans le nouveau
+ writeln("on supprime la zone"+zonemet);
+ }
+ else if (listemailleszonemetier.size() != nbMailleZoneMetier) {
+ // si la zone metier n'est pas totalement incluse dans zone de Cantonnement
+ // on reduit la zeme zone metier de cette intersection
+ // pas de modif de la matrice de proportion strmet
+ writeln("on cree une nouvelle zone a partir de:"+zonemet+" avec "+listemailleszonemetier);
+ var simpleSecteur = SecteurSimpleFactory.create("Cantonnement-"+metier.getNom()+"-"+zonemet+saison.toString(), RegionSimu, "Secteur creer durant la simulation.");
+ simpleSecteur.addAllMaille(listemailleszonemetier);
+ secteurResult.addSecteur(simpleSecteur);
+ writeln("apres addSecteur");
+ }
+ else {
+ //sinon on le met dans le nouveau
+ writeln("On remet tel quelle la zone:"+zonemet);
+ secteurResult.addSecteur(zonemet);
+ }
+ }// fin du for sur les zone metier de la zone de pratique du metier
+ }
+
+ else {
+ var secteurResult=saisonmetier.getSecteur().getAllSecteur();
+ writeln("Toute la zone metier est ferme");
+ ToutFerme=true;
+ }
+
+// 1er cas: la saison m�tier est identique (ou totalement incluse dans la saison ferm�e, dans ce cas l�, on change juste
+// le secteur
+ if (SaisonFermee.toListMois().containsAll(saison.toListMois())){
+ writeln("toute la saison metier est incluse dans la saison de fermeture");
+ //si tout est ferm�, on met le metier au ch�mage
+
+ if (ToutFerme==true){
+ writeln ("toute la zone est ferm�e, le metier passe donc � ch�mage pour cette saison");
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ var ListeMois=saison.toListMois();
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier)){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ writeln("tout n'est pas ferm�e, le secteur de p�che devient "+secteurResult);
+ var ListeMois=SaisonFermee.toListMois();
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ mois=imois.next();
+ metier.setSecteurMois(secteurResult, mois);
+ }
+ }
+ }
+
+// 2�me cas de figure: moisDeb est inclus mais pas moisFin (ou alors c'est le dernier mois)
+ else if (DebInclus && ((!FinInclus) || moisFin==saison.getLastMois().getNumMois())){
+ writeln ("il y a intersection de la saison de fermeture avec la saison m�tier de "+moisDeb+" � "+saison.getLastMois().getNumMois());
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ writeln ("toute la zone m�tier est ferm�e");
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ var ListeMois=SaisonFermee.toListMois().retainAll(saison.toListMois());
+ writeln ("de "+ListeMois.get(0)+" a "+ ListeMois.get(ListeMois.size())+ ", le metier est donc mis au chomage");
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier)){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,saison.getLastMois().getNumMois());
+ var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+ saisonmetier.setSaison(NouvelleSaison1);
+ //on cr�e un nouveau infoSaisonMetier
+ var NouvelInfoSaison=InfoSaisonMetierFactory.create(metier, NouvelleSaison2, secteurResult, "saison cr�e pendant la simulation") ;
+ metier.addInfoSaison(NouvelInfoSaison);
+ writeln ("de "+saison.getFirstMois().getNumMois()+" � "+moisDeb-1+" le metier peche en "+saisonmetier.getSecteur());
+ writeln ("de "+moisDeb+" � "+saison.getLastMois().getNumMois()+" le metier peche en "+secteurResult);
+ }
+ }
+// 3�me cas de figure: moisFin est inclus mais pas moisDeb (ou alors il est �gal au premier mois)
+ else if (((!DebInclus) || moisDeb==saison.getFirstMois().getNumMois()) && FinInclus){
+ writeln ("il y a intersection de la saison de fermeture avec la saison m�tier de "+moisDeb+" � "+saison.getLastMois().getNumMois());
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ writeln ("toute la zone est fermee");
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ var ListeMois=SaisonFermee.toListMois().retainAll(saison.toListMois());
+ writeln ("de "+ListeMois.get(0)+" a "+ ListeMois.get(ListeMois.size())+ ", le metier est donc mis au chomage");
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier) ){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisFin);
+ var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisFin+1,saison.getLastMois.getNumMois());
+ saisonmetier.setSaison(NouvelleSaison2);
+ //on cr�e un nouveau infoSaisonMetier
+ var NouvelInfoSaison=InfoSaisonMetierFactory.create(metier, NouvelleSaison1, secteurResult, "saison cr�e pendant la simulation") ;
+ metier.addInfoSaison(NouvelInfoSaison);
+ writeln ("de "+saison.getFirstMois().getNumMois()+" � "+moisFin+" le metier peche en "+secteurResult);
+ writeln ("de "+moisFin+1+" � "+saison.getLastMois().getNumMois()+" le metier peche en "+saisonmetier.getSecteur());
+ }
+ }
+
+// dernier cas de figure: les deux sont inclus et sont diff�rents des bornes
+ else {
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ writeln("toute la zone m�tier est ferm�e");
+ var listestrategies=StrategyFactory.findAllByRegion(metier.getRegion());
+ var ListeMois=SaisonFermee.toListMois();
+ writeln("le m�tier passe � ch�mage de "+moisDeb+" � "+moidFin);
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier) ){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+ var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+ var NouvelleSaison3=new Packages.fr.ifremer.nodb.Saison(moisFin+1,saison.getLastMois().getNumMois());
+ saisonmetier.setSaison(NouvelleSaison1);
+ //on cr�e 2 nouveau infoSaisonMetier
+ var NouvelInfoSaison2=InfoSaisonMetierFactory.create(metier, NouvelleSaison2, secteurResult, "saison cr�e pendant la simulation") ;
+ var NouvelInfoSaison3=InfoSaisonMetierFactory.create(metier, NouvelleSaison3, saisonmetier.getSecteur(), "saison cr�e pendant la simulation") ;
+ metier.addInfoSaison(NouvelInfoSaison2);
+ metier.addInfoSaison(NouvelInfoSaison3);
+ writeln ("de "+saison.getFirstMois().getNumMois()+" � "+(moisDeb-1)+" le metier peche en "+saisonmetier.getSecteur());
+ writeln ("de "+moisDeb+" � "+moisFin+" le metier peche en "+secteurResult);
+ writeln ("de "+(moisFin+1)+" � "+saison.getLastMois().getNumMois()+" le metier peche en "+saisonmetier.getSecteur());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ */
+
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ boolean result = false;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+ if (mat != null && affectNonActivite == false) {
+ result = true;
+ }
+ return result;
+ // fin
+
+ /*
+ var mat=p.tableNonActivite.get(p.date.getMois());
+ writeln(p.affectNonActivite);
+ if(oldValue != undefined)
+ return oldValue;
+ else if (mat!=null && p.affectNonActivite==false){
+ return true;
+ }
+ else {return false;}
+ */
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // on ne doit le faire qu'une seul fois quelque soit le nombre de metier
+ affectNonActivite=true;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND noActivity = metierMon.getNoActivity(date);
+
+ if (noActivity == null){
+ metierMon.setNoActivity(date, mat.copy());
+ }
+ else{
+ noActivity = noActivity.add(mat);
+ }
+
+ /*
+ p.affectNonActivite=true;
+var mat=p.tableNonActivite.get(p.date.getMois());
+var matNonActivite=nonActivite.get(p.date);
+var nonactivite=matNonActivite!=null;
+if (!nonactivite){
+ nonActivite.put(p.date,mat);
+}
+else{
+ matNonActivite=matNonActivite.add(mat);
+}
+return p.gestionMetier;
+
+ */
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ affectNonActivite = false;
+
+ /*
+ p.affectNonActivite=false;
+return p.gestionMetier;
+ */
+ }
+
+}
Added: branches/3.1.0/rules/ChangementParamControlablePresimu.java
===================================================================
--- branches/3.1.0/rules/ChangementParamControlablePresimu.java (rev 0)
+++ branches/3.1.0/rules/ChangementParamControlablePresimu.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,316 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * TailleMin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class ChangementParamControlablePresimu extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(ChangementParamControlablePresimu.class);
+
+ public Zone param_zone = null;
+ public Gear param_gear = null;
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+ public String param_newParamValue = "80";
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Change gear parameter value for all metier with this gear");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+
+ Zone ZoneFermee = param_zone;
+ Month MoisDeb = param_beginMonth;
+ Month MoisFin= param_endMonth;
+ String nouvelleValeurParam = param_newParamValue;
+ Gear EnginInterdit = param_gear;
+
+ log.info("nom de l'engin interdit " + EnginInterdit.getName());
+
+ FisheryRegion RegionSimu = RegionStorage.getFisheryRegion(context.getDB());
+ List<Metier> ListeMetiers = RegionSimu.getMetier();
+ List<Month> SaisonFermee = Month.getMonths(MoisDeb, MoisFin);
+
+ for (Metier metier : ListeMetiers) {
+ log.info("metier examin� " + metier.getName() + " son engin " + metier.getGear().getName());
+ if (!metier.getGear().equals(EnginInterdit)){
+ log.info("l engin du m�tier n est pas concern�");
+ } else {
+ log.info("l engin du m�tier est bien concern�");
+ if (ZoneFermee == null && Month.JANUARY.equals(MoisDeb) && Month.DECEMBER.equals(MoisFin)){
+ //aucun crit�re spatio-temporel il suffit donc de mettre
+ //le param controlable � la nouvelle valeur
+ metier.setGearParameterValue(nouvelleValeurParam);
+ log.info("aucune spatialisation ni saisonnalit�, on passe le Param Controlable a "+nouvelleValeurParam);
+ } else {
+ List<MetierSeasonInfo> ListeSaisons = metier.getMetierSeasonInfo();
+ for (MetierSeasonInfo saisonmetier : ListeSaisons) {
+ List<Month> saison = saisonmetier.getMonths();
+ int taille=0;
+ if (ZoneFermee != null){
+ taille = siMatrix.nbCellInter(saisonmetier.getZone(), ZoneFermee);
+ } else {
+ log.info ("pas de s�lection de zone, toute la zone d'�tude est donc concern�e");
+ }
+ if (ZoneFermee == null || taille!=0){
+ if (saison.containsAll(SaisonFermee)){
+ log.info ("il y a intersection de la zone metier au cours de la saison" + saison);
+ List<Month> moisconcerne = new ArrayList<Month>(saison);
+ moisconcerne.retainAll(SaisonFermee);
+
+ MetierDAO metierDao = IsisFishDAOHelper.getMetierDAO(context.getDB());
+ MetierSeasonInfoDAO infoDao = IsisFishDAOHelper.getMetierSeasonInfoDAO(context.getDB());
+ EffortDescriptionDAO effortDao = IsisFishDAOHelper.getEffortDescriptionDAO(context.getDB());
+
+ Metier NouveauMetier = metierDao.create();
+ NouveauMetier.setName(metier.getName()+" Mois "+moisconcerne.get(0).getMonthNumber()+" a "+moisconcerne.get(moisconcerne.size()-1).getMonthNumber()+" ValeurParam "+nouvelleValeurParam);
+ NouveauMetier.setGear(EnginInterdit);
+ NouveauMetier.setGearParameterValue(nouvelleValeurParam);
+ NouveauMetier.setComment("m�tier cr�� pendant la simu pour le changement de param�tre contr�lable");
+
+ for (MetierSeasonInfo infsais : metier.getMetierSeasonInfo()){
+ List<Month> sais = infsais.getMonths();
+ MetierSeasonInfo NouveauInfoSaison = infoDao.create();
+ NouveauInfoSaison.setMetier(NouveauMetier);
+ NouveauInfoSaison.setMonths(sais);
+ NouveauInfoSaison.setZone(infsais.getZone());
+ NouveauInfoSaison.setComment("cr�� durant la simulation");
+ NouveauMetier.addMetierSeasonInfo(NouveauInfoSaison);
+ }
+
+ //On ajoute aux strategies qui pratiquent le m�tier le nouveau m�tier
+ List<Strategy> listestrategies = RegionSimu.getStrategy();
+ for(Strategy strategie : listestrategies){
+ SetOfVessels SetOfBateau = strategie.getSetOfVessels();
+ EffortDescription AncienEffort = SetOfBateau.getPossibleMetiers(metier);
+ if (AncienEffort != null) {
+ EffortDescription DescriptionEffort = effortDao.create();
+ DescriptionEffort.setPossibleMetiers(NouveauMetier);
+ DescriptionEffort.setSetOfVessels(SetOfBateau);
+ DescriptionEffort.setFishingOperation(AncienEffort.getFishingOperation());
+ DescriptionEffort.setFishingOperationDuration(AncienEffort.getFishingOperationDuration());
+ DescriptionEffort.setGearsNumberPerOperation(AncienEffort.getGearsNumberPerOperation());
+ DescriptionEffort.setCrewSize(AncienEffort.getCrewSize());
+ DescriptionEffort.setUnitCostOfFishing(AncienEffort.getUnitCostOfFishing());
+ DescriptionEffort.setFixedCrewSalary(AncienEffort.getFixedCrewSalary());
+ DescriptionEffort.setCrewShareRate(AncienEffort.getCrewShareRate());
+ DescriptionEffort.setCrewFoodCost(AncienEffort.getCrewFoodCost());
+ DescriptionEffort.setRepairAndMaintenanceGearCost(AncienEffort.getRepairAndMaintenanceGearCost());
+ DescriptionEffort.setLandingCosts(AncienEffort.getLandingCosts());
+ DescriptionEffort.setOtherRunningCost(AncienEffort.getOtherRunningCost());
+
+ SetOfBateau.addPossibleMetiers(DescriptionEffort);
+
+ // on a ajout� le nouveau m�tier au set of vessels,
+ // maintenant, on va report� l'effort du m�tier ancien
+ // vers le nouveau pour les mois concern�s
+ for (Month mois : Month.MONTH){
+ StrategyMonthInfo PropStratMois = strategie.getStrategyMonthInfo(mois);
+ double prop = PropStratMois .getProportionMetier(metier);
+ if (moisconcerne.contains(mois) && prop != 0){
+ //on cr�� un nouveau PropStrMet
+ log.info ("la strat�gie "+strategie.getName()+" pratique bien le metier "+metier.getName()+" au mois " + mois);
+ PropStratMois.setProportionMetier(NouveauMetier, prop);
+ PropStratMois.setProportionMetier(metier, 0);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // fin de la methode
+
+ /*
+this.p = new Object();
+this.p.paramRegle = this.param;
+
+
+//attention: cette r�gle de gestion ne fonctionne que si le changement a lieu pour toutes
+//les ann�es de simulation
+
+
+var zoneselective=this.param.getValue("ZoneSelective"); //entrez le nom de la zone concern�e, non si pas de s�lection sur zone
+var moisDeb=this.param.getValue("moisDeb"); //entrez le mois debut de fermeture
+var moisFin=this.param.getValue("moisFin");//entrez le mois de fin de fermeture
+var nouvelleValeurParam=this.param.getValue("nouvelleValeurParam");//entrez la valeur du param�tre contr�lable
+
+
+if (zoneselective!="non") {
+ var ZoneFermee=this.param.getValue("zone");
+}
+var EnginInterdit=this.param.getValue("engin");
+writeln("nom de l'engin interdit "+EnginInterdit.getNom());
+var RegionSimu=EnginInterdit.getRegion();
+var ListeMetiers=MetierFactory.findAllByRegion(RegionSimu);
+var MoisDeb=new Packages.fr.ifremer.nodb.Mois(moisDeb);
+var MoisFin=new Packages.fr.ifremer.nodb.Mois(moisFin);
+var SaisonFermee= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+
+
+
+
+for (var imetier = ListeMetiers.iterator() ; imetier.hasNext();){
+ var metier=imetier.next();
+ writeln ("metier examin� "+metier.getNom()+"son engin "+metier.getEngin().getNom());
+ if (!metier.getEngin().equals(EnginInterdit)){
+ writeln("l engin du m�tier n est pas concern�");
+ }
+ else {
+ writeln("l engin du m�tier est bien concern�");
+ if (zoneselective==false && moisDeb==0 && moisFin==11){
+ //aucun crit�re spatio-temporel il suffit donc de mettre
+ //le param controlable � la nouvelle valeur
+ metier.setValeurParamControlable(nouvelleValeurParam);
+ writeln("aucune spatialisation ni saisonnalit�, on passe le Param Controlable a "+nouvelleValeurParam);
+ }
+ else {
+ var ListeSaisons = metier.getInfoSaison();
+ for (var isaisonmetier = ListeSaisons.iterator() ; isaisonmetier.hasNext();){
+ var saisonmetier=isaisonmetier.next();
+ var saison=saisonmetier.getSaison();
+ var taille=0;
+ if (zoneselective){
+ var maillefermee=ZoneFermee.getMaille();
+ var MailleMetier=saisonmetier.getSecteur().getMaille().copy();
+ MailleMetier.retainAll(maillefermee);
+ taille=MailleMetier.size();
+ }
+ else {
+ writeln ("pas de s�lection de zone, toute la zone d'�tude est donc concern�e");
+ }
+ if (zoneselective==false || taille!=0){
+ if (saison.contains(SaisonFermee)){
+ writeln ("il y a intersection de la zone metier au cours de la saison"+saison.toString());
+ var moisconcerne=saison.copy().toListMois();
+ moisconcerne.retainAll(SaisonFermee.toListMois());
+ var NouveauMetier=MetierFactory.create(metier.getNom()+" Mois "+moisconcerne.get(0).getNumMois()+" a "+moisconcerne.get(moisconcerne.size()-1).getNumMois()+" ValeurParam "+nouvelleValeurParam, RegionSimu, EnginInterdit,nouvelleValeurParam, "m�tier cr�� pendant la simu pour le changement de param�tre contr�lable");
+ for (var iinfsais=metier.getInfoSaison().iterator();iinfsais.hasNext();){
+ var infsais=iinfsais.next();
+ var sais=infsais.getSaison();
+ var NouveauInfoSaison=InfoSaisonMetierFactory.create(NouveauMetier, sais, infsais.getSecteur(), "cr�� durant la simulation")
+ NouveauMetier.addInfoSaison(NouveauInfoSaison);
+ }
+
+ //On ajoute aux strategies qui pratiquent le m�tier le nouveau m�tier
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ for(var i=0; i<listestrategies.size(); i++){
+ var strategie=listestrategies.get(i);
+ var SetOfBateau=strategie.getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier)){
+ var AncienEffort=SetOfBateau.getEffort(metier);
+ var DescriptionEffort=EffortDescriptionFactory.create(NouveauMetier, SetOfBateau, AncienEffort.getFishingOperation(), AncienEffort.getFishingOperationDuration(), AncienEffort.getGearsNumberPerOperation(), AncienEffort.getCrewSize(), AncienEffort.getUnitCostOfFishing(), AncienEffort.getFixedCrewSalary(), AncienEffort.getCrewShareRate(), AncienEffort.getCrewFoodCost(), AncienEffort.getRepairAndMaintenanceGearCost(), AncienEffort.getLandingCosts(), AncienEffort.getOtherRunningCosts(), "effort description cr�� durant la simulation");
+
+ SetOfBateau.addPossibleMetiers(DescriptionEffort);
+
+ //on a ajout� le nouveau m�tier au set of vessels, maintenant, on va report� l'effort du m�tier ancien vers le nouveau pour les mois concern�s
+ for (var intmois=0; intmois<=11;intmois++){
+ var mois=new Packages.fr.ifremer.nodb.Mois(intmois);
+ var PropStratMois=strategie.getStrategyMonthInfo(mois);
+ var NouveauStrMet=PropStrMetFactory.create(PropStratMois, NouveauMetier, 0, "cr�� durant la simulation");
+ PropStratMois.addPropStrMet(NouveauStrMet);
+ if (moisconcerne.contains(mois) && PropStratMois.getProportionMetier(metier)!=0){
+ //on cr�� un nouveau PropStrMet
+ writeln ("la strat�gie "+strategie.getName()+" pratique bien le metier "+metier.getNom()+" au mois "+mois.getNumMois());
+ PropStratMois.setProportionMetier(NouveauMetier,new Packages.java.lang.Float(PropStratMois.getProportionMetier(metier)));
+ PropStratMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+ */
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ return false;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+}
Added: branches/3.1.0/rules/GraviteCPUE.java
===================================================================
--- branches/3.1.0/rules/GraviteCPUE.java (rev 0)
+++ branches/3.1.0/rules/GraviteCPUE.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,484 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.GravityModel;
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * GraviteCPUE.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-07-18 08:59:38 $
+ * by : $Author: hilaire $
+ */
+public class GraviteCPUE extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(GraviteCPUE.class);
+
+ /** stocke la somme des prop initiales [str x month] */
+ private MatrixND SommePropInitial = null;
+ /** stocke par strat*met, la derni�re attractivite pour chaque mois
+ * [str x met x month] */
+ private MatrixND HistoriqueCPUE = null;
+
+ /** va permettre de stocker a chaque pas de temps la somme des attractivite [str] */
+ MatrixND SommeCPUEstrat = null;
+ /** va permettre de stocker a chaque pas de temps la somme des proportions
+ * pour les metiers n'ayant pas d'attractivite [str] */
+ MatrixND SommeProp = null;
+
+ /** permet de stocker les CPUE standardiser [str x met] */
+ private MatrixND catchPerUnitOfEffort = null;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET,
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ // TODO
+ return _("GraviteCPUE");
+ }
+
+ /**
+ * function used to initialise MatrixND to NaN double
+ */
+ private MapFunction nanFunction = new MapFunction() {
+ public double apply(double value) {
+ return Double.NaN;
+ }
+ };
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ Date date = new Date(0);
+
+ List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date);
+ List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date);
+ List<Month> months = Arrays.asList(Month.MONTH);
+
+ SommePropInitial = MatrixFactory.getInstance().create("SommePropInitial",
+ new List[]{strs, months}, new String[]{"Strategies", "Months"});
+ SommePropInitial.map(nanFunction);
+
+ HistoriqueCPUE = MatrixFactory.getInstance().create("HistoriqueCPUE",
+ new List[]{strs, metiers, months}, new String[]{"Strategies", "Metiers", "Months"});
+ HistoriqueCPUE.map(nanFunction);
+
+
+ SommeCPUEstrat = MatrixFactory.getInstance().create("SommeCPUEstrat",
+ new List[]{strs}, new String[]{"Strategies"});
+ SommeCPUEstrat.map(nanFunction);
+
+ SommeProp = MatrixFactory.getInstance().create("SommeProp",
+ new List[]{strs}, new String[]{"Strategies"});
+ SommeProp.map(nanFunction);
+
+ catchPerUnitOfEffort = MatrixFactory.getInstance().create("ValuePerUnitOfEffort",
+ new List[]{strs, metiers}, new String[]{"Strategies", "Metiers"});
+ catchPerUnitOfEffort.map(nanFunction);
+
+ for (Strategy str : strs) {
+ List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date);
+ List<StrategyMonthInfo> infos = str.getStrategyMonthInfo();
+ for (StrategyMonthInfo info : infos) {
+ double somme = 0;
+ for (Metier strMetier : strMetiers) {
+ somme += info.getProportionMetier(strMetier);
+ }
+ // FIXME soit on somme pour toutes les str le meme metier; donc pas de notion de str.getName dans la cle
+ // soit pour une str on somme tous ces metiers (mais ce doit etre 1; donc pas de notion de metier.getName dans la cle
+ SommePropInitial.setValue(str, info.getMonth(), somme);
+ }
+ }
+
+/*
+var allStr = SiMatrice.getListStrategies();
+
+for(var i=0; i<allStr.size(); i++){
+ var str=allStr.get(i);
+ var metiers=str.getSetOfVessels().getMetiers();
+ var ListeStrMonthInfos=str.getStrategyMonthInfos();
+ for (var j=0; j<ListeStrMonthInfos.size();j++){
+ var somme=0;
+ var StrMonthInfo=ListeStrMonthInfos.get(j);
+ for (var k=0;k<metiers.size();k++){
+ var metier=metiers.get(k);
+ somme+=StrMonthInfo.getProportionMetier(metier);
+ }
+ this.p.SommePropInitial.put(new Chaine(str.getName()+"-"+metier.getNom()+"-"+StrMonthInfo.getMonth().getNumMois()),somme);
+ }
+}
+
+ //permet de stocker les CPUE standardiser
+CatchperUnitOfEffort = MatrixFactory.create("ValuePerUnitOfEffort",new Array(allStr,SiMatrice.getListMetiers()),new Array("Strategies","Metiers"));
+*/
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ // Il faut etre au moins au deuxieme pas de temps.
+ // FIXME 2eme pas de temps ou 2eme annee ? ici c 2eme annee et non pas 2eme mois
+ return date.getYear() > 0;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ if (log.isDebugEnabled()) {
+ log.debug("Gravite Action avant metier:"+ metier + "date:"+ date);
+ }
+
+ List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date);
+ List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date);
+
+ double newPropDiv = 0;
+
+ ResultStorage resultmanager = context.getSimulationStorage().getResultStorage();
+
+ //on commence par creer une matrice de capture par strategie met
+ MatrixND catchWeigthPerStrMet = null;
+ for (Population pop : populations){
+ MatrixND temp = resultmanager.getMatrix(
+ date.previousYear(),
+ pop,
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ // on somme sur les zones
+ temp=temp.sumOverDim(3);
+ // on somme sur les groupes
+ temp=temp.sumOverDim(2);
+ if (catchWeigthPerStrMet == null) {
+ catchWeigthPerStrMet = temp;
+ } else {
+ catchWeigthPerStrMet.add(temp);
+ }
+ }
+
+ MatrixND effortPerStrMet = resultmanager.getMatrix(
+ date.previousYear(),
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+
+ for (Strategy str : strs){
+ List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date);
+ for (Metier strMetier : strMetiers){
+ double effort = effortPerStrMet.getValue(str, strMetier);
+ if (effort > 0){
+ EffortDescription effortdesc = str.getSetOfVessels().getPossibleMetiers(strMetier);
+ int nombreop=effortdesc.getFishingOperation();
+ int nombregear=effortdesc.getGearsNumberPerOperation();
+ double param=strMetier.getGearParameterValueAsDouble();
+ double facteur = param * nombreop * nombregear*strMetier.getGear().getStandardisationFactor() / 24.0;
+ //on restandardise l'effort
+ effort /= facteur;
+ //on recupere la capture tot
+ Object group = catchWeigthPerStrMet.getSemantics(2).get(0);
+ Object zone = catchWeigthPerStrMet.getSemantics(3).get(0);
+
+ double capture = catchWeigthPerStrMet.getValue(str, strMetier, group, zone);
+
+ catchPerUnitOfEffort.setValue(str, strMetier, capture/effort);
+ }
+ }
+ }
+
+
+
+ for (Strategy str : strs){
+ List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date);
+ StrategyMonthInfo info = str.getStrategyMonthInfo(date.getMonth());
+
+ if(strMetiers.contains(metier)){
+ // on verifie que le metier est bien un metier possible
+ double CPUE = Double.NaN;
+ if (SommeCPUEstrat.getValue(str) == Double.NaN){
+ if (effortPerStrMet.getValue(str, metier) > 0){
+ CPUE = catchPerUnitOfEffort.getValue(str, metier);
+ }
+ }
+
+ if (CPUE != Double.NaN){
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE l'ann�e n-1, on la met dans l'historique\n" + info + " " + metier);
+ }
+ HistoriqueCPUE.setValue(str, metier, info.getMonth(), CPUE);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("ou calcul d�j� fait ou pas de CPUE � l'ann�e n-1");
+ }
+ CPUE = HistoriqueCPUE.getValue(str, metier, info.getMonth());
+ if (CPUE != Double.NaN) {
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE dans le pass�: " + CPUE);
+ }
+ } else{
+ if (log.isDebugEnabled()) {
+ log.debug("on a pas de CPUE dans le pass�, on remet donc la poportion initiale");
+ }
+ }
+ }
+ if (CPUE != Double.NaN) {
+ // si on a une CPUE, il faut aller voir l'attractivite des autres metiers: 2 cas de figure:
+ // soit on en retrouve une dans le passe qui est son attractivite
+ // soit on en retrouve pas et dans ce cas le, la proportion d'effort sera celle initiale de la db
+ // on a alors newProp=(1-sum(pmet1))*CPUE/somme(CPUEmet2)
+ // avec pmet1 la proprtion initiale pour les metiers pour lesquels on a pas retrouve de CPUE, CPUEmet2, la CPUE pour les
+ // metiers qui ont eu une CPUE dans le passe, et CPUE la CPUE du metier courant
+ if (SommeCPUEstrat.getValue(str) == Double.NaN){
+ double SommeCPUE=0;
+ double PropTot=0;
+ for (Metier strMetier : strMetiers){
+ double temp = Double.NaN;
+ if (effortPerStrMet.getValue(str, strMetier) > 0){
+ temp = catchPerUnitOfEffort.getValue(str, strMetier);
+ }
+ if (temp != Double.NaN){
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE l'ann�e n-1, on l'ajoute � p.SommeCPUEstrat");
+ }
+ HistoriqueCPUE.setValue(str, metier, info.getMonth(), temp);
+ SommeCPUE += temp;
+ }
+ else{
+ if (log.isDebugEnabled()) {
+ log.debug("on a pas de CPUE l'ann�e n-1, on regarde si il y en a dans le pass�");
+ }
+ temp = HistoriqueCPUE.getValue(str, metier, info.getMonth());
+ if (temp != Double.NaN){
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE dans le pass�: "+temp);
+ }
+ SommeCPUE+=temp;
+ }
+ else{
+ if (log.isDebugEnabled()) {
+ log.debug("on a pas de CPUE dans le pass�, on l'ajoute donc � p.SommeProp");
+ }
+ PropTot += info.getProportionMetier(strMetier);
+ }
+ }
+ }
+ SommeCPUEstrat.setValue(str, SommeCPUE);
+ SommeProp.setValue(str, PropTot);
+ }
+
+ if (SommeCPUEstrat.getValue(str) > 0){
+ newPropDiv = (SommePropInitial.getValue(str, info.getMonth()) - SommeProp.getValue(str))
+ * CPUE / SommeCPUEstrat.getValue(str);
+ if (log.isDebugEnabled()) {
+ log.debug("newpropdiv: " + newPropDiv);
+ }
+ info.setProportionMetier(metier, newPropDiv);
+ }
+ else { // c'est le cas e priori quasi impossible oe y a toujours eu une CPUE nulle quelquesoit le metier, dans ce cas le on remet aussi la prop iniitiale
+ if (log.isDebugEnabled()) {
+ log.debug("aucun metier n'a d'attractivite, on remet la prop initiale");
+ }
+ }
+ }
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("fin Gravite CPUEAction avant");
+ }
+
+/*
+writeln("Gravite Action avant metier:"+p.metier+ "date:"+ p.date);
+var Chaine=Packages.java.lang.String;
+
+
+
+var month=p.date.getMois();
+var allStr = SiMatrice.getListStrategies();
+var newPropDiv=0.0;
+
+if (!p.CalculCatch){
+ var resultmanager=control.getResultatManager();
+
+ //on commence par creer une matrice de capture par strategie met
+ var ListePopulation=SiMatrice.getListPopulations();
+ pop=ListePopulation.get(0);
+ var CaptureParStrMet=resultmanager.getMatrix(new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12),pop,"matriceCatchWeightPerStrategyMet");
+ CaptureParStrMet=CaptureParStrMet.sumOverDim(3);
+ CaptureParStrMet=CaptureParStrMet.sumOverDim(2);
+ writeln(CaptureParStrMet);
+ for (var ipop=1;ipop<ListePopulation.size();ipop++){
+ var pop=ListePopulation.get(ipop);
+ var temp=resultmanager.getMatrix(new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12),pop,"matriceCatchWeightPerStrategyMet");
+ temp=temp.sumOverDim(3);
+ temp=temp.sumOverDim(2);
+ writeln(temp);
+ CaptureParStrMet.add(temp);
+ writeln(CaptureParStrMet);
+ }
+
+ var Effort=resultmanager.getMatrix(new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12),"matriceEffortPerStrategyMet");
+ writeln("on r�cup�re la matrice d'effort");
+ for (var iStrategie=allStr.iterator();iStrategie.hasNext();){
+ var Strategie=iStrategie.next();
+ var listeMet=Strategie.getSetOfVessels().getMetiers();
+ for (imetier=listeMet.iterator();imetier.hasNext();){
+ var metier=imetier.next();
+ var effort=Effort.getValue(Strategie,metier);
+ if (effort>0){
+ var effortdesc=Strategie.getSetOfVessels().getEffort(metier);
+ var nombreop=effortdesc.getFishingOperation();
+ var nombregear=effortdesc.getGearsNumberPerOperation();
+ var param=metier.getValeurParamControlable();
+ var facteur=metier.getValeurParamControlable()*nombreop*nombregear/24.0;
+ //on restandardise l'effort
+ effort/=facteur;
+ //on recupere la capture tot
+ var dim3=new Packages.java.util.ArrayList(CaptureParStrMet.getSemantics(3));
+ var dim2=new Packages.java.util.ArrayList(CaptureParStrMet.getSemantics(2));
+
+ var capture=CaptureParStrMet.getValue(Strategie,metier,dim2.get(0),dim3.get(0));
+
+ p.CatchperUnitOfEffort.setValue(Strategie,metier,capture/effort);
+ }
+ }
+ }
+ p.CalculCatch=true;
+}
+
+
+
+for(var i=0; i<allStr.size(); i++){
+ var str = allStr.get(i);
+ var strMonthInfo = str.getStrategyMonthInfo(month);
+ var propStrMet = strMonthInfo.getPropStrMetier(p.metier);
+
+ if(str.getSetOfVessels().getMetiers().contains(p.metier)){
+//on verifie que le metier est bien un metier possible
+ var CPUE=null;
+ if (!p.SommeCPUEstrat.containsKey(new Chaine(str.getName()))){
+ if (GravityModel.getEffortPerStrategyMet(str, p.metier, new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12))>0){
+ CPUE=p.CatchperUnitOfEffort.getValue(str,p.metier);
+ }
+ }
+ if (CPUE!=null){
+ writeln("on a une CPUE l'ann�e n-1, on la met dans l'historique");
+ writeln(strMonthInfo+" "+p.metier);
+ p.HistoriqueCPUE.put(new Chaine(str.getName()+"-"+p.metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()),CPUE);
+ }
+ else{
+ writeln ("ou calcul d�j� fait ou pas de CPUE � l'ann�e n-1");
+ CPUE=p.HistoriqueCPUE.get(new Chaine(str.getName()+"-"+p.metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()));
+ if (CPUE!=null){
+ writeln ("on a une CPUE dans le pass�: "+CPUE);
+ }
+ else{
+ writeln ("on a pas de CPUE dans le pass�, on remet donc la poportion initiale");
+ }
+ }
+ if (CPUE!=null) {
+//si on a une CPUE, il faut aller voir l'attractivite des autres metiers: 2 cas de figure:
+// soit on en retrouve une dans le passe qui est son attractivite
+// soit on en retrouve pas et dans ce cas le, la proportion d'effort sera celle initiale de la db
+//on a alors newProp=(1-sum(pmet1))*CPUE/somme(CPUEmet2)
+//avec pmet1 la proprtion initiale pour les metiers pour lesquels on a pas retrouve de CPUE, CPUEmet2, la CPUE pour les
+//metiers qui ont eu une CPUE dans le passe, et CPUE la CPUE du metier courant
+ if (!p.SommeCPUEstrat.containsKey(str.getName())){
+ var SommeCPUE=0;
+ var PropTot=0;
+ var metiers=str.getSetOfVessels().getMetiers();
+ for (var imetiers=metiers.iterator();imetiers.hasNext();){
+ var metier=imetiers.next();
+ var temp=null;
+ if (GravityModel.getEffortPerStrategyMet(str, metier, new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12))>0){
+ temp=p.CatchperUnitOfEffort.getValue(str,metier);
+ }
+ if (temp!=null){
+ writeln("on a une CPUE l'ann�e n-1, on l'ajoute � p.SommeCPUEstrat");
+ p.HistoriqueCPUE.put(new Chaine(str.getName()+"-"+metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()),CPUE);
+ SommeCPUE+=temp;
+ }
+ else{
+ writeln ("on a pas de CPUE l'ann�e n-1, on regarde si il y en a dans le pass�");
+ temp=p.HistoriqueCPUE.get(new Chaine(str.getName()+"-"+metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()));
+ if (temp!=null){
+ writeln ("on a une CPUE dans le pass�: "+temp);
+ SommeCPUE+=temp;
+ }
+ else{
+ writeln ("on a pas de CPUE dans le pass�, on l'ajoute donc � p.SommeProp");
+ PropTot+=strMonthInfo.getProportionMetier(metier);
+ }
+ }
+ }
+ p.SommeCPUEstrat.put(new Chaine(str.getName()),SommeCPUE);
+ p.SommeProp.put(new Chaine(str.getName()),PropTot);
+ }
+ if (p.SommeCPUEstrat.get(new Chaine(str.getName()))>0){
+ newPropDiv = (p.SommePropInitial.get(new Chaine(str.getName()+"-"+strMonthInfo.getMonth().getNumMois()))-p.SommeProp.get(new Chaine(str.getName())))*CPUE/ p.SommeCPUEstrat.get(new Chaine(str.getName()));
+ writeln("newpropdiv: "+newPropDiv);
+ strMonthInfo.setProportionMetier(p.metier, new Packages.java.lang.Float(newPropDiv));
+ }
+ else { // c'est le cas e priori quasi impossible oe y a toujours eu une CPUE nulle quelquesoit le metier, dans ce cas le on remet aussi la prop iniitiale
+ writeln("aucun metier n'a d'attractivite, on remet la prop initiale");
+ }
+ }
+ }
+}
+
+writeln("fin Gravite CPUEAction avant");
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ SommeCPUEstrat.map(nanFunction);
+ SommeProp.map(nanFunction);
+ catchPerUnitOfEffort.map(nanFunction);
+ }
+
+}
Added: branches/3.1.0/rules/InterdictionEngin.java
===================================================================
--- branches/3.1.0/rules/InterdictionEngin.java (rev 0)
+++ branches/3.1.0/rules/InterdictionEngin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,272 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * InterdictionEngin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class InterdictionEngin extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(InterdictionEngin.class);
+
+ public Gear param_gear = null;
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(119);
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Prohibited gear");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ // TODO
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("condition fermeture zone");
+ boolean result = true;
+ Month mois = date.getMonth();
+ log.info("mois:" + mois);
+ if(!(param_beginMonth.getMonthNumber()<=mois.getMonthNumber()
+ && mois.getMonthNumber()<=param_endMonth.getMonthNumber())) {
+ result = false;
+ } else {
+ log.info("on est dans l'espace des mois possible");
+ if(date.before(param_beginDate)) {
+ result = false;
+ } else if(date.after(param_endDate)) {
+ result = false;
+ } else if (!metier.getGear().equals(param_gear)) {
+ result = false;
+ }
+ }
+
+ return result;
+ // fin condition
+
+ /*
+writeln("condition fermeture zone");
+var result=true;
+var mois = p.date.getMois().getNumMois();
+writeln("mois:"+mois);
+if(!(p.moisDeb<=mois && mois<=p.moisFin))
+ return false;
+writeln("on est dans l'espace des mois possible");
+//on est dans l'espace des mois possible
+if(p.date.before(p.dateDeb))
+ return false;
+if(p.date.after(p.dateFin))
+ return false;
+if (!p.metier.getEngin().equals(p.engin))
+ return false;
+
+
+return result;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("le metier vise par l'interdiction : " + metier);
+
+ MetierMonitor metierMon = context.getMetierMonitor();
+ metierMon.addforbiddenMetier(metier);
+
+ // r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ List<Strategy> strs = siMatrix.getStrategies(date);
+ List<Strategy> ListeStrat = new ArrayList<Strategy>();
+
+ for (Strategy str : strs) {
+ double prop = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ if (prop != 0) {
+ ListeStrat.add(str);
+ }
+ }
+
+ for (Strategy Strat : ListeStrat) {
+ StrategyMonthInfo StratMonthInfo = Strat.getStrategyMonthInfo(date.getMonth());
+
+ // 1er cas:l'effort est reporte sur un metier de la meme strategie,
+ // n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ List<EffortDescription> MetiersPossibles= new ArrayList<EffortDescription>(Strat.getSetOfVessels().getPossibleMetiers());
+
+ // on verifie que les metiers sont bien pratiques au mois courant,
+ // qu'ils n'ont pas le meme engin et qu'ils ne sont pas
+ // interdits par ailleurs
+ for (Iterator<EffortDescription> effort=MetiersPossibles.iterator(); effort.hasNext();) {
+ Metier met = effort.next().getPossibleMetiers();
+ if (StratMonthInfo.getProportionMetier(met) == 0
+ || met.getGear().equals(metier.getGear())
+ || met.getName().equalsIgnoreCase("nonActivite")
+ || metierMon.isForbidden(metier, date.getMonth())){
+ effort.remove();
+ }
+ }
+
+ // on repartit maintenant l'effort entre les differents metiers
+ // possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size() != 0){
+ int NbMetier=MetiersPossibles.size();
+ for (EffortDescription effort : MetiersPossibles) {
+ Metier met = effort.getPossibleMetiers();
+ double NouvelleProportion =
+ StratMonthInfo.getProportionMetier(met)
+ + (StratMonthInfo.getProportionMetier(metier) / NbMetier);
+ StratMonthInfo.setProportionMetier(met, NouvelleProportion);
+ }
+ StratMonthInfo.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ }
+ // s'il n'y a pas de metier alternatif, on passe a nonActivite
+ else{
+ MatrixND matNonActivite = metierMon.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ matNonActivite.setValue(Strat, metier, StratMonthInfo.getProportionMetier(metier));
+ StratMonthInfo.setProportionMetier(metier,0);
+ }
+ }
+
+ // fin methode
+
+ /*
+var Chaine=Packages.java.lang.String;
+writeln("Action avant");
+var metier=p.metier;
+writeln("le metier vise par l'interdiction : "+metier);
+
+
+MetiersInterdits.put(new Chaine(p.metier.getNom(),true));
+//r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+var ListeStrat=new Packages.org.codelutin.dbobject.DBCollection(StrategyFactory);
+var Vessels=SetOfVesselsFactory.findAllByRegion(p.metier.getRegion());
+for (var ves=0; ves<Vessels.size();ves++){
+ if (Vessels.get(ves).getMetiers().contains(p.metier)){
+ var listestrattemp=StrategyFactory.findAllBySetOfVessels(Vessels.get(ves)).copy();
+ for (var strat=0;strat<listestrattemp.size();strat++){
+ var proportion=listestrattemp.get(strat).getStrategyMonthInfo(p.date.getMois()).getProportionMetier(p.metier) //on recupere la proportion d'effort attribue au metier
+ if (proportion!=0){
+ listestrattemp.removeAll(ListeStrat);
+ ListeStrat.addAll(listestrattemp);//permet d'obtenir une liste sans doublon
+ }
+ }
+ }
+}
+
+
+
+for (iStrat=ListeStrat.iterator();iStrat.hasNext();){
+ var Strat=iStrat.next();
+ var StratMonthInfo=Strat.getStrategyMonthInfo(p.date.getMois());
+ //1er cas:l'effort est reporte sur un metier de la meme strategie, n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ var MetiersPossibles=Strat.getSetOfVessels().getMetiers().copy();
+
+ //on verifie que les metiers sont bien pratiques au mois courant, qu'ils n'ont pas le meme ont le meme engin et qu'ils ne sont pas interdits par ailleurs
+ for (var imet=MetiersPossibles.iterator();imet.hasNext();){
+ var met=imet.next();
+ if (StratMonthInfo.getProportionMetier(met)==0 || met.getEngin().equals(p.metier.getEngin()) || met.getNom()=="nonActivite" || MetiersInterdits.containsKey(new Chaine(met.getNom())) || MetiersInterditsPresimu.containsKey(new Chaine(met.getNom()+"-"+p.date.getMois().getNumMois()))){
+ MetiersPossibles.remove(met);
+ }
+ }
+
+ //on repartit maintenant l'effort entre les differents metiers possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size()!=0){
+ var NbMetier=MetiersPossibles.size();
+ for (imet=MetiersPossibles.iterator();imet.hasNext();){
+ met=imet.next();
+ var NouvelleProportion=StratMonthInfo.getProportionMetier(met)+(StratMonthInfo.getProportionMetier(p.metier)/NbMetier);
+ StratMonthInfo.setProportionMetier(met, new Packages.java.lang.Float(NouvelleProportion))
+ }
+ StratMonthInfo.setProportionMetier(p.metier, new Packages.java.lang.Float(0)) //le metier vise a alors une proportion nulle
+ }
+//s'il n'y a pas de metier alternatif, on passe a nonActivite
+ else{
+ var matNonActivite=nonActivite.get(p.date);
+ var nonactivite=matNonActivite!=null;
+ if (!nonactivite){
+ matNonActivite=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ nonActivite.put(p.date,matNonActivite);
+ }
+
+ matNonActivite.setValue(Strat,p.metier,InfoMois.getProportionMetier(p.metier));
+ StratMonthInfo.setProportionMetier(p.metier,new Packages.java.lang.Float(0));
+ }
+}
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+}
Added: branches/3.1.0/rules/InterdictionEnginPreSimu.java
===================================================================
--- branches/3.1.0/rules/InterdictionEnginPreSimu.java (rev 0)
+++ branches/3.1.0/rules/InterdictionEnginPreSimu.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,296 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * InterdictionEngin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class InterdictionEnginPreSimu extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(InterdictionEnginPreSimu.class);
+
+ public Gear param_gear = null;
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>();
+ protected boolean affectNonActivite = false;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Prohibited gear");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ MetierMonitor metierMon = context.getMetierMonitor();
+
+ Month moisDeb = param_beginMonth;
+ Month moisFin = param_endMonth;
+ Gear EnginInterdit = param_gear;
+
+ log.info("nom de l'engin interdit "+EnginInterdit.getName());
+ FisheryRegion RegionSimu = RegionStorage.getFisheryRegion(context.getDB());
+ List<Metier> ListeMetiers = RegionSimu.getMetier();
+
+ for (Metier metier : ListeMetiers) {
+ if (metier.getGear().equals(EnginInterdit)) {
+ //r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ List<Strategy> ListeStrat=RegionSimu.getStrategy();
+ for (Strategy Strat : ListeStrat){
+ SetOfVessels vessels = Strat.getSetOfVessels();
+ if (vessels.getPossibleMetiers(metier) != null){
+ for (Month mois : Month.getMonths(param_beginMonth, param_endMonth)) {
+ StrategyMonthInfo StratMonthInfo = Strat.getStrategyMonthInfo(mois);
+ metierMon.addforbiddenMetier(metier, mois);
+
+ //1er cas:l'effort est reporte sur un metier de la meme strategie, n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ List<EffortDescription> MetiersPossibles =
+ new ArrayList<EffortDescription>(Strat.getSetOfVessels().getPossibleMetiers());
+
+ // on verifie que les metiers sont bien pratiques au mois courant,
+ // qu'ils n'ont pas le meme ont le meme engin et qu'ils ne sont
+ // pas interdits par ailleurs
+ for (Iterator<EffortDescription> effort=MetiersPossibles.iterator(); effort.hasNext();) {
+ Metier met = effort.next().getPossibleMetiers();
+ if (StratMonthInfo.getProportionMetier(met) == 0
+ || met.getGear().equals(metier.getGear())
+ || met.getName().equalsIgnoreCase("nonActivite")
+ || metierMon.isForbidden(metier, mois)){
+ effort.remove();
+ }
+ }
+
+ //on repartit maintenant l'effort entre les differents metiers possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size() != 0){
+ int NbMetier=MetiersPossibles.size();
+ for (EffortDescription effort : MetiersPossibles) {
+ Metier met = effort.getPossibleMetiers();
+ double NouvelleProportion =
+ StratMonthInfo.getProportionMetier(met)
+ + (StratMonthInfo.getProportionMetier(metier) / NbMetier);
+ StratMonthInfo.setProportionMetier(met, NouvelleProportion);
+ }
+ StratMonthInfo.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ }
+ else{
+ log.info("debut reportNonActivite");
+ // on regarde si on a d�j� une entr�e pour le mois courant
+ MatrixND matNonActiviteMois=tableNonActivite.get(mois);
+ if (matNonActiviteMois == null){
+ matNonActiviteMois = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NO_ACTIVITY,
+ new List[]{ListeStrat, ListeMetiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+ tableNonActivite.put(mois, matNonActiviteMois);
+ }
+
+ matNonActiviteMois.setValue(Strat, metier, StratMonthInfo.getProportionMetier(metier));
+ log.info("fin reportNonActivite");
+
+ StratMonthInfo.setProportionMetier(metier, 0);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // fin methode
+
+ /*
+this.param = param;
+
+//construction de p
+this.p = new Object();
+this.p.paramRegle = this.param;
+this.p.tableNonActivite=new Packages.java.util.HashMap();
+this.p.affectNonActivite=false;
+
+//attention: cette r�gle de gestion ne fonctionne que si le changement a lieu pour toutes
+//les ann�es de simulation
+
+
+var moisDeb=this.param.getValue("moisDeb"); //entrez le mois debut de fermeture
+var moisFin=this.param.getValue("moisFin");//entrez le mois de fin de fermeture
+var EnginInterdit=this.param.getValue("engin");
+
+writeln("nom de l'engin interdit "+EnginInterdit.getNom());
+var RegionSimu=EnginInterdit.getRegion();
+var ListeMetiers=MetierFactory.findAllByRegion(RegionSimu);
+
+for (var imetier=ListeMetiers.iterator();imetier.hasNext();){
+ var metier=imetier.next();
+ if (metier.getEngin().equals(EnginInterdit)){
+ //r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ var ListeStrat=SiMatrice.getListStrategies();
+ for (iStrat=ListeStrat.iterator();iStrat.hasNext();){
+ var Strat=iStrat.next();
+ var vessels=Strat.getSetOfVessels();
+ if (vessels.getMetiers().contains(metier)){
+ for (var imois=moisDeb; imois<=moisFin;imois++){
+ var mois=new Packages.fr.ifremer.nodb.Mois(imois);
+ var StratMonthInfo=Strat.getStrategyMonthInfo(mois);
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ //1er cas:l'effort est reporte sur un metier de la meme strategie, n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ var MetiersPossibles=Strat.getSetOfVessels().getMetiers().copy();
+ var MetiersPossibles2=Strat.getSetOfVessels().getMetiers().copy();
+ //on verifie que les metiers sont bien pratiques au mois courant, qu'ils n'ont pas le meme ont le meme engin et qu'ils ne sont pas interdits par ailleurs
+ for (var imet=MetiersPossibles2.iterator();imet.hasNext();){
+ var met=imet.next();
+ if (StratMonthInfo.getProportionMetier(met)==0 || met.getEngin().equals(metier.getEngin()) || met.getNom()=="nonActivite" || MetiersInterditsPresimu.containsKey(new Chaine(met.getNom()+"-"+mois.getNumMois()))){
+ MetiersPossibles.remove(met);
+ }
+ }
+
+ //on repartit maintenant l'effort entre les differents metiers possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size()!=0){
+ var NbMetier=MetiersPossibles.size();
+ for (imet=MetiersPossibles.iterator();imet.hasNext();){
+ met=imet.next();
+ var NouvelleProportion=StratMonthInfo.getProportionMetier(met)+(StratMonthInfo.getProportionMetier(metier)/NbMetier);
+ StratMonthInfo.setProportionMetier(met, new Packages.java.lang.Float(NouvelleProportion))
+ }
+ StratMonthInfo.setProportionMetier(metier, new Packages.java.lang.Float(0)) //le metier vise a alors une proportion nulle
+ }
+ //s'il n'y a pas de metier alternatif, on passe e nonActivite
+ else{
+ p.tableNonActivite=Regle_action_lib.reportNonActivite(p.tableNonActivite, Strat, metier, mois, StratMonthInfo.getProportionMetier(metier));
+ StratMonthInfo.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ }
+ }
+ }
+ }
+ }
+}
+ */
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ boolean result = false;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+ if (mat != null && affectNonActivite == false) {
+ result = true;
+ }
+ return result;
+ // fin
+
+ /*
+var mat=p.tableNonActivite.get(p.date.getMois());
+writeln(p.affectNonActivite);
+if(oldValue != undefined)
+ return oldValue;
+else if (mat!=null && p.affectNonActivite==false){
+ return true;
+}
+else {return false;}
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // on ne doit le faire qu'une seul fois quelque soit le nombre de metier
+ affectNonActivite=true;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND noActivity = metierMon.getNoActivity(date);
+
+ if (noActivity == null){
+ metierMon.setNoActivity(date, mat.copy());
+ }
+ else{
+ noActivity = noActivity.add(mat);
+ }
+ // fin
+
+ /*
+p.affectNonActivite=true;
+var mat=p.tableNonActivite.get(p.date.getMois());
+var matNonActivite=nonActivite.get(p.date);
+var nonactivite=matNonActivite!=null;
+if (!nonactivite){
+ nonActivite.put(p.date,mat);
+}
+else{
+ matNonActivite=matNonActivite.add(mat);
+}
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ affectNonActivite = false;
+
+ /*
+ p.affectNonActivite=false;
+return p.gestionMetier;
+ */
+ }
+
+}
Added: branches/3.1.0/rules/RecrutementLangoustine.java
===================================================================
--- branches/3.1.0/rules/RecrutementLangoustine.java (rev 0)
+++ branches/3.1.0/rules/RecrutementLangoustine.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,174 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.util.StringUtil;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RecrutementLangoustine.java
+ *
+ * Created: 22 mars 2007
+ *
+ * @author stephanie MAHEVAS <smahevas(a)ifremer.fr>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-03-22 17:33:56 $
+ * by : $Author: bpoussin $
+ */
+public class RecrutementLangoustine extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RecrutementLangoustine.class);
+
+ public double param_recrut1998 =0;
+ public double param_recrut1999 =0;
+ public double param_recrut2000 =0;
+ public double param_recrut2001 =0;
+ public double param_recrut2002 =0;
+ public double param_recrut2003 =0;
+ public double param_recrut2004 =0;
+ public double param_recrut2005 =0;
+
+ public double [] recru = null;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ // TODO
+ return _("TODO description rule");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ // remarque on pourrait aussi avoir un seul parametre de regle
+ // par exemple param_recru_depuis_1998 = "0;0;0;0;0;0;0;0";
+ // on ferait alors
+ // recru = StringUtil.toArrayDouble(param_recru_depuis_1998.split(";"));
+
+ recru = new double[]{
+ param_recrut1998,
+ param_recrut1999,
+ param_recrut2000,
+ param_recrut2001,
+ param_recrut2002,
+ param_recrut2003,
+ param_recrut2004,
+ param_recrut2005,
+ };
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ boolean result = false;
+ if (date.getMonth().equals(Month.SEPTEMBER) ||
+ date.getMonth().equals(Month.OCTOBER)
+ || date.getMonth().equals(Month.NOVEMBER)
+ ||date.getMonth().equals(Month.DECEMBER)) {
+ result = true;
+ }
+ return result;
+/*
+writeln("recrutement CIEM");
+var mois = p.date.getMois().getNumMois();
+//si le recrutement a lieu en octobre
+if( mois==8 ||mois==9 || mois==10 || mois==11){
+//??&& p.oprfaite==false{
+var result = true;
+}
+ return result ;
+*/
+
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant
+le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ TopiaContext db = context.getDB();
+
+ PopulationDAO popDao = IsisFishDAOHelper.getPopulationDAO(db);
+ Population pop = popDao.findByName("nephrops");
+ PopulationGroup group0 = pop.getPopulationGroup().get(0);
+
+ ZoneDAO zoneDao = IsisFishDAOHelper.getZoneDAO(db);
+ Zone zone1 = zoneDao.findByName("zone L21E7");
+ Zone zone2 = zoneDao.findByName("zone L21E8");
+ Zone zone3 = zoneDao.findByName("zone L22E6");
+ Zone zone4 = zoneDao.findByName("zone L22E7");
+ Zone zone5 = zoneDao.findByName("zone L23E5");
+ Zone zone6 = zoneDao.findByName("zone L23E6");
+ Zone zone7 = zoneDao.findByName("zone L23E7");
+ Zone zone8 = zoneDao.findByName("zone L24E5");
+ Zone zone9 = zoneDao.findByName("zone L24E6");
+
+ int year = date.getYear();
+ MatrixND matN = context.getPopulationMonitor().getN(pop);
+
+ double coefR =4/(Math.exp(-0.6/12))*(1+ Math.exp(-0.3/12)+ Math.exp(-0.6/12)+ Math.exp(-0.9/12));
+
+ double R = recru[year] * coefR / 9.0;
+
+ matN.setValue(group0, zone1, R);
+ matN.setValue(group0, zone2, R);
+ matN.setValue(group0, zone3, R);
+ matN.setValue(group0, zone4, R);
+ matN.setValue(group0, zone5, R);
+ matN.setValue(group0, zone6, R);
+ matN.setValue(group0, zone7, R);
+ matN.setValue(group0, zone8, R);
+ matN.setValue(group0, zone9, R);
+
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // TODO
+ }
+
+}
\ No newline at end of file
Added: branches/3.1.0/rules/TACpoids.java
===================================================================
--- branches/3.1.0/rules/TACpoids.java (rev 0)
+++ branches/3.1.0/rules/TACpoids.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,300 @@
+package rules;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import scripts.RuleUtil;
+import scripts.SiMatrix;
+
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.entities.TargetSpecies;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * TAC.java
+ *
+ * Created: 7 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.5 $
+ *
+ * Last update: $Date: 2007-11-20 15:50:09 $
+ * by : $Author: bpoussin $
+ */
+
+/**
+ * TAC peut-etre utilis� pour les diff�rents TAC, en proportion des effectifs
+ * et/ou avec survie ou non.
+ *
+ * <li>Pour utiliser le tac proportionnel, il faut mettre dans le parametre propTac
+ * une valeur > 0, le TAC sera alors recalcul� a chaque mois de janvier.
+ * <li>Pour utiliser la survie il faut mettre dans le param�tre propSurvie
+ * une valeur > 0, automatiquement les suvie seront ajout� aux effectifs
+ *
+ */
+public class TACpoids extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(TACpoids.class);
+
+ public Species param_species = null;
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(22);
+ public double param_propSurvie = 0;
+ public double param_propTac = 0;
+
+ /** TAC in tonne */
+ public double param_tacInTons = 0;
+
+ boolean affectation = false;
+
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ /**
+ * @return the necessaryResult
+ */
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() {
+ return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed use propTac other than 0.");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ // read species in current session
+ param_species = (Species)context.getDB().findByTopiaId(param_species.getTopiaId());
+
+ // on fait le calcul du tac si n�cessaire
+ if (param_propTac > 0 && date.getMonth().equals(Month.JANUARY)){
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ param_tacInTons = popMon.getBiomass(param_species) * param_propTac;
+ }
+
+ boolean result = false;
+ if(date.before(param_beginDate)) {
+ result = false;
+ } else if(date.after(param_endDate)) {
+ result = false;
+ } else {
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ if (ts != null) {
+ double catchTons = RuleUtil.getTotalCatchTons(context, param_species, date);
+ log.info("[TAC] catchTons = " + catchTons + " >= param_tacInTons:" + param_tacInTons );
+ if (catchTons >= param_tacInTons) {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ affectation = false;
+ log.info("[TAC] preAction for: " + metier);
+
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ if(ts != null && ts.getPrimaryCatch()) {
+ // recupere tous les metiers qui ont l'espece en capture principale =>metiers vises
+ List<Metier> aimedMetiers = context.getDB().find("select distinct(metierSeasonInfo.metier) " +
+ "from fr.ifremer.isisfish.entities.TargetSpecies " +
+ "where species=? and primaryCatch=true", param_species);
+
+ log.info("aimed Metier: " + aimedMetiers);
+ context.getMetierMonitor().addforbiddenMetier(metier);
+
+ //r�cupere toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ Set<Strategy> strs = new HashSet<Strategy>();
+ for (Strategy str : siMatrix.getStrategies(date)) {
+ double prop = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ if (prop != 0) {
+ strs.add(str);
+ }
+ }
+
+ for (Strategy str : strs){
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(date.getMonth());
+
+ // 1er cas de figure: l'effort est reporte sur un metier de la
+ // meme strategie, n'ayant pas l'espece comme capture principale
+ // et pechant avec le meme engin
+ Set<Metier> possibleMetierCase1 = new HashSet<Metier>();
+ // second cas de figure: on cherche un metier de substitution
+ // sans condition sur les engins, mais qui soit pratique
+ Set<Metier> possibleMetierCase2 = new HashSet<Metier>();
+ // 3 eme cas de figure: on cherche des metiers non vises,
+ // sans consideration sur les engins, et pour lesquels la
+ // proportion peut etre nulle
+ Set<Metier> possibleMetierCase3 = new HashSet<Metier>();
+
+ for (EffortDescription effort : str.getSetOfVessels().getPossibleMetiers()) {
+ Metier newMetier = effort.getPossibleMetiers();
+ if (
+ !aimedMetiers.contains(newMetier)
+ && !metier.getName().equalsIgnoreCase("nonActiviy")
+ && !metier.getName().equalsIgnoreCase("nonActivie")
+ && !context.getMetierMonitor().getForbiddenMetier().contains(newMetier)
+ ) {
+ possibleMetierCase3.add(newMetier);
+
+ if (smi.getProportionMetier(newMetier) != 0) {
+ possibleMetierCase2.add(newMetier);
+
+ if (metier.getGear().equals(newMetier.getGear())) {
+ possibleMetierCase1.add(newMetier);
+ }
+ }
+ }
+ }
+
+ Set<Metier> possibleMetier = null;
+ if (possibleMetierCase1.size() != 0){
+ log.info("[TAC] Use case 1");
+ possibleMetier = possibleMetierCase1;
+ } else if (possibleMetierCase2.size() != 0) {
+ log.info("[TAC] Use case 2");
+ possibleMetier = possibleMetierCase2;
+ } else if (possibleMetierCase3.size() != 0){
+ log.info("[TAC] Use case 3");
+ possibleMetier = possibleMetierCase3;
+ }
+
+ if (possibleMetier != null) {
+ // on repartit maintenant l'effort entre les differents metiers
+ // possibles dans la meme strategie si un metier possible existe
+ // bien la repartion est proportionnelle a l'effort deja alloue
+ // dans la strategie
+
+ double somme=0;
+ for (Metier met : possibleMetierCase1) {
+ somme += smi.getProportionMetier(met);
+ }
+ for (Metier met : possibleMetierCase1) {
+ double newProportion =
+ smi.getProportionMetier(met)
+ + (smi.getProportionMetier(metier)
+ * smi.getProportionMetier(met) / somme);
+ smi.setProportionMetier(met, newProportion);
+ }
+ smi.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ } else{
+ log.info("[TAC] Use no activity");
+
+ // sinon on met tout dans le metier nonActivite
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND mat = metierMon.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ mat.setValue(str, metier, smi.getProportionMetier(metier));
+
+ smi.getProportionMetier().setValue(metier, 0);
+ }
+ }
+ }
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("[TAC] postAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ if(ts != null){
+ if (!affectation){
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier
+ // pour qui l'espece est secondaire: elles sont affectees aux
+ // rejets
+
+ //pb : ne se fait pas par metier
+ // il faut une matrice pour chaques pas de temps qui stocke les
+ // rejets par metier, par metapop et par classes d'age (comme
+ // pour les captures)
+ //////
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ for (Population pop : param_species.getPopulation()) {
+ // si on a deja une matrice rejet on le vide (elle vient
+ // forcement de la regle taille minimale or si le tac est
+ // atteint, tout va dorenavent dans les rejets et on mais
+ // TOUTES les captures dans les rejets
+ MatrixND discard = popMon.getDiscard(date, pop);
+ if (discard != null) {
+ discard.mults(0);
+ }
+
+ discard = popMon.getCatch(pop).copy();
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ popMon.addDiscard(date, pop, discard);
+ log.info("[TAC] add discard for " + pop + ": " + discard);
+
+ if (param_propSurvie > 0) {
+ MatrixND eff = popMon.getN(pop);
+ //on r�ajoute les survivants aux effectifs
+ for (MatrixIterator i=discard.iterator(); i.next();){
+ Object [] coord = i.getSemanticsCoordinates();
+ eff.setValue(coord[2],coord[3],
+ eff.getValue(coord[2],coord[3])+i.getValue()*param_propSurvie);
+ }
+ }
+
+ }
+
+ // on a affecte une fois cette meta pop au rejet il ne faut pas
+ // le refaire
+ affectation=true;
+ }
+ }
+ }
+
+}
Added: branches/3.1.0/rules/TailleMin.java
===================================================================
--- branches/3.1.0/rules/TailleMin.java (rev 0)
+++ branches/3.1.0/rules/TailleMin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,253 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.io.Writer;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * TailleMin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+
+/**
+ * Cette methode remplace aussi TailleMinSurvieRejet si propSurvie est > 0
+ */
+public class TailleMin extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(TailleMin.class);
+
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(119);
+ public Species param_species = null;
+ public double param_TailleMin = 27;
+ public double param_propSurvie = 0;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ // TODO
+ return _("TODO description rule");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * @param context
+ * @param date
+ * @param param_species
+ * @param metier
+ * @return
+ */
+ private boolean isCaptureDate(Date date, Species species, Metier metier) {
+ MetierSeasonInfo info = metier.getMetierSeasonInfo(date.getMonth());
+ TargetSpecies target = info.getSpeciesTargetSpecies(species);
+ boolean result = target != null;
+
+ return result;
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("Recherche si la taille Minimale s'applique");
+ boolean result = true;
+ if (date.before(param_beginDate)) {
+ result = false;
+ } else if (date.after(param_endDate)) {
+ result = false;
+ } else if (isCaptureDate(date, param_species, metier) != true) {
+ result=false;
+ }
+
+ log.info("fin de condition TailleMin:" + result);
+ return result;
+
+ // fin
+
+ /*
+
+writeln("Recherche si la taille Minimale s'applique (oldValue="+oldValue);
+var metier=p.metier;
+var result = true;
+if(oldValue != undefined)
+ result = oldValue;
+else if (Regle_libUtil.isCaptureDate(p.date,p.metapop, metier)!=true)
+ result=false;
+else if(p.date.before(p.dateDeb))
+ result = false;
+else if(p.date.after(p.dateFin))
+ result = false;
+
+writeln("fin de condition TailleMin:"+result);
+return result;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("*$*$*$* TailleMin.actionApres:" + date + " metapop:" + param_species + " metier:" + metier);
+
+ if(isCaptureDate(date, param_species, metier)){
+ log.info("*$*$*$* ok affecte capture inf�?rieure �? TailleMin au rejet");
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier pour qui
+ // l'espece est secondaire: elles sont affectees aux rejets
+
+ //pb : ne se fait pas par metier
+ //il faut une matrice pour chaques pas de temps qui stocke les rejets
+ //par metier, par metapop et par classes d'age (comme pour les captures)
+ //////
+ log.info("deb de affecterCaptureREJETTailleMin");
+
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ for (Population pop : pops) {
+ if (pop.getSpecies().equals(param_species)) {
+ if (popMon.getDiscard(date, pop) == null) {
+ MatrixND discard = popMon.getCatch(pop).copy();
+ MatrixND eff = popMon.getN(pop);
+
+ for (MatrixIterator i=discard.iterator(); i.next();) {
+ Object [] coordonnees = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)coordonnees[2];
+ if (group.getLength() >= param_TailleMin) {
+ i.setValue(0);
+ } else if (param_propSurvie > 0) {
+ eff.setValue(coordonnees[2], coordonnees[3],
+ eff.getValue(coordonnees[2], coordonnees[3])
+ + i.getValue() * param_propSurvie);
+ }
+ }
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ popMon.addDiscard(date, pop, discard);
+ }
+ }
+ }
+
+ log.info("fin de affecterCaptureRejetTailleMin");
+
+ //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
+ }
+
+ // fin
+
+ /*
+
+
+
+writeln("*$*$*$* TailleMin.actionApres:"+p.date+" metapop:"+p.metapop+" metier:"+p.metier);
+if(Regle_libUtil.isCaptureDate(p.date,p.metapop, p.metier)){
+ writeln("*$*$*$* ok affecte capture inf�?rieure �? TailleMin au rejet");
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier pour qui
+ // l'espece est secondaire: elles sont affectees aux rejets
+
+ //pb : ne se fait pas par metier
+ //il faut une matrice pour chaques pas de temps qui stocke les rejets
+ //par metier, par metapop et par classes d'age (comme pour les captures)
+ //////
+writeln("deb de affecterCaptureREJETTailleMin");
+var suivi = null;
+
+//recherche du suivi pour les pop qui ont une certaine meta pop
+for(var i=0; i< suiviePop.size(); i++){
+ if(suiviePop.get(i).getPop().getMetaPopulation().equals(metapop)){
+ suivi = suiviePop.get(i);
+ var populations=suivi.getPop();
+
+ //si on a pas deja creer le rejet on le cree et on en fait un resultat
+ var matRejet = suivi.getRejet(date);
+ if (matRejet==null){
+ var matRejetBis = MatrixFactory.create(suivi.getCapture());
+ var eff=suivi.getN();
+//on encapsule les objets des 4 dimensions de la matrice capture
+ for (var iiterateur=matRejetBis.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var classe=coordonnees[2];
+ if (classe.getLongueur()>=TailleMin){
+ iiterateur.setValue(0);
+ }
+ else if (param_propSurvie > 0) {
+ eff.setValue(coordonnees[2],coordonnees[3],eff.getValue(coordonnees[2],coordonnees[3])+iiterateur.getValue()*proportion);
+ }
+ }
+ matRejetBis.setName("Rejet par metier");
+ suivi.addRejet(date,matRejetBis);
+ }
+ }
+}
+
+
+writeln("fin de affecterCaptureRejetTailleMin");
+
+
+ //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
+}
+
+return p.gestionMetier;
+*/
+ }
+
+}
Added: branches/3.1.0/scripts/GravityModel.java
===================================================================
--- branches/3.1.0/scripts/GravityModel.java (rev 0)
+++ branches/3.1.0/scripts/GravityModel.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,1311 @@
+/* *##%
+ * Copyright (C) 2006
+ * Code Lutin, C�dric Pineau, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * GravityModel.java
+ *
+ * Created: 4 sept. 06 15:49:08
+ *
+ * @author poussin
+ * @version $Revision: 1.9 $
+ *
+ * Last update: $Date: 2007-03-01 17:16:12 $
+ * by : $Author: bpoussin $
+ */
+
+package scripts;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.StorageException;
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.SetOfVessels;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeUnit;
+
+
+/**
+ * @author poussin
+ *
+ */
+
+public class GravityModel {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(GravityModel.class);
+
+ protected SimulationContext context = null;
+ protected TopiaContext db = null;
+ protected SiMatrix siMatrix = null;
+ protected ResultStorage resultManager = null;
+
+ /**
+ * Method used to get GravityModel used for simulation
+ * @param context context simulation
+ * @return GravityModel or null if no GravityModel created for simulation
+ */
+ public static GravityModel getGravityModel(SimulationContext context) {
+ GravityModel result = (GravityModel)context.getValue(GravityModel.class.getName());
+ return result;
+ }
+
+ private static void setGravityModel(SimulationContext context, GravityModel gravityModel) {
+ context.setValue(GravityModel.class.getName(), gravityModel);
+ }
+
+
+ public GravityModel(SimulationContext context, SiMatrix siMatrix) throws TopiaException, StorageException{
+ this.context = context;
+ this.db = context.getDB();
+ this.resultManager = context.getSimulationStorage().getResultStorage();
+ this.siMatrix = siMatrix;
+ setGravityModel(context, this);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // Matrice de Revenue et Cout
+ //////////////////////////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////////////////////////
+ // MatrixFishingTimePerMonthPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixFishingTimePerMonthPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = fishingTimePerMonthPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = fishingTimePerMonthPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * FishingTimePerMonthPerVessel[str,met,month] = FishingTimePerTrip[str,met,month]NbTripsPerMonth[str,month]
+
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double fishingTimePerMonthPerVessel(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ double timePerTrip = siMatrix.fishingTimePerTrip(str, metier, date);
+ int nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
+ return timePerTrip * nbTrip;
+ }
+
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixFuelCostsOfTravelPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixFuelCostsOfTravelPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = fuelCostsOfTravelPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = fuelCostsOfTravelPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * FuelCostsOfTravelPerVessel[sov,met,month]�=�NbTripsPerMonth[str,month]*TravelTimePerTrip[sov,met,month]*UnitFuelCostsOfTravel[vt]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double fuelCostsOfTravelPerVessel(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ int nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
+
+ Collection<Zone> zone = metier.getMetierSeasonInfo(month).getZone();
+ // TODO: verifier que travelTime est bien en heure, car le unitFuelCost est l'unite par heure
+ double travelTime = siMatrix.travelTimePerTrip(str.getSetOfVessels(), zone);
+ double unitFuelCost = str.getSetOfVessels().getVesselType().getUnitFuelCostOfTravel();
+
+ return nbTrip * travelTime * unitFuelCost;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixCostsOfFishingPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixCostsOfFishingPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = costsOfFishingPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = costsOfFishingPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * CostsOfFishingPerVessel[str,met,month]= FishingTimePerMonthPerVessel [str,met,month] {NbFishingOperationsPerDay[sov,met] UnitCostsOfFishing[sov,met] / 24}
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double costsOfFishingPerVessel(Strategy str, Metier metier, Date date) {
+ double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ int nbOperation = 0;
+ double unitCostOfFishing = 0;
+ if(effort != null){
+ nbOperation = effort.getFishingOperation();
+ unitCostOfFishing = effort.getUnitCostOfFishing();
+ }
+
+ return fishingTime * ( nbOperation * unitCostOfFishing / TimeUnit.HOUR_PER_DAY);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixFuelCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixFuelCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FUEL_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = fuelCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = fuelCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * FuelCostsPerVessel[str,met,month] = FuelCostsOfTravelPerVessel [sov,met,month] + CostsOfFishingPerVessel [str,met,month]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double fuelCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fuelCosts = fuelCostsOfTravelPerVessel(str, metier, date);
+ double costsOfFishing = costsOfFishingPerVessel(str, metier, date);
+
+ return fuelCosts + costsOfFishing;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixRepairAndMaintenanceGearCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixRepairAndMaintenanceGearCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * RepairAndMaintenanceGearCostsPerVessel[str,met,month]�=�FishingTimePerMonthPerVessel[str,met,month] *RepairAndMaintenanceGearCostsPerDay[sov,met]/NbHoursPerDay
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double repairAndMaintenanceGearCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+
+ double repair = 0;
+ if(effort != null){
+ repair = effort.getRepairAndMaintenanceGearCost();
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return fishingTime * repair / TimeUnit.HOUR_PER_DAY;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOtherRunningCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOtherRunningCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = otherRunningCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = otherRunningCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OtherRunningCostsPerVessel[str,met,month]=�FishingTimePerMonthPerVessel[str,met,month]*OtherRunningCostsPerDay[sov,met]/ NbHoursPerDay
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double otherRunningCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+
+ double otherCosts = 0;
+ if(effort != null){
+ otherCosts = effort.getOtherRunningCost();
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return fishingTime * otherCosts / TimeUnit.HOUR_PER_DAY;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixSharedNotFixedCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixSharedNotFixedCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = sharedNotFixedCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = sharedNotFixedCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * SharedNotFixedCostsPerVessel[str,met,month]=�FuelCostsPerVessel[str,met,month] +�OtherRunningCostsPerVessel[str,met,month]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double sharedNotFixedCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fuelCostsPerVessel = fuelCostsPerVessel(str, metier, date);
+ double otherRunningCostsPerVessel = otherRunningCostsPerVessel(str, metier, date);
+
+ return fuelCostsPerVessel + otherRunningCostsPerVessel;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixSharedFixedCostsPerVesselPerMet
+ //////////////////////////////////////////////////////////////////////
+// Supprime avec Steph le 20070227
+// public MatrixND matrixSharedFixedCostsPerVesselPerMet(Date date) throws TopiaException{
+// List<Strategy> strategies = siMatrix.getStrategies(date);
+//
+// MatrixND result = MatrixFactory.getInstance().create(
+// ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET,
+// new List[]{strategies},
+// new String[]{n_("Strategies")});
+//
+// for (int s=0; s < strategies.size(); s++) {
+// Strategy str = strategies.get(s);
+// double value = sharedFixedCostsPerVesselPerMet(str, date);
+// result.setValue(s, value);
+// }
+//// for(Strategy str : strategies){
+//// double value = sharedFixedCostsPerVesselPerMet(str, date);
+//// result.setValue(str, value);
+//// }
+//
+// return result;
+// }
+//
+// /**
+// * implant� suivant document ModifTable3PourBP25-07-2006.doc
+// * SharedFixedCostsPerVesselPerMet [str,month]=FixedCostsPerMonth[sov]/NbMet[sov]
+// *
+// * @param str
+// * @param date
+// * @return
+// */
+// private double sharedFixedCostsPerVesselPerMet(Strategy str, Date date) {
+// SetOfVessels sov = str.getSetOfVessels();
+// double fixedCosts = sov.getFixedCosts();
+// int nbMet = sov.sizePossibleMetiers();
+//
+// return fixedCosts / (double)nbMet;
+// }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixGrossValueOfLandingsPerSpeciesPerStrategyMet
+ //////////////////////////////////////////////////////////////////////
+
+
+ public MatrixND matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET,
+ new List[]{strategies, metiers, pops},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Populations")});
+
+ for (int p=0; p < pops.size(); p++) {
+ Population pop = pops.get(p);
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ result.setValue(str, metier, pop, value);
+ }
+ }
+ }
+
+// for(Population pop : pops){
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+// result.setValue(str, metier, pop, value);
+// }
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month]�=�sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet [str,met,pop,cl,month] ?DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
+nth]
+ * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month] = sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet [str,met,pop,cl,month] -DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
+nth])]
+ *
+ * @param str
+ * @param metier
+ * @param pop
+ * @param date
+ * @return
+ */
+ private double grossValueOfLandingsPerSpeciesPerStrategyMet(Strategy str, Metier metier, Population pop, Date date) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ float result = 0;
+ for(PopulationGroup group : groups){
+ double price = group.getPrice();
+ Collection<Zone> zones = pop.getPopulationZone();
+ for(Zone zone : zones){
+ double catchWeight = getCatchWeightPerStrMet(str, metier, group, zone, date);
+ double discardsWeight = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ // FIXME demander/verifier que ce le bon calcule
+ result += price * (catchWeight - discardsWeight);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param group
+ * @param zone
+ * @param date
+ * @return
+ */
+ private double getCatchWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ double result = 0;
+ if(mat != null){
+ result = mat.getValue(str, metier, group, zone);
+ }
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param group
+ * @param zone
+ * @param date
+ * @return
+ */
+ private double getDiscardsWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+ double result = 0;
+ if(mat != null){
+ result = mat.getValue(str, metier, group, zone);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixGrossValueOfLandingsPerStrategyMet
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixGrossValueOfLandingsPerStrategyMet(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double grossValueOfLandingsPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ List<Population> pops = siMatrix.getPopulations(date);
+ double result = 0;
+ for(int i=0; i<pops.size(); i++){
+ Population pop = (Population)pops.get(i);
+ result += grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixGrossValueOfLandingsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixGrossValueOfLandingsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * GrossValueOfLandingsPerStrategyMetPerVessel[str,met,month]�= GrossValueOfLandingsPerStrategyMet[str,met,month]�/[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double grossValueOfLandingsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double grossValueOfLandingsPerStrategyMet = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov)
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(str,metier,date);
+
+
+ return (grossValueOfLandingsPerStrategyMet + grossValueOfLandingsOtherSpeciesPerStrategyMet) / (proportionSetOfVessels * numberOfVessels);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixNetValueOfLandingsPerStrategyMet
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixNetValueOfLandingsPerStrategyMet(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = netValueOfLandingsPerStrategyMet(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = netValueOfLandingsPerStrategyMet(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * NetValueOfLandingsPerStrategyMet[str,met,month]�=�GrossValueOfLandingsPerStrategyMet[str,met,month]�(1-LandingCostRate[str,met]�)
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double netValueOfLandingsPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ double grossValue = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ double landingCost = 1;
+ // FIXME demander si le metier n'a pas d'effort s'il faut que landingCost soit bien a 1
+ if(effort != null){
+ landingCost -= effort.getLandingCosts();
+ }
+
+ double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(str,metier,date);
+
+ double result = (grossValue + grossValueOfLandingsOtherSpeciesPerStrategyMet)* landingCost;
+ return result;
+ }
+
+ private double grossValueOfLandingsOtherSpeciesPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ // FIXME evaluer l'equation dans suivant le doc des equations
+ return 0;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixNetValueOfLandingsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixNetValueOfLandingsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * NetValueOfLandingsPerStrategyMetPerVessel[str,met,month]�=�NetValueOfLandingsPerStrategyMet[str,met,month]�/[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double netValueOfLandingsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netValueOfLandingsPerStrategyMet = netValueOfLandingsPerStrategyMet(str, metier, date);
+ // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov)
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ return netValueOfLandingsPerStrategyMet / (proportionSetOfVessels * numberOfVessels);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixNetRenevueToSharePerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixNetRenevueToSharePerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�=�NetValueOfLandingsPerStrategyMetPerVessel[str,met,month]�-�SharedNotFixedCostsPerVessel [str,met,month]*PropStr(str,met,month) - SharedFixedCostsPerVessel
+PerMet[str,month]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double netRenevueToSharePerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToSharePerStrategyMetPerVessel = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str, metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+
+ double result = netRenevueToSharePerStrategyMetPerVessel - sharedNotFixedCostsPerVessel * propStr;
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixCrewSharePerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixCrewSharePerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = crewSharePerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = crewSharePerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * CrewSharePerStrategyMetPerVessel[str,met,month]�=�NetRevenueToSharePerStrategyMetPerVessel[str,met,month]*CrewShareRate[sov,met]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double crewSharePerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+
+ double crewShareRate = 0;
+ if(effort != null){
+ crewShareRate = effort.getCrewShareRate();
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return netRenevueToShare * crewShareRate;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategyMetPerVessel[str,met,month] = NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�- CrewSharePerStrategyMetPerVessel[str,met,month]�- RepairAndMaintenanceGearCostsPerVes
+sel[str,met,month]�* PropStr(str,met,month)
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double ownerMarginOverVariableCostsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ double crewShare = crewSharePerStrategyMetPerVessel(str, metier, date);
+ double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+
+ return netRenevueToShare - crewShare - repair * propStr;
+ }
+
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * VesselMarginOverVariableCostsPerStrategyMetPerVessel�[str,met,month]�=NetRevenueToSharePerStrategyMetPerVessel[str,met,month]- RepairAndMaintenanceGearCostsPerVessel [str,met,month]�* PropStr(str,met,month)
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double vesselMarginOverVariableCostsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+
+ return netRenevueToShare - repair * propStr;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOwnerMarginOverVariableCostsPerStrategyPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategyPerVessel[str,month]�=�somme sur tous les m�tiers de OwnerMarginOverVariableCostsPerStrategyMetPerVessel [str,met,month]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double ownerMarginOverVariableCostsPerStrategyPerVessel(Strategy str, Date date) throws TopiaException {
+ SetOfVessels sov = str.getSetOfVessels();
+ Collection<EffortDescription> efforts = sov.getPossibleMetiers();
+
+ float result = 0;
+
+ for (EffortDescription effort : efforts) {
+ Metier metier = effort.getPossibleMetiers();
+ result += ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOwnerMarginOverVariableCostsPerStrategy
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategy(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = ownerMarginOverVariableCostsPerStrategy(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = ownerMarginOverVariableCostsPerStrategy(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategy[str,month]�=�OwnerMarginOverVariableCostsPerStrategyPerVessel[str,month]�*[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double ownerMarginOverVariableCostsPerStrategy(Strategy str, Date date) throws TopiaException {
+ double ownerMarginOverVariableCostsPerStrategyPerVessel = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ return ownerMarginOverVariableCostsPerStrategyPerVessel * (proportionSetOfVessels * numberOfVessels);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixVesselMarginOverVariableCostsPerStrategyPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategyPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * VesselMarginOverVariableCostsPerStrategyPerVessel[str,month]�= somme sur tous les m�tiers de VesselMarginOverVariableCostsPerStrategyMetPerVessel� [str,met,month]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double vesselMarginOverVariableCostsPerStrategyPerVessel(Strategy str, Date date) throws TopiaException {
+ SetOfVessels sov = str.getSetOfVessels();
+ Collection<EffortDescription> efforts = sov.getPossibleMetiers();
+
+ float result = 0;
+
+ for (EffortDescription effort : efforts) {
+ Metier metier = effort.getPossibleMetiers();
+ result += vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ }
+ return result;
+ }
+
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixVesselMarginOverVariableCostsPerStrategy
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategy(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = vesselMarginOverVariableCostsPerStrategy(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = vesselMarginOverVariableCostsPerStrategy(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * VesselMarginOverVariableCostsPerStrategy[str,month]�=VesselMarginOverVariableCostsPerStrategyPerVessel�[str,month] *[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double vesselMarginOverVariableCostsPerStrategy(Strategy str, Date date) throws TopiaException {
+ double vesselMarginOverVariableCostsPerStrategyPerVessel = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ return vesselMarginOverVariableCostsPerStrategyPerVessel * (proportionSetOfVessels * numberOfVessels);
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Methode non utilis�e directement dans GravityModel, mais dans les rules
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ public double valuePerUnitFishingEffort(Strategy str, Metier metier, Date date) throws TopiaException{
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ double result = 0;
+
+ for(Population pop : pops){
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ Collection<Zone> zones = pop.getPopulationZone();
+ for(PopulationGroup group : groups){
+ double price = group.getPrice();
+ for(Zone zone : zones){
+ double catchValue = getCatchWeightPerStrMet(str, metier, group, zone, date);
+ double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ result += price * (catchValue - discards);
+ }
+ }
+ }
+
+ double effort = getEffortPerStrategyMet(str, metier, date);
+
+ if(effort == 0){
+ result = 0;
+ } else {
+ result = result / effort;
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ public double getEffortPerStrategyMet(Strategy str, Metier metier, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+ double result = 0;
+ if(mat != null){
+ result = mat.getValue(str, metier);
+ }
+ return result;
+ }
+
+ public double landingPerUnitFishingEffort(Strategy str, Metier metier, Date date) throws TopiaException{
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ double effort = getEffortPerStrategyMet(str, metier, date);
+ double result = 0;
+
+ if(effort != 0){ // s'il n'y a pas d'effort on retournera 0
+ for(Population pop : pops){
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ Collection<Zone> zones = pop.getPopulationZone();
+ for(PopulationGroup group : groups){
+ for(Zone zone : zones){
+ double catchValue = getCatchWeightPerStrMet(str, metier, group, zone, date);
+ double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ result += catchValue - discards;
+ }
+ }
+ }
+ result = result / effort;
+ }
+
+ return result;
+ }
+
+}
+
+
Added: branches/3.1.0/scripts/ResultName.java
===================================================================
--- branches/3.1.0/scripts/ResultName.java (rev 0)
+++ branches/3.1.0/scripts/ResultName.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,96 @@
+/* *##%
+ * Copyright (C) 2006
+ * Code Lutin, C�dric Pineau, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * ResultName.java
+ *
+ * Created: 23 ao�t 2006 15:09:37
+ *
+ * @author poussin
+ * @version $Revision: 1.10 $
+ *
+ * Last update: $Date: 2007-07-09 19:51:34 $
+ * by : $Author: bpoussin $
+ */
+
+package scripts;
+
+import static org.codelutin.i18n.I18n.n_;
+
+/**
+ * Contient l'ensemble des noms des differents resultats. Le mieux lorsque l'on
+ * veut un nouveau r�sultat est d'ajouter une constante ici, et de l'utiliser
+ * ensuite lors de la cr�ation de la matrice.
+ * <p>
+ * Ceci permet d'avoir un endroit unique ou l'on voit l'ensemble des r�sultats
+ * potentiellement disponible et de ne pas ce tromper en �crivent le nom
+ * d'un r�sultat
+ * <p>
+ * Cette classe ne doit contenir que des noms de resultat en static public String
+ * l'interface de lancement de simulation se base sur cette classe pour
+ * afficher l'ensemble des r�sultats disponible
+ *
+ * @author poussin
+ */
+public class ResultName {
+
+ static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET = n_("matrixDiscardsWeightPerStrMet");
+
+ static final public String MATRIX_DISCARDS_PER_STR_MET = n_("matrixDiscardsPerStrMet");
+ static final public String MATRIX_LANDING_PER_MET = n_("matrixLandingPerMet");
+
+ static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n_("matrixEffortPerStrategyMet");
+ static final public String MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET = n_("matrixStdTravelEffortPerStrategyMet");
+ static final public String MATRIX_EFFORT_PER_ZONE_POP = n_("matrixEffortPerZonePop");
+ static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET = n_("matrixCatchRatePerStrategyMet");
+ static final public String MATRIX_CATCH_PER_STRATEGY_MET = n_("matrixCatchPerStrategyMet");
+ static final public String MATRIX_FISHING_MORTALITY = n_("matrixFishingMortality");
+ static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET = n_("matrixCatchWeightPerStrategyMet");
+ static final public String MATRIX_ABUNDANCE = n_("matrixAbundance");
+ static final public String MATRIX_BIOMASS = n_("matrixBiomass");
+
+ static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n_("matrixFishingTimePerMonthPerVessel");
+ static final public String MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL = n_("matrixFuelCostsOfTravelPerVessel");
+ static final public String MATRIX_COSTS_OF_FISHING_PER_VESSEL = n_("matrixCostsOfFishingPerVessel");
+ static final public String MATRIX_FUEL_COSTS_PER_VESSEL = n_("matrixFuelCostsPerVessel");
+ static final public String MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL = n_("matrixRepairAndMaintenanceGearCostsPerVessel");
+ static final public String MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL = n_("matrixOtherRunningCostsPerVessel");
+ static final public String MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL = n_("matrixSharedNotFixedCostsPerVessel");
+// static final public String MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET = n_("matrixSharedFixedCostsPerVesselPerMet");
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet");
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerStrategyMet");
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixGrossValueOfLandingsPerStrategyMetPerVessel");
+ static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixNetValueOfLandingsPerStrategyMet");
+ static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetValueOfLandingsPerStrategyMetPerVessel");
+ static final public String MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetRenevueToSharePerStrategyMetPerVessel");
+ static final public String MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixCrewSharePerStrategyPerVessel");
+ static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel");
+ static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel");
+ static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyPerVessel");
+ static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixOwnerMarginOverVariableCostsPerStrategy");
+ static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyPerVessel");
+ static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixVesselMarginOverVariableCostsPerStrategy");
+
+ static final public String MATRIX_NO_ACTIVITY = n_("matrixNoActivity");
+ static final public String MATRIX_METIER_ZONE = n_("matrixMetierZone");
+ static final public String MATRIX_PRICE = n_("matrixPrice");
+
+}
+
+
Added: branches/3.1.0/scripts/RuleUtil.java
===================================================================
--- branches/3.1.0/scripts/RuleUtil.java (rev 0)
+++ branches/3.1.0/scripts/RuleUtil.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,65 @@
+package scripts;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+
+/**
+ * ChangeMatrixBackend.java
+ *
+ * Created: 6 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-11-20 15:51:05 $
+ * by : $Author: bpoussin $
+ */
+public class RuleUtil {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RuleUtil.class);
+
+ /**
+ * @param context le context de simulation
+ * @param species l'espece sur lequel on souhaite le total
+ * @param date la date pour laquel on veut le calcul, cet argument est
+ * passe seulement pour que le cache ne retourne pas toujours la meme valeur
+ * @return
+ */
+ public static double getTotalCatchTons(SimulationContext context, Species species, Date date) {
+ double result = 0;
+ for (Population pop : species.getPopulation()) {
+ MatrixND mat = context.getPopulationMonitor().getHoldCatch(pop);
+ if(mat!=null) {
+ mat = mat.copy();
+ mat = mat.sumOverDim(0); // sum over Strategies
+ mat = mat.sumOverDim(1); // sum over metiers
+ mat = mat.sumOverDim(3); // sum over zones
+// List<PopulationGroup> groups = mat.getSemantics(2);
+
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+
+ for (int c=0; c<groups.size(); c++) {
+ PopulationGroup group = groups.get(c);
+ double weight = group.getMeanWeight();
+ result += mat.getValue(0, 0, c, 0) * weight / 1000.0;
+ }
+ }
+ }
+ return result;
+ }
+
+
+
+
+}
Added: branches/3.1.0/scripts/SiMatrix.java
===================================================================
--- branches/3.1.0/scripts/SiMatrix.java (rev 0)
+++ branches/3.1.0/scripts/SiMatrix.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,1180 @@
+/* *##%
+ * Copyright (C) 2006
+ * Code Lutin, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * SiMatrix.java
+ *
+ * Created: 21 ao�t 2006 15:53:01
+ *
+ * @author poussin
+ * @version $Revision: 1.18 $
+ *
+ * Last update: $Date: 2007-11-02 17:53:20 $
+ * by : $Author: bpoussin $
+ */
+
+package scripts;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.entities.Cell;
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Gear;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.MetierSeasonInfo;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.Selectivity;
+import fr.ifremer.isisfish.entities.SetOfVessels;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.entities.ZoneDAO;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * @author poussin
+ *
+ */
+
+public class SiMatrix {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(SiMatrix.class);
+
+ protected SimulationContext context = null;
+ protected TopiaContext db = null;
+
+ /**
+ * Method used to get SiMatrix used for simulation
+ * @param context context simulation
+ * @return SiMatrix or null if no SiMatrix created for simulation
+ */
+ public static SiMatrix getSiMatrix(SimulationContext context) {
+ SiMatrix result = (SiMatrix)context.getValue(SiMatrix.class.getName());
+ return result;
+ }
+
+ private static void setSiMatrix(SimulationContext context, SiMatrix siMatrix) {
+ context.setValue(SiMatrix.class.getName(), siMatrix);
+ }
+
+ /**
+ *
+ * @param context Simulation context
+ * @param db TopiaContext with transaction opened. You must used this
+ * TopiaContext and not used
+ * SimulationContext.getSimulationStorage().getStorage()
+ * @throws TopiaException
+ */
+ public SiMatrix(SimulationContext context) throws TopiaException {
+ this.context = context;
+ this.db = context.getDB();
+ setSiMatrix(context, this);
+ }
+
+ /**
+ * @return
+ * @throws TopiaException
+ */
+ public List<Zone> getZones(Date date) throws TopiaException {
+ ZoneDAO dao = IsisFishDAOHelper.getZoneDAO(db);
+ List<Zone> result = dao.findAll();
+ return result;
+ }
+
+ /**
+ * @return
+ * @throws TopiaException
+ */
+ public List<Population> getPopulations(Date date) throws TopiaException {
+ List<Population> populations = new ArrayList<Population>();
+ for (Population pop : context.getSimulationStorage().getParameter().getPopulations()) {
+ Population tmp = (Population)db.findByTopiaId(pop.getTopiaId());
+ populations.add(tmp);
+ }
+ return populations;
+ }
+
+ /**
+ * @return
+ * @throws TopiaException
+ */
+ public List<Strategy> getStrategies(Date date) throws TopiaException {
+// if (strategies == null) {
+ List<Strategy> strategies = new ArrayList<Strategy>();
+ for (Strategy str : context.getSimulationStorage().getParameter().getStrategies()) {
+ Strategy tmp = (Strategy)db.findByTopiaId(str.getTopiaId());
+ strategies.add(tmp);
+ }
+// }
+ return strategies;
+ }
+
+ public List<Metier> getMetiers(Date date) throws TopiaException {
+// if (metiers == null) {
+ List<Metier> metiers = new ArrayList<Metier>();
+ HashSet<Metier> tmp = new HashSet<Metier>();
+ for (Strategy str : getStrategies(date)) {
+ SetOfVessels sov = str.getSetOfVessels();
+ for (EffortDescription effort : sov.getPossibleMetiers()) {
+ Metier metier = effort.getPossibleMetiers();
+ if (tmp.add(metier)) {
+ metiers.add(metier);
+ }
+ }
+ }
+// }
+ return metiers;
+ }
+
+ /**
+ * Retourne les metiers pratiqu�s par une Strategie � une date donn�e
+ * Un metier est pratiqu� si le PropStrMet est diff�rent de 0
+ *
+ * @param str
+ * @param date
+ * @return
+ */
+ public List<Metier> getMetiers(Strategy str, Date date) {
+ StrategyMonthInfo info = str.getStrategyMonthInfo(date.getMonth());
+ MatrixND props = info.getProportionMetier();
+
+ List<Metier> result = new ArrayList<Metier>();
+
+ for (MatrixIterator i=props.iterator(); i.hasNext();) {
+ i.next();
+ if (i.getValue() != 0) {
+ Metier metier = (Metier)i.getSemanticsCoordinates()[0];
+ result.add(metier);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Retourne la matrix Metier x Zone qui correspond au zone utilis� par
+ * un m�tier pour une date donn�e. Si la valeur de la matrice est 1 alors
+ * la zone est utilis� par le m�tier, si elle vaut 0 alors elle n'est pas
+ * utilis�e.
+ *
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ public MatrixND getMetierZone(Date date) throws TopiaException {
+ List<Metier> metiers = getMetiers(date);
+ List<Zone> zones = getZones(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_METIER_ZONE,
+ new List[]{metiers, zones},
+ new String[]{n_("Metiers"), n_("Zones")});
+
+ for (Metier metier : metiers) {
+ Collection<Zone> zoneMetier = metier.getMetierSeasonInfo(date.getMonth()).getZone();
+ for (Zone zone : zoneMetier) {
+ result.setValue(metier, zone, 1);
+ }
+ }
+ return result;
+ }
+
+ public MatrixND matrixPrice(Date date, Population pop) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_PRICE,
+ new List[]{groups},
+ new String[]{n_("PopulationGroup")});
+
+ for (PopulationGroup group : groups) {
+ result.setValue(group, group.getPrice());
+ }
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Toutes les methodes suivantes ne sont utiles que pour
+ // matrixCatchPerStrategyMet
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Matrice des captures en nombre
+ * dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param N l'abondance sous forme de matrice 2D [class x zone]
+ * @param pop
+ * @param date
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ public MatrixND matrixCatchPerStrategyMet(MatrixND N, Population pop,
+ Date date, MatrixND matrixCatchRatePerStrategyMet) throws TopiaException, IsisFishException {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ // on le passe en argument ce qui evite de le calculer 2 fois
+// MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMet(pop, date);
+ MatrixND result = matrixCatchRatePerStrategyMet.copy();
+ result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
+
+ for(PopulationGroup group : groups) {
+ MatrixND sub = result.getSubMatrix(2, group, 1);
+ for(Zone zone : zones){
+ MatrixND subsub = sub.getSubMatrix(3, zone, 1);
+ double val = N.getValue(group, zone);
+ subsub.mults(val);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Matrice des captures en poids
+ * dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param pop
+ * @param date
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ public MatrixND matrixCatchRatePerStrategyMet(Population pop, Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+ List<Strategy> strategies = getStrategies(date);
+ List<Metier> metiers = getMetiers(date);
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET,
+ new List[]{strategies, metiers, groups, zones},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+
+// for (int s=0; s < strategies.size(); s++) {
+// Strategy str = strategies.get(s);
+// metiers = getMetiers(str, date);
+// for (int m=0; m < metiers.size(); m++) {
+// Metier metier = metiers.get(m);
+// for (int g=0; g < groups.size(); g++) {
+// PopulationGroup group = groups.get(g);
+// for (int z=0; z < zones.size(); z++) {
+// Zone zone = zones.get(z);
+// double value = catchRatePerStrategyMet(str, metier, date, group, zone);
+// result.setValue(str, metier, group, zone, value);
+// }
+// }
+// }
+// }
+
+// if(totalFishingMortality == 0){
+// if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + pop + ")");}
+// } else {
+ // Optimisation Hilaire
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double effort = effortPerZonePop(str,metier,date,zone);
+ if (effort > 0){
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ double value = catchRatePerStrategyMet(str, metier, date, group, zone, matrixFishingMortality);
+ result.setValue(str, metier, group, zone, value);
+ }
+ }
+ }
+ }
+ }
+// }
+
+// for (Strategy str : strategies) {
+// List<Metier> metierStr = getMetiers(str, date);
+// for (Metier metier : metierStr) {
+// for (PopulationGroup group : groups) {
+// for (Zone zone : zones) {
+// double val = catchRatePerStrategyMet(str, metier, date, group, zone);
+// result.setValue(str, metier, group, zone, val);
+// }
+// }
+// }
+// }
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @param group
+ * @param zone
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+// private double catchRatePerStrategyMet(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone) throws TopiaException, IsisFishException {
+// double totalFishingMortality = totalFishingMortality(date, group, zone);
+//
+// if(totalFishingMortality == 0){
+// if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + group + ", " + zone +")");}
+// return 0;
+// }
+//
+// double fishingMortality = fishingMortality(str, metier, date, group, zone);
+// double totalCatchRate = totalCatchRate(date, group, zone, totalFishingMortality);
+//
+// if(log.isDebugEnabled()) {
+// log.debug(
+// " totalFishingMortality=" + totalFishingMortality +
+// " fishingMortality=" + fishingMortality +
+// " totalCatchRate=" + totalCatchRate);
+// }
+// double result = fishingMortality / totalFishingMortality * totalCatchRate;
+//
+// return result;
+// }
+
+ // Optimisation Hilaire
+ private double catchRatePerStrategyMet(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+// double totalFishingMortality = matrixFishingMortality.sumAll();
+ double totalFishingMortality = totalFishingMortality(date, matrixFishingMortality).getValue(group, zone);
+
+ if(totalFishingMortality == 0){
+ if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + group + ", " + zone +")");}
+ return 0;
+ }
+
+ double fishingMortality = matrixFishingMortality.getValue(str, metier, group, zone);
+ double totalCatchRate = totalCatchRate(date, group, zone, totalFishingMortality);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " totalFishingMortality=" + totalFishingMortality +
+ " fishingMortality=" + fishingMortality +
+ " totalCatchRate=" + totalCatchRate);
+ }
+ double result = fishingMortality / totalFishingMortality * totalCatchRate;
+
+ return result;
+ }
+
+
+ /**
+ * @param date
+ * @param group
+ * @param zone
+ * @param totalFishingMortality
+ * @return
+ * @throws TopiaException
+ */
+ private double totalCatchRate(Date date, PopulationGroup group,
+ Zone zone, double totalFishingMortality) throws TopiaException {
+ double M = group.getNaturalDeathRate(zone) / Month.NUMBER_OF_MONTH;
+ if(M == 0){
+ // normalement il devrait y avoir de la mortalite naturelle
+ if (log.isWarnEnabled()) {
+ log.warn("Pas de mortalit� naturelle pour: " + group);
+ }
+ }
+ double F = totalFishingMortality;
+
+ double result = 0;
+ if( M != 0 || F != 0){
+ result = F/(F+M) * (1 - Math.exp(-(F+M)));
+ }
+
+ return result;
+ }
+
+ /**
+ * Returne une matrice de mortalite group x zone, donc somme sur str et metier
+ *
+ * @param date
+ * @param matrixFishingMortality
+ * @param group
+ * @param zone
+ * @return
+ */
+ private MatrixND totalFishingMortality(Date date, MatrixND matrixFishingMortality) {
+ MatrixND result = matrixFishingMortality.sumOverDim(0);
+ result = result.sumOverDim(1);
+ result = result.reduceDims(0, 1);
+ return result;
+ }
+
+ /**
+ * Matrice fishing mortality
+ * dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param pop
+ * @param date
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ public MatrixND matrixFishingMortality(Date date, Population pop) throws TopiaException, IsisFishException {
+ List<Strategy> strategies = getStrategies(date);
+ List<Metier> metiers = getMetiers(date);
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ // default value in matrix is 0
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FISHING_MORTALITY,
+ new List[]{strategies, metiers, groups, zones},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+
+ Month month = date.getMonth();
+ PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+
+// org.codelutin.util.CallAnalyse.activate();
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+
+ // getCapturability is check matrix validity and create matrix if needed and get one value in
+// org.codelutin.util.CallAnalyse.enter("debug infoPop.getCapturability");
+ double capturability = infoPop.getCapturability(group);
+// org.codelutin.util.CallAnalyse.exit("debug infoPop.getCapturability");
+ if (capturability != 0) { // check 0, this prevent next call, for default value
+
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+
+// org.codelutin.util.CallAnalyse.enter("debug infoMet.getTargetFactor");
+ MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month);
+ // getTargetFactor seem to be simple
+ double ciblage = infoMet.getTargetFactor(group);
+// org.codelutin.util.CallAnalyse.exit("debug infoMet.getTargetFactor");
+
+ if (ciblage != 0) { // check 0, this prevent next call, for default value
+
+// org.codelutin.util.CallAnalyse.enter("debug gear.getPopulationSelectivity");
+ Gear gear = metier.getGear();
+ Selectivity selectivity = gear.getPopulationSelectivity(pop);
+// org.codelutin.util.CallAnalyse.exit("debug gear.getPopulationSelectivity");
+ if (selectivity != null) {
+
+ // getCoefficient is equation evaluation
+// org.codelutin.util.CallAnalyse.enter("debug selectivity.getCoefficient");
+ double coeff = selectivity.getCoefficient(pop, group, metier);
+// org.codelutin.util.CallAnalyse.exit("debug selectivity.getCoefficient");
+ if (coeff != 0) { // check 0, this prevent next call, for default value
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double effort = effortPerZonePop(str,metier,date,zone);
+ if (effort > 0){ // put value only if <> 0
+ double value = coeff * capturability * ciblage * effort;
+// org.codelutin.util.CallAnalyse.enter("debug result.setValue");
+ result.setValue(str, metier, group, zone, value);
+// org.codelutin.util.CallAnalyse.exit("debug result.setValue");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+// System.out.println("****DEBUG matrixFishingMortality:" + org.codelutin.util.CallAnalyse.getThreadStatistics().toString());
+ return result;
+ }
+
+ // ne prendre que les metiers pratiqu� semble une bonne idee, mais en fait non, car cela oblige l'ordre des boucles
+ // et donc ne permet pas autant d'optimisation que souhait�
+// public MatrixND matrixFishingMortality2(Date date, Population pop) throws TopiaException, IsisFishException {
+// List<Strategy> strategies = getStrategies(date);
+// List<Metier> metiers = getMetiers(date);
+// List<PopulationGroup> groups = pop.getPopulationGroup();
+// List<Zone> zones = pop.getPopulationZone();
+
+// // default value in matrix is 0
+// MatrixND result = MatrixFactory.getInstance().create(
+// ResultName.MATRIX_FISHING_MORTALITY,
+// new List[]{strategies, metiers, groups, zones},
+// new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+
+// Month month = date.getMonth();
+// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+
+// for (int s=0; s < strategies.size(); s++) {
+// Strategy str = strategies.get(s);
+// metiers = getMetiers(str, date);
+// for (int m=0; m < metiers.size(); m++) {
+// Metier metier = metiers.get(m);
+// Gear gear = metier.getGear();
+// Selectivity selectivity = gear.getPopulationSelectivity(pop);
+// if (selectivity != null) {
+// MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month);
+// for (int z=0; z < zones.size(); z++) {
+// Zone zone = zones.get(z);
+// double effort = effortPerZonePop(str,metier,date,zone);
+// if (effort > 0){ // put value only if <> 0
+// for (int g=0; g < groups.size(); g++) {
+// PopulationGroup group = groups.get(g);
+
+// // getTargetFactor seem to be simple
+// double ciblage = infoMet.getTargetFactor(group);
+// if (ciblage != 0) { // check 0, this prevent next call, for default value
+// // getCapturability is check matrix validity and create matrix if needed and get one value in
+// double capturability = infoPop.getCapturability(group);
+// if (capturability != 0) { // check 0, this prevent next call, for default value
+// // getCoefficient is equation evaluation
+// double coeff = selectivity.getCoefficient(pop, group, metier);
+// if (coeff != 0) { // check 0, this prevent next call, for default value
+// double value = coeff * capturability * ciblage * effort;
+// result.setValue(str, metier, group, zone, value);
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// return result;
+// }
+
+// /**
+// * @param date
+// * @param group
+// * @param zone
+// * @return
+// * @throws TopiaException
+// * @throws IsisFishException
+// */
+// private double totalFishingMortality(Date date, PopulationGroup group, Zone zone) throws TopiaException, IsisFishException {
+// List<Strategy> strategies = getStrategies(date);
+//
+// float result = 0;
+//
+//// for(Strategy str : strategies){
+//// List<Metier> metierStr = getMetiers(str, date);
+//// for (Metier metier : metierStr) {
+//// // TODO peut etre ne pas le faire si classe.pop n'est pas
+//// /// peche par le metier
+//// result += fishingMortality(str, metier, date, group, zone);
+//// }
+//// }
+//
+// // Optimisation Hilaire
+// for(Strategy str : strategies){
+// List<Metier> metierStr = getMetiers(str, date);
+// for (Metier metier : metierStr) {
+// double effort=effortPerZonePop(str,metier,date,zone);
+// if (effort>0)
+// result += fishingMortality(str, metier, date, group, zone, effort);
+// }
+// }
+//
+// return result;
+// }
+
+
+ // fusion fishingMortality and matrixFishingMortality for performance reason
+// /**
+// * @param str
+// * @param metier
+// * @param date
+// * @param group
+// * @param zone
+// * @return
+// * @throws IsisFishException
+// */
+// private double fishingMortality(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone, double effort) throws IsisFishException {
+// Month month = date.getMonth();
+// Population pop = group.getPopulation();
+// Gear gear = metier.getGear();
+//
+// Selectivity selectivity = gear.getPopulationSelectivity(pop);
+//
+// double result = 0;
+//
+// if (selectivity != null) {
+// MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month);
+// double ciblage = infoMet.getTargetFactor(group);
+//
+// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+// double capturability = infoPop.getCapturability(group);
+//
+// double coeff = selectivity.getCoefficient(pop, group, metier);
+//
+// // Optimisation Hilaire
+//// double effort = effortPerZonePop(str, metier, date, zone);
+//
+// // la methode est appeler des millions de fois, donc meme si
+// // on ne perd pas beaucoup de temps avec le if, on en perd deja
+// // trop
+//// if(log.isDebugEnabled()) {
+//// log.debug(
+//// " strategy=" + str +
+//// " metier=" + metier +
+//// " ciblage=" + ciblage +
+//// " capturabilite=" + capturability +
+//// " selectivity=" + coeff +
+//// " effort=" + effort);
+//// }
+//
+// result = coeff * capturability * ciblage * effort;
+// }
+//
+// return result;
+// }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @param zone
+ * @return
+ */
+ private double effortPerZonePop(Strategy str, Metier metier, Date date, Zone zonePop) {
+ Month month = date.getMonth();
+ Collection<Zone> zoneMet = metier.getMetierSeasonInfo(month).getZone();
+ double inter = nbCellInter(zoneMet, zonePop);
+
+ double effortPerStrategyPerCell = effortPerStrategyPerCell(str, metier, date);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " inter=" + inter +
+ " effortPerStrategyPerCell=" + effortPerStrategyPerCell
+ );
+ }
+
+ double result = effortPerStrategyPerCell * inter;
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double effortPerStrategyPerCell(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ Collection<Zone> zones = metier.getMetierSeasonInfo(month).getZone();
+ double nbCell = getCells(zones).size();
+
+ if(nbCell == 0){
+ // normalement il devrait y avoir des mailles, mais pour les
+ // ancienne zone AuPort, il n'y en avait pas
+ if(log.isWarnEnabled()) log.warn("Calcul d'une distance pour le metier "+metier+" pour le mois "+month+" avec une zone sans maille: " + zones);
+ return 0;
+ }
+
+
+ double effortPerStrategy = effortPerStrategyMet(str, metier, date);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " nbCell=" + nbCell +
+ " effortPerStrategy=" + effortPerStrategy
+ );
+ }
+
+ double result = effortPerStrategy/nbCell;
+
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double effortPerStrategyMet(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+
+ double propSetOfVessels = str.getProportionSetOfVessels();
+ int nbOfVessels = str.getSetOfVessels().getNumberOfVessels();
+ double propStrMet = smi.getProportionMetier(metier);
+ double effortPerVessel = effortPerStrategyPerVessel(str, metier, date);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " propSetOfVessels=" + propSetOfVessels +
+ " nbOfVessels=" + nbOfVessels +
+ " propStrMet=" + propStrMet +
+ " effortPerVessel=" + effortPerVessel
+ );
+ }
+
+ double result = propSetOfVessels * nbOfVessels * propStrMet * effortPerVessel;
+
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double effortPerStrategyPerVessel(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ int nbTrips = smi.getNumberOfTrips();
+ double fishingTime = fishingTimePerTrip(str, metier, date);
+ double stdEffortPerHour = stdEffortPerHour(str.getSetOfVessels(), metier);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " nbTrips=" + nbTrips +
+ " fishingTime=" + fishingTime +
+ " stdEffortPerHour=" + stdEffortPerHour
+ );
+ }
+
+ double result = nbTrips * fishingTime * stdEffortPerHour;
+
+ return result;
+ }
+
+ /**
+ * Used in GravityModel too
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ protected double fishingTimePerTrip(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ Collection<Zone> zone = metier.getMetierSeasonInfo(month).getZone();
+
+ if (zone == null) {
+ if(log.isWarnEnabled()) log.warn(
+ "missing zone for metier =" + metier +
+ " for month" + month
+ );
+ }
+
+ double tripDuration = smi.getTripType().getTripDuration().getHour();
+ double travelTime = travelTimePerTrip(str.getSetOfVessels(), zone);
+
+ double result = tripDuration - travelTime;
+
+ if (result < 0 ) {
+ if(log.isWarnEnabled()) log.warn(
+ " strategy=" + str +
+ " metier=" + metier +
+ " tripDuration=" + tripDuration +
+ " travelTime=" + travelTime
+ );
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param setOfVessels
+ * @param zone
+ * @return
+ */
+ protected double travelTimePerTrip(SetOfVessels sov, Collection<Zone> zoneMetier) {
+ Cell maille = sov.getPort().getCell();
+ double result =
+ 2 * distance(zoneMetier, maille) / sov.getVesselType().getSpeed();
+
+ return result;
+ }
+
+ /**
+ * @param zoneMetier
+ * @param maille
+ * @return
+ */
+ private double distance(Collection<Zone> zones, Cell cell) {
+ double result = 0;
+ List<Cell> cells = getCells(zones);
+
+ if(cells.size() == 0){
+ // normalement il devrait y avoir des mailles, mais pour les
+ // ancienne zone AuPort, il n'y en avait pas
+ if(log.isWarnEnabled()) {
+ log.warn("Calcul d'une distance avec une zone sans maille");
+ }
+ return 0;
+ }
+
+ for(Cell c : cells){
+ result += distance(c, cell);
+ }
+
+ if(log.isDebugEnabled()) {
+ log.debug(" result=" + result + " nbMaille="+cells.size());
+ }
+
+ result = result / (double)cells.size();
+ return result;
+ }
+
+ /**
+ * @param c
+ * @param cell
+ * @return
+ */
+ private double distance(Cell m1, Cell m2) {
+ double earthRadius = 6378.388;
+ double p = 180/Math.PI;
+
+ if(log.isDebugEnabled()) log.debug("p: " + p);
+
+ double m1lat = m1.getLatitude();
+ double m2lat = m2.getLatitude();
+ double m1lon = m1.getLongitude();
+ double m2lon = m2.getLongitude();
+
+ if(log.isDebugEnabled()) log.debug(
+ " m1lat=" + m1lat +
+ " m2lat=" + m2lat +
+ " m1lon=" + m1lon +
+ " m2lonx=" + m2lon
+ );
+
+ double m1lat_div_p = m1lat/p;
+ double m2lat_div_p = m2lat/p;
+ double m1lon_div_p = m1lon/p;
+ double m2lon_div_p = m2lon/p;
+
+ if(log.isDebugEnabled()) log.debug(
+ " m1lat_div_p=" + m1lat_div_p +
+ " m2lat_div_p=" + m2lat_div_p +
+ " m1lon_div_p=" + m1lon_div_p +
+ " m2lon_div_p=" + m2lon_div_p
+ );
+
+ double sin_m1lat_div_p = Math.sin(m1lat_div_p);
+ double sin_m2lat_div_p = Math.sin(m2lat_div_p);
+ double cos_m1lat_div_p = Math.cos(m1lat_div_p);
+ double cos_m2lat_div_p = Math.cos(m2lat_div_p);
+
+ if(log.isDebugEnabled()) log.debug(
+ " sin_m1lat_div_p=" + sin_m1lat_div_p +
+ " sin_m2lat_div_p=" + sin_m2lat_div_p +
+ " cos_m1lat_div_p=" + cos_m1lat_div_p +
+ " cos_m2lat_div_p=" + cos_m2lat_div_p
+ );
+
+ double cos_m1lon_div_p_minus_m2lon_div_p = Math.cos(m1lon_div_p - m2lon_div_p);
+
+ if(log.isDebugEnabled()) log.debug(
+ " cos_m1lon_div_p_minus_m2lon_div_p=" + cos_m1lon_div_p_minus_m2lon_div_p);
+
+ double acos = Math.acos(
+ sin_m1lat_div_p
+ * sin_m2lat_div_p
+ +
+ cos_m1lat_div_p
+ * cos_m2lat_div_p
+ * cos_m1lon_div_p_minus_m2lon_div_p
+ );
+
+ if(log.isDebugEnabled()) log.debug(" acos=" + acos);
+
+ double result = earthRadius * acos;
+
+ return result;
+ }
+
+ /**
+ * @param setOfVessels
+ * @param metier
+ * @return
+ */
+ private double stdEffortPerHour(SetOfVessels sov, Metier metier) {
+ double result = 0;
+ EffortDescription ed = sov.getPossibleMetiers(metier);
+ if(ed != null){
+ double fstd = metier.getGear().getStandardisationFactor();
+ double val = fstd * ed.getFishingOperation() * ed.getGearsNumberPerOperation();
+ result = val;
+ }
+ result = result/24; // 24 heures
+
+ return result;
+ }
+
+
+ /**
+ * used here and in Rule (CantonnementPreSimu)
+ *
+ * @param zones
+ * @return
+ */
+ public List<Cell> getCells(Collection<Zone> zones) {
+ List<Cell> result = new ArrayList<Cell>();
+ for (Zone zone : zones) {
+ result.addAll(zone.getCell());
+ }
+ return result;
+ }
+
+ /**
+ * used here and in Rule (CantonnementPreSimu)
+ *
+ * @param zoneMet
+ * @param zonePop
+ * @return
+ */
+ public int nbCellInter(Collection<Zone> zoneMet, Zone zonePop) {
+ List<Cell> cells = getCells(zoneMet);
+ List<Cell> tmp = new ArrayList<Cell>(cells);
+ tmp.retainAll(zonePop.getCell());
+ return tmp.size();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param N
+ * @param pop
+ * @param date
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ public MatrixND matrixAbundance(MatrixND N, Population pop, Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_ABUNDANCE,
+ new List[]{groups, zones},
+ new String[]{n_("Groups"), n_("Zones")});
+
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double value = survivalRate(date, group, zone, matrixFishingMortality);
+ double n = N.getValue(g, z);
+ value *= n;
+ result.setValue(g, z, value);
+ }
+ }
+
+// for(PopulationGroup group : groups){
+// for(Zone zone : zones){
+// double val = survivalRate(date, group, zone);
+// val *= N.getValue(group, zone);
+// result.setValue(group, zone, val);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * @param date
+ * @param group
+ * @param zone
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ private double survivalRate(Date date, PopulationGroup group, Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+ double F = totalFishingMortality(date, matrixFishingMortality).getValue(group, zone); //totalFishingMortality(date, group, zone); // rem perf: totalFishingMortality a deja ete calcul�
+ double M = group.getNaturalDeathRate(zone)/(double)Month.NUMBER_OF_MONTH;
+ double result = (double)Math.exp(-(F+M));
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param n
+ * @param pop
+ * @param date
+ * @return
+ */
+ public MatrixND matrixBiomass(MatrixND N, Population pop, Date date) {
+ List<PopulationGroup> groups = N.getSemantics(0);
+ List<Zone> zones = N.getSemantics(1);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_BIOMASS,
+ new List[]{groups, zones},
+ new String[]{n_("Groups"), n_("Zones")});
+
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ double meanWeight = group.getMeanWeight();
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double n = N.getValue(group, zone);
+ double value = n * meanWeight;
+ result.setValue(group, zone, value);
+ }
+ }
+
+// for(PopulationGroup group : groups){
+// double meanWeight = group.getMeanWeight();
+// for(Zone zone : zones){
+// double val = N.getValue(group, zone) * meanWeight;
+// result.setValue(group, zone, val);
+// }
+// }
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ public MatrixND matrixEffortPerStrategyMet(Date date) throws TopiaException {
+ List<Strategy> strategies = getStrategies(date);
+ List<Metier> metiers = getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = effortPerStrategyMet(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+
+// for(Strategy str : strategies){
+// List<Metier> metierStr = getMetiers(str, date);
+// for(Metier metier : metierStr) {
+// double val = effortPerStrategyMet(str, metier, date); // rem perf: effortPerStrategyMet a deja ete calcul�
+// result.setValue(str, metier, val);
+// }
+// }
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param pop
+ * @param date
+ * @return
+ */
+ public MatrixND matrixCatchWeightPerStrategyMet(Population pop,
+ Date date, MatrixND matrixCatchPerStrategyMet) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+
+ MatrixND result = matrixCatchPerStrategyMet.copy();
+ result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+
+ for(PopulationGroup group : groups){
+ MatrixND sub = result.getSubMatrix(2, group, 1);
+ double meanWeight = group.getMeanWeight();
+ sub.mults(meanWeight);
+ }
+
+ return result;
+ }
+
+ /**
+ * @param pop
+ * @param date
+ * @return
+ */
+ public MatrixND matrixDiscardWeightPerStrategyMet(Population pop,
+ Date date, MatrixND matrixDiscardPerStrategyMet) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+
+ MatrixND result = matrixDiscardPerStrategyMet.copy();
+ result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+
+ for(PopulationGroup group : groups){
+ MatrixND sub = result.getSubMatrix(2, group, 1);
+ double meanWeight = group.getMeanWeight();
+ sub.mults(meanWeight);
+ }
+
+ return result;
+ }
+
+}
Added: branches/3.1.0/simulators/DefaultSimulator.java
===================================================================
--- branches/3.1.0/simulators/DefaultSimulator.java (rev 0)
+++ branches/3.1.0/simulators/DefaultSimulator.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,526 @@
+/* *##%
+ * Copyright (C) 2006
+ * Ifremer, Code Lutin, C�dric Pineau, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * DefaultSimulator.java
+ *
+ * Created: 21 ao�t 2006 10:57:46
+ *
+ * @author poussin
+ * @version $Revision: 1.19 $
+ *
+ * Last update: $Date: 2007-11-06 18:16:14 $
+ * by : $Author: bpoussin $
+ */
+
+package simulators;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+import scripts.GravityModel;
+import scripts.ResultName;
+import scripts.SiMatrix;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.RuleMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationControl;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.Simulator;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * @author poussin
+ *
+ */
+
+public class DefaultSimulator implements Simulator {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(DefaultSimulator.class);
+
+ /**
+ * Called by isis don't modify signature
+ */
+ public void simulate(SimulationContext context) throws Exception {
+
+ SimulationParameter param = context.getSimulationStorage().getParameter();
+ SimulationControl control = context.getSimulationControl();
+ int lastYear = param.getNumberOfYear();
+ int lastDate = lastYear * Month.NUMBER_OF_MONTH;
+ Date date = control.getDate();
+ control.setProgressMax(lastDate);
+
+ ResultStorage resManager = context.getSimulationStorage().getResultStorage();
+ TopiaContext db = context.getDB();
+
+ SiMatrix siMatrix = new SiMatrix(context);
+ GravityModel gravityModel = new GravityModel(context, siMatrix);
+
+ PopulationMonitor populationMonitor = context.getPopulationMonitor();
+ MetierMonitor metierMonitor = context.getMetierMonitor();
+ RuleMonitor ruleMonitor = context.getRuleMonitor();
+
+ for (Population pop : siMatrix.getPopulations(date)) {
+ MatrixND N = param.getNumberOf(pop);
+ N.setName(ResultName.MATRIX_ABUNDANCE);
+ populationMonitor.setN(pop, N);
+ }
+
+ //
+ // Rule initialisation
+ //
+ List<Rule> rules = param.getRules();
+ control.setText("Rules initialisation:" + rules);
+ for (Rule rule : rules) {
+ rule.init(context);
+ log.info("Rule " +rule.getClass().getSimpleName()+ " initialized");
+ }
+
+ //
+ // Commit all change done un init rules methods.
+ //
+ context.getDB().commitTransaction();
+
+ //
+ // Simulation loop
+ //
+ while (date.getDate() < lastDate) {
+ //
+ // if user stop simulation before last year
+ //
+ if (control.isStopSimulationRequest()) {
+ break;
+ }
+
+ control.setDate(date);
+ control.setProgress(date.getDate());
+ control.setText(_("begin step " + date));
+
+ // raz des metiers interdits et des licences
+ metierMonitor.clear();
+
+ if (date.getMonth().equals(Month.JANUARY)) {
+ populationMonitor.clearCatch();
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
+ MatrixND mat = metierMonitor.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ resManager.addResult(date, mat);
+ }
+
+ //
+ // Rule condition evaluation
+ //
+ control.setText("Evalute Rules conditions ("+rules.size()+" rules)");
+ for (Rule rule : rules) {
+ for (Metier metier : siMatrix.getMetiers(date)) {
+ boolean active = false;
+ try {
+ active = rule.condition(context, date, metier);
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't evaluate rule condition for: " + rule, eee);
+ }
+ }
+ ruleMonitor.setEvaluationCondition(date, rule, metier, active);
+ if (active) {
+ log.info("Activate rule: " + rule.getClass().getSimpleName());
+ resManager.addActiveRule(date, rule);
+ }
+ }
+ }
+
+ //
+ // Rule pre action
+ //
+ control.setText("Do pre action Rules");
+ for (Rule rule : rules) {
+ for (Metier metier : siMatrix.getMetiers(date)) {
+ boolean condition = ruleMonitor.getEvalutionCondition(date, rule, metier);
+ if (condition) {
+ rule.preAction(context, date, metier);
+ }
+ }
+ }
+
+ //
+ // Keep modification's information done in rule
+ //
+ if (resManager.isEnabled(ResultName.MATRIX_METIER_ZONE)) {
+ MatrixND metierZone = siMatrix.getMetierZone(date);
+ resManager.addResult(date, metierZone);
+ }
+
+ //
+ // Simulate one step for all pop
+ //
+ control.setText("Simulate one month");
+ for (Population pop : siMatrix.getPopulations(date)) {
+ computeMonth(context, siMatrix, date, pop);
+ }
+
+ //
+ // Add some result not population dependante
+ //
+
+ // only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+
+ control.setText("Add some results");
+ if (resManager.isEnabled(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET)) {
+ MatrixND effortPerStrategyMet = siMatrix.matrixEffortPerStrategyMet(date);
+ resManager.addResult(date, effortPerStrategyMet);
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET)) {
+ MatrixND stdTravelEffortPerStrategyMet = siMatrix.matrixEffortPerStrategyMet(date);
+ resManager.addResult(date, stdTravelEffortPerStrategyMet);
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_EFFORT_PER_ZONE_POP)) {
+ MatrixND effortPerZonePop = siMatrix.matrixEffortPerStrategyMet(date);
+ resManager.addResult(date, effortPerZonePop);
+ }
+
+
+ //
+ // Add economics results
+ //
+ if (!"false".equalsIgnoreCase(param.getTagValue().get("ecoResult"))) {
+ control.setText("Add economics results");
+ saveGravityModel(date, resManager, gravityModel);
+ }
+ }
+
+ //
+ // Add economics results
+ //
+ if (resManager.isEnabled(ResultName.MATRIX_PRICE)) {
+ for (Population pop : siMatrix.getPopulations(date)) {
+ MatrixND matPrice = siMatrix.matrixPrice(date, pop);
+ resManager.addResult(date, pop, matPrice);
+ }
+ }
+
+
+
+ //
+ // Rule post action
+ //
+ control.setText("Do post action Rules");
+ for (Rule rule : rules) {
+ for (Metier metier : siMatrix.getMetiers(date)) {
+ if (ruleMonitor.getEvalutionCondition(date, rule, metier)) {
+ rule.postAction(context, date, metier);
+ }
+ }
+ }
+
+ // discard and landing must be done after post action rules
+ // only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+
+ control.setText("Compute discard and landing");
+ for (Population pop : siMatrix.getPopulations(date)) {
+ //
+ // discard computation
+ //
+ MatrixND discard = populationMonitor.getDiscard(date, pop);
+ if (discard != null || date.getDate() == 0) { // force discard for the first month to have discard in result
+ if (discard == null) {
+ discard = MatrixFactory.getInstance().create(ResultName.MATRIX_DISCARDS_PER_STR_MET,
+ new List[]{siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date),
+ pop.getPopulationGroup(),
+ pop.getPopulationZone()},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+ }
+ resManager.addResult(date, pop, discard);
+
+ if (resManager.isEnabled(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET)) {
+ MatrixND discardWeightPerStrategyMet = siMatrix.matrixDiscardWeightPerStrategyMet(pop, date, discard);
+ resManager.addResult(date, pop, discardWeightPerStrategyMet);
+ }
+
+ }
+
+ //
+ // add landing result
+ //
+ if (resManager.isEnabled(ResultName.MATRIX_LANDING_PER_MET)) {
+ MatrixND landing = MatrixFactory.getInstance().create(populationMonitor.getCatch(pop));
+ if (discard != null) {
+ landing = landing.minus(discard);
+ }
+ landing.setName(ResultName.MATRIX_LANDING_PER_MET);
+ resManager.addResult(date, pop, landing);
+ }
+ }
+ }
+
+ //
+ // revert modification for next step
+ //
+ control.setText("Rollback rules changes");
+ db.rollbackTransaction();
+
+ //
+ // commit result
+ //
+ control.setText("Commit results");
+ TopiaContext tx = context.getDbResult();
+ tx.commitTransaction();
+
+ //
+ // Go next step
+ //
+ date = date.next();
+ }
+ }
+
+ protected void computeMonth(SimulationContext context, SiMatrix siMatrix, Date date, Population pop) throws IsisFishException, TopiaException {
+ // to add result
+ ResultStorage resManager = context.getSimulationStorage().getResultStorage();
+
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ MatrixND N = popMon.getN(pop);
+
+ if (log.isInfoEnabled()) {
+ log.info("====================== begin "+ date + " - " + pop +" =========================== " + System.currentTimeMillis());
+ log.info("N: " + N);
+ }
+
+ // add N and biomass result now, before computation
+ // N is reassigned during computation
+ resManager.addResult(date, pop, N);
+
+ if (resManager.isEnabled(ResultName.MATRIX_BIOMASS)) {
+ MatrixND biomass = siMatrix.matrixBiomass(N, pop, date);
+ resManager.addResult(date, pop, biomass);
+ }
+
+ Month month = date.getMonth();
+ PopulationSeasonInfo info = pop.getPopulationSeasonInfo(month);
+
+ // group change
+ MatrixND CA = null;
+ if (date.getDate() == 0) {
+ CA = MatrixFactory.getInstance().matrixId(pop.sizePopulationGroup()*pop.sizePopulationZone());
+ } else {
+ CA = info.getGroupChangeMatrix(month);
+ }
+
+ log.debug("CA: " + CA);
+
+ //migration
+ MatrixND M = info.getMigrationMatrix(month, N);
+ log.debug("M: " + M);
+ //emigration
+ MatrixND EM = info.getEmigrationMatrix(month, N);
+ log.debug("EM: " + EM);
+ //immigration
+ MatrixND IM = info.getImmigrationMatrix(month, N).transpose();
+ log.debug("IM: " + IM);
+
+ // pour les premiers calculs on met N en une matrice 1D
+ MatrixND N1D = pop.N2DToN1D(N);
+ log.debug("N1D: " + N1D);
+
+ MatrixND tmp0 = N1D.mult(CA);
+ MatrixND tmp1 = M.minus(EM);
+ MatrixND tmp2 = tmp0.mult(tmp1);
+ MatrixND tmp3 = tmp2.add(IM);
+
+ log.debug("N1D after mig: " + tmp3);
+
+ // On reconvertie en une matrice Semantique
+ N = pop.split2D(tmp3);
+
+ log.debug("N after mig: " + N);
+
+ //Recrutement
+ MatrixND R = info.getReproductionMatrix(month, N);
+ log.debug("R: " + R);
+
+ // ajout de la matrice R dans le suivi de la pop comme etant
+ // la reproduction pour le mois courant.
+ popMon.setReproduction(date, pop, R);
+
+ // recrutement
+ MatrixND recruitment = popMon.getRecruitment(date, pop);
+ log.debug("recruitment: " + recruitment);
+
+ // mortalite de la reproduction
+ popMon.applyReproductionMortality(pop);
+
+ N = N.add(recruitment);
+ log.debug("N after recru: " + N);
+
+ MatrixND abundance = N;
+ // compute fishing matrix only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+ // compute some Matrix and add result
+ MatrixND matrixFishingMortality = siMatrix.matrixFishingMortality(date, pop);
+ resManager.addResult(date, pop, matrixFishingMortality);
+
+ abundance = siMatrix.matrixAbundance(N, pop, date, matrixFishingMortality);
+
+ // this matrix is necessary for matrixCatchPerStrategyMet
+ MatrixND catchRatePerStrategyMet = siMatrix.matrixCatchRatePerStrategyMet(pop, date, matrixFishingMortality);
+ resManager.addResult(date, pop, catchRatePerStrategyMet);
+
+ // this matrix is necessary for PopulationMonitor.holdCatch (reused in rule)
+ MatrixND catchPerStrategyMet = siMatrix.matrixCatchPerStrategyMet(N, pop, date, catchRatePerStrategyMet);
+ popMon.holdCatch(pop, catchPerStrategyMet);
+ resManager.addResult(date, pop, catchPerStrategyMet);
+
+ if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET)) {
+ MatrixND catchWeightPerStrategyMet = siMatrix.matrixCatchWeightPerStrategyMet(pop, date, catchPerStrategyMet);
+ resManager.addResult(date, pop, catchWeightPerStrategyMet);
+ }
+ }
+ log.debug("abundance: " + abundance);
+
+ // Keep new N
+ popMon.setN(pop, abundance);
+
+ log.debug("====================== end " + date + " - " + pop +" ===========================");
+
+ }
+
+ /**
+ * @param date
+ * @param resManager
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ private void saveGravityModel(Date date, ResultStorage resManager, GravityModel gravityModel) throws IsisFishException, TopiaException {
+ if (resManager.isEnabled(ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFishingTimePerMonthPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixCostsOfFishingPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_FUEL_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixRepairAndMaintenanceGearCostsPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOtherRunningCostsPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixSharedNotFixedCostsPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+// if (resManager.isEnabled(ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET)) {
+// MatrixND mat = gravityModel.matrixSharedFixedCostsPerVesselPerMet(date);
+// resManager.addResult(date, mat);
+// }
+ if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerStrategyMet(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel.matrixNetValueOfLandingsPerStrategyMet(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixNetValueOfLandingsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixNetRenevueToSharePerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixCrewSharePerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
+ MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategy(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategyPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
+ MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategy(date);
+ resManager.addResult(date, mat);
+ }
+ }
+
+}
+
+
Added: trunk/3.1.0/analyseplans/Calibration.java
===================================================================
--- trunk/3.1.0/analyseplans/Calibration.java (rev 0)
+++ trunk/3.1.0/analyseplans/Calibration.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,335 @@
+package analyseplans;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.*;
+import java.util.*;
+
+import org.codelutin.math.matrix.*;
+
+import org.codelutin.topia.*;// pour pouvoir utiliser la methode StringUtil.toDouble()
+import org.codelutin.util.*;// pour pouvoir utiliser la methode StringUtil.toDouble()
+
+import fr.ifremer.isisfish.*;
+import fr.ifremer.isisfish.types.*;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.simulator.AnalysePlan;
+import fr.ifremer.isisfish.simulator.AnalysePlanContext;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Calibration_bidon.java
+ *
+ * Created: 8 mars 2007
+ *
+ * @author <>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-11-02 17:43:14 $
+ * by : $Author: bpoussin $
+ */
+public class Calibration implements AnalysePlan {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Calibration.class);
+
+ enum State {STATE_INIT, STATE_0, STATE_1, STATE_2, STATE_3, STATE_4};
+
+ //parametres de la simu 3 points initiaux d un simplex d ordre 2
+ public Population param_Population = null;
+ public String param_M1 = "1e-5;1e-6";// devient un parametre du plan d analyse
+ public String param_M2 = "2e-4;2e-5";// devient un parametre du plan d analyse
+
+ public String param_M3 = "1e-4;1e-6";// devient un parametre du plan d analyse
+ public String param_pas = "1e-5";// devient un parametre du plan d analyse
+ public String param_nomfichier_debarquements = "";//nom + chemin du fichier contenant les debarquements observes par groupe pour la derniere annee
+
+ protected File debarquementsObserves;
+ protected MatrixND matrixDebarquement;
+
+ protected State state = State.STATE_INIT;
+ protected Experiences experiences = new Experiences();
+
+
+ /**
+ * @return the experiences
+ */
+ public Experiences getExperiences() {
+ return this.experiences;
+ }
+
+ public String [] necessaryResult = {
+ ResultName.MATRIX_LANDING_PER_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur le plan.
+ * @return L'aide ou la description du plan
+ */
+ public String getDescription() throws Exception {
+ return _("Simplexe");
+ }
+
+ /**
+ * Appele au demarrage de la simulation, cette methode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(AnalysePlanContext context) throws Exception {
+ if (param_nomfichier_debarquements==null || "".equals(param_nomfichier_debarquements)){
+ debarquementsObserves = FileUtil.getFile(".*.csv", "fichier csv s�parateur ';'");
+ } else {
+ debarquementsObserves = new File(param_nomfichier_debarquements);
+ }
+// int nbYear = context.getParam().getNumberOfYear();
+ TopiaContext db = context.getParam().getRegion().getStorage().beginTransaction();
+ Population pop = (Population)db.findByTopiaId(param_Population.getTopiaId());
+
+ int nbGroup = pop.sizePopulationGroup();
+ matrixDebarquement = MatrixFactory.getInstance().create(new int[]{nbGroup});
+// List<PopulationGroup> groups = pop.getPopulationGroup();
+// matrixDebarquement = MatrixFactory.getInstance().create(new List[]{groups});
+
+ matrixDebarquement.importCSV(new FileReader(debarquementsObserves),new int []{0});
+ db.closeContext();
+ }
+
+ /**
+ * Call before each simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean beforeSimulation(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception {
+ boolean doNext = true;
+
+ int number = context.getNumber();
+
+ if (number < 3) {
+ String [] M1 = param_M1.split(";");
+ String [] M2 = param_M2.split(";");
+ String [] M3 = param_M3.split(";");
+ double [] q1 = StringUtil.toArrayDouble(M1[0], M2[0], M3[0]);
+ double [] q2 = StringUtil.toArrayDouble(M1[1], M2[1], M3[1]);
+
+ experiences.getExperience(number).q1 = q1[number];
+ experiences.getExperience(number).q2 = q2[number];
+
+ changeDB(experiences.getExperience(number), nextSimulation);
+ } else {
+ double q1 = 0;
+ double q2 = 0;
+
+ double lastCritere = experiences.getExperience(number-1).criteria;
+ double g1 = (experiences.current.get(2).q1 + experiences.current.get(1).q1) / 2.0;
+ double g2 = (experiences.current.get(2).q2 + experiences.current.get(1).q2) / 2.0;
+
+ double worst1 = experiences.current.get(0).q1;
+ double worst2 = experiences.current.get(0).q2;
+
+
+ if (state == State.STATE_INIT) {
+ // on fait la 4eme simulation dans tous les cas
+ state = State.STATE_0;
+ Collections.sort(experiences.current);
+ q1 = 2 * g1 - worst1;
+ q2 = 2 * g2 - worst2;
+ } else if (state == State.STATE_0) {
+ // on fait la 5eme avec des q qui dependent de la 4eme dans le dernier cas
+ if (lastCritere < experiences.current.get(0).criteria) {
+ state = State.STATE_1;
+ q1 = g1 - ( g1 - worst1 ) / 2.0;
+ q2 = g2 - ( g2 - worst2 ) / 2.0;
+ } else if (lastCritere < experiences.current.get(1).criteria) {
+ state = State.STATE_2;
+ q1 = g1 + ( g1 - worst1 ) / 2.0;
+ q2 = g2 + ( g2 - worst2 ) / 2.0;
+ } else if (lastCritere < experiences.current.get(2).criteria) {
+ state = State.STATE_INIT;
+ experiences.current.remove(3);
+ } else { // dernier cas possible: if (lastCritere > experiences.current.get(2).critere) {
+ state = State.STATE_4;
+ q1 = experiences.current.get(3).q1 + g1 - worst1;
+ q2 = experiences.current.get(3).q2 + g2 - worst2;
+ }
+ } else if (state == State.STATE_1) {
+ // la derniere simulation a ete faite
+ if (lastCritere > experiences.current.get(0).criteria) {
+ experiences.current.remove(3);
+ experiences.current.remove(0);
+ } else {
+ // FIXME on supprime les 2 derniere qui vient d'etre faite, on risque donc de boucler
+ experiences.current.remove(4);
+ experiences.current.remove(3);
+ doNext = false;
+ }
+ state = State.STATE_INIT;
+ } else if (state == State.STATE_2) {
+ if (lastCritere > experiences.current.get(0).criteria) {
+ experiences.current.remove(3);
+ experiences.current.remove(0);
+ } else {
+ // FIXME on supprime les 2 derniere qui vient d'etre faite, on risque donc de boucler
+ experiences.current.remove(4);
+ experiences.current.remove(3);
+ doNext = false;
+ }
+ state = State.STATE_INIT;
+ } else if (state == State.STATE_4) {
+ if (lastCritere > experiences.current.get(3).criteria) {
+ experiences.current.remove(3);
+ experiences.current.remove(0);
+ } else {
+ experiences.current.remove(4);
+ experiences.current.remove(0);
+ }
+ state = State.STATE_INIT;
+ }
+
+ experiences.getExperience(number).q1 = q1;
+ experiences.getExperience(number).q2 = q2;
+
+ changeDB(experiences.getExperience(number), nextSimulation);
+ }
+
+ return doNext;
+ }
+
+ /**
+ * Call after each simulation, compute criteria for last simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean afterSimulation(AnalysePlanContext context, SimulationStorage lastSimulation) throws Exception {
+ boolean doNext = true;
+
+ int number = context.getNumber();
+
+ ResultStorage result = lastSimulation.getResultStorage();
+ log.fatal("sim: " + lastSimulation + " result: " + result);
+ MatrixND L = result.getMatrix(param_Population, ResultName.MATRIX_LANDING_PER_MET);
+ L = L.sumOverDim(0);// sum sur les mois, si on ajoute le pas (12) on peut sommer sur les annees
+ L = L.sumOverDim(1);// sum sur les strategies
+ L = L.sumOverDim(3);// sum sur les metiers
+ L = L.sumOverDim(4);// sum sur les zones
+ L = L.reduce(); // supprime les dim qui n ont qu un element
+
+ double crit = 0;
+ for ( MatrixIterator g = L.iterator(); g.hasNext();){
+ g.next();
+ int [] dim = g.getCoordinates();
+ double obs = matrixDebarquement.getValue(dim);
+ double simules = g.getValue();
+ crit += Math.pow(obs-simules, 2);
+ }
+ experiences.getExperience(number).criteria = crit;
+
+ return doNext;
+ }
+
+ /**
+ * Modify nextSimulation database with q1 and q2 in exp.
+ * @param exp
+ * @param nextSimulation
+ * @throws Exception
+ */
+ protected void changeDB(Experience exp, SimulationStorage nextSimulation) throws Exception {
+ TopiaContext db = nextSimulation.getStorage().beginTransaction();//ouvrir un context pour modifier les donnees
+ Population pop = (Population)db.findByTopiaId(param_Population.getTopiaId());
+// autre solution moins efficace:
+// PopulationDAO popDAO = IsisFishDAOHelper.getPopulationDAO(db);
+// Population Nephrops = dao.findByName(param_Population.getName());
+
+ MatrixND c = pop.getCapturability();
+
+ for (MatrixIterator i = c.iterator(); i.hasNext();){
+ i.next();
+
+ Object [] sem = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)sem[0];
+ PopulationSeasonInfo season = (PopulationSeasonInfo)sem[1];
+
+ if (season.getFirstMonth().after(Month.JULY) && group.getId() >=18){ //mois >= aout
+ i.setValue(exp.q2);
+ }
+ else {
+ i.setValue(exp.q1);
+ }
+ }
+ db.commitTransaction();
+ db.closeContext();
+ }
+
+ public class Experiences {
+ /** contains last simplex and potentialy 2 more simulation */
+ protected List<Experience> current = new ArrayList<Experience>();
+ /** contains all experience done */
+ protected List<Experience> history = new ArrayList<Experience>();
+
+ /**
+ * @return the history
+ */
+ public List<Experience> getHistory() {
+ return this.history;
+ }
+
+ /**
+ * return experience requested, if this experience doesn't exist
+ * create it.
+ *
+ * @param i simulation number
+ * @return experience with simulation number fixed if new experience
+ * is returned
+ */
+ public Experience getExperience(int i) {
+ Experience result;
+ if (i<history.size()) {
+ result = history.get(i);
+ } else {
+ result = new Experience();
+ result.simNumber = i;
+ history.add(i, result);
+ current.add(result);
+ }
+ return result;
+ }
+ }
+
+ /**
+ * Use to keep q1, q2 and criteria of simulation
+ * @author poussin
+ */
+ public class Experience implements Comparable {
+ public int simNumber;
+ public double criteria;
+ public double q1;
+ public double q2;
+
+ /**
+ * Permit to order experience, first is experience with smallest criteria
+ */
+ public int compareTo(Object arg0) {
+ Experience other = (Experience)arg0;
+ int result = Double.compare(this.criteria, other.criteria);
+ return result;
+ }
+ }
+
+}
+
Added: trunk/3.1.0/analyseplans/Max.java
===================================================================
--- trunk/3.1.0/analyseplans/Max.java (rev 0)
+++ trunk/3.1.0/analyseplans/Max.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,93 @@
+package analyseplans;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.simulator.AnalysePlan;
+import fr.ifremer.isisfish.simulator.AnalysePlanContext;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Max.java
+ *
+ * Created: 2 mars 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-03-09 15:27:21 $
+ * by : $Author: bpoussin $
+ */
+public class Max implements AnalysePlan {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Max.class);
+
+ public int param_max = 10;
+
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur le plan.
+ * @return L'aide ou la description du plan
+ */
+ public String getDescription() throws Exception {
+ return _("Permit to specify maximum simulation numbers");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(AnalysePlanContext context) throws Exception {
+
+ }
+
+ /**
+ * Call before each simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean beforeSimulation(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception {
+ return true;
+ }
+
+ /**
+ * Call after each simulation
+ * @param context plan context
+ * @param nextSimulation storage used for next simulation
+ * @return true if we must do next simulation, false to stop plan
+ * @throws Exception
+ */
+ public boolean afterSimulation(AnalysePlanContext context, SimulationStorage lastSimulation) throws Exception {
+ boolean result = context.getNumber() + 1 < param_max;
+ return result;
+ }
+
+}
Added: trunk/3.1.0/exports/Abundances.java
===================================================================
--- trunk/3.1.0/exports/Abundances.java (rev 0)
+++ trunk/3.1.0/exports/Abundances.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,109 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Abundance.java
+ *
+ * Created: 1 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class Abundances implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Abundances.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_ABUNDANCE
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "Abondances";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les abondances en nombre tableau avec des lignes pop;id;zone;date;nombre.");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_ABUNDANCE);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ PopulationGroup group = (PopulationGroup)sems[1];
+ Zone zone = (Zone)sems[2];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+/*
+writeln("debut export abondances");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var result="";
+
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ writeln("population "+pop.getNom());
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+
+ var matrice=resultats.getMatrix(date,pop, "Abondance");
+ var BadZones=matrice.getSemantics(1);
+ var Zones = new Packages.java.util.ArrayList(BadZones);
+ var BadClasses=matrice.getSemantics(0);
+ var Classes=new Packages.java.util.ArrayList(BadClasses);
+ for(var iz=Zones.iterator(); iz.hasNext();){
+ var z=iz.next();
+ for(var ic=Classes.iterator(); ic.hasNext();){
+ var c = ic.next();
+ result+=pop.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+matrice.getValue(c,z)+"\n";
+ }
+ }
+ }
+}
+writeln("fin export abondances");
+
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/Biomasses.java
===================================================================
--- trunk/3.1.0/exports/Biomasses.java (rev 0)
+++ trunk/3.1.0/exports/Biomasses.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,110 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * Biomasses.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class Biomasses implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Biomasses.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_BIOMASS
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "Biomasses";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les biomasses tableau avec des lignes pop;id;zone;date;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_BIOMASS);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ PopulationGroup group = (PopulationGroup)sems[1];
+ Zone zone = (Zone)sems[2];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+
+
+ /*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+var finsimu=resultats.getLastDate().getDate();
+
+
+var result="";
+writeln("debut export biomasse");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop, "matriceBiomass");
+ var BadZones=matrice.getSemantics(1);
+ var Zones = new Packages.java.util.ArrayList(BadZones);
+ var BadClasses=matrice.getSemantics(0);
+ var Classes=new Packages.java.util.ArrayList(BadClasses);
+ for(var iz=Zones.iterator(); iz.hasNext();){
+ var z=iz.next();
+ for(var ic=Classes.iterator(); ic.hasNext();){
+ var c = ic.next();
+ result+=pop.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+matrice.getValue(c,z)+"\n";
+ }
+ }
+ }
+}
+writeln("fin export biomasse");
+
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/CapturesNombre.java
===================================================================
--- trunk/3.1.0/exports/CapturesNombre.java (rev 0)
+++ trunk/3.1.0/exports/CapturesNombre.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,118 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * CapturesNombre.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class CapturesNombre implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CapturesNombre.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "CapturesNombre";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les captures en nombre de la simulation. tableau pop;metier;id;zone;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+ /*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+
+writeln("debut de export captures nombre");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop, "matriceCatchPerStrategyMet");
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de CapturesNombre");
+
+
+
+return ""+result;
+
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/CapturesPoids.java
===================================================================
--- trunk/3.1.0/exports/CapturesPoids.java (rev 0)
+++ trunk/3.1.0/exports/CapturesPoids.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,114 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * CapturesPoids.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class CapturesPoids implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CapturesPoids.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "CapturesPoids";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les captures en poids de la simulation. tableau pop;metier;id;zone;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+/*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+writeln("debut de export captures poids");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop, "matriceCatchWeightPerStrategyMet");
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de CapturesPoids");
+return ""+result;
+
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/CellsDefinition.java
===================================================================
--- trunk/3.1.0/exports/CellsDefinition.java (rev 0)
+++ trunk/3.1.0/exports/CellsDefinition.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,65 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+import java.util.List;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * CellsDefinition.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class CellsDefinition implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CellsDefinition.class);
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "MailleDefinition";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export cell's position(longitute/latitute)");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ List<Cell> cells = simulation.getFisheryRegion().getCell();
+
+ for (Cell cell : cells) {
+ out.write(cell + ";" + cell.getLongitude() + ";" + cell.getLatitude() + "\n");
+ }
+ }
+
+}
Added: trunk/3.1.0/exports/EffortsMetier.java
===================================================================
--- trunk/3.1.0/exports/EffortsMetier.java (rev 0)
+++ trunk/3.1.0/exports/EffortsMetier.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,98 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * EffortsMetier.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class EffortsMetier implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(EffortsMetier.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "EffortsMetier";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("retourne un tableau strategie;metier;date;effort");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+ Metier metier = (Metier)sems[2];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ metier.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+/*
+var PDate=Packages.fr.ifremer.nodb.Date;
+writeln("debut de export effort");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+var result="";
+
+var finsimu=resultats.getLastDate().getDate();
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "matriceEffortPerStrategyMet");
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var strat=coordonnees[0];
+ capture=iiterateur.getValue();
+ result+=strat.getName()+";"+metier.getNom()+";"+idate+";"+capture+"\n";
+ }
+}
+
+writeln("fin de EffortMetier");
+return ""+result;
+
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/MetierZone.java
===================================================================
--- trunk/3.1.0/exports/MetierZone.java (rev 0)
+++ trunk/3.1.0/exports/MetierZone.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,73 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * MetierZone.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class MetierZone implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(MetierZone.class);
+
+ public String [] necessaryResult = {
+ ResultName.MATRIX_METIER_ZONE,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "MetierZone";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export zone used by metier during simulation");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, ResultName.MATRIX_METIER_ZONE);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ if (i.getValue() == 1) {
+ Object metier = i.getSemanticsCoordinates()[0];
+ Object zone = i.getSemanticsCoordinates()[1];
+ out.write(metier + ";" + zone + ";" + date.getDate() + "\n");
+ }
+ }
+ }
+ }
+ }
+
+}
Added: trunk/3.1.0/exports/NonActivite.java
===================================================================
--- trunk/3.1.0/exports/NonActivite.java (rev 0)
+++ trunk/3.1.0/exports/NonActivite.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,100 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * NonActivite.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class NonActivite implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(NonActivite.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_NO_ACTIVITY
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "NonActivite";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("retourne un tableau strategie;metier;date;proportion");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_NO_ACTIVITY);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+ Metier metier = (Metier)sems[2];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ metier.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+/*
+var PDate=Packages.fr.ifremer.nodb.Date;
+writeln("debut de export nonActivite");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+var result="";
+
+var finsimu=resultats.getLastDate().getDate();
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "nonActivite");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),"nonActivite"));
+ matrice.mults(0);
+ }
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var strat=coordonnees[0];
+ capture=iiterateur.getValue();
+ result+=strat.getName()+";"+metier.getNom()+";"+idate+";"+capture+"\n";
+ }
+}
+
+writeln("fin de nonActivite");
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/OwnerMargin.java
===================================================================
--- trunk/3.1.0/exports/OwnerMargin.java (rev 0)
+++ trunk/3.1.0/exports/OwnerMargin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,95 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * OwnerMargin.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class OwnerMargin implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(OwnerMargin.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "PatronProfit";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("cvs out strategy;date;value");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+/*
+var Parametre=sim.getParametre();
+var PDate=Packages.fr.ifremer.nodb.Date;
+var finsimu=resultats.getLastDate().getDate();
+
+
+var result="";
+writeln("debut export ownermargin");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "matriceOwnerMarginOverVariableCostsPerStrategyPerVessel");
+ for(var iiterateur=matrice.iterator(); iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var str=coordonnees[0];
+ result+=str.getName()+";"+idate+";"+iiterateur.getValue()+"\n";
+ }
+}
+writeln("fin export ownermargin");
+
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/RegionDefinition.java
===================================================================
--- trunk/3.1.0/exports/RegionDefinition.java (rev 0)
+++ trunk/3.1.0/exports/RegionDefinition.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,68 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RegionDefinition.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 10:05:22 $
+ * by : $Author: bpoussin $
+ */
+public class RegionDefinition implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RegionDefinition.class);
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "RegionDefinition";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export region description");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ // NomRegion LatituteMin LatitudeMax LongitudeMin LongitudeMax PasLatitude PasLongitude
+ FisheryRegion region = simulation.getFisheryRegion();
+ out.write(region.getName() + ";"
+ + region.getMinLatitude() + ";"
+ + region.getMaxLatitude() + ";"
+ + region.getMinLongitude() + ";"
+ + region.getMaxLongitude() + ";"
+ + region.getCellLengthLatitude() + ";"
+ + region.getCellLengthLongitude() +
+ "\n");
+ }
+
+}
Added: trunk/3.1.0/exports/RejetsNombre.java
===================================================================
--- trunk/3.1.0/exports/RejetsNombre.java (rev 0)
+++ trunk/3.1.0/exports/RejetsNombre.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,117 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RejetsNombre.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class RejetsNombre implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RejetsNombre.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_DISCARDS_PER_STR_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "RejetsNombre";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+/*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+writeln("debut de export rejets nombre");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop ,"Rejet par metier");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
+ matrice.mults(0);
+ }
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de RejetsNombre");
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/RejetsPoids.java
===================================================================
--- trunk/3.1.0/exports/RejetsPoids.java (rev 0)
+++ trunk/3.1.0/exports/RejetsPoids.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,116 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RejetsPoids.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.4 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class RejetsPoids implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RejetsPoids.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "RejetsPoids";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+ if (mat != null) { // can be null if simulation is stopped before last year simulation
+ mat = mat.sumOverDim(0); //sum on strategy
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier)sems[1];
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+
+ double val = i.getValue();
+ out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ }
+ }
+ }
+/*
+var Parametre=sim.getParametre();
+var Populations=Parametre.getPopulations();
+var PDate=Packages.fr.ifremer.nodb.Date;
+
+var capture=0.0;
+var result="";
+writeln("debut de export rejets poids");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+var finsimu=resultats.getLastDate().getDate();
+
+for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, pop, "Rejet par metier");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
+ matrice.mults(0);
+ }
+ var temp=matrice.sumOverDim(0);
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue()*c.getPoidsMoyen();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+}
+
+writeln("fin de RejetsPoids");
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/VesselMargin.java
===================================================================
--- trunk/3.1.0/exports/VesselMargin.java (rev 0)
+++ trunk/3.1.0/exports/VesselMargin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,95 @@
+package exports;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * VesselMargin.java
+ *
+ * Created: 23 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class VesselMargin implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(VesselMargin.class);
+
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "BateauProfit";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("cvs out strategy;date;value");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
+ for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ Date date = (Date)sems[0];
+ Strategy str = (Strategy)sems[1];
+
+ double val = i.getValue();
+ out.write(str.getName() +";"+ date.getDate() +";"+ val +"\n");
+ }
+ /*
+var Parametre=sim.getParametre();
+var PDate=Packages.fr.ifremer.nodb.Date;
+var finsimu=resultats.getLastDate().getDate();
+
+
+var result="";
+writeln("debut export vesselmargin");
+var dateexport=new Packages.java.util.Date();
+var formatteur= new Packages.java.text.SimpleDateFormat();
+writeln("heure de debut: "+formatteur.format(dateexport));
+
+
+for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, "matriceVesselMarginOverVariableCostsPerStrategyPerVessel");
+ for(var iiterateur=matrice.iterator(); iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var str=coordonnees[0];
+ result+=str.getName()+";"+idate+";"+iiterateur.getValue()+"\n";
+ }
+}
+writeln("fin export vesselmargin");
+
+return ""+result;
+*/
+ }
+
+}
Added: trunk/3.1.0/exports/ZonesDefinition.java
===================================================================
--- trunk/3.1.0/exports/ZonesDefinition.java (rev 0)
+++ trunk/3.1.0/exports/ZonesDefinition.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,70 @@
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+import java.util.List;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * ZonesDefinition.java
+ *
+ * Created: 17 janvier 2007
+ *
+ * @author bpoussin <bpoussin(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $
+ * by : $Author: bpoussin $
+ */
+public class ZonesDefinition implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(ZonesDefinition.class);
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ public String getExportFilename() {
+ return "ZonesDefinition";
+ }
+
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ public String getDescription() {
+ return _("Export cell's zone constitution");
+ }
+
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ List<Zone> zones = simulation.getFisheryRegion().getZone();
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
+ for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
+ for (Zone zone : zones) {
+ for (Cell cell : zone.getCell()) {
+ out.write(zone + ";" + cell + ";" + date.getDate() + "\n");
+ }
+ }
+ }
+ }
+
+}
Added: trunk/3.1.0/pom.xml
===================================================================
--- trunk/3.1.0/pom.xml (rev 0)
+++ trunk/3.1.0/pom.xml 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!--The version of maven's project object model-->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!--lutinproject.xml-->
+<!--
+ <parent>
+ <groupId>lutinlib</groupId>
+ <artifactId>lutinproject</artifactId>
+ <version>2.2</version>
+ </parent>
+-->
+
+ <!--A unique name for this project-->
+ <groupId>ifremer</groupId>
+ <artifactId>isis-fish-data</artifactId>
+ <name>IsisFish data</name>
+
+ <!--ejb, jar, war...-->
+ <packaging>jar</packaging>
+
+ <!--Version-->
+ <version>3.0.0</version>
+
+ <!--Description-->
+ <description>Data for Isis-fish</description>
+ <inceptionYear>2000</inceptionYear>
+
+ <!--Tracking-->
+ <issueManagement>
+ <url>http://labs.libre-entreprise.org/tracker/?group_id=8</url>
+ </issueManagement>
+
+ <build>
+ <sourceDirectory>${basedir}</sourceDirectory>
+ <plugins>
+ </plugins>
+ </build>
+
+ <!--Librairies-->
+ <dependencies>
+ <dependency>
+ <groupId>ifremer</groupId>
+ <artifactId>isis-fish</artifactId>
+ <version>3.0.10</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <distributionManagement>
+ <site>
+ <id>labs</id>
+ <url>scp://labs.libre-entreprise.org/home/groups/${pom.artifactId}/htdocs/isis-f…</url>
+ </site>
+ </distributionManagement>
+
+</project>
Added: trunk/3.1.0/profiles.xml
===================================================================
--- trunk/3.1.0/profiles.xml (rev 0)
+++ trunk/3.1.0/profiles.xml 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<settings>
+ <!--Definition of profiles-->
+ <profiles>
+ <profile>
+ <id>codelutin-repository</id>
+
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+
+ <properties>
+ <maven.src.dir>${basedir}/src</maven.src.dir>
+ <maven.test.skip>true</maven.test.skip>
+ <maven.compile.source>1.5</maven.compile.source>
+ <maven.compile.target>1.5</maven.compile.target>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>codelutin-lib</id>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>codelutin-plugin</id>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+
+ <!--List of profiles that are active for all builds.-->
+ <activeProfiles>
+ <activeProfile>codelutin-repository</activeProfile>
+ </activeProfiles>
+</settings>
Added: trunk/3.1.0/regions/DemoRegion/data-backup.sql.gz
===================================================================
(Binary files differ)
Property changes on: trunk/3.1.0/regions/DemoRegion/data-backup.sql.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/3.1.0/rules/Cantonnement.java
===================================================================
--- trunk/3.1.0/rules/Cantonnement.java (rev 0)
+++ trunk/3.1.0/rules/Cantonnement.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,321 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+
+/**
+ * Cantonnement.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.5 $
+ *
+ * Last update: $Date: 2007-11-02 17:41:41 $
+ * by : $Author: bpoussin $
+ */
+
+/**
+ * Remplace aussi Cantonnement Engin
+ */
+public class Cantonnement extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Cantonnement.class);
+
+ public Zone param_zone = null;
+ public Gear param_gear = null;
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(119);
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_NO_ACTIVITY,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ if(date.before(param_beginDate)) {
+ return false;
+ } else if(date.after(param_endDate)) {
+ return false;
+ }
+
+ if (date.getMonth().before(param_beginMonth)) {
+ return false;
+ } else if (date.getMonth().after(param_endMonth)) {
+ return false;
+ }
+ if (param_gear != null && !param_gear.equals(metier.getGear())) {
+ return false;
+ }
+
+
+ List<Cell> cellMetiers = metier.getMetierSeasonInfo(date.getMonth()).getCells();
+ List<Cell> cells = param_zone.getCell();
+
+ cellMetiers.retainAll(cells);
+
+ boolean result = !Collections.disjoint(cellMetiers, cells);
+ if (result && log.isInfoEnabled()) {
+ log.info("Cantonnement condition true");
+ }
+ return result;
+
+/*
+writeln("condition fermeture zone");
+var mois = p.date.getMois().getNumMois();
+writeln("mois:"+mois);
+if(p.moisDeb>mois || p.moisFin<mois)
+ return false;
+writeln("on est dans l'espace des mois possible");
+//on est dans l'espace des mois possible
+if(p.date.before(p.dateDeb))
+ return false;
+if(p.date.after(p.dateFin))
+ return false;
+
+
+var mailleMetier = p.metier.getSecteurMois(p.date.getMois()).getMaille();
+
+// s'il y a une intersection avec la zone ferme, alors la regle s'applique
+mailleMetier.retainAll(p.mailles);
+var result = mailleMetier.size() != 0;
+
+if(result)
+ writeln("===== Fermeture Zone s'applique ======");
+return result;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ MetierMonitor metierMon = context.getMetierMonitor();
+
+ MetierSeasonInfo infoMetier = metier.getMetierSeasonInfo(date.getMonth());
+
+ List<Cell> cellMetiers = infoMetier.getCells();
+ List<Cell> cells = param_zone.getCell();
+
+ cellMetiers.removeAll(cells);
+
+ if (cellMetiers.size() != 0) {
+ ZoneDAO dao = IsisFishDAOHelper.getZoneDAO(context.getDB());
+
+ //
+ // Create new empty zone for cantonnement
+ //
+ String name = "ZoneCantonnement-" + metier.getName()+ "-" + date.getDate();
+ Zone zoneCantonnement = dao.findByName(name);
+ int cpt=0;
+ while (zoneCantonnement != null) {
+ cpt++;
+ zoneCantonnement = dao.findByName(name + "-" + cpt);
+ }
+ zoneCantonnement = dao.create();
+ if (cpt > 0) {
+ name += "-" + cpt;
+ }
+ zoneCantonnement.setName(name);
+
+ //
+ // Remove prohibited zone and add not prohibited cell to zoneCantonnement
+ //
+ Collection<Zone> zoneMetiers = infoMetier.getZone();
+ for (Iterator<Zone> i=zoneMetiers.iterator(); i.hasNext();) {
+ Zone zone = i.next();
+ // copy list cell to not modify original zone
+ List<Cell> tmpCells = new ArrayList<Cell>(zone.getCell());
+ tmpCells.removeAll(param_zone.getCell());
+
+ zoneCantonnement.addAllCell(tmpCells);
+ i.remove();
+ }
+ ArrayList<Zone> newZone = new ArrayList<Zone>();
+ newZone.add(zoneCantonnement);
+ infoMetier.setZone(newZone);
+ } else {
+ // sinon toute la zone de pratique du metier est incluse dans zone Cantonnement
+ // alors metier devient metier-nonactivite
+
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ MatrixND noActivity = metierMon.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ metierMon.addforbiddenMetier(metier);
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ for(Strategy str : strategies){
+ StrategyMonthInfo info = str.getStrategyMonthInfo(date.getMonth());
+ double prop = info.getProportionMetier(metier);
+ if (prop != 0){
+ noActivity.setValue(str , metier, prop);
+ info.setProportionMetier(metier, 0);
+ }
+ }
+ }
+ // fin de preAction
+
+/*
+writeln("Cantonnement zone Action avant metier:"+p.metier);
+writeln("Les mailles fermees sont:"+p.mailles);
+
+var zoneMetier = p.metier.getSecteurMois(p.date.getMois());
+var mailleMetier = zoneMetier.getMaille().copy();
+mailleMetier.removeAll(p.mailles);
+writeln("inter maille:"+mailleMetier.size());
+// test pour savoir si toute la zone de pratique du metier
+// (reunion de toutes les zones metiers de metier a date)
+// est totalement incluse dans la zone Cantonnement
+if (mailleMetier.size() != 0){ //le cas intersection.length==mailleMetier est dans condition
+ // si toute la zone de pratique du metier n'est pas incluse dans zone Cantonnement
+
+ //creation du nouveau secteur de metier
+ //on v�rifie si le secteur a pas d�j� �t� modifi� par une autre r�gle afin de ne pas avoir de probl�me d'ID
+ var ListeSecteur=MetaSecteurFactory.findAllByKey("MetaCantonnement-"+p.metier.getNom()+"-"+date.getDate(),p.metier.getRegion());
+ if (ListeSecteur.size()!=0){
+ var secteurResult = MetaSecteurFactory.create(zoneMetier.getNom()+"Modif", p.metier.getRegion(), "Secteur creer durant la simulation.");
+ }
+ else{
+ var secteurResult = MetaSecteurFactory.create("MetaCantonnement-"+p.metier.getNom()+"-"+date.getDate(), p.metier.getRegion(), "Secteur creer durant la simulation.");
+ }
+ writeln("nouveau secteur cree:"+secteurResult);
+ var zonesMetier = zoneMetier.getAllSecteur();
+ writeln("zonesMetier:"+zonesMetier);
+ writeln("zonesMetier.size:"+zonesMetier.size());
+
+ for(var i=0; i<zonesMetier.size(); i++){
+ var zonemet = zonesMetier.get(i);
+ writeln("zonemet:"+zonemet);
+ // intersection entre la zeme zone metier a date et zone de Cantonnement
+ var listemailleszonemetier = zonemet.getMaille().copy();
+ var nbMailleZoneMetier = listemailleszonemetier.size();
+ writeln("maille metier:"+listemailleszonemetier);
+ writeln("maille Cantonnement:"+p.mailles);
+ listemailleszonemetier.removeAll(p.mailles);
+ if(0==listemailleszonemetier.size()){
+ //si completement inclus on le supprime
+ //donc on ne le met pas dans le nouveau
+ writeln("on supprime la zone"+zonemet);
+ }
+ else if (listemailleszonemetier.size() != nbMailleZoneMetier) {
+ // si la zone metier n'est pas totalement incluse dans zone de Cantonnement
+ // on reduit la zeme zone metier de cette intersection
+ // pas de modif de la matrice de proportion strmet
+ writeln("on cree une nouvelle zone a partir de:"+zonemet+" avec "+listemailleszonemetier);
+ var simpleSecteur = SecteurSimpleFactory.create("Cantonnement-"+p.metier.getNom()+"-"+zonemet+"-"+date.getDate(), p.metier.getRegion(), "Secteur creer durant la simulation.");
+ simpleSecteur.addAllMaille(listemailleszonemetier);
+ secteurResult.addSecteur(simpleSecteur);
+ writeln("apres addSecteur");
+ }else {
+ //sinon on le met dans le nouveau
+ writeln("On remet tel quelle la zone:"+zonemet);
+ secteurResult.addSecteur(zonemet);
+ }
+ }// fin du for sur les zone metier de la zone de pratique du metier
+ writeln("Zone metier avant"+zoneMetier.getMaille());
+ writeln("Zone metier apres"+secteurResult);
+ writeln("Zone metier apres"+secteurResult.getMaille());
+ p.metier.setSecteurMois(secteurResult, p.date.getMois());
+}
+else {
+ writeln("Toute la zone metier est ferme");
+ // sinon toute la zone de pratique du metier est incluse dans zone Cantonnement
+ // alors metier devient metier-nonactivite
+
+ //on regarde si la matrice nonActivite a �t� cr�e, sinon on la cr�e
+ var matNonActivite=nonActivite.get(p.date);
+ var nonactivite=matNonActivite!=null;
+ if (!nonactivite){
+ matNonActivite=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ nonActivite.put(p.date,matNonActivite);
+ }
+
+ //listes des strategies contenant ce metier et tel que strmet(metier,date)!=0
+ MetiersInterdits.put(new Packages.java.lang.String(p.metier.getNom()),true);
+ var listestrategies=StrategyFactory.findAllByRegion(p.metier.getRegion());
+
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+
+ if (MetiersPosibles.contains(p.metier) ){
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(p.date.getMois());
+ if (InfoMois.getProportionMetier(p.metier)!=0){
+ matNonActivite.setValue(listestrategies.get(i),p.metier,InfoMois.getProportionMetier(p.metier));
+ InfoMois.setProportionMetier(p.metier,new Packages.java.lang.Float(0));
+ }
+ }
+ }
+}// fin du else passage a metier-nonactivite
+writeln("fin Cantonnement zone action avant");
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+}
Added: trunk/3.1.0/rules/CantonnementPreSimu.java
===================================================================
--- trunk/3.1.0/rules/CantonnementPreSimu.java (rev 0)
+++ trunk/3.1.0/rules/CantonnementPreSimu.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,711 @@
+package rules;
+
+import static org.codelutin.i18n.I18n.n_;
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+
+/**
+ * Cantonnement.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class CantonnementPreSimu extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(CantonnementPreSimu.class);
+
+ public Zone param_zone = null;
+ public Gear param_gear = null;
+ public boolean param_enginSelective = true;
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>();
+ protected boolean affectNonActivite = false;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_NO_ACTIVITY,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter");
+ }
+
+ private void reportNonActivite(SimulationContext context,
+ List<Strategy> listestrategies, List<Metier> metiers,
+ Metier metier, List<Month> chomageMonth) {
+ for(Strategy strategy : listestrategies) {
+ SetOfVessels SetOfBateau = strategy.getSetOfVessels();
+ EffortDescription effort = SetOfBateau.getPossibleMetiers(metier);
+ if (effort != null){
+ for (Month month : chomageMonth) {
+ StrategyMonthInfo InfoMois = strategy.getStrategyMonthInfo(month);
+//this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+ log.info("debut reportNonActivite");
+ // on regarde si on a d�j� une entr�e pour le mois courant
+ MatrixND matNonActiviteMois=tableNonActivite.get(month);
+ if (matNonActiviteMois == null){
+ matNonActiviteMois = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NO_ACTIVITY,
+ new List[]{listestrategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+ tableNonActivite.put(month, matNonActiviteMois);
+ }
+
+ matNonActiviteMois.setValue(strategy, metier, InfoMois.getProportionMetier(metier));
+ log.info("fin reportNonActivite");
+
+ InfoMois.setProportionMetier(metier, 0);
+ MetierMonitor metierMon = context.getMetierMonitor();
+ metierMon.isLimited(metier, month);
+ metierMon.addforbiddenMetier(metier, month);
+ }
+ }
+ }
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+
+// MetierDAO metierDao = IsisFishDAOHelper.getMetierDAO(context.getDB());
+ ZoneDAO zoneDao = IsisFishDAOHelper.getZoneDAO(context.getDB());
+ MetierSeasonInfoDAO metierSeasonInfoDao = IsisFishDAOHelper.getMetierSeasonInfoDAO(context.getDB());
+
+// List<Metier> metiers = metierDao.findAll();
+ List<Month> SaisonFermee = Month.getMonths(param_beginMonth, param_endMonth);
+ List<Cell> maillefermee = param_zone.getCell();
+
+ FisheryRegion region = RegionStorage.getFisheryRegion(context.getDB());
+ List<Strategy> listestrategies= region.getStrategy();
+ List<Metier> metiers = region.getMetier();
+
+// var SaisonFermee= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+
+
+ for (Metier metier : metiers) {
+ log.info("metier examin� " + metier.getName());
+ if (param_gear != null && !metier.getGear().equals(param_gear)){
+ log.info("l engin du m�tier n est pas concern�");
+ }
+ else {
+ log.info("l engin du m�tier est bien concern�");
+ List<MetierSeasonInfo> saisons = metier.getMetierSeasonInfo();
+ for (MetierSeasonInfo saisonmetier: saisons){
+ int inter = siMatrix.nbCellInter(saisonmetier.getZone(), param_zone);
+ if (inter != 0){
+ List<Cell> MailleMetier = siMatrix.getCells(saisonmetier.getZone());
+
+ // les mailles qui reste dans la zone metier
+ List<Cell> newCellMetier = new ArrayList<Cell>(MailleMetier);
+ newCellMetier.removeAll(maillefermee);
+
+ List<Month> saison=saisonmetier.getMonths();
+ if (saison.containsAll(SaisonFermee)){
+ log.info("il y a bien intersection entre la zone m�tier et le cantonnement pour la saison "+saison.toString());
+ // calcule de la zone restante:
+ boolean ToutFerme=false;
+ boolean DebInclus=saison.contains(param_beginMonth);
+ boolean FinInclus=saison.contains(param_endMonth);
+
+ //creation du nouveau secteur de metier
+ Zone secteurResult = zoneDao.create();
+ secteurResult.setName("MetaCantonnement-" + metier.getName() + "-" + saison.toString());
+ secteurResult.setComment("Secteur cr�� durant la simulation.");
+ // on ajoute les mailles restants de la zone metier dans la zone resultante
+ secteurResult.addAllCell(newCellMetier);
+
+
+ // test pour savoir si toute la zone de pratique du metier
+ // (reunion de toutes les zones metiers de metier a date)
+ // est totalement incluse dans la zone Cantonnement
+ if (newCellMetier.size() != 0){ //le cas intersection.length==mailleMetier est dans condition
+ // si toute la zone de pratique du metier n'est pas incluse dans zone Cantonnement
+ ToutFerme=false;
+ } else {
+ log.info("Toute la zone metier est ferme");
+ ToutFerme=true;
+ }
+
+// 1er cas: la saison m�tier est identique (ou totalement incluse dans la saison ferm�e, dans ce cas l�, on change juste
+// le secteur
+ if (SaisonFermee.containsAll(saison)){
+ log.info("toute la saison metier est incluse dans la saison de fermeture");
+ //si tout est ferm�, on met le metier au ch�mage
+
+ if (ToutFerme==true) {
+ log.info ("toute la zone est ferm�e, le metier passe donc � ch�mage pour cette saison");
+ reportNonActivite(context, listestrategies, metiers, metier, saison);
+
+ } else {
+ log.info("tout n'est pas ferm�e, le secteur de p�che devient " + secteurResult);
+ for (Month month : SaisonFermee){
+ metier.getMetierSeasonInfo(month).clearZone();
+ metier.getMetierSeasonInfo(month).addZone(secteurResult);
+ }
+ }
+ }
+
+// 2�me cas de figure: moisDeb est inclus mais pas moisFin (ou alors c'est le dernier mois)
+ else if (DebInclus && ((!FinInclus) || param_endMonth.equals(saison.get(saison.size()-1)))) {
+ log.info ("il y a intersection de la saison de fermeture avec la saison m�tier de " + param_beginMonth + " � " + saison.get(saison.size()-1));
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ log.info ("toute la zone m�tier est ferm�e");
+ List<Month> chomageMonth = new ArrayList<Month>(SaisonFermee);
+ chomageMonth.retainAll(saison);
+ log.info ("de "+chomageMonth.get(0)+" a "+ chomageMonth.get(chomageMonth.size()-1)+ ", le metier est donc mis au chomage");
+
+ reportNonActivite(context, listestrategies, metiers, metier, chomageMonth);
+ } else {
+ //on commence par cr�e les nouvelles saisons
+// var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,saison.getLastMois().getNumMois());
+// var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+ saisonmetier.setLastMonth(param_beginMonth.previous());
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison= metierSeasonInfoDao.create();
+ NouvelInfoSaison.setMetier(metier);
+ NouvelInfoSaison.setFirstMonth(param_beginMonth);
+ NouvelInfoSaison.setLastMonth(saison.get(saison.size()-1));
+ NouvelInfoSaison.addZone(secteurResult);
+ NouvelInfoSaison.setComment("saison cr�e pendant la simulation") ;
+
+ metier.addMetierSeasonInfo(NouvelInfoSaison);
+ log.info ("de "+saison.get(0)+" � "+param_beginMonth.previous()+" le metier peche en "+saisonmetier.getZone());
+ log.info ("de "+param_beginMonth+" � "+saison.get(saison.size()-1)+" le metier peche en "+secteurResult);
+ }
+ }
+// 3�me cas de figure: moisFin est inclus mais pas moisDeb (ou alors il est �gal au premier mois)
+ else if (((!DebInclus) || param_beginMonth.equals(saison.get(0))) && FinInclus) {
+ log.info ("il y a intersection de la saison de fermeture avec la saison m�tier de "+param_beginMonth+" � "+saison.get(saison.size()-1));
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ log.info ("toute la zone est fermee");
+ List<Month> chomageMonth = new ArrayList<Month>(SaisonFermee);
+ chomageMonth.retainAll(saison);
+ reportNonActivite(context, listestrategies, metiers, metier, chomageMonth);
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ saisonmetier.setFirstMonth(param_endMonth.next());
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison= metierSeasonInfoDao.create();
+ NouvelInfoSaison.setMetier(metier);
+ NouvelInfoSaison.setFirstMonth(saison.get(0));
+ NouvelInfoSaison.setLastMonth(param_endMonth);
+ NouvelInfoSaison.addZone(secteurResult);
+ NouvelInfoSaison.setComment("saison cr�e pendant la simulation") ;
+
+ metier.addMetierSeasonInfo(NouvelInfoSaison);
+ log.info ("de "+saison.get(0)+" � "+param_endMonth+" le metier peche en "+secteurResult);
+ log.info ("de "+param_endMonth.next()+" � "+saison.get(saison.size()-1)+" le metier peche en "+saisonmetier.getZone());
+ }
+ }
+
+// dernier cas de figure: les deux sont inclus et sont diff�rents des bornes
+ else {
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ log.info("toute la zone m�tier est ferm�e");
+ reportNonActivite(context, listestrategies, metiers, metier, SaisonFermee);
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+// var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+// var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+// var NouvelleSaison3=new Packages.fr.ifremer.nodb.Saison(moisFin+1,saison.getLastMois().getNumMois());
+//
+ saisonmetier.setFirstMonth(param_beginMonth.previous());
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison = metierSeasonInfoDao.create();
+ NouvelInfoSaison.setMetier(metier);
+ NouvelInfoSaison.setFirstMonth(param_beginMonth);
+ NouvelInfoSaison.setLastMonth(param_endMonth);
+ NouvelInfoSaison.addZone(secteurResult);
+ NouvelInfoSaison.setComment("saison cr�e pendant la simulation") ;
+ metier.addMetierSeasonInfo(NouvelInfoSaison);
+
+ //on cr�e un nouveau infoSaisonMetier
+ MetierSeasonInfo NouvelInfoSaison2 = metierSeasonInfoDao.create();
+ NouvelInfoSaison2.setMetier(metier);
+ NouvelInfoSaison2.setFirstMonth(param_endMonth.next());
+ NouvelInfoSaison2.setLastMonth(saison.get(saison.size()-1));
+ NouvelInfoSaison2.setZone(saisonmetier.getZone());
+ NouvelInfoSaison2.setComment("saison cr�e pendant la simulation") ;
+ metier.addMetierSeasonInfo(NouvelInfoSaison2);
+
+ log.info ("de "+saison.get(0)+" � "+param_beginMonth.previous()+" le metier peche en "+saisonmetier.getZone());
+ log.info ("de "+param_beginMonth+" � "+param_endMonth+" le metier peche en "+secteurResult);
+ log.info ("de "+param_endMonth.next()+" � "+saison.get(saison.size()-1)+" le metier peche en "+saisonmetier.getZone());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ this.p = new Object();
+ this.p.paramRegle = this.param;
+ this.p.tableNonActivite=new Packages.java.util.HashMap();
+ this.p.affectNonActivite=false;
+
+
+ var enginselectif=this.param.getValue("EnginSelective");//entrez le nom de l'engin ferm�e ou non si pas de s�lection sur engin
+ var moisDeb=this.param.getValue("moisDeb"); //entrez le mois debut de fermeture
+ var moisFin=this.param.getValue("moisFin");//entrez le mois de fin de fermeture
+
+
+
+ var ZoneFermee=this.param.getValue("zone");
+ writeln("bla");
+ if (enginselectif) {var EnginInterdit=this.param.getValue("engin");} else {var EnginInterdit=MetierFactory.findByNom("nonActivite").getEngin();}
+ var RegionSimu=ZoneFermee.getRegion();
+ var ListeMetiers=MetierFactory.findAllByRegion(RegionSimu);
+ var MoisDeb=new Packages.fr.ifremer.nodb.Mois(moisDeb);
+ var MoisFin=new Packages.fr.ifremer.nodb.Mois(moisFin);
+ var SaisonFermee= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+
+
+
+ for (var imetier = ListeMetiers.iterator() ; imetier.hasNext();){
+ var metier=imetier.next();
+ writeln ("metier examin� "+metier.getNom());
+ if ((!metier.getEngin().equals(EnginInterdit)) && enginselectif){
+ writeln("l engin du m�tier n est pas concern�");
+ }
+ else {
+ writeln("l engin du m�tier est bien concern�");
+ var ListeSaisons = metier.getInfoSaison();
+ for (var isaisonmetier = ListeSaisons.iterator() ; isaisonmetier.hasNext();){
+ var saisonmetier=isaisonmetier.next();
+ var maillefermee=ZoneFermee.getMaille();
+ var MailleMetier=saisonmetier.getSecteur().getMaille().copy();
+ MailleMetier.retainAll(maillefermee);
+
+ if (MailleMetier.size()!=0){
+ MailleMetier=saisonmetier.getSecteur().getMaille().copy();
+ var saison=saisonmetier.getSaison();
+ if (saison.contains(SaisonFermee)){
+ writeln("il y a bien intersection entre la zone m�tier et le cantonnement pour la saison "+saison.toString());
+// calcule de la zone restante:
+ var ToutFerme=false;
+ var DebInclus=saison.contains(MoisDeb);
+ var FinInclus=saison.contains(MoisFin);
+ MailleMetier.removeAll(maillefermee);
+ writeln("inter maille:"+MailleMetier.size());
+ // test pour savoir si toute la zone de pratique du metier
+ // (reunion de toutes les zones metiers de metier a date)
+ // est totalement incluse dans la zone Cantonnement
+
+ if (MailleMetier.size() != 0){ //le cas intersection.length==mailleMetier est dans condition
+ // si toute la zone de pratique du metier n'est pas incluse dans zone Cantonnement
+
+ ToutFerme=false;
+
+ //creation du nouveau secteur de metier
+ //on v�rifie si le secteur a pas d�j� �t� modifi� par une autre r�gle afin de ne pas avoir de probl�me d'ID
+ var ListeSecteur=MetaSecteurFactory.findAllByKey("MetaCantonnement-"+metier.getNom()+saison.toString(), RegionSimu);
+ if (ListeSecteur.size()!=0){
+ var secteurResult = MetaSecteurFactory.create(saisonmetier.getSecteur().getNom()+"Modif", RegionSimu, "Secteur cr�� durant la simulation.");
+ }
+ else{
+ var secteurResult = MetaSecteurFactory.create("MetaCantonnement-"+metier.getNom()+saison.toString(),RegionSimu, "Secteur cr�� durant la simulation.");
+ }
+
+ writeln("nouveau secteur cree:"+secteurResult);
+ var zonesMetier = saisonmetier.getSecteur().getAllSecteur();
+ writeln("zonesMetier:"+zonesMetier);
+ writeln("zonesMetier.size:"+zonesMetier.size());
+
+ for(var i=0; i<zonesMetier.size(); i++){
+ var zonemet = zonesMetier.get(i);
+ writeln("zonemet:"+zonemet);
+ // intersection entre la zeme zone metier a date et zone de Cantonnement
+ var listemailleszonemetier = zonemet.getMaille().copy();
+ var nbMailleZoneMetier = listemailleszonemetier.size();
+ writeln("maille metier:"+listemailleszonemetier);
+ writeln("maille Cantonnement:"+maillefermee);
+ listemailleszonemetier.removeAll(maillefermee);
+ if(0==listemailleszonemetier.size()){
+ //si completement inclus on le supprime
+ //donc on ne le met pas dans le nouveau
+ writeln("on supprime la zone"+zonemet);
+ }
+ else if (listemailleszonemetier.size() != nbMailleZoneMetier) {
+ // si la zone metier n'est pas totalement incluse dans zone de Cantonnement
+ // on reduit la zeme zone metier de cette intersection
+ // pas de modif de la matrice de proportion strmet
+ writeln("on cree une nouvelle zone a partir de:"+zonemet+" avec "+listemailleszonemetier);
+ var simpleSecteur = SecteurSimpleFactory.create("Cantonnement-"+metier.getNom()+"-"+zonemet+saison.toString(), RegionSimu, "Secteur creer durant la simulation.");
+ simpleSecteur.addAllMaille(listemailleszonemetier);
+ secteurResult.addSecteur(simpleSecteur);
+ writeln("apres addSecteur");
+ }
+ else {
+ //sinon on le met dans le nouveau
+ writeln("On remet tel quelle la zone:"+zonemet);
+ secteurResult.addSecteur(zonemet);
+ }
+ }// fin du for sur les zone metier de la zone de pratique du metier
+ }
+
+ else {
+ var secteurResult=saisonmetier.getSecteur().getAllSecteur();
+ writeln("Toute la zone metier est ferme");
+ ToutFerme=true;
+ }
+
+// 1er cas: la saison m�tier est identique (ou totalement incluse dans la saison ferm�e, dans ce cas l�, on change juste
+// le secteur
+ if (SaisonFermee.toListMois().containsAll(saison.toListMois())){
+ writeln("toute la saison metier est incluse dans la saison de fermeture");
+ //si tout est ferm�, on met le metier au ch�mage
+
+ if (ToutFerme==true){
+ writeln ("toute la zone est ferm�e, le metier passe donc � ch�mage pour cette saison");
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ var ListeMois=saison.toListMois();
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier)){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ writeln("tout n'est pas ferm�e, le secteur de p�che devient "+secteurResult);
+ var ListeMois=SaisonFermee.toListMois();
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ mois=imois.next();
+ metier.setSecteurMois(secteurResult, mois);
+ }
+ }
+ }
+
+// 2�me cas de figure: moisDeb est inclus mais pas moisFin (ou alors c'est le dernier mois)
+ else if (DebInclus && ((!FinInclus) || moisFin==saison.getLastMois().getNumMois())){
+ writeln ("il y a intersection de la saison de fermeture avec la saison m�tier de "+moisDeb+" � "+saison.getLastMois().getNumMois());
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ writeln ("toute la zone m�tier est ferm�e");
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ var ListeMois=SaisonFermee.toListMois().retainAll(saison.toListMois());
+ writeln ("de "+ListeMois.get(0)+" a "+ ListeMois.get(ListeMois.size())+ ", le metier est donc mis au chomage");
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier)){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,saison.getLastMois().getNumMois());
+ var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+ saisonmetier.setSaison(NouvelleSaison1);
+ //on cr�e un nouveau infoSaisonMetier
+ var NouvelInfoSaison=InfoSaisonMetierFactory.create(metier, NouvelleSaison2, secteurResult, "saison cr�e pendant la simulation") ;
+ metier.addInfoSaison(NouvelInfoSaison);
+ writeln ("de "+saison.getFirstMois().getNumMois()+" � "+moisDeb-1+" le metier peche en "+saisonmetier.getSecteur());
+ writeln ("de "+moisDeb+" � "+saison.getLastMois().getNumMois()+" le metier peche en "+secteurResult);
+ }
+ }
+// 3�me cas de figure: moisFin est inclus mais pas moisDeb (ou alors il est �gal au premier mois)
+ else if (((!DebInclus) || moisDeb==saison.getFirstMois().getNumMois()) && FinInclus){
+ writeln ("il y a intersection de la saison de fermeture avec la saison m�tier de "+moisDeb+" � "+saison.getLastMois().getNumMois());
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ writeln ("toute la zone est fermee");
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ var ListeMois=SaisonFermee.toListMois().retainAll(saison.toListMois());
+ writeln ("de "+ListeMois.get(0)+" a "+ ListeMois.get(ListeMois.size())+ ", le metier est donc mis au chomage");
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier) ){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisFin);
+ var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisFin+1,saison.getLastMois.getNumMois());
+ saisonmetier.setSaison(NouvelleSaison2);
+ //on cr�e un nouveau infoSaisonMetier
+ var NouvelInfoSaison=InfoSaisonMetierFactory.create(metier, NouvelleSaison1, secteurResult, "saison cr�e pendant la simulation") ;
+ metier.addInfoSaison(NouvelInfoSaison);
+ writeln ("de "+saison.getFirstMois().getNumMois()+" � "+moisFin+" le metier peche en "+secteurResult);
+ writeln ("de "+moisFin+1+" � "+saison.getLastMois().getNumMois()+" le metier peche en "+saisonmetier.getSecteur());
+ }
+ }
+
+// dernier cas de figure: les deux sont inclus et sont diff�rents des bornes
+ else {
+ //si tout est ferm� on met les proportions � 0 pour les mois fermes
+ if (ToutFerme==true){
+ writeln("toute la zone m�tier est ferm�e");
+ var listestrategies=StrategyFactory.findAllByRegion(metier.getRegion());
+ var ListeMois=SaisonFermee.toListMois();
+ writeln("le m�tier passe � ch�mage de "+moisDeb+" � "+moidFin);
+ for(var i=0; i<listestrategies.size(); i++){
+ var SetOfBateau=listestrategies.get(i).getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier) ){
+ for (imois=ListeMois.iterator();imois.hasNext();){
+ var mois=imois.next();
+ var InfoMois=listestrategies.get(i).getStrategyMonthInfo(mois);
+ //this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+
+
+writeln("debut reportNonActivite");
+//on regarde si on a d�j� une entr�e pour le mois courant
+var matNonActiviteMois=table.get(mois);
+var nonactivite=matNonActiviteMois!=null;
+
+if (!nonactivite){
+ matNonActiviteMois=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ table.put(mois,matNonActiviteMois);
+}
+
+matNonActiviteMois.setValue(strategie,metier,proportion);
+writeln("fin reportNonActivite");
+
+
+
+ InfoMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ }
+ }
+ }
+ }
+ else {
+ //on commence par cr�e les nouvelles saisons
+ var NouvelleSaison1= new Packages.fr.ifremer.nodb.Saison(saison.getFirstMois().getNumMois(),moisDeb-1);
+ var NouvelleSaison2= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+ var NouvelleSaison3=new Packages.fr.ifremer.nodb.Saison(moisFin+1,saison.getLastMois().getNumMois());
+ saisonmetier.setSaison(NouvelleSaison1);
+ //on cr�e 2 nouveau infoSaisonMetier
+ var NouvelInfoSaison2=InfoSaisonMetierFactory.create(metier, NouvelleSaison2, secteurResult, "saison cr�e pendant la simulation") ;
+ var NouvelInfoSaison3=InfoSaisonMetierFactory.create(metier, NouvelleSaison3, saisonmetier.getSecteur(), "saison cr�e pendant la simulation") ;
+ metier.addInfoSaison(NouvelInfoSaison2);
+ metier.addInfoSaison(NouvelInfoSaison3);
+ writeln ("de "+saison.getFirstMois().getNumMois()+" � "+(moisDeb-1)+" le metier peche en "+saisonmetier.getSecteur());
+ writeln ("de "+moisDeb+" � "+moisFin+" le metier peche en "+secteurResult);
+ writeln ("de "+(moisFin+1)+" � "+saison.getLastMois().getNumMois()+" le metier peche en "+saisonmetier.getSecteur());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ */
+
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ boolean result = false;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+ if (mat != null && affectNonActivite == false) {
+ result = true;
+ }
+ return result;
+ // fin
+
+ /*
+ var mat=p.tableNonActivite.get(p.date.getMois());
+ writeln(p.affectNonActivite);
+ if(oldValue != undefined)
+ return oldValue;
+ else if (mat!=null && p.affectNonActivite==false){
+ return true;
+ }
+ else {return false;}
+ */
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // on ne doit le faire qu'une seul fois quelque soit le nombre de metier
+ affectNonActivite=true;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND noActivity = metierMon.getNoActivity(date);
+
+ if (noActivity == null){
+ metierMon.setNoActivity(date, mat.copy());
+ }
+ else{
+ noActivity = noActivity.add(mat);
+ }
+
+ /*
+ p.affectNonActivite=true;
+var mat=p.tableNonActivite.get(p.date.getMois());
+var matNonActivite=nonActivite.get(p.date);
+var nonactivite=matNonActivite!=null;
+if (!nonactivite){
+ nonActivite.put(p.date,mat);
+}
+else{
+ matNonActivite=matNonActivite.add(mat);
+}
+return p.gestionMetier;
+
+ */
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ affectNonActivite = false;
+
+ /*
+ p.affectNonActivite=false;
+return p.gestionMetier;
+ */
+ }
+
+}
Added: trunk/3.1.0/rules/ChangementParamControlablePresimu.java
===================================================================
--- trunk/3.1.0/rules/ChangementParamControlablePresimu.java (rev 0)
+++ trunk/3.1.0/rules/ChangementParamControlablePresimu.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,316 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * TailleMin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class ChangementParamControlablePresimu extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(ChangementParamControlablePresimu.class);
+
+ public Zone param_zone = null;
+ public Gear param_gear = null;
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+ public String param_newParamValue = "80";
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Change gear parameter value for all metier with this gear");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+
+ Zone ZoneFermee = param_zone;
+ Month MoisDeb = param_beginMonth;
+ Month MoisFin= param_endMonth;
+ String nouvelleValeurParam = param_newParamValue;
+ Gear EnginInterdit = param_gear;
+
+ log.info("nom de l'engin interdit " + EnginInterdit.getName());
+
+ FisheryRegion RegionSimu = RegionStorage.getFisheryRegion(context.getDB());
+ List<Metier> ListeMetiers = RegionSimu.getMetier();
+ List<Month> SaisonFermee = Month.getMonths(MoisDeb, MoisFin);
+
+ for (Metier metier : ListeMetiers) {
+ log.info("metier examin� " + metier.getName() + " son engin " + metier.getGear().getName());
+ if (!metier.getGear().equals(EnginInterdit)){
+ log.info("l engin du m�tier n est pas concern�");
+ } else {
+ log.info("l engin du m�tier est bien concern�");
+ if (ZoneFermee == null && Month.JANUARY.equals(MoisDeb) && Month.DECEMBER.equals(MoisFin)){
+ //aucun crit�re spatio-temporel il suffit donc de mettre
+ //le param controlable � la nouvelle valeur
+ metier.setGearParameterValue(nouvelleValeurParam);
+ log.info("aucune spatialisation ni saisonnalit�, on passe le Param Controlable a "+nouvelleValeurParam);
+ } else {
+ List<MetierSeasonInfo> ListeSaisons = metier.getMetierSeasonInfo();
+ for (MetierSeasonInfo saisonmetier : ListeSaisons) {
+ List<Month> saison = saisonmetier.getMonths();
+ int taille=0;
+ if (ZoneFermee != null){
+ taille = siMatrix.nbCellInter(saisonmetier.getZone(), ZoneFermee);
+ } else {
+ log.info ("pas de s�lection de zone, toute la zone d'�tude est donc concern�e");
+ }
+ if (ZoneFermee == null || taille!=0){
+ if (saison.containsAll(SaisonFermee)){
+ log.info ("il y a intersection de la zone metier au cours de la saison" + saison);
+ List<Month> moisconcerne = new ArrayList<Month>(saison);
+ moisconcerne.retainAll(SaisonFermee);
+
+ MetierDAO metierDao = IsisFishDAOHelper.getMetierDAO(context.getDB());
+ MetierSeasonInfoDAO infoDao = IsisFishDAOHelper.getMetierSeasonInfoDAO(context.getDB());
+ EffortDescriptionDAO effortDao = IsisFishDAOHelper.getEffortDescriptionDAO(context.getDB());
+
+ Metier NouveauMetier = metierDao.create();
+ NouveauMetier.setName(metier.getName()+" Mois "+moisconcerne.get(0).getMonthNumber()+" a "+moisconcerne.get(moisconcerne.size()-1).getMonthNumber()+" ValeurParam "+nouvelleValeurParam);
+ NouveauMetier.setGear(EnginInterdit);
+ NouveauMetier.setGearParameterValue(nouvelleValeurParam);
+ NouveauMetier.setComment("m�tier cr�� pendant la simu pour le changement de param�tre contr�lable");
+
+ for (MetierSeasonInfo infsais : metier.getMetierSeasonInfo()){
+ List<Month> sais = infsais.getMonths();
+ MetierSeasonInfo NouveauInfoSaison = infoDao.create();
+ NouveauInfoSaison.setMetier(NouveauMetier);
+ NouveauInfoSaison.setMonths(sais);
+ NouveauInfoSaison.setZone(infsais.getZone());
+ NouveauInfoSaison.setComment("cr�� durant la simulation");
+ NouveauMetier.addMetierSeasonInfo(NouveauInfoSaison);
+ }
+
+ //On ajoute aux strategies qui pratiquent le m�tier le nouveau m�tier
+ List<Strategy> listestrategies = RegionSimu.getStrategy();
+ for(Strategy strategie : listestrategies){
+ SetOfVessels SetOfBateau = strategie.getSetOfVessels();
+ EffortDescription AncienEffort = SetOfBateau.getPossibleMetiers(metier);
+ if (AncienEffort != null) {
+ EffortDescription DescriptionEffort = effortDao.create();
+ DescriptionEffort.setPossibleMetiers(NouveauMetier);
+ DescriptionEffort.setSetOfVessels(SetOfBateau);
+ DescriptionEffort.setFishingOperation(AncienEffort.getFishingOperation());
+ DescriptionEffort.setFishingOperationDuration(AncienEffort.getFishingOperationDuration());
+ DescriptionEffort.setGearsNumberPerOperation(AncienEffort.getGearsNumberPerOperation());
+ DescriptionEffort.setCrewSize(AncienEffort.getCrewSize());
+ DescriptionEffort.setUnitCostOfFishing(AncienEffort.getUnitCostOfFishing());
+ DescriptionEffort.setFixedCrewSalary(AncienEffort.getFixedCrewSalary());
+ DescriptionEffort.setCrewShareRate(AncienEffort.getCrewShareRate());
+ DescriptionEffort.setCrewFoodCost(AncienEffort.getCrewFoodCost());
+ DescriptionEffort.setRepairAndMaintenanceGearCost(AncienEffort.getRepairAndMaintenanceGearCost());
+ DescriptionEffort.setLandingCosts(AncienEffort.getLandingCosts());
+ DescriptionEffort.setOtherRunningCost(AncienEffort.getOtherRunningCost());
+
+ SetOfBateau.addPossibleMetiers(DescriptionEffort);
+
+ // on a ajout� le nouveau m�tier au set of vessels,
+ // maintenant, on va report� l'effort du m�tier ancien
+ // vers le nouveau pour les mois concern�s
+ for (Month mois : Month.MONTH){
+ StrategyMonthInfo PropStratMois = strategie.getStrategyMonthInfo(mois);
+ double prop = PropStratMois .getProportionMetier(metier);
+ if (moisconcerne.contains(mois) && prop != 0){
+ //on cr�� un nouveau PropStrMet
+ log.info ("la strat�gie "+strategie.getName()+" pratique bien le metier "+metier.getName()+" au mois " + mois);
+ PropStratMois.setProportionMetier(NouveauMetier, prop);
+ PropStratMois.setProportionMetier(metier, 0);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // fin de la methode
+
+ /*
+this.p = new Object();
+this.p.paramRegle = this.param;
+
+
+//attention: cette r�gle de gestion ne fonctionne que si le changement a lieu pour toutes
+//les ann�es de simulation
+
+
+var zoneselective=this.param.getValue("ZoneSelective"); //entrez le nom de la zone concern�e, non si pas de s�lection sur zone
+var moisDeb=this.param.getValue("moisDeb"); //entrez le mois debut de fermeture
+var moisFin=this.param.getValue("moisFin");//entrez le mois de fin de fermeture
+var nouvelleValeurParam=this.param.getValue("nouvelleValeurParam");//entrez la valeur du param�tre contr�lable
+
+
+if (zoneselective!="non") {
+ var ZoneFermee=this.param.getValue("zone");
+}
+var EnginInterdit=this.param.getValue("engin");
+writeln("nom de l'engin interdit "+EnginInterdit.getNom());
+var RegionSimu=EnginInterdit.getRegion();
+var ListeMetiers=MetierFactory.findAllByRegion(RegionSimu);
+var MoisDeb=new Packages.fr.ifremer.nodb.Mois(moisDeb);
+var MoisFin=new Packages.fr.ifremer.nodb.Mois(moisFin);
+var SaisonFermee= new Packages.fr.ifremer.nodb.Saison(moisDeb,moisFin);
+
+
+
+
+for (var imetier = ListeMetiers.iterator() ; imetier.hasNext();){
+ var metier=imetier.next();
+ writeln ("metier examin� "+metier.getNom()+"son engin "+metier.getEngin().getNom());
+ if (!metier.getEngin().equals(EnginInterdit)){
+ writeln("l engin du m�tier n est pas concern�");
+ }
+ else {
+ writeln("l engin du m�tier est bien concern�");
+ if (zoneselective==false && moisDeb==0 && moisFin==11){
+ //aucun crit�re spatio-temporel il suffit donc de mettre
+ //le param controlable � la nouvelle valeur
+ metier.setValeurParamControlable(nouvelleValeurParam);
+ writeln("aucune spatialisation ni saisonnalit�, on passe le Param Controlable a "+nouvelleValeurParam);
+ }
+ else {
+ var ListeSaisons = metier.getInfoSaison();
+ for (var isaisonmetier = ListeSaisons.iterator() ; isaisonmetier.hasNext();){
+ var saisonmetier=isaisonmetier.next();
+ var saison=saisonmetier.getSaison();
+ var taille=0;
+ if (zoneselective){
+ var maillefermee=ZoneFermee.getMaille();
+ var MailleMetier=saisonmetier.getSecteur().getMaille().copy();
+ MailleMetier.retainAll(maillefermee);
+ taille=MailleMetier.size();
+ }
+ else {
+ writeln ("pas de s�lection de zone, toute la zone d'�tude est donc concern�e");
+ }
+ if (zoneselective==false || taille!=0){
+ if (saison.contains(SaisonFermee)){
+ writeln ("il y a intersection de la zone metier au cours de la saison"+saison.toString());
+ var moisconcerne=saison.copy().toListMois();
+ moisconcerne.retainAll(SaisonFermee.toListMois());
+ var NouveauMetier=MetierFactory.create(metier.getNom()+" Mois "+moisconcerne.get(0).getNumMois()+" a "+moisconcerne.get(moisconcerne.size()-1).getNumMois()+" ValeurParam "+nouvelleValeurParam, RegionSimu, EnginInterdit,nouvelleValeurParam, "m�tier cr�� pendant la simu pour le changement de param�tre contr�lable");
+ for (var iinfsais=metier.getInfoSaison().iterator();iinfsais.hasNext();){
+ var infsais=iinfsais.next();
+ var sais=infsais.getSaison();
+ var NouveauInfoSaison=InfoSaisonMetierFactory.create(NouveauMetier, sais, infsais.getSecteur(), "cr�� durant la simulation")
+ NouveauMetier.addInfoSaison(NouveauInfoSaison);
+ }
+
+ //On ajoute aux strategies qui pratiquent le m�tier le nouveau m�tier
+ var listestrategies=StrategyFactory.findAllByRegion(RegionSimu);
+ for(var i=0; i<listestrategies.size(); i++){
+ var strategie=listestrategies.get(i);
+ var SetOfBateau=strategie.getSetOfVessels();
+ var MetiersPosibles=SetOfBateau.getMetiers();
+ if (MetiersPosibles.contains(metier)){
+ var AncienEffort=SetOfBateau.getEffort(metier);
+ var DescriptionEffort=EffortDescriptionFactory.create(NouveauMetier, SetOfBateau, AncienEffort.getFishingOperation(), AncienEffort.getFishingOperationDuration(), AncienEffort.getGearsNumberPerOperation(), AncienEffort.getCrewSize(), AncienEffort.getUnitCostOfFishing(), AncienEffort.getFixedCrewSalary(), AncienEffort.getCrewShareRate(), AncienEffort.getCrewFoodCost(), AncienEffort.getRepairAndMaintenanceGearCost(), AncienEffort.getLandingCosts(), AncienEffort.getOtherRunningCosts(), "effort description cr�� durant la simulation");
+
+ SetOfBateau.addPossibleMetiers(DescriptionEffort);
+
+ //on a ajout� le nouveau m�tier au set of vessels, maintenant, on va report� l'effort du m�tier ancien vers le nouveau pour les mois concern�s
+ for (var intmois=0; intmois<=11;intmois++){
+ var mois=new Packages.fr.ifremer.nodb.Mois(intmois);
+ var PropStratMois=strategie.getStrategyMonthInfo(mois);
+ var NouveauStrMet=PropStrMetFactory.create(PropStratMois, NouveauMetier, 0, "cr�� durant la simulation");
+ PropStratMois.addPropStrMet(NouveauStrMet);
+ if (moisconcerne.contains(mois) && PropStratMois.getProportionMetier(metier)!=0){
+ //on cr�� un nouveau PropStrMet
+ writeln ("la strat�gie "+strategie.getName()+" pratique bien le metier "+metier.getNom()+" au mois "+mois.getNumMois());
+ PropStratMois.setProportionMetier(NouveauMetier,new Packages.java.lang.Float(PropStratMois.getProportionMetier(metier)));
+ PropStratMois.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+ */
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ return false;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+}
Added: trunk/3.1.0/rules/GraviteCPUE.java
===================================================================
--- trunk/3.1.0/rules/GraviteCPUE.java (rev 0)
+++ trunk/3.1.0/rules/GraviteCPUE.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,484 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.GravityModel;
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * GraviteCPUE.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2007-07-18 08:59:38 $
+ * by : $Author: hilaire $
+ */
+public class GraviteCPUE extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(GraviteCPUE.class);
+
+ /** stocke la somme des prop initiales [str x month] */
+ private MatrixND SommePropInitial = null;
+ /** stocke par strat*met, la derni�re attractivite pour chaque mois
+ * [str x met x month] */
+ private MatrixND HistoriqueCPUE = null;
+
+ /** va permettre de stocker a chaque pas de temps la somme des attractivite [str] */
+ MatrixND SommeCPUEstrat = null;
+ /** va permettre de stocker a chaque pas de temps la somme des proportions
+ * pour les metiers n'ayant pas d'attractivite [str] */
+ MatrixND SommeProp = null;
+
+ /** permet de stocker les CPUE standardiser [str x met] */
+ private MatrixND catchPerUnitOfEffort = null;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET,
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ // TODO
+ return _("GraviteCPUE");
+ }
+
+ /**
+ * function used to initialise MatrixND to NaN double
+ */
+ private MapFunction nanFunction = new MapFunction() {
+ public double apply(double value) {
+ return Double.NaN;
+ }
+ };
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ Date date = new Date(0);
+
+ List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date);
+ List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date);
+ List<Month> months = Arrays.asList(Month.MONTH);
+
+ SommePropInitial = MatrixFactory.getInstance().create("SommePropInitial",
+ new List[]{strs, months}, new String[]{"Strategies", "Months"});
+ SommePropInitial.map(nanFunction);
+
+ HistoriqueCPUE = MatrixFactory.getInstance().create("HistoriqueCPUE",
+ new List[]{strs, metiers, months}, new String[]{"Strategies", "Metiers", "Months"});
+ HistoriqueCPUE.map(nanFunction);
+
+
+ SommeCPUEstrat = MatrixFactory.getInstance().create("SommeCPUEstrat",
+ new List[]{strs}, new String[]{"Strategies"});
+ SommeCPUEstrat.map(nanFunction);
+
+ SommeProp = MatrixFactory.getInstance().create("SommeProp",
+ new List[]{strs}, new String[]{"Strategies"});
+ SommeProp.map(nanFunction);
+
+ catchPerUnitOfEffort = MatrixFactory.getInstance().create("ValuePerUnitOfEffort",
+ new List[]{strs, metiers}, new String[]{"Strategies", "Metiers"});
+ catchPerUnitOfEffort.map(nanFunction);
+
+ for (Strategy str : strs) {
+ List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date);
+ List<StrategyMonthInfo> infos = str.getStrategyMonthInfo();
+ for (StrategyMonthInfo info : infos) {
+ double somme = 0;
+ for (Metier strMetier : strMetiers) {
+ somme += info.getProportionMetier(strMetier);
+ }
+ // FIXME soit on somme pour toutes les str le meme metier; donc pas de notion de str.getName dans la cle
+ // soit pour une str on somme tous ces metiers (mais ce doit etre 1; donc pas de notion de metier.getName dans la cle
+ SommePropInitial.setValue(str, info.getMonth(), somme);
+ }
+ }
+
+/*
+var allStr = SiMatrice.getListStrategies();
+
+for(var i=0; i<allStr.size(); i++){
+ var str=allStr.get(i);
+ var metiers=str.getSetOfVessels().getMetiers();
+ var ListeStrMonthInfos=str.getStrategyMonthInfos();
+ for (var j=0; j<ListeStrMonthInfos.size();j++){
+ var somme=0;
+ var StrMonthInfo=ListeStrMonthInfos.get(j);
+ for (var k=0;k<metiers.size();k++){
+ var metier=metiers.get(k);
+ somme+=StrMonthInfo.getProportionMetier(metier);
+ }
+ this.p.SommePropInitial.put(new Chaine(str.getName()+"-"+metier.getNom()+"-"+StrMonthInfo.getMonth().getNumMois()),somme);
+ }
+}
+
+ //permet de stocker les CPUE standardiser
+CatchperUnitOfEffort = MatrixFactory.create("ValuePerUnitOfEffort",new Array(allStr,SiMatrice.getListMetiers()),new Array("Strategies","Metiers"));
+*/
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ // Il faut etre au moins au deuxieme pas de temps.
+ // FIXME 2eme pas de temps ou 2eme annee ? ici c 2eme annee et non pas 2eme mois
+ return date.getYear() > 0;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ if (log.isDebugEnabled()) {
+ log.debug("Gravite Action avant metier:"+ metier + "date:"+ date);
+ }
+
+ List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date);
+ List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date);
+
+ double newPropDiv = 0;
+
+ ResultStorage resultmanager = context.getSimulationStorage().getResultStorage();
+
+ //on commence par creer une matrice de capture par strategie met
+ MatrixND catchWeigthPerStrMet = null;
+ for (Population pop : populations){
+ MatrixND temp = resultmanager.getMatrix(
+ date.previousYear(),
+ pop,
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ // on somme sur les zones
+ temp=temp.sumOverDim(3);
+ // on somme sur les groupes
+ temp=temp.sumOverDim(2);
+ if (catchWeigthPerStrMet == null) {
+ catchWeigthPerStrMet = temp;
+ } else {
+ catchWeigthPerStrMet.add(temp);
+ }
+ }
+
+ MatrixND effortPerStrMet = resultmanager.getMatrix(
+ date.previousYear(),
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+
+ for (Strategy str : strs){
+ List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date);
+ for (Metier strMetier : strMetiers){
+ double effort = effortPerStrMet.getValue(str, strMetier);
+ if (effort > 0){
+ EffortDescription effortdesc = str.getSetOfVessels().getPossibleMetiers(strMetier);
+ int nombreop=effortdesc.getFishingOperation();
+ int nombregear=effortdesc.getGearsNumberPerOperation();
+ double param=strMetier.getGearParameterValueAsDouble();
+ double facteur = param * nombreop * nombregear*strMetier.getGear().getStandardisationFactor() / 24.0;
+ //on restandardise l'effort
+ effort /= facteur;
+ //on recupere la capture tot
+ Object group = catchWeigthPerStrMet.getSemantics(2).get(0);
+ Object zone = catchWeigthPerStrMet.getSemantics(3).get(0);
+
+ double capture = catchWeigthPerStrMet.getValue(str, strMetier, group, zone);
+
+ catchPerUnitOfEffort.setValue(str, strMetier, capture/effort);
+ }
+ }
+ }
+
+
+
+ for (Strategy str : strs){
+ List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date);
+ StrategyMonthInfo info = str.getStrategyMonthInfo(date.getMonth());
+
+ if(strMetiers.contains(metier)){
+ // on verifie que le metier est bien un metier possible
+ double CPUE = Double.NaN;
+ if (SommeCPUEstrat.getValue(str) == Double.NaN){
+ if (effortPerStrMet.getValue(str, metier) > 0){
+ CPUE = catchPerUnitOfEffort.getValue(str, metier);
+ }
+ }
+
+ if (CPUE != Double.NaN){
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE l'ann�e n-1, on la met dans l'historique\n" + info + " " + metier);
+ }
+ HistoriqueCPUE.setValue(str, metier, info.getMonth(), CPUE);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("ou calcul d�j� fait ou pas de CPUE � l'ann�e n-1");
+ }
+ CPUE = HistoriqueCPUE.getValue(str, metier, info.getMonth());
+ if (CPUE != Double.NaN) {
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE dans le pass�: " + CPUE);
+ }
+ } else{
+ if (log.isDebugEnabled()) {
+ log.debug("on a pas de CPUE dans le pass�, on remet donc la poportion initiale");
+ }
+ }
+ }
+ if (CPUE != Double.NaN) {
+ // si on a une CPUE, il faut aller voir l'attractivite des autres metiers: 2 cas de figure:
+ // soit on en retrouve une dans le passe qui est son attractivite
+ // soit on en retrouve pas et dans ce cas le, la proportion d'effort sera celle initiale de la db
+ // on a alors newProp=(1-sum(pmet1))*CPUE/somme(CPUEmet2)
+ // avec pmet1 la proprtion initiale pour les metiers pour lesquels on a pas retrouve de CPUE, CPUEmet2, la CPUE pour les
+ // metiers qui ont eu une CPUE dans le passe, et CPUE la CPUE du metier courant
+ if (SommeCPUEstrat.getValue(str) == Double.NaN){
+ double SommeCPUE=0;
+ double PropTot=0;
+ for (Metier strMetier : strMetiers){
+ double temp = Double.NaN;
+ if (effortPerStrMet.getValue(str, strMetier) > 0){
+ temp = catchPerUnitOfEffort.getValue(str, strMetier);
+ }
+ if (temp != Double.NaN){
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE l'ann�e n-1, on l'ajoute � p.SommeCPUEstrat");
+ }
+ HistoriqueCPUE.setValue(str, metier, info.getMonth(), temp);
+ SommeCPUE += temp;
+ }
+ else{
+ if (log.isDebugEnabled()) {
+ log.debug("on a pas de CPUE l'ann�e n-1, on regarde si il y en a dans le pass�");
+ }
+ temp = HistoriqueCPUE.getValue(str, metier, info.getMonth());
+ if (temp != Double.NaN){
+ if (log.isDebugEnabled()) {
+ log.debug("on a une CPUE dans le pass�: "+temp);
+ }
+ SommeCPUE+=temp;
+ }
+ else{
+ if (log.isDebugEnabled()) {
+ log.debug("on a pas de CPUE dans le pass�, on l'ajoute donc � p.SommeProp");
+ }
+ PropTot += info.getProportionMetier(strMetier);
+ }
+ }
+ }
+ SommeCPUEstrat.setValue(str, SommeCPUE);
+ SommeProp.setValue(str, PropTot);
+ }
+
+ if (SommeCPUEstrat.getValue(str) > 0){
+ newPropDiv = (SommePropInitial.getValue(str, info.getMonth()) - SommeProp.getValue(str))
+ * CPUE / SommeCPUEstrat.getValue(str);
+ if (log.isDebugEnabled()) {
+ log.debug("newpropdiv: " + newPropDiv);
+ }
+ info.setProportionMetier(metier, newPropDiv);
+ }
+ else { // c'est le cas e priori quasi impossible oe y a toujours eu une CPUE nulle quelquesoit le metier, dans ce cas le on remet aussi la prop iniitiale
+ if (log.isDebugEnabled()) {
+ log.debug("aucun metier n'a d'attractivite, on remet la prop initiale");
+ }
+ }
+ }
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("fin Gravite CPUEAction avant");
+ }
+
+/*
+writeln("Gravite Action avant metier:"+p.metier+ "date:"+ p.date);
+var Chaine=Packages.java.lang.String;
+
+
+
+var month=p.date.getMois();
+var allStr = SiMatrice.getListStrategies();
+var newPropDiv=0.0;
+
+if (!p.CalculCatch){
+ var resultmanager=control.getResultatManager();
+
+ //on commence par creer une matrice de capture par strategie met
+ var ListePopulation=SiMatrice.getListPopulations();
+ pop=ListePopulation.get(0);
+ var CaptureParStrMet=resultmanager.getMatrix(new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12),pop,"matriceCatchWeightPerStrategyMet");
+ CaptureParStrMet=CaptureParStrMet.sumOverDim(3);
+ CaptureParStrMet=CaptureParStrMet.sumOverDim(2);
+ writeln(CaptureParStrMet);
+ for (var ipop=1;ipop<ListePopulation.size();ipop++){
+ var pop=ListePopulation.get(ipop);
+ var temp=resultmanager.getMatrix(new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12),pop,"matriceCatchWeightPerStrategyMet");
+ temp=temp.sumOverDim(3);
+ temp=temp.sumOverDim(2);
+ writeln(temp);
+ CaptureParStrMet.add(temp);
+ writeln(CaptureParStrMet);
+ }
+
+ var Effort=resultmanager.getMatrix(new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12),"matriceEffortPerStrategyMet");
+ writeln("on r�cup�re la matrice d'effort");
+ for (var iStrategie=allStr.iterator();iStrategie.hasNext();){
+ var Strategie=iStrategie.next();
+ var listeMet=Strategie.getSetOfVessels().getMetiers();
+ for (imetier=listeMet.iterator();imetier.hasNext();){
+ var metier=imetier.next();
+ var effort=Effort.getValue(Strategie,metier);
+ if (effort>0){
+ var effortdesc=Strategie.getSetOfVessels().getEffort(metier);
+ var nombreop=effortdesc.getFishingOperation();
+ var nombregear=effortdesc.getGearsNumberPerOperation();
+ var param=metier.getValeurParamControlable();
+ var facteur=metier.getValeurParamControlable()*nombreop*nombregear/24.0;
+ //on restandardise l'effort
+ effort/=facteur;
+ //on recupere la capture tot
+ var dim3=new Packages.java.util.ArrayList(CaptureParStrMet.getSemantics(3));
+ var dim2=new Packages.java.util.ArrayList(CaptureParStrMet.getSemantics(2));
+
+ var capture=CaptureParStrMet.getValue(Strategie,metier,dim2.get(0),dim3.get(0));
+
+ p.CatchperUnitOfEffort.setValue(Strategie,metier,capture/effort);
+ }
+ }
+ }
+ p.CalculCatch=true;
+}
+
+
+
+for(var i=0; i<allStr.size(); i++){
+ var str = allStr.get(i);
+ var strMonthInfo = str.getStrategyMonthInfo(month);
+ var propStrMet = strMonthInfo.getPropStrMetier(p.metier);
+
+ if(str.getSetOfVessels().getMetiers().contains(p.metier)){
+//on verifie que le metier est bien un metier possible
+ var CPUE=null;
+ if (!p.SommeCPUEstrat.containsKey(new Chaine(str.getName()))){
+ if (GravityModel.getEffortPerStrategyMet(str, p.metier, new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12))>0){
+ CPUE=p.CatchperUnitOfEffort.getValue(str,p.metier);
+ }
+ }
+ if (CPUE!=null){
+ writeln("on a une CPUE l'ann�e n-1, on la met dans l'historique");
+ writeln(strMonthInfo+" "+p.metier);
+ p.HistoriqueCPUE.put(new Chaine(str.getName()+"-"+p.metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()),CPUE);
+ }
+ else{
+ writeln ("ou calcul d�j� fait ou pas de CPUE � l'ann�e n-1");
+ CPUE=p.HistoriqueCPUE.get(new Chaine(str.getName()+"-"+p.metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()));
+ if (CPUE!=null){
+ writeln ("on a une CPUE dans le pass�: "+CPUE);
+ }
+ else{
+ writeln ("on a pas de CPUE dans le pass�, on remet donc la poportion initiale");
+ }
+ }
+ if (CPUE!=null) {
+//si on a une CPUE, il faut aller voir l'attractivite des autres metiers: 2 cas de figure:
+// soit on en retrouve une dans le passe qui est son attractivite
+// soit on en retrouve pas et dans ce cas le, la proportion d'effort sera celle initiale de la db
+//on a alors newProp=(1-sum(pmet1))*CPUE/somme(CPUEmet2)
+//avec pmet1 la proprtion initiale pour les metiers pour lesquels on a pas retrouve de CPUE, CPUEmet2, la CPUE pour les
+//metiers qui ont eu une CPUE dans le passe, et CPUE la CPUE du metier courant
+ if (!p.SommeCPUEstrat.containsKey(str.getName())){
+ var SommeCPUE=0;
+ var PropTot=0;
+ var metiers=str.getSetOfVessels().getMetiers();
+ for (var imetiers=metiers.iterator();imetiers.hasNext();){
+ var metier=imetiers.next();
+ var temp=null;
+ if (GravityModel.getEffortPerStrategyMet(str, metier, new Packages.fr.ifremer.nodb.Date(p.date.getDate()-12))>0){
+ temp=p.CatchperUnitOfEffort.getValue(str,metier);
+ }
+ if (temp!=null){
+ writeln("on a une CPUE l'ann�e n-1, on l'ajoute � p.SommeCPUEstrat");
+ p.HistoriqueCPUE.put(new Chaine(str.getName()+"-"+metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()),CPUE);
+ SommeCPUE+=temp;
+ }
+ else{
+ writeln ("on a pas de CPUE l'ann�e n-1, on regarde si il y en a dans le pass�");
+ temp=p.HistoriqueCPUE.get(new Chaine(str.getName()+"-"+metier.getNom()+"-"+strMonthInfo.getMonth().getNumMois()));
+ if (temp!=null){
+ writeln ("on a une CPUE dans le pass�: "+temp);
+ SommeCPUE+=temp;
+ }
+ else{
+ writeln ("on a pas de CPUE dans le pass�, on l'ajoute donc � p.SommeProp");
+ PropTot+=strMonthInfo.getProportionMetier(metier);
+ }
+ }
+ }
+ p.SommeCPUEstrat.put(new Chaine(str.getName()),SommeCPUE);
+ p.SommeProp.put(new Chaine(str.getName()),PropTot);
+ }
+ if (p.SommeCPUEstrat.get(new Chaine(str.getName()))>0){
+ newPropDiv = (p.SommePropInitial.get(new Chaine(str.getName()+"-"+strMonthInfo.getMonth().getNumMois()))-p.SommeProp.get(new Chaine(str.getName())))*CPUE/ p.SommeCPUEstrat.get(new Chaine(str.getName()));
+ writeln("newpropdiv: "+newPropDiv);
+ strMonthInfo.setProportionMetier(p.metier, new Packages.java.lang.Float(newPropDiv));
+ }
+ else { // c'est le cas e priori quasi impossible oe y a toujours eu une CPUE nulle quelquesoit le metier, dans ce cas le on remet aussi la prop iniitiale
+ writeln("aucun metier n'a d'attractivite, on remet la prop initiale");
+ }
+ }
+ }
+}
+
+writeln("fin Gravite CPUEAction avant");
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ SommeCPUEstrat.map(nanFunction);
+ SommeProp.map(nanFunction);
+ catchPerUnitOfEffort.map(nanFunction);
+ }
+
+}
Added: trunk/3.1.0/rules/InterdictionEngin.java
===================================================================
--- trunk/3.1.0/rules/InterdictionEngin.java (rev 0)
+++ trunk/3.1.0/rules/InterdictionEngin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,272 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * InterdictionEngin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class InterdictionEngin extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(InterdictionEngin.class);
+
+ public Gear param_gear = null;
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(119);
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Prohibited gear");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ // TODO
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("condition fermeture zone");
+ boolean result = true;
+ Month mois = date.getMonth();
+ log.info("mois:" + mois);
+ if(!(param_beginMonth.getMonthNumber()<=mois.getMonthNumber()
+ && mois.getMonthNumber()<=param_endMonth.getMonthNumber())) {
+ result = false;
+ } else {
+ log.info("on est dans l'espace des mois possible");
+ if(date.before(param_beginDate)) {
+ result = false;
+ } else if(date.after(param_endDate)) {
+ result = false;
+ } else if (!metier.getGear().equals(param_gear)) {
+ result = false;
+ }
+ }
+
+ return result;
+ // fin condition
+
+ /*
+writeln("condition fermeture zone");
+var result=true;
+var mois = p.date.getMois().getNumMois();
+writeln("mois:"+mois);
+if(!(p.moisDeb<=mois && mois<=p.moisFin))
+ return false;
+writeln("on est dans l'espace des mois possible");
+//on est dans l'espace des mois possible
+if(p.date.before(p.dateDeb))
+ return false;
+if(p.date.after(p.dateFin))
+ return false;
+if (!p.metier.getEngin().equals(p.engin))
+ return false;
+
+
+return result;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("le metier vise par l'interdiction : " + metier);
+
+ MetierMonitor metierMon = context.getMetierMonitor();
+ metierMon.addforbiddenMetier(metier);
+
+ // r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ List<Strategy> strs = siMatrix.getStrategies(date);
+ List<Strategy> ListeStrat = new ArrayList<Strategy>();
+
+ for (Strategy str : strs) {
+ double prop = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ if (prop != 0) {
+ ListeStrat.add(str);
+ }
+ }
+
+ for (Strategy Strat : ListeStrat) {
+ StrategyMonthInfo StratMonthInfo = Strat.getStrategyMonthInfo(date.getMonth());
+
+ // 1er cas:l'effort est reporte sur un metier de la meme strategie,
+ // n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ List<EffortDescription> MetiersPossibles= new ArrayList<EffortDescription>(Strat.getSetOfVessels().getPossibleMetiers());
+
+ // on verifie que les metiers sont bien pratiques au mois courant,
+ // qu'ils n'ont pas le meme engin et qu'ils ne sont pas
+ // interdits par ailleurs
+ for (Iterator<EffortDescription> effort=MetiersPossibles.iterator(); effort.hasNext();) {
+ Metier met = effort.next().getPossibleMetiers();
+ if (StratMonthInfo.getProportionMetier(met) == 0
+ || met.getGear().equals(metier.getGear())
+ || met.getName().equalsIgnoreCase("nonActivite")
+ || metierMon.isForbidden(metier, date.getMonth())){
+ effort.remove();
+ }
+ }
+
+ // on repartit maintenant l'effort entre les differents metiers
+ // possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size() != 0){
+ int NbMetier=MetiersPossibles.size();
+ for (EffortDescription effort : MetiersPossibles) {
+ Metier met = effort.getPossibleMetiers();
+ double NouvelleProportion =
+ StratMonthInfo.getProportionMetier(met)
+ + (StratMonthInfo.getProportionMetier(metier) / NbMetier);
+ StratMonthInfo.setProportionMetier(met, NouvelleProportion);
+ }
+ StratMonthInfo.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ }
+ // s'il n'y a pas de metier alternatif, on passe a nonActivite
+ else{
+ MatrixND matNonActivite = metierMon.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ matNonActivite.setValue(Strat, metier, StratMonthInfo.getProportionMetier(metier));
+ StratMonthInfo.setProportionMetier(metier,0);
+ }
+ }
+
+ // fin methode
+
+ /*
+var Chaine=Packages.java.lang.String;
+writeln("Action avant");
+var metier=p.metier;
+writeln("le metier vise par l'interdiction : "+metier);
+
+
+MetiersInterdits.put(new Chaine(p.metier.getNom(),true));
+//r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+var ListeStrat=new Packages.org.codelutin.dbobject.DBCollection(StrategyFactory);
+var Vessels=SetOfVesselsFactory.findAllByRegion(p.metier.getRegion());
+for (var ves=0; ves<Vessels.size();ves++){
+ if (Vessels.get(ves).getMetiers().contains(p.metier)){
+ var listestrattemp=StrategyFactory.findAllBySetOfVessels(Vessels.get(ves)).copy();
+ for (var strat=0;strat<listestrattemp.size();strat++){
+ var proportion=listestrattemp.get(strat).getStrategyMonthInfo(p.date.getMois()).getProportionMetier(p.metier) //on recupere la proportion d'effort attribue au metier
+ if (proportion!=0){
+ listestrattemp.removeAll(ListeStrat);
+ ListeStrat.addAll(listestrattemp);//permet d'obtenir une liste sans doublon
+ }
+ }
+ }
+}
+
+
+
+for (iStrat=ListeStrat.iterator();iStrat.hasNext();){
+ var Strat=iStrat.next();
+ var StratMonthInfo=Strat.getStrategyMonthInfo(p.date.getMois());
+ //1er cas:l'effort est reporte sur un metier de la meme strategie, n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ var MetiersPossibles=Strat.getSetOfVessels().getMetiers().copy();
+
+ //on verifie que les metiers sont bien pratiques au mois courant, qu'ils n'ont pas le meme ont le meme engin et qu'ils ne sont pas interdits par ailleurs
+ for (var imet=MetiersPossibles.iterator();imet.hasNext();){
+ var met=imet.next();
+ if (StratMonthInfo.getProportionMetier(met)==0 || met.getEngin().equals(p.metier.getEngin()) || met.getNom()=="nonActivite" || MetiersInterdits.containsKey(new Chaine(met.getNom())) || MetiersInterditsPresimu.containsKey(new Chaine(met.getNom()+"-"+p.date.getMois().getNumMois()))){
+ MetiersPossibles.remove(met);
+ }
+ }
+
+ //on repartit maintenant l'effort entre les differents metiers possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size()!=0){
+ var NbMetier=MetiersPossibles.size();
+ for (imet=MetiersPossibles.iterator();imet.hasNext();){
+ met=imet.next();
+ var NouvelleProportion=StratMonthInfo.getProportionMetier(met)+(StratMonthInfo.getProportionMetier(p.metier)/NbMetier);
+ StratMonthInfo.setProportionMetier(met, new Packages.java.lang.Float(NouvelleProportion))
+ }
+ StratMonthInfo.setProportionMetier(p.metier, new Packages.java.lang.Float(0)) //le metier vise a alors une proportion nulle
+ }
+//s'il n'y a pas de metier alternatif, on passe a nonActivite
+ else{
+ var matNonActivite=nonActivite.get(p.date);
+ var nonactivite=matNonActivite!=null;
+ if (!nonactivite){
+ matNonActivite=MatrixFactory.create("nonActivite",new Array(SiMatrice.getListStrategies(),SiMatrice.getListMetiers())
+ ,new Array("Strategies", "Metiers"));
+ nonActivite.put(p.date,matNonActivite);
+ }
+
+ matNonActivite.setValue(Strat,p.metier,InfoMois.getProportionMetier(p.metier));
+ StratMonthInfo.setProportionMetier(p.metier,new Packages.java.lang.Float(0));
+ }
+}
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+}
Added: trunk/3.1.0/rules/InterdictionEnginPreSimu.java
===================================================================
--- trunk/3.1.0/rules/InterdictionEnginPreSimu.java (rev 0)
+++ trunk/3.1.0/rules/InterdictionEnginPreSimu.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,296 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * InterdictionEngin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+public class InterdictionEnginPreSimu extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(InterdictionEnginPreSimu.class);
+
+ public Gear param_gear = null;
+ public Month param_beginMonth = Month.JANUARY;
+ public Month param_endMonth = Month.DECEMBER;
+
+ protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>();
+ protected boolean affectNonActivite = false;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("Prohibited gear");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ MetierMonitor metierMon = context.getMetierMonitor();
+
+ Month moisDeb = param_beginMonth;
+ Month moisFin = param_endMonth;
+ Gear EnginInterdit = param_gear;
+
+ log.info("nom de l'engin interdit "+EnginInterdit.getName());
+ FisheryRegion RegionSimu = RegionStorage.getFisheryRegion(context.getDB());
+ List<Metier> ListeMetiers = RegionSimu.getMetier();
+
+ for (Metier metier : ListeMetiers) {
+ if (metier.getGear().equals(EnginInterdit)) {
+ //r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ List<Strategy> ListeStrat=RegionSimu.getStrategy();
+ for (Strategy Strat : ListeStrat){
+ SetOfVessels vessels = Strat.getSetOfVessels();
+ if (vessels.getPossibleMetiers(metier) != null){
+ for (Month mois : Month.getMonths(param_beginMonth, param_endMonth)) {
+ StrategyMonthInfo StratMonthInfo = Strat.getStrategyMonthInfo(mois);
+ metierMon.addforbiddenMetier(metier, mois);
+
+ //1er cas:l'effort est reporte sur un metier de la meme strategie, n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ List<EffortDescription> MetiersPossibles =
+ new ArrayList<EffortDescription>(Strat.getSetOfVessels().getPossibleMetiers());
+
+ // on verifie que les metiers sont bien pratiques au mois courant,
+ // qu'ils n'ont pas le meme ont le meme engin et qu'ils ne sont
+ // pas interdits par ailleurs
+ for (Iterator<EffortDescription> effort=MetiersPossibles.iterator(); effort.hasNext();) {
+ Metier met = effort.next().getPossibleMetiers();
+ if (StratMonthInfo.getProportionMetier(met) == 0
+ || met.getGear().equals(metier.getGear())
+ || met.getName().equalsIgnoreCase("nonActivite")
+ || metierMon.isForbidden(metier, mois)){
+ effort.remove();
+ }
+ }
+
+ //on repartit maintenant l'effort entre les differents metiers possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size() != 0){
+ int NbMetier=MetiersPossibles.size();
+ for (EffortDescription effort : MetiersPossibles) {
+ Metier met = effort.getPossibleMetiers();
+ double NouvelleProportion =
+ StratMonthInfo.getProportionMetier(met)
+ + (StratMonthInfo.getProportionMetier(metier) / NbMetier);
+ StratMonthInfo.setProportionMetier(met, NouvelleProportion);
+ }
+ StratMonthInfo.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ }
+ else{
+ log.info("debut reportNonActivite");
+ // on regarde si on a d�j� une entr�e pour le mois courant
+ MatrixND matNonActiviteMois=tableNonActivite.get(mois);
+ if (matNonActiviteMois == null){
+ matNonActiviteMois = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NO_ACTIVITY,
+ new List[]{ListeStrat, ListeMetiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+ tableNonActivite.put(mois, matNonActiviteMois);
+ }
+
+ matNonActiviteMois.setValue(Strat, metier, StratMonthInfo.getProportionMetier(metier));
+ log.info("fin reportNonActivite");
+
+ StratMonthInfo.setProportionMetier(metier, 0);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // fin methode
+
+ /*
+this.param = param;
+
+//construction de p
+this.p = new Object();
+this.p.paramRegle = this.param;
+this.p.tableNonActivite=new Packages.java.util.HashMap();
+this.p.affectNonActivite=false;
+
+//attention: cette r�gle de gestion ne fonctionne que si le changement a lieu pour toutes
+//les ann�es de simulation
+
+
+var moisDeb=this.param.getValue("moisDeb"); //entrez le mois debut de fermeture
+var moisFin=this.param.getValue("moisFin");//entrez le mois de fin de fermeture
+var EnginInterdit=this.param.getValue("engin");
+
+writeln("nom de l'engin interdit "+EnginInterdit.getNom());
+var RegionSimu=EnginInterdit.getRegion();
+var ListeMetiers=MetierFactory.findAllByRegion(RegionSimu);
+
+for (var imetier=ListeMetiers.iterator();imetier.hasNext();){
+ var metier=imetier.next();
+ if (metier.getEngin().equals(EnginInterdit)){
+ //r�cup�re toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ var ListeStrat=SiMatrice.getListStrategies();
+ for (iStrat=ListeStrat.iterator();iStrat.hasNext();){
+ var Strat=iStrat.next();
+ var vessels=Strat.getSetOfVessels();
+ if (vessels.getMetiers().contains(metier)){
+ for (var imois=moisDeb; imois<=moisFin;imois++){
+ var mois=new Packages.fr.ifremer.nodb.Mois(imois);
+ var StratMonthInfo=Strat.getStrategyMonthInfo(mois);
+ MetiersInterditsPresimu.put(new Chaine(metier.getNom()+"-"+mois.getNumMois()),true);
+ //1er cas:l'effort est reporte sur un metier de la meme strategie, n'ayant pas l'espece comme capture principale et pechant avec le meme engin
+ var MetiersPossibles=Strat.getSetOfVessels().getMetiers().copy();
+ var MetiersPossibles2=Strat.getSetOfVessels().getMetiers().copy();
+ //on verifie que les metiers sont bien pratiques au mois courant, qu'ils n'ont pas le meme ont le meme engin et qu'ils ne sont pas interdits par ailleurs
+ for (var imet=MetiersPossibles2.iterator();imet.hasNext();){
+ var met=imet.next();
+ if (StratMonthInfo.getProportionMetier(met)==0 || met.getEngin().equals(metier.getEngin()) || met.getNom()=="nonActivite" || MetiersInterditsPresimu.containsKey(new Chaine(met.getNom()+"-"+mois.getNumMois()))){
+ MetiersPossibles.remove(met);
+ }
+ }
+
+ //on repartit maintenant l'effort entre les differents metiers possibles dans la meme strategie si un metier possible existe bien
+ if (MetiersPossibles.size()!=0){
+ var NbMetier=MetiersPossibles.size();
+ for (imet=MetiersPossibles.iterator();imet.hasNext();){
+ met=imet.next();
+ var NouvelleProportion=StratMonthInfo.getProportionMetier(met)+(StratMonthInfo.getProportionMetier(metier)/NbMetier);
+ StratMonthInfo.setProportionMetier(met, new Packages.java.lang.Float(NouvelleProportion))
+ }
+ StratMonthInfo.setProportionMetier(metier, new Packages.java.lang.Float(0)) //le metier vise a alors une proportion nulle
+ }
+ //s'il n'y a pas de metier alternatif, on passe e nonActivite
+ else{
+ p.tableNonActivite=Regle_action_lib.reportNonActivite(p.tableNonActivite, Strat, metier, mois, StratMonthInfo.getProportionMetier(metier));
+ StratMonthInfo.setProportionMetier(metier,new Packages.java.lang.Float(0));
+ }
+ }
+ }
+ }
+ }
+}
+ */
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ boolean result = false;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+ if (mat != null && affectNonActivite == false) {
+ result = true;
+ }
+ return result;
+ // fin
+
+ /*
+var mat=p.tableNonActivite.get(p.date.getMois());
+writeln(p.affectNonActivite);
+if(oldValue != undefined)
+ return oldValue;
+else if (mat!=null && p.affectNonActivite==false){
+ return true;
+}
+else {return false;}
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // on ne doit le faire qu'une seul fois quelque soit le nombre de metier
+ affectNonActivite=true;
+ MatrixND mat = tableNonActivite.get(date.getMonth());
+
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND noActivity = metierMon.getNoActivity(date);
+
+ if (noActivity == null){
+ metierMon.setNoActivity(date, mat.copy());
+ }
+ else{
+ noActivity = noActivity.add(mat);
+ }
+ // fin
+
+ /*
+p.affectNonActivite=true;
+var mat=p.tableNonActivite.get(p.date.getMois());
+var matNonActivite=nonActivite.get(p.date);
+var nonactivite=matNonActivite!=null;
+if (!nonactivite){
+ nonActivite.put(p.date,mat);
+}
+else{
+ matNonActivite=matNonActivite.add(mat);
+}
+return p.gestionMetier;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ affectNonActivite = false;
+
+ /*
+ p.affectNonActivite=false;
+return p.gestionMetier;
+ */
+ }
+
+}
Added: trunk/3.1.0/rules/RecrutementLangoustine.java
===================================================================
--- trunk/3.1.0/rules/RecrutementLangoustine.java (rev 0)
+++ trunk/3.1.0/rules/RecrutementLangoustine.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,174 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+
+import org.codelutin.math.matrix.*;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.util.StringUtil;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * RecrutementLangoustine.java
+ *
+ * Created: 22 mars 2007
+ *
+ * @author stephanie MAHEVAS <smahevas(a)ifremer.fr>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-03-22 17:33:56 $
+ * by : $Author: bpoussin $
+ */
+public class RecrutementLangoustine extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RecrutementLangoustine.class);
+
+ public double param_recrut1998 =0;
+ public double param_recrut1999 =0;
+ public double param_recrut2000 =0;
+ public double param_recrut2001 =0;
+ public double param_recrut2002 =0;
+ public double param_recrut2003 =0;
+ public double param_recrut2004 =0;
+ public double param_recrut2005 =0;
+
+ public double [] recru = null;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ // TODO
+ return _("TODO description rule");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ // remarque on pourrait aussi avoir un seul parametre de regle
+ // par exemple param_recru_depuis_1998 = "0;0;0;0;0;0;0;0";
+ // on ferait alors
+ // recru = StringUtil.toArrayDouble(param_recru_depuis_1998.split(";"));
+
+ recru = new double[]{
+ param_recrut1998,
+ param_recrut1999,
+ param_recrut2000,
+ param_recrut2001,
+ param_recrut2002,
+ param_recrut2003,
+ param_recrut2004,
+ param_recrut2005,
+ };
+ }
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ boolean result = false;
+ if (date.getMonth().equals(Month.SEPTEMBER) ||
+ date.getMonth().equals(Month.OCTOBER)
+ || date.getMonth().equals(Month.NOVEMBER)
+ ||date.getMonth().equals(Month.DECEMBER)) {
+ result = true;
+ }
+ return result;
+/*
+writeln("recrutement CIEM");
+var mois = p.date.getMois().getNumMois();
+//si le recrutement a lieu en octobre
+if( mois==8 ||mois==9 || mois==10 || mois==11){
+//??&& p.oprfaite==false{
+var result = true;
+}
+ return result ;
+*/
+
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant
+le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ TopiaContext db = context.getDB();
+
+ PopulationDAO popDao = IsisFishDAOHelper.getPopulationDAO(db);
+ Population pop = popDao.findByName("nephrops");
+ PopulationGroup group0 = pop.getPopulationGroup().get(0);
+
+ ZoneDAO zoneDao = IsisFishDAOHelper.getZoneDAO(db);
+ Zone zone1 = zoneDao.findByName("zone L21E7");
+ Zone zone2 = zoneDao.findByName("zone L21E8");
+ Zone zone3 = zoneDao.findByName("zone L22E6");
+ Zone zone4 = zoneDao.findByName("zone L22E7");
+ Zone zone5 = zoneDao.findByName("zone L23E5");
+ Zone zone6 = zoneDao.findByName("zone L23E6");
+ Zone zone7 = zoneDao.findByName("zone L23E7");
+ Zone zone8 = zoneDao.findByName("zone L24E5");
+ Zone zone9 = zoneDao.findByName("zone L24E6");
+
+ int year = date.getYear();
+ MatrixND matN = context.getPopulationMonitor().getN(pop);
+
+ double coefR =4/(Math.exp(-0.6/12))*(1+ Math.exp(-0.3/12)+ Math.exp(-0.6/12)+ Math.exp(-0.9/12));
+
+ double R = recru[year] * coefR / 9.0;
+
+ matN.setValue(group0, zone1, R);
+ matN.setValue(group0, zone2, R);
+ matN.setValue(group0, zone3, R);
+ matN.setValue(group0, zone4, R);
+ matN.setValue(group0, zone5, R);
+ matN.setValue(group0, zone6, R);
+ matN.setValue(group0, zone7, R);
+ matN.setValue(group0, zone8, R);
+ matN.setValue(group0, zone9, R);
+
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // TODO
+ }
+
+}
\ No newline at end of file
Added: trunk/3.1.0/rules/TACpoids.java
===================================================================
--- trunk/3.1.0/rules/TACpoids.java (rev 0)
+++ trunk/3.1.0/rules/TACpoids.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,300 @@
+package rules;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import scripts.RuleUtil;
+import scripts.SiMatrix;
+
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.entities.TargetSpecies;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * TAC.java
+ *
+ * Created: 7 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.5 $
+ *
+ * Last update: $Date: 2007-11-20 15:50:09 $
+ * by : $Author: bpoussin $
+ */
+
+/**
+ * TAC peut-etre utilis� pour les diff�rents TAC, en proportion des effectifs
+ * et/ou avec survie ou non.
+ *
+ * <li>Pour utiliser le tac proportionnel, il faut mettre dans le parametre propTac
+ * une valeur > 0, le TAC sera alors recalcul� a chaque mois de janvier.
+ * <li>Pour utiliser la survie il faut mettre dans le param�tre propSurvie
+ * une valeur > 0, automatiquement les suvie seront ajout� aux effectifs
+ *
+ */
+public class TACpoids extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(TACpoids.class);
+
+ public Species param_species = null;
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(22);
+ public double param_propSurvie = 0;
+ public double param_propTac = 0;
+
+ /** TAC in tonne */
+ public double param_tacInTons = 0;
+
+ boolean affectation = false;
+
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ /**
+ * @return the necessaryResult
+ */
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() {
+ return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed use propTac other than 0.");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ // read species in current session
+ param_species = (Species)context.getDB().findByTopiaId(param_species.getTopiaId());
+
+ // on fait le calcul du tac si n�cessaire
+ if (param_propTac > 0 && date.getMonth().equals(Month.JANUARY)){
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ param_tacInTons = popMon.getBiomass(param_species) * param_propTac;
+ }
+
+ boolean result = false;
+ if(date.before(param_beginDate)) {
+ result = false;
+ } else if(date.after(param_endDate)) {
+ result = false;
+ } else {
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ if (ts != null) {
+ double catchTons = RuleUtil.getTotalCatchTons(context, param_species, date);
+ log.info("[TAC] catchTons = " + catchTons + " >= param_tacInTons:" + param_tacInTons );
+ if (catchTons >= param_tacInTons) {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ affectation = false;
+ log.info("[TAC] preAction for: " + metier);
+
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ if(ts != null && ts.getPrimaryCatch()) {
+ // recupere tous les metiers qui ont l'espece en capture principale =>metiers vises
+ List<Metier> aimedMetiers = context.getDB().find("select distinct(metierSeasonInfo.metier) " +
+ "from fr.ifremer.isisfish.entities.TargetSpecies " +
+ "where species=? and primaryCatch=true", param_species);
+
+ log.info("aimed Metier: " + aimedMetiers);
+ context.getMetierMonitor().addforbiddenMetier(metier);
+
+ //r�cupere toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ Set<Strategy> strs = new HashSet<Strategy>();
+ for (Strategy str : siMatrix.getStrategies(date)) {
+ double prop = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ if (prop != 0) {
+ strs.add(str);
+ }
+ }
+
+ for (Strategy str : strs){
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(date.getMonth());
+
+ // 1er cas de figure: l'effort est reporte sur un metier de la
+ // meme strategie, n'ayant pas l'espece comme capture principale
+ // et pechant avec le meme engin
+ Set<Metier> possibleMetierCase1 = new HashSet<Metier>();
+ // second cas de figure: on cherche un metier de substitution
+ // sans condition sur les engins, mais qui soit pratique
+ Set<Metier> possibleMetierCase2 = new HashSet<Metier>();
+ // 3 eme cas de figure: on cherche des metiers non vises,
+ // sans consideration sur les engins, et pour lesquels la
+ // proportion peut etre nulle
+ Set<Metier> possibleMetierCase3 = new HashSet<Metier>();
+
+ for (EffortDescription effort : str.getSetOfVessels().getPossibleMetiers()) {
+ Metier newMetier = effort.getPossibleMetiers();
+ if (
+ !aimedMetiers.contains(newMetier)
+ && !metier.getName().equalsIgnoreCase("nonActiviy")
+ && !metier.getName().equalsIgnoreCase("nonActivie")
+ && !context.getMetierMonitor().getForbiddenMetier().contains(newMetier)
+ ) {
+ possibleMetierCase3.add(newMetier);
+
+ if (smi.getProportionMetier(newMetier) != 0) {
+ possibleMetierCase2.add(newMetier);
+
+ if (metier.getGear().equals(newMetier.getGear())) {
+ possibleMetierCase1.add(newMetier);
+ }
+ }
+ }
+ }
+
+ Set<Metier> possibleMetier = null;
+ if (possibleMetierCase1.size() != 0){
+ log.info("[TAC] Use case 1");
+ possibleMetier = possibleMetierCase1;
+ } else if (possibleMetierCase2.size() != 0) {
+ log.info("[TAC] Use case 2");
+ possibleMetier = possibleMetierCase2;
+ } else if (possibleMetierCase3.size() != 0){
+ log.info("[TAC] Use case 3");
+ possibleMetier = possibleMetierCase3;
+ }
+
+ if (possibleMetier != null) {
+ // on repartit maintenant l'effort entre les differents metiers
+ // possibles dans la meme strategie si un metier possible existe
+ // bien la repartion est proportionnelle a l'effort deja alloue
+ // dans la strategie
+
+ double somme=0;
+ for (Metier met : possibleMetierCase1) {
+ somme += smi.getProportionMetier(met);
+ }
+ for (Metier met : possibleMetierCase1) {
+ double newProportion =
+ smi.getProportionMetier(met)
+ + (smi.getProportionMetier(metier)
+ * smi.getProportionMetier(met) / somme);
+ smi.setProportionMetier(met, newProportion);
+ }
+ smi.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ } else{
+ log.info("[TAC] Use no activity");
+
+ // sinon on met tout dans le metier nonActivite
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND mat = metierMon.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ mat.setValue(str, metier, smi.getProportionMetier(metier));
+
+ smi.getProportionMetier().setValue(metier, 0);
+ }
+ }
+ }
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("[TAC] postAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ if(ts != null){
+ if (!affectation){
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier
+ // pour qui l'espece est secondaire: elles sont affectees aux
+ // rejets
+
+ //pb : ne se fait pas par metier
+ // il faut une matrice pour chaques pas de temps qui stocke les
+ // rejets par metier, par metapop et par classes d'age (comme
+ // pour les captures)
+ //////
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ for (Population pop : param_species.getPopulation()) {
+ // si on a deja une matrice rejet on le vide (elle vient
+ // forcement de la regle taille minimale or si le tac est
+ // atteint, tout va dorenavent dans les rejets et on mais
+ // TOUTES les captures dans les rejets
+ MatrixND discard = popMon.getDiscard(date, pop);
+ if (discard != null) {
+ discard.mults(0);
+ }
+
+ discard = popMon.getCatch(pop).copy();
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ popMon.addDiscard(date, pop, discard);
+ log.info("[TAC] add discard for " + pop + ": " + discard);
+
+ if (param_propSurvie > 0) {
+ MatrixND eff = popMon.getN(pop);
+ //on r�ajoute les survivants aux effectifs
+ for (MatrixIterator i=discard.iterator(); i.next();){
+ Object [] coord = i.getSemanticsCoordinates();
+ eff.setValue(coord[2],coord[3],
+ eff.getValue(coord[2],coord[3])+i.getValue()*param_propSurvie);
+ }
+ }
+
+ }
+
+ // on a affecte une fois cette meta pop au rejet il ne faut pas
+ // le refaire
+ affectation=true;
+ }
+ }
+ }
+
+}
Added: trunk/3.1.0/rules/TailleMin.java
===================================================================
--- trunk/3.1.0/rules/TailleMin.java (rev 0)
+++ trunk/3.1.0/rules/TailleMin.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,253 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+
+import java.io.Writer;
+import java.util.List;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+
+/**
+ * TailleMin.java
+ *
+ * Created: 30 novembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.1 $
+ *
+ * Last update: $Date: 2007-01-24 18:25:34 $
+ * by : $Author: bpoussin $
+ */
+
+/**
+ * Cette methode remplace aussi TailleMinSurvieRejet si propSurvie est > 0
+ */
+public class TailleMin extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(TailleMin.class);
+
+ public Date param_beginDate = new Date(0);
+ public Date param_endDate = new Date(119);
+ public Species param_species = null;
+ public double param_TailleMin = 27;
+ public double param_propSurvie = 0;
+
+ public String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ // TODO
+ return _("TODO description rule");
+ }
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * @param context
+ * @param date
+ * @param param_species
+ * @param metier
+ * @return
+ */
+ private boolean isCaptureDate(Date date, Species species, Metier metier) {
+ MetierSeasonInfo info = metier.getMetierSeasonInfo(date.getMonth());
+ TargetSpecies target = info.getSpeciesTargetSpecies(species);
+ boolean result = target != null;
+
+ return result;
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions
+ * @param simulation La simulation pour lequel on utilise cette regle
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("Recherche si la taille Minimale s'applique");
+ boolean result = true;
+ if (date.before(param_beginDate)) {
+ result = false;
+ } else if (date.after(param_endDate)) {
+ result = false;
+ } else if (isCaptureDate(date, param_species, metier) != true) {
+ result=false;
+ }
+
+ log.info("fin de condition TailleMin:" + result);
+ return result;
+
+ // fin
+
+ /*
+
+writeln("Recherche si la taille Minimale s'applique (oldValue="+oldValue);
+var metier=p.metier;
+var result = true;
+if(oldValue != undefined)
+ result = oldValue;
+else if (Regle_libUtil.isCaptureDate(p.date,p.metapop, metier)!=true)
+ result=false;
+else if(p.date.before(p.dateDeb))
+ result = false;
+else if(p.date.after(p.dateFin))
+ result = false;
+
+writeln("fin de condition TailleMin:"+result);
+return result;
+*/
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e avant le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ // nothing
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e apres le pas
+ * de temps de la simulation.
+ * @param simulation La simulation pour lequel on utilise cette regle
+ */
+ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ log.info("*$*$*$* TailleMin.actionApres:" + date + " metapop:" + param_species + " metier:" + metier);
+
+ if(isCaptureDate(date, param_species, metier)){
+ log.info("*$*$*$* ok affecte capture inf�?rieure �? TailleMin au rejet");
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier pour qui
+ // l'espece est secondaire: elles sont affectees aux rejets
+
+ //pb : ne se fait pas par metier
+ //il faut une matrice pour chaques pas de temps qui stocke les rejets
+ //par metier, par metapop et par classes d'age (comme pour les captures)
+ //////
+ log.info("deb de affecterCaptureREJETTailleMin");
+
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ for (Population pop : pops) {
+ if (pop.getSpecies().equals(param_species)) {
+ if (popMon.getDiscard(date, pop) == null) {
+ MatrixND discard = popMon.getCatch(pop).copy();
+ MatrixND eff = popMon.getN(pop);
+
+ for (MatrixIterator i=discard.iterator(); i.next();) {
+ Object [] coordonnees = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)coordonnees[2];
+ if (group.getLength() >= param_TailleMin) {
+ i.setValue(0);
+ } else if (param_propSurvie > 0) {
+ eff.setValue(coordonnees[2], coordonnees[3],
+ eff.getValue(coordonnees[2], coordonnees[3])
+ + i.getValue() * param_propSurvie);
+ }
+ }
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ popMon.addDiscard(date, pop, discard);
+ }
+ }
+ }
+
+ log.info("fin de affecterCaptureRejetTailleMin");
+
+ //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
+ }
+
+ // fin
+
+ /*
+
+
+
+writeln("*$*$*$* TailleMin.actionApres:"+p.date+" metapop:"+p.metapop+" metier:"+p.metier);
+if(Regle_libUtil.isCaptureDate(p.date,p.metapop, p.metier)){
+ writeln("*$*$*$* ok affecte capture inf�?rieure �? TailleMin au rejet");
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier pour qui
+ // l'espece est secondaire: elles sont affectees aux rejets
+
+ //pb : ne se fait pas par metier
+ //il faut une matrice pour chaques pas de temps qui stocke les rejets
+ //par metier, par metapop et par classes d'age (comme pour les captures)
+ //////
+writeln("deb de affecterCaptureREJETTailleMin");
+var suivi = null;
+
+//recherche du suivi pour les pop qui ont une certaine meta pop
+for(var i=0; i< suiviePop.size(); i++){
+ if(suiviePop.get(i).getPop().getMetaPopulation().equals(metapop)){
+ suivi = suiviePop.get(i);
+ var populations=suivi.getPop();
+
+ //si on a pas deja creer le rejet on le cree et on en fait un resultat
+ var matRejet = suivi.getRejet(date);
+ if (matRejet==null){
+ var matRejetBis = MatrixFactory.create(suivi.getCapture());
+ var eff=suivi.getN();
+//on encapsule les objets des 4 dimensions de la matrice capture
+ for (var iiterateur=matRejetBis.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var classe=coordonnees[2];
+ if (classe.getLongueur()>=TailleMin){
+ iiterateur.setValue(0);
+ }
+ else if (param_propSurvie > 0) {
+ eff.setValue(coordonnees[2],coordonnees[3],eff.getValue(coordonnees[2],coordonnees[3])+iiterateur.getValue()*proportion);
+ }
+ }
+ matRejetBis.setName("Rejet par metier");
+ suivi.addRejet(date,matRejetBis);
+ }
+ }
+}
+
+
+writeln("fin de affecterCaptureRejetTailleMin");
+
+
+ //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
+}
+
+return p.gestionMetier;
+*/
+ }
+
+}
Added: trunk/3.1.0/scripts/GravityModel.java
===================================================================
--- trunk/3.1.0/scripts/GravityModel.java (rev 0)
+++ trunk/3.1.0/scripts/GravityModel.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,1311 @@
+/* *##%
+ * Copyright (C) 2006
+ * Code Lutin, C�dric Pineau, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * GravityModel.java
+ *
+ * Created: 4 sept. 06 15:49:08
+ *
+ * @author poussin
+ * @version $Revision: 1.9 $
+ *
+ * Last update: $Date: 2007-03-01 17:16:12 $
+ * by : $Author: bpoussin $
+ */
+
+package scripts;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.StorageException;
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.SetOfVessels;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeUnit;
+
+
+/**
+ * @author poussin
+ *
+ */
+
+public class GravityModel {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(GravityModel.class);
+
+ protected SimulationContext context = null;
+ protected TopiaContext db = null;
+ protected SiMatrix siMatrix = null;
+ protected ResultStorage resultManager = null;
+
+ /**
+ * Method used to get GravityModel used for simulation
+ * @param context context simulation
+ * @return GravityModel or null if no GravityModel created for simulation
+ */
+ public static GravityModel getGravityModel(SimulationContext context) {
+ GravityModel result = (GravityModel)context.getValue(GravityModel.class.getName());
+ return result;
+ }
+
+ private static void setGravityModel(SimulationContext context, GravityModel gravityModel) {
+ context.setValue(GravityModel.class.getName(), gravityModel);
+ }
+
+
+ public GravityModel(SimulationContext context, SiMatrix siMatrix) throws TopiaException, StorageException{
+ this.context = context;
+ this.db = context.getDB();
+ this.resultManager = context.getSimulationStorage().getResultStorage();
+ this.siMatrix = siMatrix;
+ setGravityModel(context, this);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // Matrice de Revenue et Cout
+ //////////////////////////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////////////////////////
+ // MatrixFishingTimePerMonthPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixFishingTimePerMonthPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = fishingTimePerMonthPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = fishingTimePerMonthPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * FishingTimePerMonthPerVessel[str,met,month] = FishingTimePerTrip[str,met,month]NbTripsPerMonth[str,month]
+
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double fishingTimePerMonthPerVessel(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ double timePerTrip = siMatrix.fishingTimePerTrip(str, metier, date);
+ int nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
+ return timePerTrip * nbTrip;
+ }
+
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixFuelCostsOfTravelPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixFuelCostsOfTravelPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = fuelCostsOfTravelPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = fuelCostsOfTravelPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * FuelCostsOfTravelPerVessel[sov,met,month]�=�NbTripsPerMonth[str,month]*TravelTimePerTrip[sov,met,month]*UnitFuelCostsOfTravel[vt]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double fuelCostsOfTravelPerVessel(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ int nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
+
+ Collection<Zone> zone = metier.getMetierSeasonInfo(month).getZone();
+ // TODO: verifier que travelTime est bien en heure, car le unitFuelCost est l'unite par heure
+ double travelTime = siMatrix.travelTimePerTrip(str.getSetOfVessels(), zone);
+ double unitFuelCost = str.getSetOfVessels().getVesselType().getUnitFuelCostOfTravel();
+
+ return nbTrip * travelTime * unitFuelCost;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixCostsOfFishingPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixCostsOfFishingPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = costsOfFishingPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = costsOfFishingPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * CostsOfFishingPerVessel[str,met,month]= FishingTimePerMonthPerVessel [str,met,month] {NbFishingOperationsPerDay[sov,met] UnitCostsOfFishing[sov,met] / 24}
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double costsOfFishingPerVessel(Strategy str, Metier metier, Date date) {
+ double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ int nbOperation = 0;
+ double unitCostOfFishing = 0;
+ if(effort != null){
+ nbOperation = effort.getFishingOperation();
+ unitCostOfFishing = effort.getUnitCostOfFishing();
+ }
+
+ return fishingTime * ( nbOperation * unitCostOfFishing / TimeUnit.HOUR_PER_DAY);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixFuelCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixFuelCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FUEL_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = fuelCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = fuelCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * FuelCostsPerVessel[str,met,month] = FuelCostsOfTravelPerVessel [sov,met,month] + CostsOfFishingPerVessel [str,met,month]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double fuelCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fuelCosts = fuelCostsOfTravelPerVessel(str, metier, date);
+ double costsOfFishing = costsOfFishingPerVessel(str, metier, date);
+
+ return fuelCosts + costsOfFishing;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixRepairAndMaintenanceGearCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixRepairAndMaintenanceGearCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * RepairAndMaintenanceGearCostsPerVessel[str,met,month]�=�FishingTimePerMonthPerVessel[str,met,month] *RepairAndMaintenanceGearCostsPerDay[sov,met]/NbHoursPerDay
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double repairAndMaintenanceGearCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+
+ double repair = 0;
+ if(effort != null){
+ repair = effort.getRepairAndMaintenanceGearCost();
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return fishingTime * repair / TimeUnit.HOUR_PER_DAY;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOtherRunningCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOtherRunningCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = otherRunningCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = otherRunningCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OtherRunningCostsPerVessel[str,met,month]=�FishingTimePerMonthPerVessel[str,met,month]*OtherRunningCostsPerDay[sov,met]/ NbHoursPerDay
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double otherRunningCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+
+ double otherCosts = 0;
+ if(effort != null){
+ otherCosts = effort.getOtherRunningCost();
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return fishingTime * otherCosts / TimeUnit.HOUR_PER_DAY;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixSharedNotFixedCostsPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixSharedNotFixedCostsPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = sharedNotFixedCostsPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = sharedNotFixedCostsPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * SharedNotFixedCostsPerVessel[str,met,month]=�FuelCostsPerVessel[str,met,month] +�OtherRunningCostsPerVessel[str,met,month]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double sharedNotFixedCostsPerVessel(Strategy str, Metier metier, Date date) {
+ double fuelCostsPerVessel = fuelCostsPerVessel(str, metier, date);
+ double otherRunningCostsPerVessel = otherRunningCostsPerVessel(str, metier, date);
+
+ return fuelCostsPerVessel + otherRunningCostsPerVessel;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixSharedFixedCostsPerVesselPerMet
+ //////////////////////////////////////////////////////////////////////
+// Supprime avec Steph le 20070227
+// public MatrixND matrixSharedFixedCostsPerVesselPerMet(Date date) throws TopiaException{
+// List<Strategy> strategies = siMatrix.getStrategies(date);
+//
+// MatrixND result = MatrixFactory.getInstance().create(
+// ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET,
+// new List[]{strategies},
+// new String[]{n_("Strategies")});
+//
+// for (int s=0; s < strategies.size(); s++) {
+// Strategy str = strategies.get(s);
+// double value = sharedFixedCostsPerVesselPerMet(str, date);
+// result.setValue(s, value);
+// }
+//// for(Strategy str : strategies){
+//// double value = sharedFixedCostsPerVesselPerMet(str, date);
+//// result.setValue(str, value);
+//// }
+//
+// return result;
+// }
+//
+// /**
+// * implant� suivant document ModifTable3PourBP25-07-2006.doc
+// * SharedFixedCostsPerVesselPerMet [str,month]=FixedCostsPerMonth[sov]/NbMet[sov]
+// *
+// * @param str
+// * @param date
+// * @return
+// */
+// private double sharedFixedCostsPerVesselPerMet(Strategy str, Date date) {
+// SetOfVessels sov = str.getSetOfVessels();
+// double fixedCosts = sov.getFixedCosts();
+// int nbMet = sov.sizePossibleMetiers();
+//
+// return fixedCosts / (double)nbMet;
+// }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixGrossValueOfLandingsPerSpeciesPerStrategyMet
+ //////////////////////////////////////////////////////////////////////
+
+
+ public MatrixND matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET,
+ new List[]{strategies, metiers, pops},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Populations")});
+
+ for (int p=0; p < pops.size(); p++) {
+ Population pop = pops.get(p);
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ result.setValue(str, metier, pop, value);
+ }
+ }
+ }
+
+// for(Population pop : pops){
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+// result.setValue(str, metier, pop, value);
+// }
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month]�=�sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet [str,met,pop,cl,month] ?DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
+nth]
+ * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month] = sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet [str,met,pop,cl,month] -DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
+nth])]
+ *
+ * @param str
+ * @param metier
+ * @param pop
+ * @param date
+ * @return
+ */
+ private double grossValueOfLandingsPerSpeciesPerStrategyMet(Strategy str, Metier metier, Population pop, Date date) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ float result = 0;
+ for(PopulationGroup group : groups){
+ double price = group.getPrice();
+ Collection<Zone> zones = pop.getPopulationZone();
+ for(Zone zone : zones){
+ double catchWeight = getCatchWeightPerStrMet(str, metier, group, zone, date);
+ double discardsWeight = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ // FIXME demander/verifier que ce le bon calcule
+ result += price * (catchWeight - discardsWeight);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param group
+ * @param zone
+ * @param date
+ * @return
+ */
+ private double getCatchWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ double result = 0;
+ if(mat != null){
+ result = mat.getValue(str, metier, group, zone);
+ }
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param group
+ * @param zone
+ * @param date
+ * @return
+ */
+ private double getDiscardsWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+ double result = 0;
+ if(mat != null){
+ result = mat.getValue(str, metier, group, zone);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixGrossValueOfLandingsPerStrategyMet
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixGrossValueOfLandingsPerStrategyMet(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double grossValueOfLandingsPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ List<Population> pops = siMatrix.getPopulations(date);
+ double result = 0;
+ for(int i=0; i<pops.size(); i++){
+ Population pop = (Population)pops.get(i);
+ result += grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixGrossValueOfLandingsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixGrossValueOfLandingsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * GrossValueOfLandingsPerStrategyMetPerVessel[str,met,month]�= GrossValueOfLandingsPerStrategyMet[str,met,month]�/[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double grossValueOfLandingsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double grossValueOfLandingsPerStrategyMet = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov)
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(str,metier,date);
+
+
+ return (grossValueOfLandingsPerStrategyMet + grossValueOfLandingsOtherSpeciesPerStrategyMet) / (proportionSetOfVessels * numberOfVessels);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixNetValueOfLandingsPerStrategyMet
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixNetValueOfLandingsPerStrategyMet(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = netValueOfLandingsPerStrategyMet(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = netValueOfLandingsPerStrategyMet(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * NetValueOfLandingsPerStrategyMet[str,met,month]�=�GrossValueOfLandingsPerStrategyMet[str,met,month]�(1-LandingCostRate[str,met]�)
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double netValueOfLandingsPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ double grossValue = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ double landingCost = 1;
+ // FIXME demander si le metier n'a pas d'effort s'il faut que landingCost soit bien a 1
+ if(effort != null){
+ landingCost -= effort.getLandingCosts();
+ }
+
+ double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(str,metier,date);
+
+ double result = (grossValue + grossValueOfLandingsOtherSpeciesPerStrategyMet)* landingCost;
+ return result;
+ }
+
+ private double grossValueOfLandingsOtherSpeciesPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ // FIXME evaluer l'equation dans suivant le doc des equations
+ return 0;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixNetValueOfLandingsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixNetValueOfLandingsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * NetValueOfLandingsPerStrategyMetPerVessel[str,met,month]�=�NetValueOfLandingsPerStrategyMet[str,met,month]�/[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double netValueOfLandingsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netValueOfLandingsPerStrategyMet = netValueOfLandingsPerStrategyMet(str, metier, date);
+ // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov)
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ return netValueOfLandingsPerStrategyMet / (proportionSetOfVessels * numberOfVessels);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixNetRenevueToSharePerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixNetRenevueToSharePerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�=�NetValueOfLandingsPerStrategyMetPerVessel[str,met,month]�-�SharedNotFixedCostsPerVessel [str,met,month]*PropStr(str,met,month) - SharedFixedCostsPerVessel
+PerMet[str,month]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double netRenevueToSharePerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToSharePerStrategyMetPerVessel = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str, metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+
+ double result = netRenevueToSharePerStrategyMetPerVessel - sharedNotFixedCostsPerVessel * propStr;
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixCrewSharePerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixCrewSharePerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = crewSharePerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = crewSharePerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * CrewSharePerStrategyMetPerVessel[str,met,month]�=�NetRevenueToSharePerStrategyMetPerVessel[str,met,month]*CrewShareRate[sov,met]
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double crewSharePerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+
+ double crewShareRate = 0;
+ if(effort != null){
+ crewShareRate = effort.getCrewShareRate();
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return netRenevueToShare * crewShareRate;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategyMetPerVessel[str,met,month] = NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�- CrewSharePerStrategyMetPerVessel[str,met,month]�- RepairAndMaintenanceGearCostsPerVes
+sel[str,met,month]�* PropStr(str,met,month)
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double ownerMarginOverVariableCostsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ double crewShare = crewSharePerStrategyMetPerVessel(str, metier, date);
+ double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+
+ return netRenevueToShare - crewShare - repair * propStr;
+ }
+
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+ List<Metier> metiers = siMatrix.getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = siMatrix.getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+// for(Strategy str : strategies){
+// metiers = siMatrix.getMetiers(str, date);
+// for(Metier metier : metiers) {
+// double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+// result.setValue(str, metier, value);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * VesselMarginOverVariableCostsPerStrategyMetPerVessel�[str,met,month]�=NetRevenueToSharePerStrategyMetPerVessel[str,met,month]- RepairAndMaintenanceGearCostsPerVessel [str,met,month]�* PropStr(str,met,month)
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double vesselMarginOverVariableCostsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+
+ return netRenevueToShare - repair * propStr;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOwnerMarginOverVariableCostsPerStrategyPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategyPerVessel[str,month]�=�somme sur tous les m�tiers de OwnerMarginOverVariableCostsPerStrategyMetPerVessel [str,met,month]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double ownerMarginOverVariableCostsPerStrategyPerVessel(Strategy str, Date date) throws TopiaException {
+ SetOfVessels sov = str.getSetOfVessels();
+ Collection<EffortDescription> efforts = sov.getPossibleMetiers();
+
+ float result = 0;
+
+ for (EffortDescription effort : efforts) {
+ Metier metier = effort.getPossibleMetiers();
+ result += ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixOwnerMarginOverVariableCostsPerStrategy
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategy(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = ownerMarginOverVariableCostsPerStrategy(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = ownerMarginOverVariableCostsPerStrategy(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategy[str,month]�=�OwnerMarginOverVariableCostsPerStrategyPerVessel[str,month]�*[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double ownerMarginOverVariableCostsPerStrategy(Strategy str, Date date) throws TopiaException {
+ double ownerMarginOverVariableCostsPerStrategyPerVessel = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ return ownerMarginOverVariableCostsPerStrategyPerVessel * (proportionSetOfVessels * numberOfVessels);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixVesselMarginOverVariableCostsPerStrategyPerVessel
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategyPerVessel(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * VesselMarginOverVariableCostsPerStrategyPerVessel[str,month]�= somme sur tous les m�tiers de VesselMarginOverVariableCostsPerStrategyMetPerVessel� [str,met,month]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double vesselMarginOverVariableCostsPerStrategyPerVessel(Strategy str, Date date) throws TopiaException {
+ SetOfVessels sov = str.getSetOfVessels();
+ Collection<EffortDescription> efforts = sov.getPossibleMetiers();
+
+ float result = 0;
+
+ for (EffortDescription effort : efforts) {
+ Metier metier = effort.getPossibleMetiers();
+ result += vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ }
+ return result;
+ }
+
+
+ //////////////////////////////////////////////////////////////////////
+ // matrixVesselMarginOverVariableCostsPerStrategy
+ //////////////////////////////////////////////////////////////////////
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategy(Date date) throws TopiaException{
+ List<Strategy> strategies = siMatrix.getStrategies(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
+ new List[]{strategies},
+ new String[]{n_("Strategies")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ double value = vesselMarginOverVariableCostsPerStrategy(str, date);
+ result.setValue(s, value);
+ }
+// for(Strategy str : strategies){
+// double value = vesselMarginOverVariableCostsPerStrategy(str, date);
+// result.setValue(str, value);
+// }
+
+ return result;
+ }
+
+ /**
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * VesselMarginOverVariableCostsPerStrategy[str,month]�=VesselMarginOverVariableCostsPerStrategyPerVessel�[str,month] *[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ *
+ * @param str
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ private double vesselMarginOverVariableCostsPerStrategy(Strategy str, Date date) throws TopiaException {
+ double vesselMarginOverVariableCostsPerStrategyPerVessel = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ double proportionSetOfVessels = str.getProportionSetOfVessels();
+ double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ return vesselMarginOverVariableCostsPerStrategyPerVessel * (proportionSetOfVessels * numberOfVessels);
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Methode non utilis�e directement dans GravityModel, mais dans les rules
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ public double valuePerUnitFishingEffort(Strategy str, Metier metier, Date date) throws TopiaException{
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ double result = 0;
+
+ for(Population pop : pops){
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ Collection<Zone> zones = pop.getPopulationZone();
+ for(PopulationGroup group : groups){
+ double price = group.getPrice();
+ for(Zone zone : zones){
+ double catchValue = getCatchWeightPerStrMet(str, metier, group, zone, date);
+ double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ result += price * (catchValue - discards);
+ }
+ }
+ }
+
+ double effort = getEffortPerStrategyMet(str, metier, date);
+
+ if(effort == 0){
+ result = 0;
+ } else {
+ result = result / effort;
+ }
+ // FIXME verifier qu'il faut bien retourner 0, si pas d'effort
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ public double getEffortPerStrategyMet(Strategy str, Metier metier, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+ double result = 0;
+ if(mat != null){
+ result = mat.getValue(str, metier);
+ }
+ return result;
+ }
+
+ public double landingPerUnitFishingEffort(Strategy str, Metier metier, Date date) throws TopiaException{
+ List<Population> pops = siMatrix.getPopulations(date);
+
+ double effort = getEffortPerStrategyMet(str, metier, date);
+ double result = 0;
+
+ if(effort != 0){ // s'il n'y a pas d'effort on retournera 0
+ for(Population pop : pops){
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ Collection<Zone> zones = pop.getPopulationZone();
+ for(PopulationGroup group : groups){
+ for(Zone zone : zones){
+ double catchValue = getCatchWeightPerStrMet(str, metier, group, zone, date);
+ double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ result += catchValue - discards;
+ }
+ }
+ }
+ result = result / effort;
+ }
+
+ return result;
+ }
+
+}
+
+
Added: trunk/3.1.0/scripts/ResultName.java
===================================================================
--- trunk/3.1.0/scripts/ResultName.java (rev 0)
+++ trunk/3.1.0/scripts/ResultName.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,96 @@
+/* *##%
+ * Copyright (C) 2006
+ * Code Lutin, C�dric Pineau, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * ResultName.java
+ *
+ * Created: 23 ao�t 2006 15:09:37
+ *
+ * @author poussin
+ * @version $Revision: 1.10 $
+ *
+ * Last update: $Date: 2007-07-09 19:51:34 $
+ * by : $Author: bpoussin $
+ */
+
+package scripts;
+
+import static org.codelutin.i18n.I18n.n_;
+
+/**
+ * Contient l'ensemble des noms des differents resultats. Le mieux lorsque l'on
+ * veut un nouveau r�sultat est d'ajouter une constante ici, et de l'utiliser
+ * ensuite lors de la cr�ation de la matrice.
+ * <p>
+ * Ceci permet d'avoir un endroit unique ou l'on voit l'ensemble des r�sultats
+ * potentiellement disponible et de ne pas ce tromper en �crivent le nom
+ * d'un r�sultat
+ * <p>
+ * Cette classe ne doit contenir que des noms de resultat en static public String
+ * l'interface de lancement de simulation se base sur cette classe pour
+ * afficher l'ensemble des r�sultats disponible
+ *
+ * @author poussin
+ */
+public class ResultName {
+
+ static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET = n_("matrixDiscardsWeightPerStrMet");
+
+ static final public String MATRIX_DISCARDS_PER_STR_MET = n_("matrixDiscardsPerStrMet");
+ static final public String MATRIX_LANDING_PER_MET = n_("matrixLandingPerMet");
+
+ static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n_("matrixEffortPerStrategyMet");
+ static final public String MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET = n_("matrixStdTravelEffortPerStrategyMet");
+ static final public String MATRIX_EFFORT_PER_ZONE_POP = n_("matrixEffortPerZonePop");
+ static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET = n_("matrixCatchRatePerStrategyMet");
+ static final public String MATRIX_CATCH_PER_STRATEGY_MET = n_("matrixCatchPerStrategyMet");
+ static final public String MATRIX_FISHING_MORTALITY = n_("matrixFishingMortality");
+ static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET = n_("matrixCatchWeightPerStrategyMet");
+ static final public String MATRIX_ABUNDANCE = n_("matrixAbundance");
+ static final public String MATRIX_BIOMASS = n_("matrixBiomass");
+
+ static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n_("matrixFishingTimePerMonthPerVessel");
+ static final public String MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL = n_("matrixFuelCostsOfTravelPerVessel");
+ static final public String MATRIX_COSTS_OF_FISHING_PER_VESSEL = n_("matrixCostsOfFishingPerVessel");
+ static final public String MATRIX_FUEL_COSTS_PER_VESSEL = n_("matrixFuelCostsPerVessel");
+ static final public String MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL = n_("matrixRepairAndMaintenanceGearCostsPerVessel");
+ static final public String MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL = n_("matrixOtherRunningCostsPerVessel");
+ static final public String MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL = n_("matrixSharedNotFixedCostsPerVessel");
+// static final public String MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET = n_("matrixSharedFixedCostsPerVesselPerMet");
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet");
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerStrategyMet");
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixGrossValueOfLandingsPerStrategyMetPerVessel");
+ static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixNetValueOfLandingsPerStrategyMet");
+ static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetValueOfLandingsPerStrategyMetPerVessel");
+ static final public String MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetRenevueToSharePerStrategyMetPerVessel");
+ static final public String MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixCrewSharePerStrategyPerVessel");
+ static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel");
+ static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel");
+ static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyPerVessel");
+ static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixOwnerMarginOverVariableCostsPerStrategy");
+ static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyPerVessel");
+ static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixVesselMarginOverVariableCostsPerStrategy");
+
+ static final public String MATRIX_NO_ACTIVITY = n_("matrixNoActivity");
+ static final public String MATRIX_METIER_ZONE = n_("matrixMetierZone");
+ static final public String MATRIX_PRICE = n_("matrixPrice");
+
+}
+
+
Added: trunk/3.1.0/scripts/RuleUtil.java
===================================================================
--- trunk/3.1.0/scripts/RuleUtil.java (rev 0)
+++ trunk/3.1.0/scripts/RuleUtil.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,65 @@
+package scripts;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.codelutin.math.matrix.*;
+
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+
+/**
+ * ChangeMatrixBackend.java
+ *
+ * Created: 6 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 2007-11-20 15:51:05 $
+ * by : $Author: bpoussin $
+ */
+public class RuleUtil {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(RuleUtil.class);
+
+ /**
+ * @param context le context de simulation
+ * @param species l'espece sur lequel on souhaite le total
+ * @param date la date pour laquel on veut le calcul, cet argument est
+ * passe seulement pour que le cache ne retourne pas toujours la meme valeur
+ * @return
+ */
+ public static double getTotalCatchTons(SimulationContext context, Species species, Date date) {
+ double result = 0;
+ for (Population pop : species.getPopulation()) {
+ MatrixND mat = context.getPopulationMonitor().getHoldCatch(pop);
+ if(mat!=null) {
+ mat = mat.copy();
+ mat = mat.sumOverDim(0); // sum over Strategies
+ mat = mat.sumOverDim(1); // sum over metiers
+ mat = mat.sumOverDim(3); // sum over zones
+// List<PopulationGroup> groups = mat.getSemantics(2);
+
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+
+ for (int c=0; c<groups.size(); c++) {
+ PopulationGroup group = groups.get(c);
+ double weight = group.getMeanWeight();
+ result += mat.getValue(0, 0, c, 0) * weight / 1000.0;
+ }
+ }
+ }
+ return result;
+ }
+
+
+
+
+}
Added: trunk/3.1.0/scripts/SiMatrix.java
===================================================================
--- trunk/3.1.0/scripts/SiMatrix.java (rev 0)
+++ trunk/3.1.0/scripts/SiMatrix.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,1180 @@
+/* *##%
+ * Copyright (C) 2006
+ * Code Lutin, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * SiMatrix.java
+ *
+ * Created: 21 ao�t 2006 15:53:01
+ *
+ * @author poussin
+ * @version $Revision: 1.18 $
+ *
+ * Last update: $Date: 2007-11-02 17:53:20 $
+ * by : $Author: bpoussin $
+ */
+
+package scripts;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+import fr.ifremer.isisfish.IsisFishDAOHelper;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.entities.Cell;
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Gear;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.MetierSeasonInfo;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.Selectivity;
+import fr.ifremer.isisfish.entities.SetOfVessels;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.entities.ZoneDAO;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * @author poussin
+ *
+ */
+
+public class SiMatrix {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(SiMatrix.class);
+
+ protected SimulationContext context = null;
+ protected TopiaContext db = null;
+
+ /**
+ * Method used to get SiMatrix used for simulation
+ * @param context context simulation
+ * @return SiMatrix or null if no SiMatrix created for simulation
+ */
+ public static SiMatrix getSiMatrix(SimulationContext context) {
+ SiMatrix result = (SiMatrix)context.getValue(SiMatrix.class.getName());
+ return result;
+ }
+
+ private static void setSiMatrix(SimulationContext context, SiMatrix siMatrix) {
+ context.setValue(SiMatrix.class.getName(), siMatrix);
+ }
+
+ /**
+ *
+ * @param context Simulation context
+ * @param db TopiaContext with transaction opened. You must used this
+ * TopiaContext and not used
+ * SimulationContext.getSimulationStorage().getStorage()
+ * @throws TopiaException
+ */
+ public SiMatrix(SimulationContext context) throws TopiaException {
+ this.context = context;
+ this.db = context.getDB();
+ setSiMatrix(context, this);
+ }
+
+ /**
+ * @return
+ * @throws TopiaException
+ */
+ public List<Zone> getZones(Date date) throws TopiaException {
+ ZoneDAO dao = IsisFishDAOHelper.getZoneDAO(db);
+ List<Zone> result = dao.findAll();
+ return result;
+ }
+
+ /**
+ * @return
+ * @throws TopiaException
+ */
+ public List<Population> getPopulations(Date date) throws TopiaException {
+ List<Population> populations = new ArrayList<Population>();
+ for (Population pop : context.getSimulationStorage().getParameter().getPopulations()) {
+ Population tmp = (Population)db.findByTopiaId(pop.getTopiaId());
+ populations.add(tmp);
+ }
+ return populations;
+ }
+
+ /**
+ * @return
+ * @throws TopiaException
+ */
+ public List<Strategy> getStrategies(Date date) throws TopiaException {
+// if (strategies == null) {
+ List<Strategy> strategies = new ArrayList<Strategy>();
+ for (Strategy str : context.getSimulationStorage().getParameter().getStrategies()) {
+ Strategy tmp = (Strategy)db.findByTopiaId(str.getTopiaId());
+ strategies.add(tmp);
+ }
+// }
+ return strategies;
+ }
+
+ public List<Metier> getMetiers(Date date) throws TopiaException {
+// if (metiers == null) {
+ List<Metier> metiers = new ArrayList<Metier>();
+ HashSet<Metier> tmp = new HashSet<Metier>();
+ for (Strategy str : getStrategies(date)) {
+ SetOfVessels sov = str.getSetOfVessels();
+ for (EffortDescription effort : sov.getPossibleMetiers()) {
+ Metier metier = effort.getPossibleMetiers();
+ if (tmp.add(metier)) {
+ metiers.add(metier);
+ }
+ }
+ }
+// }
+ return metiers;
+ }
+
+ /**
+ * Retourne les metiers pratiqu�s par une Strategie � une date donn�e
+ * Un metier est pratiqu� si le PropStrMet est diff�rent de 0
+ *
+ * @param str
+ * @param date
+ * @return
+ */
+ public List<Metier> getMetiers(Strategy str, Date date) {
+ StrategyMonthInfo info = str.getStrategyMonthInfo(date.getMonth());
+ MatrixND props = info.getProportionMetier();
+
+ List<Metier> result = new ArrayList<Metier>();
+
+ for (MatrixIterator i=props.iterator(); i.hasNext();) {
+ i.next();
+ if (i.getValue() != 0) {
+ Metier metier = (Metier)i.getSemanticsCoordinates()[0];
+ result.add(metier);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Retourne la matrix Metier x Zone qui correspond au zone utilis� par
+ * un m�tier pour une date donn�e. Si la valeur de la matrice est 1 alors
+ * la zone est utilis� par le m�tier, si elle vaut 0 alors elle n'est pas
+ * utilis�e.
+ *
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ public MatrixND getMetierZone(Date date) throws TopiaException {
+ List<Metier> metiers = getMetiers(date);
+ List<Zone> zones = getZones(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_METIER_ZONE,
+ new List[]{metiers, zones},
+ new String[]{n_("Metiers"), n_("Zones")});
+
+ for (Metier metier : metiers) {
+ Collection<Zone> zoneMetier = metier.getMetierSeasonInfo(date.getMonth()).getZone();
+ for (Zone zone : zoneMetier) {
+ result.setValue(metier, zone, 1);
+ }
+ }
+ return result;
+ }
+
+ public MatrixND matrixPrice(Date date, Population pop) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_PRICE,
+ new List[]{groups},
+ new String[]{n_("PopulationGroup")});
+
+ for (PopulationGroup group : groups) {
+ result.setValue(group, group.getPrice());
+ }
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Toutes les methodes suivantes ne sont utiles que pour
+ // matrixCatchPerStrategyMet
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Matrice des captures en nombre
+ * dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param N l'abondance sous forme de matrice 2D [class x zone]
+ * @param pop
+ * @param date
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ public MatrixND matrixCatchPerStrategyMet(MatrixND N, Population pop,
+ Date date, MatrixND matrixCatchRatePerStrategyMet) throws TopiaException, IsisFishException {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ // on le passe en argument ce qui evite de le calculer 2 fois
+// MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMet(pop, date);
+ MatrixND result = matrixCatchRatePerStrategyMet.copy();
+ result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
+
+ for(PopulationGroup group : groups) {
+ MatrixND sub = result.getSubMatrix(2, group, 1);
+ for(Zone zone : zones){
+ MatrixND subsub = sub.getSubMatrix(3, zone, 1);
+ double val = N.getValue(group, zone);
+ subsub.mults(val);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Matrice des captures en poids
+ * dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param pop
+ * @param date
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ public MatrixND matrixCatchRatePerStrategyMet(Population pop, Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+ List<Strategy> strategies = getStrategies(date);
+ List<Metier> metiers = getMetiers(date);
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET,
+ new List[]{strategies, metiers, groups, zones},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+
+// for (int s=0; s < strategies.size(); s++) {
+// Strategy str = strategies.get(s);
+// metiers = getMetiers(str, date);
+// for (int m=0; m < metiers.size(); m++) {
+// Metier metier = metiers.get(m);
+// for (int g=0; g < groups.size(); g++) {
+// PopulationGroup group = groups.get(g);
+// for (int z=0; z < zones.size(); z++) {
+// Zone zone = zones.get(z);
+// double value = catchRatePerStrategyMet(str, metier, date, group, zone);
+// result.setValue(str, metier, group, zone, value);
+// }
+// }
+// }
+// }
+
+// if(totalFishingMortality == 0){
+// if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + pop + ")");}
+// } else {
+ // Optimisation Hilaire
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double effort = effortPerZonePop(str,metier,date,zone);
+ if (effort > 0){
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ double value = catchRatePerStrategyMet(str, metier, date, group, zone, matrixFishingMortality);
+ result.setValue(str, metier, group, zone, value);
+ }
+ }
+ }
+ }
+ }
+// }
+
+// for (Strategy str : strategies) {
+// List<Metier> metierStr = getMetiers(str, date);
+// for (Metier metier : metierStr) {
+// for (PopulationGroup group : groups) {
+// for (Zone zone : zones) {
+// double val = catchRatePerStrategyMet(str, metier, date, group, zone);
+// result.setValue(str, metier, group, zone, val);
+// }
+// }
+// }
+// }
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @param group
+ * @param zone
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+// private double catchRatePerStrategyMet(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone) throws TopiaException, IsisFishException {
+// double totalFishingMortality = totalFishingMortality(date, group, zone);
+//
+// if(totalFishingMortality == 0){
+// if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + group + ", " + zone +")");}
+// return 0;
+// }
+//
+// double fishingMortality = fishingMortality(str, metier, date, group, zone);
+// double totalCatchRate = totalCatchRate(date, group, zone, totalFishingMortality);
+//
+// if(log.isDebugEnabled()) {
+// log.debug(
+// " totalFishingMortality=" + totalFishingMortality +
+// " fishingMortality=" + fishingMortality +
+// " totalCatchRate=" + totalCatchRate);
+// }
+// double result = fishingMortality / totalFishingMortality * totalCatchRate;
+//
+// return result;
+// }
+
+ // Optimisation Hilaire
+ private double catchRatePerStrategyMet(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+// double totalFishingMortality = matrixFishingMortality.sumAll();
+ double totalFishingMortality = totalFishingMortality(date, matrixFishingMortality).getValue(group, zone);
+
+ if(totalFishingMortality == 0){
+ if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + group + ", " + zone +")");}
+ return 0;
+ }
+
+ double fishingMortality = matrixFishingMortality.getValue(str, metier, group, zone);
+ double totalCatchRate = totalCatchRate(date, group, zone, totalFishingMortality);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " totalFishingMortality=" + totalFishingMortality +
+ " fishingMortality=" + fishingMortality +
+ " totalCatchRate=" + totalCatchRate);
+ }
+ double result = fishingMortality / totalFishingMortality * totalCatchRate;
+
+ return result;
+ }
+
+
+ /**
+ * @param date
+ * @param group
+ * @param zone
+ * @param totalFishingMortality
+ * @return
+ * @throws TopiaException
+ */
+ private double totalCatchRate(Date date, PopulationGroup group,
+ Zone zone, double totalFishingMortality) throws TopiaException {
+ double M = group.getNaturalDeathRate(zone) / Month.NUMBER_OF_MONTH;
+ if(M == 0){
+ // normalement il devrait y avoir de la mortalite naturelle
+ if (log.isWarnEnabled()) {
+ log.warn("Pas de mortalit� naturelle pour: " + group);
+ }
+ }
+ double F = totalFishingMortality;
+
+ double result = 0;
+ if( M != 0 || F != 0){
+ result = F/(F+M) * (1 - Math.exp(-(F+M)));
+ }
+
+ return result;
+ }
+
+ /**
+ * Returne une matrice de mortalite group x zone, donc somme sur str et metier
+ *
+ * @param date
+ * @param matrixFishingMortality
+ * @param group
+ * @param zone
+ * @return
+ */
+ private MatrixND totalFishingMortality(Date date, MatrixND matrixFishingMortality) {
+ MatrixND result = matrixFishingMortality.sumOverDim(0);
+ result = result.sumOverDim(1);
+ result = result.reduceDims(0, 1);
+ return result;
+ }
+
+ /**
+ * Matrice fishing mortality
+ * dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param pop
+ * @param date
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ public MatrixND matrixFishingMortality(Date date, Population pop) throws TopiaException, IsisFishException {
+ List<Strategy> strategies = getStrategies(date);
+ List<Metier> metiers = getMetiers(date);
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ // default value in matrix is 0
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_FISHING_MORTALITY,
+ new List[]{strategies, metiers, groups, zones},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+
+ Month month = date.getMonth();
+ PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+
+// org.codelutin.util.CallAnalyse.activate();
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+
+ // getCapturability is check matrix validity and create matrix if needed and get one value in
+// org.codelutin.util.CallAnalyse.enter("debug infoPop.getCapturability");
+ double capturability = infoPop.getCapturability(group);
+// org.codelutin.util.CallAnalyse.exit("debug infoPop.getCapturability");
+ if (capturability != 0) { // check 0, this prevent next call, for default value
+
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+
+// org.codelutin.util.CallAnalyse.enter("debug infoMet.getTargetFactor");
+ MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month);
+ // getTargetFactor seem to be simple
+ double ciblage = infoMet.getTargetFactor(group);
+// org.codelutin.util.CallAnalyse.exit("debug infoMet.getTargetFactor");
+
+ if (ciblage != 0) { // check 0, this prevent next call, for default value
+
+// org.codelutin.util.CallAnalyse.enter("debug gear.getPopulationSelectivity");
+ Gear gear = metier.getGear();
+ Selectivity selectivity = gear.getPopulationSelectivity(pop);
+// org.codelutin.util.CallAnalyse.exit("debug gear.getPopulationSelectivity");
+ if (selectivity != null) {
+
+ // getCoefficient is equation evaluation
+// org.codelutin.util.CallAnalyse.enter("debug selectivity.getCoefficient");
+ double coeff = selectivity.getCoefficient(pop, group, metier);
+// org.codelutin.util.CallAnalyse.exit("debug selectivity.getCoefficient");
+ if (coeff != 0) { // check 0, this prevent next call, for default value
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double effort = effortPerZonePop(str,metier,date,zone);
+ if (effort > 0){ // put value only if <> 0
+ double value = coeff * capturability * ciblage * effort;
+// org.codelutin.util.CallAnalyse.enter("debug result.setValue");
+ result.setValue(str, metier, group, zone, value);
+// org.codelutin.util.CallAnalyse.exit("debug result.setValue");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+// System.out.println("****DEBUG matrixFishingMortality:" + org.codelutin.util.CallAnalyse.getThreadStatistics().toString());
+ return result;
+ }
+
+ // ne prendre que les metiers pratiqu� semble une bonne idee, mais en fait non, car cela oblige l'ordre des boucles
+ // et donc ne permet pas autant d'optimisation que souhait�
+// public MatrixND matrixFishingMortality2(Date date, Population pop) throws TopiaException, IsisFishException {
+// List<Strategy> strategies = getStrategies(date);
+// List<Metier> metiers = getMetiers(date);
+// List<PopulationGroup> groups = pop.getPopulationGroup();
+// List<Zone> zones = pop.getPopulationZone();
+
+// // default value in matrix is 0
+// MatrixND result = MatrixFactory.getInstance().create(
+// ResultName.MATRIX_FISHING_MORTALITY,
+// new List[]{strategies, metiers, groups, zones},
+// new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+
+// Month month = date.getMonth();
+// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+
+// for (int s=0; s < strategies.size(); s++) {
+// Strategy str = strategies.get(s);
+// metiers = getMetiers(str, date);
+// for (int m=0; m < metiers.size(); m++) {
+// Metier metier = metiers.get(m);
+// Gear gear = metier.getGear();
+// Selectivity selectivity = gear.getPopulationSelectivity(pop);
+// if (selectivity != null) {
+// MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month);
+// for (int z=0; z < zones.size(); z++) {
+// Zone zone = zones.get(z);
+// double effort = effortPerZonePop(str,metier,date,zone);
+// if (effort > 0){ // put value only if <> 0
+// for (int g=0; g < groups.size(); g++) {
+// PopulationGroup group = groups.get(g);
+
+// // getTargetFactor seem to be simple
+// double ciblage = infoMet.getTargetFactor(group);
+// if (ciblage != 0) { // check 0, this prevent next call, for default value
+// // getCapturability is check matrix validity and create matrix if needed and get one value in
+// double capturability = infoPop.getCapturability(group);
+// if (capturability != 0) { // check 0, this prevent next call, for default value
+// // getCoefficient is equation evaluation
+// double coeff = selectivity.getCoefficient(pop, group, metier);
+// if (coeff != 0) { // check 0, this prevent next call, for default value
+// double value = coeff * capturability * ciblage * effort;
+// result.setValue(str, metier, group, zone, value);
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// return result;
+// }
+
+// /**
+// * @param date
+// * @param group
+// * @param zone
+// * @return
+// * @throws TopiaException
+// * @throws IsisFishException
+// */
+// private double totalFishingMortality(Date date, PopulationGroup group, Zone zone) throws TopiaException, IsisFishException {
+// List<Strategy> strategies = getStrategies(date);
+//
+// float result = 0;
+//
+//// for(Strategy str : strategies){
+//// List<Metier> metierStr = getMetiers(str, date);
+//// for (Metier metier : metierStr) {
+//// // TODO peut etre ne pas le faire si classe.pop n'est pas
+//// /// peche par le metier
+//// result += fishingMortality(str, metier, date, group, zone);
+//// }
+//// }
+//
+// // Optimisation Hilaire
+// for(Strategy str : strategies){
+// List<Metier> metierStr = getMetiers(str, date);
+// for (Metier metier : metierStr) {
+// double effort=effortPerZonePop(str,metier,date,zone);
+// if (effort>0)
+// result += fishingMortality(str, metier, date, group, zone, effort);
+// }
+// }
+//
+// return result;
+// }
+
+
+ // fusion fishingMortality and matrixFishingMortality for performance reason
+// /**
+// * @param str
+// * @param metier
+// * @param date
+// * @param group
+// * @param zone
+// * @return
+// * @throws IsisFishException
+// */
+// private double fishingMortality(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone, double effort) throws IsisFishException {
+// Month month = date.getMonth();
+// Population pop = group.getPopulation();
+// Gear gear = metier.getGear();
+//
+// Selectivity selectivity = gear.getPopulationSelectivity(pop);
+//
+// double result = 0;
+//
+// if (selectivity != null) {
+// MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month);
+// double ciblage = infoMet.getTargetFactor(group);
+//
+// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+// double capturability = infoPop.getCapturability(group);
+//
+// double coeff = selectivity.getCoefficient(pop, group, metier);
+//
+// // Optimisation Hilaire
+//// double effort = effortPerZonePop(str, metier, date, zone);
+//
+// // la methode est appeler des millions de fois, donc meme si
+// // on ne perd pas beaucoup de temps avec le if, on en perd deja
+// // trop
+//// if(log.isDebugEnabled()) {
+//// log.debug(
+//// " strategy=" + str +
+//// " metier=" + metier +
+//// " ciblage=" + ciblage +
+//// " capturabilite=" + capturability +
+//// " selectivity=" + coeff +
+//// " effort=" + effort);
+//// }
+//
+// result = coeff * capturability * ciblage * effort;
+// }
+//
+// return result;
+// }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @param zone
+ * @return
+ */
+ private double effortPerZonePop(Strategy str, Metier metier, Date date, Zone zonePop) {
+ Month month = date.getMonth();
+ Collection<Zone> zoneMet = metier.getMetierSeasonInfo(month).getZone();
+ double inter = nbCellInter(zoneMet, zonePop);
+
+ double effortPerStrategyPerCell = effortPerStrategyPerCell(str, metier, date);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " inter=" + inter +
+ " effortPerStrategyPerCell=" + effortPerStrategyPerCell
+ );
+ }
+
+ double result = effortPerStrategyPerCell * inter;
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double effortPerStrategyPerCell(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ Collection<Zone> zones = metier.getMetierSeasonInfo(month).getZone();
+ double nbCell = getCells(zones).size();
+
+ if(nbCell == 0){
+ // normalement il devrait y avoir des mailles, mais pour les
+ // ancienne zone AuPort, il n'y en avait pas
+ if(log.isWarnEnabled()) log.warn("Calcul d'une distance pour le metier "+metier+" pour le mois "+month+" avec une zone sans maille: " + zones);
+ return 0;
+ }
+
+
+ double effortPerStrategy = effortPerStrategyMet(str, metier, date);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " nbCell=" + nbCell +
+ " effortPerStrategy=" + effortPerStrategy
+ );
+ }
+
+ double result = effortPerStrategy/nbCell;
+
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double effortPerStrategyMet(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+
+ double propSetOfVessels = str.getProportionSetOfVessels();
+ int nbOfVessels = str.getSetOfVessels().getNumberOfVessels();
+ double propStrMet = smi.getProportionMetier(metier);
+ double effortPerVessel = effortPerStrategyPerVessel(str, metier, date);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " propSetOfVessels=" + propSetOfVessels +
+ " nbOfVessels=" + nbOfVessels +
+ " propStrMet=" + propStrMet +
+ " effortPerVessel=" + effortPerVessel
+ );
+ }
+
+ double result = propSetOfVessels * nbOfVessels * propStrMet * effortPerVessel;
+
+ return result;
+ }
+
+ /**
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ private double effortPerStrategyPerVessel(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ int nbTrips = smi.getNumberOfTrips();
+ double fishingTime = fishingTimePerTrip(str, metier, date);
+ double stdEffortPerHour = stdEffortPerHour(str.getSetOfVessels(), metier);
+
+ if(log.isDebugEnabled()) {
+ log.debug(
+ " strategy=" + str +
+ " metier=" + metier +
+ " nbTrips=" + nbTrips +
+ " fishingTime=" + fishingTime +
+ " stdEffortPerHour=" + stdEffortPerHour
+ );
+ }
+
+ double result = nbTrips * fishingTime * stdEffortPerHour;
+
+ return result;
+ }
+
+ /**
+ * Used in GravityModel too
+ *
+ * @param str
+ * @param metier
+ * @param date
+ * @return
+ */
+ protected double fishingTimePerTrip(Strategy str, Metier metier, Date date) {
+ Month month = date.getMonth();
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ Collection<Zone> zone = metier.getMetierSeasonInfo(month).getZone();
+
+ if (zone == null) {
+ if(log.isWarnEnabled()) log.warn(
+ "missing zone for metier =" + metier +
+ " for month" + month
+ );
+ }
+
+ double tripDuration = smi.getTripType().getTripDuration().getHour();
+ double travelTime = travelTimePerTrip(str.getSetOfVessels(), zone);
+
+ double result = tripDuration - travelTime;
+
+ if (result < 0 ) {
+ if(log.isWarnEnabled()) log.warn(
+ " strategy=" + str +
+ " metier=" + metier +
+ " tripDuration=" + tripDuration +
+ " travelTime=" + travelTime
+ );
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param setOfVessels
+ * @param zone
+ * @return
+ */
+ protected double travelTimePerTrip(SetOfVessels sov, Collection<Zone> zoneMetier) {
+ Cell maille = sov.getPort().getCell();
+ double result =
+ 2 * distance(zoneMetier, maille) / sov.getVesselType().getSpeed();
+
+ return result;
+ }
+
+ /**
+ * @param zoneMetier
+ * @param maille
+ * @return
+ */
+ private double distance(Collection<Zone> zones, Cell cell) {
+ double result = 0;
+ List<Cell> cells = getCells(zones);
+
+ if(cells.size() == 0){
+ // normalement il devrait y avoir des mailles, mais pour les
+ // ancienne zone AuPort, il n'y en avait pas
+ if(log.isWarnEnabled()) {
+ log.warn("Calcul d'une distance avec une zone sans maille");
+ }
+ return 0;
+ }
+
+ for(Cell c : cells){
+ result += distance(c, cell);
+ }
+
+ if(log.isDebugEnabled()) {
+ log.debug(" result=" + result + " nbMaille="+cells.size());
+ }
+
+ result = result / (double)cells.size();
+ return result;
+ }
+
+ /**
+ * @param c
+ * @param cell
+ * @return
+ */
+ private double distance(Cell m1, Cell m2) {
+ double earthRadius = 6378.388;
+ double p = 180/Math.PI;
+
+ if(log.isDebugEnabled()) log.debug("p: " + p);
+
+ double m1lat = m1.getLatitude();
+ double m2lat = m2.getLatitude();
+ double m1lon = m1.getLongitude();
+ double m2lon = m2.getLongitude();
+
+ if(log.isDebugEnabled()) log.debug(
+ " m1lat=" + m1lat +
+ " m2lat=" + m2lat +
+ " m1lon=" + m1lon +
+ " m2lonx=" + m2lon
+ );
+
+ double m1lat_div_p = m1lat/p;
+ double m2lat_div_p = m2lat/p;
+ double m1lon_div_p = m1lon/p;
+ double m2lon_div_p = m2lon/p;
+
+ if(log.isDebugEnabled()) log.debug(
+ " m1lat_div_p=" + m1lat_div_p +
+ " m2lat_div_p=" + m2lat_div_p +
+ " m1lon_div_p=" + m1lon_div_p +
+ " m2lon_div_p=" + m2lon_div_p
+ );
+
+ double sin_m1lat_div_p = Math.sin(m1lat_div_p);
+ double sin_m2lat_div_p = Math.sin(m2lat_div_p);
+ double cos_m1lat_div_p = Math.cos(m1lat_div_p);
+ double cos_m2lat_div_p = Math.cos(m2lat_div_p);
+
+ if(log.isDebugEnabled()) log.debug(
+ " sin_m1lat_div_p=" + sin_m1lat_div_p +
+ " sin_m2lat_div_p=" + sin_m2lat_div_p +
+ " cos_m1lat_div_p=" + cos_m1lat_div_p +
+ " cos_m2lat_div_p=" + cos_m2lat_div_p
+ );
+
+ double cos_m1lon_div_p_minus_m2lon_div_p = Math.cos(m1lon_div_p - m2lon_div_p);
+
+ if(log.isDebugEnabled()) log.debug(
+ " cos_m1lon_div_p_minus_m2lon_div_p=" + cos_m1lon_div_p_minus_m2lon_div_p);
+
+ double acos = Math.acos(
+ sin_m1lat_div_p
+ * sin_m2lat_div_p
+ +
+ cos_m1lat_div_p
+ * cos_m2lat_div_p
+ * cos_m1lon_div_p_minus_m2lon_div_p
+ );
+
+ if(log.isDebugEnabled()) log.debug(" acos=" + acos);
+
+ double result = earthRadius * acos;
+
+ return result;
+ }
+
+ /**
+ * @param setOfVessels
+ * @param metier
+ * @return
+ */
+ private double stdEffortPerHour(SetOfVessels sov, Metier metier) {
+ double result = 0;
+ EffortDescription ed = sov.getPossibleMetiers(metier);
+ if(ed != null){
+ double fstd = metier.getGear().getStandardisationFactor();
+ double val = fstd * ed.getFishingOperation() * ed.getGearsNumberPerOperation();
+ result = val;
+ }
+ result = result/24; // 24 heures
+
+ return result;
+ }
+
+
+ /**
+ * used here and in Rule (CantonnementPreSimu)
+ *
+ * @param zones
+ * @return
+ */
+ public List<Cell> getCells(Collection<Zone> zones) {
+ List<Cell> result = new ArrayList<Cell>();
+ for (Zone zone : zones) {
+ result.addAll(zone.getCell());
+ }
+ return result;
+ }
+
+ /**
+ * used here and in Rule (CantonnementPreSimu)
+ *
+ * @param zoneMet
+ * @param zonePop
+ * @return
+ */
+ public int nbCellInter(Collection<Zone> zoneMet, Zone zonePop) {
+ List<Cell> cells = getCells(zoneMet);
+ List<Cell> tmp = new ArrayList<Cell>(cells);
+ tmp.retainAll(zonePop.getCell());
+ return tmp.size();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param N
+ * @param pop
+ * @param date
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ public MatrixND matrixAbundance(MatrixND N, Population pop, Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_ABUNDANCE,
+ new List[]{groups, zones},
+ new String[]{n_("Groups"), n_("Zones")});
+
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double value = survivalRate(date, group, zone, matrixFishingMortality);
+ double n = N.getValue(g, z);
+ value *= n;
+ result.setValue(g, z, value);
+ }
+ }
+
+// for(PopulationGroup group : groups){
+// for(Zone zone : zones){
+// double val = survivalRate(date, group, zone);
+// val *= N.getValue(group, zone);
+// result.setValue(group, zone, val);
+// }
+// }
+
+ return result;
+ }
+
+ /**
+ * @param date
+ * @param group
+ * @param zone
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ private double survivalRate(Date date, PopulationGroup group, Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException {
+ double F = totalFishingMortality(date, matrixFishingMortality).getValue(group, zone); //totalFishingMortality(date, group, zone); // rem perf: totalFishingMortality a deja ete calcul�
+ double M = group.getNaturalDeathRate(zone)/(double)Month.NUMBER_OF_MONTH;
+ double result = (double)Math.exp(-(F+M));
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param n
+ * @param pop
+ * @param date
+ * @return
+ */
+ public MatrixND matrixBiomass(MatrixND N, Population pop, Date date) {
+ List<PopulationGroup> groups = N.getSemantics(0);
+ List<Zone> zones = N.getSemantics(1);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_BIOMASS,
+ new List[]{groups, zones},
+ new String[]{n_("Groups"), n_("Zones")});
+
+ for (int g=0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ double meanWeight = group.getMeanWeight();
+ for (int z=0; z < zones.size(); z++) {
+ Zone zone = zones.get(z);
+ double n = N.getValue(group, zone);
+ double value = n * meanWeight;
+ result.setValue(group, zone, value);
+ }
+ }
+
+// for(PopulationGroup group : groups){
+// double meanWeight = group.getMeanWeight();
+// for(Zone zone : zones){
+// double val = N.getValue(group, zone) * meanWeight;
+// result.setValue(group, zone, val);
+// }
+// }
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param date
+ * @return
+ * @throws TopiaException
+ */
+ public MatrixND matrixEffortPerStrategyMet(Date date) throws TopiaException {
+ List<Strategy> strategies = getStrategies(date);
+ List<Metier> metiers = getMetiers(date);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET,
+ new List[]{strategies, metiers},
+ new String[]{n_("Strategies"), n_("Metiers")});
+
+ for (int s=0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ metiers = getMetiers(str, date);
+ for (int m=0; m < metiers.size(); m++) {
+ Metier metier = metiers.get(m);
+ double value = effortPerStrategyMet(str, metier, date);
+ result.setValue(str, metier, value);
+ }
+ }
+
+// for(Strategy str : strategies){
+// List<Metier> metierStr = getMetiers(str, date);
+// for(Metier metier : metierStr) {
+// double val = effortPerStrategyMet(str, metier, date); // rem perf: effortPerStrategyMet a deja ete calcul�
+// result.setValue(str, metier, val);
+// }
+// }
+
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ //
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param pop
+ * @param date
+ * @return
+ */
+ public MatrixND matrixCatchWeightPerStrategyMet(Population pop,
+ Date date, MatrixND matrixCatchPerStrategyMet) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+
+ MatrixND result = matrixCatchPerStrategyMet.copy();
+ result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+
+ for(PopulationGroup group : groups){
+ MatrixND sub = result.getSubMatrix(2, group, 1);
+ double meanWeight = group.getMeanWeight();
+ sub.mults(meanWeight);
+ }
+
+ return result;
+ }
+
+ /**
+ * @param pop
+ * @param date
+ * @return
+ */
+ public MatrixND matrixDiscardWeightPerStrategyMet(Population pop,
+ Date date, MatrixND matrixDiscardPerStrategyMet) {
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+
+ MatrixND result = matrixDiscardPerStrategyMet.copy();
+ result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+
+ for(PopulationGroup group : groups){
+ MatrixND sub = result.getSubMatrix(2, group, 1);
+ double meanWeight = group.getMeanWeight();
+ sub.mults(meanWeight);
+ }
+
+ return result;
+ }
+
+}
Added: trunk/3.1.0/simulators/DefaultSimulator.java
===================================================================
--- trunk/3.1.0/simulators/DefaultSimulator.java (rev 0)
+++ trunk/3.1.0/simulators/DefaultSimulator.java 2007-12-04 22:35:33 UTC (rev 1)
@@ -0,0 +1,526 @@
+/* *##%
+ * Copyright (C) 2006
+ * Ifremer, Code Lutin, C�dric Pineau, Benjamin Poussin
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+/* *
+ * DefaultSimulator.java
+ *
+ * Created: 21 ao�t 2006 10:57:46
+ *
+ * @author poussin
+ * @version $Revision: 1.19 $
+ *
+ * Last update: $Date: 2007-11-06 18:16:14 $
+ * by : $Author: bpoussin $
+ */
+
+package simulators;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+import scripts.GravityModel;
+import scripts.ResultName;
+import scripts.SiMatrix;
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.rule.Rule;
+import fr.ifremer.isisfish.simulator.MetierMonitor;
+import fr.ifremer.isisfish.simulator.PopulationMonitor;
+import fr.ifremer.isisfish.simulator.RuleMonitor;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.simulator.SimulationControl;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.Simulator;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * @author poussin
+ *
+ */
+
+public class DefaultSimulator implements Simulator {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(DefaultSimulator.class);
+
+ /**
+ * Called by isis don't modify signature
+ */
+ public void simulate(SimulationContext context) throws Exception {
+
+ SimulationParameter param = context.getSimulationStorage().getParameter();
+ SimulationControl control = context.getSimulationControl();
+ int lastYear = param.getNumberOfYear();
+ int lastDate = lastYear * Month.NUMBER_OF_MONTH;
+ Date date = control.getDate();
+ control.setProgressMax(lastDate);
+
+ ResultStorage resManager = context.getSimulationStorage().getResultStorage();
+ TopiaContext db = context.getDB();
+
+ SiMatrix siMatrix = new SiMatrix(context);
+ GravityModel gravityModel = new GravityModel(context, siMatrix);
+
+ PopulationMonitor populationMonitor = context.getPopulationMonitor();
+ MetierMonitor metierMonitor = context.getMetierMonitor();
+ RuleMonitor ruleMonitor = context.getRuleMonitor();
+
+ for (Population pop : siMatrix.getPopulations(date)) {
+ MatrixND N = param.getNumberOf(pop);
+ N.setName(ResultName.MATRIX_ABUNDANCE);
+ populationMonitor.setN(pop, N);
+ }
+
+ //
+ // Rule initialisation
+ //
+ List<Rule> rules = param.getRules();
+ control.setText("Rules initialisation:" + rules);
+ for (Rule rule : rules) {
+ rule.init(context);
+ log.info("Rule " +rule.getClass().getSimpleName()+ " initialized");
+ }
+
+ //
+ // Commit all change done un init rules methods.
+ //
+ context.getDB().commitTransaction();
+
+ //
+ // Simulation loop
+ //
+ while (date.getDate() < lastDate) {
+ //
+ // if user stop simulation before last year
+ //
+ if (control.isStopSimulationRequest()) {
+ break;
+ }
+
+ control.setDate(date);
+ control.setProgress(date.getDate());
+ control.setText(_("begin step " + date));
+
+ // raz des metiers interdits et des licences
+ metierMonitor.clear();
+
+ if (date.getMonth().equals(Month.JANUARY)) {
+ populationMonitor.clearCatch();
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
+ MatrixND mat = metierMonitor.getOrCreateNoActivity(date,
+ ResultName.MATRIX_NO_ACTIVITY,
+ siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date));
+ resManager.addResult(date, mat);
+ }
+
+ //
+ // Rule condition evaluation
+ //
+ control.setText("Evalute Rules conditions ("+rules.size()+" rules)");
+ for (Rule rule : rules) {
+ for (Metier metier : siMatrix.getMetiers(date)) {
+ boolean active = false;
+ try {
+ active = rule.condition(context, date, metier);
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't evaluate rule condition for: " + rule, eee);
+ }
+ }
+ ruleMonitor.setEvaluationCondition(date, rule, metier, active);
+ if (active) {
+ log.info("Activate rule: " + rule.getClass().getSimpleName());
+ resManager.addActiveRule(date, rule);
+ }
+ }
+ }
+
+ //
+ // Rule pre action
+ //
+ control.setText("Do pre action Rules");
+ for (Rule rule : rules) {
+ for (Metier metier : siMatrix.getMetiers(date)) {
+ boolean condition = ruleMonitor.getEvalutionCondition(date, rule, metier);
+ if (condition) {
+ rule.preAction(context, date, metier);
+ }
+ }
+ }
+
+ //
+ // Keep modification's information done in rule
+ //
+ if (resManager.isEnabled(ResultName.MATRIX_METIER_ZONE)) {
+ MatrixND metierZone = siMatrix.getMetierZone(date);
+ resManager.addResult(date, metierZone);
+ }
+
+ //
+ // Simulate one step for all pop
+ //
+ control.setText("Simulate one month");
+ for (Population pop : siMatrix.getPopulations(date)) {
+ computeMonth(context, siMatrix, date, pop);
+ }
+
+ //
+ // Add some result not population dependante
+ //
+
+ // only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+
+ control.setText("Add some results");
+ if (resManager.isEnabled(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET)) {
+ MatrixND effortPerStrategyMet = siMatrix.matrixEffortPerStrategyMet(date);
+ resManager.addResult(date, effortPerStrategyMet);
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET)) {
+ MatrixND stdTravelEffortPerStrategyMet = siMatrix.matrixEffortPerStrategyMet(date);
+ resManager.addResult(date, stdTravelEffortPerStrategyMet);
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_EFFORT_PER_ZONE_POP)) {
+ MatrixND effortPerZonePop = siMatrix.matrixEffortPerStrategyMet(date);
+ resManager.addResult(date, effortPerZonePop);
+ }
+
+
+ //
+ // Add economics results
+ //
+ if (!"false".equalsIgnoreCase(param.getTagValue().get("ecoResult"))) {
+ control.setText("Add economics results");
+ saveGravityModel(date, resManager, gravityModel);
+ }
+ }
+
+ //
+ // Add economics results
+ //
+ if (resManager.isEnabled(ResultName.MATRIX_PRICE)) {
+ for (Population pop : siMatrix.getPopulations(date)) {
+ MatrixND matPrice = siMatrix.matrixPrice(date, pop);
+ resManager.addResult(date, pop, matPrice);
+ }
+ }
+
+
+
+ //
+ // Rule post action
+ //
+ control.setText("Do post action Rules");
+ for (Rule rule : rules) {
+ for (Metier metier : siMatrix.getMetiers(date)) {
+ if (ruleMonitor.getEvalutionCondition(date, rule, metier)) {
+ rule.postAction(context, date, metier);
+ }
+ }
+ }
+
+ // discard and landing must be done after post action rules
+ // only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+
+ control.setText("Compute discard and landing");
+ for (Population pop : siMatrix.getPopulations(date)) {
+ //
+ // discard computation
+ //
+ MatrixND discard = populationMonitor.getDiscard(date, pop);
+ if (discard != null || date.getDate() == 0) { // force discard for the first month to have discard in result
+ if (discard == null) {
+ discard = MatrixFactory.getInstance().create(ResultName.MATRIX_DISCARDS_PER_STR_MET,
+ new List[]{siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date),
+ pop.getPopulationGroup(),
+ pop.getPopulationZone()},
+ new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+ }
+ resManager.addResult(date, pop, discard);
+
+ if (resManager.isEnabled(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET)) {
+ MatrixND discardWeightPerStrategyMet = siMatrix.matrixDiscardWeightPerStrategyMet(pop, date, discard);
+ resManager.addResult(date, pop, discardWeightPerStrategyMet);
+ }
+
+ }
+
+ //
+ // add landing result
+ //
+ if (resManager.isEnabled(ResultName.MATRIX_LANDING_PER_MET)) {
+ MatrixND landing = MatrixFactory.getInstance().create(populationMonitor.getCatch(pop));
+ if (discard != null) {
+ landing = landing.minus(discard);
+ }
+ landing.setName(ResultName.MATRIX_LANDING_PER_MET);
+ resManager.addResult(date, pop, landing);
+ }
+ }
+ }
+
+ //
+ // revert modification for next step
+ //
+ control.setText("Rollback rules changes");
+ db.rollbackTransaction();
+
+ //
+ // commit result
+ //
+ control.setText("Commit results");
+ TopiaContext tx = context.getDbResult();
+ tx.commitTransaction();
+
+ //
+ // Go next step
+ //
+ date = date.next();
+ }
+ }
+
+ protected void computeMonth(SimulationContext context, SiMatrix siMatrix, Date date, Population pop) throws IsisFishException, TopiaException {
+ // to add result
+ ResultStorage resManager = context.getSimulationStorage().getResultStorage();
+
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ MatrixND N = popMon.getN(pop);
+
+ if (log.isInfoEnabled()) {
+ log.info("====================== begin "+ date + " - " + pop +" =========================== " + System.currentTimeMillis());
+ log.info("N: " + N);
+ }
+
+ // add N and biomass result now, before computation
+ // N is reassigned during computation
+ resManager.addResult(date, pop, N);
+
+ if (resManager.isEnabled(ResultName.MATRIX_BIOMASS)) {
+ MatrixND biomass = siMatrix.matrixBiomass(N, pop, date);
+ resManager.addResult(date, pop, biomass);
+ }
+
+ Month month = date.getMonth();
+ PopulationSeasonInfo info = pop.getPopulationSeasonInfo(month);
+
+ // group change
+ MatrixND CA = null;
+ if (date.getDate() == 0) {
+ CA = MatrixFactory.getInstance().matrixId(pop.sizePopulationGroup()*pop.sizePopulationZone());
+ } else {
+ CA = info.getGroupChangeMatrix(month);
+ }
+
+ log.debug("CA: " + CA);
+
+ //migration
+ MatrixND M = info.getMigrationMatrix(month, N);
+ log.debug("M: " + M);
+ //emigration
+ MatrixND EM = info.getEmigrationMatrix(month, N);
+ log.debug("EM: " + EM);
+ //immigration
+ MatrixND IM = info.getImmigrationMatrix(month, N).transpose();
+ log.debug("IM: " + IM);
+
+ // pour les premiers calculs on met N en une matrice 1D
+ MatrixND N1D = pop.N2DToN1D(N);
+ log.debug("N1D: " + N1D);
+
+ MatrixND tmp0 = N1D.mult(CA);
+ MatrixND tmp1 = M.minus(EM);
+ MatrixND tmp2 = tmp0.mult(tmp1);
+ MatrixND tmp3 = tmp2.add(IM);
+
+ log.debug("N1D after mig: " + tmp3);
+
+ // On reconvertie en une matrice Semantique
+ N = pop.split2D(tmp3);
+
+ log.debug("N after mig: " + N);
+
+ //Recrutement
+ MatrixND R = info.getReproductionMatrix(month, N);
+ log.debug("R: " + R);
+
+ // ajout de la matrice R dans le suivi de la pop comme etant
+ // la reproduction pour le mois courant.
+ popMon.setReproduction(date, pop, R);
+
+ // recrutement
+ MatrixND recruitment = popMon.getRecruitment(date, pop);
+ log.debug("recruitment: " + recruitment);
+
+ // mortalite de la reproduction
+ popMon.applyReproductionMortality(pop);
+
+ N = N.add(recruitment);
+ log.debug("N after recru: " + N);
+
+ MatrixND abundance = N;
+ // compute fishing matrix only if there are one or more strategy
+ if (siMatrix.getStrategies(date).size() > 0) {
+ // compute some Matrix and add result
+ MatrixND matrixFishingMortality = siMatrix.matrixFishingMortality(date, pop);
+ resManager.addResult(date, pop, matrixFishingMortality);
+
+ abundance = siMatrix.matrixAbundance(N, pop, date, matrixFishingMortality);
+
+ // this matrix is necessary for matrixCatchPerStrategyMet
+ MatrixND catchRatePerStrategyMet = siMatrix.matrixCatchRatePerStrategyMet(pop, date, matrixFishingMortality);
+ resManager.addResult(date, pop, catchRatePerStrategyMet);
+
+ // this matrix is necessary for PopulationMonitor.holdCatch (reused in rule)
+ MatrixND catchPerStrategyMet = siMatrix.matrixCatchPerStrategyMet(N, pop, date, catchRatePerStrategyMet);
+ popMon.holdCatch(pop, catchPerStrategyMet);
+ resManager.addResult(date, pop, catchPerStrategyMet);
+
+ if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET)) {
+ MatrixND catchWeightPerStrategyMet = siMatrix.matrixCatchWeightPerStrategyMet(pop, date, catchPerStrategyMet);
+ resManager.addResult(date, pop, catchWeightPerStrategyMet);
+ }
+ }
+ log.debug("abundance: " + abundance);
+
+ // Keep new N
+ popMon.setN(pop, abundance);
+
+ log.debug("====================== end " + date + " - " + pop +" ===========================");
+
+ }
+
+ /**
+ * @param date
+ * @param resManager
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ private void saveGravityModel(Date date, ResultStorage resManager, GravityModel gravityModel) throws IsisFishException, TopiaException {
+ if (resManager.isEnabled(ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFishingTimePerMonthPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixCostsOfFishingPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_FUEL_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixRepairAndMaintenanceGearCostsPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOtherRunningCostsPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixSharedNotFixedCostsPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+// if (resManager.isEnabled(ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET)) {
+// MatrixND mat = gravityModel.matrixSharedFixedCostsPerVesselPerMet(date);
+// resManager.addResult(date, mat);
+// }
+ if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerStrategyMet(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel.matrixNetValueOfLandingsPerStrategyMet(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixNetValueOfLandingsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixNetRenevueToSharePerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixCrewSharePerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
+ MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategy(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategyPerVessel(date);
+ resManager.addResult(date, mat);
+ }
+ if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
+ MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategy(date);
+ resManager.addResult(date, mat);
+ }
+ }
+
+}
+
+
1
0