/* * Copyright (C) 2014 slehuta * * 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 scripts.ResultName; import java.io.Writer; import org.nuiton.math.matrix.*; import org.nuiton.util.*; import org.nuiton.topia.*; import fr.ifremer.isisfish.util.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.SimulationContext; import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.SimulationPlanIndependent; import fr.ifremer.isisfish.simulator.SimulationPlanContext; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.datastore.ResultStorage; import java.io.File; import java.io.FileReader; /** * SaisineSole0914.java * * Created: 30 septembre 2014 * * @author slehuta * @version $Revision: 1545 $ * Last update: $Date: 30 septembre 2014 $ * by : $Author: slehuta $ */ public class SaisineSole0914 implements SimulationPlanIndependent{ /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(SaisineSole0914.class); private MatrixND mateffInit2008 = null; private MatrixND mateffInit2009 = null; private MatrixND mateffInit2010 = null; static private final String effInit2008 = "InputMixChannel/EffectifsInitiauxSole2008_V5.csv"; static private final String effInit2009 = "InputMixChannel/EffectifsInitiauxSole2009_V5.csv"; static private final String effInit2010 = "InputMixChannel/EffectifsInitiauxSole2010_V5.csv"; public int param_first = 0; public int param_simulationNumber = 51; public String param_directory = "InputMixChannel/EffortMatrices/"; 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 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 "Modif effectifs initiaux"; } /** * Called once before {@code beforeSimulation} call. * * @param context plan context */ @Override public void init(SimulationPlanContext context) throws Exception { mateffInit2008 = MatrixFactory.getInstance().create(new int[]{11, 31}); mateffInit2008.importCSV(new FileReader(new File(effInit2008)), new int[]{0,0}); mateffInit2009 = MatrixFactory.getInstance().create(new int[]{11, 31}); mateffInit2009.importCSV(new FileReader(new File(effInit2009)), new int[]{0,0}); mateffInit2010 = MatrixFactory.getInstance().create(new int[]{11, 31}); mateffInit2010.importCSV(new FileReader(new File(effInit2010)), 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(); if (simNum < param_simulationNumber) { String fin = "InactivityHistoric2008-2010_saisine_"; int y = (int) (simNum + param_first)/17; int reduc = simNum + param_first - y * 17; String FileInactivityName = fin + reduc + ".csv"; log.info(FileInactivityName); nextSimulation.getParameter().getTagValue().put("year",Integer.toString(y)); nextSimulation.getParameter().getTagValue().put("FileInactivityName",FileInactivityName); nextSimulation.getParameter().getTagValue().put("Saisine","yes"); Population pop = nextSimulation.getParameter().getPopulations().get(0); MatrixND mat = nextSimulation.getParameter().getNumberOf(pop); MatrixND mateffInit = null; if(y == 0){ mateffInit = mateffInit2008; }else if(y == 1){ mateffInit = mateffInit2009; }else{ mateffInit = mateffInit2010; } for(MatrixIterator i = mat.iterator(); i.hasNext();){ i.next(); int[] dim = i.getCoordinates(); double val = mateffInit.getValue(dim); i.setValue(val); } 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; } }