Bonjour Eric, Désolé pour la réponse tardive mais je suis parti en congés entre temps. Je joins les scripts demandés. Paul Eric Chatellier a écrit :
Le 05/08/2011 15:58, Paul MARCHAL a écrit :
Bonjour,
Je me lance dans les plans de simulaation pour la première, ce qui explique sans doute ce message.
Bon, j'ai commencé par quelque chose de simple où une variable de ma règle peut prendre deux valeurs. 2 simulations devraient normalement être réalisées. La première se passe bien, mais la seconde bloque. Apparemment la matrix est "null", alors qu'elle affiche des valeurs normales la première fois. Je l'ai mise en private et en public mais cela ne change rien. Je vous envoie le plan, le debug, la règle dont un paramètre est modifié, et les fichiers texte nécessaires à son lancement.
Merci d'avance pour votre aide
Bonjour,
Etrange en effet qu'une valeur definie dans l'init redeviennent null à la deuxieme simulations.
Je n'ai pas pu tester, la regle ne compile pas sans les scripts: scripts.Fmin; scripts.Fmsy; scripts.Fsq; scripts.Fmgt;
-- 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 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; /** * 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; }