/* * Copyright (C) 2024 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 rules; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import scripts.SiMatrix; import fr.ifremer.isisfish.entities.Metier; import fr.ifremer.isisfish.entities.Strategy; import fr.ifremer.isisfish.rule.AbstractRule; import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.TimeStep; import fr.ifremer.isisfish.annotations.Doc; import org.nuiton.math.matrix.*; import java.util.regex.Pattern; import static scripts.PTAtoolbox.expandEnvirVar; import java.io.File; import java.io.FileReader; import fr.ifremer.isisfish.entities.*; import fr.ifremer.isisfish.types.*; /** * MaccoEquilibriumRestartSim.java */ public class MaccoEquilibriumRestartSim extends AbstractRule { /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(MaccoEquilibriumRestartSim.class); public String paramPath = "${PBS_O_WORKDIR}/RUN"; private MatrixND matNinit = null; protected String[] necessaryResult = { // put here all necessary result for this rule // example: // MatrixBiomass.NAME, // MatrixNetValueOfLandingsPerStrategyMet.NAME, }; public String[] getNecessaryResult() { return this.necessaryResult; } /** * Permet d'afficher a l'utilisateur une aide sur la regle. * @return L'aide ou la description de la regle */ public String getDescription() throws Exception { return "Set initial abundance of each species, as a function of exploitation pattern and effort reduction parameter, when the simulation is restarted"; } /** * Appel�� au d��marrage de la simulation, cette m��thode permet d'initialiser * des valeurs. * * @param context la simulation pour lequel on utilise cette regle */ public void init(SimulationContext context) throws Exception { String simu = context.getSimulationControl().getId();// String simu = "simu_i0"; System.out.println("nom de la simu en cours : " + simu); Pattern simulNamePattern = Pattern.compile("^(.+)_(i\\d+)$"); for (Population pop : context.getSimulationStorage().getParameter().getPopulations()) { String popName = pop.getName(); String path = simulNamePattern.matcher(simu).replaceAll("_$1/$2/"); // exemple : "simu_i0" devient "RUN_simu/i0/" path = path + popName + "_restart.csv"; System.out.println("file : " + path); paramPath = expandEnvirVar.replace(paramPath); if(popName == "Nephrops_norvegicus"){ matNinit = MatrixFactory.getInstance().create(new int[]{58,10});// create a matrix with 58 lines and 10 columns }else if(popName == "Merluccius_merluccius"){ matNinit = MatrixFactory.getInstance().create(new int[]{72,6}); }else if(popName == "Solea_solea"){ matNinit = MatrixFactory.getInstance().create(new int[]{7,3}); }else if(popName == "Lepidorhombus_whiffiagonis"){ matNinit = MatrixFactory.getInstance().create(new int[]{10,4}); }else if(popName == "Lophius_piscatorius"){ matNinit = MatrixFactory.getInstance().create(new int[]{8,4}); }else if(popName == "Raja_clavata"){ matNinit = MatrixFactory.getInstance().create(new int[]{1,3}); }else if(popName == "Leucoraja_naevus"){ matNinit = MatrixFactory.getInstance().create(new int[]{1,1}); } matNinit.importCSV(new FileReader(new File(paramPath + path)), new int[]{0,0}); MatrixND mat = context.getSimulationStorage().getParameter().getNumberOf(pop); for(MatrixIterator i = mat.iterator(); i.hasNext();){ i.next(); int[] dim = i.getCoordinates(); double val = matNinit.getValue(dim); i.setValue(val); } System.out.println("new initial conditions : " + mat); } } /** * La condition qui doit etre vrai pour faire les actions. * * @param context la simulation pour lequel on utilise cette regle * @param step le pas de temps courant * @param metier le metier concern�� * @return vrai si on souhaite que les actions soit faites */ public boolean condition(SimulationContext context, TimeStep step, Metier metier) throws Exception { return false; } /** * 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�� */ public void preAction(SimulationContext context, TimeStep step, Metier metier) throws Exception { // TODO } /** * Si la condition est vrai alors cette action est execut��e 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�� */ public void postAction(SimulationContext context, TimeStep step, Metier metier) throws Exception { // TODO } }