Bonjour Eric, Toujours bloqué. Je t'envoie ma base, les scripts et les règles nécessaires au lancement des simulations. Je continue à chercher de mon côté. Paul Eric Chatellier a écrit :
Le 28/10/2011 16:17, Paul MARCHAL a écrit :
Bonjour,
J'ai lancé une appli ISIS comportant plusieurs règles. Tout se passe bien les 5 premières années, mais à la sixième (jan 5), la simulation semble bloquée. Dans le fichier debug.txt (ci-joint), une ligne est répétée en boucle:
*INFO [monitor-thread] (SimulationControl.java:201) setText - Do pre action Rules * Merci d'avance pour votre aide
Il n'y a rien dans le debug. Y a-t-il quelque chose de plus interressant dans le fichier "simulation.log" de la simulation concernée ?
-- Paul Marchal IFREMER RBE/HMMN 150, Quai Gambetta BP 699 62321 Boulogne sur mer FRANCE Tel: (+33) 321 99 56 86 Fax: (+33) 321 99 56 01 Mail: paul.marchal@ifremer.fr /* * Copyright (C) 2010 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package rules; import static org.nuiton.i18n.I18n._; import org.nuiton.j2r.REngine; import org.nuiton.j2r.RException; import org.nuiton.j2r.RProxy; import org.nuiton.j2r.types.RDataFrame; import scripts.ResultName; import scripts.SiMatrix; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.types.Date; import fr.ifremer.isisfish.types.Month; import scripts.ResultName; import java.io.Writer; import fr.ifremer.isisfish.export.Export; import java.io.File; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import org.nuiton.util.FileUtil; import org.nuiton.math.matrix.*; import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.Date; import fr.ifremer.isisfish.entities.*; import fr.ifremer.isisfish.rule.AbstractRule; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.datastore.ResultStorage; import org.nuiton.math.matrix.MatrixIterator; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.simulator.SimulationControl; import fr.ifremer.isisfish.simulator.SimulationProperties; /** * XSA.java * * Created: 11 mars 2010 * * @author ben <user.name@vcs.hostName> * @version $Revision: 1545 $ * Last update: $Date: 12 juillet 2011 $ * by : $Author: Paul et Youen $ */ public class XSA extends AbstractRule { /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(XSA.class); protected TopiaContext db = null; private MatrixND catchYear0; private MatrixND effortS1Met0; private MatrixND catchS1Met0; public MatrixND matrixCpue; public static MatrixND matrixNageExport; public static MatrixND matrixFageExport; public static double ssbExport, fbarExport; RDataFrame FauxAges; RDataFrame NauxAges; // Configuration @Doc("Mois de l'evaluation") public Month param_month = Month.JANUARY; // Matrices necessaires public String [] necessaryResult = { ResultName.MATRIX_ABUNDANCE, ResultName.MATRIX_BIOMASS, ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP, ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP }; public String[] getNecessaryResult() { return this.necessaryResult; } public String getDescription() throws Exception { return _("Fait une XSA"); } public void init(SimulationContext context) throws Exception { Date date = new Date(0); List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date); List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date); List<Month> months = Arrays.asList(Month.MONTH); List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date); List<PopulationGroup> agegroupsall = new ArrayList<PopulationGroup>(); this.db = context.getDB(); for (Population pop : populations) { if (pop.getName().compareTo("BlueLingSouth") == 0){ for (PopulationGroup age : pop.getPopulationGroup()) { PopulationGroup tmp = (PopulationGroup) db.findByTopiaId(age.getTopiaId()); agegroupsall.add(tmp); } } } catchYear0 = MatrixFactory.getInstance().create( "catchYear0", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); catchS1Met0 = MatrixFactory.getInstance().create( "catchS1MetYear0", new List[]{agegroupsall,metiers}, new String[]{"AgeGroupsAll","Metiers"}); effortS1Met0 = MatrixFactory.getInstance().create( "effortS1MetYear0", new List[]{metiers}, new String[]{"Metiers"}); matrixCpue = MatrixFactory.getInstance().create( "matrixCpue", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixNageExport = MatrixFactory.getInstance().create( "matrixNageExport", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFageExport = MatrixFactory.getInstance().create( "matrixFageExport", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); REngine engine = new RProxy(); engine.voidEval("library(FLXSA)"); engine.voidEval("stock<-readFLStock(\"C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/VPA/bli567ind.txt\")"); engine.voidEval("indices<-readFLIndices(\"C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/VPA/bli567fl.txt\")"); //engine.voidEval("stock<-readFLStock(\"F:/D/Projets/deepfishman/Blue ling/bli567ind.txt\")"); // //engine.voidEval("indices<-readFLIndices(\"F:/D/Projets/deepfishman/Blue ling/bli567fl.txt\")"); // Parametres XSA engine.voidEval("tol<-1.e-09"); engine.voidEval("maxit<-1000"); engine.voidEval("min.nse<-0.3"); engine.voidEval("fse<-2.0"); engine.voidEval("rage<-9"); engine.voidEval("qage<-17"); engine.voidEval("shk.n<-TRUE"); engine.voidEval("shk.f<-TRUE"); engine.voidEval("shk.yrs<-5"); engine.voidEval("shk.ages<-5"); engine.voidEval("window<-100"); engine.voidEval("tsrange<-20"); engine.voidEval("tspower<-3"); // stocke dans FLXSA les parametres engine.voidEval("xsa.control<-FLXSA.control(tol=tol,maxit=maxit,min.nse=min.nse,fse=fse,rage=rage,qage=qage,shk.n=shk.n,shk.f=shk.f,shk.yrs=shk.yrs,shk.ages=shk.ages,window=window,tsrange=tsrange,tspower=tspower,vpa=FALSE)"); engine.voidEval("stock@catch.n <- stock@landings.n"); // recupere les capt aux ages de l annee precedente engine.voidEval("save.image(file=\"C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/VPA/xsaRes.RData\")"); // sauver l'objet pour pouvoir le rouvrir ensuite pour utilisation //engine.voidEval("save.image(file=\"F:/D/Projets/deepfishman/Blue ling/xsaRes.RData\")"); // sauver l'objet pour pouvoir le rouvrir ensuite pour utilisation } /** * La condition qui doit etre vrai pour faire les actions * @param simulation La simulation pour lequel on utilise cette regle * @return vrai si on souhaite que les actions soit faites */ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception { Month currentMonth = date.getMonth(); if (currentMonth.equals(param_month) && (date.getYear() > 0)) { return true; } else return false; } // Booleen permettant que ne boucler que sur un seul metier dans la preaction : boolean first = true; /** * @param simulation La simulation pour lequel on utilise cette regle */ public void preAction(SimulationContext context, Date date, Metier metier) throws Exception { if (first){ List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date); List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date); List<Month> months = Arrays.asList(Month.MONTH); List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date); ResultStorage resultmanager = context.getSimulationStorage().getResultStorage(); for (Population pop : populations) { if (pop.getName().compareTo("BlueLingSouth") == 0){ List<PopulationGroup> agegroups = pop.getPopulationGroup(); for (PopulationGroup age : agegroups){ catchYear0.setValue(age,0.0); for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ for (Metier met : metiers){ catchS1Met0.setValue(age,met,0.0); effortS1Met0.setValue(met,0.0); } } } } // end of age loop; for (Date dat = date.previousYear(); dat.before(date); dat = dat.next()) { MatrixND CatchPop = resultmanager.getMatrix(dat,pop,ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP); MatrixND EffortS1Met = resultmanager.getMatrix(dat,ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); MatrixND Prov2 = CatchPop.sumOverDim(0); // sum over strategies; Prov2 = Prov2.sumOverDim(1); // sum over metiers; Prov2 = Prov2.sumOverDim(3); // sum over zones; MatrixND Prov3 = CatchPop.sumOverDim(3); // sum over zones; for (PopulationGroup age : agegroups){ catchYear0.setValue(age,catchYear0.getValue(age)+Prov2.getValue(0,0,age,0)); } //end of age loop; for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ for (Metier met : metiers){ for (PopulationGroup age : agegroups){ catchS1Met0.setValue(age,met,catchS1Met0.getValue(age,met)+ Prov3.getValue(str,met,age,0)); } // end of age loop; effortS1Met0.setValue(met,effortS1Met0.getValue(met)+ EffortS1Met.getValue(str,met)); } // end of metier loop; } // end of str = S1 if-test; } // end of str loop; } // end of dat loop; for (PopulationGroup age : agegroups){ double dummyCpue = 0.0; int dummyMet = 0; for (Metier met : metiers){ if (effortS1Met0.getValue(met) > 0.0){ dummyCpue += catchS1Met0.getValue(age,met)/effortS1Met0.getValue(met); dummyMet++; } } // end of metier loop; if (dummyMet > 0){ //matrixCpue.setValue(age,pop,dummyCpue/dummyMet); matrixCpue.setValue(age,dummyCpue/dummyMet);//YV } else{ matrixCpue.setValue(age,0.00); } } // end of age loop; // Si on est au mois de Janvier, avant le pas de temps: // Recuperer les captures aux ages etc du pas de temps precedent // realiser la xsa //log.info("Avant engine"); REngine engine = new RProxy(); //log.info("Avant import"); engine.voidEval("load(file=\"C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/VPA/xsaRes.RData\")"); //engine.voidEval("load(file=\"F:/D/Projets/deepfishman/Blue ling/xsaRes.RData\")"); // etendre l'objet FLR // Objet Stock engine.voidEval("stock<-window(stock,end=range(stock)[5]+1)"); // On agrandit la fenetre temporelle du stock de 1 YV log.info("catchYear0" + catchYear0); MatrixND caaAexprter = catchYear0.getSubMatrix(0,7,14) ; log.info("caaAexporter" + caaAexprter); // int j=0; String essaimatrix = "test <- c("; for(MatrixIterator i = caaAexprter.iterator();i.hasNext();){ i.next(); j = j+1; if (j < 14) { essaimatrix += i.getValue() + ","; } else { essaimatrix += i.getValue(); } } essaimatrix = essaimatrix + ")"; engine.voidEval(essaimatrix); //log.info("essaimatrix=" + essaimatrix); //engine.voidEval("save.image(file=\"F:/D/Projets/deepfishman/Blue ling/xsaRes.RData\")"); //engine.voidEval("test<-as.vector(" + caaAexprter + ")"); engine.voidEval("stock@catch.n[,dim(stock@catch.n)[2],,,] <-test/1000" ); // recupere les capt aux ages de l annee precedente engine.voidEval("stock@catch.wt[,dim(stock@catch.n)[2],,,]<-as.vector(rowMeans(stock@catch.wt[,c((dim(stock@catch.wt)[2] - 1):(dim(stock@catch.wt)[2] - 3)),,,]))"); // calcule la moyenne des poids aux ages sur les 3 dernieres annees engine.voidEval("stock@landings.n[,dim(stock@landings.n)[2],,,]<-stock@catch.n[,dim(stock@catch.n)[2],,,] "); // pas de rejets les capt==debarquements engine.voidEval("stock@landings.wt[,dim(stock@landings.wt)[2],,,]<-as.vector(rowMeans(stock@landings.wt[,c((dim(stock@landings.wt)[2] - 1):(dim(stock@landings.wt)[2] - 3)),,,]))"); // calcule la moyenne des poids aux ages sur les 3 dernieres annees engine.voidEval("stock@stock.wt[,dim(stock@stock.wt)[2],,,]<-as.vector(rowMeans(stock@stock.wt[,c((dim(stock@stock.wt)[2] - 1):(dim(stock@stock.wt)[2] - 3)),,,]))"); // calcule la moyenne des poids aux ages sur les 3 dernieres annees engine.voidEval("stock@m[,dim(stock@m)[2],,,]<-stock@m[,dim(stock@m)[2] - 1,,,] "); // copie la M de l'anne precedente engine.voidEval("stock@mat[,dim(stock@mat)[2],,,]<-stock@mat[,dim(stock@mat)[2] - 1,,,] "); // copie la Maturite de l'anne precedente engine.voidEval("stock@harvest.spwn[,dim(stock@harvest.spwn)[2],,,]<-stock@harvest.spwn[,dim(stock@harvest.spwn)[2] - 1,,,] "); // engine.voidEval("stock@m.spwn[,dim(stock@m.spwn)[2],,,]<-stock@m.spwn[,dim(stock@m.spwn)[2] - 1,,,] "); // // Objet fleet engine.voidEval("indices<-window(indices,end=range(indices)[4]+1)"); // On agrandit la fenetre temporelle de fleet de 1 YV MatrixND iaAexprter = matrixCpue.getSubMatrix(0,7,14) ; // int j2=0; String essaimatrix2 = "test <- c("; for(MatrixIterator i = iaAexprter.iterator();i.hasNext();){ i.next(); j2 = j2+1; if (j2 < 14) { essaimatrix2 += i.getValue() + ","; } else { essaimatrix2 += i.getValue(); } } essaimatrix2 = essaimatrix2 + ")"; engine.voidEval(essaimatrix2); engine.voidEval("indices@.Data[[1]]@catch.n[,dim(indices@.Data[[1]]@catch.n)[2],,,]<-test/1000");// recupere les indices aux ages de l annee precedente engine.voidEval("indices@.Data[[1]]@effort[,dim(indices@.Data[[1]]@effort)[2],,,]<-1");// recupere les indices aux ages de l annee precedente log.info("Avant XSA"); // Faire la xsa engine.voidEval("xsa<-FLXSA(stock,indices,xsa.control)"); log.info("Apres XSA"); engine.voidEval("save.image(file=\"C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/VPA/xsaRes.RData\")"); //engine.voidEval("save.image(file=\"F:/D/Projets/deepfishman/Blue ling/xsaRes.RData\")"); // retourner ssb et f de la derniere annee engine.voidEval("range(stock)[3]<-range(xsa)[3]"); engine.voidEval("stock<-stock+xsa"); Double ssb = ((Double) engine.eval("ssb<-as.numeric(as.data.frame(ssb(stock)[1,ncol(ssb(stock))]))[7]")).doubleValue(); Double fbar = ((Double) engine.eval("fbar<-as.numeric(as.data.frame(fbar(stock)[1,ncol(fbar(stock))]))[7]")).doubleValue(); FauxAges = (RDataFrame) engine.eval("FauxAges <- as.data.frame(as.data.frame(harvest(stock)[,ncol(harvest(stock))])$data)"); NauxAges = (RDataFrame) engine.eval("NauxAges<- as.data.frame(as.data.frame(stock.n(stock)[,ncol(stock.n(stock))])$data)"); //MatrixND FauxAges = ((MatrixND) engine.eval("FauxAges <- as.data.frame(harvest(xsa.stock)[,ncol(harvest(xsa.stock))])$data")).doubleValue(); //MatrixND NauxAges = ((MatrixND) engine.eval("NauxAges <- as.data.frame(stock.n(xsa.stock)[,ncol(stock.n(xsa.stock))])$data")).doubleValue(); ssbExport = ssb; fbarExport = fbar; //log.info("agegroups = " + agegroups); for (int iage=0; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); if (iage < 7){ matrixNageExport.setValue(age,0.0); matrixFageExport.setValue(age,0.0); } // end of iage if-test; else{ //log.info("NauxAges.get(iage-7,1) = " + NauxAges.get(iage,1) + "iage= " + iage); //log.info("age = " + iage); //log.info("NauxAges = " + NauxAges.get(0,iage-7)); matrixNageExport.setValue(age,(Double) NauxAges.get(0,iage-7)); matrixFageExport.setValue(age,(Double) FauxAges.get(0,iage-7)); } // end of iage else-test; } // end of age for loop; engine.voidEval("save.image(file=\"C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/VPA/xsaRes.RData\")"); //engine.voidEval("save.image(file=\"F:/D/Projets/deepfishman/Blue ling/xsaRes.RData\")"); } // end of pop=bli if-test; } // end of pop loop; first = false; } // end of (first) if-test; } /** * @param simulation La simulation pour lequel on utilise cette regle */ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception { first = true; } } /* * Copyright (C) 2010 pmarchal * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package rules; import static org.nuiton.i18n.I18n._; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import scripts.ResultName; import scripts.SiMatrix; import scripts.Fmin; import scripts.Fmsy; import scripts.Fsq; import scripts.Fmgt; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.io.File; import java.io.Writer; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.FileReader; import org.nuiton.math.matrix.*; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.Date; import fr.ifremer.isisfish.types.Month; import fr.ifremer.isisfish.entities.*; import fr.ifremer.isisfish.rule.AbstractRule; import fr.ifremer.isisfish.datastore.ResultStorage; import org.nuiton.util.FileUtil; /** * CalcTAC.java * * Created: 8 septembre 2010 * * @author pmarchal <anonymous@labs.libre-entreprise.org> * @version $Revision: 1545 $ * Last update: $Date: 29 mars 2011 $ * by : $Author: pmarchal $ */ public class CalcTAC extends AbstractRule { /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(CalcTAC.class); protected TopiaContext db = null; // Output files facility; public String FichierOpti1 = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/FichierOpti1.csv"; protected File OptiFile1; public BufferedWriter outOpti1; public String FichierOpti2 = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/FichierOpti2.csv"; protected File OptiFile2; public BufferedWriter outOpti2; public String [] necessaryResult = { // put here all necessary result for this rule // example: // ResultName.MATRIX_BIOMASS, // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, }; public String[] getNecessaryResult() { return this.necessaryResult; } public String getDescription() throws Exception { return _("TODO description rule"); } public static double tacBLI67T0 = 2309000.0; //TAC(2009) of BLI in VI and VII; public static double qfrBLI67T0 = 1518000.0; //French quota(2009) of BLI in VI and VII; public static double pfrBLI67T0 = qfrBLI67T0/tacBLI67T0; //Proportion of french quota(2009) of BLI in VI and VII; public static double cafBLI5b1T0 = 865000.0; //French catch(2008) of BLI in Vb1; public static double cafBLI5b2T0 = 0.0; //French catch(2008) of BLI in Vb2; public static double cafBLI5bT0 = cafBLI5b1T0 + cafBLI5b2T0; //French catch(2008) of BLI in Vb; public static double cafLIN5b1T0 = 4000.0; //French catch(2008) of LIN in Vb1; public static double cafLIN5b2T0 = 2000.0; //French catch(2008) of LIN in Vb2; public static double cafLIN5bT0 = cafLIN5b1T0 + cafLIN5b2T0; //French catch(2008) of LIN in Vb; public static double cafBLILIN5bT0 = cafBLI5bT0 + cafLIN5bT0; //French catch(2008) of BLI and LIN in Vb; public static double qfrBLILIN5bFAT0 = 1992000.0; //French quota(2009) of BLI and LIN in Vb (FA); public static double qfrBLI5bFAT0 = qfrBLILIN5bFAT0*(cafBLI5bT0/cafBLILIN5bT0); //Estimated french quota(2009) of BLI in Vb(FA); public static double qfrBLI5bT0 = qfrBLI5bFAT0 + 28000.0/2; //Estimated french quota(2009) of BLI in Vb (all waters); public static double qfrBLI4T0 = 28000.0/2; //Estimated french quota(2009) of BLI in II and IV); public static double tacPOK34T0 = 125934000.0; //TAC(2009) of POK in III and IV; public static double qfrPOK34T0 = 31035000.0; //French quota(2009) of POK in III and IV; public static double pfrPOK34T0 = qfrPOK34T0/tacPOK34T0; //Proportion of french quota(2009) of POK in III and IV; public static double tacPOK5bEU6T0 = 13066000.0; //TAC(2009) of POK in Vb(EU) and VI; public static double qfrPOK5bEU6T0 = 8158000.0; //French quota(2009) of POK in Vb(EU) and VI - almost only in VI & 5bEU negligable; public static double qfrPOK5bFAT0 = 1463000.0; //French quota(2009) of POK in Vb(FA); public static double qfrPOK5b6T0 = qfrPOK5bEU6T0 + qfrPOK5bFAT0; //French quota(2009) of POK in Vb(all waters) and VI; public static double tacPOK78T0 = 3790000.0; //TAC(2009) of POK in VII, VIII...; public static double qfrPOK78T0 = 1723000.0; //French quota(2009) of POK in VII, VIII...; public static double tacRNG5b67T0 = 3910000.0; //TAC(2009) of RNG in Vb, VI and VII; public static double qfrRNG5b67T0 = 3222000.0; //French quota(2009) of RNG in Vb, VI and VII; public static double pfrRNG5b67T0 = qfrRNG5b67T0/tacRNG5b67T0; //Proportion of french quota(2009) of RNG in Vb, VI and VII; public static double qfrRNG4T0 = 11000.0; //French quota(2009) of RNG in I, II, IV...; public static double tacBSF5b67T0 = 2738000.0; //TAC(2009) of BSF in Vb, VI, VII, and XII; public static double qfrBSF5b67T0 = 2189000.0; //French quota(2009) of BSF in Vb, VI, VII, and XII; public static double pfrBSF5b67T0 = qfrBSF5b67T0/tacBSF5b67T0; //Proportion of french quota(2009) of BSF in Vb, VI, VII, and XII; public static double qfrBSF4T0 = 4000.0; //French quota(2009) of BSF in I, II, IV...; public static double tacDWST0 = 824000.0; //TAC(2009) of DWS in V-IXb; public static double qfrDWST0 = 339000.0; //French quota(2009) of DWS in V-IXb; public static double pfrDWST0 = qfrDWST0/tacDWST0; //Proportion of french quota(2009) of DWS in V-IX; private MatrixND catchYear0; private MatrixND effortS1Met0; private MatrixND catchS1Met0; public MatrixND matrixCpue; public MatrixND matrixCpueMean; public MatrixND matrixYmeanFra; public MatrixND matrixYmeanOth; public MatrixND matrixSlope; public MatrixND matrixNcur; public MatrixND matrixNest; public MatrixND matrixNageXSA; public MatrixND matrixB0; public MatrixND matrixBmsy; public MatrixND matrixBlim; public MatrixND matrixBcur; public MatrixND matrixBest; public MatrixND matrixCcurFra; public MatrixND matrixCestFra; public MatrixND matrixCestOth; public MatrixND matrixYmsy; public MatrixND matrixYcurFra; public MatrixND matrixYcurOth; public MatrixND matrixYestFra; public MatrixND matrixYestOth; public static MatrixND matrixYmgtFra; public MatrixND matrixYmgtOth; public MatrixND matrixFmsy; public MatrixND matrixFcur; public MatrixND matrixFcurFra; public MatrixND matrixFcurOth; public MatrixND matrixFest; public MatrixND matrixFestFra; public MatrixND matrixFestOth; public MatrixND matrixFmgtFra; public MatrixND matrixFmgtOth; public MatrixND matrixFageXSA; public MatrixND matrixPoth; public MatrixND mortNatAct; public MatrixND matrixweightAA; public MatrixND matrixmaturityAA; public MatrixND matrixPrice; public MatrixND matrixEmgtFra; public MatrixND matrixProdK; public MatrixND matrixProdR; public static MatrixND matrixRepRec; public double scalSelBliF1, scalSelPokF1, scalSelRngF1, scalSelBsfF1, scalSelSkhF1; public double scalSelBliF2, scalSelPokF2, scalSelRngF2, scalSelBsfF2, scalSelSkhF2; public double totalCost0,totalCost_2; public static double totalCost_1; public static double totalEffort_1; public double totalEffort0; public double totalGR_1,totalGR_2; public static double rateGRoth; public double totalProfit_1,totalProfit_2; public double slopeCapacity; public double costIndex; public double Bxsa, Fxsa; public double recruitBli, recruitPok; public double srBliBHa, srBliBHb, srBliBHs2, srPokHS; Fsq optimFsq; Fmsy optimFmsy; Fmgt optimFmgt; public double FmultMsy; public double gamma; public int beta; public int delta; public static int FleetCapacityOld,FleetCapacityNew; public int optimNumber; public int optimType; public int hcrType; public int lastYear; public int lastDate; public Date lastdate; public static List<Zone> zonePopNew = new ArrayList<Zone>(); public static List<Zone> zoneReproNew = new ArrayList<Zone>(); public static List<Zone> zoneRecruitNew = new ArrayList<Zone>(); // Variables to be changed through the simulations plan; public double param_noiseRecBli = 0.0; public double param_noiseRecPok = 0.0; /** * Appelee au demarrage de la simulation, cette methode permet d'initialiser * des valeurs * @param simulation La simulation pour lequel on utilise cette regle **/ public void init(SimulationContext context) throws Exception { recruitBli = 2824000.0; // Calculated based on BH stock-recruitment curve; recruitPok = 151522000.0; // Average recruitment using hockey-stick stock-recruitment curve; srBliBHa = 5216506.0; srBliBHb = 22607123.0; srBliBHs2 = 0.0097; srPokHS = recruitPok; Date date = new Date(0); lastYear = context.getSimulationStorage().getParameter().getNumberOfYear() - 1; lastDate = 12*lastYear; lastdate = new Date(lastDate); List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date); List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date); List<Month> months = Arrays.asList(Month.MONTH); List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date); List<Integer> years= new ArrayList<Integer>(); for (int iyear = 0; iyear <= lastYear; iyear++){ years.add(iyear); } List<Zone> zones = SiMatrix.getSiMatrix(context).getZones(date); List<PopulationGroup> agegroupsall = new ArrayList<PopulationGroup>(); this.db = context.getDB(); for (Population pop : populations) { for (PopulationGroup age : pop.getPopulationGroup()) { PopulationGroup tmp = (PopulationGroup) db.findByTopiaId(age.getTopiaId()); agegroupsall.add(tmp); } } catchYear0 = MatrixFactory.getInstance().create( "catchYear0", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); catchS1Met0 = MatrixFactory.getInstance().create( "catchS1MetYear0", new List[]{populations,metiers}, new String[]{"Populations","Metiers"}); effortS1Met0 = MatrixFactory.getInstance().create( "effortS1MetYear0", new List[]{metiers}, new String[]{"Metiers"}); matrixCpue = MatrixFactory.getInstance().create( "matrixCpue", new List[]{years,populations}, new String[]{"Years","Populations"}); matrixCpueMean = MatrixFactory.getInstance().create( "matrixCpueMean", new List[]{populations}, new String[]{"Populations"}); matrixYmeanFra = MatrixFactory.getInstance().create( "matrixYmeanFra", new List[]{populations}, new String[]{"Populations"}); matrixYmeanOth = MatrixFactory.getInstance().create( "matrixYmeanOth", new List[]{populations}, new String[]{"Populations"}); matrixSlope = MatrixFactory.getInstance().create( "matrixSlope", new List[]{populations}, new String[]{"Populations"}); matrixNcur = MatrixFactory.getInstance().create( "matrixNcur", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixNest = MatrixFactory.getInstance().create( "matrixNest", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixNageXSA = MatrixFactory.getInstance().create( "matrixNageXSA", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixCcurFra = MatrixFactory.getInstance().create( "matrixCcurFra", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixCestFra = MatrixFactory.getInstance().create( "matrixCestFra", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixCestOth = MatrixFactory.getInstance().create( "matrixCestOth", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFcur = MatrixFactory.getInstance().create( "matrixFcur", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFcurFra = MatrixFactory.getInstance().create( "matrixFcurFra", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFcurOth = MatrixFactory.getInstance().create( "matrixFcurOth", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFest = MatrixFactory.getInstance().create( "matrixFest", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFestFra = MatrixFactory.getInstance().create( "matrixFestFra", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFestOth = MatrixFactory.getInstance().create( "matrixFestOth", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFmgtFra = MatrixFactory.getInstance().create( "matrixFmgtFra", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFmgtOth = MatrixFactory.getInstance().create( "matrixFmgtOth", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFageXSA = MatrixFactory.getInstance().create( "matrixFageXSA", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); mortNatAct = MatrixFactory.getInstance().create( "mortNatAct", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixweightAA = MatrixFactory.getInstance().create( "matrixweightAA", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixmaturityAA = MatrixFactory.getInstance().create( "matrixmaturityAA", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixFmsy = MatrixFactory.getInstance().create( "matrixFmsy", new List[]{agegroupsall}, new String[]{"AgeGroupsAll"}); matrixPoth = MatrixFactory.getInstance().create( "matrixPoth", new List[]{populations}, new String[]{"Populations"}); matrixB0 = MatrixFactory.getInstance().create( "matrixB0", new List[]{populations}, new String[]{"Populations"}); matrixBmsy = MatrixFactory.getInstance().create( "matrixBmsy", new List[]{populations}, new String[]{"Populations"}); matrixBest = MatrixFactory.getInstance().create( "matrixBest", new List[]{populations}, new String[]{"Populations"}); matrixBcur = MatrixFactory.getInstance().create( "matrixBcur", new List[]{populations}, new String[]{"Populations"}); matrixBlim = MatrixFactory.getInstance().create( "matrixBlim", new List[]{populations}, new String[]{"Populations"}); matrixProdK = MatrixFactory.getInstance().create( "matrixProdK", new List[]{populations}, new String[]{"Populations"});; matrixProdR = MatrixFactory.getInstance().create( "matrixProdR", new List[]{populations}, new String[]{"Populations"});; matrixYmsy = MatrixFactory.getInstance().create( "matrixYmsy", new List[]{populations}, new String[]{"Populations"}); matrixYcurFra = MatrixFactory.getInstance().create( "matrixYcurFra", new List[]{years,populations}, new String[]{"Years","Populations"}); matrixYcurOth = MatrixFactory.getInstance().create( "matrixYcurOth", new List[]{years,populations}, new String[]{"Years","Populations"}); matrixYestFra = MatrixFactory.getInstance().create( "matrixYestFra", new List[]{populations}, new String[]{"Populations"}); matrixYestOth = MatrixFactory.getInstance().create( "matrixYestOth", new List[]{populations}, new String[]{"Populations"}); matrixYmgtFra = MatrixFactory.getInstance().create( "matrixYmgtFra", new List[]{populations}, new String[]{"Populations"}); matrixYmgtOth = MatrixFactory.getInstance().create( "matrixYmgtOth", new List[]{populations}, new String[]{"Populations"}); matrixPrice = MatrixFactory.getInstance().create( "matrixPrice", new List[]{populations}, new String[]{"Populations"}); matrixEmgtFra = MatrixFactory.getInstance().create( "matrixEmgtFra", new List[]{populations}, new String[]{"Populations"}); hcrType = 2; //0: constant TAC, 1: CPUE-based HCR, 2: assessment-based HCR; beta = 1; //0: free fishing, 1: TAC regulation applies; gamma = 2.0; // parameter determining TAC response for the cpue-based HCR; delta = 2; // parameter determining whether we have a single-species blue ling fishery (0) or a mixed fishery (2); if (beta != 0){ matrixYmgtFra.setValue(0,qfrBLI5bT0+qfrBLI67T0); } else{ matrixYmgtFra.setValue(0,1.0e15); } matrixYmgtFra.setValue(1,qfrPOK34T0); matrixYmgtFra.setValue(2,qfrRNG5b67T0); matrixYmgtFra.setValue(3,qfrBSF5b67T0); matrixYmgtFra.setValue(4,qfrDWST0); matrixYmgtOth.setValue(0,915000.0); // non French blue ling catches estimated from WGDEEP10; matrixYmgtOth.setValue(1,((1-pfrPOK34T0)/pfrPOK34T0)*matrixYmgtFra.getValue(1)); matrixYmgtOth.setValue(2,((1-pfrRNG5b67T0)/pfrRNG5b67T0)*matrixYmgtFra.getValue(2)); matrixYmgtOth.setValue(3,((1-pfrBSF5b67T0)/pfrBSF5b67T0)*matrixYmgtFra.getValue(3)); matrixYmgtOth.setValue(4,((1-pfrDWST0)/pfrDWST0)*matrixYmgtFra.getValue(4)); for (Population pop : populations){ if (pop.getName().compareTo("BlueLingSouth") == 0){ matrixPoth.setValue(pop,0.36); //average over 2007-2009; for (int iage=7; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); matrixFcurOth.setValue(age,0.072); matrixFmgtOth.setValue(age,matrixFcurOth.getValue(age)); } context.setValue("FOthBli",matrixFmgtOth); } else if (pop.getName().compareTo("Pok3a46") == 0){ matrixPoth.setValue(pop,0.84); for (int iage=3; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); if (iage == 3) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.16);} else if (iage == 4) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.24);} else if (iage == 5) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.37);} else if (iage == 6) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.37);} else if (iage == 7) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.46);} else if (iage == 8) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.44);} else if (iage == 9) {matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.34);} else if (iage == 10){matrixFcurOth.setValue(age,matrixPoth.getValue(pop)*0.34);} matrixFmgtOth.setValue(age,matrixFcurOth.getValue(age)); } context.setValue("FOthPok",matrixFmgtOth); context.setValue("selPok",matrixFmgtOth); } } // end of pop loop; context.setValue("YOthRng",1090000.0); context.setValue("YOthBsf",935000.0); context.setValue("YOthSkh",590000.0); context.setValue("recruitBli",recruitBli); context.setValue("recruitPok",recruitPok); context.setValue("bInitRng",153379000.0); context.setValue("bInitBsf",82472000.0); context.setValue("bInitSkh",27914000.0); scalSelBliF1 = 5.029e-7; scalSelPokF1 = 1.007e-7; scalSelRngF1 = 3.838e-7; scalSelBsfF1 = 1.986e-7; scalSelSkhF1 = 1.084e-6; scalSelBliF2 = 4.756e-7; scalSelPokF2 = 1.541e-7; scalSelRngF2 = 3.594e-7; scalSelBsfF2 = 2.214e-7; scalSelSkhF2 = 1.616e-6; context.setValue("scalSelBliF1",scalSelBliF1); context.setValue("scalSelPokF1",scalSelPokF1); context.setValue("scalSelRngF1",scalSelRngF1); context.setValue("scalSelBsfF1",scalSelBsfF1); context.setValue("scalSelSkhF1",scalSelSkhF1); context.setValue("scalSelBliF2",scalSelBliF2); context.setValue("scalSelPokF2",scalSelPokF2); context.setValue("scalSelRngF2",scalSelRngF2); context.setValue("scalSelBsfF2",scalSelBsfF2); context.setValue("scalSelSkhF2",scalSelSkhF2); // initialises economics parameters; rateGRoth = 0.36; // average over 2007-2009; totalCost0 = 69313333; // average over 2006-2008; slopeCapacity = 0.0002/2638; // slope of the deltaE vs profit regression divided by effort per vessel input in ISIS; costIndex = 1.00; optimFsq = null; optimFmsy = null; optimFmgt = null; FmultMsy = 1.0; optimNumber = 0; optimType = 0; context.setValue("delta",delta); OptiFile1 = new File(FichierOpti1); outOpti1 = new BufferedWriter(new FileWriter(OptiFile1, false)); outOpti1.write("date"+";"+"pop"+";"+"age"+";"+"WAA"+";"+"Mact"+";"+ "Fcur"+";"+"FcurFra"+";"+"FcurOth"+";"+"Fmsy"+";"+ "FestFra"+";"+"FestOth"+";"+"FmgtFra"+";"+"FmgtOth"+";"+ "Ncur"+";"+"Nest"+";"+"CcurFra"+";"+"CestFra"+";"+"CestOth"); outOpti1.newLine(); OptiFile2 = new File(FichierOpti2); outOpti2 = new BufferedWriter(new FileWriter(OptiFile2, false)); outOpti2.write("date"+";"+"pop"+";"+"B0"+";"+"Blim"+";"+"Bmsy"+";"+"Bcur"+";"+"Best"+";"+"Bxsa"+";"+ "Fxsa"+";"+"Poth"+";"+"Ymsy"+";"+"YcurFra"+";"+"YestFra"+";"+"YestOth"+";"+"YmgtFra"+";"+"YmgtOth"+";"+ "Slope"+";"+"totalCost_1"+";"+"totalCost_2"+";"+"totalGR_1"+";"+"totalGR_2"+";"+ "totalProfit_1"+";"+"totalProfit_2"+";"+"CapOld"+";"+"CapNew"); outOpti2.newLine(); } /** * La condition qui doit etre vrai pour faire les actions * @param simulation La simulation pour lequel on utilise cette regle * @return vrai si on souhaite que les actions soit faites **/ public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception { return ((date.getYear() > 0) && (date.getMonth().getMonthNumber() == 0)); // do every january where year >= 0; } /** * Si la condition est vrai alors cette action est executee avant le pas * de temps de la simulation. * @param simulation La simulation pour lequel on utilise cette regle */ // Booleen permettant que ne boucler que sur un seul metier dans la preaction : boolean first = true; public void preAction(SimulationContext context, Date date, Metier metier) throws Exception { if (first){ List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date); List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date); List<Month> months = Arrays.asList(Month.MONTH); List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date); List<Zone> zones = SiMatrix.getSiMatrix(context).getZones(date); ResultStorage resultmanager = context.getSimulationStorage().getResultStorage(); Bxsa = XSA.ssbExport*1000; Fxsa = XSA.fbarExport; matrixFageXSA = XSA.matrixFageExport; matrixNageXSA = XSA.matrixNageExport; System.out.println("IN CALCTAC: "+date); System.out.println("Bxsa: "+ Bxsa); System.out.println("Fxsa: "+ Fxsa); System.out.println("matrixNageXSA: "+ matrixNageXSA); System.out.println("matrixFageXSA: "+ matrixFageXSA); int jan1 = 12; Date datejan1 = new Date(jan1); double Fcur,FcurFra,FcurOth; double countPquota = 0.0; double cumcountPquota = 0.0; // Updates number of vessels; for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ if (date.compareTo(datejan1) == 0){ // applicable only in year 1; FleetCapacityOld = str.getSetOfVessels().getNumberOfVessels(); FleetCapacityNew = FleetCapacityOld; } // end of year == 1 if-test; else{ // applicable from year 2 onwards; FleetCapacityOld = FleetCapacityNew; } // end of year > 1 else-test; double sumGrossRev_1 = 0.0; double sumEffortStrat_1 = 0.0; for (Date dat = date.previousYear(); dat.before(date); dat = dat.next()) { MatrixND GrossValuePerStrMet = resultmanager.getMatrix(dat,ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET); MatrixND GrossRev_1 = GrossValuePerStrMet.sumOverDim(1); GrossRev_1 = GrossRev_1.sumOverDim(2); MatrixND Effort_1 = resultmanager.getMatrix(dat,ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); MatrixND ProvEff_1 = Effort_1.sumOverDim(1); sumGrossRev_1 += GrossRev_1.getValue(str,0,0); sumEffortStrat_1 += ProvEff_1.getValue(str,0); } // end of dat loop; totalEffort_1 = sumEffortStrat_1; if (date.getYear() == 1){ totalEffort0 = sumEffortStrat_1; totalCost_1 = totalCost0; totalCost_2 = 0.0; totalGR_1 = sumGrossRev_1/(1.0 - rateGRoth); totalGR_2 = 0.0; } // end of year == 1 if-test; else if (date.getYear() > 1){ totalCost_2 = totalCost_1; totalCost_1 = totalCost0*(sumEffortStrat_1/totalEffort0)*costIndex; totalGR_2 = totalGR_1; totalGR_1 = sumGrossRev_1/(1.0 - rateGRoth); totalProfit_1 = totalGR_1 - totalCost_1; totalProfit_2 = totalGR_2 - totalCost_2; FleetCapacityNew = (int) Math.round(FleetCapacityOld + slopeCapacity*(totalProfit_1+totalProfit_2)/2); if (FleetCapacityNew < 1){ FleetCapacityNew = 1; } } // end of year > 1 else if-test; } // end of str = S1 if-test; } // end of for str loop; for (Population pop : populations){ int ageMin; if (pop.getName().compareTo("BlueLingSouth") == 0){ ageMin = 7; } else if (pop.getName().compareTo("Pok3a46") == 0){ ageMin = 3; } else{ ageMin = 0; } MatrixND AbundancePop = resultmanager.getMatrix(date.previousYear(),pop,ResultName.MATRIX_ABUNDANCE_BEGIN_MONTH); MatrixND Prov1 = AbundancePop.sumOverDim(1); // sum over zones; double recruitNumber = Prov1.getValue(ageMin,0); List<PopulationGroup> agegroups = pop.getPopulationGroup(); if (date.compareTo(datejan1) == 0){ // loop applicable only in year 1; matrixPrice.setValue(pop,pop.getPopulationGroup().get(0).getPrice()); if ((pop.getName().compareTo("BlueLingSouth") == 0) || (pop.getName().compareTo("Pok3a46") == 0)){ // Choosing age-structured stocks; if (pop.getName().compareTo("BlueLingSouth") == 0){ for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); mortNatAct.setValue(age,(Double) context.getValue("MBli")); } } else if (pop.getName().compareTo("Pok3a46") == 0){ for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); mortNatAct.setValue(age,(Double) context.getValue("MPok")); } } for (PopulationGroup age : agegroups){ matrixweightAA.setValue(age,age.getMeanWeight()); matrixmaturityAA.setValue(age,age.getReproductionRate()); } if (pop.getName().compareTo("BlueLingSouth") == 0){ matrixB0.setValue(pop,137743000); // Estimated in spreadsheet SR_Fit.xls; matrixBlim.setValue(pop,0.20*matrixB0.getValue(pop)); //default value; } else if (pop.getName().compareTo("Pok3a46") == 0){ matrixB0.setValue(pop,913465000); // Estimated in spreadsheet SR_Fit.xls; matrixBlim.setValue(pop,106000000); //saithe management plan; } } // End of choosing age-structured stocks; else{ // Choosing NON age-structured stocks; if (pop.getName().compareTo("Rng5b6712b") == 0){ ageMin = 0; matrixPoth.setValue(pop,1-pfrRNG5b67T0); matrixProdK.setValue(pop, (Double) context.getValue("KRng")); matrixProdR.setValue(pop, (Double) context.getValue("rRng")); } else if (pop.getName().compareTo("Bsf5b6712b") == 0){ ageMin = 0; matrixPoth.setValue(pop,1-pfrBSF5b67T0); matrixProdK.setValue(pop, (Double) context.getValue("KBsf")); matrixProdR.setValue(pop, (Double) context.getValue("rBsf")); } else if (pop.getName().compareTo("Skh5b67") == 0){ ageMin = 0; matrixPoth.setValue(pop,1-pfrDWST0); matrixProdK.setValue(pop, (Double) context.getValue("KSkh")); matrixProdR.setValue(pop, (Double) context.getValue("rSkh")); } matrixB0.setValue(pop,matrixProdK.getValue(pop)); matrixBlim.setValue(pop,0.2*matrixB0.getValue(pop)); matrixBmsy.setValue(pop,0.5*matrixB0.getValue(pop)); matrixYmsy.setValue(pop,matrixProdK.getValue(pop)*matrixProdR.getValue(pop)/4); matrixFmsy.setValue(pop.getPopulationGroup().get(0),0.5*matrixProdR.getValue(pop)); } // End of choosing NON age-structured stocks; } // end of loop applicable only in year 1; else{ // loop applicable from year 2 onwards; if ((pop.getName().compareTo("BlueLingSouth") == 0) || (pop.getName().compareTo("Pok3a46") == 0)){ // Choosing age-structured stocks; for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); matrixFcurOth.setValue(age,matrixFmgtOth.getValue(age)); } } // End of choosing age-structured stocks; } // End of loop applicable from year 2 onwards; double countNcur = 0.0; double countCcurFra = 0.0; double countNest = 0.0; double countBest = 0.0; double countBcur = 0.0; double countYcurFra = 0.0; double countCestFra = 0.0; double countCestOth = 0.0; double countYestFra = 0.0; double countYestOth = 0.0; double cumcountBest = 0.0; double cumcountBcur = 0.0; double cumcountYestFra = 0.0; double cumcountYestOth = 0.0; double cumcountYcurFra = 0.0; for (PopulationGroup age : agegroups){ catchYear0.setValue(age,0.0); for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ for (Metier met : metiers){ catchS1Met0.setValue(pop,met,0.0); effortS1Met0.setValue(met,0.0); } } } } for (Date dat = date.previousYear(); dat.before(date); dat = dat.next()) { MatrixND CatchPop = resultmanager.getMatrix(dat,pop,ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP); MatrixND EffortS1Met = resultmanager.getMatrix(dat,ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); MatrixND Prov2 = CatchPop.sumOverDim(0); // sum over strategies; Prov2 = Prov2.sumOverDim(1); // sum over metiers; Prov2 = Prov2.sumOverDim(3); // sum over zones; MatrixND Prov3 = CatchPop.sumOverDim(2); //sum over ages; Prov3 = Prov3.sumOverDim(3); // sum over zones; for (PopulationGroup age : agegroups){ catchYear0.setValue(age,catchYear0.getValue(age)+Prov2.getValue(0,0,age,0)); } for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ for (Metier met : metiers){ catchS1Met0.setValue(pop,met,catchS1Met0.getValue(pop,met)+ Prov3.getValue(str,met,0,0)); effortS1Met0.setValue(met,effortS1Met0.getValue(met)+ EffortS1Met.getValue(str,met)); } } } } double dummyCpue = 0.0; int dummyMet = 0; for (Metier met : metiers){ if (effortS1Met0.getValue(met) > 0.0){ dummyCpue += catchS1Met0.getValue(pop,met)/effortS1Met0.getValue(met); dummyMet++; } } if (dummyMet > 0){ matrixCpue.setValue(date.previousYear().getYear(),pop,dummyCpue/dummyMet); } else{ matrixCpue.setValue(date.previousYear().getYear(),pop,-999.99); } if ((pop.getName().compareTo("BlueLingSouth") == 0) || (pop.getName().compareTo("Pok3a46") == 0)){ // Choosing age-structured stocks; for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); PopulationGroup ageMinus1 = pop.getPopulationGroup().get(iage-1); countNcur = Prov1.getValue(age,0); countCcurFra = catchYear0.getValue(age); optimType = 0; optimFsq = new Fsq(countCcurFra,countNcur,mortNatAct.getValue(age),matrixFcurOth.getValue(age)); FcurFra = Fmin.fmin(0.0,2.0,1.0e-10,optimFsq,optimFmsy,optimFmgt,optimNumber,optimType); matrixFcurFra.setValue(age,FcurFra); matrixFcur.setValue(age,matrixFcurFra.getValue(age) + matrixFcurOth.getValue(age)); matrixCcurFra.setValue(age,countCcurFra); matrixNcur.setValue(age,countNcur); optimNumber++; if (iage == ageMin){ countNest = recruitNumber; } else if (iage > ageMin && iage < (pop.sizePopulationGroup()-1)){ countNest = matrixNcur.getValue(ageMinus1)* Math.exp(-mortNatAct.getValue(ageMinus1)-matrixFcur.getValue(ageMinus1)); } else if (iage == (pop.sizePopulationGroup() - 1)){ countNest = matrixNcur.getValue(ageMinus1)* Math.exp(-mortNatAct.getValue(ageMinus1)-matrixFcur.getValue(ageMinus1))+ matrixNcur.getValue(age)* Math.exp(-mortNatAct.getValue(age)-matrixFcur.getValue(age)); } matrixNest.setValue(age,countNest); countBest = countNest*age.getMeanWeight()*age.getReproductionRate(); countBcur = countNcur*age.getMeanWeight()*age.getReproductionRate(); countYcurFra = countCcurFra*age.getMeanWeight(); cumcountBest += countBest; cumcountBcur += countBcur; cumcountYcurFra += countYcurFra; } // end of age loop; matrixBest.setValue(pop,cumcountBest); matrixBcur.setValue(pop,cumcountBcur); matrixYcurFra.setValue(date.getYear()-1,pop,cumcountYcurFra); matrixYcurOth.setValue(date.getYear()-1,pop,matrixYmgtOth.getValue(pop)); if (date.compareTo(datejan1) == 0){ // loop applicable only in year 1; optimType = 1; optimFmsy = new Fmsy(pop, ageMin, pop.sizePopulationGroup()-1, recruitNumber, matrixB0.getValue(pop), mortNatAct, matrixFcur, matrixweightAA, matrixmaturityAA); FmultMsy = Fmin.fmin(0.0,2.0,1.0e-10,optimFsq,optimFmsy,optimFmgt,optimNumber,optimType); for (PopulationGroup age : agegroups){ matrixFmsy.setValue(age,matrixFcur.getValue(age)*FmultMsy); } matrixBmsy.setValue(pop,optimFmsy.Bmsy); matrixYmsy.setValue(pop,optimFmsy.Ymsy); optimNumber++; } // end of date=jan0 if-test; // DEFININING ZONES; if (pop.getName().compareTo("BlueLingSouth") == 0){ // Applicable to blue ling only; Zone zrep = null; Zone znrep = null; matrixRepRec = pop.getMappingZoneReproZoneRecru(); if (matrixBcur.getValue(pop) < 0.25*matrixBlim.getValue(pop)){ zrep = zones.get(24); znrep = zones.get(23); } else if (matrixBcur.getValue(pop) < 0.50*matrixBlim.getValue(pop)){ zrep = zones.get(21); znrep = zones.get(22); } else if (matrixBcur.getValue(pop) < 0.75*matrixBlim.getValue(pop)){ zrep = zones.get(19); znrep = zones.get(20); } else if (matrixBcur.getValue(pop) < 1.00*matrixBlim.getValue(pop)){ zrep = zones.get(17); znrep = zones.get(18); } else{ zrep = zones.get(14); znrep = zones.get(16); } zoneReproNew.clear(); zoneReproNew.add(zrep); zonePopNew.clear(); zonePopNew.add(zrep); zonePopNew.add(znrep); zoneRecruitNew.clear(); zoneRecruitNew.add(zrep); zoneRecruitNew.add(znrep); int sizeReproNew = zrep.sizeCell(); int sizeNonReproNew = znrep.sizeCell(); int sizePopNew = sizeReproNew + sizeNonReproNew; matrixRepRec.setValue(0,0,(double) sizeReproNew/sizePopNew); matrixRepRec.setValue(0,1,(double) sizeNonReproNew/sizePopNew); } } // end of choosing age-structured stocks; else { // Choosing non age-structured stocks; countNcur = Prov1.getValue(pop.getPopulationGroup().get(0),0); countCcurFra = catchYear0.getValue(pop.getPopulationGroup().get(0)); FcurFra = countCcurFra/countNcur; FcurOth = matrixYmgtOth.getValue(pop)/countNcur; Fcur = FcurFra + FcurOth; matrixFcur.setValue(pop.getPopulationGroup().get(0),Fcur); matrixFcurFra.setValue(pop.getPopulationGroup().get(0),FcurFra); matrixFcurOth.setValue(pop.getPopulationGroup().get(0),FcurOth); matrixNcur.setValue(pop.getPopulationGroup().get(0),countNcur); matrixCcurFra.setValue(pop.getPopulationGroup().get(0),countCcurFra); countNest = matrixNcur.getValue(pop.getPopulationGroup().get(0))+ matrixProdR.getValue(pop)*matrixNcur.getValue(pop.getPopulationGroup().get(0))* (1-matrixNcur.getValue(pop.getPopulationGroup().get(0))/matrixProdK.getValue(pop)) - matrixYmgtOth.getValue(pop) - countCcurFra; matrixNest.setValue(pop.getPopulationGroup().get(0),countNest); matrixBest.setValue(pop,countNest); matrixBcur.setValue(pop,countNcur); matrixYcurFra.setValue(date.getYear()-1,pop,countCcurFra); matrixYcurOth.setValue(date.getYear()-1,pop,matrixYmgtOth.getValue(pop)); } // end of choosing non age-structured stocks; // CALCULATES TAC and Fmgt for the French and the other fleets; if ((date.getYear() >= 5) && (beta != 0)){ if (hcrType == 1){ double dummyCpueMean = 0.0; double dummyYcurFra = 0.0; double dummyYcurOth = 0.0; int dummyYear = 0; double dummyYearMean = 0; double yearMean = 0.0; for (int iyear=date.getYear()-5; iyear <= date.getYear()-1; iyear++){ if (matrixCpue.getValue(iyear,pop) >= 0.0){ dummyCpueMean += matrixCpue.getValue(iyear,pop); dummyYear++; dummyYearMean += iyear; } dummyYcurFra += matrixYcurFra.getValue(iyear,pop); dummyYcurOth += matrixYcurOth.getValue(iyear,pop); } matrixCpueMean.setValue(pop,dummyCpueMean/dummyYear); matrixYmeanFra.setValue(pop,dummyYcurFra/5); matrixYmeanOth.setValue(pop,dummyYcurOth/5); yearMean = dummyYearMean/dummyYear; double dummySlope1 = 0.0; double dummySlope2 = 0.0; for (int iyear=date.getYear()-5; iyear <= date.getYear()-1; iyear++){ if (matrixCpue.getValue(iyear,pop) >= 0.0){ dummySlope1 += (iyear - yearMean)*(matrixCpue.getValue(iyear,pop) - matrixCpueMean.getValue(pop)); dummySlope2 += (iyear - yearMean)*(iyear - yearMean); } } matrixSlope.setValue(pop,dummySlope1/dummySlope2); double testTacInfFra = 0.85*matrixYmgtFra.getValue(pop); double testTacSupFra = 1.15*matrixYmgtFra.getValue(pop); double testTacFra = (1+gamma*matrixSlope.getValue(pop))*matrixYmeanFra.getValue(pop); if (testTacFra <= testTacInfFra){ matrixYmgtFra.setValue(pop,testTacInfFra); } else if (testTacFra >= testTacSupFra){ matrixYmgtFra.setValue(pop,testTacSupFra); } else{ matrixYmgtFra.setValue(pop,testTacFra); } double testTacInfOth = 0.85*matrixYmgtOth.getValue(pop); double testTacSupOth = 1.15*matrixYmgtOth.getValue(pop); double testTacOth = (1+gamma*matrixSlope.getValue(pop))*matrixYmeanOth.getValue(pop); if (testTacOth <= testTacInfOth){ matrixYmgtOth.setValue(pop,testTacInfOth); } else if (testTacOth >= testTacSupOth){ matrixYmgtOth.setValue(pop,testTacSupOth); } else{ matrixYmgtOth.setValue(pop,testTacOth); } for (PopulationGroup age : agegroups){ matrixFmgtOth.setValue(age,matrixFmgtOth.getValue(age)* matrixYmgtOth.getValue(pop)/matrixYcurOth.getValue(date.getYear()-1,pop)); } } // end of hcrType == 1 if test; else if (hcrType == 2){ double meanFcur = 0.0; if ((pop.getName().compareTo("Pok3a46") == 0)){ // Calculating mean F for saithe; meanFcur = (matrixFcur.getValue(pop.getPopulationGroup().get(3)) + matrixFcur.getValue(pop.getPopulationGroup().get(4)) + matrixFcur.getValue(pop.getPopulationGroup().get(5)) + matrixFcur.getValue(pop.getPopulationGroup().get(6)))/4; } // end of calculating mean F for saithe; for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); if (matrixBest.getValue(pop) < matrixBlim.getValue(pop)) { if ((pop.getName().compareTo("Pok3a46") == 0)){ // Implementing saithe management plan; matrixFest.setValue(age,(matrixFcur.getValue(age)/meanFcur)*0.1); } // end of implementing saithe management plan; else{ // Implementing same HCR for all DW species; matrixFest.setValue(age,0.0); } // end of implementing DW species HCR; } else if ((matrixBest.getValue(pop) >= matrixBlim.getValue(pop)) && (matrixBest.getValue(pop) < matrixBmsy.getValue(pop))) { if ((pop.getName().compareTo("Pok3a46") == 0)){ // Implementing saithe management plan; matrixFest.setValue(age,(matrixFcur.getValue(age)/meanFcur)* (0.30 - 0.20*((matrixBmsy.getValue(pop)-matrixBest.getValue(pop))/ (matrixBmsy.getValue(pop)-matrixBlim.getValue(pop))))); } // end of implementing saithe management plan; else{ // Implementing same HCR for all DW species; matrixFest.setValue(age,matrixFmsy.getValue(age)* ((matrixBest.getValue(pop)-matrixBlim.getValue(pop))/ (matrixBmsy.getValue(pop)-matrixBlim.getValue(pop)))); } // end of implementing DW species HCR; } else if (matrixBest.getValue(pop) >= matrixBmsy.getValue(pop)) { if ((pop.getName().compareTo("Pok3a46") == 0)){ // Implementing saithe management plan; matrixFest.setValue(age,(matrixFcur.getValue(age)/meanFcur)*0.30); } // end of implementing saithe management plan; else{ // Implementing same HCR for all DW species; matrixFest.setValue(age,matrixFmsy.getValue(age)); } // end of implementing DW species HCR; } matrixFestOth.setValue(age,matrixPoth.getValue(pop)*matrixFest.getValue(age)); matrixFestFra.setValue(age,(1-matrixPoth.getValue(pop))*matrixFest.getValue(age)); if ((pop.getName().compareTo("BlueLingSouth") == 0) || (pop.getName().compareTo("Pok3a46") == 0)){ // Choosing age-structured stocks; countCestFra = (matrixFestFra.getValue(age)/(matrixFest.getValue(age)+mortNatAct.getValue(age)))* (1-Math.exp(-matrixFest.getValue(age)-mortNatAct.getValue(age)))*matrixNest.getValue(age); countCestOth = (matrixFestOth.getValue(age)/(matrixFest.getValue(age)+mortNatAct.getValue(age)))* (1-Math.exp(-matrixFest.getValue(age)-mortNatAct.getValue(age)))*matrixNest.getValue(age); } else{ // Choosing NON age-structured stocks; countCestFra = matrixFestFra.getValue(age)*matrixNest.getValue(age); countCestOth = matrixFestOth.getValue(age)*matrixNest.getValue(age); } countYestFra = countCestFra*age.getMeanWeight(); countYestOth = countCestOth*age.getMeanWeight(); matrixCestFra.setValue(age,countCestFra); matrixCestOth.setValue(age,countCestOth); cumcountYestFra += countYestFra; cumcountYestOth += countYestOth; } // end of age loop; matrixYestFra.setValue(pop,cumcountYestFra); matrixYestOth.setValue(pop,cumcountYestOth); // CALCULATING FRENCH QUOTA; if ((matrixBest.getValue(pop) < matrixBlim.getValue(pop)) ||(matrixYmgtFra.getValue(pop) == 0.0)){ // General procedure for setting French quota next year; matrixYmgtFra.setValue(pop,matrixYestFra.getValue(pop)); } else{ // Particular boundaries applicable to French quota next year; if (matrixYestFra.getValue(pop) <= 0.85*matrixYmgtFra.getValue(pop)){// The French quota cannot be lower than 85% of the previous year's; matrixYmgtFra.setValue(pop,0.85*matrixYmgtFra.getValue(pop)); } else if (matrixYestFra.getValue(pop) >= 1.15*matrixYmgtFra.getValue(pop)){// The French quota cannot exceed 115% of the previous year's; matrixYmgtFra.setValue(pop,1.15*matrixYmgtFra.getValue(pop)); } else { // General procedure for setting French quota next year; matrixYmgtFra.setValue(pop,matrixYestFra.getValue(pop)); } // end of French quota (general & particular) procedure; } // end of setting French quota; // CALCULATING OTHER FLEETS' QUOTA; if ((matrixBest.getValue(pop) < matrixBlim.getValue(pop)) ||(matrixYmgtOth.getValue(pop) == 0.0)){ // General procedure for setting other fleets' quota next year; matrixYmgtOth.setValue(pop,matrixYestOth.getValue(pop)); } else{ // Particular boundaries applicable to other fleets' quota next year; if (matrixYestOth.getValue(pop) <= 0.85*matrixYmgtOth.getValue(pop)){// The other fleets' quota cannot be lower than 85% of the previous year's; matrixYmgtOth.setValue(pop,0.85*matrixYmgtOth.getValue(pop)); } else if (matrixYestOth.getValue(pop) >= 1.15*matrixYmgtOth.getValue(pop)){// The other fleets' quota cannot exceed 115% of the previous year's; matrixYmgtOth.setValue(pop,1.15*matrixYmgtOth.getValue(pop)); } else { // General procedure for setting other fleets' quota next year; matrixYmgtOth.setValue(pop,matrixYestOth.getValue(pop)); } // end ofother fleets' quota (general & particular) procedure; } // end of setting other fleets' quota; for (PopulationGroup age : agegroups){ matrixFmgtOth.setValue(age,matrixFestOth.getValue(age)* matrixYmgtOth.getValue(pop)/matrixYestOth.getValue(pop)); } } // end of hcrType == 2 else if test; } // end of date.getYear if test; double Fmult = 1.0; if ((pop.getName().compareTo("BlueLingSouth") == 0) || (pop.getName().compareTo("Pok3a46") == 0)){ // Choosing age-structured stocks; optimType = 2; optimFmgt = new Fmgt(pop, ageMin, pop.sizePopulationGroup()-1, recruitNumber, matrixYmgtFra.getValue(pop), mortNatAct, matrixFcurFra, matrixFmgtOth, matrixweightAA); Fmult = Fmin.fmin(0.0,2.0,1.0e-10,optimFsq,optimFmsy,optimFmgt,optimNumber,optimType); for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); matrixFmgtFra.setValue(age,matrixFcurFra.getValue(age)*Fmult); } optimNumber++; } // end of choosing age-structured stocks; else { // Choosing non age-structured stocks; Fmult = matrixYmgtFra.getValue(pop)/matrixYcurFra.getValue(date.getYear()-1,pop); for (int iage=ageMin; iage <= pop.sizePopulationGroup()-1; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); matrixFmgtFra.setValue(age,matrixFcurFra.getValue(age)*Fmult); } } // end of choosing non age-structured stocks; countPquota = matrixYmgtFra.getValue(pop)*matrixPrice.getValue(pop); cumcountPquota += countPquota; matrixEmgtFra.setValue(pop,countPquota*Fmult); // EXPORTS OTHER FLEETS' F or Y and also recruitment, Bcur and Blim for blue ling and saithe; if ((pop.getName().compareTo("BlueLingSouth") == 0)){ recruitBli = srBliBHa*Math.exp(srBliBHs2/2)*matrixBcur.getValue(pop)/ (matrixBcur.getValue(pop) + srBliBHb); // Beverton and Holt SR curve; context.setValue("FOthBli",matrixFmgtOth); context.setValue("BlimBli",matrixBlim.getValue(pop)); context.setValue("BcurBli",matrixBcur.getValue(pop)); context.setValue("recruitBli",recruitBli); } else if ((pop.getName().compareTo("Pok3a46") == 0)){ if (matrixBcur.getValue(pop) < matrixBlim.getValue(pop)){ recruitPok = srPokHS*(matrixBcur.getValue(pop)/matrixBlim.getValue(pop)); } context.setValue("FOthPok",matrixFmgtOth); context.setValue("recruitPok",recruitPok); } else if (pop.getName().compareTo("Rng5b6712b") == 0){ context.setValue("YOthRng",matrixYmgtOth.getValue(pop)); } else if (pop.getName().compareTo("Bsf5b6712b") == 0){ context.setValue("YOthBsf",matrixYmgtOth.getValue(pop)); } else if (pop.getName().compareTo("Skh5b67") == 0){ context.setValue("YOthSkh",matrixYmgtOth.getValue(pop)); } } // end of pop loop; // WRITES OUTPUTS IN CSV FILE; for (Population pop:populations){ List<PopulationGroup> agegroups = pop.getPopulationGroup(); for (PopulationGroup age : agegroups){ outOpti1.write(date+";"+pop+";"+age+";"+age.getMeanWeight()+";"+ mortNatAct.getValue(age)+";"+matrixFcur.getValue(age)+";"+ matrixFcurFra.getValue(age)+";"+matrixFcurOth.getValue(age)+";"+ matrixFmsy.getValue(age)+";"+ matrixFestFra.getValue(age)+";"+matrixFestOth.getValue(age)+";"+ matrixFmgtFra.getValue(age)+";"+matrixFmgtOth.getValue(age)+";"+ matrixNcur.getValue(age)+";"+matrixNest.getValue(age)+";"+ matrixCcurFra.getValue(age)+";"+ matrixCestFra.getValue(age)+";"+matrixCestOth.getValue(age)); outOpti1.newLine(); } // end of age loop; outOpti2.write(date+";"+pop+";"+matrixB0.getValue(pop)+";"+matrixBlim.getValue(pop)+";"+ matrixBmsy.getValue(pop)+";"+matrixBcur.getValue(pop)+";"+matrixBest.getValue(pop)+";"+Bxsa+";"+ Fxsa+";"+matrixPoth.getValue(pop)+";"+matrixYmsy.getValue(pop)+";"+matrixYcurFra.getValue(date.getYear()-1,pop)+";"+ matrixYestFra.getValue(pop)+";"+matrixYestOth.getValue(pop)+";"+ matrixYmgtFra.getValue(pop)+";"+matrixYmgtOth.getValue(pop)+";"+ matrixSlope.getValue(pop)+";"+totalCost_1+";"+totalCost_2+";"+totalGR_1+";"+totalGR_2+";"+ totalProfit_1+";"+totalProfit_2+";"+FleetCapacityOld+";"+FleetCapacityNew); outOpti2.newLine(); } // end of pop loop; first = false; } // end of (first) if-test; } /** * Si la condition est vrai alors cette action est executee apres le pas * de temps de la simulation. * @param simulation La simulation pour lequel on utilise cette regle */ public void postAction(SimulationContext context, Date date, Metier metier) throws Exception { first = true; if (date.compareTo(lastdate) == 0){ outOpti1.close(); outOpti2.close(); } } } package rules; import static org.nuiton.i18n.I18n._; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import scripts.GravityModel; import scripts.ResultName; import scripts.SiMatrix; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.io.File; import java.io.Writer; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.FileReader; import org.nuiton.math.matrix.*; import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.Date; import fr.ifremer.isisfish.types.Month; import fr.ifremer.isisfish.entities.*; import fr.ifremer.isisfish.rule.AbstractRule; import fr.ifremer.isisfish.datastore.ResultStorage; import org.nuiton.util.FileUtil; /** * FleetManagementDeep.java * * Created: 21 july 2010 * * Last update: 2010-09-08 * by : Paul Marchal */ public class FleetManagementDeep extends AbstractRule { static private Log log = LogFactory.getLog(FleetManagementDeep.class); // to use log facility, just put in your code: log.info("..."); // Output files facility; public String FichierBiomassBli = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/BiomassBLI.csv"; public String FichierBiomassPok = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/BiomassPOK.csv"; public String FichierBiomassRng = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/BiomassRNG.csv"; public String FichierBiomassBsf = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/BiomassBSF.csv"; public String FichierBiomassSkh = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/BiomassSKH.csv"; public String FichierCatchStrMetierBli = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/CatchStrMetierBLI.csv"; public String FichierCatchStrMetierPok = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/CatchStrMetierPOK.csv"; public String FichierCatchStrMetierRng = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/CatchStrMetierRNG.csv"; public String FichierCatchStrMetierBsf = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/CatchStrMetierBSF.csv"; public String FichierCatchStrMetierSkh = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/CatchStrMetierSKH.csv"; public String FichierEffortStrMetier = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/EffortStrMetier.csv"; public String FichierValueStrMetier = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/ValueStrMetier.csv"; public String FichierEcoMan = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/EcoMan.csv"; public String FichierDeep1 = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/FichierDeep1.csv"; public String FichierDeep2 = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/FichierDeep2.csv"; public String FichierDeb = "C:/Paul/2005-2011/DPCP/P6/DEEPFISHMAN/Science/WP5/ISIS_Output/FichierDeb.csv"; protected File BiomassBliFile; protected File BiomassPokFile; protected File BiomassRngFile; protected File BiomassBsfFile; protected File BiomassSkhFile; protected File CatchStrMetierBliFile; protected File CatchStrMetierPokFile; protected File CatchStrMetierRngFile; protected File CatchStrMetierBsfFile; protected File CatchStrMetierSkhFile; protected File EffortStrMetierFile; protected File ValueStrMetierFile; protected File EcoManFile; protected File DeepFile1; protected File DeepFile2; protected File DeepDeb; public BufferedWriter outBiomassBli; public BufferedWriter outBiomassPok; public BufferedWriter outBiomassRng; public BufferedWriter outBiomassBsf; public BufferedWriter outBiomassSkh; public BufferedWriter outCatchStrMetierBli; public BufferedWriter outCatchStrMetierPok; public BufferedWriter outCatchStrMetierRng; public BufferedWriter outCatchStrMetierBsf; public BufferedWriter outCatchStrMetierSkh; public BufferedWriter outEffortStrMetier; public BufferedWriter outValueStrMetier; public BufferedWriter outEcoMan; public BufferedWriter outDeep1; public BufferedWriter outDeep2; public BufferedWriter outDeb; //public lastYear and lastDate; public int lastYear; public int lastDate; public Date lastdate; public MatrixND matrixTac; public MatrixND TacMoinsCatch; public MatrixND matrixEffortAlloc; public double alpha; // fishers behaviour parameter; public double qfrBLI4; public double qfrBLI5b; public double qfrBLI67; public double qfrPOK34; public double qfrPOK5b6; public double qfrPOK78; public double qfrRNG4; public double qfrRNG5b67; public double qfrBSF4; public double qfrBSF5b67; public double qfrDWS; public double fixedCosts0; public double costRate; public double effortStrat0; private MatrixND SommePropInitial = null; //stocke la somme des prop initiales [str x month]; private MatrixND valuePerUnitOfEffort = null; //permet de stocker les CPUE nominales [str x met] private File CoeffOthers0; 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_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP, //ResultName.MATRIX_EFFORT_PER_STRATEGY_MET, ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET, // garder la , }; public String[] getNecessaryResult() { return this.necessaryResult; } public String getDescription() throws Exception { //Permet d'afficher a l'utilisateur une aide sur la regle. //@return L'aide ou la description de la regle return _("calcule les proportions par metier chaque mois en fonction de la VPUE du metier l'annee precedente"); //HYPOTHESES GRAVITE: //attention cette regle doit toujours etre mise avant les mesures de gestion //si pour un metier Effort (metier annee-1,mois) = 0 et propinitiale (metier, mois) !=0 //(ie metier potentiellement pratique), alors on remet propInitiale pour tous les metiers //(premiere vue complete pour tous les metiers de la strategie - graviteVPUE1-, une alternative //pourrait etre de chercher la premiere annee avant annee -1 pour laquelle le metier, //ayant une propInitiale non nulle , aurait une VPUE (metier,mois) non nulle //et recuperer la propStr (metier,mois) pour cette annee et on l'affecte annee courante - mois, //les autres metiers se partageant la proportion d'effort restante en fonction de leur VPUE - //graviteVPUE2-, une alternative pourrait etre de chercher la premiere annee avant annee -1 //pour laquelle tous les metiers, ayant une propInitiale non nulle, auraient eu une propStr non nulle, //(surement difficile a trouver) - graviteVPUE3- d'autres hypotheses pourraient etre envisagees) } private MapFunction nanFunction = new MapFunction() { //function used to initialise MatrixND to NaN double; public double apply(double value) { return Double.NaN; } }; public void init(SimulationContext context) throws Exception { //Appele au demarrage de la simulation, cette methode permet d'initialiser des valeurs //@param simulation La simulation pour lequel on utilise cette regle Date date = new Date(0); lastYear = context.getSimulationStorage().getParameter().getNumberOfYear() - 1; lastDate = 12*(lastYear + 1) - 1; lastdate = new Date(lastDate); List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date); List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date); List<Month> months = Arrays.asList(Month.MONTH); List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date); List<Zone> zones = SiMatrix.getSiMatrix(context).getZones(date); System.out.println("My name is Paul"); costRate = 0.5; // assumed cost rate for large trawlers; alpha = 0.5; //fishers behavior: alpha varies between 0 (fully static) to 1 (fully dynamic); matrixTac = MatrixFactory.getInstance().create( "matrixTac", new List[]{populations,metiers}, new String[]{"Populations","Metiers"}); TacMoinsCatch = MatrixFactory.getInstance().create( "TacMoinsCatch", new List[]{populations,metiers}, new String[]{"Populations","Metiers"}); matrixEffortAlloc = MatrixFactory.getInstance().create( "matrixEffortAlloc", new List[]{strs,metiers,months}, new String[]{"Strategies","Metiers","Months"}); SommePropInitial = MatrixFactory.getInstance().create("SommePropInitial", new List[]{strs, months}, new String[]{"Strategies", "Months"}); SommePropInitial.map(nanFunction); valuePerUnitOfEffort = MatrixFactory.getInstance().create("ValuePerUnitOfEffort", new List[]{strs, metiers}, new String[]{"Strategies", "Metiers"}); valuePerUnitOfEffort.map(nanFunction); Date endDat = new Date(11); for (Date idat = new Date(0); idat.beforeOrEquals(endDat); idat = idat.next()){ for (Strategy str : strs) { Collection<EffortDescription> strMet = str.getSetOfVessels().getPossibleMetiers(); StrategyMonthInfo smi0 = str.getStrategyMonthInfo(idat.getMonth()); for (EffortDescription ed : strMet){ Metier strMetier = ed.getPossibleMetiers() ; matrixEffortAlloc.setValue(str,strMetier,idat.getMonth(), smi0.getProportionMetier(strMetier)); } } } for (Strategy str : strs) { List<Metier> strMetiers = SiMatrix.getSiMatrix(context).getMetiers(str, date); List<StrategyMonthInfo> infos = str.getStrategyMonthInfo(); for (StrategyMonthInfo info : infos) { double somme = 0; for (Metier strMetier : strMetiers) { somme += info.getProportionMetier(strMetier); } // FIXME soit on somme pour toutes les str le meme metier; // donc pas de notion de str.getName dans la cle // soit pour une str on somme tous ces metiers (mais ce doit etre 1; // donc pas de notion de metier.getName dans la cle SommePropInitial.setValue(str, info.getMonth(), somme); } } BiomassBliFile = new File(FichierBiomassBli); BiomassPokFile = new File(FichierBiomassPok); BiomassRngFile = new File(FichierBiomassRng); BiomassBsfFile = new File(FichierBiomassBsf); BiomassSkhFile = new File(FichierBiomassSkh); CatchStrMetierBliFile = new File(FichierCatchStrMetierBli); CatchStrMetierPokFile = new File(FichierCatchStrMetierPok); CatchStrMetierRngFile = new File(FichierCatchStrMetierRng); CatchStrMetierBsfFile = new File(FichierCatchStrMetierBsf); CatchStrMetierSkhFile = new File(FichierCatchStrMetierSkh); EffortStrMetierFile = new File(FichierEffortStrMetier); ValueStrMetierFile = new File(FichierValueStrMetier); EcoManFile = new File(FichierEcoMan); DeepFile1 = new File(FichierDeep1); DeepFile2 = new File(FichierDeep2); DeepDeb = new File(FichierDeb); outBiomassBli = new BufferedWriter(new FileWriter(BiomassBliFile, false)); outBiomassPok = new BufferedWriter(new FileWriter(BiomassPokFile, false)); outBiomassRng = new BufferedWriter(new FileWriter(BiomassRngFile, false)); outBiomassBsf = new BufferedWriter(new FileWriter(BiomassBsfFile, false)); outBiomassSkh = new BufferedWriter(new FileWriter(BiomassSkhFile, false)); outCatchStrMetierBli = new BufferedWriter(new FileWriter(CatchStrMetierBliFile, false)); outCatchStrMetierPok = new BufferedWriter(new FileWriter(CatchStrMetierPokFile, false)); outCatchStrMetierRng = new BufferedWriter(new FileWriter(CatchStrMetierRngFile, false)); outCatchStrMetierBsf = new BufferedWriter(new FileWriter(CatchStrMetierBsfFile, false)); outCatchStrMetierSkh = new BufferedWriter(new FileWriter(CatchStrMetierSkhFile, false)); outEffortStrMetier = new BufferedWriter(new FileWriter(EffortStrMetierFile, false)); outValueStrMetier = new BufferedWriter(new FileWriter(ValueStrMetierFile, false)); outEcoMan = new BufferedWriter(new FileWriter(EcoManFile, false)); outDeep1 = new BufferedWriter(new FileWriter(DeepFile1, false)); outDeep2 = new BufferedWriter(new FileWriter(DeepFile2, false)); outDeb = new BufferedWriter(new FileWriter(DeepDeb, false)); } //end of init; // La condition qui doit etre vrai pour faire les actions // @param simulation La simulation pour lequel on utilise cette regle // @return vrai si on souhaite que les actions soit faites public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception { // Il faut etre au moins au deuxieme pas de temps. return date.getYear() > 0; } // Si la condition est vrai alors cette action est executee avant le pas de temps de la simulation. // @param simulation La simulation pour lequel on utilise cette regle // Booleen permettant que ne boucler que sur un seul metier dans la preaction : boolean first = true; public void preAction(SimulationContext context, Date date, Metier metier) throws Exception { System.out.println("IN FLEETMANDEEP: "+date); if (log.isDebugEnabled()) { log.debug("first = "+ first + "date:"+ date); } System.out.println("date = " + date); System.out.println("first = " + first+ " ,on passe dans la preaction ?"); if (first){ // on passe dans preaction pour la premiere fois; System.out.println("Oui, preaction : "); List<Strategy> strs = SiMatrix.getSiMatrix(context).getStrategies(date); List<Population> populations = SiMatrix.getSiMatrix(context).getPopulations(date); List<Metier> metiers = SiMatrix.getSiMatrix(context).getMetiers(date); ResultStorage resultmanager = context.getSimulationStorage().getResultStorage(); int ny = date.getYear() ; Month nm = date.getMonth(); Date dateY00 = new Date(nm.getMonthNumber()); int janny = 12*ny; int janny_1 = 12*(ny-1); int jan1 = 12; Date date0 = new Date(janny); Date date0_1 = new Date(janny_1); Date datejan1 = new Date(jan1); /** for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ SetOfVessels newSet; newSet = str.getSetOfVessels(); newSet.setNumberOfVessels(CalcTAC.FleetCapacityNew); str.setSetOfVessels(newSet); } } **/ // Calcul des efforts nominaux par strategy met, aux lags -1 et -12; MatrixND EffortNominalPerStrMetL12 = null; EffortNominalPerStrMetL12 = resultmanager.getMatrix( date.previousYear(),ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); MatrixND EffortNominalPerStrMetL01 = null; EffortNominalPerStrMetL01 = resultmanager.getMatrix( date.previous(),ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); MatrixND EffortNominalPerStrMetY00 = null; EffortNominalPerStrMetY00 = resultmanager.getMatrix( dateY00,ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); // Matrice de valeurs, aux lags -1 et -12; MatrixND GrossValuePerStrMetL12 = null; GrossValuePerStrMetL12 = resultmanager.getMatrix( date.previousYear(),ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET); MatrixND GrossValuePerStrMetL01 = null; GrossValuePerStrMetL01 = resultmanager.getMatrix( date.previous(),ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET); ResultStorage matResult = context.getSimulationStorage().getResultStorage(); MatrixND CatchPopMetL01 = MatrixFactory.getInstance().create( "CatchPopMetL01", new List[]{populations,metiers}, new String[]{"Populations","Metiers"}); MatrixND CatchPopStrMetL01 = MatrixFactory.getInstance().create( "CatchPopStrMetL01", new List[]{populations,strs,metiers}, new String[]{"Populations","Strategy","Metiers"}); MatrixND CatchPopMetL12 = MatrixFactory.getInstance().create( "CatchPopMetL12", new List[]{populations,metiers}, new String[]{"Populations","Metiers"}); MatrixND CatchPopStrMetL12 = MatrixFactory.getInstance().create( "CatchPopStrMetL12", new List[]{populations,strs,metiers}, new String[]{"Populations","Strategy","Metiers"}); if (datejan1.compareTo(date) == 0){ //write headers in output file in jan 1 and calculates operating costs; for (Strategy str : strs){ if (str.getName().compareTo("S1") == 0){ double dummyGrossRev_1 = 0.0; double dummyEffortStrat_1 = 0.0; for (Date dat = date.previousYear(); dat.before(date); dat = dat.next()) { MatrixND GrossValuePerStrMet = resultmanager.getMatrix(dat,ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET); MatrixND GrossRev_1 = GrossValuePerStrMet.sumOverDim(1); GrossRev_1 = GrossRev_1.sumOverDim(2); MatrixND Effort_1 = resultmanager.getMatrix(dat,ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); MatrixND ProvEff_1 = Effort_1.sumOverDim(1); dummyGrossRev_1 += GrossRev_1.getValue(str,0,0); dummyEffortStrat_1 += ProvEff_1.getValue(str,0); } // end of dat loop; fixedCosts0 = costRate*dummyGrossRev_1; effortStrat0 = dummyEffortStrat_1; } // end of str = S1; } // end of str loop; outDeep1.write("date"+";"+"stock"+";"+"fleet"+";"+"metier"+";"+"matrixTac"+";"+ "CatchPopStrMetL01"+";"+"CatchPopMetL01"+";"+"TacMoinsCatch"); outDeep1.newLine(); } //end of date = 0 if loop; Date dat = date.previous(); for (Population pop : populations){ if (pop.getName().compareTo("BlueLingSouth") == 0){ // Applicable to blue ling only; pop.setPopulationZone(CalcTAC.zonePopNew); pop.setRecruitmentZone(CalcTAC.zoneRecruitNew); pop.setReproductionZone(CalcTAC.zoneReproNew); pop.setMappingZoneReproZoneRecru(CalcTAC.matrixRepRec); } // end of blue ling specifics; PopulationGroup group0 = pop.getPopulationGroup().get(0); MatrixND CatchPopL01 = null; CatchPopL01 = resultmanager.getMatrix(dat,pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); if (date0.compareTo(date) == 0){ // in january; qfrBLI4 = CalcTAC.qfrBLI4T0; qfrBLI5b = (CalcTAC.qfrBLI5bT0/(CalcTAC.qfrBLI5bT0+CalcTAC.qfrBLI67T0))* CalcTAC.matrixYmgtFra.getValue(0); qfrBLI67 = (CalcTAC.qfrBLI67T0/(CalcTAC.qfrBLI5bT0+CalcTAC.qfrBLI67T0))* CalcTAC.matrixYmgtFra.getValue(0); qfrPOK34 = (CalcTAC.qfrPOK34T0/(CalcTAC.qfrPOK34T0+CalcTAC.qfrPOK5bEU6T0))* CalcTAC.matrixYmgtFra.getValue(1); qfrPOK5b6 = (CalcTAC.qfrPOK5bEU6T0/(CalcTAC.qfrPOK34T0+CalcTAC.qfrPOK5bEU6T0))* CalcTAC.matrixYmgtFra.getValue(1) + CalcTAC.qfrPOK5bFAT0; qfrPOK78 = CalcTAC.qfrPOK78T0; qfrRNG4 = CalcTAC.qfrRNG4T0; qfrRNG5b67 = CalcTAC.matrixYmgtFra.getValue(2); qfrBSF4 = CalcTAC.qfrBSF4T0; qfrBSF5b67 = CalcTAC.matrixYmgtFra.getValue(3); qfrDWS = CalcTAC.matrixYmgtFra.getValue(4); matrixTac.setValue(0,0,qfrBLI4); //BLI and Dem4T; matrixTac.setValue(0,1,qfrBLI5b); //BLI and Dem5T; matrixTac.setValue(0,2,qfrBLI67); //BLI and Dem6T; matrixTac.setValue(0,3,qfrBLI67); //BLI and Dem78T; matrixTac.setValue(0,4,qfrBLI67); //BLI and DeepEdge6T; matrixTac.setValue(0,5,qfrBLI5b); //BLI and DeepNew5T; matrixTac.setValue(0,6,qfrBLI67); //BLI and DeepNew6T; matrixTac.setValue(0,7,qfrBLI67); //BLI and DeepOther6T; matrixTac.setValue(0,8,qfrBLI5b); //BLI and DeepRef5T; matrixTac.setValue(0,9,qfrBLI67); //BLI and DeepRef7T; matrixTac.setValue(0,10,qfrBLI4); //BLI and Dem4; matrixTac.setValue(0,11,qfrBLI5b); //BLI and Dem5; matrixTac.setValue(0,12,qfrBLI67); //BLI and Dem6; matrixTac.setValue(0,13,qfrBLI67); //BLI and Dem78; matrixTac.setValue(0,14,qfrBLI67); //BLI and DeepEdge6; matrixTac.setValue(0,15,qfrBLI5b); //BLI and DeepNew5; matrixTac.setValue(0,16,qfrBLI67); //BLI and DeepNew6; matrixTac.setValue(0,17,qfrBLI67); //BLI and DeepOther6; matrixTac.setValue(0,18,qfrBLI5b); //BLI and DeepRef5; matrixTac.setValue(0,19,qfrBLI67); //BLI and DeepRef7; matrixTac.setValue(1,0,qfrPOK34); //POK and Dem4T; matrixTac.setValue(1,1,qfrPOK5b6); //POK and Dem5T; matrixTac.setValue(1,2,qfrPOK5b6); //POK and Dem6T; matrixTac.setValue(1,3,qfrPOK78); //POK and Dem78T; matrixTac.setValue(1,4,qfrPOK5b6); //POK and DeepEdge6T; matrixTac.setValue(1,5,qfrPOK5b6); //POK and DeepNew5T; matrixTac.setValue(1,6,qfrPOK5b6); //POK and DeepNew6T; matrixTac.setValue(1,7,qfrPOK5b6); //POK and DeepOther6T; matrixTac.setValue(1,8,qfrPOK5b6); //POK and DeepRef5T; matrixTac.setValue(1,9,qfrPOK78); //POK and DeepRef7T; matrixTac.setValue(1,10,qfrPOK34); //POK and Dem4; matrixTac.setValue(1,11,qfrPOK5b6); //POK and Dem5; matrixTac.setValue(1,12,qfrPOK5b6); //POK and Dem6; matrixTac.setValue(1,13,qfrPOK78); //POK and Dem78; matrixTac.setValue(1,14,qfrPOK5b6); //POK and DeepEdge6; matrixTac.setValue(1,15,qfrPOK5b6); //POK and DeepNew5; matrixTac.setValue(1,16,qfrPOK5b6); //POK and DeepNew6; matrixTac.setValue(1,17,qfrPOK5b6); //POK and DeepOther6; matrixTac.setValue(1,18,qfrPOK5b6); //POK and DeepRef5; matrixTac.setValue(1,19,qfrPOK78); //POK and DeepRef7; matrixTac.setValue(2,0,qfrRNG4); //RNG and Dem4T; matrixTac.setValue(2,1,qfrRNG5b67); //RNG and Dem5T; matrixTac.setValue(2,2,qfrRNG5b67); //RNG and Dem6T; matrixTac.setValue(2,3,qfrRNG5b67); //RNG and Dem78T; matrixTac.setValue(2,4,qfrRNG5b67); //RNG and DeepEdge6T; matrixTac.setValue(2,5,qfrRNG5b67); //RNG and DeepNew5T; matrixTac.setValue(2,6,qfrRNG5b67); //RNG and DeepNew6T; matrixTac.setValue(2,7,qfrRNG5b67); //RNG and DeepOther6T; matrixTac.setValue(2,8,qfrRNG5b67); //RNG and DeepRef5T; matrixTac.setValue(2,9,qfrRNG5b67); //RNG and DeepRef7T; matrixTac.setValue(2,10,qfrRNG4); //RNG and Dem4; matrixTac.setValue(2,11,qfrRNG5b67); //RNG and Dem5; matrixTac.setValue(2,12,qfrRNG5b67); //RNG and Dem6; matrixTac.setValue(2,13,qfrRNG5b67); //RNG and Dem78; matrixTac.setValue(2,14,qfrRNG5b67); //RNG and DeepEdge6; matrixTac.setValue(2,15,qfrRNG5b67); //RNG and DeepNew5; matrixTac.setValue(2,16,qfrRNG5b67); //RNG and DeepNew6; matrixTac.setValue(2,17,qfrRNG5b67); //RNG and DeepOther6; matrixTac.setValue(2,18,qfrRNG5b67); //RNG and DeepRef5; matrixTac.setValue(2,19,qfrRNG5b67); //RNG and DeepRef7; matrixTac.setValue(3,0,qfrBSF4); //BSF and Dem4T; matrixTac.setValue(3,1,qfrBSF5b67); //BSF and Dem5T; matrixTac.setValue(3,2,qfrBSF5b67); //BSF and Dem6T; matrixTac.setValue(3,3,qfrBSF5b67); //BSF and Dem78T; matrixTac.setValue(3,4,qfrBSF5b67); //BSF and DeepEdge6T; matrixTac.setValue(3,5,qfrBSF5b67); //BSF and DeepNew5T; matrixTac.setValue(3,6,qfrBSF5b67); //BSF and DeepNew6T; matrixTac.setValue(3,7,qfrBSF5b67); //BSF and DeepOther6T; matrixTac.setValue(3,8,qfrBSF5b67); //BSF and DeepRef5T; matrixTac.setValue(3,9,qfrBSF5b67); //BSF and DeepRef7T; matrixTac.setValue(3,10,qfrBSF4); //BSF and Dem4; matrixTac.setValue(3,11,qfrBSF5b67); //BSF and Dem5; matrixTac.setValue(3,12,qfrBSF5b67); //BSF and Dem6; matrixTac.setValue(3,13,qfrBSF5b67); //BSF and Dem78; matrixTac.setValue(3,14,qfrBSF5b67); //BSF and DeepEdge6; matrixTac.setValue(3,15,qfrBSF5b67); //BSF and DeepNew5; matrixTac.setValue(3,16,qfrBSF5b67); //BSF and DeepNew6; matrixTac.setValue(3,17,qfrBSF5b67); //BSF and DeepOther6; matrixTac.setValue(3,18,qfrBSF5b67); //BSF and DeepRef5; matrixTac.setValue(3,19,qfrBSF5b67); //BSF and DeepRef7; matrixTac.setValue(4,0,qfrDWS); //DWS and Dem4T; matrixTac.setValue(4,1,qfrDWS); //DWS and Dem5T; matrixTac.setValue(4,2,qfrDWS); //DWS and Dem6T; matrixTac.setValue(4,3,qfrDWS); //DWS and Dem78T; matrixTac.setValue(4,4,qfrDWS); //DWS and DeepEdge6T; matrixTac.setValue(4,5,qfrDWS); //DWS and DeepNew5T; matrixTac.setValue(4,6,qfrDWS); //DWS and DeepNew6T; matrixTac.setValue(4,7,qfrDWS); //DWS and DeepOther6T; matrixTac.setValue(4,8,qfrDWS); //DWS and DeepRef5T; matrixTac.setValue(4,9,qfrDWS); //DWS and DeepRef7T; matrixTac.setValue(4,10,qfrDWS); //DWS and Dem4; matrixTac.setValue(4,11,qfrDWS); //DWS and Dem5; matrixTac.setValue(4,12,qfrDWS); //DWS and Dem6; matrixTac.setValue(4,13,qfrDWS); //DWS and Dem78; matrixTac.setValue(4,14,qfrDWS); //DWS and DeepEdge6; matrixTac.setValue(4,15,qfrDWS); //DWS and DeepNew5; matrixTac.setValue(4,16,qfrDWS); //DWS and DeepNew6; matrixTac.setValue(4,17,qfrDWS); //DWS and DeepOther6; matrixTac.setValue(4,18,qfrDWS); //DWS and DeepRef5; matrixTac.setValue(4,19,qfrDWS); //DWS and DeepRef7; for (Metier met : metiers){ TacMoinsCatch.setValue(pop,met,matrixTac.getValue(pop,met)); } //end of metier loop; } //end of month = january if loop; else{ //from february to december: quota update after withdrawal of cumulated catches;; for (Metier met : metiers){ MatrixND Prov1 = CatchPopL01.sumOverDim(0); //sum over strategies; Prov1 = Prov1.sumOverDim(2); //sum over age groups; Prov1 = Prov1.sumOverDim(3); //sum over zones; CatchPopMetL01.setValue(pop,met,Prov1.getValue(0,met,0,0)); for (Strategy str : strs){ MatrixND Prov2 = CatchPopL01.sumOverDim(2); //sum over age groups; Prov2 = Prov2.sumOverDim(3); //sum over zones; CatchPopStrMetL01.setValue(pop,str,met,Prov2.getValue(str,met,0,0)); } //end of fleet/strategy loop; } //end of metier for loop; double catch4 = CatchPopMetL01.getValue(pop,0) + //Dem4T; CatchPopMetL01.getValue(pop,10); //Dem4; double catch5 = CatchPopMetL01.getValue(pop,5) + //DeepNew5T; CatchPopMetL01.getValue(pop,8) + //DeepRef5T; CatchPopMetL01.getValue(pop,1) + //Dem5T; CatchPopMetL01.getValue(pop,15)+ //DeepNew5; CatchPopMetL01.getValue(pop,18)+ //DeepRef5; CatchPopMetL01.getValue(pop,11); //Dem5; double catch6 = CatchPopMetL01.getValue(pop,4) + //DeepEdge6T; CatchPopMetL01.getValue(pop,6) + //DeepNew6T; CatchPopMetL01.getValue(pop,7) + //DeepOther6T; CatchPopMetL01.getValue(pop,2) + //Dem6T; CatchPopMetL01.getValue(pop,14)+ //DeepEdge6; CatchPopMetL01.getValue(pop,16)+ //DeepNew6; CatchPopMetL01.getValue(pop,17)+ //DeepOther6; CatchPopMetL01.getValue(pop,12); //Dem6; double catch7 = CatchPopMetL01.getValue(pop,9) + //DeepRef7T; CatchPopMetL01.getValue(pop,3) + //Dem78T; CatchPopMetL01.getValue(pop,19)+ //DeepRef7; CatchPopMetL01.getValue(pop,13); //Dem78; if (pop.getName().compareTo("BlueLingSouth") == 0){ TacMoinsCatch.setValue(pop,0,TacMoinsCatch.getValue(pop,0)-catch4); //Dem4T; TacMoinsCatch.setValue(pop,1,TacMoinsCatch.getValue(pop,1)-catch5); //Dem5T; TacMoinsCatch.setValue(pop,2,TacMoinsCatch.getValue(pop,2)-catch6-catch7);//Dem6T; TacMoinsCatch.setValue(pop,3,TacMoinsCatch.getValue(pop,3)-catch6-catch7);//Dem78T; TacMoinsCatch.setValue(pop,4,TacMoinsCatch.getValue(pop,4)-catch6-catch7);//DeepEdge6T; TacMoinsCatch.setValue(pop,5,TacMoinsCatch.getValue(pop,5)-catch5); //DeepNew5T; TacMoinsCatch.setValue(pop,6,TacMoinsCatch.getValue(pop,6)-catch6-catch7);//DeepNew6T; TacMoinsCatch.setValue(pop,7,TacMoinsCatch.getValue(pop,7)-catch6-catch7);//DeepOther6T; TacMoinsCatch.setValue(pop,8,TacMoinsCatch.getValue(pop,8)-catch5); //DeepRef5T; TacMoinsCatch.setValue(pop,9,TacMoinsCatch.getValue(pop,9)-catch6-catch7);//DeepRef7T; TacMoinsCatch.setValue(pop,10,TacMoinsCatch.getValue(pop,10)-catch4); //Dem4; TacMoinsCatch.setValue(pop,11,TacMoinsCatch.getValue(pop,11)-catch5); //Dem5; TacMoinsCatch.setValue(pop,12,TacMoinsCatch.getValue(pop,12)-catch6-catch7);//Dem6; TacMoinsCatch.setValue(pop,13,TacMoinsCatch.getValue(pop,13)-catch6-catch7);//Dem78; TacMoinsCatch.setValue(pop,14,TacMoinsCatch.getValue(pop,14)-catch6-catch7);//DeepEdge6; TacMoinsCatch.setValue(pop,15,TacMoinsCatch.getValue(pop,15)-catch5); //DeepNew5; TacMoinsCatch.setValue(pop,16,TacMoinsCatch.getValue(pop,16)-catch6-catch7);//DeepNew6; TacMoinsCatch.setValue(pop,17,TacMoinsCatch.getValue(pop,17)-catch6-catch7);//DeepOther6; TacMoinsCatch.setValue(pop,18,TacMoinsCatch.getValue(pop,18)-catch5); //DeepRef5; TacMoinsCatch.setValue(pop,19,TacMoinsCatch.getValue(pop,19)-catch6-catch7);//DeepRef7; } else if (pop.getName().compareTo("Pok3a46") == 0){ TacMoinsCatch.setValue(pop,0,TacMoinsCatch.getValue(pop,0)-catch4); //Dem4T; TacMoinsCatch.setValue(pop,1,TacMoinsCatch.getValue(pop,1)-catch5-catch6); //Dem5T; TacMoinsCatch.setValue(pop,2,TacMoinsCatch.getValue(pop,2)-catch5-catch6);//Dem6T; TacMoinsCatch.setValue(pop,3,TacMoinsCatch.getValue(pop,3)-catch7);//Dem78T; TacMoinsCatch.setValue(pop,4,TacMoinsCatch.getValue(pop,4)-catch5-catch6);//DeepEdge6T; TacMoinsCatch.setValue(pop,5,TacMoinsCatch.getValue(pop,5)-catch5-catch6); //DeepNew5T; TacMoinsCatch.setValue(pop,6,TacMoinsCatch.getValue(pop,6)-catch5-catch6);//DeepNew6T; TacMoinsCatch.setValue(pop,7,TacMoinsCatch.getValue(pop,7)-catch5-catch6);//DeepOther6T; TacMoinsCatch.setValue(pop,8,TacMoinsCatch.getValue(pop,8)-catch5-catch6); //DeepRef5T; TacMoinsCatch.setValue(pop,9,TacMoinsCatch.getValue(pop,9)-catch7);//DeepRef7T; TacMoinsCatch.setValue(pop,10,TacMoinsCatch.getValue(pop,10)-catch4); //Dem4; TacMoinsCatch.setValue(pop,11,TacMoinsCatch.getValue(pop,11)-catch5-catch6); //Dem5; TacMoinsCatch.setValue(pop,12,TacMoinsCatch.getValue(pop,12)-catch5-catch6);//Dem6; TacMoinsCatch.setValue(pop,13,TacMoinsCatch.getValue(pop,13)-catch7);//Dem78; TacMoinsCatch.setValue(pop,14,TacMoinsCatch.getValue(pop,14)-catch5-catch6);//DeepEdge6; TacMoinsCatch.setValue(pop,15,TacMoinsCatch.getValue(pop,15)-catch5-catch6); //DeepNew5; TacMoinsCatch.setValue(pop,16,TacMoinsCatch.getValue(pop,16)-catch5-catch6);//DeepNew6; TacMoinsCatch.setValue(pop,17,TacMoinsCatch.getValue(pop,17)-catch5-catch6);//DeepOther6; TacMoinsCatch.setValue(pop,18,TacMoinsCatch.getValue(pop,18)-catch5-catch6); //DeepRef5; TacMoinsCatch.setValue(pop,19,TacMoinsCatch.getValue(pop,19)-catch7);//DeepRef7; } else if (pop.getName().compareTo("Rng5b6712b") == 0){ TacMoinsCatch.setValue(pop,0,TacMoinsCatch.getValue(pop,0)-catch4); //Dem4T; TacMoinsCatch.setValue(pop,1,TacMoinsCatch.getValue(pop,1)-catch5-catch6-catch7); //Dem5T; TacMoinsCatch.setValue(pop,2,TacMoinsCatch.getValue(pop,2)-catch5-catch6-catch7);//Dem6T; TacMoinsCatch.setValue(pop,3,TacMoinsCatch.getValue(pop,3)-catch5-catch6-catch7);//Dem78T; TacMoinsCatch.setValue(pop,4,TacMoinsCatch.getValue(pop,4)-catch5-catch6-catch7);//DeepEdge6T; TacMoinsCatch.setValue(pop,5,TacMoinsCatch.getValue(pop,5)-catch5-catch6-catch7); //DeepNew5T; TacMoinsCatch.setValue(pop,6,TacMoinsCatch.getValue(pop,6)-catch5-catch6-catch7);//DeepNew6T; TacMoinsCatch.setValue(pop,7,TacMoinsCatch.getValue(pop,7)-catch5-catch6-catch7);//DeepOther6T; TacMoinsCatch.setValue(pop,8,TacMoinsCatch.getValue(pop,8)-catch5-catch6-catch7); //DeepRef5T; TacMoinsCatch.setValue(pop,9,TacMoinsCatch.getValue(pop,9)-catch5-catch6-catch7);//DeepRef7T; TacMoinsCatch.setValue(pop,10,TacMoinsCatch.getValue(pop,10)-catch4); //Dem4; TacMoinsCatch.setValue(pop,11,TacMoinsCatch.getValue(pop,11)-catch5-catch6-catch7); //Dem5; TacMoinsCatch.setValue(pop,12,TacMoinsCatch.getValue(pop,12)-catch5-catch6-catch7);//Dem6; TacMoinsCatch.setValue(pop,13,TacMoinsCatch.getValue(pop,13)-catch5-catch6-catch7);//Dem78; TacMoinsCatch.setValue(pop,14,TacMoinsCatch.getValue(pop,14)-catch5-catch6-catch7);//DeepEdge6; TacMoinsCatch.setValue(pop,15,TacMoinsCatch.getValue(pop,15)-catch5-catch6-catch7); //DeepNew5; TacMoinsCatch.setValue(pop,16,TacMoinsCatch.getValue(pop,16)-catch5-catch6-catch7);//DeepNew6; TacMoinsCatch.setValue(pop,17,TacMoinsCatch.getValue(pop,17)-catch5-catch6-catch7);//DeepOther6; TacMoinsCatch.setValue(pop,18,TacMoinsCatch.getValue(pop,18)-catch5-catch6-catch7); //DeepRef5; TacMoinsCatch.setValue(pop,19,TacMoinsCatch.getValue(pop,19)-catch5-catch6-catch7);//DeepRef7; } else if (pop.getName().compareTo("Bsf5b6712b") == 0){ TacMoinsCatch.setValue(pop,0,TacMoinsCatch.getValue(pop,0)-catch4); //Dem4T; TacMoinsCatch.setValue(pop,1,TacMoinsCatch.getValue(pop,1)-catch5-catch6-catch7); //Dem5T; TacMoinsCatch.setValue(pop,2,TacMoinsCatch.getValue(pop,2)-catch5-catch6-catch7);//Dem6T; TacMoinsCatch.setValue(pop,3,TacMoinsCatch.getValue(pop,3)-catch5-catch6-catch7);//Dem78T; TacMoinsCatch.setValue(pop,4,TacMoinsCatch.getValue(pop,4)-catch5-catch6-catch7);//DeepEdge6T; TacMoinsCatch.setValue(pop,5,TacMoinsCatch.getValue(pop,5)-catch5-catch6-catch7); //DeepNew5T; TacMoinsCatch.setValue(pop,6,TacMoinsCatch.getValue(pop,6)-catch5-catch6-catch7);//DeepNew6T; TacMoinsCatch.setValue(pop,7,TacMoinsCatch.getValue(pop,7)-catch5-catch6-catch7);//DeepOther6T; TacMoinsCatch.setValue(pop,8,TacMoinsCatch.getValue(pop,8)-catch5-catch6-catch7); //DeepRef5T; TacMoinsCatch.setValue(pop,9,TacMoinsCatch.getValue(pop,9)-catch5-catch6-catch7);//DeepRef7T; TacMoinsCatch.setValue(pop,10,TacMoinsCatch.getValue(pop,10)-catch4); //Dem4; TacMoinsCatch.setValue(pop,11,TacMoinsCatch.getValue(pop,11)-catch5-catch6-catch7); //Dem5; TacMoinsCatch.setValue(pop,12,TacMoinsCatch.getValue(pop,12)-catch5-catch6-catch7);//Dem6; TacMoinsCatch.setValue(pop,13,TacMoinsCatch.getValue(pop,13)-catch5-catch6-catch7);//Dem78; TacMoinsCatch.setValue(pop,14,TacMoinsCatch.getValue(pop,14)-catch5-catch6-catch7);//DeepEdge6; TacMoinsCatch.setValue(pop,15,TacMoinsCatch.getValue(pop,15)-catch5-catch6-catch7); //DeepNew5; TacMoinsCatch.setValue(pop,16,TacMoinsCatch.getValue(pop,16)-catch5-catch6-catch7);//DeepNew6; TacMoinsCatch.setValue(pop,17,TacMoinsCatch.getValue(pop,17)-catch5-catch6-catch7);//DeepOther6; TacMoinsCatch.setValue(pop,18,TacMoinsCatch.getValue(pop,18)-catch5-catch6-catch7); //DeepRef5; TacMoinsCatch.setValue(pop,19,TacMoinsCatch.getValue(pop,19)-catch5-catch6-catch7);//DeepRef7; } else if (pop.getName().compareTo("Skh5b67") == 0){ TacMoinsCatch.setValue(pop,0,TacMoinsCatch.getValue(pop,0)-catch4-catch5-catch6-catch7); //Dem4T; TacMoinsCatch.setValue(pop,1,TacMoinsCatch.getValue(pop,1)-catch4-catch5-catch6-catch7); //Dem5T; TacMoinsCatch.setValue(pop,2,TacMoinsCatch.getValue(pop,2)-catch4-catch5-catch6-catch7);//Dem6T; TacMoinsCatch.setValue(pop,3,TacMoinsCatch.getValue(pop,3)-catch4-catch5-catch6-catch7);//Dem78T; TacMoinsCatch.setValue(pop,4,TacMoinsCatch.getValue(pop,4)-catch4-catch5-catch6-catch7);//DeepEdge6T; TacMoinsCatch.setValue(pop,5,TacMoinsCatch.getValue(pop,5)-catch4-catch5-catch6-catch7); //DeepNew5T; TacMoinsCatch.setValue(pop,6,TacMoinsCatch.getValue(pop,6)-catch4-catch5-catch6-catch7);//DeepNew6T; TacMoinsCatch.setValue(pop,7,TacMoinsCatch.getValue(pop,7)-catch4-catch5-catch6-catch7);//DeepOther6T; TacMoinsCatch.setValue(pop,8,TacMoinsCatch.getValue(pop,8)-catch4-catch5-catch6-catch7); //DeepRef5T; TacMoinsCatch.setValue(pop,9,TacMoinsCatch.getValue(pop,9)-catch4-catch5-catch6-catch7);//DeepRef7T; TacMoinsCatch.setValue(pop,10,TacMoinsCatch.getValue(pop,10)-catch4-catch5-catch6-catch7); //Dem4; TacMoinsCatch.setValue(pop,11,TacMoinsCatch.getValue(pop,11)-catch4-catch5-catch6-catch7); //Dem5; TacMoinsCatch.setValue(pop,12,TacMoinsCatch.getValue(pop,12)-catch4-catch5-catch6-catch7);//Dem6; TacMoinsCatch.setValue(pop,13,TacMoinsCatch.getValue(pop,13)-catch4-catch5-catch6-catch7);//Dem78; TacMoinsCatch.setValue(pop,14,TacMoinsCatch.getValue(pop,14)-catch4-catch5-catch6-catch7);//DeepEdge6; TacMoinsCatch.setValue(pop,15,TacMoinsCatch.getValue(pop,15)-catch4-catch5-catch6-catch7); //DeepNew5; TacMoinsCatch.setValue(pop,16,TacMoinsCatch.getValue(pop,16)-catch4-catch5-catch6-catch7);//DeepNew6; TacMoinsCatch.setValue(pop,17,TacMoinsCatch.getValue(pop,17)-catch4-catch5-catch6-catch7);//DeepOther6; TacMoinsCatch.setValue(pop,18,TacMoinsCatch.getValue(pop,18)-catch4-catch5-catch6-catch7); //DeepRef5; TacMoinsCatch.setValue(pop,19,TacMoinsCatch.getValue(pop,19)-catch4-catch5-catch6-catch7);//DeepRef7; } } //end of month = feb-dec else loop; } //end of pop for loop; // Exports; for (Strategy str : strs){ for (Metier met : metiers){ for (Population pop : populations){ outDeep1.write(date+";"+pop+";"+str+";"+met+";"+matrixTac.getValue(pop,met)+";"+ CatchPopStrMetL01.getValue(pop,str,met)+";"+ CatchPopMetL01.getValue(pop,met)+";"+TacMoinsCatch.getValue(pop,met)); outDeep1.newLine(); } // end of population loop; } // end of metier loop; } // end of str loop; if (date.compareTo(lastdate) == 0){ outDeep1.close(); } valuePerUnitOfEffort.map(nanFunction); //reinitialisation avant calcul pour date; if (datejan1.compareTo(date) == 0){ //write outDeep2 in Gravity output file; outDeep2.write("date"+";"+"stock"+";"+"fleet"+";"+"metier"+";"+ "GrossValuePerStrMetL12"+";"+"Prov1"+";"+"TacMoinsCatch"+";"+ "tax"+";"+"value"+";"+"effortL12"+";"+"sommeOverPop"+";"+ "valuePerUnitOfEffort"+";"+"somme"+";"+"SommeVPUEstrat"+";"+"newProp"+";"+"newProp2"); outDeep2.newLine(); outDeb.write("date"+";"+"str"+";"+"strMetier"+";"+ "valuePerUnitOfEffort"+";"+"SommeVPUEstrat"+";"+"newProp"+";"+"newProp2"+";"+"smi"); outDeb.newLine(); outEcoMan.write("date"+";"+"stock"+";"+"fleet"+";"+"metier"+";"+ "matrixTac"+";"+"TacMoinsCatch"+";"+"tax"); outEcoMan.newLine(); } for (Strategy str : strs){ //Calcul VPUE estimee par strategies; StrategyMonthInfo smi = str.getStrategyMonthInfo(date.getMonth()); StrategyMonthInfo smiL12 = str.getStrategyMonthInfo(date.previousYear().getMonth()); StrategyMonthInfo smiY00 = str.getStrategyMonthInfo(dateY00.getMonth()); Collection<EffortDescription> strMet = str.getSetOfVessels().getPossibleMetiers() ; boolean testCondition = false; double somme=0;//initialisation de la somme des VPUE des metiers de la strategie; double SommeVPUEstrat = 0; double newProp=0.0; double newProp2=0.0; double sommeEffortL12=0.0; for (EffortDescription ed : strMet){ Metier strMetier = ed.getPossibleMetiers() ; double effortL12 = EffortNominalPerStrMetL12.getValue(str, strMetier); double effortL01 = EffortNominalPerStrMetL01.getValue(str, strMetier); double tax=0.0; double sommeOverPop=0.0; for (Population pop : populations){ PopulationGroup group0 = pop.getPopulationGroup().get(0); MatrixND CatchPopL12 = null; CatchPopL12 = resultmanager.getMatrix(date.previousYear(),pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); MatrixND Prov1 = CatchPopL12.sumOverDim(2); // sum over age groups; Prov1 = Prov1.sumOverDim(3); // sum over zones; CatchPopStrMetL12.setValue(pop,str,strMetier,Prov1.getValue(str,strMetier,0,0)); if (TacMoinsCatch.getValue(pop,strMetier) >= 0) { // no tax when there is some quota left; tax = 0.0; } else { // a tax applies when there is no quota left; tax = group0.getPrice(); // tax assumed to equate fish price when quota is exceeded; } double valueL12 = GrossValuePerStrMetL12.getValue(str, strMetier, pop)/(1.0 - CalcTAC.rateGRoth) - CatchPopStrMetL12.getValue(pop,str,strMetier)*tax; if (effortL12 > 0){// a peche au mois, annee-1; sommeOverPop += valueL12; } outDeep2.write(date+";"+pop+";"+str+";"+strMetier+";"+ GrossValuePerStrMetL12.getValue(str,strMetier,pop)+";"+Prov1.getValue(str,strMetier,0,0)+";"+ TacMoinsCatch.getValue(pop,strMetier)+";"+tax+";"+valueL12+";"+effortL12+";"+sommeOverPop+";"+ valuePerUnitOfEffort.getValue(str, strMetier)+";"+somme+";"+SommeVPUEstrat+";"+newProp+";"+newProp2); outDeep2.newLine(); outEcoMan.write(date+";"+pop+";"+str+";"+strMetier+";"+ matrixTac.getValue(pop,strMetier)+";"+TacMoinsCatch.getValue(pop,strMetier)+";"+tax); outEcoMan.newLine(); } //end of pop loop; sommeOverPop = sommeOverPop - effortL12*(CalcTAC.totalCost_1/CalcTAC.totalEffort_1); if (effortL12 == 0){ // n'a pas peche au mois, annee-1; valuePerUnitOfEffort.setValue(str, strMetier, 0.0); } else{ // a peche au mois, annee-1; valuePerUnitOfEffort.setValue(str, strMetier, Math.exp((sommeOverPop/effortL12)*1.0e-3)); } somme += valuePerUnitOfEffort.getValue(str, strMetier); sommeEffortL12 += effortL12; outDeep2.write(date+";"+"ALL"+";"+str+";"+strMetier+";"+ 99e9+";"+99e9+";"+99e9+";"+99e9+";"+ 99e9+";"+effortL12+";"+sommeOverPop+";"+ valuePerUnitOfEffort.getValue(str,strMetier)+";"+somme+";"+99e9+";"+99e9+";"+99e9); outDeep2.newLine(); } // for end of strMet loop SommeVPUEstrat = somme; for (EffortDescription ed : strMet){ Metier strMetier = ed.getPossibleMetiers(); if (str.getName().compareTo("S1") == 0){ // Selecting large French trawlers if-test; newProp= valuePerUnitOfEffort.getValue(str, strMetier)/SommeVPUEstrat; newProp2 = matrixEffortAlloc.getValue(str,strMetier,date.getMonth()); smi.setProportionMetier(strMetier,alpha*newProp+(1-alpha)*newProp2); matrixEffortAlloc.setValue(str,strMetier,date.getMonth(), alpha*newProp+(1-alpha)*newProp2); } // End of selecting large French trawlers if-test; outDeb.write(date+";"+str+";"+strMetier+";"+ valuePerUnitOfEffort.getValue(str,strMetier)+";"+SommeVPUEstrat+";"+ newProp+";"+newProp2+";"+smi.getProportionMetier(strMetier)); outDeb.newLine(); } // End of loop over metiers; outDeep2.write(date+";"+"ALL"+";"+str+";"+"ALL"+";"+ 99e9+";"+99e9+";"+99e9+";"+ 99e9+";"+99e9+";"+99e9+";"+99e9+";"+ 99e9+";"+somme+";"+SommeVPUEstrat+";"+newProp+";"+newProp2); outDeep2.newLine(); } // end of str loop; first = false; } // end of first= true; if (date.compareTo(lastdate) == 0){ outDeb.close(); outDeep2.close(); outEcoMan.close(); } if (log.isDebugEnabled()) { log.debug("fin Gravite CPUEAction avant"); } } // end of public void preaction; // Si la condition est vrai alors cette action est executee apres le pas de temps de la simulation. // @param simulation La simulation pour lequel on utilise cette regle // boolean first2 = true; public void postAction(SimulationContext context, Date date, Metier metier) throws Exception { first = true; if (first2){ if (date.compareTo(lastdate) == 0){ for (Population pop : context.getSimulationStorage().getParameter().getPopulations()) { MatrixND matBiomass = context.getSimulationStorage().getResultStorage(). getMatrix(pop, ResultName.MATRIX_BIOMASS_BEGIN_MONTH); matBiomass = matBiomass.sumOverDim(2); //sum over zones; for (MatrixIterator i=matBiomass.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); Date dateX = (Date)sems[0]; PopulationGroup group = (PopulationGroup)sems[1]; Zone zone = (Zone)sems[2]; double val = i.getValue(); if ((pop.getName().compareTo("BlueLingSouth") == 0) && group.getId() >= 7){ outBiomassBli.write(pop.getName() +";"+ group.getId() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Pok3a46") == 0) && group.getId() >= 3){ outBiomassPok.write(pop.getName() +";"+ group.getId() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Rng5b6712b") == 0)){ outBiomassRng.write(pop.getName() +";"+ group.getId() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Bsf5b6712b") == 0)){ outBiomassBsf.write(pop.getName() +";"+ group.getId() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Skh5b67") == 0)){ outBiomassSkh.write(pop.getName() +";"+ group.getId() +";"+ dateX.getDate() +";"+ val +"\n"); } // end of if pop test; } // end of MatrixIterator loop; MatrixND matCatchStrMetier = context.getSimulationStorage().getResultStorage(). getMatrix(pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); matCatchStrMetier = matCatchStrMetier.sumOverDim(3); //sum over ages; matCatchStrMetier = matCatchStrMetier.sumOverDim(4); //sum over zones; for (MatrixIterator i=matCatchStrMetier.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); Date dateX = (Date)sems[0]; Strategy str = (Strategy)sems[1]; Metier met = (Metier)sems[2]; PopulationGroup group = (PopulationGroup)sems[3]; Zone zone = (Zone)sems[4]; double val = i.getValue(); if ((pop.getName().compareTo("BlueLingSouth") == 0)){ outCatchStrMetierBli.write(pop.getName() +";"+ str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Pok3a46") == 0)){ outCatchStrMetierPok.write(pop.getName() +";"+ str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Rng5b6712b") == 0)){ outCatchStrMetierRng.write(pop.getName() +";"+ str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Bsf5b6712b") == 0)){ outCatchStrMetierBsf.write(pop.getName() +";"+ str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } else if ((pop.getName().compareTo("Skh5b67") == 0)){ outCatchStrMetierSkh.write(pop.getName() +";"+ str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } // end of if pop test; } // end of MatrixIterator loop; } // end of pop loop; MatrixND matEffortStrMetier = context.getSimulationStorage().getResultStorage(). getMatrix(ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET); for (MatrixIterator i=matEffortStrMetier.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); Date dateX = (Date)sems[0]; Strategy str = (Strategy)sems[1]; Metier met = (Metier)sems[2]; double val = i.getValue(); outEffortStrMetier.write(str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } // end of MatrixIterator loop; MatrixND matValueStrMetier = context.getSimulationStorage().getResultStorage(). getMatrix(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET); for (MatrixIterator i=matValueStrMetier.iterator(); i.hasNext();) { i.next(); Object [] sems = i.getSemanticsCoordinates(); Date dateX = (Date)sems[0]; Strategy str = (Strategy)sems[1]; Metier met = (Metier)sems[2]; double val = i.getValue(); outValueStrMetier.write(str.getName() +";"+ met.getName() +";"+ dateX.getDate() +";"+ val +"\n"); } // end of MatrixIterator loop; outBiomassBli.close(); outBiomassPok.close(); outBiomassRng.close(); outBiomassBsf.close(); outBiomassSkh.close(); outCatchStrMetierBli.close(); outCatchStrMetierPok.close(); outCatchStrMetierRng.close(); outCatchStrMetierBsf.close(); outCatchStrMetierSkh.close(); outEffortStrMetier.close(); outValueStrMetier.close(); first2 = false; } // end of date = lastdate if test; } // end of first2 if test; } // end of postAction; } /* * Copyright (C) 2010 pmarchal * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package scripts; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.entities.*; import org.nuiton.math.matrix.*; import java.io.File; import java.io.Writer; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.FileReader; /** * Fsq.java * * Created: 24 septembre 2010 * * @author pmarchal <anonymous@labs.libre-entreprise.org> * @version $Revision: 0 $ * * Last update: $Date: 11 octobre 2010 $ * by : $Author: pmarchal $ */ public class Fsq extends Object { // The Fsq class has three fields; double C, N, M, Foth; // The Fsq class has one Constructor; public Fsq(double Ctemp, double Ntemp, double Mtemp, double FothTemp) { C = Ctemp; N = Ntemp; M = Mtemp; Foth = FothTemp; } // The Fsq class has one Method; public double deriveF(double xx, double nn) { double ff; ff = Math.pow((C - (xx/(xx+Foth+M))*(1-Math.exp(-(xx+Foth+M)))*N),2); return ff; } // end of Method deriveF; } /* * Copyright (C) 2010 pmarchal * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package scripts; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.entities.*; import org.nuiton.math.matrix.*; import java.io.File; import java.io.Writer; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.FileReader; /** * Fcalculation.java * * Created: 24 septembre 2010 * * @author pmarchal <anonymous@labs.libre-entreprise.org> * @version $Revision: 0 $ * * Last update: $Date: 24 septembre 2010 $ * by : $Author: pmarchal $ */ public class Fcalculation extends Object { double C, N, M, Bmsy, Ymsy; double recruitNumber; int ageMin, ageMax; MatrixND mortNat, Fsq, weightAA; public Fcalculation(double Ctemp, double Ntemp, double Mtemp) { C = Ctemp; N = Ntemp; M = Mtemp; } /* public Fcalculation(int ageMinTemp, int ageMaxTemp, double recruitNumberTemp, MatrixND mortNatTemp, MatrixND FsqTemp, MatrixND weightAAtemp) { ageMin = ageMinTemp; ageMax = ageMaxTemp; recruitNumber = recruitNumberTemp; mortNat = MatrixFactory.getInstance().create(mortNatTemp); Fsq = MatrixFactory.getInstance().create(FsqTemp); weightAA = MatrixFactory.getInstance().create(weightAAtemp); for (int iage=ageMin; iage <= ageMax; iage++){ mortNat.setValue(iage,mortNatTemp.getValue(iage)); Fsq.setValue(iage,FsqTemp.getValue(iage)); weightAA.setValue(iage,weightAAtemp.getValue(iage)); } } */ public double deriveF(double xx, int nn) { // Derives Fsq; double ff; ff = Math.pow((C - (xx/(xx+M))*(1-Math.exp(-(xx+M)))*N),2); return ff; } // end of Method deriving Fsq; /* public double deriveF(double xx) { // Derives Fmsy; double ff; double countNmsy = 0.0; double countBmsy = 0.0; double countCmsy = 0.0; double countYmsy = 0.0; double cumcountBmsy = 0.0; double cumcountYmsy = 0.0; for (int iage=ageMin; iage <= ageMax; iage++){ if (iage == ageMin){ countNmsy = recruitNumber; } else if (iage > ageMin && iage < ageMax){ countNmsy = countNmsy*Math.exp(-mortNat.getValue(iage-1)-xx*Fsq.getValue(iage-1)); } else if (iage == ageMax){ countNmsy = countNmsy*Math.exp(-mortNat.getValue(iage-1)-xx*Fsq.getValue(iage-1))/ (1-Math.exp(-mortNat.getValue(iage)-xx*Fsq.getValue(iage))); } countBmsy = countNmsy*weightAA.getValue(iage); countCmsy = countNmsy*(xx*Fsq.getValue(iage)/(mortNat.getValue(iage)+xx*Fsq.getValue(iage)))* (1-Math.exp(-mortNat.getValue(iage)-xx*Fsq.getValue(iage))); countYmsy = countCmsy*weightAA.getValue(iage); cumcountBmsy += countBmsy; cumcountYmsy += countCmsy; } // end of for loop; Bmsy = cumcountBmsy; Ymsy = cumcountYmsy; ff = -Ymsy; System.out.print("xx: "+xx+" ff: "+ff+" Ymsy: "+Ymsy+" Bmsy: "+Bmsy+ "\n"); return ff; } // end of Method deriving Fmsy; */ } /* * Copyright (C) 2010 pmarchal * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package scripts; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.entities.*; import org.nuiton.math.matrix.*; import java.io.File; import java.io.Writer; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.FileReader; /** * Fmgt.java * * Created: 18 octobre 2010 * * @author pmarchal <anonymous@labs.libre-entreprise.org> * @version $Revision: 0 $ * * Last update: $Date: 18 octobre 2010 $ * by : $Author: pmarchal $ */ public class Fmgt { // The Fmgt class has 7 fields; double recruitNumber; double Ymgt; int ageMin, ageMax; MatrixND mortNat, Fold, Foth, weightAA; Population pop; // The Fmgt class has one Constructor; public Fmgt(Population popTemp, int ageMinTemp, int ageMaxTemp, double recruitNumberTemp, double YmgtTemp, MatrixND mortNatTemp, MatrixND FoldTemp, MatrixND FothTemp, MatrixND weightAAtemp) { ageMin = ageMinTemp; ageMax = ageMaxTemp; recruitNumber = recruitNumberTemp; Ymgt = YmgtTemp; pop = popTemp; mortNat = MatrixFactory.getInstance().create(mortNatTemp); Fold = MatrixFactory.getInstance().create(FoldTemp); Foth = MatrixFactory.getInstance().create(FothTemp); weightAA = MatrixFactory.getInstance().create(weightAAtemp); for (int iage=ageMin; iage <= ageMax; iage++){ mortNat.setValue(iage,mortNatTemp.getValue(iage)); Fold.setValue(iage,FoldTemp.getValue(iage)); Foth.setValue(iage,FothTemp.getValue(iage)); weightAA.setValue(iage,weightAAtemp.getValue(iage)); } } // The Fmgt class has 1 method; public double deriveF(double xx, int nn) { double ff; double countN = 0.0; double countC = 0.0; double countY = 0.0; double cumcountY = 0.0; for (int iage=ageMin; iage <= ageMax; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); PopulationGroup ageMinus1 = pop.getPopulationGroup().get(iage-1); if (iage == ageMin){ countN = recruitNumber; } else if (iage > ageMin && iage < ageMax){ countN = countN*Math.exp(-mortNat.getValue(ageMinus1)- Foth.getValue(ageMinus1)-xx*Fold.getValue(ageMinus1)); } else if (iage == ageMax){ countN = countN*Math.exp(-mortNat.getValue(ageMinus1)- Foth.getValue(ageMinus1)-xx*Fold.getValue(ageMinus1))/ (1-Math.exp(-mortNat.getValue(age)-Foth.getValue(ageMinus1)-xx*Fold.getValue(age))); } countC = countN*(xx*Fold.getValue(age)/(mortNat.getValue(age)+Foth.getValue(age)+xx*Fold.getValue(age)))* (1-Math.exp(-mortNat.getValue(age)-Foth.getValue(age)-xx*Fold.getValue(age))); countY = countC*weightAA.getValue(age); cumcountY += countY; } // end of for iage loop; ff = Math.pow((Ymgt - cumcountY),2); // if a yield maximum cannot be reached; return ff; } // end of Method deriveF; } /* * Copyright (C) 2010 pmarchal * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package scripts; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.entities.*; import org.nuiton.math.matrix.*; /** * Fmin.java * * Created: 8 septembre 2010 * * @author pmarchal <anonymous@labs.libre-entreprise.org> * @version $Revision: 0 $ * * Last update: $Date: 8 septembre 2010 $ * by : $Author: pmarchal $ */ public class Fmin extends Object { /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(Fmin.class); public static double fmin (double a, double b, double tol, Fsq minclassFsq, Fmsy minclassFmsy, Fmgt minclassFmgt, int n, int ntype) { 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); w = v; x = v; e = 0.0; fx = 0.0; fu = 0.0; if (ntype == 0) { fx = minclassFsq.deriveF(x,n); } else if (ntype == 1) { fx = minclassFmsy.deriveF(x,n); } else if (ntype == 2) { fx = minclassFmgt.deriveF(x,n); } 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; 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; } } if (ntype == 0) { fu = minclassFsq.deriveF(u,n); } else if (ntype == 1) { fu = minclassFmsy.deriveF(u,n); } else if (ntype == 2) { fu = minclassFmgt.deriveF(u,n); } // 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; } } /* * Copyright (C) 2010 pmarchal * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package scripts; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.entities.*; import org.nuiton.math.matrix.*; import java.io.File; import java.io.Writer; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.FileReader; /** * Fmsy.java * * Created: 24 septembre 2010 * * @author pmarchal <anonymous@labs.libre-entreprise.org> * @version $Revision: 0 $ * * Last update: $Date: 27 septembre 2010 $ * by : $Author: pmarchal $ */ public class Fmsy extends Object { // The Fmsy class has six fields; double recruitNumber; public static double Bmsy,Ymsy,B0; int ageMin, ageMax; MatrixND mortNat, Fsq, weightAA, maturityAA; Population pop; // The Fmsy class has one Constructor; public Fmsy(Population popTemp, int ageMinTemp, int ageMaxTemp, double recruitNumberTemp, double B0temp, MatrixND mortNatTemp, MatrixND FsqTemp, MatrixND weightAAtemp, MatrixND maturityAAtemp) { ageMin = ageMinTemp; ageMax = ageMaxTemp; recruitNumber = recruitNumberTemp; B0 = B0temp; pop = popTemp; mortNat = MatrixFactory.getInstance().create(mortNatTemp); Fsq = MatrixFactory.getInstance().create(FsqTemp); weightAA = MatrixFactory.getInstance().create(weightAAtemp); maturityAA = MatrixFactory.getInstance().create(maturityAAtemp); for (int iage=ageMin; iage <= ageMax; iage++){ mortNat.setValue(iage,mortNatTemp.getValue(iage)); Fsq.setValue(iage,FsqTemp.getValue(iage)); weightAA.setValue(iage,weightAAtemp.getValue(iage)); maturityAA.setValue(iage,maturityAAtemp.getValue(iage)); } } // The Fmsy class has two Methods; public double deriveF(double xx, int nn) { double ff = 0.0; double countNmsy = 0.0; double countBmsy = 0.0; double countCmsy = 0.0; double countYmsy = 0.0; double cumcountBmsy = 0.0; double cumcountYmsy = 0.0; for (int iage=ageMin; iage <= ageMax; iage++){ PopulationGroup age = pop.getPopulationGroup().get(iage); PopulationGroup ageMinus1 = pop.getPopulationGroup().get(iage-1); if (iage == ageMin){ countNmsy = recruitNumber; } else if (iage > ageMin && iage < ageMax){ countNmsy = countNmsy*Math.exp(-mortNat.getValue(ageMinus1)-xx*Fsq.getValue(ageMinus1)); } else if (iage == ageMax){ countNmsy = countNmsy*Math.exp(-mortNat.getValue(ageMinus1)-xx*Fsq.getValue(ageMinus1))/ (1-Math.exp(-mortNat.getValue(age)-xx*Fsq.getValue(age))); } countBmsy = countNmsy*weightAA.getValue(age)*maturityAA.getValue(age); countCmsy = countNmsy*(xx*Fsq.getValue(age)/(mortNat.getValue(age)+xx*Fsq.getValue(age)))* (1-Math.exp(-mortNat.getValue(age)-xx*Fsq.getValue(age))); countYmsy = countCmsy*weightAA.getValue(age); cumcountBmsy += countBmsy; cumcountYmsy += countYmsy; } // end of for iage loop; if (pop.getName().compareTo("BlueLingSouth") == 0){ Bmsy = 0.50*B0; // if a yield maximum cannot be reached; ff = Math.pow((Bmsy - cumcountBmsy),2); // if a yield maximum cannot be reached; } else if (pop.getName().compareTo("Pok3a46") == 0){ Bmsy = cumcountBmsy; // if full yield optimization; Bmsy = 200000000; // for consistency with the saithe management plan; ff = -Ymsy; // if full yield optimization; } Ymsy = cumcountYmsy; return ff; } // end of Method deriveF; }