Author: echatellier Date: 2014-07-29 16:44:48 +0200 (Tue, 29 Jul 2014) New Revision: 4074 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4074 Log: Update test scripts Added: trunk/src/test/resources/test-database/exports/CapturesNombreStrategies.java trunk/src/test/resources/test-database/exports/CapturesPoidsStrategies.java trunk/src/test/resources/test-database/objectives/ trunk/src/test/resources/test-database/optimizations/ trunk/src/test/resources/test-database/scripts/MinimisationUtil.java trunk/src/test/resources/test-database/scripts/ObjectiveFunction.java trunk/src/test/resources/test-database/scripts/ObjectiveFunctionBaranov.java trunk/src/test/resources/test-database/simulationplans/RecuitSimuleSimulateur.java trunk/src/test/resources/test-database/simulators/SimulatorEffortByCell.java Modified: trunk/src/test/resources/test-database/exports/Abundances.java trunk/src/test/resources/test-database/exports/Biomasses.java trunk/src/test/resources/test-database/exports/CapturesNombre.java trunk/src/test/resources/test-database/exports/CapturesPoids.java trunk/src/test/resources/test-database/exports/CellsDefinition.java trunk/src/test/resources/test-database/exports/EffortsMetier.java trunk/src/test/resources/test-database/exports/MetierZone.java trunk/src/test/resources/test-database/exports/NonActivite.java trunk/src/test/resources/test-database/exports/OwnerMargin.java trunk/src/test/resources/test-database/exports/RegionDefinition.java trunk/src/test/resources/test-database/exports/RejetsNombre.java trunk/src/test/resources/test-database/exports/RejetsPoids.java trunk/src/test/resources/test-database/exports/VesselMargin.java trunk/src/test/resources/test-database/exports/ZonesDefinition.java trunk/src/test/resources/test-database/rules/Cantonnement.java trunk/src/test/resources/test-database/rules/CantonnementPreSimu.java trunk/src/test/resources/test-database/rules/ChangementParamControlablePresimu.java trunk/src/test/resources/test-database/rules/EffortReduction.java trunk/src/test/resources/test-database/rules/GraviteVPUE1.java trunk/src/test/resources/test-database/rules/InterdictionEngin.java trunk/src/test/resources/test-database/rules/InterdictionEnginPreSimu.java trunk/src/test/resources/test-database/rules/TACpoids.java trunk/src/test/resources/test-database/rules/TailleMin.java trunk/src/test/resources/test-database/rules/TotalClosure.java trunk/src/test/resources/test-database/scripts/GravityModel.java trunk/src/test/resources/test-database/scripts/ResultName.java trunk/src/test/resources/test-database/scripts/RuleUtil.java trunk/src/test/resources/test-database/scripts/SiMatrix.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassReferenceY9.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeY6.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassY3.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightReferenceY7.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeY4.java trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightY1.java trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassY2.java trunk/src/test/resources/test-database/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java trunk/src/test/resources/test-database/simulationplans/SimulationNumberRestriction.java trunk/src/test/resources/test-database/simulators/DefaultSimulator.java Modified: trunk/src/test/resources/test-database/exports/Abundances.java =================================================================== --- trunk/src/test/resources/test-database/exports/Abundances.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/Abundances.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 Ifremer, CodeLutin, 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 @@ -26,7 +26,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; import org.nuiton.math.matrix.*; import scripts.ResultName; @@ -37,7 +36,7 @@ import fr.ifremer.isisfish.datastore.SimulationStorage; /** - * Abundance.java + * Abundances.java * * Created: 1 septembre 2006 * @@ -52,8 +51,8 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(Abundances.class); - protected String [] necessaryResult = { - ResultName.MATRIX_ABUNDANCE + protected String[] necessaryResult = { + ResultName.MATRIX_ABUNDANCE }; @Override @@ -73,22 +72,22 @@ @Override public String getDescription() { - return _("Exporte les abondances en nombre tableau avec des lignes pop;id;zone;date;nombre."); + return "Exporte les abondances en nombre tableau avec des lignes pop;id;zone;date;nombre."; } @Override public void export(SimulationStorage simulation, Writer out) throws Exception { for (Population pop : simulation.getParameter().getPopulations()) { MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_ABUNDANCE); - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); - Object [] sems = i.getSemanticsCoordinates(); - TimeStep step = (TimeStep)sems[0]; - PopulationGroup group = (PopulationGroup)sems[1]; - Zone zone = (Zone)sems[2]; + Object[] sems = i.getSemanticsCoordinates(); + TimeStep step = (TimeStep) sems[0]; + PopulationGroup group = (PopulationGroup) sems[1]; + Zone zone = (Zone) sems[2]; double val = i.getValue(); - out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ step.getStep() +";"+ val +"\n"); + out.write(pop.getName() + ";" + group.getId() + ";" + zone.getName() + ";" + step.getStep() + ";" + val + "\n"); } } } Modified: trunk/src/test/resources/test-database/exports/Biomasses.java =================================================================== --- trunk/src/test/resources/test-database/exports/Biomasses.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/Biomasses.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -53,8 +51,8 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(Biomasses.class); - protected String [] necessaryResult = { - ResultName.MATRIX_BIOMASS + protected String[] necessaryResult = { + ResultName.MATRIX_BIOMASS }; @Override @@ -74,22 +72,22 @@ @Override public String getDescription() { - return _("Exporte les biomasses tableau avec des lignes pop;id;zone;date;nombre"); + return "Exporte les biomasses tableau avec des lignes pop;id;zone;date;nombre"; } @Override public void export(SimulationStorage simulation, Writer out) throws Exception { for (Population pop : simulation.getParameter().getPopulations()) { MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_BIOMASS); - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); - Object [] sems = i.getSemanticsCoordinates(); - TimeStep step = (TimeStep)sems[0]; - PopulationGroup group = (PopulationGroup)sems[1]; - Zone zone = (Zone)sems[2]; - + Object[] sems = i.getSemanticsCoordinates(); + TimeStep step = (TimeStep) sems[0]; + PopulationGroup group = (PopulationGroup) sems[1]; + Zone zone = (Zone) sems[2]; + double val = i.getValue(); - out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ step.getStep() +";"+ val +"\n"); + out.write(pop.getName() + ";" + group.getId() + ";" + zone.getName() + ";" + step.getStep() + ";" + val + "\n"); } } } Modified: trunk/src/test/resources/test-database/exports/CapturesNombre.java =================================================================== --- trunk/src/test/resources/test-database/exports/CapturesNombre.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/CapturesNombre.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,16 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - -import java.io.Writer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixIterator; -import org.nuiton.math.matrix.MatrixND; - -import scripts.ResultName; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.entities.Metier; import fr.ifremer.isisfish.entities.Population; @@ -38,12 +28,20 @@ import fr.ifremer.isisfish.entities.Zone; import fr.ifremer.isisfish.export.Export; import fr.ifremer.isisfish.types.TimeStep; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import scripts.ResultName; +import java.io.Writer; + /** * CapturesNombre.java * - * Created: 23 novembre 2006 - * + * Export des captures en nombre de la forme : + * Population ; Métier ; Groupe ; Zone ; Pas de temps ; Valeur + * * @author anonymous <anonymous@labs.libre-entreprise.org> * @version $Revision: 1.4 $ * @@ -54,7 +52,9 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(CapturesNombre.class); - protected String[] necessaryResult = { ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP }; + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP + }; @Override public String[] getNecessaryResult() { @@ -73,7 +73,7 @@ @Override public String getDescription() { - return _("Export les captures en nombre de la simulation. tableau pop;metier;id;zone;nombre"); + return "Export les captures en nombre de la simulation. tableau pop;metier;id;zone;nombre"; } @Override @@ -82,8 +82,7 @@ TimeStep lastStep = simulation.getResultStorage().getLastStep(); for (Population pop : simulation.getParameter().getPopulations()) { - for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step - .next()) { + for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step.next()) { MatrixND mat = simulation.getResultStorage().getMatrix(step, pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP); if (mat != null) { // can be null if simulation is stopped before last year simulation Added: trunk/src/test/resources/test-database/exports/CapturesNombreStrategies.java =================================================================== --- trunk/src/test/resources/test-database/exports/CapturesNombreStrategies.java (rev 0) +++ trunk/src/test/resources/test-database/exports/CapturesNombreStrategies.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,109 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2006 - 2014 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 fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Metier; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.PopulationGroup; +import fr.ifremer.isisfish.entities.Strategy; +import fr.ifremer.isisfish.entities.Zone; +import fr.ifremer.isisfish.export.Export; +import fr.ifremer.isisfish.types.TimeStep; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import scripts.ResultName; + +import java.io.Writer; + +/** + * CapturesNombreStrategies.java + * + * Export des captures en nombre de la forme : + * Population ; Stratégie ; Métier ; Groupe ; Zone ; Pas de temps ; Valeur + * + * @author anonymous <anonymous@labs.libre-entreprise.org> + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ + */ +public class CapturesNombreStrategies implements Export { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(CapturesNombreStrategies.class); + + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP + }; + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + + @Override + public String getExportFilename() { + return "CapturesNombreStrategies"; + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String getDescription() { + return "Export les captures en nombre de la simulation. tableau pop;strategie;metier;id;zone;nombre"; + } + + @Override + public void export(SimulationStorage simulation, Writer out) throws Exception { + TimeStep lastStep = simulation.getResultStorage().getLastStep(); + + for (Population pop : simulation.getParameter().getPopulations()) { + for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step + .next()) { + MatrixND mat = simulation.getResultStorage().getMatrix(step, + pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP); + if (mat != null) { // can be null if simulation is stopped before last year simulation + //mat = mat.sumOverDim(0); //sum on strategy + for (MatrixIterator i = mat.iterator(); i.hasNext();) { + i.next(); + Object[] sems = i.getSemanticsCoordinates(); + Metier metier = (Metier) sems[1]; + PopulationGroup group = (PopulationGroup) sems[2]; + Zone zone = (Zone) sems[3]; + Strategy strategy = (Strategy) sems[0]; + + double val = i.getValue(); + out.write(pop.getName() + ";" + strategy.getName() + ";" + + metier.getName() + ";" + group.getId() + ";" + + zone.getName() + ";" + step.getStep() + ";" + + val + "\n"); + } + } + } + } + } +} Property changes on: trunk/src/test/resources/test-database/exports/CapturesNombreStrategies.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/test/resources/test-database/exports/CapturesPoids.java =================================================================== --- trunk/src/test/resources/test-database/exports/CapturesPoids.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/CapturesPoids.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,16 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - -import java.io.Writer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixIterator; -import org.nuiton.math.matrix.MatrixND; - -import scripts.ResultName; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.entities.Metier; import fr.ifremer.isisfish.entities.Population; @@ -38,11 +28,19 @@ import fr.ifremer.isisfish.entities.Zone; import fr.ifremer.isisfish.export.Export; import fr.ifremer.isisfish.types.TimeStep; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import scripts.ResultName; +import java.io.Writer; + /** * CapturesPoids.java * - * Created: 23 novembre 2006 + * Export des captures en poids de la forme : + * Population ; Métier ; Groupe ; Zone ; Pas de temps ; Valeur * * @author anonymous <anonymous@labs.libre-entreprise.org> * @version $Revision: 1.4 $ @@ -54,7 +52,9 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(CapturesPoids.class); - protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP }; + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP + }; @Override public String[] getNecessaryResult() { @@ -73,7 +73,7 @@ @Override public String getDescription() { - return _("Export les captures en poids de la simulation. tableau pop;metier;id;zone;nombre"); + return "Export les captures en poids de la simulation. tableau pop;metier;id;zone;nombre"; } @Override Added: trunk/src/test/resources/test-database/exports/CapturesPoidsStrategies.java =================================================================== --- trunk/src/test/resources/test-database/exports/CapturesPoidsStrategies.java (rev 0) +++ trunk/src/test/resources/test-database/exports/CapturesPoidsStrategies.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,110 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2006 - 2014 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 fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Metier; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.PopulationGroup; +import fr.ifremer.isisfish.entities.Strategy; +import fr.ifremer.isisfish.entities.Zone; +import fr.ifremer.isisfish.export.Export; +import fr.ifremer.isisfish.types.TimeStep; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import scripts.ResultName; + +import java.io.Writer; + +/** + * CapturesPoidsStrategies.java + * + * Export des captures en poids de la forme : + * Population ; Stratégie ; Métier ; Groupe ; Zone ; Pas de temps ; Valeur + * + * @author anonymous <anonymous@labs.libre-entreprise.org> + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ + */ +public class CapturesPoidsStrategies implements Export { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(CapturesPoidsStrategies.class); + + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP + }; + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + + @Override + public String getExportFilename() { + return "CapturesPoidsStrategies"; + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String getDescription() { + return "Export les captures en poids de la simulation. tableau pop;strategie;metier;id;zone;nombre"; + } + + @Override + public void export(SimulationStorage simulation, Writer out) + throws Exception { + TimeStep lastStep = simulation.getResultStorage().getLastStep(); + + for (Population pop : simulation.getParameter().getPopulations()) { + for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step + .next()) { + MatrixND mat = simulation.getResultStorage().getMatrix(step, + pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); + if (mat != null) { // can be null if simulation is stopped before last year simulation + //mat = mat.sumOverDim(0); //sum on strategy + for (MatrixIterator i = mat.iterator(); i.hasNext();) { + i.next(); + Object[] sems = i.getSemanticsCoordinates(); + Metier metier = (Metier) sems[1]; + PopulationGroup group = (PopulationGroup) sems[2]; + Zone zone = (Zone) sems[3]; + Strategy strategy = (Strategy) sems[0]; + + double val = i.getValue(); + out.write(pop.getName() + ";" + strategy.getName() + ";" + + metier.getName() + ";" + group.getId() + ";" + + zone.getName() + ";" + step.getStep() + ";" + + val + "\n"); + } + } + } + } + } +} Property changes on: trunk/src/test/resources/test-database/exports/CapturesPoidsStrategies.java ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/src/test/resources/test-database/exports/CellsDefinition.java =================================================================== --- trunk/src/test/resources/test-database/exports/CellsDefinition.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/CellsDefinition.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import java.util.List; @@ -50,11 +48,11 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(CellsDefinition.class); - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -74,7 +72,7 @@ @Override public String getDescription() { - return _("Export cell's position(longitute/latitute)"); + return "Export cell's position(longitute/latitute)"; } @Override Modified: trunk/src/test/resources/test-database/exports/EffortsMetier.java =================================================================== --- trunk/src/test/resources/test-database/exports/EffortsMetier.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/EffortsMetier.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,7 @@ static private Log log = LogFactory.getLog(EffortsMetier.class); protected String [] necessaryResult = { - ResultName.MATRIX_EFFORT_PER_STRATEGY_MET + ResultName.MATRIX_EFFORT_PER_STRATEGY_MET }; @Override @@ -74,13 +72,13 @@ @Override public String getDescription() { - return _("retourne un tableau strategie;metier;date;effort"); + return "retourne un tableau strategie;metier;date;effort"; } @Override public void export(SimulationStorage simulation, Writer out) throws Exception { MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET); - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); TimeStep step = (TimeStep)sems[0]; Modified: trunk/src/test/resources/test-database/exports/MetierZone.java =================================================================== --- trunk/src/test/resources/test-database/exports/MetierZone.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/MetierZone.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -26,7 +26,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; import org.nuiton.math.matrix.*; import scripts.ResultName; @@ -51,8 +50,8 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(MetierZone.class); - public String [] necessaryResult = { - ResultName.MATRIX_METIER_ZONE, + protected String [] necessaryResult = { + ResultName.MATRIX_METIER_ZONE, }; @Override @@ -72,7 +71,7 @@ @Override public String getDescription() { - return _("Export zone used by metier during simulation"); + return "Export zone used by metier during simulation"; } @Override @@ -82,7 +81,7 @@ for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step.next() ) { MatrixND mat = simulation.getResultStorage().getMatrix(step, ResultName.MATRIX_METIER_ZONE); if (mat != null) { // can be null if simulation is stopped before last year simulation - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); if (i.getValue() == 1) { Object metier = i.getSemanticsCoordinates()[0]; Modified: trunk/src/test/resources/test-database/exports/NonActivite.java =================================================================== --- trunk/src/test/resources/test-database/exports/NonActivite.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/NonActivite.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,7 @@ static private Log log = LogFactory.getLog(NonActivite.class); protected String [] necessaryResult = { - ResultName.MATRIX_NO_ACTIVITY + ResultName.MATRIX_NO_ACTIVITY }; @Override @@ -74,13 +72,13 @@ @Override public String getDescription() { - return _("retourne un tableau strategie;metier;date;proportion"); + return "retourne un tableau strategie;metier;date;proportion"; } @Override public void export(SimulationStorage simulation, Writer out) throws Exception { MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_NO_ACTIVITY); - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); TimeStep step = (TimeStep)sems[0]; Modified: trunk/src/test/resources/test-database/exports/OwnerMargin.java =================================================================== --- trunk/src/test/resources/test-database/exports/OwnerMargin.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/OwnerMargin.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,7 @@ static private Log log = LogFactory.getLog(OwnerMargin.class); protected String [] necessaryResult = { - ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL + ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL }; @Override @@ -74,15 +72,15 @@ @Override public String getDescription() { - return _("Exporte les profits du patrons, retourne un tableau strategy;date;value"); + return "Exporte les profits du patrons, retourne un tableau strategy;date;value"; } @Override public void export(SimulationStorage simulation, Writer out) throws Exception { MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL); - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); - Object [] sems = i.getSemanticsCoordinates(); + Object[] sems = i.getSemanticsCoordinates(); TimeStep step = (TimeStep)sems[0]; Strategy str = (Strategy)sems[1]; Modified: trunk/src/test/resources/test-database/exports/RegionDefinition.java =================================================================== --- trunk/src/test/resources/test-database/exports/RegionDefinition.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/RegionDefinition.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -26,7 +26,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.entities.*; @@ -49,11 +48,11 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(RegionDefinition.class); - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -73,7 +72,7 @@ @Override public String getDescription() { - return _("Export region description"); + return "Export region description"; } @Override Modified: trunk/src/test/resources/test-database/exports/RejetsNombre.java =================================================================== --- trunk/src/test/resources/test-database/exports/RejetsNombre.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/RejetsNombre.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -54,7 +52,9 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(RejetsNombre.class); - protected String[] necessaryResult = { ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP }; + protected String[] necessaryResult = { + ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP + }; @Override public String[] getNecessaryResult() { @@ -73,7 +73,7 @@ @Override public String getDescription() { - return _("Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre"); + return "Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre"; } @Override Modified: trunk/src/test/resources/test-database/exports/RejetsPoids.java =================================================================== --- trunk/src/test/resources/test-database/exports/RejetsPoids.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/RejetsPoids.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -54,8 +52,8 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(RejetsPoids.class); - protected String[] necessaryResult = { ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP - + protected String[] necessaryResult = { + ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP }; @Override @@ -75,7 +73,7 @@ @Override public String getDescription() { - return _("Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre"); + return "Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre"; } @Override Modified: trunk/src/test/resources/test-database/exports/VesselMargin.java =================================================================== --- trunk/src/test/resources/test-database/exports/VesselMargin.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/VesselMargin.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,7 @@ static private Log log = LogFactory.getLog(VesselMargin.class); protected String [] necessaryResult = { - ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL + ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL }; @Override @@ -74,13 +72,13 @@ @Override public String getDescription() { - return _("cvs out strategy;date;value"); + return "cvs out strategy;date;value"; } @Override public void export(SimulationStorage simulation, Writer out) throws Exception { MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL); - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); TimeStep step = (TimeStep)sems[0]; Modified: trunk/src/test/resources/test-database/exports/ZonesDefinition.java =================================================================== --- trunk/src/test/resources/test-database/exports/ZonesDefinition.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/exports/ZonesDefinition.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -27,7 +27,6 @@ import java.io.Writer; import java.util.List; -import static org.nuiton.i18n.I18n._; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.entities.*; @@ -51,11 +50,11 @@ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(ZonesDefinition.class); - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -75,7 +74,7 @@ @Override public String getDescription() { - return _("Export cell's zone constitution"); + return "Export cell's zone constitution"; } @Override Modified: trunk/src/test/resources/test-database/rules/Cantonnement.java =================================================================== --- trunk/src/test/resources/test-database/rules/Cantonnement.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/Cantonnement.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,6 +48,8 @@ /** * Cantonnement.java * + * Remplace aussi Cantonnement Engin + * * Created: 30 novembre 2006 * * @author anonymous <anonymous@labs.libre-entreprise.org> @@ -58,10 +58,6 @@ * Last update: $Date: 2007-11-02 17:41:41 $ * by : $Author: bpoussin $ */ - -/** - * Remplace aussi Cantonnement Engin - */ public class Cantonnement extends AbstractRule { /** to use log facility, just put in your code: log.info("..."); */ @@ -80,12 +76,12 @@ @Doc(value="End month") public Month param_endMonth = Month.DECEMBER; - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - ResultName.MATRIX_NO_ACTIVITY, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + ResultName.MATRIX_NO_ACTIVITY, }; @Override @@ -101,7 +97,7 @@ public String getDescription() throws Exception { // fermeture saisiniere de zone qui peut être réduite à un engin // et a certaines années de la simulation - return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"); + return "Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"; } /** @@ -126,7 +122,7 @@ public boolean condition(SimulationContext context, TimeStep step, Metier metier) throws Exception { if (step.before(param_beginStep)) { return false; - } else if(step.after(param_endStep)) { + } else if (step.after(param_endStep)) { return false; } @@ -204,7 +200,7 @@ zoneCantonnement.addAllCell(tmpCells); i.remove(); } - List<Zone> newZone = new ArrayList<Zone>(); + List<Zone> newZone = new ArrayList<>(); newZone.add(zoneCantonnement); infoMetier.setZone(newZone); } else { @@ -219,10 +215,10 @@ metierMon.addforbiddenMetier(metier); List<Strategy> strategies = siMatrix.getStrategies(step); - for(Strategy str : strategies){ + for (Strategy str : strategies) { StrategyMonthInfo info = str.getStrategyMonthInfo(step.getMonth()); double prop = info.getProportionMetier(metier); - if (prop != 0){ + if (prop != 0) { noActivity.setValue(str , metier, prop); info.setProportionMetier(metier, 0); } Modified: trunk/src/test/resources/test-database/rules/CantonnementPreSimu.java =================================================================== --- trunk/src/test/resources/test-database/rules/CantonnementPreSimu.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/CantonnementPreSimu.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,9 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n.n_; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -73,15 +70,15 @@ @Doc(value="End month") public Month param_endMonth = Month.DECEMBER; - protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>(); + protected Map<Month, MatrixND> tableNonActivite = new HashMap<>(); protected boolean affectNonActivite = false; - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - ResultName.MATRIX_NO_ACTIVITY, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + ResultName.MATRIX_NO_ACTIVITY, }; @Override @@ -95,7 +92,7 @@ */ @Override public String getDescription() throws Exception { - return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"); + return "Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"; } private void reportNonActivite(SimulationContext context, @@ -107,7 +104,8 @@ if (effort != null){ for (Month month : chomageMonth) { StrategyMonthInfo InfoMois = strategy.getStrategyMonthInfo(month); -//this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier)); + // this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, + // listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier)); log.info("debut reportNonActivite"); // on regarde si on a déjà une entrée pour le mois courant @@ -116,7 +114,7 @@ matNonActiviteMois = MatrixFactory.getInstance().create( ResultName.MATRIX_NO_ACTIVITY, new List[]{listestrategies, metiers}, - new String[]{n_("Strategies"), n_("Metiers")}); + new String[]{"Strategies", "Metiers"}); tableNonActivite.put(month, matNonActiviteMois); } @@ -160,20 +158,20 @@ else { log.info("l engin du métier est bien concerné"); List<MetierSeasonInfo> saisons = metier.getMetierSeasonInfo(); - for (MetierSeasonInfo saisonmetier: saisons){ + for (MetierSeasonInfo saisonmetier : saisons){ int inter = siMatrix.nbCellInter(saisonmetier.getZone(), param_zone); - if (inter != 0){ + if (inter != 0) { List<Cell> MailleMetier = siMatrix.getCells(saisonmetier.getZone()); // les mailles qui reste dans la zone metier - List<Cell> newCellMetier = new ArrayList<Cell>(MailleMetier); + List<Cell> newCellMetier = new ArrayList<>(MailleMetier); newCellMetier.removeAll(maillefermee); - List<Month> saison=saisonmetier.getMonths(); + List<Month> saison = saisonmetier.getMonths(); if (saison.containsAll(SaisonFermee)){ log.info("il y a bien intersection entre la zone métier et le cantonnement pour la saison "+saison.toString()); // calcule de la zone restante: - boolean ToutFerme=false; + boolean ToutFerme; boolean DebInclus=saison.contains(param_beginMonth); boolean FinInclus=saison.contains(param_endMonth); @@ -202,7 +200,7 @@ log.info("toute la saison metier est incluse dans la saison de fermeture"); //si tout est fermé, on met le metier au chômage - if (ToutFerme==true) { + if (ToutFerme) { log.info ("toute la zone est fermée, le metier passe donc à chômage pour cette saison"); reportNonActivite(context, listestrategies, metiers, metier, saison); @@ -219,7 +217,7 @@ else if (DebInclus && ((!FinInclus) || param_endMonth.equals(saison.get(saison.size()-1)))) { log.info ("il y a intersection de la saison de fermeture avec la saison métier de " + param_beginMonth + " à " + saison.get(saison.size()-1)); //si tout est fermé on met les proportions à 0 pour les mois fermes - if (ToutFerme==true){ + if (ToutFerme){ log.info ("toute la zone métier est fermée"); List<Month> chomageMonth = new ArrayList<Month>(SaisonFermee); chomageMonth.retainAll(saison); @@ -246,7 +244,7 @@ else if (((!DebInclus) || param_beginMonth.equals(saison.get(0))) && FinInclus) { log.info ("il y a intersection de la saison de fermeture avec la saison métier de "+param_beginMonth+" à "+saison.get(saison.size()-1)); //si tout est fermé on met les proportions à 0 pour les mois fermes - if (ToutFerme==true){ + if (ToutFerme){ log.info ("toute la zone est fermee"); List<Month> chomageMonth = new ArrayList<Month>(SaisonFermee); chomageMonth.retainAll(saison); @@ -272,7 +270,7 @@ // dernier cas de figure: les deux sont inclus et sont différents des bornes else { //si tout est fermé on met les proportions à 0 pour les mois fermes - if (ToutFerme==true){ + if (ToutFerme){ log.info("toute la zone métier est fermée"); reportNonActivite(context, listestrategies, metiers, metier, SaisonFermee); } @@ -325,7 +323,7 @@ public boolean condition(SimulationContext context, TimeStep step, Metier metier) throws Exception { boolean result = false; MatrixND mat = tableNonActivite.get(step.getMonth()); - if (mat != null && affectNonActivite == false) { + if (mat != null && !affectNonActivite) { result = true; } return result; @@ -353,7 +351,7 @@ metierMon.setNoActivity(step, mat.copy()); } else{ - noActivity = noActivity.add(mat); + noActivity.add(mat); } } Modified: trunk/src/test/resources/test-database/rules/ChangementParamControlablePresimu.java =================================================================== --- trunk/src/test/resources/test-database/rules/ChangementParamControlablePresimu.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/ChangementParamControlablePresimu.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.ArrayList; import java.util.List; @@ -77,11 +75,11 @@ @Doc(value="New param controlable value") public String param_newParamValue = "80"; - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -95,7 +93,7 @@ */ @Override public String getDescription() throws Exception { - return _("Change gear parameter value for all metier with this gear"); + return "Change gear parameter value for all metier with this gear"; } /** Modified: trunk/src/test/resources/test-database/rules/EffortReduction.java =================================================================== --- trunk/src/test/resources/test-database/rules/EffortReduction.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/EffortReduction.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.List; import org.apache.commons.logging.Log; @@ -57,9 +55,13 @@ @Doc("Pourcentage de reduction d effort applique.") public double param_PercentReduction = 0.5; - boolean first = true; + protected boolean first = true; - protected String[] necessaryResult = {}; + protected String[] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + }; /** * @return the necessaryResult @@ -75,7 +77,7 @@ */ @Override public String getDescription() { - return _("Reduce monthly effort of each strategy of the percent indicated"); + return "Reduce monthly effort of each strategy of the percent indicated"; } /** Modified: trunk/src/test/resources/test-database/rules/GraviteVPUE1.java =================================================================== --- trunk/src/test/resources/test-database/rules/GraviteVPUE1.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/GraviteVPUE1.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -59,21 +57,20 @@ static private Log log = LogFactory.getLog(GraviteVPUE1.class); /** stocke la somme des prop initiales [str x month] */ - private MatrixND SommePropInitial = null; - /** stocke par strat*met, la dernière attractivite pour chaque mois [str x met x month] */ + protected MatrixND SommePropInitial = null; /** permet de stocker les CPUE nominales [str x met] */ - private MatrixND valuePerUnitOfEffort = null; + protected MatrixND valuePerUnitOfEffort = null; - public String[] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - //ResultName.MATRIX_EFFORT_PER_STRATEGY_MET, - ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET, // garder la , + // Booleen permettant que ne boucler que sur un seul metier dans la preaction : + protected boolean first = true; + protected String[] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET }; @Override @@ -87,7 +84,7 @@ */ @Override public String getDescription() throws Exception { - return _("Calcule les proportion par métier chaque mois en fonction de la VPUE du métier l'année précédante"); + return "Calcule les proportion par métier chaque mois en fonction de la VPUE du métier l'année précédante"; /*"HYPOTHESES GRAVITE" " attention cette règle doit toujours être mise avant les mesures de gestion"+ " si pour un metier Effort (métier annee-1,mois) = 0 et propinitiale (métier, mois) !=0 (ie métier potentiellement pratiqué), alors "+ @@ -146,7 +143,6 @@ SommePropInitial.setValue(str, info.getMonth(), somme); } } - } /** @@ -164,8 +160,6 @@ return step.getYear() > 0; } - // Booleen permettant que ne boucler que sur un seul metier dans la preaction : - boolean first = true; /** * Si la condition est vrai alors cette action est executee avant le pas @@ -195,14 +189,14 @@ ////////Initialisation des matrices qui resultent de la simulation//////////////////////////////////////////////////////////// //Calcul de l effort nominal par strategy met - MatrixND EffortNominalPerStrMet = null; + MatrixND EffortNominalPerStrMet; EffortNominalPerStrMet = resultmanager.getMatrix(step.previousYear(), ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); //System.out.println("EffortNominalPerStrMet calculee " // + EffortNominalPerStrMet); //on commence par creer une matrice de valeurs (somme sur ttes les especes capturees) par strategie met - MatrixND GrossValuePerStrMet = null; + MatrixND GrossValuePerStrMet; GrossValuePerStrMet = resultmanager.getMatrix(step.previousYear(), ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET); @@ -246,7 +240,7 @@ //log.info("value/effort= " + vpue); somme += value / effort; } else if ((effort == 0) - & (smi.getProportionMetier(strMetier) == 0)) {// n'a jamais pêche avec ce metier + && (smi.getProportionMetier(strMetier) == 0)) {// n'a jamais pêche avec ce metier valuePerUnitOfEffort.setValue(str, strMetier, 0); //log.info("n'a jamais pêche avec ce metier"); } else {// n'a pas peche au mois, annee -1, mais avait une prop d'effort non nul a l'annee=0 @@ -257,7 +251,7 @@ //log.info("testCondition pour str" + str.getName() // + ":" + testCondition); // A partir des VPUE stockees dans valuePerUnitOfEffort, on calcule la gravité - double newProp = 0; + double newProp; //log.info("A partir des VPUE stockees dans valuePerUnitOfEffort, on calcule la gravité"); if (!testCondition) { double SommeVPUEstrat = somme; Modified: trunk/src/test/resources/test-database/rules/InterdictionEngin.java =================================================================== --- trunk/src/test/resources/test-database/rules/InterdictionEngin.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/InterdictionEngin.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -71,11 +69,11 @@ @Doc(value="do the doc of param endMonth") public Month param_endMonth = Month.DECEMBER; - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -90,7 +88,7 @@ @Override public String getDescription() throws Exception { // interdiction des metiers utilisant cet engin - return _("Prohibited gear"); + return "Prohibited gear"; } /** @@ -167,7 +165,7 @@ // 1er cas:l'effort est reporte sur un metier de la meme strategie, // n'ayant pas l'espece comme capture principale et pechant avec le meme engin - List<EffortDescription> MetiersPossibles = new ArrayList<EffortDescription>(Strat.getSetOfVessels().getPossibleMetiers()); + List<EffortDescription> MetiersPossibles = new ArrayList<>(Strat.getSetOfVessels().getPossibleMetiers()); // on verifie que les metiers sont bien pratiques au mois courant, // qu'ils n'ont pas le meme engin et qu'ils ne sont pas @@ -184,7 +182,7 @@ // on repartit maintenant l'effort entre les differents metiers // possibles dans la meme strategie si un metier possible existe bien - if (MetiersPossibles.size() != 0){ + if (MetiersPossibles.size() != 0) { int NbMetier=MetiersPossibles.size(); for (EffortDescription effort : MetiersPossibles) { Metier met = effort.getPossibleMetiers(); @@ -203,7 +201,7 @@ siMatrix.getMetiers(step)); matNonActivite.setValue(Strat, metier, StratMonthInfo.getProportionMetier(metier)); - StratMonthInfo.setProportionMetier(metier,0); + StratMonthInfo.setProportionMetier(metier, 0); } } Modified: trunk/src/test/resources/test-database/rules/InterdictionEnginPreSimu.java =================================================================== --- trunk/src/test/resources/test-database/rules/InterdictionEnginPreSimu.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/InterdictionEnginPreSimu.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,9 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -70,14 +67,14 @@ @Doc(value="do the doc of param endMonth") public Month param_endMonth = Month.DECEMBER; - protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>(); + protected Map<Month, MatrixND> tableNonActivite = new HashMap<>(); protected boolean affectNonActivite = false; - public String [] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String [] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -91,7 +88,7 @@ */ @Override public String getDescription() throws Exception { - return _("Prohibited gear"); + return "Prohibited gear"; } /** @@ -159,7 +156,7 @@ matNonActiviteMois = MatrixFactory.getInstance().create( ResultName.MATRIX_NO_ACTIVITY, new List[]{ListeStrat, ListeMetiers}, - new String[]{n_("Strategies"), n_("Metiers")}); + new String[]{"Strategies", "Metiers"}); tableNonActivite.put(mois, matNonActiviteMois); } @@ -189,7 +186,7 @@ public boolean condition(SimulationContext context, TimeStep step, Metier metier) throws Exception { boolean result = false; MatrixND mat = tableNonActivite.get(step.getMonth()); - if (mat != null && affectNonActivite == false) { + if (mat != null && !affectNonActivite) { result = true; } return result; @@ -207,7 +204,7 @@ @Override public void preAction(SimulationContext context, TimeStep step, Metier metier) throws Exception { // on ne doit le faire qu'une seul fois quelque soit le nombre de metier - affectNonActivite=true; + affectNonActivite = true; MatrixND mat = tableNonActivite.get(step.getMonth()); MetierMonitor metierMon = context.getMetierMonitor(); @@ -215,10 +212,9 @@ if (noActivity == null) { metierMon.setNoActivity(step, mat.copy()); + } else { + noActivity.add(mat); } - else { - noActivity = noActivity.add(mat); - } // fin } Modified: trunk/src/test/resources/test-database/rules/TACpoids.java =================================================================== --- trunk/src/test/resources/test-database/rules/TACpoids.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/TACpoids.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.HashSet; import java.util.Set; @@ -87,13 +85,13 @@ @Doc("TAC in tons") public double param_tacInTons = 900; - boolean affectation = false; + protected boolean affectation = false; protected String[] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; /** @@ -111,7 +109,7 @@ */ @Override public String getDescription() { - return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0."); + return "TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0."; } /** Modified: trunk/src/test/resources/test-database/rules/TailleMin.java =================================================================== --- trunk/src/test/resources/test-database/rules/TailleMin.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/TailleMin.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 Ifremer, CodeLutin, Stéphanie Mahevas, 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 @@ -21,39 +21,41 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixIterator; import org.nuiton.math.matrix.MatrixND; import scripts.ResultName; -import scripts.SiMatrix; 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.Species; import fr.ifremer.isisfish.entities.TargetSpecies; +import fr.ifremer.isisfish.entities.Zone; import fr.ifremer.isisfish.rule.AbstractRule; import fr.ifremer.isisfish.simulator.PopulationMonitor; import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.util.Doc; +import java.util.List; /** - * Cette methode remplace aussi TailleMinSurvieRejet si propSurvie est > 0 + * Cette regles tient compte de la taille minimum des poissons capturable. * + * Les captures ne sont pas impactées, mais des rejets sont générés si la + * taille des poissons est inférieures à TailleMin. + * + * En cas de propSurvie positif, la matrice d'effectif est modifié + * pour tenir compte de la partie de poisson rejeté qui survi. + * * Created: 30 novembre 2006 - * - * @author anonymous <anonymous@labs.libre-entreprise.org> + * + * @author smahevas * @version $Revision: 1.1 $ - * - * Last update: $Date: 2007-01-24 18:25:34 $ - * by : $Author: bpoussin $ + * + * Last update: $Date: 2007-01-24 18:25:34 $ by : $Author: bpoussin $ */ public class TailleMin extends AbstractRule { @@ -74,12 +76,14 @@ @Doc(value = "Proportion de survie") public double param_propSurvie = 0; - - public String[] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + + protected boolean affectation = true; + + protected String[] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -94,19 +98,20 @@ */ @Override public String getDescription() throws Exception { - return _("Tous les poissons dont la taille est inférieure à TailleMin" + - " ne seront pas capturés. Ils sont placés en rejets et rejetés" + - " suivant la proportion de survie."); + return "Tous les poissons dont la taille est inférieure à TailleMin" + + " ne seront pas capturés. Ils sont placés en rejets et rejetés" + + " suivant la proportion de survie."; } /** - * Appelé au démarrage de la simulation, cette méthode permet d'initialiser - * des valeurs + * Appele au demarrage de la simulation, cette methode permet + * d'initialiser des valeurs de la règle. * - * @param context La simulation pour lequel on utilise cette regle + * @param context La simulation pour laquelle on utilise cette regle */ @Override public void init(SimulationContext context) throws Exception { + } /** @@ -135,12 +140,12 @@ * * @param context la simulation pour lequel on utilise cette regle * @param step le pas de temps courant - * @param metier le metier concerné + * @param metier le metier concerne * @return vrai si on souhaite que les actions soit faites */ @Override - public boolean condition(SimulationContext context, TimeStep step, Metier metier) - throws Exception { + public boolean condition(SimulationContext context, TimeStep step, + Metier metier) throws Exception { log.info("Recherche si la taille Minimale s'applique"); boolean result = true; if (step.before(param_beginStep)) { @@ -156,79 +161,92 @@ } /** - * Si la condition est vrai alors cette action est executee avant le pas - * de temps de la simulation. + * Si la condition est vrai alors cette action est executee avant le pas de + * temps de la simulation. * * @param context la simulation pour lequel on utilise cette regle * @param step le pas de temps courant - * @param metier le metier concerné + * @param metier le metier concerne */ @Override - public void preAction(SimulationContext context, TimeStep step, Metier metier) - throws Exception { - // nothing + public void preAction(SimulationContext context, TimeStep step, + Metier metier) throws Exception { + + affectation = true; // pour que affectation soit vraie au debut de + // chaque pas de temps pour rentrer au moins une + // fois dans postaction } /** - * Si la condition est vrai alors cette action est executée apres le pas + * Si la condition est vrai alors cette action est executee apres le pas * de temps de la simulation. * * @param context La simulation pour lequel on utilise cette regle * @param step le pas de temps courant - * @param metier le metier concerné + * @param metier le metier concerne */ @Override - public void postAction(SimulationContext context, TimeStep step, Metier metier) - throws Exception { - log.info("*$*$*$* TailleMin.actionApres:" + step + " metapop:" + - param_species + " metier:" + metier); + public void postAction(SimulationContext context, TimeStep step, + Metier metier) throws Exception { + //log.info("*$*$*$* TailleMin.actionApres:" + step + " metapop:" + // + param_species + " metier:" + metier); - if (isCaptureDate(step, param_species, metier)) { - log.info( - "*$*$*$* ok affecte capture infÃ?rieure Ã? TailleMin au rejet"); - // ATTENTION - // les captures pour cette metapop ne sont plus du qu'au metier pour qui - // l'espece est secondaire: elles sont affectees aux rejets + if (affectation) { + log.info("*$*$*$* ok affecte capture inferieure a TailleMin au rejet"); + // ATTENTION + // les captures pour cette metapop ne sont plus du qu'au metier pour + // qui l'espece est secondaire: elles sont affectees aux rejets - //pb : ne se fait pas par metier - //il faut une matrice pour chaques pas de temps qui stocke les rejets - //par metier, par metapop et par classes d'age (comme pour les captures) - ////// - log.info("deb de affecterCaptureREJETTailleMin"); + // pb : ne se fait pas par metier + // il faut une matrice pour chaques pas de temps qui stocke les + // rejets par metier, par metapop et par classes d'age (comme pour + // les captures) + //log.info("deb de affecterCaptureREJETTailleMin"); PopulationMonitor popMon = context.getPopulationMonitor(); - SiMatrix siMatrix = SiMatrix.getSiMatrix(context); - List<Population> pops = siMatrix.getPopulations(step); - for (Population pop : pops) { - if (pop.getSpecies().equals(param_species)) { - if (popMon.getDiscard(step, pop) == null) { - MatrixND discard = popMon.getCatch(pop).copy(); - MatrixND eff = popMon.getN(pop); + int groupDim = 2; + int zoneDim = 3; - for (MatrixIterator i = discard.iterator(); i.next();) { - Object[] coordonnees = i.getSemanticsCoordinates(); - PopulationGroup group = - (PopulationGroup) coordonnees[2]; - if (group.getLength() >= param_TailleMin) { - i.setValue(0); - } else if (param_propSurvie > 0) { - eff.setValue(coordonnees[2], coordonnees[3], - eff.getValue(coordonnees[2], - coordonnees[3]) + i.getValue() * - param_propSurvie); - } - } - discard.setName( - ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP); - popMon.addDiscard(step, pop, discard); + for (Population pop : param_species.getPopulation()) { + MatrixND discard = popMon.getCatch(pop).copy(); + discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP); + + MatrixND eff = popMon.getN(pop); + + // collect les tailles des groupes pour eviter de multiples appels a la methode + // getLength dans la boucle + List<PopulationGroup> groups = (List<PopulationGroup>)discard.getSemantic(2); + double[] length = new double[groups.size()]; + int cpt = 0; + for (PopulationGroup group : groups) { + length[cpt++] = group.getLength(); + } + + // on iter que sur les valeurs != 0, car si deja zero, ca ne + // sert a rien de le mettre a 0 + for (MatrixIterator i = discard.iteratorNotZero(); i.next();) { + int[] pos = i.getCoordinates(); + int groupIndex = pos[groupDim]; + if (length[groupIndex] >= param_TailleMin) { + i.setValue(0); + } else if (param_propSurvie > 0) { + Object[] coordonnees = i.getSemanticsCoordinates(); + PopulationGroup group = (PopulationGroup) coordonnees[groupDim]; + Zone zone = (Zone)coordonnees[zoneDim]; + eff.setValue(group, zone, + eff.getValue(group, zone) + + i.getValue() * param_propSurvie); } } + popMon.addDiscard(step, pop, discard); } - log.info("fin de affecterCaptureRejetTailleMin"); + //log.info("fin de affecterCaptureRejetTailleMin"); - //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire + // on a affecte une fois cette meta pop au rejet il ne faut pas le + // refaire pour ce pas de temps + affectation = false; } } } Modified: trunk/src/test/resources/test-database/rules/TotalClosure.java =================================================================== --- trunk/src/test/resources/test-database/rules/TotalClosure.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/rules/TotalClosure.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.List; import org.apache.commons.logging.Log; @@ -57,8 +55,8 @@ public Month param_beginMonth = Month.JANUARY; public Month param_endMonth = Month.JANUARY; - public String[] necessaryResult = { - ResultName.MATRIX_NO_ACTIVITY + protected String[] necessaryResult = { + ResultName.MATRIX_NO_ACTIVITY }; @Override @@ -68,7 +66,7 @@ @Override public String getDescription() throws Exception { - return _("Total closure of the fishery"); + return "Total closure of the fishery"; } /** @@ -77,6 +75,7 @@ */ @Override public void init(SimulationContext context) throws Exception { + } /** Modified: trunk/src/test/resources/test-database/scripts/GravityModel.java =================================================================== --- trunk/src/test/resources/test-database/scripts/GravityModel.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/scripts/GravityModel.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Cédric 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 @@ -22,7 +22,7 @@ package scripts; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; import java.util.Collection; import java.util.List; @@ -47,22 +47,22 @@ import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.types.Month; import fr.ifremer.isisfish.types.TimeUnit; +import org.nuiton.math.matrix.MatrixIterator; /** - * GravityModel.java - * - * Created: 4 sept. 06 15:49:08 - * + * Gravity model calcul des resultats à basés sur des resultats provenant + * de SiMatrix ou des resultat précédement calculé disponible via le + * result manager. + * + * Cette classe sert a calculer des résultats economique (prix, resultat + * servant a optimiser des cout pour les pécheurs...). + * * @author poussin - * @version $Revision: 1.9 $ - * - * Last update: $Date: 2007-03-01 17:16:12 $ - * by : $Author: bpoussin $ */ public class GravityModel { /** to use log facility, just put in your code: log.info("..."); */ - static private Log log = LogFactory.getLog(GravityModel.class); + final static private Log log = LogFactory.getLog(GravityModel.class); protected SimulationContext context = null; protected TopiaContext db = null; @@ -112,7 +112,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -157,7 +157,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -209,7 +209,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -263,7 +263,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FUEL_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -307,15 +307,29 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); + SetOfVessels sov = str.getSetOfVessels(); metiers = siMatrix.getMetiers(str, step); for (int m = 0; m < metiers.size(); m++) { Metier metier = metiers.get(m); - double value = repairAndMaintenanceGearCostsPerVessel(str, - metier, step); + + double fishingTime = 0; + double repair = 0; + + EffortDescription effort = sov.getPossibleMetiers(metier); + if (effort != null) { + repair = effort.getRepairAndMaintenanceGearCost(); + } + if (repair != 0 ) { + fishingTimePerMonthPerVessel(str, metier, step); + } + + // FIXME verifier qu'il faut bien retourner 0, si pas d'effort + double value = fishingTime * repair / TimeUnit.HOUR_PER_DAY; + result.setValue(str, metier, value); } } @@ -341,21 +355,21 @@ * @param step * @return */ - private double repairAndMaintenanceGearCostsPerVessel(Strategy str, - Metier metier, TimeStep step) { - double fishingTime = fishingTimePerMonthPerVessel(str, metier, step); +// private double repairAndMaintenanceGearCostsPerVessel(Strategy str, +// Metier metier, TimeStep step) { +// double fishingTime = fishingTimePerMonthPerVessel(str, metier, step); +// +// EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( +// metier); +// +// double repair = 0; +// if (effort != null) { +// repair = effort.getRepairAndMaintenanceGearCost(); +// } +// // FIXME verifier qu'il faut bien retourner 0, si pas d'effort +// return fishingTime * repair / TimeUnit.HOUR_PER_DAY; +// } - EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( - metier); - - double repair = 0; - if (effort != null) { - repair = effort.getRepairAndMaintenanceGearCost(); - } - // FIXME verifier qu'il faut bien retourner 0, si pas d'effort - return fishingTime * repair / TimeUnit.HOUR_PER_DAY; - } - ////////////////////////////////////////////////////////////////////// // matrixOtherRunningCostsPerVessel ////////////////////////////////////////////////////////////////////// @@ -368,7 +382,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -421,7 +435,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -470,61 +484,117 @@ .create( ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET, new List[] { strategies, metiers, pops }, - new String[] { n_("Strategies"), n_("Metiers"), - n_("Populations") }); + new String[] { n("Strategies"), n("Metiers"), + n("Populations") }); + // indice dans les matrices catch et discards + int strDim = 0; + int metierDim = 1; + int groupDim = 2; + int zoneDim = 3; + for (int p = 0; p < pops.size(); p++) { Population pop = pops.get(p); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = grossValueOfLandingsPerSpeciesPerStrategyMet( - str, metier, pop, step); - result.setValue(str, metier, pop, value); + List<PopulationGroup> groups = pop.getPopulationGroup(); + double[] prices = new double[groups.size()]; + int cpt=0; + for (PopulationGroup group : groups) { + prices[cpt++] = group.getPrice(); + } + + MatrixND matCatch = getResult_MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP(step, pop); + MatrixND matDiscards = getResult_MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP(step, pop); + + if (matCatch != null) { + for (MatrixIterator i=matCatch.iteratorNotZero(); i.next();){ + int[] pos = i.getCoordinates(); + double price = prices[pos[groupDim]]; + if (price != 0) { + double value = result.getValue(pos[strDim], pos[metierDim], p) + price * i.getValue(); + result.setValue(pos[strDim], pos[metierDim], p, value); + } } } + if (matDiscards != null) { + for (MatrixIterator i=matDiscards.iteratorNotZero(); i.next();){ + int[] pos = i.getCoordinates(); + double price = prices[pos[groupDim]]; + if (price != 0) { + double value = result.getValue(pos[strDim], pos[metierDim], p) - price * i.getValue(); + result.setValue(pos[strDim], pos[metierDim], p, value); + } + } + } } return result; - } - /** - * implante suivant document ModifTable3PourBP25-07-2006.doc - * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month]=sum over - * classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet - * [str,met,pop,cl,month] ?DiscardsWeightPerStrategyMet [str,met,pop,cl,mo - * nth] GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month] = - * sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet - * [str,met,pop,cl,month] -DiscardsWeightPerStrategyMet [str,met,pop,cl,mo - * nth])] - * - * @param str - * @param metier - * @param pop - * @param step - * @return - */ - private double grossValueOfLandingsPerSpeciesPerStrategyMet(Strategy str, - Metier metier, Population pop, TimeStep step) { - List<PopulationGroup> groups = pop.getPopulationGroup(); - double result = 0; - for (PopulationGroup group : groups) { - double price = group.getPrice(); - Collection<Zone> zones = pop.getPopulationZone(); - for (Zone zone : zones) { - double catchWeight = getCatchWeightPerStrMetPerZonePop(str, - metier, group, zone, step); - double discardsWeight = getDiscardsWeightPerStrMet(str, metier, - group, zone, step); - // FIXME demander/verifier que ce le bon calcule - result += price * (catchWeight - discardsWeight); - } - } - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// List<Population> pops = siMatrix.getPopulations(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET, +// new List[] { strategies, metiers, pops }, +// new String[] { n("Strategies"), n("Metiers"), +// n("Populations") }); +// +// for (int p = 0; p < pops.size(); p++) { +// Population pop = pops.get(p); +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = grossValueOfLandingsPerSpeciesPerStrategyMet( +// str, metier, pop, step); +// result.setValue(str, metier, pop, value); +// } +// } +// } +// +// return result; } +// /** +// * implante suivant document ModifTable3PourBP25-07-2006.doc +// * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month]=sum over +// * classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet +// * [str,met,pop,cl,month] ?DiscardsWeightPerStrategyMet [str,met,pop,cl,mo +// * nth] GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month] = +// * sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet +// * [str,met,pop,cl,month] -DiscardsWeightPerStrategyMet [str,met,pop,cl,mo +// * nth])] +// * +// * @param str +// * @param metier +// * @param pop +// * @param step +// * @return +// */ +// private double grossValueOfLandingsPerSpeciesPerStrategyMet(Strategy str, +// Metier metier, Population pop, TimeStep step) { +// List<PopulationGroup> groups = pop.getPopulationGroup(); +// double result = 0; +// for (PopulationGroup group : groups) { +// double price = group.getPrice(); +// if (price != 0) { +// Collection<Zone> zones = pop.getPopulationZone(); +// for (Zone zone : zones) { +// double catchWeight = getCatchWeightPerStrMetPerZonePop(str, +// metier, group, zone, step); +// double discardsWeight = getDiscardsWeightPerStrMet(str, metier, +// group, zone, step); +// // FIXME demander/verifier que ce le bon calcule +// result += price * (catchWeight - discardsWeight); +// } +// } +// } +// return result; +// } + /** * @param str * @param metier @@ -535,8 +605,7 @@ */ private double getCatchWeightPerStrMetPerZonePop(Strategy str, Metier metier, PopulationGroup group, Zone zone, TimeStep step) { - MatrixND mat = resultManager.getMatrix(step, group.getPopulation(), - ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); + MatrixND mat = getResult_MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP(step, group.getPopulation()); double result = 0; if (mat != null) { result = mat.getValue(str, metier, group, zone); @@ -544,6 +613,12 @@ return result; } + private MatrixND getResult_MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP(TimeStep step, Population pop) { + MatrixND mat = resultManager.getMatrix(step, pop, + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); + return mat; + } + /** * @param str * @param metier @@ -554,8 +629,7 @@ */ private double getDiscardsWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, TimeStep step) { - MatrixND mat = resultManager.getMatrix(step, group.getPopulation(), - ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); + MatrixND mat = getResult_MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP(step, group.getPopulation()); double result = 0; if (mat != null) { result = mat.getValue(str, metier, group, zone); @@ -563,81 +637,117 @@ return result; } + private MatrixND getResult_MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP(TimeStep step, Population pop) { + MatrixND mat = resultManager.getMatrix(step, pop, + ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); + return mat; + } + ////////////////////////////////////////////////////////////////////// // matrixGrossValueOfLandingsPerStrategyMet ////////////////////////////////////////////////////////////////////// public MatrixND matrixGrossValueOfLandingsPerStrategyMet(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); - MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); - - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = grossValueOfLandingsPerStrategyMet(str, metier, - step); - result.setValue(str, metier, value); - } - } - + MatrixND matPerSpecies = matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(step); + // sum over pop + MatrixND result = matPerSpecies.sumOverDim(2).reduceDims(2); + result.setName(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET); return result; - } - /** - * @param str - * @param metier - * @param step - * @return - * @throws TopiaException - */ - private double grossValueOfLandingsPerStrategyMet(Strategy str, - Metier metier, TimeStep step) throws TopiaException { - List<Population> pops = siMatrix.getPopulations(step); - double result = 0; - for (int i = 0; i < pops.size(); i++) { - Population pop = (Population) pops.get(i); - result += grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, - pop, step); - } - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory.getInstance().create( +// ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = grossValueOfLandingsPerStrategyMet(str, metier, +// step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } +// /** +// * @param str +// * @param metier +// * @param step +// * @return +// * @throws TopiaException +// */ +// private double grossValueOfLandingsPerStrategyMet(Strategy str, +// Metier metier, TimeStep step) throws TopiaException { +// List<Population> pops = siMatrix.getPopulations(step); +// double result = 0; +// for (int i = 0; i < pops.size(); i++) { +// Population pop = (Population) pops.get(i); +// result += grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, +// pop, step); +// } +// return result; +// } + ////////////////////////////////////////////////////////////////////// // matrixGrossValueOfLandingsPerStrategyMetPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixGrossValueOfLandingsPerStrategyMetPerVessel(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); + MatrixND matGrossValue = matrixGrossValueOfLandingsPerStrategyMet(step); + MatrixND result = matGrossValue.copy(); + result.setName(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + for (MatrixIterator i=result.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = grossValueOfLandingsPerStrategyMetPerVessel(str, - metier, step); - result.setValue(str, metier, value); - } + // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov) + double proportionSetOfVessels = str.getProportionSetOfVessels(); + double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); + + double grossValueOfLandingsOtherSpeciesPerStrategyMet = + grossValueOfLandingsOtherSpeciesPerStrategyMet(str, metier, step); + + double value = (i.getValue() + grossValueOfLandingsOtherSpeciesPerStrategyMet) + / (proportionSetOfVessels * numberOfVessels); + + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = grossValueOfLandingsPerStrategyMetPerVessel(str, +// metier, step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -651,47 +761,74 @@ * @return * @throws TopiaException */ - private double grossValueOfLandingsPerStrategyMetPerVessel(Strategy str, - Metier metier, TimeStep step) throws TopiaException { - double grossValueOfLandingsPerStrategyMet = grossValueOfLandingsPerStrategyMet( - str, metier, step); - // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov) - double proportionSetOfVessels = str.getProportionSetOfVessels(); - double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// private double grossValueOfLandingsPerStrategyMetPerVessel(Strategy str, +// Metier metier, TimeStep step) throws TopiaException { +// double grossValueOfLandingsPerStrategyMet = grossValueOfLandingsPerStrategyMet( +// str, metier, step); +// // FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov) +// double proportionSetOfVessels = str.getProportionSetOfVessels(); +// double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// +// double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet( +// str, metier, step); +// +// return (grossValueOfLandingsPerStrategyMet + grossValueOfLandingsOtherSpeciesPerStrategyMet) +// / (proportionSetOfVessels * numberOfVessels); +// } - double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet( - str, metier, step); - - return (grossValueOfLandingsPerStrategyMet + grossValueOfLandingsOtherSpeciesPerStrategyMet) - / (proportionSetOfVessels * numberOfVessels); - } - ////////////////////////////////////////////////////////////////////// // matrixNetValueOfLandingsPerStrategyMet ////////////////////////////////////////////////////////////////////// public MatrixND matrixNetValueOfLandingsPerStrategyMet(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); - MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + MatrixND result = matrixGrossValueOfLandingsPerStrategyMet(step).copy(); + result.setName(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET); + + for (MatrixIterator i=result.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = netValueOfLandingsPerStrategyMet(str, metier, - step); - result.setValue(str, metier, value); + EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( + metier); + double landingCost = 1; + // FIXME demander si le metier n'a pas d'effort s'il faut que landingCost soit bien a 1 + if (effort != null) { + landingCost -= effort.getLandingCosts(); } + + double grossValueOfLandingsOtherSpeciesPerStrategyMet = + grossValueOfLandingsOtherSpeciesPerStrategyMet(str, metier, step); + + double value = (i.getValue() + grossValueOfLandingsOtherSpeciesPerStrategyMet) + * landingCost; + i.setValue(value); } + return result; - return result; + +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory.getInstance().create( +// ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = netValueOfLandingsPerStrategyMet(str, metier, +// step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -699,33 +836,33 @@ * NetValueOfLandingsPerStrategyMet[str,met,month] = * GrossValueOfLandingsPerStrategyMet[str,met,month] * (1-LandingCostRate[str,met]) - * + * * @param str * @param metier * @param step * @return * @throws TopiaException */ - private double netValueOfLandingsPerStrategyMet(Strategy str, - Metier metier, TimeStep step) throws TopiaException { - double grossValue = grossValueOfLandingsPerStrategyMet(str, metier, - step); - EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( - metier); - double landingCost = 1; - // FIXME demander si le metier n'a pas d'effort s'il faut que landingCost soit bien a 1 - if (effort != null) { - landingCost -= effort.getLandingCosts(); - } +// private double netValueOfLandingsPerStrategyMet(Strategy str, +// Metier metier, TimeStep step) throws TopiaException { +// double grossValue = grossValueOfLandingsPerStrategyMet(str, metier, +// step); +// EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( +// metier); +// double landingCost = 1; +// // FIXME demander si le metier n'a pas d'effort s'il faut que landingCost soit bien a 1 +// if (effort != null) { +// landingCost -= effort.getLandingCosts(); +// } +// +// double grossValueOfLandingsOtherSpeciesPerStrategyMet = +// grossValueOfLandingsOtherSpeciesPerStrategyMet(str, metier, step); +// +// double result = (grossValue + grossValueOfLandingsOtherSpeciesPerStrategyMet) +// * landingCost; +// return result; +// } - double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet( - str, metier, step); - - double result = (grossValue + grossValueOfLandingsOtherSpeciesPerStrategyMet) - * landingCost; - return result; - } - private double grossValueOfLandingsOtherSpeciesPerStrategyMet(Strategy str, Metier metier, TimeStep step) throws TopiaException { // FIXME evaluer l'equation dans suivant le doc des equations @@ -738,28 +875,51 @@ public MatrixND matrixNetValueOfLandingsPerStrategyMetPerVessel(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); + MatrixND result = matrixNetValueOfLandingsPerStrategyMet(step).copy(); + result.setName(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + for(MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = netValueOfLandingsPerStrategyMetPerVessel(str, - metier, step); - result.setValue(str, metier, value); + // FIXME verifier que c bien cette donnée qu'il faut utiliser dans le doc: PropNbVessels(str, sov) + double proportionSetOfVessels = str.getProportionSetOfVessels(); + double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); + + double div = proportionSetOfVessels * numberOfVessels; + + if (div != 0) { + double value = i.getValue() / div; + + i.setValue(value); } } return result; + +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = netValueOfLandingsPerStrategyMetPerVessel(str, +// metier, step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -774,46 +934,65 @@ * @return * @throws TopiaException */ - private double netValueOfLandingsPerStrategyMetPerVessel(Strategy str, - Metier metier, TimeStep step) throws TopiaException { - double netValueOfLandingsPerStrategyMet = netValueOfLandingsPerStrategyMet( - str, metier, step); - // FIXME verifier que c bien cette donnée qu'il faut utiliser dans le doc: PropNbVessels(str, sov) - double proportionSetOfVessels = str.getProportionSetOfVessels(); - double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// private double netValueOfLandingsPerStrategyMetPerVessel(Strategy str, +// Metier metier, TimeStep step) throws TopiaException { +// double netValueOfLandingsPerStrategyMet = netValueOfLandingsPerStrategyMet( +// str, metier, step); +// // FIXME verifier que c bien cette donnée qu'il faut utiliser dans le doc: PropNbVessels(str, sov) +// double proportionSetOfVessels = str.getProportionSetOfVessels(); +// double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// +// return netValueOfLandingsPerStrategyMet +// / (proportionSetOfVessels * numberOfVessels); +// } - return netValueOfLandingsPerStrategyMet - / (proportionSetOfVessels * numberOfVessels); - } - ////////////////////////////////////////////////////////////////////// // matrixNetRenevueToSharePerStrategyMetPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixNetRenevueToSharePerStrategyMetPerVessel(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + MatrixND result = matrixNetValueOfLandingsPerStrategyMetPerVessel(step).copy(); + result.setName(ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = netRenevueToSharePerStrategyMetPerVessel(str, - metier, step); - result.setValue(str, metier, value); - } + for(MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; + + double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str, + metier, step); + double propStr = str.getStrategyMonthInfo(step.getMonth()) + .getProportionMetier(metier); + + double value = i.getValue() - sharedNotFixedCostsPerVessel * propStr; + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = netRenevueToSharePerStrategyMetPerVessel(str, +// metier, step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -829,46 +1008,68 @@ * @return * @throws TopiaException */ - private double netRenevueToSharePerStrategyMetPerVessel(Strategy str, - Metier metier, TimeStep step) throws TopiaException { - double netRenevueToSharePerStrategyMetPerVessel = netValueOfLandingsPerStrategyMetPerVessel( - str, metier, step); - double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str, - metier, step); - double propStr = str.getStrategyMonthInfo(step.getMonth()) - .getProportionMetier(metier); +// private double netRenevueToSharePerStrategyMetPerVessel(Strategy str, +// Metier metier, TimeStep step) throws TopiaException { +// double netRenevueToSharePerStrategyMetPerVessel = netValueOfLandingsPerStrategyMetPerVessel( +// str, metier, step); +// double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str, +// metier, step); +// double propStr = str.getStrategyMonthInfo(step.getMonth()) +// .getProportionMetier(metier); +// +// double result = netRenevueToSharePerStrategyMetPerVessel +// - sharedNotFixedCostsPerVessel * propStr; +// return result; +// } - double result = netRenevueToSharePerStrategyMetPerVessel - - sharedNotFixedCostsPerVessel * propStr; - return result; - } - ////////////////////////////////////////////////////////////////////// // matrixCrewSharePerStrategyMetPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixCrewSharePerStrategyMetPerVessel(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); - MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + MatrixND result = matrixNetValueOfLandingsPerStrategyMetPerVessel(step).copy(); + result.setName(ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = crewSharePerStrategyMetPerVessel(str, metier, - step); - result.setValue(str, metier, value); + for(MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; + + EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( + metier); + + double crewShareRate = 0; + if (effort != null) { + crewShareRate = effort.getCrewShareRate(); } + // FIXME verifier qu'il faut bien retourner 0, si pas d'effort + double value = i.getValue() * crewShareRate; + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory.getInstance().create( +// ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = crewSharePerStrategyMetPerVessel(str, metier, +// step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -882,50 +1083,79 @@ * @return * @throws TopiaException */ - private double crewSharePerStrategyMetPerVessel(Strategy str, - Metier metier, TimeStep step) throws TopiaException { - double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel( - str, metier, step); +// private double crewSharePerStrategyMetPerVessel(Strategy str, +// Metier metier, TimeStep step) throws TopiaException { +// double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel( +// str, metier, step); +// +// EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( +// metier); +// +// double crewShareRate = 0; +// if (effort != null) { +// crewShareRate = effort.getCrewShareRate(); +// } +// // FIXME verifier qu'il faut bien retourner 0, si pas d'effort +// return netRenevueToShare * crewShareRate; +// } - EffortDescription effort = str.getSetOfVessels().getPossibleMetiers( - metier); - - double crewShareRate = 0; - if (effort != null) { - crewShareRate = effort.getCrewShareRate(); - } - // FIXME verifier qu'il faut bien retourner 0, si pas d'effort - return netRenevueToShare * crewShareRate; - } - ////////////////////////////////////////////////////////////////////// // matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel( TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + MatrixND matRepair = matrixRepairAndMaintenanceGearCostsPerVessel(step); + MatrixND matCrew = matrixCrewSharePerStrategyMetPerVessel(step); + MatrixND matRevenue = matrixNetRenevueToSharePerStrategyMetPerVessel(step); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel( - str, metier, step); - result.setValue(str, metier, value); + MatrixND result = matRevenue.copy(); + result.setName(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL); + + for(MatrixIterator i=result.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; + + double propStr = str.getStrategyMonthInfo(step.getMonth()) + .getProportionMetier(metier); + + double netRenevueToShare = i.getValue(); + double crewShare = matCrew.getValue(str, metier); + double repair = 0; + if (propStr != 0) { + repair = matRepair.getValue(str, metier); } + + double value = netRenevueToShare - crewShare - repair * propStr; + i.setValue(value); } return result; + +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel( +// str, metier, step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -942,47 +1172,71 @@ * @return * @throws TopiaException */ - private double ownerMarginOverVariableCostsPerStrategyMetPerVessel( - Strategy str, Metier metier, TimeStep step) throws TopiaException { - double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel( - str, metier, step); - double crewShare = crewSharePerStrategyMetPerVessel(str, metier, step); - double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, - step); - double propStr = str.getStrategyMonthInfo(step.getMonth()) - .getProportionMetier(metier); +// private double ownerMarginOverVariableCostsPerStrategyMetPerVessel( +// Strategy str, Metier metier, TimeStep step) throws TopiaException { +// double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel( +// str, metier, step); +// double crewShare = crewSharePerStrategyMetPerVessel(str, metier, step); +// double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, +// step); +// double propStr = str.getStrategyMonthInfo(step.getMonth()) +// .getProportionMetier(metier); +// +// return netRenevueToShare - crewShare - repair * propStr; +// } - return netRenevueToShare - crewShare - repair * propStr; - } - ////////////////////////////////////////////////////////////////////// // matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel( TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - List<Metier> metiers = siMatrix.getMetiers(step); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL, - new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + MatrixND matRepair = matrixRepairAndMaintenanceGearCostsPerVessel(step); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = siMatrix.getMetiers(str, step); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel( - str, metier, step); - result.setValue(str, metier, value); + MatrixND result = matrixNetValueOfLandingsPerStrategyMetPerVessel(step).copy(); + result.setName(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL); + + for(MatrixIterator i=result.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + Metier metier = (Metier)sems[1]; + + double repair = 0; + double propStr = str.getStrategyMonthInfo(step.getMonth()) + .getProportionMetier(metier); + if (propStr != 0) { + // optimisation repair ne sert pas si propStr == 0, donc on va pas le chercher + repair = matRepair.getValue(str, metier); } + + double value = i.getValue() - repair * propStr; + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// List<Metier> metiers = siMatrix.getMetiers(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL, +// new List[] { strategies, metiers }, +// new String[] { n("Strategies"), n("Metiers") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// metiers = siMatrix.getMetiers(str, step); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel( +// str, metier, step); +// result.setValue(str, metier, value); +// } +// } +// +// return result; } /** @@ -998,41 +1252,67 @@ * @return * @throws TopiaException */ - private double vesselMarginOverVariableCostsPerStrategyMetPerVessel( - Strategy str, Metier metier, TimeStep step) throws TopiaException { - double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel( - str, metier, step); - double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, - step); - double propStr = str.getStrategyMonthInfo(step.getMonth()) - .getProportionMetier(metier); +// private double vesselMarginOverVariableCostsPerStrategyMetPerVessel( +// Strategy str, Metier metier, TimeStep step) throws TopiaException { +// double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel( +// str, metier, step); +// double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, +// step); +// double propStr = str.getStrategyMonthInfo(step.getMonth()) +// .getProportionMetier(metier); +// +// return netRenevueToShare - repair * propStr; +// } - return netRenevueToShare - repair * propStr; - } - ////////////////////////////////////////////////////////////////////// // matrixOwnerMarginOverVariableCostsPerStrategyPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyPerVessel( TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); + MatrixND matOwner = matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(step); MatrixND result = MatrixFactory .getInstance() .create( ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL, - new List[] { strategies }, - new String[] { n_("Strategies") }); + new List[] { matOwner.getSemantic(0) }, + new String[] { n("Strategies") }); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - double value = ownerMarginOverVariableCostsPerStrategyPerVessel( - str, step); - result.setValue(s, value); + for(MatrixIterator i=result.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + + SetOfVessels sov = str.getSetOfVessels(); + Collection<EffortDescription> efforts = sov.getPossibleMetiers(); + + double value = 0; + + for (EffortDescription effort : efforts) { + Metier metier = effort.getPossibleMetiers(); + value += matOwner.getValue(str, metier); + } + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL, +// new List[] { strategies }, +// new String[] { n("Strategies") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// double value = ownerMarginOverVariableCostsPerStrategyPerVessel( +// str, step); +// result.setValue(s, value); +// } +// +// return result; } /** @@ -1046,43 +1326,58 @@ * @return * @throws TopiaException */ - private double ownerMarginOverVariableCostsPerStrategyPerVessel( - Strategy str, TimeStep step) throws TopiaException { - SetOfVessels sov = str.getSetOfVessels(); - Collection<EffortDescription> efforts = sov.getPossibleMetiers(); +// private double ownerMarginOverVariableCostsPerStrategyPerVessel( +// Strategy str, TimeStep step) throws TopiaException { +// SetOfVessels sov = str.getSetOfVessels(); +// Collection<EffortDescription> efforts = sov.getPossibleMetiers(); +// +// float result = 0; +// +// for (EffortDescription effort : efforts) { +// Metier metier = effort.getPossibleMetiers(); +// result += ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, +// metier, step); +// } +// return result; +// } - float result = 0; - - for (EffortDescription effort : efforts) { - Metier metier = effort.getPossibleMetiers(); - result += ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, - metier, step); - } - return result; - } - ////////////////////////////////////////////////////////////////////// // matrixOwnerMarginOverVariableCostsPerStrategy ////////////////////////////////////////////////////////////////////// public MatrixND matrixOwnerMarginOverVariableCostsPerStrategy(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); + MatrixND result = matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(step).copy(); + result.setName(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY, - new List[] { strategies }, - new String[] { n_("Strategies") }); + for(MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - double value = ownerMarginOverVariableCostsPerStrategy(str, step); - result.setValue(s, value); + double proportionSetOfVessels = str.getProportionSetOfVessels(); + double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); + + double value = i.getValue() * (proportionSetOfVessels * numberOfVessels); + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY, +// new List[] { strategies }, +// new String[] { n("Strategies") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// double value = ownerMarginOverVariableCostsPerStrategy(str, step); +// result.setValue(s, value); +// } +// +// return result; } /** @@ -1096,40 +1391,69 @@ * @return * @throws TopiaException */ - private double ownerMarginOverVariableCostsPerStrategy(Strategy str, - TimeStep step) throws TopiaException { - double ownerMarginOverVariableCostsPerStrategyPerVessel = ownerMarginOverVariableCostsPerStrategyPerVessel( - str, step); - double proportionSetOfVessels = str.getProportionSetOfVessels(); - double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// private double ownerMarginOverVariableCostsPerStrategy(Strategy str, +// TimeStep step) throws TopiaException { +// double ownerMarginOverVariableCostsPerStrategyPerVessel = ownerMarginOverVariableCostsPerStrategyPerVessel( +// str, step); +// double proportionSetOfVessels = str.getProportionSetOfVessels(); +// double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// +// return ownerMarginOverVariableCostsPerStrategyPerVessel +// * (proportionSetOfVessels * numberOfVessels); +// } - return ownerMarginOverVariableCostsPerStrategyPerVessel - * (proportionSetOfVessels * numberOfVessels); - } - ////////////////////////////////////////////////////////////////////// // matrixVesselMarginOverVariableCostsPerStrategyPerVessel ////////////////////////////////////////////////////////////////////// public MatrixND matrixVesselMarginOverVariableCostsPerStrategyPerVessel( TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); + MatrixND matPerMet = + matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(step); MatrixND result = MatrixFactory .getInstance() .create( ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL, - new List[] { strategies }, - new String[] { n_("Strategies") }); + new List[] { matPerMet.getSemantic(0) }, + new String[] { n("Strategies") }); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - double value = vesselMarginOverVariableCostsPerStrategyPerVessel( - str, step); - result.setValue(s, value); + for(MatrixIterator i=result.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + + SetOfVessels sov = str.getSetOfVessels(); + Collection<EffortDescription> efforts = sov.getPossibleMetiers(); + + double value = 0; + + for (EffortDescription effort : efforts) { + Metier metier = effort.getPossibleMetiers(); + value += matPerMet.getValue(str, metier); + } + + i.setValue(value); } + return result; - return result; + +// List<Strategy> strategies = siMatrix.getStrategies(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL, +// new List[] { strategies }, +// new String[] { n("Strategies") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// double value = vesselMarginOverVariableCostsPerStrategyPerVessel( +// str, step); +// result.setValue(s, value); +// } +// +// return result; } /** @@ -1143,43 +1467,59 @@ * @return * @throws TopiaException */ - private double vesselMarginOverVariableCostsPerStrategyPerVessel( - Strategy str, TimeStep step) throws TopiaException { - SetOfVessels sov = str.getSetOfVessels(); - Collection<EffortDescription> efforts = sov.getPossibleMetiers(); +// private double vesselMarginOverVariableCostsPerStrategyPerVessel( +// Strategy str, TimeStep step) throws TopiaException { +// SetOfVessels sov = str.getSetOfVessels(); +// Collection<EffortDescription> efforts = sov.getPossibleMetiers(); +// +// float result = 0; +// +// for (EffortDescription effort : efforts) { +// Metier metier = effort.getPossibleMetiers(); +// result += vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, +// metier, step); +// } +// return result; +// } - float result = 0; - - for (EffortDescription effort : efforts) { - Metier metier = effort.getPossibleMetiers(); - result += vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, - metier, step); - } - return result; - } - ////////////////////////////////////////////////////////////////////// // matrixVesselMarginOverVariableCostsPerStrategy ////////////////////////////////////////////////////////////////////// public MatrixND matrixVesselMarginOverVariableCostsPerStrategy(TimeStep step) throws TopiaException { - List<Strategy> strategies = siMatrix.getStrategies(step); - MatrixND result = MatrixFactory - .getInstance() - .create( - ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY, - new List[] { strategies }, - new String[] { n_("Strategies") }); + MatrixND result = matrixVesselMarginOverVariableCostsPerStrategyPerVessel(step).copy(); + result.setName(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY); - for (int s = 0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - double value = vesselMarginOverVariableCostsPerStrategy(str, step); - result.setValue(s, value); + for(MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); + Strategy str = (Strategy)sems[0]; + + double proportionSetOfVessels = str.getProportionSetOfVessels(); + double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); + + double value = i.getValue() * (proportionSetOfVessels * numberOfVessels); + i.setValue(value); } + return result; - return result; +// List<Strategy> strategies = siMatrix.getStrategies(step); +// +// MatrixND result = MatrixFactory +// .getInstance() +// .create( +// ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY, +// new List[] { strategies }, +// new String[] { n("Strategies") }); +// +// for (int s = 0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// double value = vesselMarginOverVariableCostsPerStrategy(str, step); +// result.setValue(s, value); +// } +// +// return result; } /** @@ -1193,17 +1533,17 @@ * @return * @throws TopiaException */ - private double vesselMarginOverVariableCostsPerStrategy(Strategy str, - TimeStep step) throws TopiaException { - double vesselMarginOverVariableCostsPerStrategyPerVessel = vesselMarginOverVariableCostsPerStrategyPerVessel( - str, step); - double proportionSetOfVessels = str.getProportionSetOfVessels(); - double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// private double vesselMarginOverVariableCostsPerStrategy(Strategy str, +// TimeStep step) throws TopiaException { +// double vesselMarginOverVariableCostsPerStrategyPerVessel = vesselMarginOverVariableCostsPerStrategyPerVessel( +// str, step); +// double proportionSetOfVessels = str.getProportionSetOfVessels(); +// double numberOfVessels = str.getSetOfVessels().getNumberOfVessels(); +// +// return vesselMarginOverVariableCostsPerStrategyPerVessel +// * (proportionSetOfVessels * numberOfVessels); +// } - return vesselMarginOverVariableCostsPerStrategyPerVessel - * (proportionSetOfVessels * numberOfVessels); - } - /////////////////////////////////////////////////////////////////////////// // // Methode non utilisee directement dans GravityModel, mais dans les rules @@ -1216,28 +1556,27 @@ double result = 0; - for (Population pop : pops) { - List<PopulationGroup> groups = pop.getPopulationGroup(); - Collection<Zone> zones = pop.getPopulationZone(); - for (PopulationGroup group : groups) { - double price = group.getPrice(); - for (Zone zone : zones) { - double catchValue = getCatchWeightPerStrMetPerZonePop(str, - metier, group, zone, step); - double discards = getDiscardsWeightPerStrMet(str, metier, - group, zone, step); - result += price * (catchValue - discards); + double effort = getEffortPerStrategyMet(str, metier, step); + if (effort != 0) { + for (Population pop : pops) { + List<PopulationGroup> groups = pop.getPopulationGroup(); + for (PopulationGroup group : groups) { + double price = group.getPrice(); + if (price != 0) { + Collection<Zone> zones = pop.getPopulationZone(); + for (Zone zone : zones) { + double catchValue = getCatchWeightPerStrMetPerZonePop(str, + metier, group, zone, step); + double discards = getDiscardsWeightPerStrMet(str, metier, + group, zone, step); + result += price * (catchValue - discards); + } + } } } + result = result / effort; } - double effort = getEffortPerStrategyMet(str, metier, step); - - if (effort == 0) { - result = 0; - } else { - result = result / effort; - } // FIXME verifier qu'il faut bien retourner 0, si pas d'effort return result; } Added: trunk/src/test/resources/test-database/scripts/MinimisationUtil.java =================================================================== --- trunk/src/test/resources/test-database/scripts/MinimisationUtil.java (rev 0) +++ trunk/src/test/resources/test-database/scripts/MinimisationUtil.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,176 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2012, 2014 Ifremer, CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.util.Nocache; + +public class MinimisationUtil { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(MinimisationUtil.class); + + /** + * Algo de minimisation de fmin(step, x,C,M,N) sur x. + * + * en prenant une valeur initiale de x dans [a,b] et une tolerance = tol + * Reference de l'algo : http://www1.fpl.fs.fed.us/optimization.html + * Algorithme de Brent qui approxime la fonction a minimiser par une + * parabole si possible et fait du "golden step" sinon + * + * @param a + * @param b + * @param tol tolérance + * @param f fonction d'objectif + * @return + */ + @Nocache + public static double fmin(double a, double b, double tol, ObjectiveFunction f) { + + double c, d, e, eps, xm, p, q, r, tol1, t2, u, v, w, fu, fv, fw, fx, x, tol3; + + c = .5 * (3.0 - Math.sqrt(5.0)); + d = 0.0; + eps = 1.2e-16; // 1.1102e-16 is machine precision + tol1 = eps + 1.0; + eps = Math.sqrt(eps); + v = a + c * (b - a); + // log.info("Finit=" + v); + w = v; + x = v; + e = 0.0; + fx = 0.0; + fu = 0.0; + + fx = f.compute(x); + // log.info("fx= " + fx); + + fv = fx; + fw = fx; + tol3 = tol / 3.0; + xm = .5 * (a + b); + tol1 = eps * Math.abs(x) + tol3; + t2 = 2.0 * tol1; + + while (Math.abs(x - xm) > (t2 - .5 * (b - a))) { // main loop; + // ///// De là... + p = q = r = 0.0; + if (Math.abs(e) > tol1) { // fit the parabola; + r = (x - w) * (fx - fv); + q = (x - v) * (fx - fw); + p = (x - v) * q - (x - w) * r; + q = 2.0 * (q - r); + if (q > 0.0) { + p = -p; + } else { + q = -q; + } + r = e; + e = d; + } + if ((Math.abs(p) < Math.abs(.5 * q * r)) && (p > q * (a - x)) + && (p < q * (b - x))) { // parabolic interpolation step; + d = p / q; + u = x + d; + if (((u - a) < t2) || ((b - u) < t2)) { // f must not be + // evaluated too close + // to a or b; + d = tol1; + if (x >= xm) + d = -d; + } + } else { // a golden-section step; + if (x < xm) { + e = b - x; + } else { + e = a - x; + } + d = c * e; + } + if (Math.abs(d) >= tol1) { // f must not be evaluated too close to x; + u = x + d; + } else { + if (d > 0.0) { + u = x + tol1; + } else { + u = x - tol1; + } + } + // ... à ici : ne sert qu'à calculer un u (selon 2 manières + // différentes) afin de comparer fx a fu + // --> On peut très bien prendre u à partir d'une autre simu a + // la place (?) + + fu = f.compute(u); + //log.info("fu= " + fu); + + // Update a, b, v, w, and x + if (fx <= fu) { + if (u < x) { + a = u; + } else { + b = u; + } + } + if (fu <= fx) { + if (u < x) { + b = x; + } else { + a = x; + } + v = w; + fv = fw; + w = x; + fw = fx; + x = u; + fx = fu; + xm = .5 * (a + b); + tol1 = eps * Math.abs(x) + tol3; + t2 = 2.0 * tol1; + } else { + if ((fu <= fw) || (w == x)) { + v = w; + fv = fw; + w = u; + fw = fu; + xm = .5 * (a + b); + tol1 = eps * Math.abs(x) + tol3; + t2 = 2.0 * tol1; + } else if ((fu > fv) && (v != x) && (v != w)) { + xm = .5 * (a + b); + tol1 = eps * Math.abs(x) + tol3; + t2 = 2.0 * tol1; + } else { + v = u; + fv = fu; + xm = .5 * (a + b); + tol1 = eps * Math.abs(x) + tol3; + t2 = 2.0 * tol1; + } + } + } + return x; + } +} Property changes on: trunk/src/test/resources/test-database/scripts/MinimisationUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/src/test/resources/test-database/scripts/ObjectiveFunction.java =================================================================== --- trunk/src/test/resources/test-database/scripts/ObjectiveFunction.java (rev 0) +++ trunk/src/test/resources/test-database/scripts/ObjectiveFunction.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,44 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2012, 2014 Ifremer, CodeLutin, lgasche + * %% + * 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; + +/** + * ObjectiveFunction.java + * + * Created: 10 aout 2012 + * + * @author lgasche + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public abstract class ObjectiveFunction { + + /** + * Compute value depending on objective function implementation + * @param x + * @return + */ + public abstract double compute(double x); +} \ No newline at end of file Property changes on: trunk/src/test/resources/test-database/scripts/ObjectiveFunction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/src/test/resources/test-database/scripts/ObjectiveFunctionBaranov.java =================================================================== --- trunk/src/test/resources/test-database/scripts/ObjectiveFunctionBaranov.java (rev 0) +++ trunk/src/test/resources/test-database/scripts/ObjectiveFunctionBaranov.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,53 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2012, 2014 Ifremer, CodeLutin, lgasche + * %% + * 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 fr.ifremer.isisfish.util.Nocache; + +/** + * FonctionObjectif_Baranov.java + * + * Created: 10 aout 2012 + * + * @author lgasche <user.name@vcs.hostName> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +@Nocache +public class ObjectiveFunctionBaranov extends ObjectiveFunction { + + protected double C, M, N; + + public ObjectiveFunctionBaranov(double C, double M, double N) { // step ?? + this.C = C; + this.M = M; + this.N = N; + } + + public double compute(double xx) { + double ff = Math.pow((C - (xx/(xx+M))*(1-Math.exp(-(xx+M)))*N),2); + return ff; + } +} \ No newline at end of file Property changes on: trunk/src/test/resources/test-database/scripts/ObjectiveFunctionBaranov.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/test/resources/test-database/scripts/ResultName.java =================================================================== --- trunk/src/test/resources/test-database/scripts/ResultName.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/scripts/ResultName.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2014 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 @@ -22,7 +22,7 @@ package scripts; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; import fr.ifremer.isisfish.util.Doc; // pour pouvoir afficher une aide contextuelle (BUG#1605) @@ -51,7 +51,7 @@ * Dimension 4 : Zone */ @Doc(value = "do the doc of Result matrixDiscardsWeightPerStrMet") - static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsWeightPerStrMetPerZonePop"); + static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP = n("matrixDiscardsWeightPerStrMetPerZonePop"); /** * Matrix with five dimensions @@ -62,7 +62,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixDiscardsPerStrMet") - static final public String MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsPerStrMetPerZonePop"); + static final public String MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP = n("matrixDiscardsPerStrMetPerZonePop"); /** * Matrix with five dimensions @@ -73,7 +73,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixLandingPerMet") - static final public String MATRIX_LANDING_PER_MET = n_("matrixLandingPerMet"); + static final public String MATRIX_LANDING_PER_MET = n("matrixLandingPerMet"); /** * Matrix with three dimensions @@ -82,7 +82,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixEffortPerStrategyMet") - static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n_("matrixEffortPerStrategyMet"); + static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n("matrixEffortPerStrategyMet"); /** * Matrix with three dimensions @@ -91,7 +91,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixEffortNominalPerStrategyMet") - static final public String MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET = n_("matrixEffortNominalPerStrategyMet"); + static final public String MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET = n("matrixEffortNominalPerStrategyMet"); /** * Matrix with five dimensions @@ -102,7 +102,7 @@ * Dimension 5 : Zone */ @Doc(value = "Disponible uniquement avec les simulations par Zone. do the doc of Result matrixCatchRatePerStrategyMet") - static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchRatePerStrategyMet"); + static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP = n("matrixCatchRatePerStrategyMet"); /** * Matrix with five dimensions @@ -111,9 +111,12 @@ * Dimension 3 : Metier * Dimension 4 : Group * Dimension 5 : Zone + * + * N'est calculé que si l'effort est calculé par cellule et non par zone. + * @see simulators.SimulatorEffortByCell */ @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet") - static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchPerStrategyMetPerZoneMet"); + static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n("matrixCatchPerStrategyMetPerZoneMet"); /** * Matrix with five dimensions @@ -124,7 +127,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZonePop") - static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchPerStrategyMetPerZonePop"); + static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP = n("matrixCatchPerStrategyMetPerZonePop"); /** * Matrix with five dimensions @@ -133,9 +136,12 @@ * Dimension 3 : Metier * Dimension 4 : Group * Dimension 5 : Zone + * + * N'est calculé que si l'effort est calculé par cellule et non par zone. + * @see simulators.SimulatorEffortByCell */ @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet") - static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchWeightPerStrategyMetPerZoneMet"); + static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n("matrixCatchWeightPerStrategyMetPerZoneMet"); /** * Matrix with five dimensions @@ -146,7 +152,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZonePop") - static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchWeightPerStrategyMetPerZonePop"); + static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP = n("matrixCatchWeightPerStrategyMetPerZonePop"); /** * Matrix with five dimensions @@ -157,8 +163,23 @@ * Dimension 5 : Zone */ @Doc(value = "Disponible uniquement avec les simulations par Zone. do the doc of Result matrixFishingMortality") - static final public String MATRIX_FISHING_MORTALITY = n_("matrixFishingMortality"); + static final public String MATRIX_FISHING_MORTALITY = n("matrixFishingMortality"); + /** + * Matrix with 1 dimension + * Dimension 1 : TimeStep + */ + @Doc(value = "do the doc of Result matrixTotalFishingMortality") + static final public String MATRIX_TOTAL_FISHING_MORTALITY = n("matrixTotalFishingMortality"); + + /** + * Matrix with 2 dimensions + * Dimension 1 : TimeStep + * Dimension 2 : Group + */ + @Doc(value = "do the doc of Result matrixFishingMortalityPerGroup") + static final public String MATRIX_FISHING_MORTALITY_PER_GROUP = n("matrixFishingMortalityPerGroup"); + /** * Matrix with three dimensions * Dimension 1 : TimeStep @@ -166,7 +187,7 @@ * Dimension 3 : Zone (semantics : Dimension 2) */ @Doc(value = "do the doc of Result matrixAbundance") - static final public String MATRIX_ABUNDANCE = n_("matrixAbundance"); + static final public String MATRIX_ABUNDANCE = n("matrixAbundance"); /** * Matrix with three dimensions @@ -175,7 +196,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixAbundanceBeginMonth") - static final public String MATRIX_ABUNDANCE_BEGIN_MONTH = n_("matrixAbundanceBeginMonth"); + static final public String MATRIX_ABUNDANCE_BEGIN_MONTH = n("matrixAbundanceBeginMonth"); /** * Matrix with three dimensions @@ -184,7 +205,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixBiomass") - static final public String MATRIX_BIOMASS = n_("matrixBiomass"); + static final public String MATRIX_BIOMASS = n("matrixBiomass"); /** * Matrix with three dimensions @@ -193,7 +214,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixBiomassBeginMonth") - static final public String MATRIX_BIOMASS_BEGIN_MONTH = n_("matrixBiomassBeginMonth"); + static final public String MATRIX_BIOMASS_BEGIN_MONTH = n("matrixBiomassBeginMonth"); /** * Matrix with three dimensions @@ -202,7 +223,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixFishingTimePerMonthPerVessel") - static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n_("matrixFishingTimePerMonthPerVessel"); + static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n("matrixFishingTimePerMonthPerVessel"); /** * Matrix with three dimensions @@ -211,7 +232,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixFuelCostsOfTravelPerVessel") - static final public String MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL = n_("matrixFuelCostsOfTravelPerVessel"); + static final public String MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL = n("matrixFuelCostsOfTravelPerVessel"); /** * Matrix with three dimensions @@ -220,7 +241,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixCostsOfFishingPerVessel") - static final public String MATRIX_COSTS_OF_FISHING_PER_VESSEL = n_("matrixCostsOfFishingPerVessel"); + static final public String MATRIX_COSTS_OF_FISHING_PER_VESSEL = n("matrixCostsOfFishingPerVessel"); /** * Matrix with three dimensions @@ -229,7 +250,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixFuelCostsPerVessel") - static final public String MATRIX_FUEL_COSTS_PER_VESSEL = n_("matrixFuelCostsPerVessel"); + static final public String MATRIX_FUEL_COSTS_PER_VESSEL = n("matrixFuelCostsPerVessel"); /** * Matrix with three dimensions @@ -238,7 +259,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixRepairAndMaintenanceGearCostsPerVessel") - static final public String MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL = n_("matrixRepairAndMaintenanceGearCostsPerVessel"); + static final public String MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL = n("matrixRepairAndMaintenanceGearCostsPerVessel"); /** * Matrix with three dimensions @@ -247,7 +268,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixOtherRunningCostsPerVessel") - static final public String MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL = n_("matrixOtherRunningCostsPerVessel"); + static final public String MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL = n("matrixOtherRunningCostsPerVessel"); /** * Matrix with three dimensions @@ -256,7 +277,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixSharedNotFixedCostsPerVessel") - static final public String MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL = n_("matrixSharedNotFixedCostsPerVessel"); + static final public String MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL = n("matrixSharedNotFixedCostsPerVessel"); /** * Matrix with four dimensions @@ -266,7 +287,7 @@ * Dimension 4 : Population */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerSpeciesPerStrategyMet") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet"); /** * Matrix with three dimensions @@ -275,7 +296,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerStrategyMet") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerStrategyMet"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n("matrixGrossValueOfLandingsPerStrategyMet"); /** * Matrix with three dimensions @@ -286,7 +307,7 @@ * Matrix calculated in the non generic Rule : GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET = n("matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet"); /** * Matrix with three dimensions @@ -295,7 +316,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerStrategyMetPerVessel") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixGrossValueOfLandingsPerStrategyMetPerVessel"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n("matrixGrossValueOfLandingsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -304,7 +325,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNetValueOfLandingsPerStrategyMet") - static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixNetValueOfLandingsPerStrategyMet"); + static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n("matrixNetValueOfLandingsPerStrategyMet"); /** * Matrix with three dimensions @@ -313,7 +334,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNetValueOfLandingsPerStrategyMetPerVessel") - static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetValueOfLandingsPerStrategyMetPerVessel"); + static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n("matrixNetValueOfLandingsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -322,7 +343,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNetRenevueToSharePerStrategyMetPerVessel") - static final public String MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetRenevueToSharePerStrategyMetPerVessel"); + static final public String MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL = n("matrixNetRenevueToSharePerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -331,7 +352,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixCrewSharePerStrategyPerVessel") - static final public String MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixCrewSharePerStrategyPerVessel"); + static final public String MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL = n("matrixCrewSharePerStrategyPerVessel"); /** * Matrix with three dimensions @@ -340,7 +361,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel") - static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel"); + static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n("matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -349,7 +370,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel") - static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel"); + static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n("matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -358,7 +379,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixOwnerMarginOverVariableCostsPerStrategyPerVessel") - static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyPerVessel"); + static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n("matrixOwnerMarginOverVariableCostsPerStrategyPerVessel"); /** * Matrix with two dimensions @@ -366,7 +387,7 @@ * Dimension 2 : Strategy */ @Doc(value = "do the doc of Result matrixOwnerMarginOverVariableCostsPerStrategy") - static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixOwnerMarginOverVariableCostsPerStrategy"); + static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n("matrixOwnerMarginOverVariableCostsPerStrategy"); /** * Matrix with two dimensions @@ -374,7 +395,7 @@ * Dimension 2 : Strategy */ @Doc(value = "do the doc of Result matrixVesselMarginOverVariableCostsPerStrategyPerVessel") - static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyPerVessel"); + static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n("matrixVesselMarginOverVariableCostsPerStrategyPerVessel"); /** * Matrix with two dimensions @@ -382,7 +403,7 @@ * Dimension 2 : Strategy */ @Doc(value = "do the doc of Result matrixVesselMarginOverVariableCostsPerStrategy") - static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixVesselMarginOverVariableCostsPerStrategy"); + static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n("matrixVesselMarginOverVariableCostsPerStrategy"); /** * Matrix with three dimensions @@ -391,7 +412,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNoActivity") - static final public String MATRIX_NO_ACTIVITY = n_("matrixNoActivity"); + static final public String MATRIX_NO_ACTIVITY = n("matrixNoActivity"); /** * Matrix with three dimensions @@ -400,7 +421,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixMetierZone") - static final public String MATRIX_METIER_ZONE = n_("matrixMetierZone"); + static final public String MATRIX_METIER_ZONE = n("matrixMetierZone"); /** * Matrix with two dimensions @@ -408,5 +429,5 @@ * Dimension 2 : Group */ @Doc(value = "do the doc of Result matrixPrice") - static final public String MATRIX_PRICE = n_("matrixPrice"); + static final public String MATRIX_PRICE = n("matrixPrice"); } Modified: trunk/src/test/resources/test-database/scripts/RuleUtil.java =================================================================== --- trunk/src/test/resources/test-database/scripts/RuleUtil.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/scripts/RuleUtil.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 Ifremer, CodeLutin, 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 @@ -25,9 +25,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.*; - import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.entities.PopulationGroup; import fr.ifremer.isisfish.entities.Species; @@ -53,7 +52,7 @@ /** * @param context le context de simulation * @param species l'espece sur lequel on souhaite le total - * @param date la date pour laquel on veut le calcul, cet argument est + * @param step le pas de temps pour lequel on veut le calcul, cet argument est * passe seulement pour que le cache ne retourne pas toujours la meme valeur * @return total catch in tons */ @@ -78,4 +77,24 @@ } return result; } + + public static double getTotalCatchTonsPop(SimulationContext context, Population pop, TimeStep step) { + double result = 0; + MatrixND mat = context.getPopulationMonitor().getHoldCatch(pop); + if (mat != null) { + mat = mat.copy(); + mat = mat.sumOverDim(0); // sum over Strategies + mat = mat.sumOverDim(1); // sum over metiers + mat = mat.sumOverDim(3); // sum over zones + + List<PopulationGroup> groups = pop.getPopulationGroup(); + + for (int c = 0; c < groups.size(); c++) { + PopulationGroup group = groups.get(c); + double weight = group.getMeanWeight(); + result += mat.getValue(0, 0, c, 0) * weight / 1000.0; + } + } + return result; + } } Modified: trunk/src/test/resources/test-database/scripts/SiMatrix.java =================================================================== --- trunk/src/test/resources/test-database/scripts/SiMatrix.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/scripts/SiMatrix.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Benjamin Poussin + * Copyright (C) 2006 - 2014 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 @@ -22,10 +22,11 @@ package scripts; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -57,6 +58,8 @@ import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.types.Month; +import fr.ifremer.isisfish.datastore.ResultStorage; +import fr.ifremer.isisfish.util.Nocache; /** * SiMatrix.java @@ -99,13 +102,9 @@ } /** - * * @param context - * Simulation context - * @param db - * TopiaContext with transaction opened. You must used this - * TopiaContext and not used - * SimulationContext.getSimulationStorage().getStorage() + * Simulation context transaction opened. You must used this + * TopiaContext and not used SimulationContext.getSimulationStorage().getStorage() * @throws TopiaException */ public SiMatrix(SimulationContext context) throws TopiaException { @@ -181,17 +180,19 @@ */ public List<Metier> getMetiers(Strategy str, TimeStep step) { StrategyMonthInfo info = str.getStrategyMonthInfo(step.getMonth()); - MatrixND props = info.getProportionMetier(); + List<Metier> result = info.getMetierWithProportion(); - List<Metier> result = new ArrayList<Metier>(); - - for (MatrixIterator i = props.iterator(); i.hasNext();) { - i.next(); - if (i.getValue() != 0) { - Metier metier = (Metier) i.getSemanticsCoordinates()[0]; - result.add(metier); - } - } +// MatrixND props = info.getProportionMetier(); +// +// List<Metier> result = new ArrayList<Metier>(); +// +// for (MatrixIterator i = props.iterator(); i.hasNext();) { +// i.next(); +// if (i.getValue() != 0) { +// Metier metier = (Metier) i.getSemanticsCoordinates()[0]; +// result.add(metier); +// } +// } return result; } @@ -211,7 +212,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_METIER_ZONE, new List[] { metiers, zones }, - new String[] { n_("Metiers"), n_("Zones") }); + new String[] { n("Metiers"), n("Zones") }); for (Metier metier : metiers) { Collection<Zone> zoneMetier = metier.getMetierSeasonInfo( @@ -227,7 +228,7 @@ List<PopulationGroup> groups = pop.getPopulationGroup(); MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_PRICE, new List[] { groups }, - new String[] { n_("PopulationGroup") }); + new String[] { n("PopulationGroup") }); for (PopulationGroup group : groups) { result.setValue(group, group.getPrice()); @@ -246,18 +247,23 @@ public MatrixND matrixCatchWeightPerStrategyMetPerZoneMet(TimeStep step, Population pop, MatrixND matrixCatchPerStrategyMetPerZoneMet) throws TopiaException, IsisFishException { - List<PopulationGroup> groups = pop.getPopulationGroup(); - MatrixND result = matrixCatchPerStrategyMetPerZoneMet.copy(); - result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET); + return matrixToWeightMatrix(step, 2, + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET, + matrixCatchPerStrategyMetPerZoneMet); - for (PopulationGroup group : groups) { - MatrixND sub = result.getSubMatrix(2, group, 1); - double meanWeight = group.getMeanWeight(); - sub.mults(meanWeight); - } - - return result; +// 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, @@ -282,8 +288,8 @@ 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") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones") }); // matrice temporaire ou les zones pops sont sommees MatrixND tmp = matrixCatchPerStrategyMetPerCell.sumOverDim(3); @@ -293,8 +299,11 @@ Strategy str = strategies.get(s); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); - for (int m = 0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); + // 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(); @@ -339,18 +348,23 @@ public MatrixND matrixCatchWeightPerStrategyMetPerZonePop(TimeStep step, Population pop, MatrixND matrixCatchPerStrategyMetPerZonePop) throws TopiaException, IsisFishException { - List<PopulationGroup> groups = pop.getPopulationGroup(); - MatrixND result = matrixCatchPerStrategyMetPerZonePop.copy(); - result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); + return matrixToWeightMatrix(step, 2, + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP, + matrixCatchPerStrategyMetPerZonePop); - for (PopulationGroup group : groups) { - MatrixND sub = result.getSubMatrix(2, group, 1); - double meanWeight = group.getMeanWeight(); - sub.mults(meanWeight); - } - - return result; +// 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; } /** @@ -369,23 +383,36 @@ public MatrixND matrixCatchPerStrategyMetPerZone(MatrixND N, Population pop, TimeStep step, MatrixND matrixCatchRatePerStrategyMet) throws TopiaException, IsisFishException { - List<PopulationGroup> groups = pop.getPopulationGroup(); - List<Zone> zones = pop.getPopulationZone(); - // on le passe en argument ce qui evite de le calculer 2 fois - // MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMet(pop, step); + int dimGroup = 2; + int dimZone = 3; + 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); - } + for (MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] posSem = i.getSemanticsCoordinates(); + double val = i.getValue(); + double n = N.getValue(posSem[dimGroup], posSem[dimZone]); + i.setValue(val * n); } + 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; } /** @@ -410,18 +437,20 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP, new List[] { strategies, metiers, groups, zones }, - new String[] { n_("Strategies"), n_("Metiers"), n_("Groups"), - n_("Zones") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones") }); + Month month = step.getMonth(); // Optimisation Hilaire 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); + MetierSeasonInfo msi = metier.getMetierSeasonInfo(month); for (int z = 0; z < zones.size(); z++) { Zone zone = zones.get(z); - double effort = effortPerZonePop(str, metier, step, zone); + double effort = effortPerZonePop(str, metier, msi, step, zone); if (effort > 0) { for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -443,14 +472,13 @@ * @param zone * @return */ - private double effortPerZonePop(Strategy str, Metier metier, TimeStep step, + private double effortPerZonePop(Strategy str, Metier metier, MetierSeasonInfo infoMet, TimeStep step, Zone zonePop) { - Month month = step.getMonth(); - Collection<Zone> zoneMet = metier.getMetierSeasonInfo(month).getZone(); + Collection<Zone> zoneMet = infoMet.getZone(); double inter = nbCellInter(zoneMet, zonePop); double effortPerStrategyPerCell = effortPerStrategyPerCell(str, metier, - step); + infoMet, step); if (log.isDebugEnabled()) { log.debug(" strategy=" + str + " metier=" + metier + " inter=" @@ -539,9 +567,86 @@ 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 ] - * + * * @param pop * @param step * @return @@ -559,51 +664,63 @@ 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") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones") }); 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(); - for (int g = 0; g < groups.size(); g++) { - PopulationGroup group = groups.get(g); + // 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 + // 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); + // 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 + for (Metier metier : getMetiers(str, step)) { - MetierSeasonInfo infoMet = metier - .getMetierSeasonInfo(month); - // getTargetFactor seem to be simple - double ciblage = infoMet.getTargetFactor(group); +// for (int m = 0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); - if (ciblage != 0) { // check 0, this prevent next call, for default value + MetierSeasonInfo infoMet = metier + .getMetierSeasonInfo(month); + // getTargetFactor seem to be simple + double ciblage = infoMet.getTargetFactor(group); - Gear gear = metier.getGear(); - Selectivity selectivity = gear - .getPopulationSelectivity(pop); - if (selectivity != null) { + if (ciblage != 0) { // check 0, this prevent next call, for default value - // getCoefficient is equation evaluation - double coeff = selectivity.getCoefficient(pop, - group, metier); - if (coeff != 0) { // check 0, this prevent next call, for default value + Gear gear = metier.getGear(); + Selectivity selectivity = gear + .getPopulationSelectivity(pop); + if (selectivity != null) { - 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, step, zone); - if (effort > 0) { // put value only if <> 0 - double value = coeff - * capturability * ciblage - * effort; - result.setValue(str, metier, group, - zone, value); + // getCoefficient is equation evaluation + double coeff = selectivity.getCoefficient(pop, + group, metier); + if (coeff != 0) { // check 0, this prevent next call, for default value + + for (Zone zone : zones) { + 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); + } } } } @@ -616,6 +733,7 @@ return result; } + /** * Matrice des captures en nombre dim [ Strategy x Metier x Classe x zonePop ] * @@ -631,23 +749,80 @@ Population pop, TimeStep step, MatrixND matrixCatchRatePerStrategyMetPerCell) throws TopiaException, IsisFishException { - List<PopulationGroup> groups = pop.getPopulationGroup(); - List<Zone> zones = pop.getPopulationZone(); + int groupDim = 2; + int zoneDim = 3; - // on le passe en argument ce qui evite de le calculer 2 fois - // MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMet(pop, step); + int NGroupDim = 0; + int NZoneDim = 1; + 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); + 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; } /** @@ -662,103 +837,136 @@ private MatrixND matrixCatchRatePerStrategyMetPerCell(Population pop, TimeStep step, MatrixND matrixFishingMortalityPerCell) 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); - 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") }); + MatrixND totalFishingMortalityPerCell = totalFishingMortalityPerCell( + step, matrixFishingMortalityPerCell); - // Optimisation Hilaire - MatrixND matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCell - .sumOverDim(2); - matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCellSumOverGroup - .reduceDims(2); + MatrixND result = matrixFishingMortalityPerCell.copy(); + result.setName("matrixCatchRatePerStrategyMetPerCell"); - 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); - } - } - } - } - } - } + for (MatrixIterator i=result.iteratorNotZero(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); - return result; - } + PopulationGroup group = (PopulationGroup)sems[2]; + Zone zone = (Zone)sems[3]; + Cell cell = (Cell)sems[4]; - /** - * 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 { + double totalFishingMortality = totalFishingMortalityPerCell.getValue( + group, zone, cell); - MatrixND totalFishingMortalityPerCell = totalFishingMortalityPerCell( - step, matrixFishingMortalityPerCell); - double totalFishingMortality = totalFishingMortalityPerCell.getValue( - group, zone, cell); + if (totalFishingMortality != 0) { - if (totalFishingMortality == 0) { - if (log.isDebugEnabled()) { - log.debug("pas de totalFishingMortality pour (" + group + ", " - + zone + ")"); + double fishingMortalityPerCell = i.getValue(); + double totalCatchRatePerCell = totalCatchRatePerCell(step, group, zone, + totalFishingMortality); + + double value = fishingMortalityPerCell / totalFishingMortality + * totalCatchRatePerCell; + + i.setValue(value); } - return 0; } - double fishingMortalityPerCell = matrixFishingMortalityPerCell - .getValue(new Object[] { str, metier, group, zone, cell }); - double totalCatchRatePerCell = totalCatchRatePerCell(step, group, zone, - totalFishingMortality); + return result; - if (log.isDebugEnabled()) { - log.debug(" totalFishingMortality=" + totalFishingMortality - + " fishingMortality=" + fishingMortalityPerCell - + " totalCatchRate=" + totalCatchRatePerCell); - } - double result = fishingMortalityPerCell / totalFishingMortality - * totalCatchRatePerCell; - 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 @@ -791,7 +999,7 @@ /** * Returne une matrice de mortalite group x zone, donc somme sur str et * metier - * + * * @param step * @param matrixFishingMortality * @param group @@ -806,12 +1014,101 @@ 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 @@ -825,61 +1122,71 @@ 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") }); + 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); + for (Strategy str : strategies) { + StrategyMonthInfo smi = str.getStrategyMonthInfo(month); + double nbTrip = smi.getNumberOfTrips(); + double propSetOfVessels = str.getProportionSetOfVessels(); + int nbOfVessels = str.getSetOfVessels().getNumberOfVessels(); - // 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); + // 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) { - MetierSeasonInfo infoMet = metier - .getMetierSeasonInfo(month); - // getTargetFactor seem to be simple - double ciblage = infoMet.getTargetFactor(group); + // 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 - if (ciblage != 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) { - Gear gear = metier.getGear(); - Selectivity selectivity = gear.getPopulationSelectivity(pop); - if (selectivity != null) { + MetierSeasonInfo infoMet = metier + .getMetierSeasonInfo(month); + // getTargetFactor seem to be simple + double ciblage = infoMet.getTargetFactor(group); - // getCoefficient is equation evaluation - double coeff = selectivity.getCoefficient(pop,group, metier); - if (coeff != 0) { // check 0, this prevent next call, for default value + if (ciblage != 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, 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, + 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); + value); + } } } } @@ -901,19 +1208,20 @@ * @return */ private double effortPerStrategyPerCell(Strategy str, Metier metier, - TimeStep step) { - Month month = step.getMonth(); + MetierSeasonInfo infoMet, TimeStep step) { //StrategyMonthInfo smi = str.getStrategyMonthInfo(month); - Collection<Zone> zones = metier.getMetierSeasonInfo(month).getZone(); + 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()) + 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; } @@ -1078,8 +1386,8 @@ /** * - * @param setOfVessels - * @param zone + * @param sov + * @param zoneMetier * @return */ protected double travelTimePerTrip(SetOfVessels sov, @@ -1255,7 +1563,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE + "_PER_CELL", new List[] { groups, zones, allCells }, - new String[] { n_("Groups"), n_("Zones"), n_("Cells") }); + new String[] { n("Groups"), n("Zones"), n("Cells") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1320,7 +1628,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1355,7 +1663,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1386,8 +1694,8 @@ Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException { double F = totalFishingMortality(step, matrixFishingMortality) - .getValue(group, zone); //totalFishingMortality(step, group, zone); // rem perf: totalFishingMortality a deja ete calcul� - double M = group.getNaturalDeathRate(zone) + .getValue(group, zone); //totalFishingMortality(step, group, zone); // rem perf: totalFishingMortality a deja ete calcule + double M = group.getNaturalDeathRate(zone) / (double) Month.NUMBER_OF_MONTH; double result = Math.exp(-(F + M)); @@ -1407,9 +1715,9 @@ throws TopiaException, IsisFishException { double F = totalFishingMortalityPerCell(step, - matrixFishingMortalityPerCell).getValue(group, zone, cell); //totalFishingMortality(step, group, zone); // rem perf: totalFishingMortality a deja ete calcul� + 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) Month.NUMBER_OF_MONTH; double result = (double) Math.exp(-(F + M)); return result; @@ -1428,47 +1736,51 @@ * @return */ public MatrixND matrixBiomass(MatrixND N, Population pop, TimeStep step) { - List<PopulationGroup> groups = (List<PopulationGroup>)N.getSemantic(0); - List<Zone> zones = (List<Zone>)N.getSemantic(1); - - MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_BIOMASS, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); - - for (int g = 0; g < groups.size(); g++) { - PopulationGroup group = groups.get(g); - double meanWeight = group.getMeanWeight(); - for (int z = 0; z < zones.size(); z++) { - Zone zone = zones.get(z); - double n = N.getValue(group, zone); - double value = n * meanWeight; - result.setValue(group, zone, value); - } - } - - return result; + return matrixToWeightMatrix(step, 0, ResultName.MATRIX_BIOMASS, N); +// +// List<PopulationGroup> groups = (List<PopulationGroup>)N.getSemantic(0); +// List<Zone> zones = (List<Zone>)N.getSemantic(1); +// +// MatrixND result = MatrixFactory.getInstance().create( +// ResultName.MATRIX_BIOMASS, new List[] { groups, zones }, +// new String[] { n("Groups"), n("Zones") }); +// +// for (int g = 0; g < groups.size(); g++) { +// PopulationGroup group = groups.get(g); +// double meanWeight = group.getMeanWeight(); +// for (int z = 0; z < zones.size(); z++) { +// Zone zone = zones.get(z); +// double n = N.getValue(group, zone); +// double value = n * meanWeight; +// result.setValue(group, zone, value); +// } +// } +// +// return result; } public MatrixND matrixBiomassBeginMonth(MatrixND N, Population pop, TimeStep step) { - List<PopulationGroup> groups = (List<PopulationGroup>)N.getSemantic(0); - List<Zone> zones = (List<Zone>)N.getSemantic(1); + return matrixToWeightMatrix(step, 0, ResultName.MATRIX_BIOMASS_BEGIN_MONTH, N); - MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_BIOMASS_BEGIN_MONTH, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); - - for (int g = 0; g < groups.size(); g++) { - PopulationGroup group = groups.get(g); - double meanWeight = group.getMeanWeight(); - for (int z = 0; z < zones.size(); z++) { - Zone zone = zones.get(z); - double n = N.getValue(group, zone); - double value = n * meanWeight; - result.setValue(group, zone, value); - } - } - return result; +// List<PopulationGroup> groups = (List<PopulationGroup>)N.getSemantic(0); +// List<Zone> zones = (List<Zone>)N.getSemantic(1); +// +// MatrixND result = MatrixFactory.getInstance().create( +// ResultName.MATRIX_BIOMASS_BEGIN_MONTH, new List[] { groups, zones }, +// new String[] { n("Groups"), n("Zones") }); +// +// for (int g = 0; g < groups.size(); g++) { +// PopulationGroup group = groups.get(g); +// double meanWeight = group.getMeanWeight(); +// for (int z = 0; z < zones.size(); z++) { +// Zone zone = zones.get(z); +// double n = N.getValue(group, zone); +// double value = n * meanWeight; +// result.setValue(group, zone, value); +// } +// } +// return result; } public MatrixND matrixAbondanceBeginMonth(MatrixND N, Population pop, @@ -1478,7 +1790,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE_BEGIN_MONTH, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1491,12 +1803,6 @@ return result; } - /////////////////////////////////////////////////////////////////////////// - // - // - // - /////////////////////////////////////////////////////////////////////////// - /** * @param step * @return @@ -1509,7 +1815,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_EFFORT_PER_STRATEGY_MET, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1524,12 +1830,6 @@ return result; } - /////////////////////////////////////////////////////////////////////////// - // - // - // - /////////////////////////////////////////////////////////////////////////// - /** * * @@ -1540,34 +1840,33 @@ */ public MatrixND matrixDiscardWeightPerStrategyMetPerZonePop(Population pop, TimeStep step, MatrixND matrixDiscardPerStrategyMetPerZonePop) { - List<PopulationGroup> groups = pop.getPopulationGroup(); + return matrixToWeightMatrix(step, 2, + ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP, + matrixDiscardPerStrategyMetPerZonePop); - MatrixND result = matrixDiscardPerStrategyMetPerZonePop.copy(); - result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); - - for (PopulationGroup group : groups) { - MatrixND sub = result.getSubMatrix(2, group, 1); - double meanWeight = group.getMeanWeight(); - sub.mults(meanWeight); - } - - return result; +// List<PopulationGroup> groups = pop.getPopulationGroup(); +// +// MatrixND result = matrixDiscardPerStrategyMetPerZonePop.copy(); +// result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); +// +// for (PopulationGroup group : groups) { +// MatrixND sub = result.getSubMatrix(2, group, 1); +// double meanWeight = group.getMeanWeight(); +// sub.mults(meanWeight); +// } +// +// return result; } - /////////////////////////////////////////////////////////////////////////// - // - // - // - /////////////////////////////////////////////////////////////////////////// - public MatrixND matrixEffortNominalPerStrategyMet(TimeStep step) throws TopiaException { + public MatrixND matrixEffortNominalPerStrategyMet(TimeStep step) throws TopiaException { - List<Strategy> strategies = getStrategies(step); + List<Strategy> strategies = getStrategies(step); List<Metier> metiers = getMetiers(step); MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET, new List[]{strategies, metiers}, - new String[]{n_("Strategies"), n_("Metiers")}); + new String[]{n("Strategies"), n("Metiers")}); for (int s=0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1581,4 +1880,153 @@ return result; } + + /** + * Ce morceau de script sert a calculer la mortalite par peche par espece et + * par groupe d'age sur l'ensemble de la zone d'etude, + * en minimisant la difference entre les captures d'ISIS et celles calculees + * a partir de l'equation de Baranov. + * + * @param step pas de temps + * @param pop population + * @return Fishing mortality per group per year (computed in December) + */ + public MatrixND fishingMortalityPerGroup(TimeStep step, Population pop, ResultStorage resManager) throws TopiaException { + double Fgroup = 0; + double Cgroup = 0; + double Mgroup = 0; + double NgroupJan = 0; + + List<Population> populations = Collections.singletonList(pop); + List<PopulationGroup> groups = pop.getPopulationGroup(); + + MatrixND tfgMatrix = MatrixFactory.getInstance().create( + ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP, + new List[]{populations, groups}, // On travaille sur les pops ET les groupes + new String[]{n("Population"), n("Group")}); + + for (PopulationGroup group : groups) { + + if (step.getMonth() == Month.DECEMBER) { + + MatrixND catchPerStrategy = null; + + 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) + // 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(); + // 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 + } + } + + //log.info("catchPerStrategy = " + catchPerStrategy); + catchPerStrategy = catchPerStrategy.sumOverDim(0); // Strategy + catchPerStrategy = catchPerStrategy.sumOverDim(1); // Metier + catchPerStrategy = catchPerStrategy.sumOverDim(3); // Zone : une pop peut avoir plusieurs zonespop dans ISIS + List semgroup = catchPerStrategy.getSemantic(2); + catchPerStrategy = catchPerStrategy.reduce(); // Enleve les dimensions de taille 1 + catchPerStrategy.setSemantic(0, semgroup); // Ne plait pas a Eric + Cgroup = catchPerStrategy.getValue(group); + //log.info("Cgroup = " + Cgroup + "Year=" + step.getYear()); + //log.info("catchPerStrategy = " + catchPerStrategy + "Year=" + step.getYear()); + + MatrixND naturalDeathRatePop = pop.getNaturalDeathRateMatrix(); + naturalDeathRatePop = naturalDeathRatePop.meanOverDim(1); // moyenne sur Zone + naturalDeathRatePop = naturalDeathRatePop.reduce(); // Enleve les dimensions de taille 1 + Mgroup = naturalDeathRatePop.getValue(group); + //log.info("Mgroup= " + Mgroup + "Year=" + step.getYear()); + + MatrixND abundancePopJan = resManager.getMatrix(new TimeStep(12*step.getYear()), pop, ResultName.MATRIX_ABUNDANCE); // Le timestep 0 correspond a janvier de la premiere annee et les annees sont numerotees a partir de zero + abundancePopJan = abundancePopJan.sumOverDim(1); // somme sur Zone + abundancePopJan = abundancePopJan.reduce(); + NgroupJan = abundancePopJan.getValue(group); + //log.info("NgroupJan = " + NgroupJan + "Year=" + step.getYear()); + + ObjectiveFunction f = new ObjectiveFunctionBaranov(Cgroup, Mgroup, NgroupJan); + Fgroup = MinimisationUtil.fmin(0.0,2.0,1.0e-10, f); // step ?? + + //log.info("Fgroup = " + Fgroup); + + tfgMatrix.setValue(pop, group, Fgroup); // Bien faire attention a l'endroit ou on met cette etape (quelle boucle) ? + + } else { + //Fgroup = 0; // Ce n'est plus une valeur unique mais une matrice, est-ce que cette notation peut fonctionner ? + tfgMatrix.setValue(pop, group, 0); // Bien faire attention a l'endroit ou on met cette etape (quelle boucle) ? + } + } + + //log.info("tfgMatrix = " + tfgMatrix); + //log.info("tfg.DimensionNames = " + Arrays.toString(tfgMatrix.getDimensionNames())); + //log.info("tfg.Semantics = " + Arrays.toString(tfgMatrix.getSemantics())); + + return tfgMatrix; + } + + /** + * Ce morceau de script sert a calculer la mortalite par peche par espece et + * par groupe representatif a partir de la mortalite par peche par groupe + * calculee precedemment. + */ + public MatrixND totalFishingMortality(TimeStep step, Population pop, MatrixND fishingMortalityPerGroup) throws TopiaException { + MatrixND tfmMatrix = fishingMortalityPerGroup.copy(); + tfmMatrix.setName(ResultName.MATRIX_TOTAL_FISHING_MORTALITY); + //log.info("tfmMatrix = " + tfmMatrix); + + List<PopulationGroup> groups = pop.getPopulationGroup(); + + int groupMin = pop.getGroupMin(); + int groupMax = pop.getGroupMax(); + int Nbre = (int)groupMax - (int)groupMin + 1; + //log.info("Nbre = " + Nbre); + + for (PopulationGroup group : groups) { + if (group.getId() == groupMin) { + // MatrixND getSubMatrix(int dim, Object, int nb) + tfmMatrix = tfmMatrix.getSubMatrix(1, group, Nbre); + tfmMatrix = tfmMatrix.meanOverDim(1); + tfmMatrix = tfmMatrix.reduce(); + //log.info("tfm.DimensionNames = " + Arrays.toString(tfmMatrix.getDimensionNames())); + //log.info("tfm.Semantics = " + Arrays.toString(tfmMatrix.getSemantics())); + } + } + + return tfmMatrix; + } + + /** + * Converti une matrix contenant des effectifs en une matrice en poids + * + * @param step + * @param dimGroup + * @param resultName + * @return + */ + @Nocache // no need to cache it, because caller method is cached + public MatrixND matrixToWeightMatrix(TimeStep step, int dimGroup, String resultName, + MatrixND matrix) { + + MatrixND result = matrix.copy(); + result.setName(resultName); + + List<PopulationGroup> groups = (List<PopulationGroup>)result.getSemantic(dimGroup); + double[] meanWeight = new double[groups.size()]; + int cpt = 0; + for (PopulationGroup group : groups) { + meanWeight[cpt++] = group.getMeanWeight(); + } + + for (MatrixIterator i=result.iteratorNotZero(); i.next();) { + double val = i.getValue(); + int[] pos = i.getCoordinates(); + i.setValue(val * meanWeight[pos[dimGroup]]); + } + + return result; + } } Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassReferenceY9.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassReferenceY9.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassReferenceY9.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -67,10 +65,10 @@ ReverseFileReader reader = new ReverseFileReader(referenceFile); //read the last line of the file (should be empty) - String line = reader.readLine(); + reader.readLine(); //read the next line (the last written line) - line = reader.readLine(); + String line = reader.readLine(); String lastMonth=""; @@ -113,12 +111,12 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivityBiomassReferenceY9"; + return "SensitivityBiomassReferenceY9_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -71,10 +69,10 @@ ReverseFileReader reader = new ReverseFileReader(referenceFile); //read the last line of the file (should be empty) - String line = reader.readLine(); + reader.readLine(); //read the next line (the last written line) - line = reader.readLine(); + String line = reader.readLine(); String lastMonth=""; @@ -121,12 +119,12 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivityBiomassRelativeReferenceY12"; + return "SensitivityBiomassRelativeReferenceY12_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeY6.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeY6.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassRelativeY6.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -77,12 +75,12 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivityBiomassRelativeY6"; + return "SensitivityBiomassRelativeY6_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassY3.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassY3.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityBiomassY3.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -67,12 +65,12 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivityBiomassY3"; + return "SensitivityBiomassY3_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightReferenceY7.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightReferenceY7.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightReferenceY7.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -114,14 +112,14 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage " + + return "Captures in weight for the last year for the popage " + "population. Captures is the sum of zones, groups, metiers " + - "and strategies"); + "and strategies"; } @Override public String getExportFilename() { - return "SensitivityCapturesWeightReferenceY7"; + return "SensitivityCapturesWeightReferenceY7_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -39,14 +37,15 @@ import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.util.Doc; -public class SensitivityCatchWeightRelativeReferenceY10 implements - SensitivityExport { +public class SensitivityCatchWeightRelativeReferenceY10 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory .getLog(SensitivityCatchWeightRelativeReferenceY10.class); - protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP }; + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP + }; @Doc("Population") public Population param_pop; @@ -129,12 +128,12 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"); + return "Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"; } @Override public String getExportFilename() { - return "SensitivityCapturesWeightRelativeReferenceY10"; + return "SensitivityCapturesWeightRelativeReferenceY10_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeY4.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeY4.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightRelativeY4.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -43,7 +41,9 @@ static private Log log = LogFactory .getLog(SensitivityCatchWeightRelativeY4.class); - protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP }; + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP + }; @Doc("Population") public Population param_pop; @@ -85,12 +85,12 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"); + return "Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"; } @Override public String getExportFilename() { - return "SensitivityCapturesWeightRelativeY4"; + return "SensitivityCapturesWeightRelativeY4_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightY1.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightY1.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivityCatchWeightY1.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -43,7 +41,9 @@ static private Log log = LogFactory .getLog(SensitivityCatchWeightY1.class); - protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP }; + protected String[] necessaryResult = { + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP + }; @Doc("Population") public Population param_pop; @@ -76,12 +76,12 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"); + return "Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"; } @Override public String getExportFilename() { - return "SensitivityCapturesWeightY1"; + return "SensitivityCapturesWeightY1_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,43 +21,42 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - -import java.io.File; -import java.io.Writer; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import fr.ifremer.isisfish.datastore.ResultStorage; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.PopulationGroup; +import fr.ifremer.isisfish.export.SensitivityExport; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.util.Doc; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixIterator; import org.nuiton.math.matrix.MatrixND; - import org.nuiton.topia.TopiaContext; import org.nuiton.util.ReverseFileReader; 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.entities.PopulationGroup; -import fr.ifremer.isisfish.export.SensitivityExport; -import fr.ifremer.isisfish.types.TimeStep; -import fr.ifremer.isisfish.util.Doc; +import java.io.File; +import java.io.Writer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class SensitivitySpawningBiomassReferenceY8 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory .getLog(SensitivitySpawningBiomassReferenceY8.class); - protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS }; + protected String[] necessaryResult = { + ResultName.MATRIX_BIOMASS + }; @Doc("Population") public Population param_pop; @Doc("URL of the Biomasses.csv reference export file") - public String param_referenceBiomassCSV =""; + public String param_referenceBiomassCSV = ""; @Override public void export(SimulationStorage simulation, Writer out) @@ -78,7 +77,7 @@ Map<Integer, Double> map =new HashMap<Integer,Double>(); for (PopulationGroup group:groups) { - map.put(group.getId(),group.getReproductionRate()); + map.put(group.getId(),group.getMaturityOgive()); } tx.closeContext(); @@ -110,6 +109,7 @@ } line = reader.readLine(); } + reader.close(); for (Population pop : simulation.getParameter().getPopulations()) { if (pop.getName().equals(param_pop.getName())) { @@ -123,22 +123,23 @@ PopulationGroup group = (PopulationGroup) sems[1]; TimeStep step = (TimeStep) sems[0]; if (step.equals(lastStep)) { - biomass += i.getValue() * group.getReproductionRate(); + biomass += i.getValue() * group.getMaturityOgive(); } } } } + out.write(Double.toString(biomass / referenceBiomass)); } @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivitySpawningBiomassReferenceY8"; + return "SensitivitySpawningBiomassReferenceY8_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,22 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - -import java.io.File; -import java.io.Writer; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixIterator; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.topia.TopiaContext; - -import org.nuiton.util.ReverseFileReader; -import scripts.ResultName; import fr.ifremer.isisfish.datastore.ResultStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.entities.Population; @@ -44,7 +28,20 @@ import fr.ifremer.isisfish.export.SensitivityExport; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.util.Doc; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.topia.TopiaContext; +import org.nuiton.util.ReverseFileReader; +import scripts.ResultName; +import java.io.File; +import java.io.Writer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class SensitivitySpawningBiomassRelativeReferenceY11 implements SensitivityExport { @@ -58,7 +55,7 @@ public Population param_pop; @Doc("URL of the Biomasses.csv reference export file") - public String param_referenceBiomassCSV =""; + public String param_referenceBiomassCSV = ""; @Override public void export(SimulationStorage simulation, Writer out) @@ -83,7 +80,7 @@ Map<Integer, Double> map =new HashMap<Integer,Double>(); for (PopulationGroup group:groups) { - map.put(group.getId(),group.getReproductionRate()); + map.put(group.getId(),group.getMaturityOgive()); } tx.closeContext(); @@ -120,6 +117,7 @@ line = reader.readLine(); } + reader.close(); for (Population pop : simulation.getParameter().getPopulations()) { if (pop.getName().equals(param_pop.getName())) { @@ -134,7 +132,7 @@ TimeStep step = (TimeStep) sems[0]; if (step.equals(firstStep)) { firstbiomass += i.getValue() - * group.getReproductionRate(); + * group.getMaturityOgive(); } } @@ -148,23 +146,24 @@ TimeStep step = (TimeStep) sems[0]; if (step.equals(lastStep)) { biomass = biomass + i.getValue() - * group.getReproductionRate(); + * group.getMaturityOgive(); } } } } + out.write(Double.toString((biomass / firstbiomass) / (biomassReference / firstBiomassReference))); } @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivitySpawningBiomassRelativeReferenceY11"; + return "SensitivitySpawningBiomassRelativeReferenceY11_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,16 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - -import java.io.Writer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixIterator; -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; @@ -38,14 +28,24 @@ import fr.ifremer.isisfish.export.SensitivityExport; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.util.Doc; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import scripts.ResultName; + +import java.io.Writer; + public class SensitivitySpawningBiomassRelativeY5 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory .getLog(SensitivitySpawningBiomassRelativeY5.class); - protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS }; + protected String[] necessaryResult = { + ResultName.MATRIX_BIOMASS + }; @Doc("Population") public Population param_pop; @@ -72,7 +72,7 @@ TimeStep step = (TimeStep) sems[0]; if (step.equals(firstStep)) { firstbiomass += i.getValue() - * group.getReproductionRate(); + * group.getMaturityOgive(); } } @@ -85,7 +85,7 @@ PopulationGroup group = (PopulationGroup) sems[1]; TimeStep step = (TimeStep) sems[0]; if (step.equals(lastStep)) - biomass += i.getValue() * group.getReproductionRate(); + biomass += i.getValue() * group.getMaturityOgive(); } } } @@ -94,12 +94,12 @@ @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivityGenitorBiomassRelativeY5"; + return "SensitivityGenitorBiomassRelativeY5_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassY2.java =================================================================== --- trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassY2.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/sensitivityexports/SensitivitySpawningBiomassY2.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Jean Couteau + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,16 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - -import java.io.Writer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixIterator; -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; @@ -38,14 +28,24 @@ import fr.ifremer.isisfish.export.SensitivityExport; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.util.Doc; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import scripts.ResultName; + +import java.io.Writer; + public class SensitivitySpawningBiomassY2 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory .getLog(SensitivitySpawningBiomassY2.class); - protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS }; + protected String[] necessaryResult = { + ResultName.MATRIX_BIOMASS + }; @Doc("Population") public Population param_pop; @@ -69,7 +69,7 @@ TimeStep step = (TimeStep) sems[0]; PopulationGroup group = (PopulationGroup) sems[1]; if (step.equals(lastStep)) { - biomass += i.getValue() * group.getReproductionRate(); + biomass += i.getValue() * group.getMaturityOgive(); } } } @@ -79,12 +79,12 @@ @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override public String getExportFilename() { - return "SensitivityGenitorBiomassY2"; + return "SensitivityGenitorBiomassY2_" + param_pop.getName(); } @Override Modified: trunk/src/test/resources/test-database/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java =================================================================== --- trunk/src/test/resources/test-database/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2007 - 2011 Ifremer, CodeLutin, Sigrid Lehuta + * Copyright (C) 2007 - 2014 Ifremer, CodeLutin, Sigrid Lehuta * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -21,15 +21,12 @@ */ package simulationplans; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import fr.ifremer.isisfish.util.ScriptUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixIterator; @@ -38,16 +35,16 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.StringUtil; +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.entities.PopulationGroup; -import fr.ifremer.isisfish.simulator.SimulationPlanContext; import fr.ifremer.isisfish.simulator.SimulationPlan; +import fr.ifremer.isisfish.simulator.SimulationPlanContext; import fr.ifremer.isisfish.util.Doc; +import fr.ifremer.isisfish.util.ScriptUtil; -import scripts.ResultName; - /** * CalibrationSimplexePasVariable2Capturabilite. * @@ -111,7 +108,7 @@ //*** write the name of the simulated matrix that contains the data corresponding // to your observations (here MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP) - public String[] necessaryResult = { + protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP }; @@ -124,9 +121,9 @@ * @return L'aide ou la description du plan */ public String getDescription() throws Exception { - return _("Calibration using variable step Simplex method (Walters): user" + + return "Calibration using variable step Simplex method (Walters): user" + "gives a file of observations (here catches)(.csv), simulated output" + - "will try to approach oservations by changing the values of catchability"); + "will try to approach oservations by changing the values of catchability"; } /** @@ -156,7 +153,8 @@ double worst2; /** - * Call before each simulation + * Call before each simulation. + * * @param context plan context * @param nextSimulation storage used for next simulation * @return true if we must do next simulation, false to stop plan @@ -483,4 +481,4 @@ } } -} +} \ No newline at end of file Added: trunk/src/test/resources/test-database/simulationplans/RecuitSimuleSimulateur.java =================================================================== --- trunk/src/test/resources/test-database/simulationplans/RecuitSimuleSimulateur.java (rev 0) +++ trunk/src/test/resources/test-database/simulationplans/RecuitSimuleSimulateur.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,638 @@ +package simulationplans; + +/* + * #%L + * IsisFish + * %% + * Copyright (C) 1999 - 2014 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% + */ + +import static org.nuiton.i18n.I18n._; + +import java.io.File; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.topia.TopiaContext; +import org.nuiton.util.FileUtil; +import org.nuiton.util.StringUtil; + +import fr.ifremer.isisfish.datastore.ResultStorage; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.PopulationGroup; +import fr.ifremer.isisfish.simulator.SimulationException; +import fr.ifremer.isisfish.simulator.SimulationPlanContext; +import fr.ifremer.isisfish.simulator.SimulationPlan; +import fr.ifremer.isisfish.util.Doc; + +import scripts.ResultName; + +/** + * RecuitSimule. + * + * Created: + * + * @author + * @version + * + * Last update: + * by : + */ + +// //////////////////////////////////////////////////////////////////////// +// USER GUIDE +//------------------------------------------------------------------------- +// Script must be adapted to the case study (calibration data, catchability assumptions) +// Script won't compile as it stands +// Comments preceeded by /////*** explain where and how to adapt the script +// Access to the APIs is free +// //////////////////////////////////////////////////////////////////////// + +// ***You can modify class name if you want +// ***BUT attention : file name and class name must be the same (without the extention ".java"), +// ie here : "RecuitSimule" + +public class RecuitSimuleSimulateur implements SimulationPlan { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory + .getLog(RecuitSimuleSimulateur.class); + + /////***here must appear the path to export the historic file ("Historic.csv") + //in which all information about each simulation is stored + /////***Attention : before beginning a new calibration rename any potential + //old Historic.csv files or they will be lost + protected File exportHistoric = new File("Historic.csv"); + + protected String exportHisto = ""; + + @Doc("Population which parameters are calibrated") + public Population param_Population = null; + @Doc("Lower values of parameters, separated with semicolons: de la forme(\"xx1;xx2;xx3\")") + public String param_borneInf = "2.42e-5;2.11e-6";// devient un parametre du plan d analyse/// Rentrer ici les bornes inférieruers de chaque paramètre. + @Doc("Upper values of parameters, separated with semicolons: de la forme(\"xx1;xx2;xx3\"); Keep the order used to fill borneInf.") + public String param_borneSup = "2.42e-5;2.11e-6";// devient un parametre du plan d analyse/// Rentrer ici les bornes supérieruers de chaque paramètre. + @Doc("Cooling schedule : choose between \"Van Laarhoven\", \"Huang\", \"Triki\", \"Geometric\", \"Lundy\", \"Constant\" and \"Linear\".") + public String param_coolingSchedule = "Triki"; // Attention aux méthodes à valeurs à fixer par l'utilisateur. + //public long param_seed = 1; + + String [] borneInf; + String [] borneSup; + int taille; + + int current; + int compteurSimus; + int compteurTemperature; + int compteurAccept; + double deltaEnergy; + SecureRandom random; + double rhoValue; + boolean bool; + double obj; + + /////***hasard1,2,3, etc => des méthodes de hasard à déterminer, à placer en début de script. Pour le moment, elles ne font que de l'uniforme, à nous de voir ce qui est le mieux et pourquoi + public int hasard1(){ + int result = random.nextInt(taille); + return result; + } + public int hasard2(){ + int result = random.nextInt(); + return result; + } + public double hasard3(){ + double result = random.nextDouble(); + return result; + } + public double hasardUniforme(){ + double result = random.nextDouble(); + return result; + } + + //int seuilTemperature=5;// Laissés au choix de l'utilisateur. Dans l'interface, proposer des méthodes pour faire évoluer les seuils? + //int seuilAcceptance=3; + double seuilArret=0.01; //Sera utilisé en fonction du critèe d'arrêt utilisé...son cas est encore à trancher. + + // ***put here the path and name of the file containing the data used to calibrate + // your fishery ( here observed landings per season and age groups) + @Doc(value = "file name and path of observed landings") + public String param_nomfichier_debarquements = "Observedlandings2001-2003.csv"; + protected File debarquementsObserves; + protected MatrixND matrixDebarquement; + + ArrayList<Experience> historique = new ArrayList<Experience>(); //historique va contenir tout l'historique de l'algorithme, c'est un ArrayList d'Experience. + //*** double temperature=???; //Initialisation de la température. Pour le moment, à l'utilisateur de remplacer ??? par un double dans le script. + + //*** write the name of the simulated matrix that contains the data corresponding + // to your observations (here MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP) + public String[] necessaryResult = { + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP + }; + + public String[] getNecessaryResult() { + return this.necessaryResult; + } + + /** + * Permet d'afficher a l'utilisateur une aide sur le plan. + * @return L'aide ou la description du plan + */ + public String getDescription() throws Exception { + return _("Calibration using simulated annealing: user" + + "gives a file of observations (here catches)(.csv), simulated output" + + "will try to approach oservations by changing the values of catchability"); + } + + + /** + * Appele au demarrage de la simulation, cette methode permet d'initialiser + * des valeurs + * @param context La simulation pour lequel on utilise cette regle + */ + public void init(SimulationPlanContext context) throws Exception { + random = new SecureRandom(); + //random.setSeed(param_seed); + + if (param_nomfichier_debarquements == null + || "".equals(param_nomfichier_debarquements)) { + debarquementsObserves = FileUtil.getFile(".*.csv", + "fichier csv separateur ';'"); + } else { + debarquementsObserves = new File(param_nomfichier_debarquements); + } + + // ***Create the matrix named matrixDebarquement that will contain your observed landings + // method: MatrixFactory.getInstance().create() + // ***Then import your file in it + // method : matrixDebarquement.importCSV(); + log.info("MatrixDebarquement : " + matrixDebarquement); + + borneInf=param_borneInf.split(";"); + borneSup=param_borneSup.split(";"); + taille=borneInf.length; + + } + + /** + *Crée (*@see createExperience) une nouvelle expérience (le contructeur modifie la paramétrisation parente ou en initialise une si c'est la première), baisse la température si nécessaire(*@see baisse), modifie la base de données(*@see changeDB). + *@param context plan context + *@param nextSimulation storage for the next simulation + *@return true if we must do next simulation, false to stop plan + *@throws Exception + */ + + public boolean beforeSimulation(SimulationPlanContext context, + SimulationStorage nextSimulation) throws Exception {//Dans le before, on modifie la paramétrisation actuelle, on enregistre cette modification, on change la base de données. + compteurSimus=getIteration(nextSimulation); //numéro de la simulation à venir + Experience expCurrent; + + if (compteurSimus==0){//En considérant que la numérotation des simulations commence à 0, on traite ici la premièe simulation. + expCurrent = createExperience(compteurSimus, null); + expCurrent.accepted = true; + } + else { + Experience expPrev = historique.get(compteurSimus - 1); + expCurrent = createExperience(compteurSimus, expPrev); + expCurrent.temperature = baisse(expCurrent); + } + + changeDB(expCurrent, nextSimulation); + return true; + } + + /** + *Récupère les résultats de la simulation, calcule la fonction d'objectif(*@see calculFonctionObjectif), accepte ou non la nouvelle paramétrisation et décide la paramétrisation parente(*@see acceptationSolution) et vérifie le critère d'arrêt(*@see isCritereArretAtteint). + *@param context plan context + *@param lastSimulation storage for the next simulation + *@return true if we must do next simulation, false to stop plan + *@throws Exception + *@see getIteration + */ + public boolean afterSimulation(SimulationPlanContext context, + SimulationStorage lastSimulation) throws Exception{//Dans l'after, on évalue la nouvelle paramétrisation, on met en compétition cette paramétrisation + //avec celle de référence (celle de l'itération current), on modifie la température, on vérifie que le + //critèe d'arrêt de l'algorithme n'est pas atteint, on enregistre toutes les modifications dans la table historique. + ResultStorage result = lastSimulation.getResultStorage(); + boolean bool=true; + compteurSimus=getIteration(lastSimulation); //numéro de la simulation qui vient de se terminer + Experience expCurrent = historique.get(compteurSimus); + double obj=calculFonctionObjectif(result); + expCurrent.objective = obj; + + if (compteurSimus > 0){ + if (obj < expCurrent.best.objective){//On compare la nouvelle paramétrisation à la meilleure paramétrisation + expCurrent.best = expCurrent; + } + acceptationSolution(expCurrent);//On compare la nouvelle paramétrisation à la paramétrisation courante et on décide qui sera la courante. + //if (isModifierTemperature()){//Pour le moment, les méthodes proposées modifient la température à chaque fois. On intégrera un système de phase et de vérification de critère de température plus tard, si besoin. + /*} + else{ + historique.get(compteurSimus).temperature = getExperience(compteurSimus-1).temperature; + }*/ + bool=isCritereArretAtteint(expCurrent); + } + return bool; + } + +//////////////////// +//////////////////// +/// /// +///AUTRES CLASSES/// +/// /// +//////////////////// +//////////////////// + + protected Parameter[] copyM1(Parameter[]M1){ + Parameter[] result = new Parameter[M1.length]; + for (int i=0,maxi=M1.length; i<maxi; i++) { + result[i] = M1[i].copy(); + } + return result; + } + + class Parameter { + double value; + double inf; + double sup; + + public Parameter (double valeur, double borneinf, double bornesup){ + /*if (borneinf >= bornesup) { + throws SimulationException(String.format("Error: inf(%s) >= sup(%s)", borneinf, bornesup)); + }*/ + value=valeur; + inf=borneinf; + sup=bornesup; + } + + public Parameter copy() { + return new Parameter(value, inf, sup); + } + } + + class Experience{// 1 objet Experience contient toutes les informations sur la passage de l'état current à l'état suivant. + public int id; + public Experience parent; + public Experience best; + public boolean accepted; + + public double rho; + public double rand; + public Parameter[] parametrisation; //On enregistre la paramétrisation et les bornes, tout est nécessaire en cas de ré-utilisation. + public double objective; + public double temperature; + + public Experience(int id, Experience parent) { + this.id = id; + this.parent = parent; + + if (parent == null) { + best = this; + parametrisation = initM1(); + } else { + best = parent.best; + + Parameter[] M1=copyM1(parent.getParametrisation()); + modif(M1); + parametrisation = M1; + } + } + + /** + * recherche de la 1ere experience accepte et retourne parametrisation + */ + public Parameter[] getParametrisation() { + Parameter[] result = parametrisation; + if (!accepted) { + result = parent.getParametrisation(); + } + return result; + } + + /*public String toCSV() { + String sep = ";"; + String result = ""; + + result += id + sep; + result += accepted + sep; + result += rand + sep; + result += rho + sep; + result += objective + sep; + result += temperature + sep; + result += parametrisation.value + sep; + result += parent.id + sep; + result += best.id + sep; + + return result; + }*/ + } + +//////////////////// +//////////////////// +/// /// +/// METHODES /// +/// /// +//////////////////// +//////////////////// + + /** + *Retourne l'experience à l'index i dans la table historique, crée l'experience si elle n'existe pas encore. + *@param i l'index de l'Experience demandée + *@return l'Experience i + */ + + public Experience createExperience(int id, Experience parent){ + Experience result = new Experience(id, parent); + historique.add(result); + return result; + } + + /** + *Baisse la température selon une certaine méthode. Appellé par @see modifierTemperature + *@param compteurSimus la simulation qui vient de s'achever + *@return la température baissée + */ + //En faire une fonction de compteurSimus pour que toutes les méthdoes marchaent! + public double baisse(Experience expCurrent){ + double temperature = expCurrent.temperature; + double result=0; + //Méthode pour faire baisser la température. Il peut y en avoir plusieurs, l'idée étant de pouvoir basculer d'une méthode à l'autre pendant l'algorithme; + + //Van Laarhoven et al. (1987) + if (param_coolingSchedule.equals("Van Laarhoven")){ + double delta=0.001;// Valeur à fixer par l'utilisateur + double obj = expCurrent.objective; + double sigmasquare=(obj*obj-obj)*(obj*obj-obj); + double sigma=Math.sqrt(sigmasquare); + result = temperature*(1/(1+(Math.log(1+delta))*temperature/(3*sigma))); + } + //Huang et al. (1986) + if (param_coolingSchedule.equals("Huang")){ + double lambda =0.5;// 0<lambda<=1 à fixer par l'utilisateur + double obj = expCurrent.objective; + double sigmasquare=(obj*obj-obj)*(obj*obj-obj); + double sigma=Math.sqrt(sigmasquare); + result=temperature*Math.exp(-lambda*temperature/sigma); + } + // Triki et al. (2005) + if (param_coolingSchedule.equals("Triki")){ + double obj = expCurrent.objective; + double objCurrent=historique.get(expCurrent.parent.id).objective; + double delta=obj-objCurrent; + double sigmasquare=(obj*obj-obj)*(obj*obj-obj); + result= temperature*(1-temperature*delta/sigmasquare); + } + // Géométrique (décrit dans Triki et al. (2005)) + if (param_coolingSchedule.equals("Geometric")){ + double alpha =0.5; // 0<alpha<1 à fixer par l'utilisateur + result=alpha*temperature; + } + // Lundy et al. (1986) + if (param_coolingSchedule.equals("Lundy")){ + //double beta=???; // Voir à quoi ça correspond + //result= temperature*(1/(1+beta*temperature)); + } + // Fixe + if (param_coolingSchedule.equals("Constant")){ + result=temperature; //Il faut fixer une bonne température, voir Cohn et Connolly pour plus de renseignements. + } + //Linéaire + if (param_coolingSchedule.equals("Linear")){ + //double baisse =???// A fixer par l'utilisateur + //result=temperature-baisse; + } + return result; + } + + /** + *Initialise une paramétrisation avant la première simulation à partir des bornes de chaque paramètre selon une loi uniforme + *@return la paramétrisation initialisée. + */ + public Parameter[] initM1(){ + //Méthode 1 : initialisation selon une loi uniforme entre les bornes de chaque paramètre. + Parameter M1[] = new Parameter[taille]; + for (int i=0; i<taille; i++){ + double uni=hasardUniforme(); + double inf = Double.parseDouble(borneInf[i]); + double sup = Double.parseDouble(borneSup[i]); + double val= inf+uni*(sup-inf); + Parameter param = new Parameter(val, inf, sup); + M1[i]=param; + } + + //Méthode 2 => On peut proposer plusieurs méthodes d'initiation dans l'interface? Lois de Poisson, Gauss, etc. + //etc. + return M1; + } + + /** + * Modify nextSimulation database with parameters in Experience exp. + * @param exp the Experience in process + * @param nextSimulation storage for the next simulation + * @throws Exception + */ + protected void changeDB(Experience exp, SimulationStorage nextSimulation) + throws Exception { + // methode appelee dans before simualtion + TopiaContext db = nextSimulation.getStorage().beginTransaction();//ouvrir un context pour modifier les donnees + Population pop = (Population) db.findByTopiaId(param_Population.getTopiaId()); //reccupere la pop ciblee + MatrixND c = pop.getCapturability(); // reccupere la matrice de capturabilité + + // *** that is where you explain how to fill the catchability matrix with q1 and q2 + for (MatrixIterator i = c.iterator(); i.hasNext();) { + i.next(); + Object[] sem = i.getSemanticsCoordinates(); + PopulationGroup group = (PopulationGroup) sem[0]; + + // *** exemple when q2 corresponds to the 12 first groups (groups 0 to 11) + if (group.getId() < 12) { + i.setValue(exp.parametrisation[1].value); + } else { + i.setValue(exp.parametrisation[0].value); + } + + // *** exemple when it depends on seasons and groups + /*PopulationSeasonInfo season = (PopulationSeasonInfo) sem[1]; + if (season.getFirstMonth().after(Month.JULY) && group.getId() >=18){ //month >= aout && groupID >= 18 + i.setValue(exp.q2); + } else { + i.setValue(exp.q1); + } */ + }//fin du for + + db.commitTransaction(); // effectue la modification + db.closeContext(); // ferme le context + } + + /** + *Modifie une paramétrisation, utilise une méthode pour modifier paramètre par paramètre + *@param M1 la paramétrisation à modifier + *@see modifParameter + */ + public void modif(Parameter[] M1){ + double nbModif=hasard1(); //Une méthode de tirage aléatoire à coder dans une autre méthode (type getPoisson), on la mettre au début du script, + while (nbModif >= 0){ //où plusieurs possibilités de tirages sont proposées. L'utilisateur peut y rajouter les siennes. + int num=M1.length*hasard2(); //On tire au hasard entre 0 et M1.length-1 une position sur M1. + modifParameter(num, M1); //Modification du paramètre + nbModif-=1; + } + } + + /** + *Modifie un paramètre selon une certaine méthode, appellée par @see modif + *@param num la position dans la paramétrisation du paramètre à modifier + */ + public void modifParameter(int num, Parameter[] M1){ + //Méthode 1 + double amplitude = hasard3(); + double valeur=M1[num].value; + M1[num].value=amplitude*valeur; + int MAX = 10000; + while (MAX > 0 && (M1[num].value<M1[num].inf || M1[num].value>M1[num].sup)){ //Tant qu'on est en dehors du domaine de définiton du paramètre, on modifie la valeur + amplitude = hasard3(); + M1[num].value=amplitude*valeur; + MAX--; + } + /* + if (MAX <= 0) { + throws SimulationException("Can't find new value"); + }*/ + //Méthode 2 + //etc. L'idée est de faire varier la manièe de faire varier delta en fcontion de l'avancement de l'algorithme. + } + + /** + *Met en compétition la nouvelle solution et la solution courante (calcul de la "probabilité" d'acceptation) et décide de qui sera la solution courante, le renseigne dans l'historique des simulations. + *@param compteurSimus le numéro de la simulation qui vient de s'achever. + *@see getProba + */ + public void acceptationSolution(Experience expCurrent){// Mise en compétition de l'état current et du nouvel état + + deltaEnergy= expCurrent.objective - expCurrent.parent.objective;//Valeur absolue + double rhoValue = getProba(expCurrent, deltaEnergy); + expCurrent.rho = rhoValue; + double randValue; + if (rhoValue>1){ + expCurrent.rand = 0;// rand n'a pas été tiré à cette itération. + expCurrent.accepted = true; + }else{ + randValue=hasardUniforme(); + if (randValue<rhoValue){ + expCurrent.rand = randValue; + expCurrent.accepted = true; + } + else{ + expCurrent.accepted = false; + } + } + } + + /** + *Calcule la valeur de la fonction d'objectif de la paramétrisation utilisée pour la simulation qui vient de s'achever. + *@param result le numéro de la simulation venant de s'achever + *@return la valeur de fonction d'objectif + */ + public double calculFonctionObjectif(ResultStorage result){//Inclut l'import des données, des résultats de la simulation et le calcul de la fonction d'objectif; + /////***import the matrix of simulated data (here landings) from the simulation result + MatrixND L = result.getMatrix(param_Population, + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); + /////*** extract, sum, etc to obtain the same format/data as your observation matrix + // useful methods to work on matrix : sumOverDim(), getSubMatrix(), reduce() + + ///////////////////Calcul du critere////////////////// + log.info("calcul de la fonction objectif"); + log.info("dim de L" + " " + Arrays.toString(L.getDim())); + log.info("dim de obs" + " " + + Arrays.toString(matrixDebarquement.getDim())); + + double obj = 0; + // *** using the matrixIterator assumes that the observation and simulated + // matrix are organised in the exact same way ( columns and rows corresponding in each of them) + for (MatrixIterator g = L.iterator(); g.hasNext();) { + g.next(); + int[] dim = g.getCoordinates(); + double obs = matrixDebarquement.getValue(dim); + double simules = g.getValue(); + obj += Math.pow(obs - simules, 2); + } + return obj; + } + + /** + *Vérifie si le critère d'arrêt de l'algorithme est atteint, les critères pouvant changer selon les préférences de l'utilisateur. + *@param compteurSimus le numéro de la simulation qui vient de s'achever + *@return true si le critère est atteint, false sinon. + */ + public boolean isCritereArretAtteint(Experience expCurrent){// Critèe à choisir? A rendre variable au cours de l'algorithme? (autant sur le critèe d'une méthode que sur la méthode employée?) + //Méthode 1 + double deltaEnergy = expCurrent.objective - expCurrent.parent.objective; + boolean bool = deltaEnergy < seuilArret; //seuil à déterminer + + /* + if (temperature<seuilArret) //seuil à déterminer + double temperature = getExperience(compteurSimus).temperature + bool=true; + + if (compteurSimus>seuilArret) //seuil à déterminer + bool=true; + + //Méthode 4 numéro de phase...vraiment? + */ + //etc. + return bool; + } + + /** + *Calcule ce qu'on appelle (abusivement) la probabilité d'accepter la nouvelle paramétrisation, appelée par @see acceptationSolution + *@param deltaEnergy la différence de fonction d'objectif entre la nouvelle paramétrisation et la paramétrisation courante + *@return la "probabilité" + */ + public double getProba(Experience expCurrent, double deltaEnergy){ + double temp = expCurrent.temperature; + double proba = Math.exp(deltaEnergy/temp); + return proba; + } + /* + /** + *Vérifie si le critère de modification de la température est atteint, les critères pouvant varier selon les préférences de l'utilisateur. + *@return true s'il faut modifier la température (@see modifierTemperature), false sinon. + *:/ + public boolean isModifierTemperature(){//Renvoie un booléen qui indique s'il faut changer ou non la température. + boolean bool=false; + if (compteurTemperature>seuilTemperature || compteurAccept>seuilAcceptance){//seuils à fixer/déterminer + bool=true; + } + return bool; + } + */ + + /** + *Récupère le numéro de la simulation renseignée + *@param simulation storage de la simulationr enseignée + *@return numéro de la simulation renseignée + */ + public int getIteration(SimulationStorage simulation){ //Il n'y a pas de setIteration + return simulation.getParameter().getSimulationPlanNumber(); + } +} \ No newline at end of file Property changes on: trunk/src/test/resources/test-database/simulationplans/RecuitSimuleSimulateur.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/test/resources/test-database/simulationplans/SimulationNumberRestriction.java =================================================================== --- trunk/src/test/resources/test-database/simulationplans/SimulationNumberRestriction.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/simulationplans/SimulationNumberRestriction.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package simulationplans; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,11 +47,11 @@ @Doc(value = "do the doc of param max") public int param_max = 10; - public String[] necessaryResult = { - // put here all necessary result for this rule - // example: - // ResultName.MATRIX_BIOMASS, - // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, + protected String[] necessaryResult = { + // put here all necessary result for this rule + // example: + // ResultName.MATRIX_BIOMASS, + // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; @Override @@ -68,7 +66,7 @@ */ @Override public String getDescription() throws Exception { - return _("Permit to specify maximum simulation numbers"); + return "Permit to specify maximum simulation numbers"; } /** @@ -85,10 +83,8 @@ /** * Call before each simulation * - * @param context - * plan context - * @param nextSimulation - * storage used for next simulation + * @param context plan context + * @param nextSimulation storage used for next simulation * @return true if we must do next simulation, false to stop plan * @throws Exception */ @@ -102,8 +98,7 @@ /** * Call after each simulation * - * @param context - * plan context + * @param context plan context * @param lastSimulation storage used for last simulation * @return true if we must do next simulation, false to stop plan * @throws Exception Modified: trunk/src/test/resources/test-database/simulators/DefaultSimulator.java =================================================================== --- trunk/src/test/resources/test-database/simulators/DefaultSimulator.java 2014-07-29 11:59:25 UTC (rev 4073) +++ trunk/src/test/resources/test-database/simulators/DefaultSimulator.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2014 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 @@ -19,24 +19,8 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ - package simulators; -import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixFactory; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; - -import scripts.GravityModel; -import scripts.ResultName; -import scripts.SiMatrix; import fr.ifremer.isisfish.IsisFishException; import fr.ifremer.isisfish.datastore.ResultStorage; import fr.ifremer.isisfish.entities.Metier; @@ -51,13 +35,27 @@ import fr.ifremer.isisfish.simulator.SimulationControl; import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.Simulator; +import fr.ifremer.isisfish.types.Month; import fr.ifremer.isisfish.types.TimeStep; -import fr.ifremer.isisfish.types.Month; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixFactory; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import scripts.GravityModel; +import scripts.ResultName; +import scripts.SiMatrix; +import java.util.List; + +import static org.nuiton.i18n.I18n.t; +import static org.nuiton.i18n.I18n.n; + /** * DefaultSimulator.java * - * Created: 21 août 2006 10:57:46 + * Created: 21 aout 2006 10:57:46 * * @author poussin * @version $Revision: 1.19 $ @@ -134,12 +132,12 @@ control.setStep(step); control.setProgress(step.getStep()); - control.setText(_("begin step " + step)); + control.setText(t("begin step " + step)); // // Reload parameters for current step // - control.setText(_("Reloading parameters")); + control.setText(t("Reloading parameters")); // reload context parameters with db.rollbackTransaction() context param.reloadContextParameters(); rules = param.getRules(); @@ -217,11 +215,12 @@ for (Population pop : siMatrix.getPopulations(step)) { computeMonth(context, siMatrix, step, pop); } - + // // Add some result not population dependante // + // only if there are one or more strategy if (siMatrix.getStrategies(step).size() > 0) { @@ -288,9 +287,9 @@ siMatrix.getMetiers(step), pop.getPopulationGroup(), pop.getPopulationZone() }, - new String[] { n_("Strategies"), - n_("Metiers"), n_("Groups"), - n_("Zones") }); + new String[] { n("Strategies"), + n("Metiers"), n("Groups"), + n("Zones") }); } resManager.addResult(step, pop, discard); @@ -309,12 +308,11 @@ // add landing result // if (resManager.isEnabled(ResultName.MATRIX_LANDING_PER_MET)) { - MatrixND landing = MatrixFactory.getInstance().create( - populationMonitor.getCatch(pop)); + MatrixND landing = populationMonitor.getCatch(pop).copy(); + landing.setName(ResultName.MATRIX_LANDING_PER_MET); if (discard != null) { landing = landing.minus(discard); } - landing.setName(ResultName.MATRIX_LANDING_PER_MET); resManager.addResult(step, pop, landing); } } @@ -338,6 +336,7 @@ // step = step.next(); } + } protected boolean isEffortByCell(SimulationContext context) { @@ -375,7 +374,7 @@ PopulationSeasonInfo info = pop.getPopulationSeasonInfo(month); // group change - MatrixND CA = null; + MatrixND CA; if (step.getStep() == 0) { CA = MatrixFactory.getInstance().matrixId( pop.sizePopulationGroup() * pop.sizePopulationZone()); @@ -411,7 +410,7 @@ log.debug("N after mig: " + N); - //Recrutement + // reproduction MatrixND R = info.getReproductionMatrix(month, N); log.debug("R: " + R); @@ -440,7 +439,7 @@ resManager.addResult(step, pop, biomassBM); } - MatrixND abundance = N; + MatrixND abundance; // compute fishing matrix only if there are one or more strategy if (siMatrix.getStrategies(step).size() > 0) { // compute some Matrix and add result @@ -481,7 +480,7 @@ .matrixCatchWeightPerStrategyMetPerZonePop(step, pop, catchPerStrategyMetPerZonePop); resManager.addResult(step, pop, catchWeightPerStrategyMet); - } + } if (isEffortByCell(context)) { MatrixND catchPerStrategyMetPerZoneMet = siMatrix @@ -497,6 +496,21 @@ } } + 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()); + + 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); + } + } + } else { // no strategies // compute only if fishing mortality =0 to apply Natural Mortality abundance = siMatrix.matrixAbundanceSsF(N, pop, step); @@ -512,7 +526,7 @@ } /** - * @param date + * @param step * @param resManager * @throws IsisFishException * @throws TopiaException @@ -555,10 +569,6 @@ .matrixSharedNotFixedCostsPerVessel(step); resManager.addResult(step, mat); } - // if (resManager.isEnabled(ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET)) { - // MatrixND mat = gravityModel.matrixSharedFixedCostsPerVesselPerMet(date); - // resManager.addResult(date, mat); - // } if (resManager .isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET)) { MatrixND mat = gravityModel Added: trunk/src/test/resources/test-database/simulators/SimulatorEffortByCell.java =================================================================== --- trunk/src/test/resources/test-database/simulators/SimulatorEffortByCell.java (rev 0) +++ trunk/src/test/resources/test-database/simulators/SimulatorEffortByCell.java 2014-07-29 14:44:48 UTC (rev 4074) @@ -0,0 +1,54 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2009 - 2014 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 simulators; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.simulator.SimulationContext; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.simulator.Simulator; + +/** + * 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 { + + /** 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); + } + +} Property changes on: trunk/src/test/resources/test-database/simulators/SimulatorEffortByCell.java ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision HeadURL