/* * Copyright (C) 2022 aricouar * * 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 * . */ package simulationplans; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.Writer; import org.nuiton.math.matrix.*; import org.nuiton.util.*; import org.nuiton.topia.*; import resultinfos.*; import fr.ifremer.isisfish.annotations.Doc; import fr.ifremer.isisfish.*; import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.entities.*; import fr.ifremer.isisfish.simulator.SimulationPlan; import fr.ifremer.isisfish.simulator.SimulationPlanContext; import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.simulator.ResultManager; import fr.ifremer.isisfish.rule.Rule; import fr.ifremer.isisfish.rule.RuleHelper; import fr.ifremer.isisfish.datastore.RuleStorage; import java.util.Properties; import java.util.List; import java.io.File; import java.io.FileReader; /** * MyPlan1.java */ public class MyPlan1 implements SimulationPlan { public int param_parameterNumber = 1; public int param_first = 0; public int param_simulationNumber = 2; public String param_directory = "C:/Users/aricouar/Documents/MesProjets_local/ISIS_simul/isis-fish-4.4.7.2/input/effort-ranges"; public String param_MATRIX = "range1"; //contains the value of effort reduction to be simulated private MatrixND matrix = null; /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(MyPlan1.class); protected String[] necessaryResult = { // put here all necessary result for this rule // example: // MatrixBiomass.NAME, // MatrixNetValueOfLandingsPerStrategyMet.NAME, }; @Override 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 */ @Override public String getDescription() throws Exception { // TODO change description return "TODO MyPlan1 description plan"; } /** * Called once before {@code beforeSimulation} call. * * @param context plan context */ @Override public void init(SimulationPlanContext context) throws Exception { // TODO // Reads the range of effort reduction factor to be simulated File dir = new File(param_directory); matrix = MatrixFactory.getInstance().create(new int[]{param_simulationNumber, param_parameterNumber}); matrix.importCSV(new FileReader(new File(dir, param_MATRIX + ".csv")), new int[]{0,0}); } /** * Call before each simulation. * * @param context plan context * @param nextSimulation storage used for next simulation * @return true if we must do next simulation, false to stop plan * @throws Exception */ @Override public boolean beforeSimulation(SimulationPlanContext context, SimulationStorage nextSimulation) throws Exception { int simNum = nextSimulation.getParameter().getSimulationPlanNumber() + param_first; System.out.println("etape3 : determiner getDouble valeur simNum : " + simNum); if (simNum+param_first < param_simulationNumber){ ////////////////////////////////////////////////////////////////////////////////////////// // Modif rule List paramRules = nextSimulation.getParameter().getRules(); double param_PercentReduction = matrix.getValue(simNum,0); int ruleNum = 3; System.out.println("etape4 , PercentReduction =" + param_PercentReduction); String ruleName = "EffortReduction"; Properties propert = new Properties(); propert.put("rule."+ruleNum+".parameter.beginStep", ""+0); propert.put("rule."+ruleNum+".parameter.endStep", ""+132); propert.put("rule."+ruleNum+".parameter.PercentReduction", ""+param_PercentReduction); RuleStorage ruleStorage = RuleStorage.getRule(ruleName); Rule rule = ruleStorage.getNewInstance(); RuleHelper.populateRule(ruleNum, nextSimulation.getStorage(), rule, propert); paramRules.add(rule); System.out.println("etape4 : fin du changement de reduction"); return true; }else return false; } /** * Call after each simulation. * * @param context plan context * @param lastSimulation storage used for simulation * @return true if we must do next simulation, false to stop plan * @throws Exception */ @Override public boolean afterSimulation(SimulationPlanContext context, SimulationStorage lastSimulation) throws Exception { return true; } }