Isis-fish-data-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- 322 discussions
Author: jcouteau
Date: 2009-04-29 08:39:41 +0000 (Wed, 29 Apr 2009)
New Revision: 127
Modified:
trunk/sensitivity/SensitivityCalculatorRRandomLHS.java
Log:
Fixed error
Modified: trunk/sensitivity/SensitivityCalculatorRRandomLHS.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorRRandomLHS.java 2009-04-29 08:39:07 UTC (rev 126)
+++ trunk/sensitivity/SensitivityCalculatorRRandomLHS.java 2009-04-29 08:39:41 UTC (rev 127)
@@ -324,7 +324,7 @@
log.info("Message sent to R : " + data);
// Creating the factors vector.
- String rInstruction = "factornames<-c(";
+ rInstruction = "factornames<-c(";
for (int i = 0; i < factornumber; i++) {
if (i != (factornumber - 1)) {
rInstruction = rInstruction + "\""
1
0
Author: jcouteau
Date: 2009-04-29 08:39:07 +0000 (Wed, 29 Apr 2009)
New Revision: 126
Modified:
trunk/sensitivity/SensitivityCalculatorROptimumLHS.java
trunk/sensitivity/SensitivityCalculatorRRandomLHS.java
Log:
Adaptation des m?\195?\169thodes Hypercube latin au nouveau CDC.
Possibilit?\195?\169 de modifier les instructions R.
Pop-up d'erreur si facteurs non corrects.
Modified: trunk/sensitivity/SensitivityCalculatorROptimumLHS.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorROptimumLHS.java 2009-04-28 13:43:11 UTC (rev 125)
+++ trunk/sensitivity/SensitivityCalculatorROptimumLHS.java 2009-04-29 08:39:07 UTC (rev 126)
@@ -19,9 +19,14 @@
package sensitivity;
import java.io.File;
-import java.io.Serializable;
import java.util.List;
+import javax.swing.Box;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.j2r.REngine;
@@ -31,38 +36,42 @@
import org.codelutin.util.FileUtil;
import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityCalculator;
import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Domain;
import fr.ifremer.isisfish.simulator.sensitivity.Factor;
import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityCalculator;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityCalculator;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
-/**save.image()
- * Implementation of Optimum Latin Hypercube method using R.
+/**
+ * save.image() Implementation of Optimum Latin Hypercube method using R.
*
* @author jcouteau
* @version $Revision: 1.0 $
*
*/
@Doc("Optimum Latin Hypercube")
-public class SensitivityCalculatorROptimumLHS extends AbstractSensitivityCalculator {
+public class SensitivityCalculatorROptimumLHS extends
+ AbstractSensitivityCalculator {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory
.getLog(SensitivityCalculatorROptimumLHS.class);
@Doc("Number of simulations (default=10)")
- public int param_simulationNumber;
+ public int param_simulationNumber = 10;
@Doc("The maximum number of times the Columnwise Pairwise algorithm is applied to all the columns(default=2).")
- public int param_MaxSweeps;
+ public int param_MaxSweeps = 2;
@Doc("The optimal stopping criterion (between 0 and 1) (default=0.1).")
- public double param_eps;
+ public double param_eps = 0.1;
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
/**
* Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
@@ -77,12 +86,28 @@
public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
throws SensitivityException {
+ setIsisFactorsR(plan, outputdirectory);
+
int factornumber = plan.getFactors().size();
List<Factor> factors = plan.getFactors();
double[] dataframe = new double[0];
SensitivityScenarios thisExperiment = new SensitivityScenarios();
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+ //Test all factors, if one is discrete, return null
+ for (int i = 0; i < factornumber; i++) {
+ if (factors.get(i).getDomain() instanceof DiscreteDomain) {
+ JOptionPane
+ .showMessageDialog(
+ null,
+ "Error",
+ factors.get(i).getName()
+ + " has a discrete domain, this is not acceptable for this method.",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ }
+
REngine engine = new RProxy();
if ((Integer) param_simulationNumber == 0) {
@@ -98,14 +123,46 @@
try {
+ //Set working directory to get Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
+
+ //Get Isis R session
+ log.info("load(\".RData\")");
+ engine.voidEval("load(\".RData\")");
+
//Load the lhs library
engine.voidEval("library(lhs)");
log.info("Message sent to R : " + "library(lhs)");
- String rInstruction = "x<-optimumLHS(n=" + param_simulationNumber
- + ",k=" + factornumber + ",maxSweeps=" + param_MaxSweeps
- + ",eps=" + param_eps + ")";
+ //Remove all objects that will be used
+ engine.voidEval("remove(\"isis.factor.distribution\")");
+ engine.voidEval("remove(\"isis.simule\")");
+ engine.voidEval("remove(\"isis.MethodExp\")");
+ engine.voidEval("remove(\"isis.methodAnalyse\")");
+ String rInstruction = "x<-optimumLHS(n=%s,k=%s,maxSweeps=%s,eps=%s)";
+
+ String rCall = String.format(rInstruction, param_simulationNumber,
+ factornumber, param_MaxSweeps, param_eps);
+
+ if (param_modifR) {
+ JLabel label = new JLabel(
+ "Modifier le code R envoyé si vous le souhaitez");
+ JTextPane text = new JTextPane();
+ text.setText(rCall);
+ text.setSize(400, 400);
+ text.setPreferredSize(text.getSize());
+
+ Box box = Box.createVerticalBox();
+ box.add(label);
+ box.add(new JScrollPane(text));
+
+ JOptionPane.showMessageDialog(null, box, "R modif",
+ JOptionPane.QUESTION_MESSAGE);
+ rCall = text.getText();
+ }
+
//Create the scenarios
engine.voidEval(rInstruction);
log.info("Message sent to R : " + rInstruction);
@@ -122,8 +179,7 @@
for (int j = 0; j < param_simulationNumber; j++) {
Scenario experimentScenario = new Scenario();
for (int i = 0; i < factornumber; i++) {
- Factor factor = plan.getFactors()
- .get(i);
+ Factor factor = plan.getFactors().get(i);
if ((factor.getDomain() instanceof MatrixContinuousDomain)
|| (factor.getDomain() instanceof EquationContinuousDomain)) {
factor
@@ -145,13 +201,78 @@
thisExperiment.setScenarios(thisExperimentScenarios);
}
- //Create the factors vectors
- for (int j = 0; j < factornumber; j++) {
- Factor factor = thisExperimentScenarios
- .get(0).getFactors().get(j);
+ String isisFactorDistribution = "isis.factor.distribution<-data.frame(NomFacteur=c(%s),NomDistribution=c(%s),ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+ String factorNames = "";
+
+ for (int i = 0; i < factors.size(); i++) {
+ Domain domain = factors.get(i).getDomain();
+ if (i != 0) {
+ distribution += ",";
+ factorNames += ",";
+ parameters += ",";
+ }
+
+ factorNames += "\"" + factors.get(i).getName() + "\"";
+ distribution += "\"qunif\"";
+ parameters += "\"[" + ((ContinuousDomain) domain).getMinBound()
+ + ";" + ((ContinuousDomain) domain).getMaxBound()
+ + "]\"";
+ }
+
+ log.info("Message sent to R : "
+ + String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+ engine.voidEval(String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+
+ log.info("Message sent to R : " + "call<-" + "\"x<-optimumLHS(n="
+ + param_simulationNumber + ",k=" + factornumber
+ + ",maxSweeps=" + param_MaxSweeps + ",eps=" + param_eps
+ + ")\"");
+ engine.voidEval("call<-" + "\"x<-optimumLHS(n="
+ + param_simulationNumber + ",k=" + factornumber
+ + ",maxSweeps=" + param_MaxSweeps + ",eps=" + param_eps
+ + ")\"");
+
+ log
+ .info("Message sent to R : "
+ + "isis.MethodExp<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"call\"=call)");
+ engine
+ .voidEval("isis.MethodExp<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"call\"=call)");
+
+ log
+ .info("Message sent to R : "
+ + "attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ log.info("Message sent to R : " + "isis.simule<-data.frame(x)");
+ engine.voidEval("isis.simule<-data.frame(x)");
+
+ log
+ .info("Message sent to R : "
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ log.info("Message sent to R : "
+ + "names(isis.simule)<-isis.factors[[1]]");
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ String data = "data<-data.frame(";
+
+ //Create the factors vectors and the dataframe instruction
+ for (int j = 0; j < factors.size(); j++) {
+ Factor factor = thisExperimentScenarios.get(0).getFactors()
+ .get(j);
if (factor.getDomain() instanceof EquationContinuousDomain) {
- String vector = "factor" + j + "<-c(";
+ //String vector = "factor" + j + "<-c(";
+ String vector = factor.getName().replaceAll(" ", "")
+ + "<-c(";
for (int i = 0; i < param_simulationNumber; i++) {
if (i < (param_simulationNumber - 1)) {
vector = vector
@@ -170,7 +291,9 @@
engine.voidEval(vector);
log.info("Message sent to R : " + vector);
} else if (factor.getDomain() instanceof MatrixContinuousDomain) {
- String vector = "factor" + j + "<-c(";
+ //String vector = "factor" + j + "<-c(";
+ String vector = factor.getName().replaceAll(" ", "")
+ + "<-c(";
for (int i = 0; i < param_simulationNumber; i++) {
if (i < (param_simulationNumber - 1)) {
vector = vector
@@ -189,7 +312,9 @@
engine.voidEval(vector);
log.info("Message sent to R : " + vector);
} else {
- String vector = "factor" + j + "<-c(";
+ //String vector = "factor" + j + "<-c(";
+ String vector = factor.getName().replaceAll(" ", "")
+ + "<-c(";
for (int i = 0; i < param_simulationNumber; i++) {
if (i < (param_simulationNumber - 1)) {
vector = vector
@@ -207,15 +332,13 @@
engine.voidEval(vector);
log.info("Message sent to R : " + vector);
}
- }
- //Create the data data.frame from the factors
- String data = "data<-data.frame(";
- for (int j = 0; j < factornumber; j++) {
- if (j < factornumber - 1) {
- data = data + "factor" + j + "=factor(factor" + j + "),";
+ if (j < factors.size() - 1) {
+ data += factor.getName().replaceAll(" ", "") + "=factor("
+ + factor.getName().replaceAll(" ", "") + "),";
} else {
- data = data + "factor" + j + "=factor(factor" + j + "))";
+ data += factor.getName().replaceAll(" ", "") + "=factor("
+ + factor.getName().replaceAll(" ", "") + "))";
}
}
@@ -237,7 +360,7 @@
rInstruction += ")";
engine.voidEval(rInstruction);
- log.info("Message sent to R : " + rInstruction);
+ log.info("Message sent to R" + rInstruction);
// Set output directory
engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
@@ -245,7 +368,7 @@
log.info("Message sent to R : " + "setwd(\""
+ outputdirectory.getAbsolutePath() + "\")");
- // Export the scenario matrix for the second run in a .randomlhs.csv file
+ // Export the scenario matrix for the second run in a .optimumlhs.csv file
engine.voidEval("write.csv(data,file=\".optimumlhs.csv\")");
log.info("Message sent to R : "
+ "write.csv(data,file=\".optimumlhs.csv\")");
@@ -255,6 +378,14 @@
log.info("Message sent to R"
+ "dput(factornames,file=\".factornames\")");
+ //Set working directory to save Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
+
+ // Save Isis R session
+ log.info("save.image()");
+ engine.voidEval("save.image()");
+
engine.terminate();
} catch (Exception e) {
@@ -282,36 +413,48 @@
REngine engine = new RProxy();
try {
- int sensitivityNumber = simulationStorages.get(0).getParameter()
- .getSensitivityExport().size();
+ //Set working directory to get Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
- for (int k = 0; k < sensitivityNumber; k++) {
+ //Get Isis R session
+ log.info("load(\".RData\")");
+ engine.voidEval("load(\".RData\")");
- // Set output directory
- engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
- + "\")");
- log.info("Message sent to R : setwd(\""
- + outputdirectory.getAbsolutePath() + "\")");
+ // Set output directory
+ engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
+ + "\")");
+ log.info("Message sent to R : setwd(\""
+ + outputdirectory.getAbsolutePath() + "\")");
- //Get back the scenarios
- //engine.voidEval("factors<-read.csv(\".expandgrid.csv\",row.names=1,col.names=1)");
- engine.voidEval("factors<-read.csv(\".optimumlhs.csv\")");
- log
- .info("Message sent to R : factors<-read.csv(\".optimumlhs.csv\")");
+ //Get back the scenarios
+ engine.voidEval("factors<-read.csv(\".optimumlhs.csv\")");
+ log
+ .info("Message sent to R : factors<-read.csv(\".optimumlhs.csv\")");
- // Get the factornames object in the .factornames file
- engine.voidEval("factornames<-dget(\".factornames\")");
- log.info("Message sent to R : "
- + "factornames<-dget(\".factornames\")");
+ // Get the factornames object in the .factornames file
+ engine.voidEval("factornames<-dget(\".factornames\")");
+ log.info("Message sent to R : "
+ + "factornames<-dget(\".factornames\")");
- //Get back the factors number
- int factorNumber = ((Double) engine.eval("length(factors)-1"))
- .intValue();
- //factorNumber=factorNumber-1;
+ //Get back the factors number
+ int factorNumber = ((Double) engine.eval("length(factors)-1"))
+ .intValue();
- //Create the results vectors
- String result = "result<-c(";
- for (int l = 0; l < simulationStorages.size(); l++) {
+ //Get back the simulation number
+ param_simulationNumber = (Integer) (engine
+ .eval("length(factors[,1])"));
+
+ int sensitivityNumber = simulationStorages.get(0).getParameter()
+ .getSensitivityExport().size();
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = simulationStorages.get(0).getParameter()
+ .getSensitivityExport().get(k).getExportFilename();
+ String rInstruction = name + "<-c(";
+ for (int l = 0; l < param_simulationNumber; l++) {
File importFile = new File(simulationStorages.get(l)
.getDirectory().toString()
+ File.separator
@@ -324,28 +467,65 @@
.getExtensionFilename());
String simulResult = FileUtil.readAsString(importFile);
double simulationResult = Double.valueOf(simulResult);
- if (l < simulationStorages.size() - 1) {
- result = result + simulationResult + ",";
+ if (l < param_simulationNumber - 1) {
+ rInstruction = rInstruction + simulationResult + ",";
} else {
- result = result + simulationResult;
+ rInstruction = rInstruction + simulationResult;
}
}
- result = result + ")";
- engine.voidEval(result);
- log.info("Message sent to R : " + result);
+ rInstruction = rInstruction + ")";
+ log.info("Message sent to R : " + rInstruction);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," + name
+ + ")");
+ log.info("Message sent to R : "
+ + "isis.simule<-data.frame(isis.simule," + name + ")");
+ }
+
+ //adding attribute to isis.Simule
+ log
+ .info("Message sent to R : "
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ log.info("Message sent to R : "
+ + "attr(isis.simule,\"call\")<-isis.MethodExp$call");
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = simulationStorages.get(0).getParameter()
+ .getSensitivityExport().get(k).getExportFilename();
+
//Create the dataforaov data.frame
- String dataframe = "dataforaov<-data.frame(factors,result=result)";
+ String dataframe = "dataforaov<-data.frame(factors," + name
+ + "=" + name + ")";
engine.voidEval(dataframe);
log.info("Message sent to R : " + dataframe);
//Call aov()
- String aovCall = "aovresult<-aov(result~";
+ String aovCall = "aovresult<-aov(" + name + "~";
for (int j = 0; j < factorNumber; j++) {
+ log.info("Message sent to R : " + "names(factors)["
+ + (j + 2) + "]");
+
if (j < (factorNumber - 1)) {
- aovCall = aovCall + "factor" + j + "+";
+ aovCall = aovCall
+ + engine
+ .eval("names(factors)[" + (j + 2) + "]")
+ + "+";
} else {
- aovCall = aovCall + "factor" + j + ",data=dataforaov)";
+ aovCall = aovCall
+ + engine
+ .eval("names(factors)[" + (j + 2) + "]")
+ + ",data=dataforaov)";
}
}
engine.voidEval(aovCall);
@@ -388,14 +568,6 @@
log.info("Message sent to R : "
+ "row.names(exportsensitivity)<-factornames");
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
- + "\")");
- log.info("Message sent to R : setwd(\""
- + outputdirectory.getAbsolutePath() + "\")");
-
//Set dataforaov names
engine
.voidEval("resultsnames<-c(\"Simulation\",factornames,\"Result\")");
@@ -406,6 +578,14 @@
log.info("Message sent to R : "
+ "names(dataforaov)<-resultsnames");
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
+ + "\")");
+ log.info("Message sent to R : setwd(\""
+ + outputdirectory.getAbsolutePath() + "\")");
+
//Save the results with the scenarios.
engine.voidEval("write.csv(dataforaov,\""
+ simulationStorages.get(0).getParameter()
@@ -428,10 +608,71 @@
.getExportFilename()
+ "_SensitivityIndices.csv\")");
//FIXME export through java to enable export when using Rserve (when distant Rserve).
- engine.terminate();
+
+ //creating isis.methodAnalyse
+ log
+ .info("Message sent to R : "
+ + "isis.methodAnalyse<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"isis.simule\"=isis.simule,call_method=\""
+ + aovCall + "\"" + ",aovresult)");
+ engine
+ .voidEval("isis.methodAnalyse<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"isis.simule\"=isis.simule,call_method=\""
+ + aovCall + "\"" + ",aovresult)");
+
+ log
+ .info("Message sent to R : "
+ + "attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
+ String simulationName = simulationStorages.get(0).getName()
+ .replaceAll("-", "");
+ log.info("Message sent to R : "
+ + String.format(renameIsisMethodAnalyse, simulationName
+ + "." + name));
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
}
- log.info("end");
+ //Rename R objects for saving purpose
+
+ String renameIsisSimule = "%s.isis.simule<-isis.simule";
+ String renameIsisFactorDistribution = "%s.isis.factor.distribution<-isis.factor.distribution";
+ String renameIsisFactor = "%s.isis.factor<-isis.factors";
+ String renameIsisMethodExp = "%s.isis.methodExp<-isis.MethodExp";
+
+ String simulationName = simulationStorages.get(0).getName()
+ .replaceAll("-", "");
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisSimule, simulationName));
+ engine.voidEval(String.format(renameIsisSimule, simulationName));
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisFactorDistribution,
+ simulationName));
+ engine.voidEval(String.format(renameIsisFactorDistribution,
+ simulationName));
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisFactor, simulationName));
+ engine.voidEval(String.format(renameIsisFactor, simulationName));
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisMethodExp, simulationName));
+ engine.voidEval(String.format(renameIsisMethodExp, simulationName));
+
+ //Set working directory to save Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
+
+ // Save Isis R session
+ log.info("save.image()");
+ engine.voidEval("save.image()");
+
+ engine.terminate();
+
} catch (Exception e) {
e.printStackTrace();
// Error while processing
Modified: trunk/sensitivity/SensitivityCalculatorRRandomLHS.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorRRandomLHS.java 2009-04-28 13:43:11 UTC (rev 125)
+++ trunk/sensitivity/SensitivityCalculatorRRandomLHS.java 2009-04-29 08:39:07 UTC (rev 126)
@@ -21,7 +21,11 @@
import java.io.File;
import java.util.List;
+import javax.swing.Box;
+import javax.swing.JLabel;
import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -62,6 +66,8 @@
@Doc("Simulation number (default=10)")
public int param_simulationNumber = 10;
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
/**
* Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
@@ -112,17 +118,39 @@
//Get Isis R session
log.info("load(\".RData\")");
engine.voidEval("load(\".RData\")");
+
+ //Set working directory for other results
+ log.info("setwd(\"" + outputdirectory + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory + "\")");
//Load the lhs library
engine.voidEval("library(lhs)");
log.info("Message sent to R : " + "library(lhs)");
//Create the scenarios
- engine.voidEval("x<-randomLHS(" + param_simulationNumber + ","
- + factornumber + ")");
- log.info("Message sent to R : " + "x<-randomLHS("
- + param_simulationNumber + "," + factornumber + ")");
+ String rInstruction = "x<-randomLHS(%s,%s)";
+ String rCall = String.format(rInstruction,param_simulationNumber,factornumber);
+
+ if (param_modifR) {
+ JLabel label = new JLabel(
+ "Modifier le code R envoyé si vous le souhaitez");
+ JTextPane text = new JTextPane();
+ text.setText(rCall);
+ text.setSize(400, 400);
+ text.setPreferredSize(text.getSize());
+ Box box = Box.createVerticalBox();
+ box.add(label);
+ box.add(new JScrollPane(text));
+
+ JOptionPane.showMessageDialog(null, box, "R modif",
+ JOptionPane.QUESTION_MESSAGE);
+ rCall = text.getText();
+ }
+
+ engine.voidEval(rCall);
+ log.info("Message sent to R : " + rCall);
+
// Get back experiment plan
dataframe = (double[]) engine.eval("x");
log.info("Message sent to R" + "x");
@@ -139,9 +167,7 @@
if ((factor.getDomain() instanceof MatrixContinuousDomain)
|| (factor.getDomain() instanceof EquationContinuousDomain)) {
factor
- .setValueForIdentifier(Double.valueOf(
- morris.getValue(new int[] { i, j }))
- .toString());
+ .setValueForIdentifier(morris.getValue(new int[] { i, j }));
} else {
Double value = (Double) ((ContinuousDomain) factor
.getDomain()).getMinBound()
@@ -385,13 +411,16 @@
//Get back the factors number
int factorNumber = ((Double) engine.eval("length(factors)-1"))
.intValue();
+
+ //Get back the simulation number
+ param_simulationNumber = (Integer)(engine.eval("length(factors[,1])"));
- param_simulationNumber = simulationStorages.get(0).getParameter()
+ int sensitivityNumber = simulationStorages.get(0).getParameter()
.getSensitivityExport().size();
- for (int k = 0; k < param_simulationNumber; k++) {
+ for (int k = 0; k < sensitivityNumber; k++) {
- // Creates the R expression to import results in R
+ // Creates the R expression to import results in R
String name = simulationStorages.get(0).getParameter()
.getSensitivityExport().get(k).getExportFilename();
String rInstruction = name + "<-c(";
@@ -408,7 +437,7 @@
.getExtensionFilename());
String simulResult = FileUtil.readAsString(importFile);
double simulationResult = Double.valueOf(simulResult);
- if (l < simulationStorages.size() - 1) {
+ if (l < param_simulationNumber - 1) {
rInstruction = rInstruction + simulationResult + ",";
} else {
rInstruction = rInstruction + simulationResult;
@@ -439,7 +468,7 @@
+ "attr(isis.simule,\"call\")<-isis.MethodExp$call");
engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
- for (int k = 0; k < param_simulationNumber; k++) {
+ for (int k = 0; k < sensitivityNumber; k++) {
// Creates the R expression to import results in R
String name = simulationStorages.get(0).getParameter()
1
0
28 Apr '09
Author: jcouteau
Date: 2009-04-28 13:43:11 +0000 (Tue, 28 Apr 2009)
New Revision: 125
Modified:
trunk/rules/TailleMin.java
trunk/scripts/GravityModel.java
trunk/simulators/DefaultSimulator.java
Log:
Fin de l'adaptation aux scripts de Stephanie
Modified: trunk/rules/TailleMin.java
===================================================================
--- trunk/rules/TailleMin.java 2009-04-28 13:31:17 UTC (rev 124)
+++ trunk/rules/TailleMin.java 2009-04-28 13:43:11 UTC (rev 125)
@@ -2,27 +2,27 @@
import static org.codelutin.i18n.I18n._;
+import java.util.List;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MatrixIterator;
+import org.codelutin.math.matrix.MatrixND;
import scripts.ResultName;
import scripts.SiMatrix;
-
-import java.io.Writer;
-import java.util.List;
-
-import org.codelutin.math.matrix.*;
-
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.MetierSeasonInfo;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.entities.TargetSpecies;
+import fr.ifremer.isisfish.rule.AbstractRule;
import fr.ifremer.isisfish.simulator.PopulationMonitor;
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 fr.ifremer.isisfish.util.Doc;
-import fr.ifremer.isisfish.util.Doc; // pour pouvoir afficher une aide contextuelle (BUG#1605)
-
/**
* TailleMin.java
*
@@ -43,18 +43,18 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(TailleMin.class);
- @Doc(value="do the doc of param beginDate")
+ @Doc(value = "do the doc of param beginDate")
public Date param_beginDate = new Date(0);
- @Doc(value="do the doc of param endDate")
+ @Doc(value = "do the doc of param endDate")
public Date param_endDate = new Date(119);
- @Doc(value="do the doc of param species")
+ @Doc(value = "do the doc of param species")
public Species param_species = null;
- @Doc(value="do the doc of param TailleMin")
+ @Doc(value = "do the doc of param TailleMin")
public double param_TailleMin = 27;
- @Doc(value="do the doc of param propSurvie")
+ @Doc(value = "do the doc of param propSurvie")
public double param_propSurvie = 0;
- public String [] necessaryResult = {
+ public String[] necessaryResult = {
// put here all necessary result for this rule
// example:
// ResultName.MATRIX_BIOMASS,
@@ -67,21 +67,24 @@
/**
* Permet d'afficher a l'utilisateur une aide sur la regle.
+ *
* @return L'aide ou la description de la regle
*/
public String getDescription() throws Exception {
// TODO
return _("TODO description rule");
}
-
+
/**
* Appelé au démarrage de la simulation, cette méthode permet d'initialiser
* des valeurs
- * @param simulation La simulation pour lequel on utilise cette regle
+ *
+ * @param simulation
+ * La simulation pour lequel on utilise cette regle
*/
public void init(SimulationContext context) throws Exception {
}
-
+
/**
* @param context
* @param date
@@ -93,16 +96,19 @@
MetierSeasonInfo info = metier.getMetierSeasonInfo(date.getMonth());
TargetSpecies target = info.getSpeciesTargetSpecies(species);
boolean result = target != null;
-
+
return result;
}
-
+
/**
* La condition qui doit etre vrai pour faire les actions
- * @param simulation La simulation pour lequel on utilise cette regle
+ *
+ * @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 {
+ public boolean condition(SimulationContext context, Date date, Metier metier)
+ throws Exception {
log.info("Recherche si la taille Minimale s'applique");
boolean result = true;
if (date.before(param_beginDate)) {
@@ -110,56 +116,64 @@
} else if (date.after(param_endDate)) {
result = false;
} else if (isCaptureDate(date, param_species, metier) != true) {
- result=false;
+ result = false;
}
log.info("fin de condition TailleMin:" + result);
return result;
-
+
// fin
-
+
/*
-writeln("Recherche si la taille Minimale s'applique (oldValue="+oldValue);
-var metier=p.metier;
-var result = true;
-if(oldValue != undefined)
- result = oldValue;
-else if (Regle_libUtil.isCaptureDate(p.date,p.metapop, metier)!=true)
- result=false;
-else if(p.date.before(p.dateDeb))
- result = false;
-else if(p.date.after(p.dateFin))
- result = false;
+ writeln("Recherche si la taille Minimale s'applique (oldValue="+oldValue);
+ var metier=p.metier;
+ var result = true;
+ if(oldValue != undefined)
+ result = oldValue;
+ else if (Regle_libUtil.isCaptureDate(p.date,p.metapop, metier)!=true)
+ result=false;
+ else if(p.date.before(p.dateDeb))
+ result = false;
+ else if(p.date.after(p.dateFin))
+ result = false;
-writeln("fin de condition TailleMin:"+result);
-return result;
-*/
+ writeln("fin de condition TailleMin:"+result);
+ return result;
+ */
}
-
+
/**
- * Si la condition est vrai alors cette action est executée avant le pas
- * de temps de la simulation.
- * @param simulation La simulation pour lequel on utilise cette regle
+ * Si la condition est vrai alors cette action est executée avant le pas de
+ * temps de la simulation.
+ *
+ * @param simulation
+ * La simulation pour lequel on utilise cette regle
*/
- public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ public void preAction(SimulationContext context, Date date, Metier metier)
+ throws Exception {
// nothing
}
-
+
/**
- * Si la condition est vrai alors cette action est executée apres le pas
- * de temps de la simulation.
- * @param simulation La simulation pour lequel on utilise cette regle
+ * Si la condition est vrai alors cette action est executée 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 {
- log.info("*$*$*$* TailleMin.actionApres:" + date + " metapop:" + param_species + " metier:" + metier);
+ public void postAction(SimulationContext context, Date date, Metier metier)
+ throws Exception {
+ log.info("*$*$*$* TailleMin.actionApres:" + date + " metapop:"
+ + param_species + " metier:" + metier);
- if(isCaptureDate(date, param_species, metier)){
- log.info("*$*$*$* ok affecte capture infÃ?rieure Ã? TailleMin au rejet");
+ if (isCaptureDate(date, param_species, metier)) {
+ log
+ .info("*$*$*$* ok affecte capture infÃ?rieure Ã? TailleMin au rejet");
// ATTENTION
// les captures pour cette metapop ne sont plus du qu'au metier pour qui
// l'espece est secondaire: elles sont affectees aux rejets
-
+
//pb : ne se fait pas par metier
//il faut une matrice pour chaques pas de temps qui stocke les rejets
//par metier, par metapop et par classes d'age (comme pour les captures)
@@ -169,67 +183,69 @@
PopulationMonitor popMon = context.getPopulationMonitor();
SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
List<Population> pops = siMatrix.getPopulations(date);
-
+
for (Population pop : pops) {
if (pop.getSpecies().equals(param_species)) {
if (popMon.getDiscard(date, pop) == null) {
MatrixND discard = popMon.getCatch(pop).copy();
MatrixND eff = popMon.getN(pop);
-
- for (MatrixIterator i=discard.iterator(); i.next();) {
- Object [] coordonnees = i.getSemanticsCoordinates();
- PopulationGroup group = (PopulationGroup)coordonnees[2];
+
+ for (MatrixIterator i = discard.iterator(); i.next();) {
+ Object[] coordonnees = i.getSemanticsCoordinates();
+ PopulationGroup group = (PopulationGroup) coordonnees[2];
if (group.getLength() >= param_TailleMin) {
i.setValue(0);
} else if (param_propSurvie > 0) {
eff.setValue(coordonnees[2], coordonnees[3],
- eff.getValue(coordonnees[2], coordonnees[3])
- + i.getValue() * param_propSurvie);
+ eff.getValue(coordonnees[2],
+ coordonnees[3])
+ + i.getValue()
+ * param_propSurvie);
}
}
- discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP);
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET);
popMon.addDiscard(date, pop, discard);
}
}
}
-
+
log.info("fin de affecterCaptureRejetTailleMin");
-
- //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
+
+ //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
}
// fin
-
+
/*
-writeln("*$*$*$* TailleMin.actionApres:"+p.date+" metapop:"+p.metapop+" metier:"+p.metier);
-if(Regle_libUtil.isCaptureDate(p.date,p.metapop, p.metier)){
- writeln("*$*$*$* ok affecte capture infÃ?rieure Ã? TailleMin au rejet");
- // ATTENTION
- // les captures pour cette metapop ne sont plus du qu'au metier pour qui
- // l'espece est secondaire: elles sont affectees aux rejets
+ writeln("*$*$*$* TailleMin.actionApres:"+p.date+" metapop:"+p.metapop+" metier:"+p.metier);
+ if(Regle_libUtil.isCaptureDate(p.date,p.metapop, p.metier)){
+ writeln("*$*$*$* ok affecte capture infÃ?rieure Ã? TailleMin au rejet");
+ // ATTENTION
+ // les captures pour cette metapop ne sont plus du qu'au metier pour qui
+ // l'espece est secondaire: elles sont affectees aux rejets
- //pb : ne se fait pas par metier
- //il faut une matrice pour chaques pas de temps qui stocke les rejets
- //par metier, par metapop et par classes d'age (comme pour les captures)
- //////
-writeln("deb de affecterCaptureREJETTailleMin");
-var suivi = null;
+ //pb : ne se fait pas par metier
+ //il faut une matrice pour chaques pas de temps qui stocke les rejets
+ //par metier, par metapop et par classes d'age (comme pour les captures)
+ //////
+ writeln("deb de affecterCaptureREJETTailleMin");
+ var suivi = null;
-//recherche du suivi pour les pop qui ont une certaine meta pop
-for(var i=0; i< suiviePop.size(); i++){
- if(suiviePop.get(i).getPop().getMetaPopulation().equals(metapop)){
+ //recherche du suivi pour les pop qui ont une certaine meta pop
+ for(var i=0; i< suiviePop.size(); i++){
+ if(suiviePop.get(i).getPop().getMetaPopulation().equals(metapop)){
suivi = suiviePop.get(i);
var populations=suivi.getPop();
- //si on a pas deja creer le rejet on le cree et on en fait un resultat
+ //si on a pas deja creer le rejet on le cree et on en fait un resultat
var matRejet = suivi.getRejet(date);
if (matRejet==null){
var matRejetBis = MatrixFactory.create(suivi.getCapture());
var eff=suivi.getN();
-//on encapsule les objets des 4 dimensions de la matrice capture
+ //on encapsule les objets des 4 dimensions de la matrice capture
for (var iiterateur=matRejetBis.iterator();iiterateur.next();){
var coordonnees=iiterateur.getSemanticsCoordinates();
var classe=coordonnees[2];
@@ -243,18 +259,18 @@
matRejetBis.setName("Rejet par metier");
suivi.addRejet(date,matRejetBis);
}
- }
-}
+ }
+ }
-writeln("fin de affecterCaptureRejetTailleMin");
+ writeln("fin de affecterCaptureRejetTailleMin");
- //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
-}
+ //on a affecte une fois cette meta pop au rejet il ne faut pas le refaire
+ }
-return p.gestionMetier;
-*/
+ return p.gestionMetier;
+ */
}
}
Modified: trunk/scripts/GravityModel.java
===================================================================
--- trunk/scripts/GravityModel.java 2009-04-28 13:31:17 UTC (rev 124)
+++ trunk/scripts/GravityModel.java 2009-04-28 13:43:11 UTC (rev 125)
@@ -31,7 +31,6 @@
package scripts;
-import static org.codelutin.i18n.I18n._;
import static org.codelutin.i18n.I18n.n_;
import java.util.Collection;
@@ -58,17 +57,16 @@
import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.types.TimeUnit;
-
/**
* @author poussin
- *
+ *
*/
public class GravityModel {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(GravityModel.class);
-
+
protected SimulationContext context = null;
protected TopiaContext db = null;
protected SiMatrix siMatrix = null;
@@ -76,20 +74,24 @@
/**
* Method used to get GravityModel used for simulation
- * @param context context simulation
+ *
+ * @param context
+ * context simulation
* @return GravityModel or null if no GravityModel created for simulation
*/
public static GravityModel getGravityModel(SimulationContext context) {
- GravityModel result = (GravityModel)context.getValue(GravityModel.class.getName());
+ GravityModel result = (GravityModel) context
+ .getValue(GravityModel.class.getName());
return result;
}
-
- private static void setGravityModel(SimulationContext context, GravityModel gravityModel) {
+
+ private static void setGravityModel(SimulationContext context,
+ GravityModel gravityModel) {
context.setValue(GravityModel.class.getName(), gravityModel);
}
-
-
- public GravityModel(SimulationContext context, SiMatrix siMatrix) throws TopiaException, StorageException{
+
+ public GravityModel(SimulationContext context, SiMatrix siMatrix)
+ throws TopiaException, StorageException {
this.context = context;
this.db = context.getDB();
this.resultManager = context.getSimulationStorage().getResultStorage();
@@ -105,82 +107,85 @@
// MatrixFishingTimePerMonthPerVessel
//////////////////////////////////////////////////////////////////////
- public MatrixND matrixFishingTimePerMonthPerVessel(Date date) throws TopiaException{
+ public MatrixND matrixFishingTimePerMonthPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
double value = fishingTimePerMonthPerVessel(str, metier, date);
result.setValue(str, metier, value);
}
}
-
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = fishingTimePerMonthPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = fishingTimePerMonthPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
+
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * FishingTimePerMonthPerVessel[str,met,month] = FishingTimePerTrip[str,met,month]NbTripsPerMonth[str,month]
-
+ * FishingTimePerMonthPerVessel[str,met,month] =
+ * FishingTimePerTrip[str,met,month]NbTripsPerMonth[str,month]
+ *
* @param str
* @param metier
* @param date
* @return
*/
- private double fishingTimePerMonthPerVessel(Strategy str, Metier metier, Date date) {
- Month month = date.getMonth();
- double timePerTrip = siMatrix.fishingTimePerTrip(str, metier, date);
- double nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
- return timePerTrip * nbTrip;
- }
+ private double fishingTimePerMonthPerVessel(Strategy str, Metier metier,
+ Date date) {
+ Month month = date.getMonth();
+ double timePerTrip = siMatrix.fishingTimePerTrip(str, metier, date);
+ double nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
+ return timePerTrip * nbTrip;
+ }
-
//////////////////////////////////////////////////////////////////////
// matrixFuelCostsOfTravelPerVessel
//////////////////////////////////////////////////////////////////////
- public MatrixND matrixFuelCostsOfTravelPerVessel(Date date) throws TopiaException{
+ public MatrixND matrixFuelCostsOfTravelPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
double value = fuelCostsOfTravelPerVessel(str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = fuelCostsOfTravelPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = fuelCostsOfTravelPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
@@ -188,20 +193,23 @@
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
* FuelCostsOfTravelPerVessel[sov,met,month]�=�NbTripsPerMonth[str,month]*TravelTimePerTrip[sov,met,month]*UnitFuelCostsOfTravel[vt]
- *
+ *
* @param str
* @param metier
* @param date
* @return
*/
- private double fuelCostsOfTravelPerVessel(Strategy str, Metier metier, Date date) {
+ private double fuelCostsOfTravelPerVessel(Strategy str, Metier metier,
+ Date date) {
Month month = date.getMonth();
double nbTrip = str.getStrategyMonthInfo(month).getNumberOfTrips();
Collection<Zone> zone = metier.getMetierSeasonInfo(month).getZone();
// TODO: verifier que travelTime est bien en heure, car le unitFuelCost est l'unite par heure
- double travelTime = siMatrix.travelTimePerTrip(str.getSetOfVessels(), zone);
- double unitFuelCost = str.getSetOfVessels().getVesselType().getUnitFuelCostOfTravel();
+ double travelTime = siMatrix.travelTimePerTrip(str.getSetOfVessels(),
+ zone);
+ double unitFuelCost = str.getSetOfVessels().getVesselType()
+ .getUnitFuelCostOfTravel();
return nbTrip * travelTime * unitFuelCost;
}
@@ -210,94 +218,101 @@
// matrixCostsOfFishingPerVessel
//////////////////////////////////////////////////////////////////////
- public MatrixND matrixCostsOfFishingPerVessel(Date date) throws TopiaException{
+ public MatrixND matrixCostsOfFishingPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
double value = costsOfFishingPerVessel(str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = costsOfFishingPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = costsOfFishingPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * CostsOfFishingPerVessel[str,met,month]= FishingTimePerMonthPerVessel [str,met,month] {NbFishingOperationsPerDay[sov,met] UnitCostsOfFishing[sov,met] / 24}
+ * CostsOfFishingPerVessel[str,met,month]= FishingTimePerMonthPerVessel
+ * [str,met,month] {NbFishingOperationsPerDay[sov,met]
+ * UnitCostsOfFishing[sov,met] / 24}
*
* @param str
* @param metier
* @param date
* @return
*/
- private double costsOfFishingPerVessel(Strategy str, Metier metier, Date date) {
+ private double costsOfFishingPerVessel(Strategy str, Metier metier,
+ Date date) {
double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
- EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(
+ metier);
int nbOperation = 0;
double unitCostOfFishing = 0;
- if(effort != null){
+ if (effort != null) {
nbOperation = effort.getFishingOperation();
unitCostOfFishing = effort.getUnitCostOfFishing();
}
- return fishingTime * ( nbOperation * unitCostOfFishing / TimeUnit.HOUR_PER_DAY);
+ return fishingTime
+ * (nbOperation * unitCostOfFishing / TimeUnit.HOUR_PER_DAY);
}
//////////////////////////////////////////////////////////////////////
// matrixFuelCostsPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixFuelCostsPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixFuelCostsPerVessel(Date date) throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_FUEL_COSTS_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
double value = fuelCostsPerVessel(str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = fuelCostsPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = fuelCostsPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * FuelCostsPerVessel[str,met,month] = FuelCostsOfTravelPerVessel [sov,met,month] + CostsOfFishingPerVessel [str,met,month]
+ * FuelCostsPerVessel[str,met,month] = FuelCostsOfTravelPerVessel
+ * [sov,met,month] + CostsOfFishingPerVessel [str,met,month]
*
* @param str
* @param metier
@@ -314,52 +329,57 @@
//////////////////////////////////////////////////////////////////////
// matrixRepairAndMaintenanceGearCostsPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixRepairAndMaintenanceGearCostsPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixRepairAndMaintenanceGearCostsPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ double value = repairAndMaintenanceGearCostsPerVessel(str,
+ metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * RepairAndMaintenanceGearCostsPerVessel[str,met,month]�=�FishingTimePerMonthPerVessel[str,met,month] *RepairAndMaintenanceGearCostsPerDay[sov,met]/NbHoursPerDay
+ * RepairAndMaintenanceGearCostsPerVessel[str,met,month]�=�FishingTimePerMonthPerVessel[str,met,month]
+ * *RepairAndMaintenanceGearCostsPerDay[sov,met]/NbHoursPerDay
*
* @param str
* @param metier
* @param date
* @return
*/
- private double repairAndMaintenanceGearCostsPerVessel(Strategy str, Metier metier, Date date) {
+ private double repairAndMaintenanceGearCostsPerVessel(Strategy str,
+ Metier metier, Date date) {
double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
- EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(
+ metier);
double repair = 0;
- if(effort != null){
+ if (effort != null) {
repair = effort.getRepairAndMaintenanceGearCost();
}
// FIXME verifier qu'il faut bien retourner 0, si pas d'effort
@@ -369,52 +389,56 @@
//////////////////////////////////////////////////////////////////////
// matrixOtherRunningCostsPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixOtherRunningCostsPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixOtherRunningCostsPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
double value = otherRunningCostsPerVessel(str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = otherRunningCostsPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = otherRunningCostsPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * OtherRunningCostsPerVessel[str,met,month]=�FishingTimePerMonthPerVessel[str,met,month]*OtherRunningCostsPerDay[sov,met]/ NbHoursPerDay
+ * OtherRunningCostsPerVessel[str,met,month]=�FishingTimePerMonthPerVessel[str,met,month]*OtherRunningCostsPerDay[sov,met]/
+ * NbHoursPerDay
*
* @param str
* @param metier
* @param date
* @return
*/
- private double otherRunningCostsPerVessel(Strategy str, Metier metier, Date date) {
+ private double otherRunningCostsPerVessel(Strategy str, Metier metier,
+ Date date) {
double fishingTime = fishingTimePerMonthPerVessel(str, metier, date);
- EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(
+ metier);
double otherCosts = 0;
- if(effort != null){
+ if (effort != null) {
otherCosts = effort.getOtherRunningCost();
}
// FIXME verifier qu'il faut bien retourner 0, si pas d'effort
@@ -424,156 +448,170 @@
//////////////////////////////////////////////////////////////////////
// matrixSharedNotFixedCostsPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixSharedNotFixedCostsPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixSharedNotFixedCostsPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
double value = sharedNotFixedCostsPerVessel(str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = sharedNotFixedCostsPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = sharedNotFixedCostsPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * SharedNotFixedCostsPerVessel[str,met,month]=�FuelCostsPerVessel[str,met,month] +�OtherRunningCostsPerVessel[str,met,month]
- *
+ * SharedNotFixedCostsPerVessel[str,met,month]=�FuelCostsPerVessel[str,met,month]
+ * +�OtherRunningCostsPerVessel[str,met,month]
+ *
* @param str
* @param metier
* @param date
* @return
*/
- private double sharedNotFixedCostsPerVessel(Strategy str, Metier metier, Date date) {
+ private double sharedNotFixedCostsPerVessel(Strategy str, Metier metier,
+ Date date) {
double fuelCostsPerVessel = fuelCostsPerVessel(str, metier, date);
- double otherRunningCostsPerVessel = otherRunningCostsPerVessel(str, metier, date);
+ double otherRunningCostsPerVessel = otherRunningCostsPerVessel(str,
+ metier, date);
return fuelCostsPerVessel + otherRunningCostsPerVessel;
- }
+ }
//////////////////////////////////////////////////////////////////////
// matrixSharedFixedCostsPerVesselPerMet
//////////////////////////////////////////////////////////////////////
-// Supprime avec Steph le 20070227
-// public MatrixND matrixSharedFixedCostsPerVesselPerMet(Date date) throws TopiaException{
-// List<Strategy> strategies = siMatrix.getStrategies(date);
-//
-// MatrixND result = MatrixFactory.getInstance().create(
-// ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET,
-// new List[]{strategies},
-// new String[]{n_("Strategies")});
-//
-// for (int s=0; s < strategies.size(); s++) {
-// Strategy str = strategies.get(s);
-// double value = sharedFixedCostsPerVesselPerMet(str, date);
-// result.setValue(s, value);
-// }
-//// for(Strategy str : strategies){
-//// double value = sharedFixedCostsPerVesselPerMet(str, date);
-//// result.setValue(str, value);
-//// }
-//
-// return result;
-// }
-//
-// /**
-// * implant� suivant document ModifTable3PourBP25-07-2006.doc
-// * SharedFixedCostsPerVesselPerMet [str,month]=FixedCostsPerMonth[sov]/NbMet[sov]
-// *
-// * @param str
-// * @param date
-// * @return
-// */
-// private double sharedFixedCostsPerVesselPerMet(Strategy str, Date date) {
-// SetOfVessels sov = str.getSetOfVessels();
-// double fixedCosts = sov.getFixedCosts();
-// int nbMet = sov.sizePossibleMetiers();
-//
-// return fixedCosts / (double)nbMet;
-// }
+ // Supprime avec Steph le 20070227
+ // public MatrixND matrixSharedFixedCostsPerVesselPerMet(Date date) throws TopiaException{
+ // List<Strategy> strategies = siMatrix.getStrategies(date);
+ //
+ // MatrixND result = MatrixFactory.getInstance().create(
+ // ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET,
+ // new List[]{strategies},
+ // new String[]{n_("Strategies")});
+ //
+ // for (int s=0; s < strategies.size(); s++) {
+ // Strategy str = strategies.get(s);
+ // double value = sharedFixedCostsPerVesselPerMet(str, date);
+ // result.setValue(s, value);
+ // }
+ //// for(Strategy str : strategies){
+ //// double value = sharedFixedCostsPerVesselPerMet(str, date);
+ //// result.setValue(str, value);
+ //// }
+ //
+ // return result;
+ // }
+ //
+ // /**
+ // * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ // * SharedFixedCostsPerVesselPerMet [str,month]=FixedCostsPerMonth[sov]/NbMet[sov]
+ // *
+ // * @param str
+ // * @param date
+ // * @return
+ // */
+ // private double sharedFixedCostsPerVesselPerMet(Strategy str, Date date) {
+ // SetOfVessels sov = str.getSetOfVessels();
+ // double fixedCosts = sov.getFixedCosts();
+ // int nbMet = sov.sizePossibleMetiers();
+ //
+ // return fixedCosts / (double)nbMet;
+ // }
//////////////////////////////////////////////////////////////////////
// matrixGrossValueOfLandingsPerSpeciesPerStrategyMet
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(Date date) throws TopiaException{
+ public MatrixND matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
List<Population> pops = siMatrix.getPopulations(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET,
- new List[]{strategies, metiers, pops},
- new String[]{n_("Strategies"), n_("Metiers"), n_("Populations")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET,
+ new List[] { strategies, metiers, pops },
+ new String[] { n_("Strategies"), n_("Metiers"),
+ n_("Populations") });
- for (int p=0; p < pops.size(); p++) {
+ for (int p = 0; p < pops.size(); p++) {
Population pop = pops.get(p);
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ double value = grossValueOfLandingsPerSpeciesPerStrategyMet(
+ str, metier, pop, date);
result.setValue(str, metier, pop, value);
}
}
}
-// for(Population pop : pops){
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
-// result.setValue(str, metier, pop, value);
-// }
-// }
-// }
+ // for(Population pop : pops){
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ // result.setValue(str, metier, pop, value);
+ // }
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month]�=�sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet [str,met,pop,cl,month] ?DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
-nth]
- * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month] = sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet [str,met,pop,cl,month] -DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
-nth])]
- *
+ * GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month]�=�sum
+ * over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet
+ * [str,met,pop,cl,month] ?DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
+ * nth] GrossValueOfLandingsPerSpeciesPerStrategyMet[str,met,pop,month] =
+ * sum over classes_cl of [PricePerKg(pop,cl, t)* (CatchWeightPerStrategyMet
+ * [str,met,pop,cl,month] -DiscardsWeightPerStrategyMet [str,met,pop,cl,mo
+ * nth])]
+ *
* @param str
* @param metier
* @param pop
* @param date
* @return
*/
- private double grossValueOfLandingsPerSpeciesPerStrategyMet(Strategy str, Metier metier, Population pop, Date date) {
+ private double grossValueOfLandingsPerSpeciesPerStrategyMet(Strategy str,
+ Metier metier, Population pop, Date date) {
List<PopulationGroup> groups = pop.getPopulationGroup();
double result = 0;
- for(PopulationGroup group : groups){
+ for (PopulationGroup group : groups) {
double price = group.getPrice();
Collection<Zone> zones = pop.getPopulationZone();
- for(Zone zone : zones){
- double catchWeight = getCatchWeightPerStrMetPerZonePop(str, metier, group, zone, date);
- double discardsWeight = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ for (Zone zone : zones) {
+ double catchWeight = getCatchWeightPerStrMetPerZonePop(str,
+ metier, group, zone, date);
+ double discardsWeight = getDiscardsWeightPerStrMet(str, metier,
+ group, zone, date);
// FIXME demander/verifier que ce le bon calcule
result += price * (catchWeight - discardsWeight);
}
@@ -589,10 +627,12 @@
* @param date
* @return
*/
- private double getCatchWeightPerStrMetPerZonePop(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) {
- MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
- double result = 0;
- if(mat != null){
+ private double getCatchWeightPerStrMetPerZonePop(Strategy str,
+ Metier metier, PopulationGroup group, Zone zone, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, group.getPopulation(),
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
+ double result = 0;
+ if (mat != null) {
result = mat.getValue(str, metier, group, zone);
}
return result;
@@ -606,10 +646,12 @@
* @param date
* @return
*/
- private double getDiscardsWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) {
- MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP);
- double result = 0;
- if(mat != null){
+ private double getDiscardsWeightPerStrMet(Strategy str, Metier metier,
+ PopulationGroup group, Zone zone, Date date) {
+ MatrixND mat = resultManager.getMatrix(date, group.getPopulation(),
+ ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
+ double result = 0;
+ if (mat != null) {
result = mat.getValue(str, metier, group, zone);
}
return result;
@@ -618,33 +660,35 @@
//////////////////////////////////////////////////////////////////////
// matrixGrossValueOfLandingsPerStrategyMet
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixGrossValueOfLandingsPerStrategyMet(Date date) throws TopiaException{
+
+ public MatrixND matrixGrossValueOfLandingsPerStrategyMet(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ double value = grossValueOfLandingsPerStrategyMet(str, metier,
+ date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
-
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
+
return result;
}
@@ -653,14 +697,16 @@
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double grossValueOfLandingsPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ private double grossValueOfLandingsPerStrategyMet(Strategy str,
+ Metier metier, Date date) throws TopiaException {
List<Population> pops = siMatrix.getPopulations(date);
double result = 0;
- for(int i=0; i<pops.size(); i++){
- Population pop = (Population)pops.get(i);
- result += grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier, pop, date);
+ for (int i = 0; i < pops.size(); i++) {
+ Population pop = (Population) pops.get(i);
+ result += grossValueOfLandingsPerSpeciesPerStrategyMet(str, metier,
+ pop, date);
}
return result;
}
@@ -668,87 +714,97 @@
//////////////////////////////////////////////////////////////////////
// matrixGrossValueOfLandingsPerStrategyMetPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixGrossValueOfLandingsPerStrategyMetPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixGrossValueOfLandingsPerStrategyMetPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ double value = grossValueOfLandingsPerStrategyMetPerVessel(str,
+ metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = grossValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * GrossValueOfLandingsPerStrategyMetPerVessel[str,met,month]�= GrossValueOfLandingsPerStrategyMet[str,met,month]�/[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ * GrossValueOfLandingsPerStrategyMetPerVessel[str,met,month]�=
+ * GrossValueOfLandingsPerStrategyMet[str,met,month]�/[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
*
* @param str
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double grossValueOfLandingsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
- double grossValueOfLandingsPerStrategyMet = grossValueOfLandingsPerStrategyMet(str, metier, date);
+ private double grossValueOfLandingsPerStrategyMetPerVessel(Strategy str,
+ Metier metier, Date date) throws TopiaException {
+ double grossValueOfLandingsPerStrategyMet = grossValueOfLandingsPerStrategyMet(
+ str, metier, date);
// FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov)
double proportionSetOfVessels = str.getProportionSetOfVessels();
double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
- double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(str,metier,date);
+ double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(
+ str, metier, date);
-
- return (grossValueOfLandingsPerStrategyMet + grossValueOfLandingsOtherSpeciesPerStrategyMet) / (proportionSetOfVessels * numberOfVessels);
+ return (grossValueOfLandingsPerStrategyMet + grossValueOfLandingsOtherSpeciesPerStrategyMet)
+ / (proportionSetOfVessels * numberOfVessels);
}
//////////////////////////////////////////////////////////////////////
// matrixNetValueOfLandingsPerStrategyMet
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixNetValueOfLandingsPerStrategyMet(Date date) throws TopiaException{
+
+ public MatrixND matrixNetValueOfLandingsPerStrategyMet(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = netValueOfLandingsPerStrategyMet(str, metier, date);
+ double value = netValueOfLandingsPerStrategyMet(str, metier,
+ date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = netValueOfLandingsPerStrategyMet(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = netValueOfLandingsPerStrategyMet(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
@@ -761,61 +817,70 @@
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double netValueOfLandingsPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
- double grossValue = grossValueOfLandingsPerStrategyMet(str, metier, date);
- EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ private double netValueOfLandingsPerStrategyMet(Strategy str,
+ Metier metier, Date date) throws TopiaException {
+ double grossValue = grossValueOfLandingsPerStrategyMet(str, metier,
+ date);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(
+ metier);
double landingCost = 1;
// FIXME demander si le metier n'a pas d'effort s'il faut que landingCost soit bien a 1
- if(effort != null){
+ if (effort != null) {
landingCost -= effort.getLandingCosts();
}
- double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(str,metier,date);
-
- double result = (grossValue + grossValueOfLandingsOtherSpeciesPerStrategyMet)* landingCost;
+ double grossValueOfLandingsOtherSpeciesPerStrategyMet = grossValueOfLandingsOtherSpeciesPerStrategyMet(
+ str, metier, date);
+
+ double result = (grossValue + grossValueOfLandingsOtherSpeciesPerStrategyMet)
+ * landingCost;
return result;
- }
+ }
- private double grossValueOfLandingsOtherSpeciesPerStrategyMet(Strategy str, Metier metier, Date date) throws TopiaException {
+ private double grossValueOfLandingsOtherSpeciesPerStrategyMet(Strategy str,
+ Metier metier, Date date) throws TopiaException {
// FIXME evaluer l'equation dans suivant le doc des equations
return 0;
}
-
+
//////////////////////////////////////////////////////////////////////
// matrixNetValueOfLandingsPerStrategyMetPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixNetValueOfLandingsPerStrategyMetPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixNetValueOfLandingsPerStrategyMetPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ double value = netValueOfLandingsPerStrategyMetPerVessel(str,
+ metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
-
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
@@ -825,104 +890,118 @@
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double netValueOfLandingsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
- double netValueOfLandingsPerStrategyMet = netValueOfLandingsPerStrategyMet(str, metier, date);
+ private double netValueOfLandingsPerStrategyMetPerVessel(Strategy str,
+ Metier metier, Date date) throws TopiaException {
+ double netValueOfLandingsPerStrategyMet = netValueOfLandingsPerStrategyMet(
+ str, metier, date);
// FIXME verifier que c bien cette donn�e qu'il faut utiliser dans le doc: PropNbVessels(str, sov)
double proportionSetOfVessels = str.getProportionSetOfVessels();
double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
- return netValueOfLandingsPerStrategyMet / (proportionSetOfVessels * numberOfVessels);
+ return netValueOfLandingsPerStrategyMet
+ / (proportionSetOfVessels * numberOfVessels);
}
//////////////////////////////////////////////////////////////////////
// matrixNetRenevueToSharePerStrategyMetPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixNetRenevueToSharePerStrategyMetPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixNetRenevueToSharePerStrategyMetPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL,
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ double value = netRenevueToSharePerStrategyMetPerVessel(str,
+ metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�=�NetValueOfLandingsPerStrategyMetPerVessel[str,met,month]�-�SharedNotFixedCostsPerVessel [str,met,month]*PropStr(str,met,month) - SharedFixedCostsPerVessel
-PerMet[str,month]
- *
+ * NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�=�NetValueOfLandingsPerStrategyMetPerVessel[str,met,month]�-�SharedNotFixedCostsPerVessel
+ * [str,met,month]*PropStr(str,met,month) - SharedFixedCostsPerVessel
+ * PerMet[str,month]
+ *
* @param str
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double netRenevueToSharePerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
- double netRenevueToSharePerStrategyMetPerVessel = netValueOfLandingsPerStrategyMetPerVessel(str, metier, date);
- double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str, metier, date);
- double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ private double netRenevueToSharePerStrategyMetPerVessel(Strategy str,
+ Metier metier, Date date) throws TopiaException {
+ double netRenevueToSharePerStrategyMetPerVessel = netValueOfLandingsPerStrategyMetPerVessel(
+ str, metier, date);
+ double sharedNotFixedCostsPerVessel = sharedNotFixedCostsPerVessel(str,
+ metier, date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth())
+ .getProportionMetier(metier);
- double result = netRenevueToSharePerStrategyMetPerVessel - sharedNotFixedCostsPerVessel * propStr;
+ double result = netRenevueToSharePerStrategyMetPerVessel
+ - sharedNotFixedCostsPerVessel * propStr;
return result;
}
//////////////////////////////////////////////////////////////////////
// matrixCrewSharePerStrategyMetPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixCrewSharePerStrategyMetPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixCrewSharePerStrategyMetPerVessel(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
MatrixND result = MatrixFactory.getInstance().create(
ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = crewSharePerStrategyMetPerVessel(str, metier, date);
+ double value = crewSharePerStrategyMetPerVessel(str, metier,
+ date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = crewSharePerStrategyMetPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = crewSharePerStrategyMetPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
-
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
* CrewSharePerStrategyMetPerVessel[str,met,month]�=�NetRevenueToSharePerStrategyMetPerVessel[str,met,month]*CrewShareRate[sov,met]
@@ -931,170 +1010,200 @@
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double crewSharePerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
- double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ private double crewSharePerStrategyMetPerVessel(Strategy str,
+ Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(
+ str, metier, date);
- EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(metier);
+ EffortDescription effort = str.getSetOfVessels().getPossibleMetiers(
+ metier);
double crewShareRate = 0;
- if(effort != null){
+ if (effort != null) {
crewShareRate = effort.getCrewShareRate();
}
// FIXME verifier qu'il faut bien retourner 0, si pas d'effort
return netRenevueToShare * crewShareRate;
- }
+ }
//////////////////////////////////////////////////////////////////////
// matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(
+ Date date) throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(
+ str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
-
/**
- * implant� suivant document ModifTable3PourBP25-07-2006.doc
- * OwnerMarginOverVariableCostsPerStrategyMetPerVessel[str,met,month] = NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�- CrewSharePerStrategyMetPerVessel[str,met,month]�- RepairAndMaintenanceGearCostsPerVes
-sel[str,met,month]�* PropStr(str,met,month)
+ * implant� suivant document ModifTable3PourBP25-07-2006.doc
+ * OwnerMarginOverVariableCostsPerStrategyMetPerVessel[str,met,month] =
+ * NetRevenueToSharePerStrategyMetPerVessel[str,met,month]�-
+ * CrewSharePerStrategyMetPerVessel[str,met,month]�-
+ * RepairAndMaintenanceGearCostsPerVes sel[str,met,month]�*
+ * PropStr(str,met,month)
*
* @param str
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double ownerMarginOverVariableCostsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
- double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
+ private double ownerMarginOverVariableCostsPerStrategyMetPerVessel(
+ Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(
+ str, metier, date);
double crewShare = crewSharePerStrategyMetPerVessel(str, metier, date);
- double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
- double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ double repair = repairAndMaintenanceGearCostsPerVessel(str, metier,
+ date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth())
+ .getProportionMetier(metier);
return netRenevueToShare - crewShare - repair * propStr;
- }
+ }
-
//////////////////////////////////////////////////////////////////////
// matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(
+ Date date) throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
List<Metier> metiers = siMatrix.getMetiers(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
- new List[]{strategies, metiers},
- new String[]{n_("Strategies"), n_("Metiers")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL,
+ new List[] { strategies, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
metiers = siMatrix.getMetiers(str, date);
- for (int m=0; m < metiers.size(); m++) {
+ for (int m = 0; m < metiers.size(); m++) {
Metier metier = metiers.get(m);
- double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(
+ str, metier, date);
result.setValue(str, metier, value);
}
}
-// for(Strategy str : strategies){
-// metiers = siMatrix.getMetiers(str, date);
-// for(Metier metier : metiers) {
-// double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
-// result.setValue(str, metier, value);
-// }
-// }
+ // for(Strategy str : strategies){
+ // metiers = siMatrix.getMetiers(str, date);
+ // for(Metier metier : metiers) {
+ // double value = vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ // result.setValue(str, metier, value);
+ // }
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * VesselMarginOverVariableCostsPerStrategyMetPerVessel�[str,met,month]�=NetRevenueToSharePerStrategyMetPerVessel[str,met,month]- RepairAndMaintenanceGearCostsPerVessel [str,met,month]�* PropStr(str,met,month)
+ * VesselMarginOverVariableCostsPerStrategyMetPerVessel�[str,met,month]�=NetRevenueToSharePerStrategyMetPerVessel[str,met,month]-
+ * RepairAndMaintenanceGearCostsPerVessel [str,met,month]�*
+ * PropStr(str,met,month)
*
* @param str
* @param metier
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double vesselMarginOverVariableCostsPerStrategyMetPerVessel(Strategy str, Metier metier, Date date) throws TopiaException {
- double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(str, metier, date);
- double repair = repairAndMaintenanceGearCostsPerVessel(str, metier, date);
- double propStr = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ private double vesselMarginOverVariableCostsPerStrategyMetPerVessel(
+ Strategy str, Metier metier, Date date) throws TopiaException {
+ double netRenevueToShare = netRenevueToSharePerStrategyMetPerVessel(
+ str, metier, date);
+ double repair = repairAndMaintenanceGearCostsPerVessel(str, metier,
+ date);
+ double propStr = str.getStrategyMonthInfo(date.getMonth())
+ .getProportionMetier(metier);
return netRenevueToShare - repair * propStr;
- }
-
+ }
+
//////////////////////////////////////////////////////////////////////
// matrixOwnerMarginOverVariableCostsPerStrategyPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(
+ Date date) throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
- new List[]{strategies},
- new String[]{n_("Strategies")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
+ new List[] { strategies },
+ new String[] { n_("Strategies") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
- double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ double value = ownerMarginOverVariableCostsPerStrategyPerVessel(
+ str, date);
result.setValue(s, value);
}
-// for(Strategy str : strategies){
-// double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
-// result.setValue(str, value);
-// }
+ // for(Strategy str : strategies){
+ // double value = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ // result.setValue(str, value);
+ // }
return result;
}
-
+
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * OwnerMarginOverVariableCostsPerStrategyPerVessel[str,month]�=�somme sur tous les m�tiers de OwnerMarginOverVariableCostsPerStrategyMetPerVessel [str,met,month]
+ * OwnerMarginOverVariableCostsPerStrategyPerVessel[str,month]�=�somme sur
+ * tous les m�tiers de OwnerMarginOverVariableCostsPerStrategyMetPerVessel
+ * [str,met,month]
*
* @param str
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double ownerMarginOverVariableCostsPerStrategyPerVessel(Strategy str, Date date) throws TopiaException {
+ private double ownerMarginOverVariableCostsPerStrategyPerVessel(
+ Strategy str, Date date) throws TopiaException {
SetOfVessels sov = str.getSetOfVessels();
Collection<EffortDescription> efforts = sov.getPossibleMetiers();
float result = 0;
-
+
for (EffortDescription effort : efforts) {
Metier metier = effort.getPossibleMetiers();
- result += ownerMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ result += ownerMarginOverVariableCostsPerStrategyMetPerVessel(str,
+ metier, date);
}
return result;
}
@@ -1102,24 +1211,27 @@
//////////////////////////////////////////////////////////////////////
// matrixOwnerMarginOverVariableCostsPerStrategy
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixOwnerMarginOverVariableCostsPerStrategy(Date date) throws TopiaException{
+
+ public MatrixND matrixOwnerMarginOverVariableCostsPerStrategy(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
- new List[]{strategies},
- new String[]{n_("Strategies")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
+ new List[] { strategies },
+ new String[] { n_("Strategies") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
double value = ownerMarginOverVariableCostsPerStrategy(str, date);
result.setValue(s, value);
}
-// for(Strategy str : strategies){
-// double value = ownerMarginOverVariableCostsPerStrategy(str, date);
-// result.setValue(str, value);
-// }
+ // for(Strategy str : strategies){
+ // double value = ownerMarginOverVariableCostsPerStrategy(str, date);
+ // result.setValue(str, value);
+ // }
return result;
}
@@ -1131,51 +1243,61 @@
* @param str
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double ownerMarginOverVariableCostsPerStrategy(Strategy str, Date date) throws TopiaException {
- double ownerMarginOverVariableCostsPerStrategyPerVessel = ownerMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ private double ownerMarginOverVariableCostsPerStrategy(Strategy str,
+ Date date) throws TopiaException {
+ double ownerMarginOverVariableCostsPerStrategyPerVessel = ownerMarginOverVariableCostsPerStrategyPerVessel(
+ str, date);
double proportionSetOfVessels = str.getProportionSetOfVessels();
double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
- return ownerMarginOverVariableCostsPerStrategyPerVessel * (proportionSetOfVessels * numberOfVessels);
- }
+ return ownerMarginOverVariableCostsPerStrategyPerVessel
+ * (proportionSetOfVessels * numberOfVessels);
+ }
//////////////////////////////////////////////////////////////////////
// matrixVesselMarginOverVariableCostsPerStrategyPerVessel
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixVesselMarginOverVariableCostsPerStrategyPerVessel(Date date) throws TopiaException{
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategyPerVessel(
+ Date date) throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
- new List[]{strategies},
- new String[]{n_("Strategies")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL,
+ new List[] { strategies },
+ new String[] { n_("Strategies") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
- double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ double value = vesselMarginOverVariableCostsPerStrategyPerVessel(
+ str, date);
result.setValue(s, value);
}
-// for(Strategy str : strategies){
-// double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
-// result.setValue(str, value);
-// }
+ // for(Strategy str : strategies){
+ // double value = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ // result.setValue(str, value);
+ // }
return result;
}
-
+
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * VesselMarginOverVariableCostsPerStrategyPerVessel[str,month]�= somme sur tous les m�tiers de VesselMarginOverVariableCostsPerStrategyMetPerVessel� [str,met,month]
+ * VesselMarginOverVariableCostsPerStrategyPerVessel[str,month]�= somme sur
+ * tous les m�tiers de VesselMarginOverVariableCostsPerStrategyMetPerVessel�
+ * [str,met,month]
*
* @param str
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double vesselMarginOverVariableCostsPerStrategyPerVessel(Strategy str, Date date) throws TopiaException {
+ private double vesselMarginOverVariableCostsPerStrategyPerVessel(
+ Strategy str, Date date) throws TopiaException {
SetOfVessels sov = str.getSetOfVessels();
Collection<EffortDescription> efforts = sov.getPossibleMetiers();
@@ -1183,74 +1305,83 @@
for (EffortDescription effort : efforts) {
Metier metier = effort.getPossibleMetiers();
- result += vesselMarginOverVariableCostsPerStrategyMetPerVessel(str, metier, date);
+ result += vesselMarginOverVariableCostsPerStrategyMetPerVessel(str,
+ metier, date);
}
return result;
- }
+ }
-
//////////////////////////////////////////////////////////////////////
// matrixVesselMarginOverVariableCostsPerStrategy
//////////////////////////////////////////////////////////////////////
-
- public MatrixND matrixVesselMarginOverVariableCostsPerStrategy(Date date) throws TopiaException{
+
+ public MatrixND matrixVesselMarginOverVariableCostsPerStrategy(Date date)
+ throws TopiaException {
List<Strategy> strategies = siMatrix.getStrategies(date);
- MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
- new List[]{strategies},
- new String[]{n_("Strategies")});
+ MatrixND result = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY,
+ new List[] { strategies },
+ new String[] { n_("Strategies") });
- for (int s=0; s < strategies.size(); s++) {
+ for (int s = 0; s < strategies.size(); s++) {
Strategy str = strategies.get(s);
double value = vesselMarginOverVariableCostsPerStrategy(str, date);
result.setValue(s, value);
}
-// for(Strategy str : strategies){
-// double value = vesselMarginOverVariableCostsPerStrategy(str, date);
-// result.setValue(str, value);
-// }
+ // for(Strategy str : strategies){
+ // double value = vesselMarginOverVariableCostsPerStrategy(str, date);
+ // result.setValue(str, value);
+ // }
return result;
}
/**
* implant� suivant document ModifTable3PourBP25-07-2006.doc
- * VesselMarginOverVariableCostsPerStrategy[str,month]�=VesselMarginOverVariableCostsPerStrategyPerVessel�[str,month] *[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
+ * VesselMarginOverVariableCostsPerStrategy[str,month]�=VesselMarginOverVariableCostsPerStrategyPerVessel�[str,month]
+ * *[PropNbVessels(str,sov)*NbVesselsSetOfVessels(sov)]
*
* @param str
* @param date
* @return
- * @throws TopiaException
+ * @throws TopiaException
*/
- private double vesselMarginOverVariableCostsPerStrategy(Strategy str, Date date) throws TopiaException {
- double vesselMarginOverVariableCostsPerStrategyPerVessel = vesselMarginOverVariableCostsPerStrategyPerVessel(str, date);
+ private double vesselMarginOverVariableCostsPerStrategy(Strategy str,
+ Date date) throws TopiaException {
+ double vesselMarginOverVariableCostsPerStrategyPerVessel = vesselMarginOverVariableCostsPerStrategyPerVessel(
+ str, date);
double proportionSetOfVessels = str.getProportionSetOfVessels();
double numberOfVessels = str.getSetOfVessels().getNumberOfVessels();
- return vesselMarginOverVariableCostsPerStrategyPerVessel * (proportionSetOfVessels * numberOfVessels);
+ return vesselMarginOverVariableCostsPerStrategyPerVessel
+ * (proportionSetOfVessels * numberOfVessels);
}
-
///////////////////////////////////////////////////////////////////////////
//
// Methode non utilis�e directement dans GravityModel, mais dans les rules
//
///////////////////////////////////////////////////////////////////////////
- public double valuePerUnitFishingEffort(Strategy str, Metier metier, Date date) throws TopiaException{
- List<Population> pops = siMatrix.getPopulations(date);
+ public double valuePerUnitFishingEffort(Strategy str, Metier metier,
+ Date date) throws TopiaException {
+ List<Population> pops = siMatrix.getPopulations(date);
- double result = 0;
+ double result = 0;
- for(Population pop : pops){
+ for (Population pop : pops) {
List<PopulationGroup> groups = pop.getPopulationGroup();
Collection<Zone> zones = pop.getPopulationZone();
- for(PopulationGroup group : groups){
+ for (PopulationGroup group : groups) {
double price = group.getPrice();
- for(Zone zone : zones){
- double catchValue = getCatchWeightPerStrMetPerZonePop(str, metier, group, zone, date);
- double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ for (Zone zone : zones) {
+ double catchValue = getCatchWeightPerStrMetPerZonePop(str,
+ metier, group, zone, date);
+ double discards = getDiscardsWeightPerStrMet(str, metier,
+ group, zone, date);
result += price * (catchValue - discards);
}
}
@@ -1258,7 +1389,7 @@
double effort = getEffortPerStrategyMet(str, metier, date);
- if(effort == 0){
+ if (effort == 0) {
result = 0;
} else {
result = result / effort;
@@ -1274,28 +1405,32 @@
* @return
*/
public double getEffortPerStrategyMet(Strategy str, Metier metier, Date date) {
- MatrixND mat = resultManager.getMatrix(date, ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
+ MatrixND mat = resultManager.getMatrix(date,
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
double result = 0;
- if(mat != null){
+ if (mat != null) {
result = mat.getValue(str, metier);
}
return result;
}
- public double landingPerUnitFishingEffort(Strategy str, Metier metier, Date date) throws TopiaException{
+ public double landingPerUnitFishingEffort(Strategy str, Metier metier,
+ Date date) throws TopiaException {
List<Population> pops = siMatrix.getPopulations(date);
double effort = getEffortPerStrategyMet(str, metier, date);
double result = 0;
- if(effort != 0){ // s'il n'y a pas d'effort on retournera 0
- for(Population pop : pops){
+ if (effort != 0) { // s'il n'y a pas d'effort on retournera 0
+ for (Population pop : pops) {
List<PopulationGroup> groups = pop.getPopulationGroup();
Collection<Zone> zones = pop.getPopulationZone();
- for(PopulationGroup group : groups){
- for(Zone zone : zones){
- double catchValue = getCatchWeightPerStrMetPerZonePop(str, metier, group, zone, date);
- double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date);
+ for (PopulationGroup group : groups) {
+ for (Zone zone : zones) {
+ double catchValue = getCatchWeightPerStrMetPerZonePop(
+ str, metier, group, zone, date);
+ double discards = getDiscardsWeightPerStrMet(str,
+ metier, group, zone, date);
result += catchValue - discards;
}
}
@@ -1307,5 +1442,3 @@
}
}
-
-
Modified: trunk/simulators/DefaultSimulator.java
===================================================================
--- trunk/simulators/DefaultSimulator.java 2009-04-28 13:31:17 UTC (rev 124)
+++ trunk/simulators/DefaultSimulator.java 2009-04-28 13:43:11 UTC (rev 125)
@@ -34,7 +34,6 @@
import static org.codelutin.i18n.I18n._;
import static org.codelutin.i18n.I18n.n_;
-import java.util.Collection;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -52,8 +51,6 @@
import fr.ifremer.isisfish.entities.Metier;
import fr.ifremer.isisfish.entities.Population;
import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
-import fr.ifremer.isisfish.entities.Strategy;
-import fr.ifremer.isisfish.entities.Zone;
import fr.ifremer.isisfish.rule.Rule;
import fr.ifremer.isisfish.simulator.MetierMonitor;
import fr.ifremer.isisfish.simulator.PopulationMonitor;
@@ -68,11 +65,11 @@
/**
* @author poussin
- *
+ *
*/
public class DefaultSimulator implements Simulator {
-
+
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(DefaultSimulator.class);
@@ -81,31 +78,32 @@
*/
public void simulate(SimulationContext context) throws Exception {
- SimulationParameter param = context.getSimulationStorage().getParameter();
+ SimulationParameter param = context.getSimulationStorage()
+ .getParameter();
SimulationControl control = context.getSimulationControl();
int lastYear = param.getNumberOfYear();
int lastDate = lastYear * Month.NUMBER_OF_MONTH;
Date date = control.getDate();
-
+
ResultManager resManager = context.getResultManager();
TopiaContext db = context.getDB();
-
+
SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
GravityModel gravityModel = new GravityModel(context, siMatrix);
-
+
PopulationMonitor populationMonitor = context.getPopulationMonitor();
MetierMonitor metierMonitor = context.getMetierMonitor();
RuleMonitor ruleMonitor = context.getRuleMonitor();
-
+
List<Population> allpops = siMatrix.getPopulations(date);
populationMonitor.init(allpops);
-
+
for (Population pop : allpops) {
MatrixND N = param.getNumberOf(pop);
N.setName(ResultName.MATRIX_ABUNDANCE);
populationMonitor.setN(pop, N);
}
-
+
//
// Rule initialisation
//
@@ -113,14 +111,16 @@
control.setText("Rules initialisation:" + rules);
for (Rule rule : rules) {
rule.init(context);
- log.info("Rule " +rule.getClass().getSimpleName()+ " initialized");
+ log
+ .info("Rule " + rule.getClass().getSimpleName()
+ + " initialized");
}
-
+
//
// Commit all change done un init rules methods.
//
context.getDB().commitTransaction();
-
+
//
// Simulation loop
//
@@ -131,14 +131,14 @@
if (control.isStopSimulationRequest()) {
break;
}
-
+
control.setDate(date);
control.setProgress(date.getDate());
control.setText(_("begin step " + date));
-
+
// raz des metiers interdits et des licences
metierMonitor.clear();
-
+
if (date.getMonth().equals(Month.JANUARY)) {
populationMonitor.clearCatch();
}
@@ -147,17 +147,18 @@
if (siMatrix.getStrategies(date).size() > 0) {
if (resManager.isEnabled(ResultName.MATRIX_NO_ACTIVITY)) {
MatrixND mat = metierMonitor.getOrCreateNoActivity(date,
- ResultName.MATRIX_NO_ACTIVITY,
- siMatrix.getStrategies(date),
- siMatrix.getMetiers(date));
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ .getStrategies(date), siMatrix
+ .getMetiers(date));
resManager.addResult(date, mat);
}
}
-
+
//
// Rule condition evaluation
//
- control.setText("Evalute Rules conditions ("+rules.size()+" rules)");
+ control.setText("Evalute Rules conditions (" + rules.size()
+ + " rules)");
for (Rule rule : rules) {
for (Metier metier : siMatrix.getMetiers(date)) {
boolean active = false;
@@ -165,30 +166,34 @@
active = rule.condition(context, date, metier);
} catch (Exception eee) {
if (log.isWarnEnabled()) {
- log.warn("Can't evaluate rule condition for: " + rule, eee);
+ log.warn("Can't evaluate rule condition for: "
+ + rule, eee);
}
}
- ruleMonitor.setEvaluationCondition(date, rule, metier, active);
+ ruleMonitor.setEvaluationCondition(date, rule, metier,
+ active);
if (active) {
- log.info("Activate rule: " + rule.getClass().getSimpleName());
+ log.info("Activate rule: "
+ + rule.getClass().getSimpleName());
resManager.addActiveRule(date, rule);
}
}
}
-
+
//
// Rule pre action
//
control.setText("Do pre action Rules");
for (Rule rule : rules) {
for (Metier metier : siMatrix.getMetiers(date)) {
- boolean condition = ruleMonitor.getEvalutionCondition(date, rule, metier);
+ boolean condition = ruleMonitor.getEvalutionCondition(date,
+ rule, metier);
if (condition) {
rule.preAction(context, date, metier);
}
}
}
-
+
//
// Keep modification's information done in rule
//
@@ -196,7 +201,7 @@
MatrixND metierZone = siMatrix.getMetierZone(date);
resManager.addResult(date, metierZone);
}
-
+
//
// Simulate one step for all pop
//
@@ -204,40 +209,45 @@
for (Population pop : siMatrix.getPopulations(date)) {
computeMonth(context, siMatrix, date, pop);
}
-
+
//
// Add some result not population dependante
//
-
+
// only if there are one or more strategy
if (siMatrix.getStrategies(date).size() > 0) {
control.setText("Add some results");
- if (resManager.isEnabled(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET)) {
- MatrixND effortPerStrategyMet = siMatrix.matrixEffortPerStrategyMet(date);
+ if (resManager
+ .isEnabled(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET)) {
+ MatrixND effortPerStrategyMet = siMatrix
+ .matrixEffortPerStrategyMet(date);
resManager.addResult(date, effortPerStrategyMet);
}
-
- if (resManager.isEnabled(ResultName.MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET)) {
- MatrixND stdTravelEffortPerStrategyMet = siMatrix.matrixEffortPerStrategyMet(date);
+
+ if (resManager
+ .isEnabled(ResultName.MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET)) {
+ MatrixND stdTravelEffortPerStrategyMet = siMatrix
+ .matrixEffortPerStrategyMet(date);
resManager.addResult(date, stdTravelEffortPerStrategyMet);
}
-
+
if (resManager.isEnabled(ResultName.MATRIX_EFFORT_PER_ZONE_POP)) {
- MatrixND effortPerZonePop = siMatrix.matrixEffortPerStrategyMet(date);
+ MatrixND effortPerZonePop = siMatrix
+ .matrixEffortPerStrategyMet(date);
resManager.addResult(date, effortPerZonePop);
- }
+ }
-
//
// Add economics results
//
- if (!"false".equalsIgnoreCase(param.getTagValue().get("ecoResult"))) {
+ if (!"false".equalsIgnoreCase(param.getTagValue().get(
+ "ecoResult"))) {
control.setText("Add economics results");
saveGravityModel(date, resManager, gravityModel);
}
}
-
+
//
// Add economics results
//
@@ -248,8 +258,6 @@
}
}
-
-
//
// Rule post action
//
@@ -274,18 +282,25 @@
MatrixND discard = populationMonitor.getDiscard(date, pop);
if (discard != null || date.getDate() == 0) { // force discard for the first month to have discard in result
if (discard == null) {
- discard = MatrixFactory.getInstance().create(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP,
- new List[]{siMatrix.getStrategies(date),
- siMatrix.getMetiers(date),
- pop.getPopulationGroup(),
- pop.getPopulationZone()},
- new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
+ discard = MatrixFactory.getInstance().create(
+ ResultName.MATRIX_DISCARDS_PER_STR_MET,
+ new List[] { siMatrix.getStrategies(date),
+ siMatrix.getMetiers(date),
+ pop.getPopulationGroup(),
+ pop.getPopulationZone() },
+ new String[] { n_("Strategies"),
+ n_("Metiers"), n_("Groups"),
+ n_("Zones") });
}
resManager.addResult(date, pop, discard);
- if (resManager.isEnabled(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP)) {
- MatrixND discardWeightPerStrategyMet = siMatrix.matrixDiscardWeightPerStrategyMetPerZonePop(pop, date, discard);
- resManager.addResult(date, pop, discardWeightPerStrategyMet);
+ if (resManager
+ .isEnabled(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET)) {
+ MatrixND discardWeightPerStrategyMet = siMatrix
+ .matrixDiscardWeightPerStrategyMetPerZonePop(
+ pop, date, discard);
+ resManager.addResult(date, pop,
+ discardWeightPerStrategyMet);
}
}
@@ -294,7 +309,8 @@
// add landing result
//
if (resManager.isEnabled(ResultName.MATRIX_LANDING_PER_MET)) {
- MatrixND landing = MatrixFactory.getInstance().create(populationMonitor.getCatch(pop));
+ MatrixND landing = MatrixFactory.getInstance().create(
+ populationMonitor.getCatch(pop));
if (discard != null) {
landing = landing.minus(discard);
}
@@ -309,14 +325,14 @@
//
control.setText("Rollback rules changes");
db.rollbackTransaction();
-
+
//
// commit result
//
control.setText("Commit results");
TopiaContext tx = context.getDbResult();
tx.commitTransaction();
-
+
//
// Go next step
//
@@ -330,45 +346,50 @@
return result;
}
- protected void computeMonth(SimulationContext context, SiMatrix siMatrix, Date date, Population pop) throws IsisFishException, TopiaException {
+ protected void computeMonth(SimulationContext context, SiMatrix siMatrix,
+ Date date, Population pop) throws IsisFishException, TopiaException {
// to add result
- ResultStorage resManager = context.getSimulationStorage().getResultStorage();
+ ResultStorage resManager = context.getSimulationStorage()
+ .getResultStorage();
PopulationMonitor popMon = context.getPopulationMonitor();
MatrixND N = popMon.getN(pop);
-
+
if (log.isInfoEnabled()) {
- log.info("====================== begin "+ date + " - " + pop +" =========================== " + System.currentTimeMillis());
+ log.info("====================== begin " + date + " - " + pop
+ + " =========================== "
+ + System.currentTimeMillis());
log.info("N: " + N);
}
-
+
// add N and biomass result now, before computation
// N is reassigned during computation
- resManager.addResult(date, pop, N);
+ resManager.addResult(date, pop, N);
if (resManager.isEnabled(ResultName.MATRIX_BIOMASS)) {
MatrixND biomass = siMatrix.matrixBiomass(N, pop, date);
resManager.addResult(date, pop, biomass);
}
-
+
Month month = date.getMonth();
PopulationSeasonInfo info = pop.getPopulationSeasonInfo(month);
-
+
// group change
MatrixND CA = null;
if (date.getDate() == 0) {
- CA = MatrixFactory.getInstance().matrixId(pop.sizePopulationGroup()*pop.sizePopulationZone());
+ CA = MatrixFactory.getInstance().matrixId(
+ pop.sizePopulationGroup() * pop.sizePopulationZone());
} else {
CA = info.getGroupChangeMatrix(month);
}
log.debug("CA: " + CA);
-
+
//migration
- MatrixND M = info.getMigrationMatrix(month, N);
+ MatrixND M = info.getMigrationMatrix(month, N);
log.debug("M: " + M);
//emigration
- MatrixND EM = info.getEmigrationMatrix(month, N);
+ MatrixND EM = info.getEmigrationMatrix(month, N);
log.debug("EM: " + EM);
//immigration
MatrixND IM = info.getImmigrationMatrix(month, N).transpose();
@@ -382,9 +403,9 @@
MatrixND tmp1 = M.minus(EM);
MatrixND tmp2 = tmp0.mult(tmp1);
MatrixND tmp3 = tmp2.add(IM);
-
+
log.debug("N1D after mig: " + tmp3);
-
+
// On reconvertie en une matrice Semantique
N = pop.split2D(tmp3);
@@ -393,32 +414,32 @@
//Recrutement
MatrixND R = info.getReproductionMatrix(month, N);
log.debug("R: " + R);
-
+
// ajout de la matrice R dans le suivi de la pop comme etant
// la reproduction pour le mois courant.
popMon.setReproduction(date, pop, R);
-
+
// recrutement
MatrixND recruitment = popMon.getRecruitment(date, pop);
log.debug("recruitment: " + recruitment);
-
+
// mortalite de la reproduction
popMon.applyReproductionMortality(pop);
-
+
N = N.add(recruitment);
log.debug("N after recru: " + N);
- if (resManager.isEnabled(ResultName.MATRIX_ABONDANCE_BEGIN_MONTH)) {
- MatrixND abondanceBM = siMatrix.matrixAbondanceBeginMonth(N, pop, date);
+ if (resManager.isEnabled(ResultName.MATRIX_ABUNDANCE)) {
+ MatrixND abondanceBM = siMatrix.matrixAbondanceBeginMonth(N, pop,
+ date);
resManager.addResult(date, pop, abondanceBM);
}
- if (resManager.isEnabled(ResultName.MATRIX_BIOMASS_BEGIN_MONTH)) {
+ if (resManager.isEnabled(ResultName.MATRIX_BIOMASS)) {
MatrixND biomassBM = siMatrix.matrixBiomassBeginMonth(N, pop, date);
resManager.addResult(date, pop, biomassBM);
}
-
MatrixND abundance = N;
// compute fishing matrix only if there are one or more strategy
if (siMatrix.getStrategies(date).size() > 0) {
@@ -429,153 +450,193 @@
if (isEffortByCell(context)) {
abundance = siMatrix.matrixAbundance(N, pop, date);
- catchPerStrategyMetPerZonePop =
- siMatrix.matrixCatchPerStrategyMetPerZonePop(N, pop, date);
+ catchPerStrategyMetPerZonePop = siMatrix
+ .matrixCatchPerStrategyMetPerZonePop(N, pop, date);
} else { // en zone
- MatrixND matrixFishingMortality = siMatrix.matrixFishingMortality(date, pop);
+ MatrixND matrixFishingMortality = siMatrix
+ .matrixFishingMortality(date, pop);
resManager.addResult(date, pop, matrixFishingMortality);
-
- abundance = siMatrix.matrixAbundance(N, pop, date, matrixFishingMortality);
+ abundance = siMatrix.matrixAbundance(N, pop, date,
+ matrixFishingMortality);
+
// this matrix is necessary for matrixCatchPerStrategyMet
- MatrixND catchRatePerStrategyMet = siMatrix.matrixCatchRatePerStrategyMetPerZone(pop, date, matrixFishingMortality);
+ MatrixND catchRatePerStrategyMet = siMatrix
+ .matrixCatchRatePerStrategyMetPerZone(pop, date,
+ matrixFishingMortality);
resManager.addResult(date, pop, catchRatePerStrategyMet);
- catchPerStrategyMetPerZonePop =
- siMatrix.matrixCatchPerStrategyMetPerZone(N, pop, date, catchRatePerStrategyMet);
+ catchPerStrategyMetPerZonePop = siMatrix
+ .matrixCatchPerStrategyMetPerZone(N, pop, date,
+ catchRatePerStrategyMet);
}
-
+
popMon.holdCatch(pop, catchPerStrategyMetPerZonePop);
resManager.addResult(date, pop, catchPerStrategyMetPerZonePop);
-
- if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP)) {
- MatrixND catchWeightPerStrategyMet =
- siMatrix.matrixCatchWeightPerStrategyMetPerZonePop(date, pop,
- catchPerStrategyMetPerZonePop);
+
+ if (resManager
+ .isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET)) {
+ MatrixND catchWeightPerStrategyMet = siMatrix
+ .matrixCatchWeightPerStrategyMetPerZonePop(date, pop,
+ catchPerStrategyMetPerZonePop);
resManager.addResult(date, pop, catchWeightPerStrategyMet);
}
if (isEffortByCell(context)) {
- MatrixND catchPerStrategyMetPerZoneMet =
- siMatrix.matrixCatchPerStrategyMetPerZoneMet(N, pop, date);
+ MatrixND catchPerStrategyMetPerZoneMet = siMatrix
+ .matrixCatchPerStrategyMetPerZoneMet(N, pop, date);
resManager.addResult(date, pop, catchPerStrategyMetPerZoneMet);
- if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET)) {
- MatrixND catchWeightPerStrategyMet =
- siMatrix.matrixCatchWeightPerStrategyMetPerZoneMet(date, pop,
- catchPerStrategyMetPerZoneMet);
+ if (resManager
+ .isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET)) {
+ MatrixND catchWeightPerStrategyMet = siMatrix
+ .matrixCatchWeightPerStrategyMetPerZoneMet(date,
+ pop, catchPerStrategyMetPerZoneMet);
resManager.addResult(date, pop, catchWeightPerStrategyMet);
}
}
-
-
+
} else { // no strategies
// compute only if fishing mortality =0 to apply Natural Mortality
abundance = siMatrix.matrixAbundanceSsF(N, pop, date);
}
log.debug("abundance: " + abundance);
-
+
// Keep new N
popMon.setN(pop, abundance);
- log.debug("====================== end " + date + " - " + pop +" ===========================");
-
+ log.debug("====================== end " + date + " - " + pop
+ + " ===========================");
+
}
-
+
/**
* @param date
* @param resManager
- * @throws IsisFishException
- * @throws TopiaException
+ * @throws IsisFishException
+ * @throws TopiaException
*/
- private void saveGravityModel(Date date, ResultManager resManager, GravityModel gravityModel) throws IsisFishException, TopiaException {
- if (resManager.isEnabled(ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixFishingTimePerMonthPerVessel(date);
+ private void saveGravityModel(Date date, ResultManager resManager,
+ GravityModel gravityModel) throws IsisFishException, TopiaException {
+ if (resManager
+ .isEnabled(ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixFishingTimePerMonthPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
resManager.addResult(date, mat);
- }
+ }
if (resManager.isEnabled(ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixCostsOfFishingPerVessel(date);
+ MatrixND mat = gravityModel.matrixCostsOfFishingPerVessel(date);
resManager.addResult(date, mat);
- }
+ }
if (resManager.isEnabled(ResultName.MATRIX_FUEL_COSTS_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
+ MatrixND mat = gravityModel.matrixFuelCostsOfTravelPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixRepairAndMaintenanceGearCostsPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixRepairAndMaintenanceGearCostsPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixOtherRunningCostsPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel.matrixOtherRunningCostsPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixSharedNotFixedCostsPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixSharedNotFixedCostsPerVessel(date);
resManager.addResult(date, mat);
- }
-// if (resManager.isEnabled(ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET)) {
-// MatrixND mat = gravityModel.matrixSharedFixedCostsPerVesselPerMet(date);
-// resManager.addResult(date, mat);
-// }
- if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET)) {
- MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(date);
+ }
+ // if (resManager.isEnabled(ResultName.MATRIX_SHARED_FIXED_COSTS_PER_VESSEL_PER_MET)) {
+ // MatrixND mat = gravityModel.matrixSharedFixedCostsPerVesselPerMet(date);
+ // resManager.addResult(date, mat);
+ // }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel
+ .matrixGrossValueOfLandingsPerSpeciesPerStrategyMet(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
- MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerStrategyMet(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel
+ .matrixGrossValueOfLandingsPerStrategyMet(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixGrossValueOfLandingsPerStrategyMetPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixGrossValueOfLandingsPerStrategyMetPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
- MatrixND mat = gravityModel.matrixNetValueOfLandingsPerStrategyMet(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET)) {
+ MatrixND mat = gravityModel
+ .matrixNetValueOfLandingsPerStrategyMet(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixNetValueOfLandingsPerStrategyMetPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixNetValueOfLandingsPerStrategyMetPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixNetRenevueToSharePerStrategyMetPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixNetRenevueToSharePerStrategyMetPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixCrewSharePerStrategyMetPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixCrewSharePerStrategyMetPerVessel(date);
resManager.addResult(date, mat);
}
- if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(date);
+ if (resManager
+ .isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel(date);
resManager.addResult(date, mat);
}
- if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(date);
+ if (resManager
+ .isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixOwnerMarginOverVariableCostsPerStrategyPerVessel(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
- MatrixND mat = gravityModel.matrixOwnerMarginOverVariableCostsPerStrategy(date);
+ }
+ if (resManager
+ .isEnabled(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
+ MatrixND mat = gravityModel
+ .matrixOwnerMarginOverVariableCostsPerStrategy(date);
resManager.addResult(date, mat);
- }
- if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
- MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategyPerVessel(date);
- resManager.addResult(date, mat);
}
- if (resManager.isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
- MatrixND mat = gravityModel.matrixVesselMarginOverVariableCostsPerStrategy(date);
+ if (resManager
+ .isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL)) {
+ MatrixND mat = gravityModel
+ .matrixVesselMarginOverVariableCostsPerStrategyPerVessel(date);
resManager.addResult(date, mat);
}
+ if (resManager
+ .isEnabled(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY)) {
+ MatrixND mat = gravityModel
+ .matrixVesselMarginOverVariableCostsPerStrategy(date);
+ resManager.addResult(date, mat);
+ }
}
}
-
-
1
0
Author: jcouteau
Date: 2009-04-28 13:31:17 +0000 (Tue, 28 Apr 2009)
New Revision: 124
Modified:
trunk/exports/RejetsNombre.java
trunk/exports/RejetsPoids.java
Log:
Adaptation aux scripts de St?\195?\169phanie
Modified: trunk/exports/RejetsNombre.java
===================================================================
--- trunk/exports/RejetsNombre.java 2009-04-28 13:29:04 UTC (rev 123)
+++ trunk/exports/RejetsNombre.java 2009-04-28 13:31:17 UTC (rev 124)
@@ -21,25 +21,22 @@
/**
* RejetsNombre.java
- *
+ *
* Created: 23 novembre 2006
- *
+ *
* @author anonymous <anonymous(a)labs.libre-entreprise.org>
* @version $Revision: 1.4 $
- *
- * Last update: $Date: 2007-05-24 09:30:07 $
- * by : $Author: bpoussin $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $ by : $Author: bpoussin $
*/
- @Doc(value="do the doc of class RejetsNombre")
+@Doc(value = "do the doc of class RejetsNombre")
public class RejetsNombre implements Export {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(RejetsNombre.class);
- protected String [] necessaryResult = {
- ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP
- };
-
+ protected String[] necessaryResult = { ResultName.MATRIX_DISCARDS_PER_STR_MET };
+
public String[] getNecessaryResult() {
return this.necessaryResult;
}
@@ -47,74 +44,79 @@
public String getExportFilename() {
return "RejetsNombre";
}
-
+
public String getExtensionFilename() {
return ".csv";
}
-
+
public String getDescription() {
return _("Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre");
}
- public void export(SimulationStorage simulation, Writer out) throws Exception {
- Date lastDate = simulation.getResultStorage().getLastDate();
-
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
for (Population pop : simulation.getParameter().getPopulations()) {
- for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
- MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP);
+ for (Date date = new Date(0); !date.after(lastDate); date = date
+ .next()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date,
+ pop, ResultName.MATRIX_DISCARDS_PER_STR_MET);
if (mat != null) { // can be null if simulation is stopped before last year simulation
mat = mat.sumOverDim(0); //sum on strategy
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- Object [] sems = i.getSemanticsCoordinates();
- Metier metier = (Metier)sems[1];
- PopulationGroup group = (PopulationGroup)sems[2];
- Zone zone = (Zone)sems[3];
-
+ Object[] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier) sems[1];
+ PopulationGroup group = (PopulationGroup) sems[2];
+ Zone zone = (Zone) sems[3];
+
double val = i.getValue();
- out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ out.write(pop.getName() + ";" + metier.getName() + ";"
+ + group.getId() + ";" + zone.getName() + ";"
+ + date.getDate() + ";" + val + "\n");
}
}
}
}
-/*
-var Parametre=sim.getParametre();
-var Populations=Parametre.getPopulations();
-var PDate=Packages.fr.ifremer.nodb.Date;
+ /*
+ var Parametre=sim.getParametre();
+ var Populations=Parametre.getPopulations();
+ var PDate=Packages.fr.ifremer.nodb.Date;
-var capture=0.0;
-var result="";
-writeln("debut de export rejets nombre");
-var dateexport=new Packages.java.util.Date();
-var formatteur= new Packages.java.text.SimpleDateFormat();
-writeln("heure de debut: "+formatteur.format(dateexport));
-var finsimu=resultats.getLastDate().getDate();
+ var capture=0.0;
+ var result="";
+ writeln("debut de export rejets nombre");
+ var dateexport=new Packages.java.util.Date();
+ var formatteur= new Packages.java.text.SimpleDateFormat();
+ writeln("heure de debut: "+formatteur.format(dateexport));
+ var finsimu=resultats.getLastDate().getDate();
-for (var ipop=Populations.iterator();ipop.hasNext();){
- var pop=ipop.next();
- for (var idate=0;idate<=finsimu;idate++){
- var date=new PDate(idate);
- var matrice=resultats.getMatrix(date,pop ,"Rejet par metier");
- if (matrice==null){
- matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
- matrice.mults(0);
- }
- var temp=matrice.sumOverDim(0);
- writeln("on a la matrice");
- for (var iiterateur=temp.iterator();iiterateur.next();){
- var coordonnees=iiterateur.getSemanticsCoordinates();
- var metier=coordonnees[1];
- var c=coordonnees[2];
- var z=coordonnees[3];
- capture=iiterateur.getValue();
- result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
- }
- }
-}
+ for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date,pop ,"Rejet par metier");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
+ matrice.mults(0);
+ }
+ var temp=matrice.sumOverDim(0);
+ writeln("on a la matrice");
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+ }
-writeln("fin de RejetsNombre");
-return ""+result;
-*/
+ writeln("fin de RejetsNombre");
+ return ""+result;
+ */
}
}
Modified: trunk/exports/RejetsPoids.java
===================================================================
--- trunk/exports/RejetsPoids.java 2009-04-28 13:29:04 UTC (rev 123)
+++ trunk/exports/RejetsPoids.java 2009-04-28 13:31:17 UTC (rev 124)
@@ -21,26 +21,24 @@
/**
* RejetsPoids.java
- *
+ *
* Created: 23 novembre 2006
- *
+ *
* @author anonymous <anonymous(a)labs.libre-entreprise.org>
* @version $Revision: 1.4 $
- *
- * Last update: $Date: 2007-05-24 09:30:07 $
- * by : $Author: bpoussin $
+ *
+ * Last update: $Date: 2007-05-24 09:30:07 $ by : $Author: bpoussin $
*/
- @Doc(value="do the doc of class RejetsPoids")
+@Doc(value = "do the doc of class RejetsPoids")
public class RejetsPoids implements Export {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(RejetsPoids.class);
- protected String [] necessaryResult = {
- ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP
-
+ protected String[] necessaryResult = { ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET
+
};
-
+
public String[] getNecessaryResult() {
return this.necessaryResult;
}
@@ -48,73 +46,78 @@
public String getExportFilename() {
return "RejetsPoids";
}
-
+
public String getExtensionFilename() {
return ".csv";
}
-
+
public String getDescription() {
return _("Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre");
}
- public void export(SimulationStorage simulation, Writer out) throws Exception {
- Date lastDate = simulation.getResultStorage().getLastDate();
-
+ public void export(SimulationStorage simulation, Writer out)
+ throws Exception {
+ Date lastDate = simulation.getResultStorage().getLastDate();
+
for (Population pop : simulation.getParameter().getPopulations()) {
- for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
- MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP);
+ for (Date date = new Date(0); !date.after(lastDate); date = date
+ .next()) {
+ MatrixND mat = simulation.getResultStorage().getMatrix(date,
+ pop, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
if (mat != null) { // can be null if simulation is stopped before last year simulation
mat = mat.sumOverDim(0); //sum on strategy
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- Object [] sems = i.getSemanticsCoordinates();
- Metier metier = (Metier)sems[1];
- PopulationGroup group = (PopulationGroup)sems[2];
- Zone zone = (Zone)sems[3];
+ Object[] sems = i.getSemanticsCoordinates();
+ Metier metier = (Metier) sems[1];
+ PopulationGroup group = (PopulationGroup) sems[2];
+ Zone zone = (Zone) sems[3];
double val = i.getValue();
- out.write(pop.getName() +";"+ metier.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ date.getDate() +";"+ val +"\n");
+ out.write(pop.getName() + ";" + metier.getName() + ";"
+ + group.getId() + ";" + zone.getName() + ";"
+ + date.getDate() + ";" + val + "\n");
}
}
}
}
-/*
-var Parametre=sim.getParametre();
-var Populations=Parametre.getPopulations();
-var PDate=Packages.fr.ifremer.nodb.Date;
+ /*
+ var Parametre=sim.getParametre();
+ var Populations=Parametre.getPopulations();
+ var PDate=Packages.fr.ifremer.nodb.Date;
-var capture=0.0;
-var result="";
-writeln("debut de export rejets poids");
-var dateexport=new Packages.java.util.Date();
-var formatteur= new Packages.java.text.SimpleDateFormat();
-writeln("heure de debut: "+formatteur.format(dateexport));
-var finsimu=resultats.getLastDate().getDate();
+ var capture=0.0;
+ var result="";
+ writeln("debut de export rejets poids");
+ var dateexport=new Packages.java.util.Date();
+ var formatteur= new Packages.java.text.SimpleDateFormat();
+ writeln("heure de debut: "+formatteur.format(dateexport));
+ var finsimu=resultats.getLastDate().getDate();
-for (var ipop=Populations.iterator();ipop.hasNext();){
- var pop=ipop.next();
- for (var idate=0;idate<=finsimu;idate++){
- var date=new PDate(idate);
- var matrice=resultats.getMatrix(date, pop, "Rejet par metier");
- if (matrice==null){
- matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
- matrice.mults(0);
- }
- var temp=matrice.sumOverDim(0);
- for (var iiterateur=temp.iterator();iiterateur.next();){
- var coordonnees=iiterateur.getSemanticsCoordinates();
- var metier=coordonnees[1];
- var c=coordonnees[2];
- var z=coordonnees[3];
- capture=iiterateur.getValue()*c.getPoidsMoyen();
- result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
- }
- }
-}
+ for (var ipop=Populations.iterator();ipop.hasNext();){
+ var pop=ipop.next();
+ for (var idate=0;idate<=finsimu;idate++){
+ var date=new PDate(idate);
+ var matrice=resultats.getMatrix(date, pop, "Rejet par metier");
+ if (matrice==null){
+ matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),pop ,"Rejet par metier"));
+ matrice.mults(0);
+ }
+ var temp=matrice.sumOverDim(0);
+ for (var iiterateur=temp.iterator();iiterateur.next();){
+ var coordonnees=iiterateur.getSemanticsCoordinates();
+ var metier=coordonnees[1];
+ var c=coordonnees[2];
+ var z=coordonnees[3];
+ capture=iiterateur.getValue()*c.getPoidsMoyen();
+ result+=pop.getNom()+";"+metier.getNom()+";"+c.getId()+";"+z.getNom()+";"+idate+";"+capture+"\n";
+ }
+ }
+ }
-writeln("fin de RejetsPoids");
-return ""+result;
-*/
+ writeln("fin de RejetsPoids");
+ return ""+result;
+ */
}
}
1
0
Author: jcouteau
Date: 2009-04-28 13:29:04 +0000 (Tue, 28 Apr 2009)
New Revision: 123
Modified:
trunk/exports/CapturesNombre.java
trunk/exports/CapturesPoids.java
Log:
Adpatation aux scripts de St?\195?\169phanie
Modified: trunk/exports/CapturesNombre.java
===================================================================
--- trunk/exports/CapturesNombre.java 2009-04-28 13:25:06 UTC (rev 122)
+++ trunk/exports/CapturesNombre.java 2009-04-28 13:29:04 UTC (rev 123)
@@ -37,7 +37,7 @@
static private Log log = LogFactory.getLog(CapturesNombre.class);
protected String [] necessaryResult = {
- ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET
};
public String[] getNecessaryResult() {
@@ -62,7 +62,7 @@
for (Population pop : simulation.getParameter().getPopulations()) {
for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
MatrixND mat = simulation.getResultStorage().getMatrix(date, pop,
- ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
if (mat != null) { // can be null if simulation is stopped before last year simulation
mat = mat.sumOverDim(0); //sum on strategy
for (MatrixIterator i=mat.iterator(); i.hasNext();) {
Modified: trunk/exports/CapturesPoids.java
===================================================================
--- trunk/exports/CapturesPoids.java 2009-04-28 13:25:06 UTC (rev 122)
+++ trunk/exports/CapturesPoids.java 2009-04-28 13:29:04 UTC (rev 123)
@@ -37,7 +37,7 @@
static private Log log = LogFactory.getLog(CapturesPoids.class);
protected String [] necessaryResult = {
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET
};
public String[] getNecessaryResult() {
@@ -62,7 +62,7 @@
for (Population pop : simulation.getParameter().getPopulations()) {
for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
MatrixND mat = simulation.getResultStorage().getMatrix(date, pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
if (mat != null) { // can be null if simulation is stopped before last year simulation
mat = mat.sumOverDim(0); //sum on strategy
for (MatrixIterator i=mat.iterator(); i.hasNext();) {
1
0
Author: jcouteau
Date: 2009-04-28 13:25:06 +0000 (Tue, 28 Apr 2009)
New Revision: 122
Modified:
trunk/scripts/SiMatrix.java
Log:
Adaptation aux scripts de St?\195?\169phanie
Modified: trunk/scripts/SiMatrix.java
===================================================================
--- trunk/scripts/SiMatrix.java 2009-04-28 13:19:55 UTC (rev 121)
+++ trunk/scripts/SiMatrix.java 2009-04-28 13:25:06 UTC (rev 122)
@@ -246,7 +246,7 @@
List<PopulationGroup> groups = pop.getPopulationGroup();
MatrixND result = matrixCatchPerStrategyMetPerZoneMet.copy();
- result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET);
+ result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
for (PopulationGroup group : groups) {
MatrixND sub = result.getSubMatrix(2, group, 1);
@@ -271,7 +271,7 @@
Set<Cell> cellPops = new HashSet(matrixCatchPerStrategyMetPerCell.getSemantics(4));
MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET,
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET,
new List[]{strategies, metiers, groups, zones},
new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
@@ -316,7 +316,7 @@
// on somme sur les cellules
MatrixND result = matrixCatchPerStrategyMetPerCell.sumOverDim(4);
result = result.reduceDims(4);
- result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
+ result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
return result;
}
@@ -326,7 +326,7 @@
List<PopulationGroup> groups = pop.getPopulationGroup();
MatrixND result = matrixCatchPerStrategyMetPerZonePop.copy();
- result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
for (PopulationGroup group : groups) {
MatrixND sub = result.getSubMatrix(2, group, 1);
@@ -359,7 +359,7 @@
// on le passe en argument ce qui evite de le calculer 2 fois
// MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMet(pop, date);
MatrixND result = matrixCatchRatePerStrategyMet.copy();
- result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
+ result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET);
for(PopulationGroup group : groups) {
MatrixND sub = result.getSubMatrix(2, group, 1);
@@ -390,7 +390,7 @@
List<Zone> zones = pop.getPopulationZone();
MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP,
+ ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET,
new List[]{strategies, metiers, groups, zones},
new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")});
@@ -1624,7 +1624,7 @@
List<Zone> zones = N.getSemantics(1);
MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_BIOMASS_BEGIN_MONTH,
+ ResultName.MATRIX_BIOMASS,
new List[]{groups, zones},
new String[]{n_("Groups"), n_("Zones")});
@@ -1646,7 +1646,7 @@
List<Zone> zones = N.getSemantics(1);
MatrixND result = MatrixFactory.getInstance().create(
- ResultName.MATRIX_ABONDANCE_BEGIN_MONTH,
+ ResultName.MATRIX_ABUNDANCE,
new List[]{groups, zones},
new String[]{n_("Groups"), n_("Zones")});
@@ -1742,7 +1742,7 @@
List<PopulationGroup> groups = pop.getPopulationGroup();
MatrixND result = matrixDiscardPerStrategyMetPerZonePop.copy();
- result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP);
+ result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET);
for(PopulationGroup group : groups){
MatrixND sub = result.getSubMatrix(2, group, 1);
1
0
28 Apr '09
Author: jcouteau
Date: 2009-04-28 13:19:55 +0000 (Tue, 28 Apr 2009)
New Revision: 121
Added:
trunk/rules/GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD.java
Modified:
trunk/exports/SensitivityCapturesWeightReferenceY7.java
trunk/exports/SensitivityCapturesWeightRelativeReferenceY10.java
trunk/exports/SensitivityCapturesWeightRelativeY4.java
trunk/exports/SensitivityCapturesWeightY1.java
trunk/rules/GraviteCPUE.java
trunk/rules/TACpoids.java
trunk/scripts/ResultName.java
Log:
Commit des scripts modifi?\195?\169s par St?\195?\169phanie
adaptation des scripts existants
Refactoring des scripts de st?\195?\169phanie (rajouts des @Doc sur les param?\195?\168tres, plus de system.out.println, organize imports et format du code)
Modified: trunk/exports/SensitivityCapturesWeightReferenceY7.java
===================================================================
--- trunk/exports/SensitivityCapturesWeightReferenceY7.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/exports/SensitivityCapturesWeightReferenceY7.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -24,7 +24,7 @@
static private Log log = LogFactory
.getLog(SensitivityCapturesWeightReferenceY7.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET };
@Doc("Population")
public Population param_pop;
@@ -53,7 +53,7 @@
.getMatrix(
new Date(lastDate.getDate() - i),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
capturesWeight += matlastdate.sumAll();
//Get the reference captures Weight of each month of the last year
@@ -62,7 +62,7 @@
MatrixND matlastdatereference = referenceResultStorage
.getMatrix(
new Date(lastDate.getDate() - i),
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET
+ " " + pop, tx);
capturesWeightReference += matlastdatereference.sumAll();
tx.commitTransaction();
Modified: trunk/exports/SensitivityCapturesWeightRelativeReferenceY10.java
===================================================================
--- trunk/exports/SensitivityCapturesWeightRelativeReferenceY10.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/exports/SensitivityCapturesWeightRelativeReferenceY10.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -25,7 +25,7 @@
static private Log log = LogFactory
.getLog(SensitivityCapturesWeightRelativeReferenceY10.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET };
@Doc("Population")
public Population param_pop;
@@ -56,7 +56,7 @@
.getMatrix(
new Date(lastDate.getDate() - i),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
capturesWeight += matlastdate.sumAll();
//Get the captures Weight of each month of the first year
@@ -64,7 +64,7 @@
.getMatrix(
new Date(i),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
capturesWeightfirst += matfirstdate.sumAll();
//Get the reference captures Weight of each month of the last year
@@ -75,7 +75,7 @@
MatrixND matlastdatereference = referenceResultStorage
.getMatrix(
new Date(lastDate.getDate() - i),
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET
+ " " + pop, tx);
capturesWeightreference += matlastdatereference.sumAll();
@@ -83,7 +83,7 @@
MatrixND matfirstdatereference = referenceResultStorage
.getMatrix(
new Date(i),
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET
+ " " + pop, tx);
capturesWeightfirstreference += matfirstdatereference
.sumAll();
Modified: trunk/exports/SensitivityCapturesWeightRelativeY4.java
===================================================================
--- trunk/exports/SensitivityCapturesWeightRelativeY4.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/exports/SensitivityCapturesWeightRelativeY4.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -23,7 +23,7 @@
static private Log log = LogFactory
.getLog(SensitivityCapturesWeightRelativeY4.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET };
@Doc("Population")
public Population param_pop;
@@ -45,7 +45,7 @@
.getMatrix(
new Date(lastDate.getDate() - i),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
capturesWeight += matlastdate.sumAll();
//Get the captures Weight of each month of the first year
@@ -53,7 +53,7 @@
.getMatrix(
new Date(i),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
capturesWeightfirst += matfirstdate.sumAll();
}
Modified: trunk/exports/SensitivityCapturesWeightY1.java
===================================================================
--- trunk/exports/SensitivityCapturesWeightY1.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/exports/SensitivityCapturesWeightY1.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -23,7 +23,7 @@
static private Log log = LogFactory
.getLog(SensitivityCapturesWeightY1.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET };
@Doc("Population")
public Population param_pop;
@@ -44,7 +44,7 @@
.getMatrix(
new Date(lastDate.getDate() - i),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
capturesWeight += matlastdate.sumAll();
}
Modified: trunk/rules/GraviteCPUE.java
===================================================================
--- trunk/rules/GraviteCPUE.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/rules/GraviteCPUE.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -57,7 +57,7 @@
// example:
// ResultName.MATRIX_BIOMASS,
// ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP,
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET,
ResultName.MATRIX_EFFORT_PER_STRATEGY_MET,
};
@@ -186,7 +186,7 @@
MatrixND temp = resultmanager.getMatrix(
date.previousYear(),
pop,
- ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP);
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET);
// on somme sur les zones
temp=temp.sumOverDim(3);
// on somme sur les groupes
Added: trunk/rules/GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD.java
===================================================================
--- trunk/rules/GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD.java (rev 0)
+++ trunk/rules/GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -0,0 +1,542 @@
+package rules;
+
+import static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.MapFunction;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.util.FileUtil;
+
+import scripts.ResultName;
+import scripts.SiMatrix;
+import fr.ifremer.isisfish.datastore.ResultStorage;
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Population;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.rule.AbstractRule;
+import fr.ifremer.isisfish.simulator.SimulationContext;
+import fr.ifremer.isisfish.types.Date;
+import fr.ifremer.isisfish.types.Month;
+
+/**
+ * GraviteVPUE1Anchois.java
+ *
+ * Created: 26 aout 2008
+ *
+ * @author anonymous <anonymous(a)labs.libre-entreprise.org>
+ * @version $Revision: 1.2 $
+ *
+ * Last update: $Date: 2008-10-23 08:59:38 $ by : $Author: Stephanie $
+ */
+public class GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD extends
+ AbstractRule {
+ /** to use log facility, just put in your code: log.info("..."); */
+ static private Log log = LogFactory
+ .getLog(GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD.class);
+
+ public String param_nomfichier_coeffOthers0 = "Inputs_Langoustine/CoeffOthers_Intercept_Langoustine/CoeffOthersNephrops.csv";
+ public String param_nomfichier_coeffOthers1 = "Inputs_Langoustine/CoeffOthers_Intercept_Langoustine/CoeffOthersHake.csv";
+ public String param_nomfichier_coeffOthers2 = "Inputs_Langoustine/CoeffOthers_Intercept_Langoustine/CoeffOthersBenthic.csv";
+ public boolean param_gravite = false;
+ // doit �tre � vrai si gravite s'applique sinon la methode calcul uniquement les grossvalue otherspecies
+
+ static final protected String BETA_O = "BetaOthers";
+ static final protected String ALPHA_O = "AlphaOthers";
+
+ protected File CoeffOthers0;
+ protected File CoeffOthers1;
+ protected File CoeffOthers2;
+
+ protected MatrixND matrixCoeffOthers;
+
+ protected List<Metier> metiers;
+ // interdit de faire des set sur les strategies de la map, il faut recuperer les strategies de la date courante
+ protected Map<String, Strategy> mesStrategies;
+
+ /** stocke la somme des prop initiales [str x month] */
+ private MatrixND SommePropInitial = null;
+ /**
+ * stocke par strat*met, la derni�re attractivite pour chaque mois [str x
+ * met x month]
+ */
+
+ /** permet de stocker les CPUE nominales [str x met] */
+ private MatrixND valuePerUnitOfEffort = null;
+
+ 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_EFFORT_PER_STRATEGY_MET,
+ ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET, // garder la ,
+
+ };
+
+ public String[] getNecessaryResult() {
+ return this.necessaryResult;
+ }
+
+ /**
+ * Permet d'afficher a l'utilisateur une aide sur la regle.
+ *
+ * @return L'aide ou la description de la regle
+ */
+ public String getDescription() throws Exception {
+ return _("calcule les proportion par m�tier chaque mois en fonction de la VPUE du m�tier l'ann�e pr�c�dante et les gross Values otherSpecies");
+ /*"HYPOTHESES GRAVITE"
+ " attention cette r�gle doit toujours �tre mise avant les mesures de gestion"+
+ " si pour un metier Effort (m�tier annee-1,mois) = 0 et propinitiale (m�tier, mois) !=0 (ie m�tier potentiellement pratiqu�), alors "+
+ on remet propInitiale pour tous les m�tiers (premiere vue complete pour tous les metiers de la strategie - graviteVPUE1-, une alternative
+ pourrait �tre de chercher lapremiere ann�e avant ann�e -1 pour laquelle le m�tier, ayant une propInitiale non nulle , aurait une VPUE (metier,mois) non nulle
+ et recuperer la propStr (metier,mois) pour cette ann�e et on l'affecte ann�e courante - mois, les autres m�tiers se partageant la proportion d'effort restante
+ en fonction de leur VPUE - graviteVPUE2-, une alternative pourrait etre de chercher la premiere ann�e avant ann�e -1 pour laquelle tous les m�tiers,
+ ayant une propInitiale non nulle, auraient eu une propStr non nulle, (surement difficile � trouver) - - graviteVPUE3- d'autres hypoth�ses pourraient etre envisag�es)
+ "*/
+ /*Calcul des gross Value Other Species en fonction de l'effort par strategie et par m�tier � date
+ Avant ann�e 1 (premiere ann�e d'appliaction de Gravit�) - il faut deja faire les calculs des grossValues des autres esp�ces
+ A partir de l'ann�e 1 : Gravit� s'applique, il faut donc attendre de connaitre l'allocation de l'effort � date (dependant des gross values species et otherspecies � date - 1)
+ pour pouvoir calculer les grossValueOtherSpecies � date
+
+ */
+ }
+
+ /**
+ * function used to initialise MatrixND to NaN double
+ */
+ private MapFunction nanFunction = new MapFunction() {
+ public double apply(double value) {
+ return Double.NaN;
+ }
+ };
+
+ /**
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
+ * des valeurs
+ *
+ * @param simulation
+ * La simulation pour lequel on utilise cette regle
+ */
+ 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);
+
+ 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);
+
+ 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);
+ }
+ }
+
+ // load coefficients of relation others file in a matrix
+ if (param_nomfichier_coeffOthers0 == null
+ || "".equals(param_nomfichier_coeffOthers0)) {
+ CoeffOthers0 = FileUtil.getFile(".*.csv",
+ "fichier 0 csv s�parateur ';'");
+ CoeffOthers1 = FileUtil.getFile(".*.csv",
+ "fichier 1 csv s�parateur ';'");
+ CoeffOthers2 = FileUtil.getFile(".*.csv",
+ "fichier 2 csv s�parateur ';'");
+ } else {
+ CoeffOthers0 = new File(param_nomfichier_coeffOthers0);
+ CoeffOthers1 = new File(param_nomfichier_coeffOthers1);
+ CoeffOthers2 = new File(param_nomfichier_coeffOthers2);
+ }
+
+ // reccuperation des metiers et strategies
+ SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
+ List<String> coeffs = Arrays.asList(new String[] { ALPHA_O, BETA_O });
+
+ // creation de mes strategies qui ne contient pas les espagnols
+ //mesStrategies = new HashMap<String, Strategy>();
+ //for(Strategy str : strs) {
+ // mesStrategies.put(str.getName(), str);
+ //}
+
+ MatrixND matCoeffOthers0 = MatrixFactory.getInstance().create(
+ "matCoeffOthers0", new List[] { metiers, coeffs },
+ new String[] { "Metiers", "Coeff" });
+ MatrixND matCoeffOthers1 = MatrixFactory.getInstance().create(
+ "matCoeffOthers1", new List[] { metiers, coeffs },
+ new String[] { "Metiers", "Coeff" });
+ MatrixND matCoeffOthers2 = MatrixFactory.getInstance().create(
+ "matCoeffOthers2", new List[] { metiers, coeffs },
+ new String[] { "Metiers", "Coeff" });
+
+ matCoeffOthers0.importCSV(new FileReader(CoeffOthers0), new int[] { 0,
+ 0 });
+ matCoeffOthers1.importCSV(new FileReader(CoeffOthers1), new int[] { 0,
+ 0 });
+ matCoeffOthers2.importCSV(new FileReader(CoeffOthers2), new int[] { 0,
+ 0 });
+
+ // captures non simulees
+ matrixCoeffOthers = MatrixFactory.getInstance().create(
+ "matrixCoeffOthers", new List[] { strs, metiers, coeffs },
+ new String[] { "Strategies", "Metiers", "Coeff" });
+
+ MatrixND matImport = MatrixFactory.getInstance().create(
+ new int[] { 14, 2 });
+ ;
+ for (Strategy str : strs) {
+ log.info("str =" + str.getName());
+ for (Metier met : metiers) {
+ for (String coeff : coeffs) {
+ if ("NephropsLargeLesSables".equals(str.getName())
+ || "NephropsLargeGuilvinec".equals(str.getName())
+ || "NephropsIntermediateLesSables".equals(str
+ .getName())
+ || "NephropsIntermediateGuilvinec".equals(str
+ .getName())) {
+ matImport = matCoeffOthers0;
+ } else if ("HakeLargeLesSables".equals(str.getName())
+ || "HakeLargeGuilvinec".equals(str.getName())
+ || "HakeIntermediateLesSables"
+ .equals(str.getName())
+ || "HakeIntermediateGuilvinec"
+ .equals(str.getName())) {
+ matImport = matCoeffOthers1;
+ } else if ("BenthicLargeLesSables".equals(str.getName())
+ || "BenthicLargeGuilvinec".equals(str.getName())
+ || "BenthicIntermediateLesSables".equals(str
+ .getName())
+ || "BenthicIntermediateGuilvinec".equals(str
+ .getName())) {
+ matImport = matCoeffOthers2;
+ }
+ matrixCoeffOthers.setValue(str, met, coeff, matImport
+ .getValue(met, coeff));
+ }// fin de for coeff
+ }// fin de for met
+ }// fin de for strategy
+ log.info("matrixCoeffOthers : " + matrixCoeffOthers);
+
+ }
+
+ /**
+ * 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 true; // on y passe a chaque pas de temps
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e 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 (log.isDebugEnabled()) {
+ log.debug("first = " + first + "date:" + date);
+ }
+ log.info("first = " + first + " ,on passe dans la preaction ?");
+ if (first) { // on passe dans preaction pour la premiere fois
+
+ log.info("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();
+ //on commence par creer une instance de resultats de matrice GrossValuesOtherSpecies
+ MatrixND GrossValueOtherSpeciesPerStrMet = MatrixFactory
+ .getInstance()
+ .create(
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET,
+ new List[] { strs, metiers },
+ new String[] { n_("Strategies"), n_("Metiers") });
+ log.info("GrossValueOtherSpeciesPerStrMet initialisee "
+ + GrossValueOtherSpeciesPerStrMet);
+
+ // si ann�e>=1 alors on fait le calcul des gravit� puis on met � jour les gross value otherspecies
+ if ((date.getYear() > 0) & (param_gravite == true)) {
+ ////////Initialisation des matrices qui resultent de la simulation////////////////////////////////////////////////////////////
+ log.info("calcul de Gravite");
+ //Calcul de l effort nominal par strategy met
+ MatrixND EffortNominalPerStrMet = null;
+ EffortNominalPerStrMet = resultmanager.getMatrix(date
+ .previousYear(),
+ ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET);
+ log.info("EffortNominalPerStrMet calculee "
+ + EffortNominalPerStrMet);
+
+ //on commence par creer une matrice de valeurs (somme sur ttes les especes capturees) par strategie met
+ MatrixND GrossValuePerStrMet = null;
+ GrossValuePerStrMet = resultmanager
+ .getMatrix(
+ date.previousYear(),
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET)
+ .copy();
+ log.info("GrossValuePerStrMet calculee " + GrossValuePerStrMet);
+
+ //ajouter pour tous les m�tiers les valeurs li�es qux autres esp�ces calcul�es par modele lineaire
+ // Boucle sur les strategies de mes strategies
+ //List <Strategy> mStr = strs;
+ for (Strategy strIndex : strs) {
+ // interdit de faire des set sur les strategies de la semantique de la matrice, il faut recuperer les strategies de la date courante
+ Strategy str = (Strategy) context.getDB().findByTopiaId(
+ strIndex.getTopiaId());
+
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(date
+ .getMonth());
+ Collection<EffortDescription> strMet = str
+ .getSetOfVessels().getPossibleMetiers();
+ //2) calcul les valeurs non simulees du mois l ann�e pr�c�dante
+ for (EffortDescription effort : strMet) {
+ Metier met = effort.getPossibleMetiers();
+ log.info("Boucle metier 1, metier possible: "
+ + met.getName());
+ double eff = EffortNominalPerStrMet.getValue(str, met);
+ log.info("effort str" + str.getName() + met.getName()
+ + " : " + eff);
+
+ //GrossValueAutres par strat�gie
+ // Hypothese 1 = pas de distinction entre les m�tiers n'agira donc pas sur la gravit�)
+ // Hypothese 2 = a distinguer selon les m�tiers - agira sur la gravit�
+ // l'hypothese est le resultat des coef dans la matrice en entr�e si tous identiques quelque soit le metier dans la strat�gie alors H1
+ // sinon H2
+ double valMetOther = matrixCoeffOthers.getValue(str,
+ met, ALPHA_O)
+ + matrixCoeffOthers.getValue(str, met, BETA_O)
+ * eff;
+ if (valMetOther < 0) {
+ valMetOther = 0;
+ }
+ double valMet = valMetOther
+ + GrossValuePerStrMet.getValue(str, met);
+ //log.info("valOtherMetAnchois :"+matrixCoeffOthers.getValue(str,met)*eff);
+ //log.info("GrossValuePerStrMet avant : "+GrossValuePerStrMet.getValue(str,met));
+ GrossValuePerStrMet.setValue(str, met, valMet);
+ log.info("valOtherMetLangoustine : " + valMet);
+ log.info("GrossValuePerStrMet apres : "
+ + GrossValuePerStrMet.getValue(str, met));
+
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////
+ valuePerUnitOfEffort.map(nanFunction); //r�initialisation avant calcul pour date
+
+ for (Strategy str : strs) {
+ log.info("INFO: Boucle creation valuePerUnitEffort : "
+ + str.getName());
+ //log.info("Boucle creation catchperuniteffort : "+ str.getName());
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(date
+ .getMonth());
+ Collection<EffortDescription> strMet = str
+ .getSetOfVessels().getPossibleMetiers();
+ //SiMatrix.getSiMatrix(context).getMetiers(str, date);
+
+ // boucle pour tester s'il existe un metier pour lequel effort(metier)=0 et PropInitiale(metier)=0 (Condition)
+ boolean testCondition = false;
+ double somme = 0;//initialisation de la somme des VPUE des metiers de la strategie
+ for (EffortDescription ed : strMet) {
+ Metier strMetier = ed.getPossibleMetiers();
+ log.info("Pour str=" + str.getName() + " et metier="
+ + strMetier.getName());
+ double effort = EffortNominalPerStrMet.getValue(str,
+ strMetier);
+ // on teste effort pour le calcul des VPUE
+ // si effort != 0 , valeur/effort
+ //sinon (effort =0) , deux cas de figure :
+ // 1. soit propInitiale =0 pour ce m�tier et dans ce cas VPUE =0 et ca ne doit pas impacter le calcul de la gravite pour les autres metiers de str
+ // 2. soit propInitiale! =0 et dans ce cas, on mettra PropInitiale pour tous les metiers de str
+ if (effort > 0) {// a pech� au mois, annee-1
+ //on recupere la capture tot
+ double value = GrossValuePerStrMet.getValue(str,
+ strMetier);
+ log.info("DEBUG: value : " + value);
+ log.info("DEBUG: effort : " + effort);
+ double vpue = value / effort;
+ valuePerUnitOfEffort.setValue(str, strMetier, vpue);
+ log.info("value/effort= " + vpue);
+ somme += value / effort;
+ } else if ((effort == 0)
+ & (smi.getProportionMetier(strMetier) == 0)) {// n'a jamais p�che avec ce metier
+ valuePerUnitOfEffort.setValue(str, strMetier, 0);
+ log.info("n'a jamais p�che avec ce metier");
+ } else {// n'a pas peche au mois, annee -1, mais avait une prop d'effort non nul a l'annee=0
+ testCondition = true;// ie somme est incompl�te mais pas grave car on mettra PropInitiale � tous les metiers
+ log
+ .info("n'a pas peche au mois, annee -1, mais avait une prop d'effort non nul a l'annee=0");
+ }
+ }
+ log.info("testCondition pour str" + str.getName() + ":"
+ + testCondition);
+ // � partir des VPUE stockees dans valuePerUnitOfEffort, on calcule la gravit�
+ double newProp = 0;
+ log
+ .info("� partir des VPUE stockees dans valuePerUnitOfEffort, on calcule la gravit�");
+ if (!testCondition) {
+ double SommeVPUEstrat = somme;
+ log.info("SommeVPUEstrat=" + SommeVPUEstrat);
+ for (EffortDescription ed : strMet) {
+ Metier strMetier = ed.getPossibleMetiers();
+ log.info("PropStrInitiale(metier="
+ + strMetier.getName() + ")"
+ + smi.getProportionMetier(strMetier));
+ log
+ .info("SommePropInitial.getValue(str, date.getMonth()="
+ + SommePropInitial.getValue(str,
+ date.getMonth()));
+ log
+ .info("valuePerUnitOfEffort.getValue(str, strMetier)"
+ + valuePerUnitOfEffort.getValue(
+ str, strMetier));
+ if (SommeVPUEstrat == 0) {
+ newProp = 0;
+ } else {
+ newProp = SommePropInitial.getValue(str, date
+ .getMonth())
+ * valuePerUnitOfEffort.getValue(str,
+ strMetier) / SommeVPUEstrat;
+ }
+ log.info("newProp(metier=" + strMetier.getName()
+ + ")" + newProp);
+ smi.setProportionMetier(strMetier, newProp);
+ log.info("PropStrNouvelle(metier="
+ + strMetier.getName() + ")"
+ + smi.getProportionMetier(strMetier));
+ // annee>= 1 calcul des gross Value otherSpecies avec les nouvelles valeurs d'effort calcul�es par gravite
+ //avec la nouvelle proportion on en d�duit la gross Value of Species de date pour ce str-met
+ double valMetOtherSpecies = matrixCoeffOthers
+ .getValue(str, strMetier, ALPHA_O)
+ + matrixCoeffOthers.getValue(str,
+ strMetier, BETA_O) * newProp;
+ //tester si valMetOtherSpecies <= alors mettre � 0
+ if (valMetOtherSpecies < 0) {
+ valMetOtherSpecies = 0;
+ }
+ GrossValueOtherSpeciesPerStrMet.setValue(str,
+ strMetier, valMetOtherSpecies);
+ log.info("valOtherMetLangoustine : "
+ + valMetOtherSpecies);
+ log.info("GrossValuePerStrMet apres : "
+ + GrossValueOtherSpeciesPerStrMet.getValue(
+ str, strMetier));
+ }
+ }
+ // else ie on met propInitiale dans PropStr(str,annee,mois)
+ // rien n'a faire car au debut de chaque pas de temps, PropStr est par d�faut initialis� � la valeur de la base de donn�es (val initiales)
+ }//fin de boucle sur strategy
+ // r�sultats grossvalue otherspecies mis dans le resultManager
+ resultmanager
+ .addResult(
+ date,
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET,
+ GrossValueOtherSpeciesPerStrMet);
+
+ } else if ((date.getYear() == 0) || (param_gravite == false)) {
+ //si ann�e==0 alors on ne fait que le calcul des gross value other species
+ for (Strategy str : strs) {
+ log.info("INFO: Boucle creation valuePerUnitEffort : "
+ + str.getName());
+ //log.info("Boucle creation catchperuniteffort : "+ str.getName());
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(date
+ .getMonth());
+ Collection<EffortDescription> strMet = str
+ .getSetOfVessels().getPossibleMetiers();
+ for (EffortDescription ed : strMet) {
+ Metier strMetier = ed.getPossibleMetiers();
+ log.info("PropStrInitiale(metier="
+ + strMetier.getName() + ")"
+ + smi.getProportionMetier(strMetier));
+ double valMetOtherSpecies = matrixCoeffOthers.getValue(
+ str, strMetier, ALPHA_O)
+ + matrixCoeffOthers.getValue(str, strMetier,
+ BETA_O)
+ * smi.getProportionMetier(strMetier);
+ //tester si valMetOtherSpecies <= alors mettre � 0
+ if (valMetOtherSpecies < 0) {
+ valMetOtherSpecies = 0;
+ }
+ GrossValueOtherSpeciesPerStrMet.setValue(str,
+ strMetier, valMetOtherSpecies);
+ log.info("valOtherMetLangoustine : "
+ + valMetOtherSpecies);
+ log.info("GrossValuePerStrMet apres : "
+ + GrossValueOtherSpeciesPerStrMet.getValue(str,
+ strMetier));
+ }
+ }
+ // r�sultats grossvalue otherspecies mis dans le resultManager
+ resultmanager
+ .addResult(
+ date,
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET,
+ GrossValueOtherSpeciesPerStrMet);
+ } // fin de calcul pour ann�e ==0
+ first = false;
+
+ }// fin de first= true
+
+ if (log.isDebugEnabled()) {
+ log.debug("fin Gravite CPUEAction avant");
+ }
+
+ }
+
+ /**
+ * Si la condition est vrai alors cette action est execut�e 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;
+
+ }
+
+}
Modified: trunk/rules/TACpoids.java
===================================================================
--- trunk/rules/TACpoids.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/rules/TACpoids.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -1,21 +1,19 @@
package rules;
+import static org.codelutin.i18n.I18n._;
+
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
-import static org.codelutin.i18n.I18n._;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codelutin.math.matrix.MatrixFactory;
import org.codelutin.math.matrix.MatrixIterator;
import org.codelutin.math.matrix.MatrixND;
import scripts.ResultName;
import scripts.RuleUtil;
import scripts.SiMatrix;
-
+import fr.ifremer.isisfish.datastore.ResultStorage;
import fr.ifremer.isisfish.entities.EffortDescription;
import fr.ifremer.isisfish.entities.Metier;
import fr.ifremer.isisfish.entities.Population;
@@ -29,107 +27,119 @@
import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.types.Date;
import fr.ifremer.isisfish.types.Month;
+import fr.ifremer.isisfish.util.Doc;
-import fr.ifremer.isisfish.util.Doc; // pour pouvoir afficher une aide contextuelle (BUG#1605)
-
/**
* TAC.java
*
* Created: 7 septembre 2006
*
* @author anonymous <anonymous(a)labs.libre-entreprise.org>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.3 $
*
- * Last update: $Date: 2007-11-20 15:50:09 $
- * by : $Author: bpoussin $
+ * Last update: $Date: 290607 $
+ * by : $Author: sigrid $
*/
/**
- * TAC peut-etre utilisé pour les différents TAC, en proportion des effectifs
+ * TAC peut-etre utilis� pour les diff�rents TAC, en proportion des effectifs
* et/ou avec survie ou non.
*
- * <li>Pour utiliser le tac proportionnel, il faut mettre dans le parametre propTac
- * une valeur > 0, le TAC sera alors recalculé a chaque mois de janvier.
- * <li>Pour utiliser la survie il faut mettre dans le paramètre propSurvie
- * une valeur > 0, automatiquement les suvie seront ajouté aux effectifs
- *
+ * <li>Pour utiliser le tac proportionnel, il faut mettre dans le parametre
+ * propTac une valeur > 0, le TAC sera alors recalcul� a chaque mois de janvier.
+ * <li>Pour utiliser la survie il faut mettre dans le param�tre propSurvie une
+ * valeur > 0, automatiquement les suvie seront ajout� aux effectifs
+ *
*/
public class TACpoids extends AbstractRule {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(TACpoids.class);
- @Doc(value="do the doc of param species")
+ @Doc(value = "do the doc of param species")
public Species param_species = null;
- @Doc(value="do the doc of param beginDate")
+ @Doc(value = "do the doc of param beginDate")
public Date param_beginDate = new Date(0);
- @Doc(value="do the doc of param endDate")
- public Date param_endDate = new Date(22);
- @Doc(value="do the doc of param propSurvie")
+ @Doc(value = "do the doc of param endDate")
+ public Date param_endDate = new Date(90);
+ @Doc(value = "do the doc of param propSurvie")
public double param_propSurvie = 0;
- @Doc(value="do the doc of param propTac")
+ @Doc(value = "do the doc of param propTac")
public double param_propTac = 0;
- /** TAC in tonne */
- public double param_tacInTons = 0;
-
+ /** TAC in tonnes */
+ @Doc(value = "TAC in tons")
+ public double param_tacInTons = 900;
+
boolean affectation = false;
-
- protected String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+
+ protected String[] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
-
+
/**
* @return the necessaryResult
*/
public String[] getNecessaryResult() {
return this.necessaryResult;
}
-
+
/**
* Permet d'afficher a l'utilisateur une aide sur la regle.
+ *
* @return L'aide ou la description de la regle
*/
public String getDescription() {
- return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed use propTac other than 0.");
+ return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0.");
}
-
+
/**
- * Appelé au démarrage de la simulation, cette méthode permet d'initialiser
+ * Appel� au d�marrage de la simulation, cette m�thode permet d'initialiser
* des valeurs
- * @param simulation La simulation pour lequel on utilise cette regle
+ *
+ * @param simulation
+ * La simulation pour lequel on utilise cette regle
*/
- public void init(SimulationContext context) throws Exception {
+ public void init(SimulationContext context) throws Exception {
}
-
+
/**
* La condition qui doit etre vrai pour faire les actions
- * @param simulation La simulation pour lequel on utilise cette regle
+ *
+ * @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 {
+ public boolean condition(SimulationContext context, Date date, Metier metier)
+ throws Exception {
+
+ log.info("test si TAC atteint");
// read species in current session
- param_species = (Species)context.getDB().findByTopiaId(param_species.getTopiaId());
-
- // on fait le calcul du tac si nécessaire
- if (param_propTac > 0 && date.getMonth().equals(Month.JANUARY)){
+ param_species = (Species) context.getDB().findByTopiaId(
+ param_species.getTopiaId());
+
+ // on fait le calcul du tac si n�cessaire
+ if (param_propTac > 0 && date.getMonth().equals(Month.JANUARY)) {
PopulationMonitor popMon = context.getPopulationMonitor();
param_tacInTons = popMon.getBiomass(param_species) * param_propTac;
- }
-
+ }
+
boolean result = false;
- if(date.before(param_beginDate)) {
+ if (date.before(param_beginDate)) {
result = false;
- } else if(date.after(param_endDate)) {
- result = false;
+ } else if (date.after(param_endDate)) {
+ result = false;
} else {
- TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth())
+ .getSpeciesTargetSpecies(param_species);
if (ts != null) {
- double catchTons = RuleUtil.getTotalCatchTons(context, param_species, date);
- log.info("[TAC] catchTons = " + catchTons + " >= param_tacInTons:" + param_tacInTons );
+ double catchTons = RuleUtil.getTotalCatchTons(context,
+ param_species, date);
+ log.info("[TAC] catchTons = " + catchTons
+ + " >= param_tacInTons:" + param_tacInTons);
if (catchTons >= param_tacInTons) {
result = true;
}
@@ -137,39 +147,47 @@
}
return result;
}
-
+
/**
- * Si la condition est vrai alors cette action est executée avant le pas
- * de temps de la simulation.
- * @param simulation La simulation pour lequel on utilise cette regle
+ * Si la condition est vrai alors cette action est execut�e avant le pas de
+ * temps de la simulation.
+ *
+ * @param simulation
+ * La simulation pour lequel on utilise cette regle
*/
- public void preAction(SimulationContext context, Date date, Metier metier) throws Exception {
+ public void preAction(SimulationContext context, Date date, Metier metier)
+ throws Exception {
affectation = false;
+
log.info("[TAC] preAction for: " + metier);
-
- TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
- if(ts != null && ts.getPrimaryCatch()) {
+ log.info(" TAC atteint [TAC] preAction for: " + metier);
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth())
+ .getSpeciesTargetSpecies(param_species);
+ if (ts != null && ts.getPrimaryCatch()) {
// recupere tous les metiers qui ont l'espece en capture principale =>metiers vises
- List<Metier> aimedMetiers = context.getDB().find("select distinct(metierSeasonInfo.metier) " +
- "from fr.ifremer.isisfish.entities.TargetSpecies " +
- "where species=? and primaryCatch=true", param_species);
+ // aimedMetiers ne fonctionne pas je ne sais pas pourquoi ! mais au final forbiddenMetier aura le meme effet
+ /*List<Metier> aimedMetiers = context.getDB().find("select distinct(metierSeasonInfo.metier) " +
+ "from fr.ifremer.isisfish.entities.TargetSpecies" +
+ "where species=? and primaryCatch=true", param_species);
- log.info("aimed Metier: " + aimedMetiers);
+ log.info("aimed Metier: " + aimedMetiers);*/
context.getMetierMonitor().addforbiddenMetier(metier);
-
- //récupere toutes les stratégies pratiquant le métier et pour lesquelles la proportion !=0
+
+ //r�cupere toutes les strat�gies pratiquant le m�tier et pour lesquelles la proportion !=0
SiMatrix siMatrix = SiMatrix.getSiMatrix(context);
Set<Strategy> strs = new HashSet<Strategy>();
for (Strategy str : siMatrix.getStrategies(date)) {
- double prop = str.getStrategyMonthInfo(date.getMonth()).getProportionMetier(metier);
+ double prop = str.getStrategyMonthInfo(date.getMonth())
+ .getProportionMetier(metier);
if (prop != 0) {
strs.add(str);
}
}
-
- for (Strategy str : strs){
- StrategyMonthInfo smi = str.getStrategyMonthInfo(date.getMonth());
-
+
+ for (Strategy str : strs) {
+ StrategyMonthInfo smi = str.getStrategyMonthInfo(date
+ .getMonth());
+
// 1er cas de figure: l'effort est reporte sur un metier de la
// meme strategie, n'ayant pas l'espece comme capture principale
// et pechant avec le meme engin
@@ -181,35 +199,38 @@
// sans consideration sur les engins, et pour lesquels la
// proportion peut etre nulle
Set<Metier> possibleMetierCase3 = new HashSet<Metier>();
-
- for (EffortDescription effort : str.getSetOfVessels().getPossibleMetiers()) {
+
+ for (EffortDescription effort : str.getSetOfVessels()
+ .getPossibleMetiers()) {
Metier newMetier = effort.getPossibleMetiers();
if (
- !aimedMetiers.contains(newMetier)
- && !metier.getName().equalsIgnoreCase("nonActiviy")
+ /*!aimedMetiers.contains(newMetier)
+ &&*/!metier.getName().equalsIgnoreCase("nonActiviy")
&& !metier.getName().equalsIgnoreCase("nonActivie")
- && !context.getMetierMonitor().getForbiddenMetier().contains(newMetier)
- ) {
+ && !metier.getName().equalsIgnoreCase(
+ "non Activit�")
+ && !context.getMetierMonitor().getForbiddenMetier()
+ .contains(newMetier)) {
possibleMetierCase3.add(newMetier);
-
+
if (smi.getProportionMetier(newMetier) != 0) {
possibleMetierCase2.add(newMetier);
-
+
if (metier.getGear().equals(newMetier.getGear())) {
possibleMetierCase1.add(newMetier);
}
}
}
}
-
+
Set<Metier> possibleMetier = null;
- if (possibleMetierCase1.size() != 0){
+ if (possibleMetierCase1.size() != 0) {
log.info("[TAC] Use case 1");
possibleMetier = possibleMetierCase1;
} else if (possibleMetierCase2.size() != 0) {
log.info("[TAC] Use case 2");
possibleMetier = possibleMetierCase2;
- } else if (possibleMetierCase3.size() != 0){
+ } else if (possibleMetierCase3.size() != 0) {
log.info("[TAC] Use case 3");
possibleMetier = possibleMetierCase3;
}
@@ -219,46 +240,52 @@
// possibles dans la meme strategie si un metier possible existe
// bien la repartion est proportionnelle a l'effort deja alloue
// dans la strategie
-
- double somme=0;
- for (Metier met : possibleMetierCase1) {
+
+ double somme = 0;
+ for (Metier met : possibleMetier) {
somme += smi.getProportionMetier(met);
}
- for (Metier met : possibleMetierCase1) {
- double newProportion =
- smi.getProportionMetier(met)
- + (smi.getProportionMetier(metier)
- * smi.getProportionMetier(met) / somme);
+ for (Metier met : possibleMetier) {
+ double newProportion = smi.getProportionMetier(met)
+ + (smi.getProportionMetier(metier)
+ * smi.getProportionMetier(met) / somme);
smi.setProportionMetier(met, newProportion);
}
- smi.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
- } else{
+ smi.setProportionMetier(metier, 0); //le metier vise a alors une proportion nulle
+ log.info("[TAC] il y a des metiers possibles");
+ } else {
log.info("[TAC] Use no activity");
-
+
// sinon on met tout dans le metier nonActivite
MetierMonitor metierMon = context.getMetierMonitor();
MatrixND mat = metierMon.getOrCreateNoActivity(date,
- ResultName.MATRIX_NO_ACTIVITY,
- siMatrix.getStrategies(date),
- siMatrix.getMetiers(date));
+ ResultName.MATRIX_NO_ACTIVITY, siMatrix
+ .getStrategies(date), siMatrix
+ .getMetiers(date));
mat.setValue(str, metier, smi.getProportionMetier(metier));
-
+
smi.getProportionMetier().setValue(metier, 0);
- }
+ }
}
}
}
-
+
/**
- * Si la condition est vrai alors cette action est executée apres le pas
- * de temps de la simulation.
- * @param simulation La simulation pour lequel on utilise cette regle
+ * Si la condition est vrai alors cette action est execut�e 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 {
+ public void postAction(SimulationContext context, Date date, Metier metier)
+ throws Exception {
+ ResultStorage resultmanager = context.getSimulationStorage()
+ .getResultStorage();
log.info("[TAC] postAction for: " + metier);
- TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth()).getSpeciesTargetSpecies(param_species);
- if(ts != null){
- if (!affectation){
+ TargetSpecies ts = metier.getMetierSeasonInfo(date.getMonth())
+ .getSpeciesTargetSpecies(param_species);
+ if (ts != null) {
+ if (!affectation) {
// ATTENTION
// les captures pour cette metapop ne sont plus du qu'au metier
// pour qui l'espece est secondaire: elles sont affectees aux
@@ -270,36 +297,46 @@
// pour les captures)
//////
PopulationMonitor popMon = context.getPopulationMonitor();
+ log.info("popMon biomass" + popMon.getBiomass(param_species));
for (Population pop : param_species.getPopulation()) {
- // si on a deja une matrice rejet on le vide (elle vient
- // forcement de la regle taille minimale or si le tac est
- // atteint, tout va dorenavent dans les rejets et on mais
- // TOUTES les captures dans les rejets
- MatrixND discard = popMon.getDiscard(date, pop);
- if (discard != null) {
- discard.mults(0);
- }
-
- discard = popMon.getCatch(pop).copy();
- discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP);
- popMon.addDiscard(date, pop, discard);
- log.info("[TAC] add discard for " + pop + ": " + discard);
-
- if (param_propSurvie > 0) {
- MatrixND eff = popMon.getN(pop);
- //on réajoute les survivants aux effectifs
- for (MatrixIterator i=discard.iterator(); i.next();){
- Object [] coord = i.getSemanticsCoordinates();
- eff.setValue(coord[2],coord[3],
- eff.getValue(coord[2],coord[3])+i.getValue()*param_propSurvie);
+ if (!pop.getName().equals("Population_new")) {
+ log.info("pop : " + pop.getName());
+ // si on a deja une matrice rejet on le vide (elle vient
+ // forcement de la regle taille minimale or si le tac est
+ // atteint, tout va dorenavent dans les rejets et on mais
+ // TOUTES les captures dans les rejets
+ MatrixND discard = popMon.getDiscard(date, pop);
+ log.info("discard : " + discard);
+ if (discard != null) {
+ discard.mults(0);
}
+ log.info("catch = " + popMon.getCatch(pop));
+ discard = popMon.getCatch(pop).copy();
+ // ca ne doit pas pouvoir marcher car MATRIX_DISCARDS_PER_STR_MET est de dimension pop groupe str met - et discard n'a plus la dimension pop
+ discard.setName(ResultName.MATRIX_DISCARDS_PER_STR_MET);
+ popMon.addDiscard(date, pop, discard);
+ log.info("[TAC] add discard for " + pop + ": "
+ + discard);
+ // ne manquerait-il pas
+ resultmanager.addResult(date, pop, discard);
+ if (param_propSurvie > 0) {
+ MatrixND eff = popMon.getN(pop);
+ //on r�ajoute les survivants aux effectifs
+ for (MatrixIterator i = discard.iterator(); i
+ .next();) {
+ Object[] coord = i.getSemanticsCoordinates();
+ eff.setValue(coord[2], coord[3], eff.getValue(
+ coord[2], coord[3])
+ + i.getValue() * param_propSurvie);
+ }
+ }
+
}
+ // on a affecte une fois cette meta pop au rejet il ne faut pas
+ // le refaire
+ affectation = true;
}
-
- // on a affecte une fois cette meta pop au rejet il ne faut pas
- // le refaire
- affectation=true;
}
}
}
Modified: trunk/scripts/ResultName.java
===================================================================
--- trunk/scripts/ResultName.java 2009-04-22 16:32:05 UTC (rev 120)
+++ trunk/scripts/ResultName.java 2009-04-28 13:19:55 UTC (rev 121)
@@ -1,6 +1,6 @@
/* *##%
* Copyright (C) 2006
- * Code Lutin, Cédric Pineau, Benjamin Poussin
+ * Code Lutin, C�dric Pineau, Benjamin Poussin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,7 +20,7 @@
/* *
* ResultName.java
*
- * Created: 23 août 2006 15:09:37
+ * Created: 23 ao�t 2006 15:09:37
*
* @author poussin
* @version $Revision: 1.10 $
@@ -37,54 +37,48 @@
/**
* Contient l'ensemble des noms des differents resultats. Le mieux lorsque l'on
- * veut un nouveau résultat est d'ajouter une constante ici, et de l'utiliser
- * ensuite lors de la création de la matrice.
+ * veut un nouveau r�sultat est d'ajouter une constante ici, et de l'utiliser
+ * ensuite lors de la cr�ation de la matrice.
* <p>
- * Ceci permet d'avoir un endroit unique ou l'on voit l'ensemble des résultats
- * potentiellement disponible et de ne pas ce tromper en écrivent le nom
- * d'un résultat
+ * Ceci permet d'avoir un endroit unique ou l'on voit l'ensemble des r�sultats
+ * potentiellement disponible et de ne pas ce tromper en �crivent le nom
+ * d'un r�sultat
* <p>
* Cette classe ne doit contenir que des noms de resultat en static public String
* l'interface de lancement de simulation se base sur cette classe pour
- * afficher l'ensemble des résultats disponible
+ * afficher l'ensemble des r�sultats disponible
*
* @author poussin
*/
public class ResultName {
@Doc(value = "do the doc of Result matrixDiscardsWeightPerStrMet")
- static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsWeightPerStrMet");
+ static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET = n_("matrixDiscardsWeightPerStrMet");
@Doc(value = "do the doc of Result matrixDiscardsPerStrMet")
- static final public String MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsPerStrMet");
+ static final public String MATRIX_DISCARDS_PER_STR_MET = n_("matrixDiscardsPerStrMet");
@Doc(value = "do the doc of Result matrixLandingPerMet")
static final public String MATRIX_LANDING_PER_MET = n_("matrixLandingPerMet");
@Doc(value = "do the doc of Result matrixEffortPerStrategyMet")
static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n_("matrixEffortPerStrategyMet");
+ @Doc(value = "do the doc of Result matrixEffortNominalPerStrategyMet")
+ static final public String MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET = n_("matrixEffortNominalPerStrategyMet");
@Doc(value = "do the doc of Result matrixStdTravelEffortPerStrategyMet")
static final public String MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET = n_("matrixStdTravelEffortPerStrategyMet");
@Doc(value = "do the doc of Result matrixEffortPerZonePop")
static final public String MATRIX_EFFORT_PER_ZONE_POP = n_("matrixEffortPerZonePop");
- @Doc(value = "Disponible uniquement avec les simulations par Zone. do the doc of Result matrixCatchRatePerStrategyMet")
- static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchRatePerStrategyMet");
- @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet")
- static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchPerStrategyMetPerZoneMet");
- @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZonePop")
- static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchPerStrategyMetPerZonePop");
- @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet")
- static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchWeightPerStrategyMetPerZoneMet");
- @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZonePop")
- static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchWeightPerStrategyMetPerZonePop");
- @Doc(value = "Disponible uniquement avec les simulations par Zone. do the doc of Result matrixFishingMortality")
+ @Doc(value = "do the doc of Result matrixCatchRatePerStrategyMet")
+ static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET = n_("matrixCatchRatePerStrategyMet");
+ @Doc(value = "do the doc of Result matrixCatchPerStrategyMet")
+ static final public String MATRIX_CATCH_PER_STRATEGY_MET = n_("matrixCatchPerStrategyMet");
+ @Doc(value = "do the doc of Result matrixFishingMortality")
static final public String MATRIX_FISHING_MORTALITY = n_("matrixFishingMortality");
+ @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMet")
+ static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET = n_("matrixCatchWeightPerStrategyMet");
@Doc(value = "do the doc of Result matrixAbundance")
static final public String MATRIX_ABUNDANCE = n_("matrixAbundance");
@Doc(value = "do the doc of Result matrixBiomass")
static final public String MATRIX_BIOMASS = n_("matrixBiomass");
- @Doc(value = "do the doc of Result matrixBiomassBeginMonth")
- static final public String MATRIX_BIOMASS_BEGIN_MONTH = n_("matrixBiomassBeginMonth");
- @Doc(value = "do the doc of Result matrixBiomassBeginMonth")
- static final public String MATRIX_ABONDANCE_BEGIN_MONTH = n_("matrixAbondanceBeginMonth");
@Doc(value = "do the doc of Result matrixFishingTimePerMonthPerVessel")
static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n_("matrixFishingTimePerMonthPerVessel");
@@ -105,6 +99,8 @@
static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet");
@Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerStrategyMet")
static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerStrategyMet");
+ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet")
+ static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet");
@Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerStrategyMetPerVessel")
static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixGrossValueOfLandingsPerStrategyMetPerVessel");
@Doc(value = "do the doc of Result matrixNetValueOfLandingsPerStrategyMet")
1
0
Author: jcouteau
Date: 2009-04-22 16:32:05 +0000 (Wed, 22 Apr 2009)
New Revision: 120
Modified:
trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java
trunk/sensitivity/SensitivityCalculatorRFrF2.java
Log:
Code formatting and some corrections
Modified: trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java 2009-04-22 16:31:17 UTC (rev 119)
+++ trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java 2009-04-22 16:32:05 UTC (rev 120)
@@ -392,14 +392,7 @@
+ ")");
log.info("Message sent to R : "
+ "isis.simule<-data.frame(isis.simule," + name + ")");
- }
- for (int k = 0; k < sensitivityNumber; k++) {
-
- // Creates the R expression to import results in R
- String name = simulationStorages.get(0).getParameter()
- .getSensitivityExport().get(k).getExportFilename();
-
//Create the dataforaov data.frame
String dataframe = "dataforaov<-data.frame(factors," + name
+ "=" + name + ")";
Modified: trunk/sensitivity/SensitivityCalculatorRFrF2.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorRFrF2.java 2009-04-22 16:31:17 UTC (rev 119)
+++ trunk/sensitivity/SensitivityCalculatorRFrF2.java 2009-04-22 16:32:05 UTC (rev 120)
@@ -19,9 +19,7 @@
package sensitivity;
import java.io.File;
-import java.io.Serializable;
import java.util.List;
-import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -31,15 +29,12 @@
import org.codelutin.math.matrix.MatrixFactory;
import org.codelutin.math.matrix.MatrixND;
import org.codelutin.util.FileUtil;
-import org.rosuda.JRI.REXP;
import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityCalculator;
import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
import fr.ifremer.isisfish.simulator.sensitivity.Factor;
import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityCalculator;
-
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityCalculator;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
@@ -163,8 +158,7 @@
for (int j = 0; j < nbExperiments; j++) {
Scenario experimentScenario = new Scenario();
for (int i = 0; i < factorNumber; i++) {
- Factor factor = plan.getFactors()
- .get(i);
+ Factor factor = plan.getFactors().get(i);
if ((factor.getDomain() instanceof MatrixContinuousDomain)
|| (factor.getDomain() instanceof EquationContinuousDomain)) {
if (frf2.getValue(new int[] { i, j }) == -1) {
@@ -178,15 +172,13 @@
}
} else {
if (frf2.getValue(new int[] { i, j }) == -1) {
- factor
- .setValueForIdentifier(((ContinuousDomain) factor
- .getDomain()).getMinBound());
+ factor.setValueForIdentifier(((ContinuousDomain) factor
+ .getDomain()).getMinBound());
}
if (frf2.getValue(new int[] { i, j }) == 1) {
- factor
- .setValueForIdentifier(((ContinuousDomain) factor
- .getDomain()).getMaxBound());
+ factor.setValueForIdentifier(((ContinuousDomain) factor
+ .getDomain()).getMaxBound());
}
}
experimentScenario.addFactor(factor);
@@ -197,8 +189,8 @@
try {
//Create the factors vectors
for (int j = 0; j < factorNumber; j++) {
- Factor factor = thisExperimentScenarios
- .get(0).getFactors().get(j);
+ Factor factor = thisExperimentScenarios.get(0).getFactors()
+ .get(j);
if (factor.getDomain() instanceof EquationContinuousDomain) {
String vector = "factor" + j + "<-c(";
@@ -477,7 +469,6 @@
engine.voidEval("names(dataforaov)<-resultsnames");
log.info("Message sent to R : "
+ "names(dataforaov)<-resultsnames");
-
//Save the results with the scenarios.
engine.voidEval("write.csv(dataforaov,\""
1
0
Author: jcouteau
Date: 2009-04-22 16:31:17 +0000 (Wed, 22 Apr 2009)
New Revision: 119
Modified:
trunk/sensitivity/SensitivityCalculatorRRandomLHS.java
Log:
RandomLHS conform to new CDC
Modified: trunk/sensitivity/SensitivityCalculatorRRandomLHS.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorRRandomLHS.java 2009-04-22 14:33:10 UTC (rev 118)
+++ trunk/sensitivity/SensitivityCalculatorRRandomLHS.java 2009-04-22 16:31:17 UTC (rev 119)
@@ -19,9 +19,10 @@
package sensitivity;
import java.io.File;
-import java.io.Serializable;
import java.util.List;
+import javax.swing.JOptionPane;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.j2r.REngine;
@@ -31,14 +32,15 @@
import org.codelutin.util.FileUtil;
import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityCalculator;
import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Domain;
import fr.ifremer.isisfish.simulator.sensitivity.Factor;
import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityCalculator;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityCalculator;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
@@ -51,14 +53,15 @@
*
*/
@Doc("Random Latin Hypercube")
-public class SensitivityCalculatorRRandomLHS extends AbstractSensitivityCalculator {
+public class SensitivityCalculatorRRandomLHS extends
+ AbstractSensitivityCalculator {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory
.getLog(SensitivityCalculatorRRandomLHS.class);
@Doc("Simulation number (default=10)")
- public int param_simulationNumber;
+ public int param_simulationNumber = 10;
/**
* Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
@@ -73,12 +76,28 @@
public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
throws SensitivityException {
+ setIsisFactorsR(plan, outputdirectory);
+
int factornumber = plan.getFactors().size();
double[] dataframe = new double[0];
SensitivityScenarios thisExperiment = new SensitivityScenarios();
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
List<Factor> factors = plan.getFactors();
+ //Test all factors, if one is discrete, return null
+ for (int i = 0; i < factors.size(); i++) {
+ if (factors.get(i).getDomain() instanceof DiscreteDomain) {
+ JOptionPane
+ .showMessageDialog(
+ null,
+ "Error",
+ factors.get(i).getName()
+ + " has a discrete domain, this is not acceptable for this method.",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ }
+
if ((Integer) param_simulationNumber == 0) {
param_simulationNumber = 10;
}
@@ -86,6 +105,14 @@
REngine engine = new RProxy();
try {
+ //Set working directory to get Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
+
+ //Get Isis R session
+ log.info("load(\".RData\")");
+ engine.voidEval("load(\".RData\")");
+
//Load the lhs library
engine.voidEval("library(lhs)");
log.info("Message sent to R : " + "library(lhs)");
@@ -108,8 +135,7 @@
for (int j = 0; j < param_simulationNumber; j++) {
Scenario experimentScenario = new Scenario();
for (int i = 0; i < factornumber; i++) {
- Factor factor = plan.getFactors()
- .get(i);
+ Factor factor = plan.getFactors().get(i);
if ((factor.getDomain() instanceof MatrixContinuousDomain)
|| (factor.getDomain() instanceof EquationContinuousDomain)) {
factor
@@ -131,13 +157,74 @@
thisExperiment.setScenarios(thisExperimentScenarios);
}
- //Create the factors vectors
- for (int j = 0; j < factornumber; j++) {
- Factor factor = thisExperimentScenarios
- .get(0).getFactors().get(j);
+ String isisFactorDistribution = "isis.factor.distribution<-data.frame(NomFacteur=c(%s),NomDistribution=c(%s),ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+ String factorNames = "";
+
+ for (int i = 0; i < factors.size(); i++) {
+ Domain domain = factors.get(i).getDomain();
+ if (i != 0) {
+ distribution += ",";
+ factorNames += ",";
+ parameters += ",";
+ }
+
+ factorNames += "\"" + factors.get(i).getName() + "\"";
+ distribution += "\"qunif\"";
+ parameters += "\"[" + ((ContinuousDomain) domain).getMinBound()
+ + ";" + ((ContinuousDomain) domain).getMaxBound()
+ + "]\"";
+ }
+
+ log.info("Message sent to R : "
+ + String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+ engine.voidEval(String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+
+ log.info("Message sent to R : " + "call<-" + "\"x<-randomLHS("
+ + param_simulationNumber + "," + factornumber + ")\"");
+ engine.voidEval("call<-" + "\"x<-randomLHS("
+ + param_simulationNumber + "," + factornumber + ")\"");
+
+ log
+ .info("Message sent to R : "
+ + "isis.MethodExp<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"call\"=call)");
+ engine
+ .voidEval("isis.MethodExp<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"call\"=call)");
+
+ log
+ .info("Message sent to R : "
+ + "attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ log.info("Message sent to R : " + "isis.simule<-data.frame(x)");
+ engine.voidEval("isis.simule<-data.frame(x)");
+
+ log
+ .info("Message sent to R : "
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ log.info("Message sent to R : "
+ + "names(isis.simule)<-isis.factors[[1]]");
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ String data = "data<-data.frame(";
+
+ //Create the factors vectors and the dataframe instruction
+ for (int j = 0; j < factors.size(); j++) {
+ Factor factor = thisExperimentScenarios.get(0).getFactors()
+ .get(j);
if (factor.getDomain() instanceof EquationContinuousDomain) {
- String vector = "factor" + j + "<-c(";
+ //String vector = "factor" + j + "<-c(";
+ String vector = factor.getName().replaceAll(" ", "")
+ + "<-c(";
for (int i = 0; i < param_simulationNumber; i++) {
if (i < (param_simulationNumber - 1)) {
vector = vector
@@ -156,7 +243,9 @@
engine.voidEval(vector);
log.info("Message sent to R : " + vector);
} else if (factor.getDomain() instanceof MatrixContinuousDomain) {
- String vector = "factor" + j + "<-c(";
+ //String vector = "factor" + j + "<-c(";
+ String vector = factor.getName().replaceAll(" ", "")
+ + "<-c(";
for (int i = 0; i < param_simulationNumber; i++) {
if (i < (param_simulationNumber - 1)) {
vector = vector
@@ -175,7 +264,9 @@
engine.voidEval(vector);
log.info("Message sent to R : " + vector);
} else {
- String vector = "factor" + j + "<-c(";
+ //String vector = "factor" + j + "<-c(";
+ String vector = factor.getName().replaceAll(" ", "")
+ + "<-c(";
for (int i = 0; i < param_simulationNumber; i++) {
if (i < (param_simulationNumber - 1)) {
vector = vector
@@ -193,15 +284,13 @@
engine.voidEval(vector);
log.info("Message sent to R : " + vector);
}
- }
- //Create the data data.frame from the factors
- String data = "data<-data.frame(";
- for (int j = 0; j < factornumber; j++) {
- if (j < factornumber - 1) {
- data = data + "factor" + j + "=factor(factor" + j + "),";
+ if (j < factors.size() - 1) {
+ data += factor.getName().replaceAll(" ", "") + "=factor("
+ + factor.getName().replaceAll(" ", "") + "),";
} else {
- data = data + "factor" + j + "=factor(factor" + j + "))";
+ data += factor.getName().replaceAll(" ", "") + "=factor("
+ + factor.getName().replaceAll(" ", "") + "))";
}
}
@@ -241,6 +330,14 @@
log.info("Message sent to R"
+ "dput(factornames,file=\".factornames\")");
+ //Set working directory to save Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
+
+ // Save Isis R session
+ log.info("save.image()");
+ engine.voidEval("save.image()");
+
engine.terminate();
} catch (Exception e) {
@@ -261,36 +358,44 @@
REngine engine = new RProxy();
try {
- param_simulationNumber = simulationStorages.get(0).getParameter()
- .getSensitivityExport().size();
+ //Set working directory to get Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
- for (int k = 0; k < param_simulationNumber; k++) {
+ //Get Isis R session
+ log.info("load(\".RData\")");
+ engine.voidEval("load(\".RData\")");
- // Set output directory
- engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
- + "\")");
- log.info("Message sent to R : setwd(\""
- + outputdirectory.getAbsolutePath() + "\")");
+ // Set output directory
+ engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
+ + "\")");
+ log.info("Message sent to R : setwd(\""
+ + outputdirectory.getAbsolutePath() + "\")");
- //Get back the scenarios
- //engine.voidEval("factors<-read.csv(\".expandgrid.csv\",row.names=1,col.names=1)");
- engine.voidEval("factors<-read.csv(\".randomlhs.csv\")");
- log
- .info("Message sent to R : factors<-read.csv(\".randomlhs.csv\")");
+ //Get back the scenarios
+ engine.voidEval("factors<-read.csv(\".randomlhs.csv\")");
+ log
+ .info("Message sent to R : factors<-read.csv(\".randomlhs.csv\")");
- // Get the factornames object in the .factornames file
- engine.voidEval("factornames<-dget(\".factornames\")");
- log.info("Message sent to R : "
- + "factornames<-dget(\".factornames\")");
+ // Get the factornames object in the .factornames file
+ engine.voidEval("factornames<-dget(\".factornames\")");
+ log.info("Message sent to R : "
+ + "factornames<-dget(\".factornames\")");
- //Get back the factors number
- int factorNumber = ((Double) engine.eval("length(factors)-1"))
- .intValue();
- //factorNumber=factorNumber-1;
+ //Get back the factors number
+ int factorNumber = ((Double) engine.eval("length(factors)-1"))
+ .intValue();
- //Create the results vectors
- String result = "result<-c(";
- for (int l = 0; l < simulationStorages.size(); l++) {
+ param_simulationNumber = simulationStorages.get(0).getParameter()
+ .getSensitivityExport().size();
+
+ for (int k = 0; k < param_simulationNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = simulationStorages.get(0).getParameter()
+ .getSensitivityExport().get(k).getExportFilename();
+ String rInstruction = name + "<-c(";
+ for (int l = 0; l < param_simulationNumber; l++) {
File importFile = new File(simulationStorages.get(l)
.getDirectory().toString()
+ File.separator
@@ -304,27 +409,64 @@
String simulResult = FileUtil.readAsString(importFile);
double simulationResult = Double.valueOf(simulResult);
if (l < simulationStorages.size() - 1) {
- result = result + simulationResult + ",";
+ rInstruction = rInstruction + simulationResult + ",";
} else {
- result = result + simulationResult;
+ rInstruction = rInstruction + simulationResult;
}
}
- result = result + ")";
- engine.voidEval(result);
- log.info("Message sent to R : " + result);
+ rInstruction = rInstruction + ")";
+ log.info("Message sent to R : " + rInstruction);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," + name
+ + ")");
+ log.info("Message sent to R : "
+ + "isis.simule<-data.frame(isis.simule," + name + ")");
+ }
+
+ //adding attribute to isis.Simule
+ log
+ .info("Message sent to R : "
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ log.info("Message sent to R : "
+ + "attr(isis.simule,\"call\")<-isis.MethodExp$call");
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < param_simulationNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = simulationStorages.get(0).getParameter()
+ .getSensitivityExport().get(k).getExportFilename();
+
//Create the dataforaov data.frame
- String dataframe = "dataforaov<-data.frame(factors,result=result)";
+ String dataframe = "dataforaov<-data.frame(factors," + name
+ + "=" + name + ")";
engine.voidEval(dataframe);
log.info("Message sent to R : " + dataframe);
//Call aov()
- String aovCall = "aovresult<-aov(result~";
+ String aovCall = "aovresult<-aov(" + name + "~";
for (int j = 0; j < factorNumber; j++) {
+ log.info("Message sent to R : " + "names(factors)["
+ + (j + 2) + "]");
+
if (j < (factorNumber - 1)) {
- aovCall = aovCall + "factor" + j + "+";
+ aovCall = aovCall
+ + engine
+ .eval("names(factors)[" + (j + 2) + "]")
+ + "+";
} else {
- aovCall = aovCall + "factor" + j + ",data=dataforaov)";
+ aovCall = aovCall
+ + engine
+ .eval("names(factors)[" + (j + 2) + "]")
+ + ",data=dataforaov)";
}
}
engine.voidEval(aovCall);
@@ -367,14 +509,6 @@
log.info("Message sent to R : "
+ "row.names(exportsensitivity)<-factornames");
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
- + "\")");
- log.info("Message sent to R : setwd(\""
- + outputdirectory.getAbsolutePath() + "\")");
-
//Set dataforaov names
engine
.voidEval("resultsnames<-c(\"Simulation\",factornames,\"Result\")");
@@ -385,6 +519,14 @@
log.info("Message sent to R : "
+ "names(dataforaov)<-resultsnames");
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.voidEval("setwd(\"" + outputdirectory.getAbsolutePath()
+ + "\")");
+ log.info("Message sent to R : setwd(\""
+ + outputdirectory.getAbsolutePath() + "\")");
+
//Save the results with the scenarios.
engine.voidEval("write.csv(dataforaov,\""
+ simulationStorages.get(0).getParameter()
@@ -407,10 +549,71 @@
.getExportFilename()
+ "_SensitivityIndices.csv\")");
//FIXME export through java to enable export when using Rserve (when distant Rserve).
- engine.terminate();
+
+ //creating isis.methodAnalyse
+ log
+ .info("Message sent to R : "
+ + "isis.methodAnalyse<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"isis.simule\"=isis.simule,call_method=\""
+ + aovCall + "\"" + ",aovresult)");
+ engine
+ .voidEval("isis.methodAnalyse<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"isis.simule\"=isis.simule,call_method=\""
+ + aovCall + "\"" + ",aovresult)");
+
+ log
+ .info("Message sent to R : "
+ + "attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
+ String simulationName = simulationStorages.get(0).getName()
+ .replaceAll("-", "");
+ log.info("Message sent to R : "
+ + String.format(renameIsisMethodAnalyse, simulationName
+ + "." + name));
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
}
- log.info("end");
+ //Rename R objects for saving purpose
+
+ String renameIsisSimule = "%s.isis.simule<-isis.simule";
+ String renameIsisFactorDistribution = "%s.isis.factor.distribution<-isis.factor.distribution";
+ String renameIsisFactor = "%s.isis.factor<-isis.factors";
+ String renameIsisMethodExp = "%s.isis.methodExp<-isis.MethodExp";
+
+ String simulationName = simulationStorages.get(0).getName()
+ .replaceAll("-", "");
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisSimule, simulationName));
+ engine.voidEval(String.format(renameIsisSimule, simulationName));
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisFactorDistribution,
+ simulationName));
+ engine.voidEval(String.format(renameIsisFactorDistribution,
+ simulationName));
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisFactor, simulationName));
+ engine.voidEval(String.format(renameIsisFactor, simulationName));
+
+ log.info("Message sent to R : "
+ + String.format(renameIsisMethodExp, simulationName));
+ engine.voidEval(String.format(renameIsisMethodExp, simulationName));
+
+ //Set working directory to save Isis R session
+ log.info("setwd(\"" + outputdirectory.getParent() + "\")");
+ engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
+
+ // Save Isis R session
+ log.info("save.image()");
+ engine.voidEval("save.image()");
+
+ engine.terminate();
+
} catch (Exception e) {
e.printStackTrace();
// Error while processing
1
0
Author: jcouteau
Date: 2009-04-22 14:33:10 +0000 (Wed, 22 Apr 2009)
New Revision: 118
Modified:
trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java
trunk/sensitivity/SensitivityCalculatorRegularFractions.java
Log:
Changing attributes instruction in R
Modified: trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java 2009-04-21 12:27:21 UTC (rev 117)
+++ trunk/sensitivity/SensitivityCalculatorJavaExpandGrid.java 2009-04-22 14:33:10 UTC (rev 118)
@@ -284,9 +284,9 @@
log
.info("Message sent to R : "
- + "attributes(isis.MethodExp)<-list(nomModel=\"isis-fish-externe-R\")");
+ + "attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
engine
- .voidEval("attributes(isis.MethodExp)<-list(nomModel=\"isis-fish-externe-R\")");
+ .voidEval("attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
//Create isis.Simule
log.info("Message sent to R : " + "isis.simule<-data.frame(data)");
@@ -294,9 +294,9 @@
log
.info("Message sent to R : "
- + "attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
engine
- .voidEval("attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
log.info("Message sent to R : "
+ "names(isis.simule)<-isis.factors[[1]]");
@@ -394,13 +394,6 @@
+ "isis.simule<-data.frame(isis.simule," + name + ")");
}
- //adding attribute to isis.Simule
- log
- .info("Message sent to R : "
- + "attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
- engine
- .voidEval("attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
-
for (int k = 0; k < sensitivityNumber; k++) {
// Creates the R expression to import results in R
@@ -521,6 +514,12 @@
.voidEval("isis.methodAnalyse<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"isis.simule\"=isis.simule,call_method=\""
+ aovCall + "\"" + ",aovresult)");
+ log
+ .info("Message sent to R : "
+ + "attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+
String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
String simulationName = simulationStorages.get(0).getName()
.replaceAll("-", "");
Modified: trunk/sensitivity/SensitivityCalculatorRegularFractions.java
===================================================================
--- trunk/sensitivity/SensitivityCalculatorRegularFractions.java 2009-04-21 12:27:21 UTC (rev 117)
+++ trunk/sensitivity/SensitivityCalculatorRegularFractions.java 2009-04-22 14:33:10 UTC (rev 118)
@@ -303,9 +303,9 @@
log
.info("Message sent to R : "
- + "attributes(isis.MethodExp)<-list(nomModel=\"isis-fish-externe-R\")");
+ + "attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
engine
- .voidEval("attributes(isis.MethodExp)<-list(nomModel=\"isis-fish-externe-R\")");
+ .voidEval("attr(isis.MethodExp,\"nomModel\")<-\"isis-fish-externe-R\"");
//Create isis.Simule
log.info("Message sent to R : " + "isis.simule<-data.frame(data)");
@@ -313,20 +313,18 @@
log
.info("Message sent to R : "
- + "attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
engine
- .voidEval("attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
log.info("Message sent to R : "
+ "names(isis.simule)<-isis.factors[[1]]");
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Export the data.frame object for the second run in a .expandgrid file
+
+ // Export the data.frame object for the second run in a .expandgrid file
engine.voidEval("write.csv(data,file=\".data.csv\")");
- log
- .info("Message sent to R : write.csv(data,file=\".data.csv\")");
+ log.info("Message sent to R : write.csv(data,file=\".data.csv\")");
-
//Set working directory to save Isis R session
log.info("setwd(\"" + outputdirectory.getParent() + "\")");
engine.voidEval("setwd(\"" + outputdirectory.getParent() + "\")");
@@ -374,11 +372,10 @@
engine.voidEval("factornames<-dget(\".factornames\")");
log.info("Message sent to R : "
+ "factornames<-dget(\".factornames\")");
-
- //Get back the scenarios
+
+ //Get back the scenarios
engine.voidEval("factors<-read.csv(\".data.csv\")");
- log
- .info("Message sent to R : factors<-read.csv(\".data.csv\")");
+ log.info("Message sent to R : factors<-read.csv(\".data.csv\")");
//Get back the factors number
int factorNumber = ((Double) engine.eval("length(factors)-1"))
@@ -427,9 +424,9 @@
//adding attribute to isis.Simule
log
.info("Message sent to R : "
- + "attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
+ + "attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
engine
- .voidEval("attributes(isis.simule)<-list(nomModel=\"isis-fish-externe-R\")");
+ .voidEval("attr(isis.simule,\"nomModel\")<-\"isis-fish-externe-R\"");
for (int k = 0; k < sensitivityNumber; k++) {
@@ -551,6 +548,12 @@
.voidEval("isis.methodAnalyse<-list(\"isis.factors\"=isis.factors,\"isis.factor.distribution\"=isis.factor.distribution,\"isis.simule\"=isis.simule,call_method=\""
+ aovCall + "\"" + ",aovresult)");
+ log
+ .info("Message sent to R : "
+ + "attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine
+ .voidEval("attr(isis.methodAnalyse,\"nomModel\")<-\"isis-fish-externe-R\"");
+
String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
String simulationName = simulationStorages.get(0).getName()
.replaceAll("-", "");
1
0