Isis-fish-community-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
May 2013
- 2 participants
- 13 discussions
Author: loic
Date: 2013-05-02 18:57:26 +0200 (Thu, 02 May 2013)
New Revision: 38
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
sensitivityexport_total_fishing_mortality_relative
Added:
trunk/sensitivityexports/SensitivityTotalFishingMortalityY2.java
Added: trunk/sensitivityexports/SensitivityTotalFishingMortalityY2.java
===================================================================
--- trunk/sensitivityexports/SensitivityTotalFishingMortalityY2.java (rev 0)
+++ trunk/sensitivityexports/SensitivityTotalFishingMortalityY2.java 2013-05-02 16:57:26 UTC (rev 38)
@@ -0,0 +1,105 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.nuiton.i18n.I18n._;
+
+import org.nuiton.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+
+import fr.ifremer.isisfish.entities.*;
+
+import fr.ifremer.isisfish.export.SensitivityExport;
+
+import fr.ifremer.isisfish.types.TimeStep;
+
+import fr.ifremer.isisfish.util.Doc;
+
+public class SensitivityTotalFishingMortalityY2 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory
+ .getLog(SensitivityTotalFishingMortalityY2.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_TOTAL_FISHING_MORTALITY };
+
+ @Doc("Population")
+ public Population param_pop;
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ ResultStorage resultStorage = simulation.getResultStorage();
+ TimeStep lastStep = resultStorage.getLastStep();
+ TimeStep firstStep = new TimeStep(11);
+ double firsttotalFishingMortality = 0.0;
+ double totalFishingMortality = 0.0;
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+
+ //Get the fishing mortality on december of the first year
+ MatrixND matfirstdate = resultStorage.getMatrix(firstStep, pop,
+ ResultName.MATRIX_TOTAL_FISHING_MORTALITY);
+ firsttotalFishingMortality = matfirstdate.sumAll();
+
+ //Get the fishing mortality of the (last step of) the last year.
+ MatrixND matlastdate = resultStorage.getMatrix(lastStep, pop,
+ ResultName.MATRIX_TOTAL_FISHING_MORTALITY);
+ totalFishingMortality = matlastdate.sumAll();
+
+ }
+ }
+
+ out.write(Double.toString(totalFishingMortality / firsttotalFishingMortality));
+ }
+
+ @Override
+ public String getDescription() {
+ return _("Total fishing mortality for the last year for the population. Total fishing mortality is the mean on zones, representative groups, and the sum of metiers and strategies");
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityTotalFishingMortalityY2_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:57:10 +0200 (Thu, 02 May 2013)
New Revision: 37
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
sensitivityexport_total_fishing_mortality
Added:
trunk/sensitivityexports/SensitivityTotalFishingMortalityY1.java
Added: trunk/sensitivityexports/SensitivityTotalFishingMortalityY1.java
===================================================================
--- trunk/sensitivityexports/SensitivityTotalFishingMortalityY1.java (rev 0)
+++ trunk/sensitivityexports/SensitivityTotalFishingMortalityY1.java 2013-05-02 16:57:10 UTC (rev 37)
@@ -0,0 +1,98 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import static org.nuiton.i18n.I18n._;
+
+import org.nuiton.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+
+import fr.ifremer.isisfish.entities.*;
+
+import fr.ifremer.isisfish.export.SensitivityExport;
+
+import fr.ifremer.isisfish.types.TimeStep;
+
+import fr.ifremer.isisfish.util.Doc;
+
+public class SensitivityTotalFishingMortalityY1 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory
+ .getLog(SensitivityTotalFishingMortalityY1.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_TOTAL_FISHING_MORTALITY };
+
+ @Doc("Population")
+ public Population param_pop;
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ ResultStorage resultStorage = simulation.getResultStorage();
+ TimeStep lastStep = resultStorage.getLastStep();
+ double totalFishingMortality = 0.0;
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+
+ //Get the fishing mortality of the (last step of) the last year.
+ MatrixND matlastdate = resultStorage.getMatrix(lastStep, pop,
+ ResultName.MATRIX_TOTAL_FISHING_MORTALITY);
+ totalFishingMortality = matlastdate.sumAll();
+
+ }
+ }
+
+ out.write(Double.toString(totalFishingMortality));
+ }
+
+ @Override
+ public String getDescription() {
+ return _("Total fishing mortality for the last year for the population. Total fishing mortality is the mean on zones, representative groups, and the sum of metiers and strategies");
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityTotalFishingMortalityY1_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:56:41 +0200 (Thu, 02 May 2013)
New Revision: 36
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
sensitivityexport_spawning_biomass_relative_janvier
Added:
trunk/sensitivityexports/SensitivitySpawningBiomassRelativeJanvierY5.java
Added: trunk/sensitivityexports/SensitivitySpawningBiomassRelativeJanvierY5.java
===================================================================
--- trunk/sensitivityexports/SensitivitySpawningBiomassRelativeJanvierY5.java (rev 0)
+++ trunk/sensitivityexports/SensitivitySpawningBiomassRelativeJanvierY5.java 2013-05-02 16:56:41 UTC (rev 36)
@@ -0,0 +1,116 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.util.Doc;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+
+import static org.nuiton.i18n.I18n._;
+
+public class SensitivitySpawningBiomassRelativeJanvierY5 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory
+ .getLog(SensitivitySpawningBiomassRelativeJanvierY5.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+
+ @Doc("Population")
+ public Population param_pop;
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ TimeStep lastStep = simulation.getResultStorage().getLastStep();
+ TimeStep janvierLastYear = new TimeStep(12 * lastStep.getYear());
+ TimeStep firstStep = new TimeStep(0);
+ double biomass = 0.0;
+ double firstbiomass = 0.0;
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+ ResultStorage resultStorage = simulation.getResultStorage();
+
+ //Get the biomass of the first time step
+ MatrixND matfirstdate = resultStorage.getMatrix(pop,
+ ResultName.MATRIX_BIOMASS);
+ for (MatrixIterator i = matfirstdate.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sems = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup) sems[1];
+ TimeStep step = (TimeStep) sems[0];
+ if (step.equals(firstStep)) {
+ firstbiomass += i.getValue()
+ * group.getMaturityOgive();
+ }
+ }
+
+ //Get the biomass of the last time step
+ MatrixND matlastJan = resultStorage.getMatrix(pop,
+ ResultName.MATRIX_BIOMASS);
+ for (MatrixIterator i = matlastJan.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sems = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup) sems[1];
+ TimeStep step = (TimeStep) sems[0];
+ if (step.equals(janvierLastYear))
+ biomass += i.getValue() * group.getMaturityOgive();
+ }
+ }
+ }
+ out.write(Double.toString(biomass / firstbiomass));
+ }
+
+ @Override
+ public String getDescription() {
+ return _("Biomass of genitors January last year / Biomass of genitors January first year . Biomass is the sum on the groups and zones");
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityGenitorBiomassRelativeJanvierY5_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:56:05 +0200 (Thu, 02 May 2013)
New Revision: 35
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
sensitivityexport_spawning_biomass_janvier
Added:
trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java
Added: trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java
===================================================================
--- trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java (rev 0)
+++ trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java 2013-05-02 16:56:05 UTC (rev 35)
@@ -0,0 +1,101 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.util.Doc;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+
+import java.io.Writer;
+
+import static org.nuiton.i18n.I18n._;
+
+public class SensitivitySpawningBiomassJanvierY2 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory
+ .getLog(SensitivitySpawningBiomassJanvierY2.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+
+ @Doc("Population")
+ public Population param_pop;
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ TimeStep lastStep = simulation.getResultStorage().getLastStep();
+ TimeStep janvierLastYear = new TimeStep(12 * lastStep.getYear());
+ double biomass = 0.0;
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+ ResultStorage resultStorage = simulation.getResultStorage();
+
+ //Get the biomass of the last time step
+ MatrixND matlastJan = resultStorage.getMatrix(pop,
+ ResultName.MATRIX_BIOMASS);
+ for (MatrixIterator i = matlastJan.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sems = i.getSemanticsCoordinates();
+ TimeStep step = (TimeStep) sems[0];
+ PopulationGroup group = (PopulationGroup) sems[1];
+ if (step.equals(janvierLastYear)) {
+ biomass += i.getValue() * group.getMaturityOgive();
+ }
+ }
+ }
+ }
+ out.write(Double.toString(biomass));
+ }
+
+ @Override
+ public String getDescription() {
+ return _("Biomass of genitors for January of the last year. Biomass is the sum on the groups and zones");
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityGenitorBiomassJanvierY2_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:55:47 +0200 (Thu, 02 May 2013)
New Revision: 34
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
sensitivityexport_biomass_relative_janvier
Added:
trunk/sensitivityexports/SensitivityBiomassRelativeJanvierY6.java
Added: trunk/sensitivityexports/SensitivityBiomassRelativeJanvierY6.java
===================================================================
--- trunk/sensitivityexports/SensitivityBiomassRelativeJanvierY6.java (rev 0)
+++ trunk/sensitivityexports/SensitivityBiomassRelativeJanvierY6.java 2013-05-02 16:55:47 UTC (rev 34)
@@ -0,0 +1,99 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.io.Writer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.util.Doc;
+
+public class SensitivityBiomassRelativeJanvierY6 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory
+ .getLog(SensitivityBiomassRelativeJanvierY6.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+
+ @Doc("Population")
+ public Population param_pop;
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ ResultStorage resultStorage = simulation.getResultStorage();
+ TimeStep lastStep = resultStorage.getLastStep();
+ TimeStep janvierLastYear = new TimeStep(12 * lastStep.getYear());
+ TimeStep firstStep = new TimeStep(0);
+ double biomass = 0.0;
+ double firstbiomass = 0.0;
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+
+ //Get the biomass on december of the first year
+ MatrixND matfirstdate = resultStorage.getMatrix(firstStep, pop,
+ ResultName.MATRIX_BIOMASS);
+ firstbiomass = matfirstdate.sumAll();
+
+ //Get the biomass on the month of January of the last time step
+ MatrixND matlastJan = resultStorage.getMatrix(janvierLastYear, pop,
+ ResultName.MATRIX_BIOMASS);
+ biomass = matlastJan.sumAll();
+
+ }
+ }
+ out.write(Double.toString(biomass / firstbiomass));
+ }
+
+ @Override
+ public String getDescription() {
+ return _("Biomass January last year / Biomass January first year. Biomass is the sum on the groups and zones");
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityBiomassRelativeJanvierY6_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:55:25 +0200 (Thu, 02 May 2013)
New Revision: 33
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
sensitivityexport_biomass_janvier
Added:
trunk/sensitivityexports/SensitivityBiomassJanvierY3.java
Added: trunk/sensitivityexports/SensitivityBiomassJanvierY3.java
===================================================================
--- trunk/sensitivityexports/SensitivityBiomassJanvierY3.java (rev 0)
+++ trunk/sensitivityexports/SensitivityBiomassJanvierY3.java 2013-05-02 16:55:25 UTC (rev 33)
@@ -0,0 +1,89 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.io.Writer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.util.Doc;
+
+public class SensitivityBiomassJanvierY3 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(SensitivityBiomassJanvierY3.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+
+ @Doc("Population")
+ public Population param_pop;
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ ResultStorage resultStorage = simulation.getResultStorage();
+ TimeStep lastStep = resultStorage.getLastStep();
+ TimeStep janvierLastYear = new TimeStep(12 * lastStep.getYear());
+ double biomass = 0.0;
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+
+ //Get the biomass of the last time step
+ MatrixND matlastJan = resultStorage.getMatrix(janvierLastYear, pop,
+ ResultName.MATRIX_BIOMASS);
+ biomass = matlastJan.sumAll();
+ }
+ }
+ out.write(Double.toString(biomass));
+ }
+
+ @Override
+ public String getDescription() {
+ return _("Biomass for January of the last year. Biomass is the sum on the groups and zones");
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityBiomassJanvierY3_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:54:39 +0200 (Thu, 02 May 2013)
New Revision: 32
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
TAC_poids_pop_HCR
Added:
trunk/rules/TACpoidsPop_PourHCR.java
Added: trunk/rules/TACpoidsPop_PourHCR.java
===================================================================
--- trunk/rules/TACpoidsPop_PourHCR.java (rev 0)
+++ trunk/rules/TACpoidsPop_PourHCR.java 2013-05-02 16:54:39 UTC (rev 32)
@@ -0,0 +1,374 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2006 - 2011 Ifremer, CodeLutin
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package rules;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import scripts.RuleUtil;
+import scripts.SiMatrix;
+import rules.HCR_transition_MSY; // En a-t-on besoin ????
+import fr.ifremer.isisfish.datastore.ResultStorage;
+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.TimeStep;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.util.Doc;
+
+/**
+ * TAC peut-etre utilise pour les differents 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 recalcule a chaque mois de janvier.
+ * <li>Pour utiliser la survie il faut mettre dans le parametre propSurvie une
+ * valeur > 0, automatiquement les suvie seront ajoute aux effectifs
+ *
+ * Created:
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 010812 $
+ * by : $Author: Loic $
+ */
+public class TACpoidsPop_PourHCR extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog( TACpoidsPop_PourHCR.class);
+
+ /** Population */
+ public Population param_population = null;
+ /** TAC in tonnes */
+ public double tacInTons = 0;
+ /** First step at which this particular TAC is applied */
+ public TimeStep beginStep = new TimeStep(36);
+ public TimeStep endStep = new TimeStep(119);
+ /** Proportion of fish that survives when discarded */
+ public double propSurvie = 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
+ */
+ @Override
+ 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
+ */
+ @Override
+ public String getDescription() {
+ return _("TAC weight in tons per population.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0.");
+ }
+
+ /**
+ * Appele au demarrage de la simulation, cette methode permet d'initialiser
+ * des valeurs
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ */
+ @Override
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ @Override
+ public boolean condition(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ /** Population */
+ //population = (Population) context.getValue("Population_TAC_HCR"); // pb avec l'utilisation des getValue
+ /** TAC in tonnes */
+ tacInTons = (Double) context.getValue("TAC_" + param_population.getName() + "_HCR");
+ /** First step at which this particular TAC is applied */
+ beginStep = (TimeStep) context.getValue("BeginStep_TAC_" + param_population.getName() + "_HCR");
+ endStep = beginStep.nextYear(); // One TAC a year
+ log.info("beginStep = " + beginStep);
+ log.info("endStep = " + endStep);
+ /** Proportion of fish that survives when discarded */
+ propSurvie = (Double) context.getValue("PropSurvie_TAC_" + param_population.getName() + "_HCR");
+
+
+ log.info("test si TAC atteint");
+
+ param_population = (Population) context.getDB().findByTopiaId(
+ param_population.getTopiaId());
+
+
+ boolean result = false;
+ if (step.before(beginStep)) {
+ result = false;
+ } else if (step.after(endStep)) {
+ result = false;
+ } else {
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ if (ts != null) {
+ double catchTons = RuleUtil.getTotalCatchTonsPop(context,
+ param_population, step);
+
+ //PopulationMonitor popMon = context.getPopulationMonitor();
+ //double catchTons = popMon.getTotalHoldCatch(param_population); // Rend une matrice (dimensions ??) utiliser getTotalHoldCatch(Population pop) (qui rend un double) a la place ??
+
+ log.info("[TAC] catchTons = " + catchTons
+ + " >= tacInTons:" + tacInTons);
+ if (catchTons >= tacInTons) {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est executee avant le pas
+ * de temps de la simulation.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void preAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ log.info("Using TACpoidsPop_PourHCR");
+
+ affectation = false;
+
+ log.info("[TAC] preAction for: " + metier);
+ log.info(" TAC atteint [TAC] preAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ if (ts != null && ts.getPrimaryCatch()) {
+ // recupere tous les metiers qui ont l'espece en capture principale =>metiers vises
+ // aimedMetiers ne fonctionne pas je ne sais pas pourquoi ! mais au final forbiddenMetier aura le meme effet
+
+ context.getMetierMonitor().addforbiddenMetier(metier);
+
+ //recupere toutes les strategies pratiquant le metier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ Set<Strategy> strs = new HashSet<Strategy>();
+ for (Strategy str : siMatrix.getStrategies(step)) {
+ double prop = str.getStrategyMonthInfo(step.getMonth())
+ .getProportionMetier(metier);
+ if (prop != 0) {
+ strs.add(str);
+ }
+ }
+
+ for (Strategy str : strs) {
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(step
+ .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")
+ && !metier.getName().equalsIgnoreCase(
+ "non Activite")
+ && !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 : possibleMetier) {
+ somme += smi.getProportionMetier(met);
+ }
+ for (Metier met : possibleMetier) {
+ 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
+ log.info("[TAC] il y a des metiers possibles");
+ } else {
+ log.info("[TAC] Use no activity");
+
+ // sinon on met tout dans le metier nonActivite
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND mat = metierMon.getOrCreateNoActivity(step,
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ .getStrategies(step), siMatrix
+ .getMetiers(step));
+ mat.setValue(str, metier, smi.getProportionMetier(metier));
+
+ smi.getProportionMetier().setValue(metier, 0);
+ }
+ }
+ }
+ }
+
+ /**
+ // * Si la condition est vrai alors cette action est executee apres le pas
+ * de temps de la simulation.
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void postAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+ ResultStorage resultmanager = context.getSimulationStorage()
+ .getResultStorage();
+ log.info("[TAC] postAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ 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();
+ log.info("popMon biomass" + popMon.getBiomass(param_population)); // A priori on travaille ici sur une pop donnee car on defini le TAC sur une seule pop... Donc pas la peine de boucler sur les populations.
+
+ if (!param_population.getName().equals("Population_new")) {
+ log.info("param_population : " + param_population.getName());
+ // 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(step, param_population);
+ log.info("discard : " + discard);
+ if (discard != null) {
+ discard.mults(0);
+ }
+ log.info("catch = " + popMon.getCatch(param_population));
+ discard = popMon.getCatch(param_population).copy();
+ // ca ne doit pas pouvoir marcher car MATRIX_DISCARDS_PER_STR_MET est de dimension pop groupe str met - et discard n'a plus la dimension pop
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP);
+ popMon.addDiscard(step, param_population, discard);
+ log.info("[TAC] add discard for " + param_population + ": "
+ + discard);
+ // ne manquerait-il pas
+ resultmanager.addResult(step, param_population, discard);
+ if (propSurvie > 0) {
+ MatrixND eff = popMon.getN(param_population);
+ //on rajoute 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() * propSurvie);
+ }
+ }
+
+ }
+
+ // on a affecte une fois cette meta pop au rejet il ne faut pas
+ // le refaire
+ affectation = true;
+ }
+ }
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:54:16 +0200 (Thu, 02 May 2013)
New Revision: 31
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
TAC_poids_pop_3ans
Added:
trunk/rules/TACpoidsPop20082011.java
Added: trunk/rules/TACpoidsPop20082011.java
===================================================================
--- trunk/rules/TACpoidsPop20082011.java (rev 0)
+++ trunk/rules/TACpoidsPop20082011.java 2013-05-02 16:54:16 UTC (rev 31)
@@ -0,0 +1,363 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2006 - 2011 Ifremer, CodeLutin
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package rules;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import scripts.RuleUtil;
+import scripts.SiMatrix;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+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.TimeStep;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.util.Doc;
+
+/**
+ * TAC peut-etre utilise pour les differents 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 recalcule a chaque mois de janvier.
+ * <li>Pour utiliser la survie il faut mettre dans le parametre propSurvie une
+ * valeur > 0, automatiquement les suvie seront ajoute aux effectifs
+ *
+ * Created: 7 septembre 2006
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 13/12/2012 $
+ * by : $Author: Loic $
+ */
+public class TACpoidsPop20082011 extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(TACpoidsPop20082011.class);
+
+ @Doc("Affected population")
+ public Population param_population = null;
+
+ @Doc("Proportion de survie")
+ public double param_propSurvie = 0;
+
+
+ /** TAC in tonnes */
+
+ @Doc("TAC in tons 2008")
+ public double param_tacInTons2008 = 4000;
+ @Doc("TAC in tons 2009")
+ public double param_tacInTons2009 = 3500;
+ @Doc("TAC in tons 2010")
+ public double param_tacInTons2010 = 3000;
+
+ boolean affectation = true;
+
+ 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
+ */
+ @Override
+ 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
+ */
+ @Override
+ public String getDescription() {
+ return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0.");
+ }
+
+ /**
+ * Appele au demarrage de la simulation, cette methode permet d'initialiser
+ * des valeurs
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ */
+ @Override
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ @Override
+ public boolean condition(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ log.info("test si TAC atteint");
+
+ //param_population = (Population) context.getDB().findByTopiaId(param_population.getTopiaId());
+
+ double tacInTons = 0;
+ boolean result = false;
+ if (step.getYear()>2) {
+ result = false;
+ } else {
+ if (step.getYear()==0) {
+ tacInTons = param_tacInTons2008;
+ } else if (step.getYear()==1) {
+ tacInTons = param_tacInTons2009;
+ } else if (step.getYear()==2) {
+ tacInTons = param_tacInTons2010;
+ context.setValue("tacInTons_" + param_population.getName() + "_2010", tacInTons);
+ log.info("tacInTons2010 = " + tacInTons);
+ log.info("param_tacInTons2010 = " + param_tacInTons2010);
+ }
+
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+
+ if (ts != null) {
+ double catchTons = RuleUtil.getTotalCatchTonsPop(context, param_population, step);
+ log.info("catchTons = " + catchTons);
+ log.info("[TAC] catchTons = " + catchTons + " >= tacInTons:" + tacInTons);
+ if (catchTons >= tacInTons) {
+ result = true;
+ }
+ }
+ log.info("tacInTons = " + tacInTons);
+ }
+ return result;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est executee avant le pas
+ * de temps de la simulation.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void preAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ //context.setValue("tacInTons2010", param_tacInTons2010);
+
+ affectation = true; //true ?
+
+ log.info("[TAC] preAction for: " + metier);
+ log.info(" TAC atteint [TAC] preAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ if (ts != null && ts.getPrimaryCatch()) {
+ // recupere tous les metiers qui ont l'espece en capture principale =>metiers vises
+ // aimedMetiers ne fonctionne pas je ne sais pas pourquoi ! mais au final forbiddenMetier aura le meme effet
+
+ context.getMetierMonitor().addforbiddenMetier(metier);
+
+ //recupere toutes les strategies pratiquant le metier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ Set<Strategy> strs = new HashSet<Strategy>();
+ for (Strategy str : siMatrix.getStrategies(step)) {
+ double prop = str.getStrategyMonthInfo(step.getMonth())
+ .getProportionMetier(metier);
+ if (prop != 0) {
+ strs.add(str);
+ }
+ }
+
+ for (Strategy str : strs) {
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(step
+ .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")
+ && !metier.getName().equalsIgnoreCase(
+ "non Activite")
+ && !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 : possibleMetier) {
+ somme += smi.getProportionMetier(met);
+ }
+ for (Metier met : possibleMetier) {
+ 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
+ log.info("[TAC] il y a des metiers possibles");
+ } else {
+ log.info("[TAC] Use no activity");
+
+ // sinon on met tout dans le metier nonActivite
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND mat = metierMon.getOrCreateNoActivity(step,
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ .getStrategies(step), siMatrix
+ .getMetiers(step));
+ mat.setValue(str, metier, smi.getProportionMetier(metier));
+
+ smi.getProportionMetier().setValue(metier, 0);
+ }
+ }
+ }
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execute apres le pas
+ * de temps de la simulation.
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void postAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ log.info("[TAC] postAction for: " + metier);
+
+ if (affectation) { // sans ! ?
+ // 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();
+ log.info("popMon biomass" + popMon.getBiomass(param_population)); // A priori on travaille ici sur une pop donnee car on defini le TAC sur une seule pop... Donc pas la peine de boucler sur les populations.
+
+ //if (!param_population.getName().equals("param_population_new")) {
+ log.info("param_population : " + param_population.getName());
+ // 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 met
+ // TOUTES les captures dans les rejets
+ MatrixND discard = popMon.getDiscard(step, param_population);
+ //log.info("discard : " + discard);
+ if (discard != null) {
+ discard.mults(0);
+ }
+ log.info("catch = " + popMon.getCatch(param_population));
+ MatrixND discardRegle = popMon.getCatch(param_population).copy(); //nouvelle instance pour le calcul dans la regle
+ // ca ne doit pas pouvoir marcher car MATRIX_DISCARDS_PER_STR_MET est de dimension pop groupe str met - et discard n'a plus la dimension pop
+ discardRegle.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP);
+ popMon.addDiscard(step, param_population, discardRegle);
+ log.info("[TAC] add discard for " + param_population + ": "
+ + discardRegle);
+ if (param_propSurvie > 0) {
+ MatrixND eff = popMon.getN(param_population);
+ //on rajoute les survivants aux effectifs
+ for (MatrixIterator i = discardRegle.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 = false; // false ?
+ }
+ //context.setValue("tacInTons2010", param_tacInTons2010);
+ }
+}
1
0
Author: loic
Date: 2013-05-02 18:53:44 +0200 (Thu, 02 May 2013)
New Revision: 30
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
TAC_poids_pop
Added:
trunk/rules/TACpoidsPop.java
Added: trunk/rules/TACpoidsPop.java
===================================================================
--- trunk/rules/TACpoidsPop.java (rev 0)
+++ trunk/rules/TACpoidsPop.java 2013-05-02 16:53:44 UTC (rev 30)
@@ -0,0 +1,372 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2006 - 2011 Ifremer, CodeLutin
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package rules;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import scripts.RuleUtil;
+import scripts.SiMatrix;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+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.TimeStep;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.util.Doc;
+
+/**
+ * TAC peut-etre utilise pour les differents 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 recalcule a chaque mois de janvier.
+ * <li>Pour utiliser la survie il faut mettre dans le parametre propSurvie une
+ * valeur > 0, automatiquement les suvie seront ajoute aux effectifs
+ *
+ * Created:
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.3 $
+ *
+ * Last update: $Date: 010812 $
+ * by : $Author: Loic $
+ */
+public class TACpoidsPop extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog( TACpoidsPop.class);
+
+ // @Doc("Affected species")
+ //public Species param_species = null;
+ @Doc("Affected population")
+ public Population param_population = null;
+ @Doc("Begin date")
+ public TimeStep param_beginStep = new TimeStep(0);
+ @Doc("End date")
+ public TimeStep param_endStep = new TimeStep(90);
+ @Doc("Proportion de survie")
+ public double param_propSurvie = 0;
+ @Doc("Proportionnal TAC")
+ public double param_propTac = 0;
+
+ /** TAC in tonnes */
+ @Doc("TAC in tons")
+ public double param_tacInTons = 900;
+
+ 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
+ */
+ @Override
+ 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
+ */
+ @Override
+ public String getDescription() {
+ return _("TAC weight in tons per population.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0.");
+ }
+
+ /**
+ * Appele au demarrage de la simulation, cette methode permet d'initialiser
+ * des valeurs
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ */
+ @Override
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ @Override
+ public boolean condition(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ log.info("test si TAC atteint");
+ // read species in current session
+ //param_species = (Species) context.getDB().findByTopiaId(
+ //param_species.getTopiaId());
+
+ param_population = (Population) context.getDB().findByTopiaId(
+ param_population.getTopiaId());
+
+ // on fait le calcul du tac si necessaire
+ if (param_propTac > 0 && step.getMonth().equals(Month.JANUARY)) {
+ PopulationMonitor popMon = context.getPopulationMonitor();
+ param_tacInTons = popMon.getBiomass(param_population) * param_propTac;
+ }
+
+ boolean result = false;
+ if (step.before(param_beginStep)) {
+ result = false;
+ } else if (step.after(param_endStep)) {
+ result = false;
+ } else {
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ if (ts != null) {
+ double catchTons = RuleUtil.getTotalCatchTonsPop(context,
+ param_population, step);
+
+ //PopulationMonitor popMon = context.getPopulationMonitor();
+ //double catchTons = popMon.getTotalHoldCatch(param_population); // Rend une matrice (dimensions ??) utiliser getTotalHoldCatch(Population pop) (qui rend un double) a la place ??
+
+ 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 executee avant le pas
+ * de temps de la simulation.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void preAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+ affectation = false;
+
+ log.info("[TAC] preAction for: " + metier);
+ log.info(" TAC atteint [TAC] preAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ if (ts != null && ts.getPrimaryCatch()) {
+ // recupere tous les metiers qui ont l'espece en capture principale =>metiers vises
+ // aimedMetiers ne fonctionne pas je ne sais pas pourquoi ! mais au final forbiddenMetier aura le meme effet
+
+ context.getMetierMonitor().addforbiddenMetier(metier);
+
+ //recupere toutes les strategies pratiquant le metier et pour lesquelles la proportion !=0
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ Set<Strategy> strs = new HashSet<Strategy>();
+ for (Strategy str : siMatrix.getStrategies(step)) {
+ double prop = str.getStrategyMonthInfo(step.getMonth())
+ .getProportionMetier(metier);
+ if (prop != 0) {
+ strs.add(str);
+ }
+ }
+
+ for (Strategy str : strs) {
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(step
+ .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")
+ && !metier.getName().equalsIgnoreCase(
+ "non Activite")
+ && !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 : possibleMetier) {
+ somme += smi.getProportionMetier(met);
+ }
+ for (Metier met : possibleMetier) {
+ 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
+ log.info("[TAC] il y a des metiers possibles");
+ } else {
+ log.info("[TAC] Use no activity");
+
+ // sinon on met tout dans le metier nonActivite
+ MetierMonitor metierMon = context.getMetierMonitor();
+ MatrixND mat = metierMon.getOrCreateNoActivity(step,
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ .getStrategies(step), siMatrix
+ .getMetiers(step));
+ mat.setValue(str, metier, smi.getProportionMetier(metier));
+
+ smi.getProportionMetier().setValue(metier, 0);
+ }
+ }
+ }
+ }
+
+ /**
+ // * Si la condition est vrai alors cette action est executee apres le pas
+ * de temps de la simulation.
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void postAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+ ResultStorage resultmanager = context.getSimulationStorage()
+ .getResultStorage();
+ log.info("[TAC] postAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(step.getMonth())
+ .getSpeciesTargetSpecies(param_population.getSpecies());
+ 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();
+ log.info("popMon biomass" + popMon.getBiomass(param_population)); // A priori on travaille ici sur une pop donnee car on defini le TAC sur une seule pop... Donc pas la peine de boucler sur les populations.
+
+ if (!param_population.getName().equals("param_population_new")) {
+ log.info("param_population : " + param_population.getName());
+ // 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(step, param_population);
+ log.info("discard : " + discard);
+ if (discard != null) {
+ discard.mults(0);
+ }
+ log.info("catch = " + popMon.getCatch(param_population));
+ discard = popMon.getCatch(param_population).copy();
+ // ca ne doit pas pouvoir marcher car MATRIX_DISCARDS_PER_STR_MET est de dimension pop groupe str met - et discard n'a plus la dimension pop
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP);
+ popMon.addDiscard(step, param_population, discard);
+ log.info("[TAC] add discard for " + param_population + ": "
+ + discard);
+ // ne manquerait-il pas
+ resultmanager.addResult(step, param_population, discard);
+ if (param_propSurvie > 0) {
+ MatrixND eff = popMon.getN(param_population);
+ //on rajoute 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;
+ }
+ }
+ }
+
+}
1
0
Author: loic
Date: 2013-05-02 18:53:25 +0200 (Thu, 02 May 2013)
New Revision: 29
Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revision…
Log:
HCR_transition_MSY
Added:
trunk/rules/HCR_transition_MSY.java
Added: trunk/rules/HCR_transition_MSY.java
===================================================================
--- trunk/rules/HCR_transition_MSY.java (rev 0)
+++ trunk/rules/HCR_transition_MSY.java 2013-05-02 16:53:25 UTC (rev 29)
@@ -0,0 +1,337 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2006 - 2011 Ifremer, CodeLutin
+ * %%
+ * 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, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>.
+ * #L%
+ */
+package rules;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+
+import scripts.ResultName;
+import scripts.RuleUtil;
+import scripts.SiMatrix;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+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.Species;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.entities.TargetSpecies;
+import fr.ifremer.isisfish.entities.Zone; // ???????
+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.TimeStep;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.util.Doc;
+
+/**
+ * Le but de cette regle est de permettre de simuler une harvest control rule,
+ * et plus precisemment la transition entre une gestion par approche de precaution
+ * et une gestion par le MSY.
+ *
+ * La premiere annee de transition est 2011 et la derniere 2014, pour une gestion
+ * au MSY des 2015.
+ *
+ *Ici cette regle va s'appliquer a partir de la quatrieme annee de simu (annee initiale=2008)
+ * et a chacune des 4 populations simulees, alors que jusqu'a 2010 on avait un TAC commun pour la plie.
+ *
+ * Created:
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 0.1 $
+ *
+ * Last update: $Date: 131212 $
+ * by : $Author: Loic $
+ */
+public class HCR_transition_MSY extends AbstractRule {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(HCR_transition_MSY.class);
+
+ @Doc("Affected population")
+ public Population param_populationHCR = null;
+ @Doc("Begin date")
+ public TimeStep param_beginStep = new TimeStep(36);
+ @Doc("End date")
+ public TimeStep param_endStep = new TimeStep(119);
+ @Doc("Fmsy")
+ public double param_fmsy = 0.29;
+ @Doc("Fpa")
+ public double param_fpa = 0.4;
+ @Doc("MSY Btrigger")
+ public double param_msyBtrigger = 8000; // Attention aux unites : kg VS t
+ @Doc("Duration of transition period (year)")
+ public double param_transitionDuration = 5;
+ @Doc("Proportion de survie")
+ public double param_propSurvieHCR = 0;
+ @Doc("Variation annuelle max du TAC ")
+ public double param_varTac = 0.15;
+
+ public double Tac2010 = 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,
+ ResultName.MATRIX_BIOMASS,
+ ResultName.MATRIX_TOTAL_FISHING_MORTALITY,
+
+ };
+
+ /**
+ * @return the necessaryResult
+ */
+ @Override
+ 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
+ */
+ @Override
+ public String getDescription() {
+ return _("Harvest Control Rule simulatinf the transition between a precautionary approach management and a MSY management, for a given populaion");
+ }
+
+ /**
+ * Appele au demarrage de la simulation, cette methode permet d'initialiser
+ * des valeurs
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ */
+ @Override
+ public void init(SimulationContext context) throws Exception {
+ }
+
+ /**
+ * La condition qui doit etre vrai pour faire les actions.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ * @return vrai si on souhaite que les actions soit faites
+ */
+ @Override
+ public boolean condition(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ boolean result = false;
+
+ if (step.after(param_beginStep) && step.before(param_endStep) && step.getMonth() == Month.FEBRUARY){ // .previous() // JANUARY ?
+ result = true;
+ }
+ return result;
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est executee avant le pas
+ * de temps de la simulation.
+ *
+ * @param context la simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void preAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+
+ Tac2010 = (Double) context.getValue("tacInTons_" + param_populationHCR.getName() + "_2010");
+ log.info("Tac2010 = " + Tac2010);
+
+ affectation = false;
+
+ log.info("Mise en place de l'HCR");
+
+ ResultStorage matResult = context.getSimulationStorage().getResultStorage();
+
+ // Import de la mortalite par peche de 2010
+ MatrixND MatF2010 = matResult.getMatrix(param_beginStep.previous(), param_populationHCR, ResultName.MATRIX_TOTAL_FISHING_MORTALITY); // Ne marche que si param_beginStep est Janvier 2011
+ double F2010 = MatF2010.sumAll();
+ log.info("F2010 = " + F2010);
+
+ // Import de la biomasse de l'annee en cours
+ MatrixND MatBiom = matResult.getMatrix(step.previous(), param_populationHCR, ResultName.MATRIX_BIOMASS); // step,
+ MatBiom = MatBiom.reduce();
+ log.info("MatBiom = " + MatBiom);
+
+
+ // Calcul de la SSB de l'annee en cours
+ double SSBiom = 0;
+
+ for (MatrixIterator i=MatBiom.iterator(); i.hasNext();) {
+ i.next();
+ Object [] sems = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)sems[0];
+
+ double val = i.getValue()* group.getMaturityOgive();
+
+ SSBiom = SSBiom + val;
+ }
+ SSBiom = SSBiom / 1000;
+ log.info("SSBiom = " + SSBiom);
+
+ // Comparaison de la SSB a MSYBtrigger et calcul de fMsyHcr
+ double fMsyHcr = 0;
+ log.info("param_fmsy = " + param_fmsy);
+
+ if ( SSBiom < param_msyBtrigger) {
+ double triggerMult = 1 - SSBiom / param_msyBtrigger;
+ fMsyHcr = param_fmsy - triggerMult * param_fmsy;
+ }
+ else {
+ fMsyHcr = param_fmsy;
+ }
+ log.info("fMsyHcr = " + fMsyHcr);
+
+ // Calcul des multiplicateurs a appliquer a F2010 et fMsyHCR
+ double multF2010 = 1 - (step.getYear() - (param_beginStep.getYear() - 1)) * (1/param_transitionDuration);
+ if (multF2010 < 0){
+ multF2010 = 0;
+ }
+ double multFmsy = 0 + (step.getYear() - (param_beginStep.getYear() - 1)) * (1/param_transitionDuration);
+ if (multFmsy > 1){
+ multFmsy = 1;
+ }
+ log.info("multF2010 = " + multF2010);
+ log.info("multFmsy = " + multFmsy);
+
+ // Calcul de fMsyHcrTransition
+ double fMsyHcrTransition = multF2010 * F2010 + multFmsy * fMsyHcr;
+ log.info("fMsyHcrTransition = " + fMsyHcrTransition);
+
+ // Si fMsyHcrTransition > fpa on applique fpa
+ double AppliedF = 0;
+ log.info("param_fpa = " + param_fpa);
+
+ if (fMsyHcrTransition < param_fpa) {
+ AppliedF = fMsyHcrTransition;
+ }
+ else {
+ AppliedF = param_fpa;
+ }
+ log.info("AppliedF = " + AppliedF);
+
+ // Calcul du niveau de captures correspondant au F choisi
+ double TAC = AppliedF * SSBiom;
+ log.info("TAC = " + TAC);
+
+ // Si niveau de captures inferieur de plus de 15 pcts au TAC de l'annee precedente limiter a 15 pcts
+ double diffTac = 0;
+ double TacReel = 0;
+ double TacPrevYr = 0;
+
+ if (step.getYear() == param_beginStep.getYear()){
+ diffTac = TAC / Tac2010 - 1;
+ log.info("diffTac = " + diffTac);
+ if (diffTac < -1 * param_varTac){
+ TacReel = Tac2010 - param_varTac * Tac2010;
+ }
+ else if (diffTac >= param_varTac){
+ TacReel = Tac2010 + param_varTac * Tac2010;
+ }
+ else {
+ TacReel = TAC;
+ }
+ }
+ else {
+ // retrouver le niveau de TAC de l'annee precedente
+ TacPrevYr = (Double) context.getValue("TAC_" + param_populationHCR.getName() + "_HCR");
+ log.info("TacPrevYr = " + TacPrevYr);
+ diffTac = TAC / TacPrevYr - 1;
+ log.info("diffTac = " + diffTac);
+ if (diffTac < -1 * param_varTac){
+ TacReel = TacPrevYr - param_varTac * TacPrevYr;
+ }
+ else if (diffTac >= param_varTac){
+ TacReel = TacPrevYr + param_varTac * TacPrevYr;
+ }
+ else {
+ TacReel = TAC;
+ }
+ }
+ log.info("TacReel = " + TacReel);
+
+ // Stocker le TAC dans une matrice (pour pouvoir comparer les annees entre elles)
+
+ // Faire en sorte que le TAC soit utilise par la regle TACPoidsPop_PourHCR
+ context.setValue("TAC_" + param_populationHCR.getName() + "_HCR", TacReel); //TacReel
+ context.setValue("BeginStep_TAC_" + param_populationHCR.getName() + "_HCR", step); // Pas besoin de EndStep car on sait que c'est BeginStep+12 (mis dans regle TAC)
+ //context.setValue("Population_TAC_HCR", param_populationHCR);
+ context.setValue("PropSurvie_TAC_" + param_populationHCR.getName() + "_HCR", param_propSurvieHCR);
+
+ }
+
+ /**
+ // * Si la condition est vrai alors cette action est executee apres le pas
+ * de temps de la simulation.
+ *
+ * @param context La simulation pour lequel on utilise cette regle
+ * @param step le pas de temps courant
+ * @param metier le metier concerne
+ */
+ @Override
+ public void postAction(SimulationContext context, TimeStep step, Metier metier)
+ throws Exception {
+ // Creation de la matrice de stockage de TAC
+ //ResultStorage resultmanager = context.getSimulationStorage().getResultStorage();
+ //
+ // if (!affectation){
+ //
+ // // Ici les TACs sont definis au niveau de la population
+ // public MatrixND matrixTacPop(TimeStep step, Population pop) throws TopiaException { // ResultStorage resManager ?
+ //
+ // List<Population> populations = Collections.singletonList(pop);
+ //
+ // MatrixND TacPopMatrix = MatrixFactory.getInstance().create(
+ // ResultName.MATRIX_TAC_PER_POP, new List[] { populations },
+ // new String[] { n_("Populations") });
+ //
+ // if (step.getMonth() == Month.JANUARY) { // Pas besoin car postAction ne s'applique que si la condition est vraie
+ // TacPopMatrix.setValue(param_population, TacReel);
+ // }
+ // else {
+ // TacPopMatrix.setValue(param_population, 0);
+ // }
+ // return TacPopMatrix;
+ // }
+ // // on a affecte une fois un TAC a une pop et il ne faut pas le refaire
+ // affectation = true;
+ // }
+ //}
+ }
+
+}
1
0