Author: bpoussin Date: 2014-12-15 15:30:39 +0000 (Mon, 15 Dec 2014) New Revision: 4158 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4158 Log: extract interface for OptimizationContext and SimulationPlanContext this permit to prevent visibility of internal method to user add Historic object in SimulationPlanContext to permit to put some value for simulation and export all in CSV Added: trunk/src/main/java/fr/ifremer/isisfish/simulator/Historic.java trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContextInternal.java trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContextInternal.java Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlanContext.java trunk/src/main/java/fr/ifremer/isisfish/simulator/Objective.java trunk/src/main/java/fr/ifremer/isisfish/simulator/Optimization.java trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContext.java trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlan.java trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContext.java trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/OptimizationPrepareJob.java trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationPlanPrepareJob.java Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlanContext.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlanContext.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlanContext.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -40,7 +40,7 @@ * @deprecated since 4.0.0.0, use {@link SimulationPlanContext} instead */ @Deprecated -public class AnalysePlanContext extends SimulationPlanContext { +public class AnalysePlanContext extends SimulationPlanContextInternal { /** * @param id Added: trunk/src/main/java/fr/ifremer/isisfish/simulator/Historic.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/Historic.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/Historic.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -0,0 +1,79 @@ +package fr.ifremer.isisfish.simulator; + + +import fr.ifremer.isisfish.datastore.SimulationStorage; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Useful class to stock some double value for simulation, and export all + * value in CSV format + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class Historic { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(Historic.class); + + Map<String, Experience> experiences = new LinkedHashMap<String, Experience>(); + + public Experience get(SimulationStorage sim) { + Experience result = experiences.get(sim.getName()); + if (result == null) { + result = new Experience(); + experiences.put(sim.getName(), result); + } + return result; + } + + public String toCSV(String ... fieldNames) { + StringBuilder result = new StringBuilder(); + String sep = ";"; + + result.append("simulation"); + for (String field: fieldNames) { + result.append(sep).append(field); + } + + for (Map.Entry<String, Experience> e: experiences.entrySet()) { + result.append(e.getKey()); + Experience exp = e.getValue(); + for (String field : fieldNames) { + result.append(sep); + Double value = exp.get(field); + if (value != null) { + result.append(value); + } else { + result.append("NA"); + } + } + } + + return result.toString(); + } + + private static class Experience { + + Map<String, Double> values = new HashMap<String, Double>(); + + public Experience() { + } + + public Double get(String fieldName) { + Double result = values.get(fieldName); + return result; + } + + public void set(String fieldName, double value) { + values.put(fieldName, value); + } + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/simulator/Historic.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/Objective.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/Objective.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/Objective.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -59,5 +59,5 @@ * @param observations observations * @return double value */ - double eval(OptimizationContext context, List<MatrixND> exports, List<MatrixND> observations); + double eval(OptimizationContextInternal context, List<MatrixND> exports, List<MatrixND> observations); } Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/Optimization.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/Optimization.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/Optimization.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -53,7 +53,7 @@ * * @param context */ - void init(OptimizationContext context) throws Exception; + void init(OptimizationContextInternal context) throws Exception; /** * La premiere generation doit etre construite dans cette methode @@ -61,14 +61,14 @@ * * @param context */ - void firstSimulation(OptimizationContext context) throws Exception; + void firstSimulation(OptimizationContextInternal context) throws Exception; /** * Génère une nouvelle série de simulation suivant le context d'optimisation. * * @param context context */ - void nextSimulation(OptimizationContext context) throws Exception; + void nextSimulation(OptimizationContextInternal context) throws Exception; /** * Cette methode est appelee après chaque serie de simulation soit apres firstSimulation et @@ -76,12 +76,12 @@ * * @param context */ - void endSimulation(OptimizationContext context) throws Exception; + void endSimulation(OptimizationContextInternal context) throws Exception; /** * Cette methode est appelee lorsqu'il n'y a plus de simulation a faire * (init ou nextSimulation n'ont pas fait appel a context.addSimulation) * @param context */ - void finish(OptimizationContext context) throws Exception; + void finish(OptimizationContextInternal context) throws Exception; } Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContext.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContext.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContext.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -1,153 +1,64 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2014 Ifremer, Code Lutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ package fr.ifremer.isisfish.simulator; -import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.simulator.launcher.SimulationJob; import fr.ifremer.isisfish.simulator.sensitivity.Factor; -import fr.ifremer.isisfish.simulator.sensitivity.FactorHelper; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.apache.commons.collections4.CollectionUtils; /** - * Context utilisé pour gérer les différentes simulation lancées par un script d'optimisation. - * - * @author Eric Chatellier - * @since 4.3.0.0 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ -public class OptimizationContext extends SimulationPlanContext { +public interface OptimizationContext extends SimulationPlanContext { - protected SimulationJob job; + /** + * Return the current generation. + * 0 for no generation (in firstGeneration) + * 1 for one generation simulation + * ... + * + * @return + */ + int getCurrentGeneration(); - protected List<List<SimulationStorage>> generations = - new ArrayList<List<SimulationStorage>>(); + /** + * Return simulation for generation n + * @param n generation number + * @return + */ + List<SimulationStorage> getGeneration(int n); - /** Simulation to do during next generation simulation */ - protected List<SimulationStorage> nextSimulations; + /** + * Return last generation simulations. + * @return + */ + List<SimulationStorage> getLastSimulations(); - public OptimizationContext(String id, SimulationParameter param, SimulationJob job) { - super(id, param); - this.job = job; - } - - public List<SimulationStorage> getNextSimulations() { - if (nextSimulations == null) { - nextSimulations = new ArrayList<SimulationStorage>(); - } - return nextSimulations; - } - /** - * Get simulation to do, put it generations and increment currentGeneration - * This method must be call be Simulator when it want to get next simulations - * to do. - * @return null or empty collection if no more simulation to do + * Return next generation, in endGeneration, this method return all time + * empty list. + * @return */ - public List<SimulationStorage> clearNextSimulation() { - List<SimulationStorage> result = nextSimulations; + List<SimulationStorage> getNextSimulations(); - if (CollectionUtils.isNotEmpty(result)) { - generations.add(result); - nextSimulations = null; - } - - return result; - } - - public List<SimulationStorage> getLastSimulations() { - List<SimulationStorage> result = getGeneration(generations.size() - 1); - return result; - } - /** * Return new simulation. This new simulation is automaticaly added to * next simulation. - * + * * @return new Simulation */ - public SimulationStorage newSimulation() { - try { - String simId = id + "_" + number; - SimulationParameter childParam = param.copy(); - childParam.setSimulationPlanNumber(number); - SimulationStorage result = SimulationStorage.importAndRenameZip(job.getItem().getSimulationZip(), simId); - - incNumber(); - addSimulation(result); + SimulationStorage newSimulation(); - return result; - } catch (Exception eee) { - throw new IsisFishRuntimeException("can't create new simulation", eee); - } - } - - protected void addSimulation(SimulationStorage s) { - getNextSimulations().add(s); - } - /** * Create simulation. This new simulation is automatically added to * next simulations. Database will be modified with factors in parameters + * + * @param factors factors used to modify simulation + * @return simulation modified with factors */ - public void newSimulation(Factor ... factors) { - SimulationStorage s = newSimulation(); + SimulationStorage newSimulation(Factor... factors); - Collection<Factor> colFactors = new ArrayList<Factor>(); - Collections.addAll(colFactors, factors); - String script = FactorHelper.generatePreScript(colFactors); - - SimulationParameter childParam = s.getParameter(); - childParam.setGeneratedPreScript(script); - } - - /** - * Return the current generation. - * 0 for no generation - * 1 for one generation simulation - * ... - * @return - */ - public int getCurrentGeneration() { - return generations.size(); - } - - public int getSimulationNumber() { - return number; - } - - public List<SimulationStorage> getGeneration(int n) { - List<SimulationStorage> result = null; - if (n >= 0 && CollectionUtils.isNotEmpty(generations)) { - result = generations.get(n); - } - - return result; - } - } Copied: trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContextInternal.java (from rev 4157, trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContext.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContextInternal.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/OptimizationContextInternal.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -0,0 +1,171 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2014 Ifremer, Code Lutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.simulator; + +import fr.ifremer.isisfish.IsisFishRuntimeException; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.launcher.SimulationJob; +import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorHelper; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.apache.commons.collections4.CollectionUtils; + +/** + * Context utilisé pour gérer les différentes simulation lancées par un script d'optimisation. + * + * @author Eric Chatellier + * @since 4.3.0.0 + */ +public class OptimizationContextInternal extends SimulationPlanContextInternal implements OptimizationContext { + + protected SimulationJob job; + + protected int generationNumber = 0; + protected List<List<SimulationStorage>> generations = + new ArrayList<List<SimulationStorage>>(); + + /** Simulation to do during next generation simulation */ + protected List<SimulationStorage> nextSimulations; + + public OptimizationContextInternal(String id, SimulationParameter param, SimulationJob job) { + super(id, param); + this.job = job; + } + + @Override + public List<SimulationStorage> getNextSimulations() { + if (nextSimulations == null) { + nextSimulations = new ArrayList<SimulationStorage>(); + } + return nextSimulations; + } + + /** + * Get simulation to do, put it generations and increment currentGeneration + * This method must be call be Simulator when it want to get next simulations + * to do. + * @return null or empty collection if no more simulation to do + */ + public List<SimulationStorage> clearNextSimulation() { + List<SimulationStorage> result = nextSimulations; + + if (CollectionUtils.isNotEmpty(result)) { + generations.add(result); + nextSimulations = null; + } + + return result; + } + + @Override + public List<SimulationStorage> getLastSimulations() { + List<SimulationStorage> result = getGeneration(generations.size() - 1); + return result; + } + + /** + * Return new simulation. This new simulation is automaticaly added to + * next simulation. + * + * @return new Simulation + */ + @Override + public SimulationStorage newSimulation() { + try { + String simId = id + "_" + number; + SimulationParameter childParam = param.copy(); + childParam.setSimulationPlanNumber(number); + SimulationStorage result = SimulationStorage.importAndRenameZip(job.getItem().getSimulationZip(), simId); + + incNumber(); + addSimulation(result); + + return result; + } catch (Exception eee) { + throw new IsisFishRuntimeException("can't create new simulation", eee); + } + } + + protected void addSimulation(SimulationStorage s) { + getNextSimulations().add(s); + } + + /** + * Create simulation. This new simulation is automatically added to + * next simulations. Database will be modified with factors in parameters + * + * @param factors factors used to modify simulation + * @return simulation modified with factors + */ + @Override + public SimulationStorage newSimulation(Factor ... factors) { + SimulationStorage s = newSimulation(); + + Collection<Factor> colFactors = new ArrayList<Factor>(); + Collections.addAll(colFactors, factors); + String script = FactorHelper.generatePreScript(colFactors); + + SimulationParameter childParam = s.getParameter(); + childParam.setGeneratedPreScript(script); + + return s; + } + + /** + * Return the current generation. + * 0 for no generation + * 1 for one generation simulation + * ... + * @return + */ + @Override + public int getCurrentGeneration() { + return generationNumber; + } + + public void incGenerationNumber() { + generationNumber++; + } + + public int getSimulationNumber() { + return number; + } + + @Override + public List<SimulationStorage> getGeneration(int n) { + List<SimulationStorage> result = null; + if (generations.size() == n) { + result = getNextSimulations(); + } else if (n >= 0 && CollectionUtils.isNotEmpty(generations)) { + result = generations.get(n); + } + + return result; + } + +} Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlan.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlan.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlan.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -63,7 +63,7 @@ * @param context plan context * @throws Exception */ - public void init(SimulationPlanContext context) throws Exception; + public void init(SimulationPlanContextInternal context) throws Exception; /** * Call before each simulation. @@ -73,7 +73,7 @@ * @return true if we must do next simulation, false to stop plan * @throws Exception */ - public boolean beforeSimulation(SimulationPlanContext context, + public boolean beforeSimulation(SimulationPlanContextInternal context, SimulationStorage nextSimulation) throws Exception; /** @@ -84,7 +84,7 @@ * @return true if we must do next simulation, false to stop plan * @throws Exception */ - public boolean afterSimulation(SimulationPlanContext context, + public boolean afterSimulation(SimulationPlanContextInternal context, SimulationStorage lastSimulation) throws Exception; } Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContext.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContext.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContext.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -1,39 +1,8 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Code Lutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - package fr.ifremer.isisfish.simulator; -import java.util.HashMap; -import java.util.Map; - import fr.ifremer.isisfish.datastore.SimulationStorage; /** - * Simulation plan context.java - * - * Replace old {@code AnalysePlanContext}. * * @author poussin * @version $Revision$ @@ -41,113 +10,73 @@ * Last update: $Date$ * by : $Author$ */ -public class SimulationPlanContext { +public interface SimulationPlanContext { - /** Simulation id. */ - protected String id; - - /** Simulation plan number. */ - protected int number = 0; - - /** Simulation parameters. */ - protected SimulationParameter param; - - /** Additional context values. */ - protected Map<String, Object> values = new HashMap<String, Object>(); - - public SimulationPlanContext(String id, SimulationParameter param) { - this.id = id; - this.param = param; - } - /** * Get id. - * + * * @return the id */ - public String getId() { - return id; - } + String getId(); /** + * Get last simulation storage. + * + * Used in script. + * + * @return last simulation storage + */ + SimulationStorage getLastSimulation(); + + /** * Get current simulation plan simulation count. - * + * * Warning, in after simulation, refer to generated simulation count, * not ended simulation number. * Depreciated, but no remove this method, it's just to not be used * by user script. - * + * * @return the number - * + * * @deprecated use {@code nextSimulation.getParameter().getSimulationPlanNumber()} */ - public int getNumber() { - return number; - } + int getNumber(); /** - * Must be call when new simulation is generated from plan. + * Get simulation parameters. + * + * @return simulation parameters */ - public void incNumber() { - number++; - } + SimulationParameter getParam(); /** - * Get simulation parameters. - * - * @return simulation parameters + * Get {@link SimulationStorage} for specified simulation plan number. + * + * @param number number + * @return {@link SimulationStorage} */ - public SimulationParameter getParam() { - return param; - } + SimulationStorage getSimulation(int number); /** * Get plan context value. - * + * * Used in script. - * + * * @param key key * @return value for key. */ - public Object getValue(String key) { - return this.values.get(key); - } + Object getValue(String key); /** * Set plan context value. - * + * * Used in script. - * + * * @param key key * @param value value */ - public void setValue(String key, Object value) { - this.values.put(key, value); - } + void setValue(String key, Object value); - /** - * Get last simulation storage. - * - * Used in script. - * - * @return last simulation storage - */ - public SimulationStorage getLastSimulation() { - SimulationStorage result = getSimulation(getNumber() - 1); - return result; - } + Historic getHistoric(); - /** - * Get {@link SimulationStorage} for specified simulation plan number. - * - * @param number number - * @return {@link SimulationStorage} - */ - public SimulationStorage getSimulation(int number) { - SimulationStorage result = null; - if (0 <= number && number <= getNumber()) { - result = SimulationStorage.getSimulation(id + "_" + number); - } - return result; - } } Copied: trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContextInternal.java (from rev 4157, trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContext.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContextInternal.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPlanContextInternal.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -0,0 +1,168 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Code Lutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.simulator; + +import java.util.HashMap; +import java.util.Map; + +import fr.ifremer.isisfish.datastore.SimulationStorage; + +/** + * Simulation plan context.java + * + * Replace old {@code AnalysePlanContext}. + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class SimulationPlanContextInternal implements SimulationPlanContext { + + /** Simulation id. */ + protected String id; + + /** Simulation plan number. */ + protected int number = 0; + + /** Simulation parameters. */ + protected SimulationParameter param; + + protected Historic historic = new Historic(); + + /** Additional context values. */ + protected Map<String, Object> values = new HashMap<String, Object>(); + + public SimulationPlanContextInternal(String id, SimulationParameter param) { + this.id = id; + this.param = param; + } + + /** + * Get id. + * + * @return the id + */ + @Override + public String getId() { + return id; + } + + /** + * Get current simulation plan simulation count. + * + * Warning, in after simulation, refer to generated simulation count, + * not ended simulation number. + * Depreciated, but no remove this method, it's just to not be used + * by user script. + * + * @return the number + * + * @deprecated use {@code nextSimulation.getParameter().getSimulationPlanNumber()} + */ + @Override + public int getNumber() { + return number; + } + + /** + * Must be call when new simulation is generated from plan. + */ + public void incNumber() { + number++; + } + + /** + * Get simulation parameters. + * + * @return simulation parameters + */ + @Override + public SimulationParameter getParam() { + return param; + } + + /** + * Get plan context value. + * + * Used in script. + * + * @param key key + * @return value for key. + */ + @Override + public Object getValue(String key) { + return this.values.get(key); + } + + /** + * Set plan context value. + * + * Used in script. + * + * @param key key + * @param value value + */ + @Override + public void setValue(String key, Object value) { + this.values.put(key, value); + } + + /** + * Get last simulation storage. + * + * Used in script. + * + * @return last simulation storage + */ + @Override + public SimulationStorage getLastSimulation() { + SimulationStorage result = getSimulation(getNumber() - 1); + return result; + } + + /** + * Get {@link SimulationStorage} for specified simulation plan number. + * + * @param number number + * @return {@link SimulationStorage} + */ + @Override + public SimulationStorage getSimulation(int number) { + SimulationStorage result = null; + if (0 <= number && number <= getNumber()) { + result = SimulationStorage.getSimulation(id + "_" + number); + } + return result; + } + + @Override + public Historic getHistoric() { + return historic; + } + +} Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/OptimizationPrepareJob.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/OptimizationPrepareJob.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/OptimizationPrepareJob.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -44,7 +44,7 @@ import fr.ifremer.isisfish.export.Export; import fr.ifremer.isisfish.simulator.Objective; import fr.ifremer.isisfish.simulator.Optimization; -import fr.ifremer.isisfish.simulator.OptimizationContext; +import fr.ifremer.isisfish.simulator.OptimizationContextInternal; import fr.ifremer.isisfish.simulator.SimulationControl; import fr.ifremer.isisfish.simulator.SimulationParameter; @@ -64,7 +64,7 @@ static private final Log log = LogFactory.getLog(OptimizationPrepareJob.class); protected SimulationService simulationService; - protected OptimizationContext optimizationContext; + protected OptimizationContextInternal optimizationContext; protected SimulationJob job; protected String id; protected SimulationControl control; @@ -89,7 +89,7 @@ objective = param.getObjective(); optimization = param.getOptimization(); - optimizationContext = new OptimizationContext(id, param, job); + optimizationContext = new OptimizationContextInternal(id, param, job); } @Override @@ -139,6 +139,7 @@ // FIXME echatellier 20140418 exception is always false, it's value never changes if (!exception && !control.isStopSimulationRequest()) { optimization.endSimulation(optimizationContext); + optimizationContext.incGenerationNumber(); // close current generation simulations for (SimulationStorage sim : sims) { sim.closeStorage(); Modified: trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationPlanPrepareJob.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationPlanPrepareJob.java 2014-12-09 13:13:37 UTC (rev 4157) +++ trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationPlanPrepareJob.java 2014-12-15 15:30:39 UTC (rev 4158) @@ -32,7 +32,7 @@ import fr.ifremer.isisfish.simulator.SimulationControl; import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.SimulationPlan; -import fr.ifremer.isisfish.simulator.SimulationPlanContext; +import fr.ifremer.isisfish.simulator.SimulationPlanContextInternal; import java.io.File; import java.util.Iterator; import java.util.List; @@ -56,7 +56,7 @@ private static final Log log = LogFactory.getLog(SimulationPlanPrepareJob.class); protected SimulationService simulationService; - protected SimulationPlanContext planContext; + protected SimulationPlanContextInternal planContext; protected SimulationJob job; protected SimulationJob nextJob; protected boolean doNext = true; @@ -76,7 +76,7 @@ // because they a freed during simulation (soft reference) // is there is not enought memory available simulationPlan = param.getSimulationPlans(); - this.planContext = new SimulationPlanContext(control.getId(), param); + this.planContext = new SimulationPlanContextInternal(control.getId(), param); try { // appel de init sur chaque plan for (SimulationPlan plan : simulationPlan) {