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
- 322 discussions
Author: echatellier
Date: 2015-04-21 12:44:34 +0000 (Tue, 21 Apr 2015)
New Revision: 354
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/354
Log:
Prepare next iteration
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2015-04-21 09:20:26 UTC (rev 353)
+++ trunk/pom.xml 2015-04-21 12:44:34 UTC (rev 354)
@@ -74,7 +74,7 @@
<dependency>
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.4.0.0-rc-1-SNAPSHOT</version>
+ <version>4.4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
1
0
21 Apr '15
Author: echatellier
Date: 2015-04-21 09:20:26 +0000 (Tue, 21 Apr 2015)
New Revision: 353
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/353
Log:
fixes #6194: changement reproduction/recrutement
Modified:
trunk/pom.xml
trunk/scripts/SiMatrix.java
trunk/simulators/DefaultSimulator.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2015-04-16 16:43:41 UTC (rev 352)
+++ trunk/pom.xml 2015-04-21 09:20:26 UTC (rev 353)
@@ -74,7 +74,7 @@
<dependency>
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.4.0.0-SNAPSHOT</version>
+ <version>4.4.0.0-rc-1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2015-04-16 16:43:41 UTC (rev 352)
+++ trunk/scripts/SiMatrix.java 2015-04-21 09:20:26 UTC (rev 353)
@@ -29,7 +29,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -1351,7 +1350,6 @@
//log.info("Recruitment_1 = " + RecruitmentMatrix);
// Pour chaque pas de temps on recupere le recrutement
-
RecruitmentMatrix.setValue(pop, context.getPopulationMonitor().getRecruitment(step, pop).sumAll());
//log.info("RecruitmentMatrix_2 = " + RecruitmentMatrix);
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2015-04-16 16:43:41 UTC (rev 352)
+++ trunk/simulators/DefaultSimulator.java 2015-04-21 09:20:26 UTC (rev 353)
@@ -382,8 +382,8 @@
// N is reassigned during computation
resManager.addResult(step, pop, N);
+ MatrixND biomass = siMatrix.matrixBiomass(N, pop, step);
if (resManager.isEnabled(ResultName.MATRIX_BIOMASS)) {
- MatrixND biomass = siMatrix.matrixBiomass(N, pop, step);
resManager.addResult(step, pop, biomass);
}
@@ -433,7 +433,7 @@
// ajout de la matrice R dans le suivi de la pop comme etant
// la reproduction pour le mois courant.
- popMon.setReproduction(step, pop, R);
+ popMon.setReproduction(step, pop, N, biomass, R);
// recrutement
MatrixND recruitment = popMon.getRecruitment(step, pop);
1
0
r352 - in trunk: exports scripts sensitivityexports simulators
by echatellier@users.forge.codelutin.com 16 Apr '15
by echatellier@users.forge.codelutin.com 16 Apr '15
16 Apr '15
Author: echatellier
Date: 2015-04-16 16:43:41 +0000 (Thu, 16 Apr 2015)
New Revision: 352
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/352
Log:
Add Lbar and recruitment exports
Added:
trunk/exports/Lbar.java
trunk/exports/Recruitment.java
trunk/sensitivityexports/SensitivityLbarJanvierY1.java
trunk/sensitivityexports/SensitivityRecruitmentY1.java
Modified:
trunk/scripts/ResultName.java
trunk/scripts/SiMatrix.java
trunk/scripts/SiMatrixEffortByCell.java
trunk/simulators/DefaultSimulator.java
Added: trunk/exports/Lbar.java
===================================================================
--- trunk/exports/Lbar.java (rev 0)
+++ trunk/exports/Lbar.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -0,0 +1,90 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2015 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 3 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-3.0.html>.
+ * #L%
+ */
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.nuiton.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+
+/**
+ * Population mean length.
+ *
+ * Created: 03/2015
+ *
+ * @author lgasche <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision$
+ */
+public class Lbar implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Lbar.class);
+
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_LBAR
+ };
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "Lbar";
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Exporte les longueurs moyennes par pop par zone en tableau avec des lignes pop;zone;date;longueur.";
+ }
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_LBAR);
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sems = i.getSemanticsCoordinates();
+ TimeStep step = (TimeStep) sems[0];
+ Zone zone = (Zone) sems[1];
+
+ double val = i.getValue();
+ out.write(pop.getName() + ";" + zone.getName() + ";" + step.getStep() + ";" + val + "\n");
+ }
+ }
+ }
+}
Property changes on: trunk/exports/Lbar.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/exports/Recruitment.java
===================================================================
--- trunk/exports/Recruitment.java (rev 0)
+++ trunk/exports/Recruitment.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -0,0 +1,89 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2015 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 3 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-3.0.html>.
+ * #L%
+ */
+package exports;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Writer;
+
+import org.nuiton.math.matrix.*;
+
+import scripts.ResultName;
+
+import fr.ifremer.isisfish.entities.*;
+import fr.ifremer.isisfish.export.Export;
+import fr.ifremer.isisfish.types.TimeStep;
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+
+/**
+ * Recruitment.
+ *
+ * Created: 03/2015
+ *
+ * @author lgasche <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision$
+ */
+public class Recruitment implements Export {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(Recruitment.class);
+
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_RECRUITMENT
+ };
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "Recruitment";
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Exporte le recrutement par pop par en tableau avec des lignes pop;date;recrutement.";
+ }
+
+ @Override
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_RECRUITMENT);
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
+ i.next();
+ Object[] sems = i.getSemanticsCoordinates();
+ TimeStep step = (TimeStep) sems[0];
+
+ double val = i.getValue();
+ out.write(pop.getName() + ";" + step.getStep() + ";" + val + "\n");
+ }
+ }
+ }
+}
Property changes on: trunk/exports/Recruitment.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/scripts/ResultName.java
===================================================================
--- trunk/scripts/ResultName.java 2014-12-22 10:19:18 UTC (rev 351)
+++ trunk/scripts/ResultName.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin
+ * Copyright (C) 2006 - 2015 Ifremer, Code Lutin, Cedric 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
@@ -112,7 +112,7 @@
* Dimension 4 : Group
* Dimension 5 : Zone
*
- * N'est calculé que si l'effort est calculé par cellule et non par zone.
+ * N'est calcule que si l'effort est calcule par cellule et non par zone.
* @see simulators.SimulatorEffortByCell
*/
@Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet")
@@ -137,7 +137,7 @@
* Dimension 4 : Group
* Dimension 5 : Zone
*
- * N'est calculé que si l'effort est calculé par cellule et non par zone.
+ * N'est calcule que si l'effort est calcule par cellule et non par zone.
* @see simulators.SimulatorEffortByCell
*/
@Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet")
@@ -188,6 +188,21 @@
*/
@Doc(value = "do the doc of Result matrixAbundance")
static final public String MATRIX_ABUNDANCE = n("matrixAbundance");
+
+ /**
+ * Matrix with two dimensions
+ * Dimension 1 : TimeStep
+ * Dimension 2 : Zone (semantics : Dimension 1)
+ */
+ @Doc(value = "do the doc of Result matrixLbar")
+ static final public String MATRIX_LBAR = n("matrixLbar");
+
+ /**
+ * Matrix with one dimension
+ * Dimension 1 : TimeStep
+ */
+ @Doc(value = "do the doc of Result matrixRecruitment")
+ static final public String MATRIX_RECRUITMENT = n("matrixRecruitment");
/**
* Matrix with three dimensions
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2014-12-22 10:19:18 UTC (rev 351)
+++ trunk/scripts/SiMatrix.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Benjamin Poussin
+ * Copyright (C) 2006 - 2015 Ifremer, 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
@@ -273,7 +273,6 @@
* @param N l'abondance sous forme de matrice 2D [class x zone]
* @param pop
* @param step
- * @param matrixCatchRatePerStrategyMet
* @return
* @throws TopiaException
* @throws IsisFishException
@@ -306,7 +305,6 @@
*
* @param pop
* @param step
- * @param matrixFishingMortality
* @return
* @throws TopiaException
* @throws IsisFishException
@@ -894,7 +892,6 @@
* @param N
* @param pop
* @param step
- * @param matrixFishingMortality
* @return
* @throws IsisFishException
* @throws TopiaException
@@ -1289,4 +1286,76 @@
return result;
}
+
+ /**
+ * Permet de calculer la longueur moyenne (Lbar) d'une population.
+ *
+ * @param step
+ * @param pop
+ * @param N
+ * @return
+ */
+ public MatrixND Lbar(TimeStep step, Population pop, MatrixND N) throws TopiaException {
+ MatrixND LbarMatrix = N.copy();
+ LbarMatrix.setName(ResultName.MATRIX_LBAR);
+ //log.info("Lbar_1 = " + LbarMatrix);
+
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+
+ // On multiplie l'abondance de chaque groupe par la taille de ce groupe
+
+ // On somme sur les groupes
+
+ // On utilise divise la valeur obtenue par l'abondance totale
+
+ for (PopulationGroup group : groups) {
+ for (Zone zn : zones) {
+ LbarMatrix.setValue(group, zn, LbarMatrix.getValue(group, zn) * group.getLength());
+ }
+ }
+
+ LbarMatrix = LbarMatrix.sumOverDim(0); // Somme sur les groupes
+ LbarMatrix = LbarMatrix.reduce();
+ //log.info("LbarMatrix_2 = " + LbarMatrix);
+
+ MatrixND matAB = N.copy();
+ matAB = matAB.sumOverDim(0);
+ matAB = matAB.reduce();
+ //log.info("matAB = " + matAB);
+
+ for (Zone zn : zones) {
+ LbarMatrix.setValue(zn, LbarMatrix.getValue(zn) / matAB.getValue(zn));
+ }
+
+ //log.info("LbarMatrix_3 = " + LbarMatrix);
+
+ return LbarMatrix;
+ }
+
+ /**
+ * Permet de sortir le recrutement par pas de temps.
+ * @param step
+ * @param pop
+ * @return
+ */
+ public MatrixND Recruitment(TimeStep step, Population pop) throws TopiaException {
+
+ List<Population> populations = Collections.singletonList(pop);
+
+ MatrixND RecruitmentMatrix = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_RECRUITMENT,
+ new List[]{populations}, //
+ new String[]{n("Population")});
+
+ //log.info("Recruitment_1 = " + RecruitmentMatrix);
+
+ // Pour chaque pas de temps on recupere le recrutement
+
+ RecruitmentMatrix.setValue(pop, context.getPopulationMonitor().getRecruitment(step, pop).sumAll());
+
+ //log.info("RecruitmentMatrix_2 = " + RecruitmentMatrix);
+
+ return RecruitmentMatrix;
+ }
}
Modified: trunk/scripts/SiMatrixEffortByCell.java
===================================================================
--- trunk/scripts/SiMatrixEffortByCell.java 2014-12-22 10:19:18 UTC (rev 351)
+++ trunk/scripts/SiMatrixEffortByCell.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -1,3 +1,24 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2015 Ifremer, 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 3 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-3.0.html>.
+ * #L%
+ */
package scripts;
import static org.nuiton.i18n.I18n.n;
@@ -28,8 +49,6 @@
import org.nuiton.math.matrix.MatrixND;
import org.nuiton.topia.TopiaException;
-import static org.nuiton.i18n.I18n.n;
-
/**
*
* @author poussin
@@ -498,9 +517,7 @@
* metier
*
* @param step
- * @param matrixFishingMortality
- * @param group
- * @param zone
+ * @param matrixFishingMortalityPerCell
* @return
*/
protected MatrixND totalFishingMortalityPerCell(TimeStep step,
Added: trunk/sensitivityexports/SensitivityLbarJanvierY1.java
===================================================================
--- trunk/sensitivityexports/SensitivityLbarJanvierY1.java (rev 0)
+++ trunk/sensitivityexports/SensitivityLbarJanvierY1.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2015 Ifremer, Code Lutin
+ * %%
+ * 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 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 SensitivityLbarJanvierY1 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(SensitivityLbarJanvierY1.class);
+
+ protected String[] necessaryResult = { ResultName.MATRIX_LBAR };
+
+ @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 lbar = 0.0;
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+
+ //Get the lbar of the last time step
+ MatrixND matlastJan = resultStorage.getMatrix(janvierLastYear, pop,
+ ResultName.MATRIX_LBAR);
+ MatrixND meanLastJan = matlastJan.meanOverDim(0); // moyenne sur les zones
+ lbar = meanLastJan.sumAll(); // On somme tout mais en fait il n'y a plus qu'une valeur dans la matrice; permet d'avoir un double
+ }
+ }
+ out.write(Double.toString(lbar));
+ }
+
+ @Override
+ public String getDescription() {
+ return "lbar for January of the last year. lbar is the mean lbar over zones";
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityLbarJanvierY1_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
Property changes on: trunk/sensitivityexports/SensitivityLbarJanvierY1.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/sensitivityexports/SensitivityRecruitmentY1.java
===================================================================
--- trunk/sensitivityexports/SensitivityRecruitmentY1.java (rev 0)
+++ trunk/sensitivityexports/SensitivityRecruitmentY1.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -0,0 +1,94 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2015 Ifremer, Code Lutin
+ * %%
+ * 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 3 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-3.0.html>.
+ * #L%
+ */
+package sensitivityexports;
+
+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 SensitivityRecruitmentY1 implements SensitivityExport {
+
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory.getLog(SensitivityRecruitmentY1.class);
+
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_RECRUITMENT
+ };
+
+ @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 recruitment = 0.0;
+
+ for (Population pop : simulation.getParameter().getPopulations()) {
+ if (pop.getName().equals(param_pop.getName())) {
+ for (int i = 0; i < 12; i++) {
+
+ //Get the recruitment of each month of the last year
+ MatrixND matlastdate = resultStorage.getMatrix(
+ new TimeStep(lastStep.getStep() - i),
+ pop,
+ ResultName.MATRIX_RECRUITMENT);
+ recruitment += matlastdate.sumAll();
+ }
+ }
+ }
+
+ out.write(Double.toString(recruitment));
+ }
+
+ @Override
+ public String getDescription() {
+ return "Total recruitment for the last year for the population.";
+ }
+
+ @Override
+ public String getExportFilename() {
+ return "SensitivityRecruitmentY1_" + param_pop.getName();
+ }
+
+ @Override
+ public String getExtensionFilename() {
+ return ".csv";
+ }
+
+ @Override
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+}
Property changes on: trunk/sensitivityexports/SensitivityRecruitmentY1.java
___________________________________________________________________
Added: svn:eol-style
+ native
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2014-12-22 10:19:18 UTC (rev 351)
+++ trunk/simulators/DefaultSimulator.java 2015-04-16 16:43:41 UTC (rev 352)
@@ -1,9 +1,8 @@
-
/*
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2006 - 2015 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, 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
@@ -457,6 +456,16 @@
resManager.addResult(step, pop, biomassBM);
}
+ if (resManager.isEnabled(ResultName.MATRIX_LBAR)) {
+ MatrixND Lbar = siMatrix.Lbar(step, pop, N);
+ resManager.addResult(step, pop, Lbar);
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_RECRUITMENT)) {
+ MatrixND Recruitment = siMatrix.Recruitment(step, pop);
+ resManager.addResult(step, pop, Recruitment);
+ }
+
MatrixND abundance;
// compute fishing matrix only if there are one or more strategy
if (siMatrix.getStrategies(step).size() > 0) {
1
0
Author: bpoussin
Date: 2014-12-22 10:19:18 +0000 (Mon, 22 Dec 2014)
New Revision: 351
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/351
Log:
- remove dbResult transaction commit (no more needed with ResultStorageCSV)
- change TimeStep before rollback to permit export of database
Modified:
trunk/simulators/DefaultSimulator.java
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2014-12-18 12:20:31 UTC (rev 350)
+++ trunk/simulators/DefaultSimulator.java 2014-12-22 10:19:18 UTC (rev 351)
@@ -102,7 +102,7 @@
TimeStep step = control.getStep();
ResultManager resManager = context.getResultManager();
- TopiaContext db = context.getDB();
+ TopiaContext db = context.getDB(); // for database init
SiMatrix siMatrix = newSiMatrix(context);
GravityModel gravityModel = newGravityModel(context, siMatrix);
@@ -137,7 +137,7 @@
//
// Commit all change done un init rules methods.
//
- context.getDB().commitTransaction();
+ context.validateDBChanges();
//
// Simulation loop
@@ -174,9 +174,9 @@
if (siMatrix.getStrategies(step).size() > 0) {
if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
MatrixND mat = metierMonitor.getOrCreateNoActivity(step,
- ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
.getStrategies(step), siMatrix
- .getMetiers(step));
+ .getMetiers(step));
resManager.addResult(step, mat);
}
}
@@ -214,7 +214,7 @@
for (Rule rule : rules) {
for (Metier metier : siMatrix.getMetiers(step)) {
boolean condition = ruleMonitor.getEvalutionCondition(step,
- rule, metier);
+ rule, metier);
if (condition) {
rule.preAction(context, step, metier);
}
@@ -343,22 +343,17 @@
}
//
- // revert modification for next step
+ // Go next step
//
- control.setText("Rollback rules changes");
- db.rollbackTransaction();
+ // do next before rollbackTransaction to permit export to take
+ // current database value and export them.
+ step = step.next();
//
- // commit result
+ // revert modification for next step
//
- control.setText("Commit results");
- TopiaContext tx = context.getDbResult();
- tx.commitTransaction();
-
- //
- // Go next step
- //
- step = step.next();
+ control.setText("Rollback rules changes");
+ context.rollbackRuleChanges();
}
}
1
0
Author: bpoussin
Date: 2014-12-18 12:20:31 +0000 (Thu, 18 Dec 2014)
New Revision: 350
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/350
Log:
fixes #6322: Change DefaultSimulator, SiMatrix and GravityModel to permit easy overwrite method to create new simulator
Added:
trunk/scripts/SiMatrixEffortByCell.java
Modified:
trunk/scripts/SiMatrix.java
trunk/simulators/DefaultSimulator.java
trunk/simulators/SimulatorEffortByCell.java
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2014-12-03 15:48:52 UTC (rev 349)
+++ trunk/scripts/SiMatrix.java 2014-12-18 12:20:31 UTC (rev 350)
@@ -79,9 +79,11 @@
protected SimulationContext context = null;
protected TopiaContext db = null;
+ protected ResultManager resManager;
/**
- * Method used to get SiMatrix used for simulation
+ * Method used to get SiMatrix used for simulation, before call this method
+ * new SiMatrix must called
*
* @param context
* context simulation
@@ -91,9 +93,6 @@
public static SiMatrix getSiMatrix(SimulationContext context)
throws TopiaException {
SiMatrix result = (SiMatrix) context.getValue(SiMatrix.class.getName());
- if (result == null) {
- result = new SiMatrix(context);
- }
return result;
}
@@ -110,10 +109,23 @@
public SiMatrix(SimulationContext context) throws TopiaException {
this.context = context;
this.db = context.getDB();
+ this.resManager = context.getResultManager();
setSiMatrix(context, this);
}
/**
+ * This method permit to add some specific computation for specific Simulator.
+ * example use in SiMatrixEffortByCell
+ *
+ * @param step
+ * @param pop
+ * @param N
+ * @throws IsisFishException
+ */
+ public void computeMonthExtra(TimeStep step, Population pop, MatrixND N) throws TopiaException, IsisFishException {
+ }
+
+ /**
* @return
* @throws TopiaException
*/
@@ -244,107 +256,6 @@
//
///////////////////////////////////////////////////////////////////////////
- public MatrixND matrixCatchWeightPerStrategyMetPerZoneMet(TimeStep step,
- Population pop, MatrixND matrixCatchPerStrategyMetPerZoneMet)
- throws TopiaException, IsisFishException {
-
- return matrixToWeightMatrix(step, 2,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET,
- matrixCatchPerStrategyMetPerZoneMet);
-
-// List<PopulationGroup> groups = pop.getPopulationGroup();
-//
-// MatrixND result = matrixCatchPerStrategyMetPerZoneMet.copy();
-// result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET);
-//
-// for (PopulationGroup group : groups) {
-// MatrixND sub = result.getSubMatrix(2, group, 1);
-// double meanWeight = group.getMeanWeight();
-// sub.mults(meanWeight);
-// }
-//
-// return result;
- }
-
- public MatrixND matrixCatchPerStrategyMetPerZoneMet(MatrixND N,
- Population pop, TimeStep step) throws TopiaException, IsisFishException {
-
- MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(
- step, pop);
- MatrixND matrixCatchRatePerStrategyMetPerCell = matrixCatchRatePerStrategyMetPerCell(
- pop, step, matrixFishingMortalityPerCell);
- MatrixND matrixCatchPerStrategyMetPerCell = matrixCatchPerStrategyMetPerCell(
- N, pop, step, matrixCatchRatePerStrategyMetPerCell);
-
- List<Strategy> strategies = getStrategies(step);
- List<Metier> metiers = getMetiers(step);
- List<PopulationGroup> groups = (List<PopulationGroup>)matrixCatchPerStrategyMetPerCell
- .getSemantic(2);
- List<Zone> zones = getZones(step);
-
- Set<Cell> cellPops = new HashSet(matrixCatchPerStrategyMetPerCell
- .getSemantic(4));
-
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET,
- new List[] { strategies, metiers, groups, zones },
- new String[] { n("Strategies"), n("Metiers"), n("Groups"),
- n("Zones") });
-
- // matrice temporaire ou les zones pops sont sommees
- MatrixND tmp = matrixCatchPerStrategyMetPerCell.sumOverDim(3);
- tmp = tmp.reduceDims(3);
-
- for (int s = 0; s < strategies.size(); s++) {
- Strategy str = strategies.get(s);
- for (int g = 0; g < groups.size(); g++) {
- PopulationGroup group = groups.get(g);
- // on iter que sur les metiers qui ont une proportion non 0
- // car la matrice pour les autres metiers, contient 0.
- List<Metier> metiersNot0 = getMetiers(str, step);
- for (int m = 0; m < metiersNot0.size(); m++) {
- Metier metier = metiersNot0.get(m);
- MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(step
- .getMonth());
- Collection<Zone> zoneMet = infoMet.getZone();
- for (Zone z : zoneMet) {
- double value = 0;
- List<Cell> cells = z.getCell();
- for (int c = 0; c < cells.size(); c++) {
- Cell cell = cells.get(c);
- if (cellPops.contains(cell)) {
- // les cells de la matrice sont les cells des
- // zones pops, donc seul les intersections avec
- // les cells des metiers sont des cells valides
- value += tmp.getValue(str, metier, group, cell);
- }
- }
- result.setValue(str, metier, group, z, value);
- }
- }
- }
- }
-
- return result;
- }
-
- public MatrixND matrixCatchPerStrategyMetPerZonePop(MatrixND N,
- Population pop, TimeStep step) throws TopiaException, IsisFishException {
- MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(
- step, pop);
- MatrixND matrixCatchRatePerStrategyMetPerCell = matrixCatchRatePerStrategyMetPerCell(
- pop, step, matrixFishingMortalityPerCell);
- MatrixND matrixCatchPerStrategyMetPerCell = matrixCatchPerStrategyMetPerCell(
- N, pop, step, matrixCatchRatePerStrategyMetPerCell);
-
- // on somme sur les cellules
- MatrixND result = matrixCatchPerStrategyMetPerCell.sumOverDim(4);
- result = result.reduceDims(4);
- result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
-
- return result;
- }
-
public MatrixND matrixCatchWeightPerStrategyMetPerZonePop(TimeStep step,
Population pop, MatrixND matrixCatchPerStrategyMetPerZonePop)
throws TopiaException, IsisFishException {
@@ -352,19 +263,6 @@
return matrixToWeightMatrix(step, 2,
ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP,
matrixCatchPerStrategyMetPerZonePop);
-
-// List<PopulationGroup> groups = pop.getPopulationGroup();
-//
-// MatrixND result = matrixCatchPerStrategyMetPerZonePop.copy();
-// result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
-//
-// for (PopulationGroup group : groups) {
-// MatrixND sub = result.getSubMatrix(2, group, 1);
-// double meanWeight = group.getMeanWeight();
-// sub.mults(meanWeight);
-// }
-//
-// return result;
}
/**
@@ -381,9 +279,11 @@
* @throws IsisFishException
*/
public MatrixND matrixCatchPerStrategyMetPerZone(MatrixND N,
- Population pop, TimeStep step, MatrixND matrixCatchRatePerStrategyMet)
+ Population pop, TimeStep step)
throws TopiaException, IsisFishException {
+ MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMetPerZone(pop, step);
+
int dimGroup = 2;
int dimZone = 3;
@@ -398,21 +298,6 @@
}
return result;
-// List<PopulationGroup> groups = pop.getPopulationGroup();
-// List<Zone> zones = pop.getPopulationZone();
-//
-// MatrixND result = matrixCatchRatePerStrategyMet.copy();
-// result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
-//
-// 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;
}
/**
@@ -426,9 +311,11 @@
* @throws TopiaException
* @throws IsisFishException
*/
- public MatrixND matrixCatchRatePerStrategyMetPerZone(Population pop,
- TimeStep step, MatrixND matrixFishingMortality) throws TopiaException,
+ public MatrixND matrixCatchRatePerStrategyMetPerZone(Population pop, TimeStep step) throws TopiaException,
IsisFishException {
+
+ MatrixND matrixFishingMortality = matrixFishingMortality(step, pop);
+
List<Strategy> strategies = getStrategies(step);
List<Metier> metiers = getMetiers(step);
List<PopulationGroup> groups = pop.getPopulationGroup();
@@ -462,6 +349,7 @@
}
}
}
+ resManager.addResult(step, pop, result);
return result;
}
@@ -490,8 +378,44 @@
return result;
}
+ /**
+ * @param str
+ * @param metier
+ * @param step
+ * @return
+ */
+ protected double effortPerStrategyPerCell(Strategy str, Metier metier,
+ MetierSeasonInfo infoMet, TimeStep step) {
+ //StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ Collection<Zone> zones = infoMet.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()) {
+ Month month = step.getMonth();
+ 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, step);
+
+ if (log.isDebugEnabled()) {
+ log.debug(" strategy=" + str + " metier=" + metier + " nbCell="
+ + nbCell + " effortPerStrategy=" + effortPerStrategy);
+ }
+
+ double result = effortPerStrategy / nbCell;
+
+ return result;
+ }
+
// Optimisation Hilaire
- private double catchRatePerStrategyMet(Strategy str, Metier metier,
+ protected double catchRatePerStrategyMet(Strategy str, Metier metier,
TimeStep step, PopulationGroup group, Zone zone,
MatrixND matrixFishingMortality) throws TopiaException,
IsisFishException {
@@ -567,83 +491,6 @@
return result;
}
-// /**
-// * Matrice fishing mortality dim [ Strategy x Metier x Classe x zonePop ]
-// *
-// * @param pop
-// * @param step
-// * @return
-// * @throws TopiaException
-// * @throws IsisFishException
-// */
-// public MatrixND matrixFishingMortality(TimeStep step, Population pop)
-// throws TopiaException, IsisFishException {
-// List<Strategy> strategies = getStrategies(step);
-// List<Metier> metiers = getMetiers(step);
-// 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 = step.getMonth();
-// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
-//
-// 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
-// double capturability = infoPop.getCapturability(group);
-// 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);
-//
-// MetierSeasonInfo infoMet = metier
-// .getMetierSeasonInfo(month);
-// // getTargetFactor seem to be simple
-// double ciblage = infoMet.getTargetFactor(group);
-//
-// if (ciblage != 0) { // check 0, this prevent next call, for default value
-//
-// Gear gear = metier.getGear();
-// Selectivity selectivity = gear
-// .getPopulationSelectivity(pop);
-// if (selectivity != null) {
-//
-// // getCoefficient is equation evaluation
-// double coeff = selectivity.getCoefficient(pop,
-// group, metier);
-// 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, infoMet, step, zone);
-// if (effort > 0) { // put value only if <> 0
-// double value = coeff
-// * capturability * ciblage
-// * effort;
-// result.setValue(str, metier, group,
-// zone, value);
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// return result;
-// }
-
/**
* Matrice fishing mortality dim [ Strategy x Metier x Classe x zonePop ]
*
@@ -730,519 +577,16 @@
}
}
}
+ resManager.addResult(step, pop, result);
return result;
}
-
/**
- * 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 step
- * @return
- * @throws TopiaException
- * @throws IsisFishException
- */
- private MatrixND matrixCatchPerStrategyMetPerCell(MatrixND N,
- Population pop, TimeStep step,
- MatrixND matrixCatchRatePerStrategyMetPerCell)
- throws TopiaException, IsisFishException {
- int groupDim = 2;
- int zoneDim = 3;
-
- int NGroupDim = 0;
- int NZoneDim = 1;
-
- MatrixND result = matrixCatchRatePerStrategyMetPerCell.copy();
- result.setName("matrixCatchPerStrategyMetPerCell");
-
- List<PopulationGroup> groups = (List<PopulationGroup>)result.getSemantic(groupDim);
- List<Zone> zones = (List<Zone>)result.getSemantic(zoneDim);
-
- double[] sizeCell = new double[zones.size()];
- int cpt = 0;
- for (Zone z : zones) {
- sizeCell[cpt++] = z.sizeCell();
- }
-
- // on suppose que les semantics de N et matrixCatchRatePerStrategyMetPerCell
- // pour les PopulationGroup et Zone sont les memes
- // mais on verifie tout de meme
- if (groups.equals(N.getSemantic(NGroupDim)) &&
- zones.equals(N.getSemantic(NZoneDim))) {
-
- // on place les effectifs dans un tableau pour un acces rapide
- // on divise directement par le nombre de cell de la zone pour eviter
- // de le faire beaucoup plus souvent dans l'autre boucle
- double[][] NArray = new double[groups.size()][zones.size()];
- for (MatrixIterator i=N.iteratorNotZero(); i.next();) {
- int[] pos = i.getCoordinates();
- double val = i.getValue();
-
- NArray[pos[NGroupDim]][pos[NZoneDim]] = val / sizeCell[pos[NZoneDim]];
- }
-
- // calcul de la matrice resultat
- for (MatrixIterator i=result.iteratorNotZero(); i.next();) {
- int[] pos = i.getCoordinates();
- double val = i.getValue();
- val *= NArray[pos[groupDim]][pos[zoneDim]];
- i.setValue(val);
- }
-
- } else {
- // N et matrixCatchRatePerStrategyMetPerCell non pas les meme semantics
- // on fait moins rapide
- for (MatrixIterator i=result.iteratorNotZero(); i.next();) {
- int[] pos = i.getCoordinates();
- Object[] sems = i.getSemanticsCoordinates();
- PopulationGroup group = (PopulationGroup)sems[groupDim];
- Zone zone = (Zone)sems[zoneDim];
- double val = i.getValue();
- val *= N.getValue(group, zone) / sizeCell[pos[zoneDim]];
- i.setValue(val);
- }
- }
-
- return result;
-
-// List<PopulationGroup> groups = pop.getPopulationGroup();
-// List<Zone> zones = pop.getPopulationZone();
-//
-// MatrixND result = matrixCatchRatePerStrategyMetPerCell.copy();
-// result.setName("matrixCatchPerStrategyMetPerCell");
-//
-// 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) / (double) zone.sizeCell();
-// subsub.mults(val);
-// }
-// }
-// return result;
- }
-
- /**
- * Matrice des captures en poids dim [ Strategy x Metier x Classe x zonePop ]
- *
- * @param pop
- * @param step
- * @return
- * @throws TopiaException
- * @throws IsisFishException
- */
- private MatrixND matrixCatchRatePerStrategyMetPerCell(Population pop,
- TimeStep step, MatrixND matrixFishingMortalityPerCell)
- throws TopiaException, IsisFishException {
-
- MatrixND totalFishingMortalityPerCell = totalFishingMortalityPerCell(
- step, matrixFishingMortalityPerCell);
-
- MatrixND result = matrixFishingMortalityPerCell.copy();
- result.setName("matrixCatchRatePerStrategyMetPerCell");
-
- for (MatrixIterator i=result.iteratorNotZero(); i.next();) {
- Object[] sems = i.getSemanticsCoordinates();
-
- PopulationGroup group = (PopulationGroup)sems[2];
- Zone zone = (Zone)sems[3];
- Cell cell = (Cell)sems[4];
-
- double totalFishingMortality = totalFishingMortalityPerCell.getValue(
- group, zone, cell);
-
- if (totalFishingMortality != 0) {
-
- double fishingMortalityPerCell = i.getValue();
- double totalCatchRatePerCell = totalCatchRatePerCell(step, group, zone,
- totalFishingMortality);
-
- double value = fishingMortalityPerCell / totalFishingMortality
- * totalCatchRatePerCell;
-
- i.setValue(value);
- }
- }
-
- return result;
-
-
-// List<Strategy> strategies = getStrategies(step);
-// List<Metier> metiers = getMetiers(step);
-// List<PopulationGroup> groups = pop.getPopulationGroup();
-// List<Zone> zones = pop.getPopulationZone();
-// List<Cell> cells = getCells(zones);
-//
-// MatrixND result = MatrixFactory.getInstance().create(
-// "matrixCatchRatePerStrategyMetPerCell",
-// new List[] { strategies, metiers, groups, zones, cells },
-// new String[] { n("Strategies"), n("Metiers"), n("Groups"),
-// n("Zones"), n("Cells") });
-//
-// // Optimisation Hilaire
-// MatrixND matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCell
-// .sumOverDim(2);
-// matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCellSumOverGroup
-// .reduceDims(2);
-//
-// for (int s = 0; s < strategies.size(); s++) {
-// Strategy str = strategies.get(s);
-// metiers = getMetiers(str, step);
-// 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);
-// List<Cell> cellZones = zone.getCell();
-// for (int c = 0; c < cellZones.size(); c++) {
-// Cell cell = cellZones.get(c);
-// double effort = matrixFishingMortalityPerCellSumOverGroup
-// .getValue(str, metier, zone, cell);
-// if (effort > 0) {
-// for (int g = 0; g < groups.size(); g++) {
-// PopulationGroup group = groups.get(g);
-// double value = catchRatePerStrategyMetPerCell(
-// str, metier, step, group, zone, cell,
-// matrixFishingMortalityPerCell);
-// result.setValue(new Object[] { str, metier,
-// group, zone, cell }, value);
-// }
-// }
-// }
-// }
-// }
-// }
-//
-// return result;
- }
-// directement dans matrixCatchRatePerStrategyMetPerCell pour pouvoir mieux optimiser
-// /**
-// * catchRatePerStrategyMetPerCell.
-// *
-// * Optimisation Hilaire
-// *
-// * @param str
-// * @param metier
-// * @param step
-// * @param group
-// * @param zone
-// * @param cell
-// * @param matrixFishingMortalityPerCell
-// * @return
-// * @throws TopiaException
-// * @throws IsisFishException
-// */
-// private double catchRatePerStrategyMetPerCell(Strategy str, Metier metier,
-// TimeStep step, PopulationGroup group, Zone zone, Cell cell,
-// MatrixND matrixFishingMortalityPerCell) throws TopiaException,
-// IsisFishException {
-//
-// MatrixND totalFishingMortalityPerCell = totalFishingMortalityPerCell(
-// step, matrixFishingMortalityPerCell);
-// double totalFishingMortality = totalFishingMortalityPerCell.getValue(
-// group, zone, cell);
-//
-// if (totalFishingMortality == 0) {
-// if (log.isDebugEnabled()) {
-// log.debug("pas de totalFishingMortality pour (" + group + ", "
-// + zone + ")");
-// }
-// return 0;
-// }
-//
-// double fishingMortalityPerCell = matrixFishingMortalityPerCell
-// .getValue(new Object[] { str, metier, group, zone, cell });
-// double totalCatchRatePerCell = totalCatchRatePerCell(step, group, zone,
-// totalFishingMortality);
-//
-// if (log.isDebugEnabled()) {
-// log.debug(" totalFishingMortality=" + totalFishingMortality
-// + " fishingMortality=" + fishingMortalityPerCell
-// + " totalCatchRate=" + totalCatchRatePerCell);
-// }
-// double result = fishingMortalityPerCell / totalFishingMortality
-// * totalCatchRatePerCell;
-//
-// return result;
-// }
-
- /**
- * @param step
- * @param group
- * @param zone
- * @param totalFishingMortality
- * @return
- * @throws TopiaException
- */
- private double totalCatchRatePerCell(TimeStep step, PopulationGroup group,
- Zone zone, double totalFishingMortalityPerCell)
- 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 mortalite naturelle pour: " + group);
- }
- }
- double F = totalFishingMortalityPerCell;
-
- 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 step
- * @param matrixFishingMortality
- * @param group
- * @param zone
- * @return
- */
- private MatrixND totalFishingMortalityPerCell(TimeStep step,
- MatrixND matrixFishingMortalityPerCell) {
- MatrixND result = matrixFishingMortalityPerCell.sumOverDim(0);
- result = result.sumOverDim(1);
- result = result.reduceDims(0, 1);
- return result;
- }
-
-// /**
-// * Matrice fishing mortality dim [ Strategy x Metier x Classe x zonePop x
-// * cellPop]
-// *
-// * Nouvelle implantation suite a demande Steph et Sigrid: 20080208 (NouvellesEquationsfev2008ParCelluleAvecAlgo.odt)
-// *
-// * @param pop
-// * @param step
-// * @return
-// * @throws TopiaException
-// * @throws IsisFishException
-// */
-// public MatrixND matrixFishingMortalityPerCell(TimeStep step, Population pop)
-// throws TopiaException, IsisFishException {
-// List<Strategy> strategies = getStrategies(step);
-// List<Metier> metiers = getMetiers(step);
-// List<PopulationGroup> groups = pop.getPopulationGroup();
-// List<Zone> zones = pop.getPopulationZone();
-// List<Cell> cells = getCells(zones);
-//
-// // default value in matrix is 0
-// MatrixND result = MatrixFactory.getInstance().create(
-// "matrixFishingMortalityPerCell",
-// new List[] { strategies, metiers, groups, zones, cells },
-// new String[] { n("Strategies"), n("Metiers"), n("Groups"),
-// n("Zones"), n("Cells") });
-//
-// Month month = step.getMonth();
-// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
-//
-// 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
-// double capturability = infoPop.getCapturability(group);
-// 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);
-//
-// MetierSeasonInfo infoMet = metier
-// .getMetierSeasonInfo(month);
-// // getTargetFactor seem to be simple
-// double ciblage = infoMet.getTargetFactor(group);
-//
-// if (ciblage != 0) { // check 0, this prevent next call, for default value
-//
-// Gear gear = metier.getGear();
-// Selectivity selectivity = gear.getPopulationSelectivity(pop);
-// if (selectivity != null) {
-//
-// // getCoefficient is equation evaluation
-// double coeff = selectivity.getCoefficient(pop,group, metier);
-// 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);
-// // l'effort d'une cellule du metier
-// double effort = effortPerStrategyPerCell(
-// str, metier, infoMet, step);
-// if (effort > 0) { // put value only if <> 0
-// for (int z = 0; z < zones.size(); z++) {
-// Zone zone = zones.get(z);
-// Set<Cell> cellPops = new HashSet<Cell>(zone.getCell());
-// for (Cell cellMet : infoMet.getCells()) {
-// if (cellPops.contains(cellMet)) {
-// double value = coeff * capturability * ciblage * effort;
-// result.setValue(
-// new Object[] { str,
-// metier,
-// group,
-// zone,
-// cellMet },
-// value);
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// return result;
-// }
-//
-
- /**
- * Matrice fishing mortality dim [ Strategy x Metier x Classe x zonePop x
- * cellPop]
- *
- * Nouvelle implantation suite a demande Steph et Sigrid: 20080208 (NouvellesEquationsfev2008ParCelluleAvecAlgo.odt)
- *
- * @param pop
- * @param step
- * @return
- * @throws TopiaException
- * @throws IsisFishException
- */
- public MatrixND matrixFishingMortalityPerCell(TimeStep step, Population pop)
- throws TopiaException, IsisFishException {
- List<Strategy> strategies = getStrategies(step);
- List<Metier> metiers = getMetiers(step);
- List<PopulationGroup> groups = pop.getPopulationGroup();
- List<Zone> zones = pop.getPopulationZone();
- List<Cell> cells = getCells(zones);
-
- // default value in matrix is 0
- MatrixND result = MatrixFactory.getInstance().create(
- "matrixFishingMortalityPerCell",
- new List[] { strategies, metiers, groups, zones, cells },
- new String[] { n("Strategies"), n("Metiers"), n("Groups"),
- n("Zones"), n("Cells") });
-
- Month month = step.getMonth();
- PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
-
- for (Strategy str : strategies) {
- StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
- double nbTrip = smi.getNumberOfTrips();
- double propSetOfVessels = str.getProportionSetOfVessels();
- int nbOfVessels = str.getSetOfVessels().getNumberOfVessels();
-
- // dans le calcul de l'effort si une de ces donnees est 0
- // alors le result dans la matrice est 0
- // donc autant ne pas faire tous les autres calculs couteux
- if (nbTrip * propSetOfVessels * nbOfVessels != 0) {
- for (PopulationGroup group : groups) {
-
- // 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
-
- // et de la meme facon si la proportion est 0 alors
- // le resultat dans la matrice sera 0, donc on boucle que
- // sur ceux qui ont une proportion
- List<Metier> metiersNot0 = getMetiers(str, step);
- for (Metier metier : metiersNot0) {
-
- MetierSeasonInfo infoMet = metier
- .getMetierSeasonInfo(month);
- // getTargetFactor seem to be simple
- double ciblage = infoMet.getTargetFactor(group);
-
- if (ciblage != 0) { // check 0, this prevent next call, for default value
-
- Gear gear = metier.getGear();
- Selectivity selectivity = gear.getPopulationSelectivity(pop);
- if (selectivity != null) {
-
- // getCoefficient is equation evaluation
- double coeff = selectivity.getCoefficient(pop,group, metier);
- if (coeff != 0) { // check 0, this prevent next call, for default value
-
- // l'effort d'une cellule du metier
- double effort = effortPerStrategyPerCell(
- str, metier, infoMet, step);
- if (effort > 0) { // put value only if <> 0
- for (Zone zone : zones) {
- Set<Cell> cellPops = new HashSet<Cell>(zone.getCell());
- for (Cell cellMet : infoMet.getCells()) {
- if (cellPops.contains(cellMet)) {
- double value = coeff * capturability * ciblage * effort;
- result.setValue(
- new Object[] { str,
- metier,
- group,
- zone,
- cellMet },
- value);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result;
- }
-
- /**
* @param str
* @param metier
* @param step
* @return
*/
- private double effortPerStrategyPerCell(Strategy str, Metier metier,
- MetierSeasonInfo infoMet, TimeStep step) {
- //StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
- Collection<Zone> zones = infoMet.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()) {
- Month month = step.getMonth();
- 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, step);
-
- if (log.isDebugEnabled()) {
- log.debug(" strategy=" + str + " metier=" + metier + " nbCell="
- + nbCell + " effortPerStrategy=" + effortPerStrategy);
- }
-
- double result = effortPerStrategy / nbCell;
-
- return result;
- }
-
- /**
- * @param str
- * @param metier
- * @param step
- * @return
- */
private double effortNominalPerStrategyMet(Strategy str, Metier metier, TimeStep step) {
Month month = step.getMonth();
StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
@@ -1303,7 +647,7 @@
* @param step
* @return
*/
- private double effortPerStrategyMet(Strategy str, Metier metier, TimeStep step) {
+ protected double effortPerStrategyMet(Strategy str, Metier metier, TimeStep step) {
Month month = step.getMonth();
StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
@@ -1545,71 +889,6 @@
///////////////////////////////////////////////////////////////////////////
/**
- * @param N
- * @param pop
- * @param step
- * @return
- * @throws IsisFishException
- * @throws TopiaException
- */
- private MatrixND matrixAbundancePerCell(MatrixND N, Population pop,
- TimeStep step, MatrixND matrixFishingMortality) throws TopiaException,
- IsisFishException {
-
- List<PopulationGroup> groups = pop.getPopulationGroup();
- List<Zone> zones = pop.getPopulationZone();
- List<Cell> allCells = getCells(zones);
-
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_ABUNDANCE + "_PER_CELL",
- new List[] { groups, zones, allCells },
- new String[] { n("Groups"), n("Zones"), n("Cells") });
-
- 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);
- List<Cell> cells = zone.getCell();
- for (int c = 0; c < cells.size(); c++) {
- Cell cell = cells.get(c);
- double value = survivalRatePerCell(step, group, zone, cell,
- matrixFishingMortality);
- double n = N.getValue(g, z) / zone.sizeCell();
- value *= n;
- result.setValue(g, z, c, value);
- }
- }
- }
-
- return result;
- }
-
- /**
- * Utilise pour le calcule en Cell.
- *
- * @param N
- * @param pop
- * @param step
- * @return
- * @throws IsisFishException
- * @throws TopiaException
- */
- public MatrixND matrixAbundance(MatrixND N, Population pop, TimeStep step)
- throws TopiaException, IsisFishException {
-
- MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(
- step, pop);
-
- MatrixND result = matrixAbundancePerCell(N, pop, step,
- matrixFishingMortalityPerCell);
- result = result.sumOverDim(2);
- result = result.reduceDims(2);
- result.setName(ResultName.MATRIX_ABUNDANCE);
-
- return result;
- }
-
- /**
* Utilise pour le calcule en Zone.
*
* @param N
@@ -1620,9 +899,11 @@
* @throws IsisFishException
* @throws TopiaException
*/
- public MatrixND matrixAbundance(MatrixND N, Population pop, TimeStep step,
- MatrixND matrixFishingMortality) throws TopiaException,
+ public MatrixND matrixAbundance(MatrixND N, Population pop, TimeStep step) throws TopiaException,
IsisFishException {
+
+ MatrixND matrixFishingMortality = matrixFishingMortality(step, pop);
+
List<PopulationGroup> groups = pop.getPopulationGroup();
List<Zone> zones = pop.getPopulationZone();
@@ -1690,7 +971,7 @@
* @throws IsisFishException
* @throws TopiaException
*/
- private double survivalRatePerZone(TimeStep step, PopulationGroup group,
+ protected double survivalRatePerZone(TimeStep step, PopulationGroup group,
Zone zone, MatrixND matrixFishingMortality) throws TopiaException,
IsisFishException {
double F = totalFishingMortality(step, matrixFishingMortality)
@@ -1702,27 +983,6 @@
return result;
}
- /**
- * @param step
- * @param group
- * @param zone
- * @return
- * @throws IsisFishException
- * @throws TopiaException
- */
- private double survivalRatePerCell(TimeStep step, PopulationGroup group,
- Zone zone, Cell cell, MatrixND matrixFishingMortalityPerCell)
- throws TopiaException, IsisFishException {
-
- double F = totalFishingMortalityPerCell(step,
- matrixFishingMortalityPerCell).getValue(group, zone, cell); //totalFishingMortality(step, group, zone); // rem perf: totalFishingMortality a deja ete calcule
- double M = group.getNaturalDeathRate(zone)
- / (double) Month.NUMBER_OF_MONTH;
- double result = (double) Math.exp(-(F + M));
-
- return result;
- }
-
///////////////////////////////////////////////////////////////////////////
//
//
Added: trunk/scripts/SiMatrixEffortByCell.java
===================================================================
--- trunk/scripts/SiMatrixEffortByCell.java (rev 0)
+++ trunk/scripts/SiMatrixEffortByCell.java 2014-12-18 12:20:31 UTC (rev 350)
@@ -0,0 +1,514 @@
+package scripts;
+
+import static org.nuiton.i18n.I18n.n;
+
+import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.entities.Cell;
+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.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.types.TimeStep;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixFactory;
+import org.nuiton.math.matrix.MatrixIterator;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.topia.TopiaException;
+
+import static org.nuiton.i18n.I18n.n;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class SiMatrixEffortByCell extends SiMatrix {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(SiMatrixEffortByCell.class);
+
+ public SiMatrixEffortByCell(SimulationContext context) throws TopiaException {
+ super(context);
+ }
+
+ @Override
+ public void computeMonthExtra(TimeStep step, Population pop, MatrixND N) throws TopiaException, IsisFishException {
+ MatrixND catchPerStrategyMetPerZoneMet =
+ matrixCatchPerStrategyMetPerZoneMet(N, pop, step);
+ resManager.addResult(step, pop, catchPerStrategyMetPerZoneMet);
+
+ if (resManager
+ .isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET)) {
+ MatrixND catchWeightPerStrategyMet =
+ matrixCatchWeightPerStrategyMetPerZoneMet(step,
+ pop, catchPerStrategyMetPerZoneMet);
+ resManager.addResult(step, pop, catchWeightPerStrategyMet);
+ }
+ }
+
+ protected MatrixND matrixCatchWeightPerStrategyMetPerZoneMet(TimeStep step,
+ Population pop, MatrixND matrixCatchPerStrategyMetPerZoneMet)
+ throws TopiaException, IsisFishException {
+
+ return matrixToWeightMatrix(step, 2,
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET,
+ matrixCatchPerStrategyMetPerZoneMet);
+ }
+
+ protected MatrixND matrixCatchPerStrategyMetPerZoneMet(MatrixND N,
+ Population pop, TimeStep step) throws TopiaException, IsisFishException {
+
+ MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(
+ step, pop);
+ MatrixND matrixCatchRatePerStrategyMetPerCell = matrixCatchRatePerStrategyMetPerCell(
+ pop, step, matrixFishingMortalityPerCell);
+ MatrixND matrixCatchPerStrategyMetPerCell = matrixCatchPerStrategyMetPerCell(
+ N, pop, step, matrixCatchRatePerStrategyMetPerCell);
+
+ List<Strategy> strategies = getStrategies(step);
+ List<Metier> metiers = getMetiers(step);
+ List<PopulationGroup> groups = (List<PopulationGroup>)matrixCatchPerStrategyMetPerCell
+ .getSemantic(2);
+ List<Zone> zones = getZones(step);
+
+ Set<Cell> cellPops = new HashSet(matrixCatchPerStrategyMetPerCell
+ .getSemantic(4));
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET,
+ new List[] { strategies, metiers, groups, zones },
+ new String[] { n("Strategies"), n("Metiers"), n("Groups"),
+ n("Zones") });
+
+ // matrice temporaire ou les zones pops sont sommees
+ MatrixND tmp = matrixCatchPerStrategyMetPerCell.sumOverDim(3);
+ tmp = tmp.reduceDims(3);
+
+ for (int s = 0; s < strategies.size(); s++) {
+ Strategy str = strategies.get(s);
+ for (int g = 0; g < groups.size(); g++) {
+ PopulationGroup group = groups.get(g);
+ // on iter que sur les metiers qui ont une proportion non 0
+ // car la matrice pour les autres metiers, contient 0.
+ List<Metier> metiersNot0 = getMetiers(str, step);
+ for (int m = 0; m < metiersNot0.size(); m++) {
+ Metier metier = metiersNot0.get(m);
+ MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(step
+ .getMonth());
+ Collection<Zone> zoneMet = infoMet.getZone();
+ for (Zone z : zoneMet) {
+ double value = 0;
+ List<Cell> cells = z.getCell();
+ for (int c = 0; c < cells.size(); c++) {
+ Cell cell = cells.get(c);
+ if (cellPops.contains(cell)) {
+ // les cells de la matrice sont les cells des
+ // zones pops, donc seul les intersections avec
+ // les cells des metiers sont des cells valides
+ value += tmp.getValue(str, metier, group, cell);
+ }
+ }
+ result.setValue(str, metier, group, z, value);
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+
+ @Override
+ public MatrixND matrixCatchPerStrategyMetPerZone(MatrixND N,
+ Population pop, TimeStep step) throws TopiaException, IsisFishException {
+ MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(
+ step, pop);
+ MatrixND matrixCatchRatePerStrategyMetPerCell = matrixCatchRatePerStrategyMetPerCell(
+ pop, step, matrixFishingMortalityPerCell);
+ MatrixND matrixCatchPerStrategyMetPerCell = matrixCatchPerStrategyMetPerCell(
+ N, pop, step, matrixCatchRatePerStrategyMetPerCell);
+
+ // on somme sur les cellules
+ MatrixND result = matrixCatchPerStrategyMetPerCell.sumOverDim(4);
+ result = result.reduceDims(4);
+ result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
+
+ return result;
+ }
+
+
+ /**
+ * Utilise pour le calcule en Cell.
+ *
+ * @param N
+ * @param pop
+ * @param step
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ @Override
+ public MatrixND matrixAbundance(MatrixND N, Population pop, TimeStep step)
+ throws TopiaException, IsisFishException {
+
+ MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(
+ step, pop);
+
+ MatrixND result = matrixAbundancePerCell(N, pop, step,
+ matrixFishingMortalityPerCell);
+ result = result.sumOverDim(2);
+ result = result.reduceDims(2);
+ result.setName(ResultName.MATRIX_ABUNDANCE);
+
+ return result;
+ }
+
+ /**
+ * @param N
+ * @param pop
+ * @param step
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ protected MatrixND matrixAbundancePerCell(MatrixND N, Population pop,
+ TimeStep step, MatrixND matrixFishingMortality) throws TopiaException,
+ IsisFishException {
+
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+ List<Cell> allCells = getCells(zones);
+
+ MatrixND result = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_ABUNDANCE + "_PER_CELL",
+ new List[] { groups, zones, allCells },
+ new String[] { n("Groups"), n("Zones"), n("Cells") });
+
+ 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);
+ List<Cell> cells = zone.getCell();
+ for (int c = 0; c < cells.size(); c++) {
+ Cell cell = cells.get(c);
+ double value = survivalRatePerCell(step, group, zone, cell,
+ matrixFishingMortality);
+ double n = N.getValue(g, z) / zone.sizeCell();
+ value *= n;
+ result.setValue(g, z, c, value);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * @param step
+ * @param group
+ * @param zone
+ * @return
+ * @throws IsisFishException
+ * @throws TopiaException
+ */
+ protected double survivalRatePerCell(TimeStep step, PopulationGroup group,
+ Zone zone, Cell cell, MatrixND matrixFishingMortalityPerCell)
+ throws TopiaException, IsisFishException {
+
+ double F = totalFishingMortalityPerCell(step,
+ matrixFishingMortalityPerCell).getValue(group, zone, cell); //totalFishingMortality(step, group, zone); // rem perf: totalFishingMortality a deja ete calcule
+ double M = group.getNaturalDeathRate(zone)
+ / (double) Month.NUMBER_OF_MONTH;
+ double result = (double) Math.exp(-(F + M));
+
+ return result;
+ }
+
+ /**
+ * Matrice fishing mortality dim [ Strategy x Metier x Classe x zonePop x
+ * cellPop]
+ *
+ * Nouvelle implantation suite a demande Steph et Sigrid: 20080208 (NouvellesEquationsfev2008ParCelluleAvecAlgo.odt)
+ *
+ * @param pop
+ * @param step
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ protected MatrixND matrixFishingMortalityPerCell(TimeStep step, Population pop)
+ throws TopiaException, IsisFishException {
+ List<Strategy> strategies = getStrategies(step);
+ List<Metier> metiers = getMetiers(step);
+ List<PopulationGroup> groups = pop.getPopulationGroup();
+ List<Zone> zones = pop.getPopulationZone();
+ List<Cell> cells = getCells(zones);
+
+ // default value in matrix is 0
+ MatrixND result = MatrixFactory.getInstance().create(
+ "matrixFishingMortalityPerCell",
+ new List[] { strategies, metiers, groups, zones, cells },
+ new String[] { n("Strategies"), n("Metiers"), n("Groups"),
+ n("Zones"), n("Cells") });
+
+ Month month = step.getMonth();
+ PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month);
+
+ for (Strategy str : strategies) {
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(month);
+ double nbTrip = smi.getNumberOfTrips();
+ double propSetOfVessels = str.getProportionSetOfVessels();
+ int nbOfVessels = str.getSetOfVessels().getNumberOfVessels();
+
+ // dans le calcul de l'effort si une de ces donnees est 0
+ // alors le result dans la matrice est 0
+ // donc autant ne pas faire tous les autres calculs couteux
+ if (nbTrip * propSetOfVessels * nbOfVessels != 0) {
+ for (PopulationGroup group : groups) {
+
+ // 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
+
+ // et de la meme facon si la proportion est 0 alors
+ // le resultat dans la matrice sera 0, donc on boucle que
+ // sur ceux qui ont une proportion
+ List<Metier> metiersNot0 = getMetiers(str, step);
+ for (Metier metier : metiersNot0) {
+
+ MetierSeasonInfo infoMet = metier
+ .getMetierSeasonInfo(month);
+ // getTargetFactor seem to be simple
+ double ciblage = infoMet.getTargetFactor(group);
+
+ if (ciblage != 0) { // check 0, this prevent next call, for default value
+
+ Gear gear = metier.getGear();
+ Selectivity selectivity = gear.getPopulationSelectivity(pop);
+ if (selectivity != null) {
+
+ // getCoefficient is equation evaluation
+ double coeff = selectivity.getCoefficient(pop,group, metier);
+ if (coeff != 0) { // check 0, this prevent next call, for default value
+
+ // l'effort d'une cellule du metier
+ double effort = effortPerStrategyPerCell(
+ str, metier, infoMet, step);
+ if (effort > 0) { // put value only if <> 0
+ for (Zone zone : zones) {
+ Set<Cell> cellPops = new HashSet<Cell>(zone.getCell());
+ for (Cell cellMet : infoMet.getCells()) {
+ if (cellPops.contains(cellMet)) {
+ // Reduction d'effort (generic):
+ double effortReduction = getEffortReduction(step, gear, cellMet);
+
+ double value = (1.0 - effortReduction) * coeff * capturability * ciblage * effort;
+ result.setValue(
+ new Object[] { str,
+ metier,
+ group,
+ zone,
+ cellMet },
+ value);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ protected double getEffortReduction(TimeStep step, Gear gear, Cell cellMet) {
+ return 0.0;
+ }
+
+ /**
+ * 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 step
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ protected MatrixND matrixCatchPerStrategyMetPerCell(MatrixND N,
+ Population pop, TimeStep step,
+ MatrixND matrixCatchRatePerStrategyMetPerCell)
+ throws TopiaException, IsisFishException {
+ int groupDim = 2;
+ int zoneDim = 3;
+
+ int NGroupDim = 0;
+ int NZoneDim = 1;
+
+ MatrixND result = matrixCatchRatePerStrategyMetPerCell.copy();
+ result.setName("matrixCatchPerStrategyMetPerCell");
+
+ List<PopulationGroup> groups = (List<PopulationGroup>)result.getSemantic(groupDim);
+ List<Zone> zones = (List<Zone>)result.getSemantic(zoneDim);
+
+ double[] sizeCell = new double[zones.size()];
+ int cpt = 0;
+ for (Zone z : zones) {
+ sizeCell[cpt++] = z.sizeCell();
+ }
+
+ // on suppose que les semantics de N et matrixCatchRatePerStrategyMetPerCell
+ // pour les PopulationGroup et Zone sont les memes
+ // mais on verifie tout de meme
+ if (groups.equals(N.getSemantic(NGroupDim)) &&
+ zones.equals(N.getSemantic(NZoneDim))) {
+
+ // on place les effectifs dans un tableau pour un acces rapide
+ // on divise directement par le nombre de cell de la zone pour eviter
+ // de le faire beaucoup plus souvent dans l'autre boucle
+ double[][] NArray = new double[groups.size()][zones.size()];
+ for (MatrixIterator i=N.iteratorNotZero(); i.next();) {
+ int[] pos = i.getCoordinates();
+ double val = i.getValue();
+
+ NArray[pos[NGroupDim]][pos[NZoneDim]] = val / sizeCell[pos[NZoneDim]];
+ }
+
+ // calcul de la matrice resultat
+ for (MatrixIterator i=result.iteratorNotZero(); i.next();) {
+ int[] pos = i.getCoordinates();
+ double val = i.getValue();
+ val *= NArray[pos[groupDim]][pos[zoneDim]];
+ i.setValue(val);
+ }
+
+ } else {
+ // N et matrixCatchRatePerStrategyMetPerCell non pas les meme semantics
+ // on fait moins rapide
+ for (MatrixIterator i=result.iteratorNotZero(); i.next();) {
+ int[] pos = i.getCoordinates();
+ Object[] sems = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup)sems[groupDim];
+ Zone zone = (Zone)sems[zoneDim];
+ double val = i.getValue();
+ val *= N.getValue(group, zone) / sizeCell[pos[zoneDim]];
+ i.setValue(val);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Matrice des captures en poids dim [ Strategy x Metier x Classe x zonePop ]
+ *
+ * @param pop
+ * @param step
+ * @return
+ * @throws TopiaException
+ * @throws IsisFishException
+ */
+ protected MatrixND matrixCatchRatePerStrategyMetPerCell(Population pop,
+ TimeStep step, MatrixND matrixFishingMortalityPerCell)
+ throws TopiaException, IsisFishException {
+
+ MatrixND totalFishingMortalityPerCell = totalFishingMortalityPerCell(
+ step, matrixFishingMortalityPerCell);
+
+ MatrixND result = matrixFishingMortalityPerCell.copy();
+ result.setName("matrixCatchRatePerStrategyMetPerCell");
+
+ for (MatrixIterator i=result.iteratorNotZero(); i.next();) {
+ Object[] sems = i.getSemanticsCoordinates();
+
+ PopulationGroup group = (PopulationGroup)sems[2];
+ Zone zone = (Zone)sems[3];
+ Cell cell = (Cell)sems[4];
+
+ double totalFishingMortality = totalFishingMortalityPerCell.getValue(
+ group, zone, cell);
+
+ if (totalFishingMortality != 0) {
+
+ double fishingMortalityPerCell = i.getValue();
+ double totalCatchRatePerCell = totalCatchRatePerCell(step, group, zone,
+ totalFishingMortality);
+
+ double value = fishingMortalityPerCell / totalFishingMortality
+ * totalCatchRatePerCell;
+
+ i.setValue(value);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * @param step
+ * @param group
+ * @param zone
+ * @param totalFishingMortality
+ * @return
+ * @throws TopiaException
+ */
+ private double totalCatchRatePerCell(TimeStep step, PopulationGroup group,
+ Zone zone, double totalFishingMortalityPerCell)
+ 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 mortalite naturelle pour: " + group);
+ }
+ }
+ double F = totalFishingMortalityPerCell;
+
+ 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 step
+ * @param matrixFishingMortality
+ * @param group
+ * @param zone
+ * @return
+ */
+ protected MatrixND totalFishingMortalityPerCell(TimeStep step,
+ MatrixND matrixFishingMortalityPerCell) {
+ MatrixND result = matrixFishingMortalityPerCell.sumOverDim(0);
+ result = result.sumOverDim(1);
+ result = result.reduceDims(0, 1);
+ return result;
+ }
+
+}
Property changes on: trunk/scripts/SiMatrixEffortByCell.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2014-12-03 15:48:52 UTC (rev 349)
+++ trunk/simulators/DefaultSimulator.java 2014-12-18 12:20:31 UTC (rev 350)
@@ -22,8 +22,8 @@
*/
package simulators;
-import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.IsisFishException;
+import fr.ifremer.isisfish.datastore.StorageException;
import fr.ifremer.isisfish.entities.Metier;
import fr.ifremer.isisfish.entities.Population;
import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
@@ -70,6 +70,27 @@
static private Log log = LogFactory.getLog(DefaultSimulator.class);
/**
+ * When you create new simulator with specific SiMatrix you must
+ * overwrite this method to return you SiMatrix version
+ * @param context
+ * @return
+ */
+ protected SiMatrix newSiMatrix(SimulationContext context) throws TopiaException {
+ return new SiMatrix(context);
+ }
+
+ /**
+ * When you create new simulator with specific GravityModel you must
+ * overwrite this method to return you GravityModel version
+ * @param context
+ * @param siMatrix
+ * @return
+ */
+ protected GravityModel newGravityModel(SimulationContext context, SiMatrix siMatrix) throws TopiaException, StorageException {
+ return new GravityModel(context, siMatrix);
+ }
+
+ /**
* Called by isis don't modify signature
*/
public void simulate(SimulationContext context) throws Exception {
@@ -83,8 +104,8 @@
ResultManager resManager = context.getResultManager();
TopiaContext db = context.getDB();
- SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
- GravityModel gravityModel = new GravityModel(context, siMatrix);
+ SiMatrix siMatrix = newSiMatrix(context);
+ GravityModel gravityModel = newGravityModel(context, siMatrix);
PopulationMonitor populationMonitor = context.getPopulationMonitor();
MetierMonitor metierMonitor = context.getMetierMonitor();
@@ -449,30 +470,10 @@
// this matrix is necessary for PopulationMonitor.holdCatch (reused in rule)
MatrixND catchPerStrategyMetPerZonePop;
- if (isEffortByCell(context)) {
- abundance = siMatrix.matrixAbundance(N, pop, step);
- catchPerStrategyMetPerZonePop = siMatrix
- .matrixCatchPerStrategyMetPerZonePop(N, pop, step);
- } else { // en zone
- MatrixND matrixFishingMortality = siMatrix
- .matrixFishingMortality(step, pop);
- resManager.addResult(step, pop, matrixFishingMortality);
+ abundance = siMatrix.matrixAbundance(N, pop, step);
+ catchPerStrategyMetPerZonePop = siMatrix
+ .matrixCatchPerStrategyMetPerZone(N, pop, step);
- abundance = siMatrix.matrixAbundance(N, pop, step,
- matrixFishingMortality);
-
- // this matrix is necessary for matrixCatchPerStrategyMet
- MatrixND catchRatePerStrategyMet = siMatrix
- .matrixCatchRatePerStrategyMetPerZone(pop, step,
- matrixFishingMortality);
- resManager.addResult(step, pop, catchRatePerStrategyMet);
-
- catchPerStrategyMetPerZonePop = siMatrix
- .matrixCatchPerStrategyMetPerZone(N, pop, step,
- catchRatePerStrategyMet);
-
- }
-
popMon.holdCatch(pop, catchPerStrategyMetPerZonePop);
resManager.addResult(step, pop, catchPerStrategyMetPerZonePop);
@@ -484,35 +485,24 @@
resManager.addResult(step, pop, catchWeightPerStrategyMet);
}
- if (isEffortByCell(context)) {
- MatrixND catchPerStrategyMetPerZoneMet = siMatrix
- .matrixCatchPerStrategyMetPerZoneMet(N, pop, step);
- resManager.addResult(step, pop, catchPerStrategyMetPerZoneMet);
-
- if (resManager
- .isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET)) {
- MatrixND catchWeightPerStrategyMet = siMatrix
- .matrixCatchWeightPerStrategyMetPerZoneMet(step,
- pop, catchPerStrategyMetPerZoneMet);
- resManager.addResult(step, pop, catchWeightPerStrategyMet);
- }
- }
-
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP) ||
resManager.isEnabled(ResultName.MATRIX_TOTAL_FISHING_MORTALITY)) {
- MatrixND fishingMortalityPerGroup = siMatrix.fishingMortalityPerGroup(step,
- pop, context.getResultManager());
+ MatrixND fishingMortalityPerGroup = siMatrix.fishingMortalityPerGroup(
+ step, pop, context.getResultManager());
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP)) {
resManager.addResult(step, pop, fishingMortalityPerGroup);
}
if (resManager.isEnabled(ResultName.MATRIX_TOTAL_FISHING_MORTALITY)) {
- MatrixND totalFishingMortality = siMatrix.totalFishingMortality(step, pop, fishingMortalityPerGroup);
+ MatrixND totalFishingMortality = siMatrix.totalFishingMortality(
+ step, pop, fishingMortalityPerGroup);
resManager.addResult(step, pop, totalFishingMortality);
}
}
+ siMatrix.computeMonthExtra(step, pop, N);
+
} else { // no strategies
// compute only if fishing mortality =0 to apply Natural Mortality
abundance = siMatrix.matrixAbundanceSsF(N, pop, step);
Modified: trunk/simulators/SimulatorEffortByCell.java
===================================================================
--- trunk/simulators/SimulatorEffortByCell.java 2014-12-03 15:48:52 UTC (rev 349)
+++ trunk/simulators/SimulatorEffortByCell.java 2014-12-18 12:20:31 UTC (rev 350)
@@ -26,29 +26,25 @@
import org.apache.commons.logging.LogFactory;
import fr.ifremer.isisfish.simulator.SimulationContext;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.Simulator;
+import scripts.SiMatrix;
+import scripts.SiMatrixEffortByCell;
+import org.nuiton.topia.TopiaException;
+
/**
* Simulateur qui fixe la valeur de effortByCell a true pour force
* l'utilisation des calculs par cellule plutot que par zone.
*
* @author poussin
*/
-public class SimulatorEffortByCell implements Simulator {
+public class SimulatorEffortByCell extends DefaultSimulator {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(SimulatorEffortByCell.class);
- /**
- * Called by isis don't modify signature
- */
- public void simulate(SimulationContext context) throws Exception {
- SimulationParameter param = context.getSimulationStorage().getParameter();
- param.getTagValue().put("effortByCell", "true");
-
- DefaultSimulator simulator = new DefaultSimulator();
- simulator.simulate(context);
+ @Override
+ protected SiMatrix newSiMatrix(SimulationContext context) throws TopiaException {
+ return new SiMatrixEffortByCell(context);
}
}
1
0
Author: echatellier
Date: 2014-12-03 15:48:52 +0000 (Wed, 03 Dec 2014)
New Revision: 349
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/349
Log:
Update versions
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-11-10 15:48:58 UTC (rev 348)
+++ trunk/pom.xml 2014-12-03 15:48:52 UTC (rev 349)
@@ -14,7 +14,7 @@
<packaging>jar</packaging>
<!--Version -->
- <version>4.3.2-SNAPSHOT</version>
+ <version>4.4.0-SNAPSHOT</version>
<!--Description -->
<description>Data for Isis-fish</description>
@@ -36,7 +36,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
+ <version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
@@ -49,7 +49,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
- <version>1.3.1</version>
+ <version>1.3.2</version>
<executions>
<execution>
<goals>
@@ -74,7 +74,7 @@
<dependency>
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.3.2.0-SNAPSHOT</version>
+ <version>4.4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
1
0
Author: kmorin
Date: 2014-11-10 15:48:58 +0000 (Mon, 10 Nov 2014)
New Revision: 348
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/348
Log:
- upgrade isis-fish dependency version
- merge Sigrid's modification on DefaultSimulator
Modified:
trunk/pom.xml
trunk/simulators/DefaultSimulator.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-11-05 17:49:27 UTC (rev 347)
+++ trunk/pom.xml 2014-11-10 15:48:58 UTC (rev 348)
@@ -74,7 +74,7 @@
<dependency>
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.3.1.1-SNAPSHOT</version>
+ <version>4.3.2.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2014-11-05 17:49:27 UTC (rev 347)
+++ trunk/simulators/DefaultSimulator.java 2014-11-10 15:48:58 UTC (rev 348)
@@ -1,3 +1,4 @@
+
/*
* #%L
* IsisFish data
@@ -21,6 +22,7 @@
*/
package simulators;
+import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.IsisFishException;
import fr.ifremer.isisfish.entities.Metier;
import fr.ifremer.isisfish.entities.Population;
@@ -99,7 +101,7 @@
// reload context parameters with context.getDB() context
param.reloadContextParameters();
-
+
//
// Rule initialisation
//
@@ -108,7 +110,7 @@
for (Rule rule : rules) {
rule.init(context);
log.info("Rule " + rule.getClass().getSimpleName()
- + " initialized");
+ + " initialized");
}
//
@@ -120,7 +122,7 @@
// Simulation loop
//
while (step.getStep() < lastStep) {
-
+
//
// if user stop simulation before last year
//
@@ -151,9 +153,9 @@
if (siMatrix.getStrategies(step).size() > 0) {
if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
MatrixND mat = metierMonitor.getOrCreateNoActivity(step,
- ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
.getStrategies(step), siMatrix
- .getMetiers(step));
+ .getMetiers(step));
resManager.addResult(step, mat);
}
}
@@ -162,7 +164,7 @@
// Rule condition evaluation
//
control.setText("Evaluate rules conditions (" + rules.size()
- + " rules)");
+ + " rules)");
for (Rule rule : rules) {
for (Metier metier : siMatrix.getMetiers(step)) {
boolean active = false;
@@ -171,14 +173,14 @@
} catch (Exception eee) {
if (log.isWarnEnabled()) {
log.warn("Can't evaluate rule condition for: "
- + rule, eee);
+ + rule, eee);
}
}
ruleMonitor.setEvaluationCondition(step, rule, metier,
- active);
+ active);
if (active) {
log.info("Activate rule: "
- + rule.getClass().getSimpleName());
+ + rule.getClass().getSimpleName());
resManager.addActiveRule(step, rule);
}
}
@@ -191,7 +193,7 @@
for (Rule rule : rules) {
for (Metier metier : siMatrix.getMetiers(step)) {
boolean condition = ruleMonitor.getEvalutionCondition(step,
- rule, metier);
+ rule, metier);
if (condition) {
rule.preAction(context, step, metier);
}
@@ -213,7 +215,7 @@
for (Population pop : siMatrix.getPopulations(step)) {
computeMonth(context, siMatrix, step, pop);
}
-
+
//
// Add some result not population dependante
//
@@ -231,29 +233,12 @@
}
if (resManager.isEnabled(ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET)) {
- MatrixND effortNominalPerStrategyMet = siMatrix.matrixEffortNominalPerStrategyMet(step);
+ MatrixND effortNominalPerStrategyMet = siMatrix.matrixEffortNominalPerStrategyMet(step);
resManager.addResult(step, effortNominalPerStrategyMet);
}
- //
- // Add economics results
- //
- if (!"false".equalsIgnoreCase(param.getTagValue().get(
- "ecoResult"))) {
- control.setText("Add economics results");
- saveGravityModel(step, resManager, gravityModel);
- }
}
- //
- // Add economics results
- //
- if (resManager.isEnabled(ResultName.MATRIX_PRICE)) {
- for (Population pop : siMatrix.getPopulations(step)) {
- MatrixND matPrice = siMatrix.matrixPrice(step, pop);
- resManager.addResult(step, pop, matPrice);
- }
- }
//
// Rule post action
@@ -297,7 +282,7 @@
.matrixDiscardWeightPerStrategyMetPerZonePop(
pop, step, discard);
resManager.addResult(step, pop,
- discardWeightPerStrategyMet);
+ discardWeightPerStrategyMet);
}
}
@@ -314,6 +299,26 @@
resManager.addResult(step, pop, landing);
}
}
+
+ //
+ // Add economics results
+ //
+
+ if (siMatrix.getStrategies(step).size() > 0) {
+ if (!"false".equalsIgnoreCase(param.getTagValue().get(
+ "ecoResult"))) {
+ control.setText("Add economics results");
+ saveGravityModel(step, resManager, gravityModel);
+ }
+ }
+
+ if (resManager.isEnabled(ResultName.MATRIX_PRICE)) {
+ for (Population pop : siMatrix.getPopulations(step)) {
+ MatrixND matPrice = siMatrix.matrixPrice(step, pop);
+ resManager.addResult(step, pop, matPrice);
+ }
+ }
+
}
//
@@ -339,12 +344,12 @@
protected boolean isEffortByCell(SimulationContext context) {
boolean result = "true".equalsIgnoreCase(context.getSimulationStorage()
- .getParameter().getTagValue().get("effortByCell"));
+ .getParameter().getTagValue().get("effortByCell"));
return result;
}
protected void computeMonth(SimulationContext context, SiMatrix siMatrix,
- TimeStep step, Population pop) throws IsisFishException, TopiaException {
+ TimeStep step, Population pop) throws IsisFishException, TopiaException {
// to add result
ResultManager resManager = context.getResultManager();
@@ -353,8 +358,8 @@
if (log.isInfoEnabled()) {
log.info("====================== begin " + step + " - " + pop
- + " =========================== "
- + System.currentTimeMillis());
+ + " =========================== "
+ + System.currentTimeMillis());
log.info("N: " + N);
}
@@ -427,7 +432,7 @@
if (resManager.isEnabled(ResultName.MATRIX_ABUNDANCE_BEGIN_MONTH)) {
MatrixND abondanceBM = siMatrix.matrixAbondanceBeginMonth(N, pop,
- step);
+ step);
resManager.addResult(step, pop, abondanceBM);
}
@@ -454,17 +459,17 @@
resManager.addResult(step, pop, matrixFishingMortality);
abundance = siMatrix.matrixAbundance(N, pop, step,
- matrixFishingMortality);
+ matrixFishingMortality);
// this matrix is necessary for matrixCatchPerStrategyMet
MatrixND catchRatePerStrategyMet = siMatrix
.matrixCatchRatePerStrategyMetPerZone(pop, step,
- matrixFishingMortality);
+ matrixFishingMortality);
resManager.addResult(step, pop, catchRatePerStrategyMet);
catchPerStrategyMetPerZonePop = siMatrix
.matrixCatchPerStrategyMetPerZone(N, pop, step,
- catchRatePerStrategyMet);
+ catchRatePerStrategyMet);
}
@@ -475,9 +480,9 @@
.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP)) {
MatrixND catchWeightPerStrategyMet = siMatrix
.matrixCatchWeightPerStrategyMetPerZonePop(step, pop,
- catchPerStrategyMetPerZonePop);
+ catchPerStrategyMetPerZonePop);
resManager.addResult(step, pop, catchWeightPerStrategyMet);
- }
+ }
if (isEffortByCell(context)) {
MatrixND catchPerStrategyMetPerZoneMet = siMatrix
@@ -488,7 +493,7 @@
.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET)) {
MatrixND catchWeightPerStrategyMet = siMatrix
.matrixCatchWeightPerStrategyMetPerZoneMet(step,
- pop, catchPerStrategyMetPerZoneMet);
+ pop, catchPerStrategyMetPerZoneMet);
resManager.addResult(step, pop, catchWeightPerStrategyMet);
}
}
@@ -496,12 +501,12 @@
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP) ||
resManager.isEnabled(ResultName.MATRIX_TOTAL_FISHING_MORTALITY)) {
MatrixND fishingMortalityPerGroup = siMatrix.fishingMortalityPerGroup(step,
- pop, context.getResultManager());
+ pop, context.getResultManager());
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP)) {
resManager.addResult(step, pop, fishingMortalityPerGroup);
}
-
+
if (resManager.isEnabled(ResultName.MATRIX_TOTAL_FISHING_MORTALITY)) {
MatrixND totalFishingMortality = siMatrix.totalFishingMortality(step, pop, fishingMortalityPerGroup);
resManager.addResult(step, pop, totalFishingMortality);
@@ -518,7 +523,7 @@
popMon.setN(pop, abundance);
log.debug("====================== end " + step + " - " + pop
- + " ===========================");
+ + " ===========================");
}
@@ -529,7 +534,7 @@
* @throws TopiaException
*/
private void saveGravityModel(TimeStep step, ResultManager resManager,
- GravityModel gravityModel) throws IsisFishException, TopiaException {
+ GravityModel gravityModel) throws IsisFishException, TopiaException {
if (resManager
.isEnabled(ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL)) {
MatrixND mat = gravityModel
1
0
Author: kmorin
Date: 2014-11-05 18:49:27 +0100 (Wed, 05 Nov 2014)
New Revision: 347
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/347
Log:
fixes #5932 Parametrer les simulations en mois
Modified:
trunk/pom.xml
trunk/simulators/DefaultSimulator.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-10-08 11:13:07 UTC (rev 346)
+++ trunk/pom.xml 2014-11-05 17:49:27 UTC (rev 347)
@@ -74,7 +74,7 @@
<dependency>
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.3.1.0</version>
+ <version>4.3.1.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2014-10-08 11:13:07 UTC (rev 346)
+++ trunk/simulators/DefaultSimulator.java 2014-11-05 17:49:27 UTC (rev 347)
@@ -75,8 +75,7 @@
SimulationParameter param = context.getSimulationStorage()
.getParameter();
SimulationControl control = context.getSimulationControl();
- int lastYear = param.getNumberOfYear();
- int lastStep = lastYear * Month.NUMBER_OF_MONTH;
+ int lastStep = param.getNumberOfMonths();
TimeStep step = control.getStep();
ResultManager resManager = context.getResultManager();
1
0
08 Oct '14
Author: echatellier
Date: 2014-10-08 13:13:07 +0200 (Wed, 08 Oct 2014)
New Revision: 346
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/346
Log:
Use result manager
Modified:
tags/4.3.1/scripts/SiMatrix.java
tags/4.3.1/simulators/DefaultSimulator.java
Modified: tags/4.3.1/scripts/SiMatrix.java
===================================================================
--- tags/4.3.1/scripts/SiMatrix.java 2014-10-08 11:00:58 UTC (rev 345)
+++ tags/4.3.1/scripts/SiMatrix.java 2014-10-08 11:13:07 UTC (rev 346)
@@ -55,10 +55,10 @@
import fr.ifremer.isisfish.entities.StrategyMonthInfo;
import fr.ifremer.isisfish.entities.Zone;
import fr.ifremer.isisfish.entities.ZoneDAO;
+import fr.ifremer.isisfish.simulator.ResultManager;
import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.types.TimeStep;
-import fr.ifremer.isisfish.types.Month;
-import fr.ifremer.isisfish.datastore.ResultStorage;
import fr.ifremer.isisfish.util.Nocache;
/**
@@ -1891,7 +1891,7 @@
* @param pop population
* @return Fishing mortality per group per year (computed in December)
*/
- public MatrixND fishingMortalityPerGroup(TimeStep step, Population pop, ResultStorage resManager) throws TopiaException {
+ public MatrixND fishingMortalityPerGroup(TimeStep step, Population pop, ResultManager resManager) throws TopiaException {
double Fgroup = 0;
double Cgroup = 0;
double Mgroup = 0;
Modified: tags/4.3.1/simulators/DefaultSimulator.java
===================================================================
--- tags/4.3.1/simulators/DefaultSimulator.java 2014-10-08 11:00:58 UTC (rev 345)
+++ tags/4.3.1/simulators/DefaultSimulator.java 2014-10-08 11:13:07 UTC (rev 346)
@@ -499,7 +499,7 @@
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP) ||
resManager.isEnabled(ResultName.MATRIX_TOTAL_FISHING_MORTALITY)) {
MatrixND fishingMortalityPerGroup = siMatrix.fishingMortalityPerGroup(step,
- pop, context.getSimulationStorage().getResultStorage());
+ pop, context.getResultManager());
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP)) {
resManager.addResult(step, pop, fishingMortalityPerGroup);
1
0
Author: echatellier
Date: 2014-10-08 13:00:58 +0200 (Wed, 08 Oct 2014)
New Revision: 345
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/345
Log:
Use result manager
Modified:
trunk/scripts/SiMatrix.java
trunk/simulators/DefaultSimulator.java
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2014-10-08 10:20:56 UTC (rev 344)
+++ trunk/scripts/SiMatrix.java 2014-10-08 11:00:58 UTC (rev 345)
@@ -55,10 +55,10 @@
import fr.ifremer.isisfish.entities.StrategyMonthInfo;
import fr.ifremer.isisfish.entities.Zone;
import fr.ifremer.isisfish.entities.ZoneDAO;
+import fr.ifremer.isisfish.simulator.ResultManager;
import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.types.TimeStep;
-import fr.ifremer.isisfish.types.Month;
-import fr.ifremer.isisfish.datastore.ResultStorage;
import fr.ifremer.isisfish.util.Nocache;
/**
@@ -1891,7 +1891,7 @@
* @param pop population
* @return Fishing mortality per group per year (computed in December)
*/
- public MatrixND fishingMortalityPerGroup(TimeStep step, Population pop, ResultStorage resManager) throws TopiaException {
+ public MatrixND fishingMortalityPerGroup(TimeStep step, Population pop, ResultManager resManager) throws TopiaException {
double Fgroup = 0;
double Cgroup = 0;
double Mgroup = 0;
@@ -1913,12 +1913,12 @@
for (TimeStep loopstep = new TimeStep(step.getYear() * 12); loopstep.beforeOrEquals(step); loopstep=loopstep.next()) {
// On fait cette boucle pour contourner les aspects de cache qui font que les resultats ne sont pas recuperes
- //s'ils ont deja ete calcules une fois (meme s'ils ont change depuis)
+ // s'ils ont deja ete calcules une fois (meme s'ils ont change depuis)
// beforeOrEquals sert a bien prendre Decembre aussi
MatrixND catchPerStrategyTemp = resManager.getMatrix(loopstep, pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
if (catchPerStrategy == null) {
- catchPerStrategy = catchPerStrategyTemp.clone();
+ catchPerStrategy = catchPerStrategyTemp.copy();
// On clone la matrice car si on fait les operations sur celle contenue dans le cache on la modifie et donc on recupere des resultats faux.
} else {
catchPerStrategy = catchPerStrategy.add(catchPerStrategyTemp); // Pour avoir la somme des captures sur les 12 mois
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2014-10-08 10:20:56 UTC (rev 344)
+++ trunk/simulators/DefaultSimulator.java 2014-10-08 11:00:58 UTC (rev 345)
@@ -497,7 +497,7 @@
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP) ||
resManager.isEnabled(ResultName.MATRIX_TOTAL_FISHING_MORTALITY)) {
MatrixND fishingMortalityPerGroup = siMatrix.fishingMortalityPerGroup(step,
- pop, context.getSimulationStorage().getResultStorage());
+ pop, context.getResultManager());
if (resManager.isEnabled(ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP)) {
resManager.addResult(step, pop, fishingMortalityPerGroup);
1
0