diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..4c07f35
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,25 @@
+name: CI
+
+on:
+ push:
+ branches: ["master"]
+ pull_request:
+ branches: ["**"]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4.2.2
+
+ - name: Set up Java 11
+ uses: actions/setup-java@v4.7.0
+ with:
+ java-version: "11"
+ distribution: temurin
+ cache: maven
+
+ - name: Run tests
+ working-directory: structSimV1
+ run: mvn test
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f398f94
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.class
+ResultSim/
+all.log
+structSimV1/target/
\ No newline at end of file
diff --git a/README.md b/README.md
index b54e40d..98b7818 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,113 @@ To use our framework to your project you have to add the "structSimV1.jar" to yo
A tutorial (structSimTutorial.pdf) is available to help you to begin with our framework. Some example are also described in this tutorial.
+## Citation
+
+If you use this framework in your research, please cite the following paper:
+
+> René Schumann, Caroline Taramarcaz. **Towards Systematic Testing of Complex Interacting Systems.** In *Proceedings of the Workshop on Testing Extra-Functional Properties and Quality Characteristics of Software Systems (ITEQS)*, CEUR Workshop Proceedings, Vol. 2397, pp. 55–, 2019. https://ceur-ws.org/Vol-2397/paper8.pdf
+
If you have some questions/remarks about this project, you can consult the official page of the project at this address :
https://www.hevs.ch/fr/mini-sites/projets-produits/si-lab/projets/structured-simulation--a-framework-for-the-automated-analysis-of-adaptive-systems-8640
And in case, don't hesitate to contact us.
+
+## Running the simulation (mock mode)
+
+The framework ships with a mock simulator (`SimpleSimulationHandler`) that lets you run without a real external simulator.
+
+Ready-to-use example files are in [`examples/simple/`](examples/simple/). Copy them as described below.
+
+### 1. Copy `config.properties` into the classpath
+
+Copy [`examples/simple/config.properties`](examples/simple/config.properties) to `structSimV1/src/main/resources/config.properties`:
+
+```bash
+cp examples/simple/config.properties structSimV1/src/main/resources/config.properties
+```
+
+```properties
+pathOUT = /tmp/structsim-results
+pathParameters = parameters.txt
+pathSimulator = /tmp/structsim-simulator
+pathToSimulatorResultFile = /tmp/structsim-simulator/results/results.txt
+cuttOfPlanning = 10
+typeCuttOfPlanning = INT
+```
+
+| Key | Description |
+|-----|-------------|
+| `pathOUT` | Folder where results and `SummaryFile.txt` are written |
+| `pathParameters` | Name of the parameters file — loaded from the classpath, so place it in `src/main/resources/` |
+| `pathSimulator` | Folder where per-simulation sub-folders are created |
+| `pathToSimulatorResultFile` | Result file the simulator creates after each run |
+| `typeCuttOfPlanning` | When to stop generating simulations — `INT`, `CRITERIA`, `HOURS`, `MINUTES`, or `DAY` |
+| `cuttOfPlanning` | Threshold value for the chosen stop type (see below) |
+
+**How `typeCuttOfPlanning` works:**
+
+The framework builds a tree of simulations by applying modifiers on top of each other. This setting controls when it stops growing the tree:
+
+- `INT` — stops after N outer loop iterations (e.g. `10` means 10 rounds of applying all modifiers). Good for a quick bounded run.
+- `CRITERIA` — prunes any branch whose cumulative probability drops below the threshold (e.g. `0.15` = stop exploring paths less likely than 15%). Each modifier has a probability; they multiply as modifiers are combined. Good for skipping unlikely scenarios.
+- `HOURS` / `MINUTES` / `DAY` — runs for a fixed wall-clock duration regardless of how many simulations are generated.
+
+> **Note:** the file must have the `.properties` extension.
+
+### 2. Copy `parameters.txt` into the classpath
+
+Copy [`examples/simple/parameters.txt`](examples/simple/parameters.txt) to `structSimV1/src/main/resources/parameters.txt`:
+
+```bash
+cp examples/simple/parameters.txt structSimV1/src/main/resources/parameters.txt
+```
+
+```
+val1=1
+val2=2
+val3=3
+val4=4
+val5=5
+```
+
+One `key=value` pair per line. Values must be numbers.
+
+### 3. Configure modifiers in `Simulation.java`
+
+Open `structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/Simulation.java` and edit the modifiers list. Each `ConcreteModifier` takes `(parameterKey, operator, delta, probability)`:
+
+```java
+modifiers.add(new ConcreteModifier("val2", '+', 1.0, 0.5));
+modifiers.add(new ConcreteModifier("val2", '+', 10.0, 0.5));
+```
+
+Supported operators: `+`, `-`, `*`, `/`
+
+The `probability` field is only used for pruning when `typeCuttOfPlanning = CRITERIA`. With `INT` mode it has no effect on how many simulations run.
+
+### 4. Create output directories and run
+
+```bash
+mkdir -p /tmp/structsim-results /tmp/structsim-simulator
+cd structSimV1
+mvn exec:java -Dexec.mainClass=ch.hevs.silab.structuredsim.gluecode.Simulation
+```
+
+Results are written to `pathOUT/SummaryFile.txt`.
+
+---
+
+## Quick start - run the built-in example (Linux and Mac)
+
+The `examples/simple/` directory is a ready-to-run project matching the tutorial. It modifies `val2` with two modifiers (`+1` and `+10`) and runs 10 iterations.
+
+```bash
+cd examples/simple
+./run.sh
+```
+
+The script will:
+1. Build and install `structSimV1` to your local Maven repo
+2. Create `/tmp/structsim-results` and `/tmp/structsim-simulator`
+3. Run the simulation
+4. Print `SummaryFile.txt` when done
diff --git a/examples/simple/config.properties b/examples/simple/config.properties
new file mode 100644
index 0000000..d27816b
--- /dev/null
+++ b/examples/simple/config.properties
@@ -0,0 +1,15 @@
+# Folder where results and SummaryFile.txt are written
+pathOUT = /tmp/structsim-results
+
+# Name of the parameters file - must be on the classpath (src/main/resources/)
+pathParameters = parameters.txt
+
+# Folder where per-simulation sub-folders are created
+pathSimulator = /tmp/structsim-simulator
+
+# Result file the simulator creates after each run
+pathToSimulatorResultFile = /tmp/structsim-simulator/results/results.txt
+
+# Stop after 10 outer exploration loop iterations
+cuttOfPlanning = 10
+typeCuttOfPlanning = INT
diff --git a/examples/simple/parameters.txt b/examples/simple/parameters.txt
new file mode 100644
index 0000000..a1aff25
--- /dev/null
+++ b/examples/simple/parameters.txt
@@ -0,0 +1,5 @@
+val1=1
+val2=2
+val3=3
+val4=4
+val5=5
diff --git a/examples/simple/pom.xml b/examples/simple/pom.xml
new file mode 100644
index 0000000..929dffb
--- /dev/null
+++ b/examples/simple/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+ example
+ simple-simulation
+ 1.0-SNAPSHOT
+ jar
+
+
+ 11
+ 11
+
+
+
+
+ hevs.ch.silab
+ hevs.ch.silab
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 3.1.0
+
+ example.Simulation
+
+
+
+
+
diff --git a/examples/simple/run.sh b/examples/simple/run.sh
new file mode 100755
index 0000000..555750a
--- /dev/null
+++ b/examples/simple/run.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+set -e
+
+REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
+EXAMPLE_DIR="$REPO_ROOT/examples/simple"
+BUILD_DIR="$EXAMPLE_DIR/target/classes"
+
+STRUCT_CLASSES="$REPO_ROOT/structSimV1/target/classes"
+LOG4J_JAR="$HOME/.m2/repository/org/apache/logging/log4j/log4j-api/2.24.3/log4j-api-2.24.3.jar"
+
+echo "==> Compiling structSimV1..."
+cd "$REPO_ROOT/structSimV1"
+mvn compile -q
+
+echo "==> Creating output directories..."
+mkdir -p /tmp/structsim-results /tmp/structsim-simulator
+mkdir -p "$BUILD_DIR"
+
+echo "==> Compiling example..."
+javac -cp "$STRUCT_CLASSES:$LOG4J_JAR" \
+ -d "$BUILD_DIR" \
+ "$EXAMPLE_DIR/src/main/java/example/Simulation.java"
+
+echo "==> Running simulation..."
+java -cp "$BUILD_DIR:$STRUCT_CLASSES:$LOG4J_JAR:$EXAMPLE_DIR/src/main/resources" \
+ example.Simulation
+
+echo ""
+echo "Done! Results written to /tmp/structsim-results/SummaryFile.txt"
+echo ""
+cat /tmp/structsim-results/SummaryFile.txt
diff --git a/examples/simple/src/main/java/example/Simulation.java b/examples/simple/src/main/java/example/Simulation.java
new file mode 100644
index 0000000..10af864
--- /dev/null
+++ b/examples/simple/src/main/java/example/Simulation.java
@@ -0,0 +1,29 @@
+package example;
+
+import ch.hevs.silab.structuredsim.gluecode.ConcreteModifier;
+import ch.hevs.silab.structuredsim.gluecode.SimpleSimulationHandler;
+import ch.hevs.silab.structuredsim.interfaces.AModifier;
+import ch.hevs.silab.structuredsim.interfaces.StartProgram;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Simulation extends StartProgram {
+
+ public static void main(String[] args) throws IOException {
+
+ InputStream config = Simulation.class
+ .getClassLoader()
+ .getResourceAsStream("config.properties");
+
+ List modifiers = new ArrayList<>();
+ modifiers.add(new ConcreteModifier("val2", '+', 1.0, 0.5));
+ modifiers.add(new ConcreteModifier("val2", '+', 10.0, 0.5));
+
+ SimpleSimulationHandler ssh = new SimpleSimulationHandler(modifiers);
+
+ startProgram(config, ssh);
+ }
+}
diff --git a/examples/simple/src/main/resources/config.properties b/examples/simple/src/main/resources/config.properties
new file mode 100644
index 0000000..f9a2c05
--- /dev/null
+++ b/examples/simple/src/main/resources/config.properties
@@ -0,0 +1,6 @@
+pathOUT = /tmp/structsim-results
+pathParameters = parameters.txt
+pathSimulator = /tmp/structsim-simulator
+pathToSimulatorResultFile = /tmp/structsim-simulator/results/results.txt
+cuttOfPlanning = 10
+typeCuttOfPlanning = INT
diff --git a/examples/simple/src/main/resources/parameters.txt b/examples/simple/src/main/resources/parameters.txt
new file mode 100644
index 0000000..a1aff25
--- /dev/null
+++ b/examples/simple/src/main/resources/parameters.txt
@@ -0,0 +1,5 @@
+val1=1
+val2=2
+val3=3
+val4=4
+val5=5
diff --git a/structSimV1/pom.xml b/structSimV1/pom.xml
index 269efa9..a7a50d4 100644
--- a/structSimV1/pom.xml
+++ b/structSimV1/pom.xml
@@ -16,15 +16,33 @@
- junit
- junit
- 3.8.1
- test
+ org.apache.logging.log4j
+ log4j-api
+ 2.24.3
-
- com.hynnet
- jacob
- 1.18
-
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.11.4
+ test
+
+
+ org.mockito
+ mockito-core
+ 5.10.0
+ test
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Environment.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Environment.java
index fda0a15..d63833e 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Environment.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Environment.java
@@ -49,7 +49,6 @@ public class Environment implements Comparable {
*
* @param id : ID
* @param setOfParameters : List of Parameters of this Environment
- * @param idParamChanged : ID from the parameters changed in this environment
* @param probability : Probability
*/
public Environment(int id, Vector setOfParameters, double probability) {
@@ -65,7 +64,12 @@ public Environment(int id, Vector setOfParameters, double probability
*/
public Environment(int id, Environment e){
this.id = id;
- this.setOfParameters = e.setOfParameters;
+
+ this.setOfParameters = new Vector();
+ for (Parameter p : e.setOfParameters) {
+ this.setOfParameters.add(new Parameter(p)); // Constructor by copy
+ }
+
this.probability = e.probability;
this.trace = new ArrayList();
for(String s :e.trace){
@@ -73,6 +77,14 @@ public Environment(int id, Environment e){
}
}
+ /**
+ * Default constructor to facilitate the writing
+ * of the units tests of the FileManagement class
+ */
+ public Environment() {
+ this(1, new Vector(), 1);
+ }
+
/**
* Getter for id
* @return ID
@@ -129,18 +141,13 @@ public void setPathSaveResult(String pathSaveResult) {
this.pathSaveResult = pathSaveResult;
}
-
-
-
public String toStringModifier() {
String result ="" ;
for(String s : trace){
result += " " + s;
}
-
- return "Simulation ID : " + id + "\t" + "Modifier implemented : " + result ;
+ return "Simulation ID : " + id + "\t Probability : " + probability + "\t Modifier implemented : " + result;
}
-
public List getTrace() {
return trace;
@@ -150,10 +157,16 @@ public void setTrace(List trace) {
this.trace = trace;
}
+ /**
+ Allow to order environments by ascending order of probability
+ @return
+ 1 if first environment is more probable,
+ -1 if first environment is less probable,
+ 0 if they have equal probability
+ */
@Override
- public int compareTo(Environment arg0) {
- return (int)(this.probability - arg0.getProbability());
+ public int compareTo(Environment other) {
+ return Double.compare(this.probability, other.probability);
}
-
-}
+}
\ No newline at end of file
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentPlanGenerator.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentPlanGenerator.java
index 840ba51..7608815 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentPlanGenerator.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentPlanGenerator.java
@@ -20,7 +20,6 @@
package ch.hevs.silab.structuredsim.experimenthandling;
-import java.time.temporal.IsoFields;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
@@ -28,11 +27,11 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
+import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ch.hevs.silab.structuredsim.interfaces.AModifier;
-import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import ch.hevs.silab.structuredsim.interfaces.IManageModifier;
import ch.hevs.silab.structuredsim.util.FileManagement;
@@ -51,6 +50,7 @@ public class ExperimentPlanGenerator implements Runnable {
//Variable
protected Environment baseEnvironment;
protected BlockingQueue planningQueue;
+
protected Options options;
protected ASimulationSystemHandler glueCode;
private long endTime =0 ;
@@ -93,33 +93,36 @@ private void createNextEnvironments (Environment baseEnv){
int idCpt = baseEnv.getId();
int cpt = 0;
-
while(!toExplore.isEmpty()){
+ // This break statement stops the program at the right time.
+ if(options.getTypeOfCuttOfPlanning().equals("INT") && cpt >= options.getCuttOfPlanning()){
+ break;
+ }
+
parentEnv = toExplore.remove(0);
for (AModifier modifier : listModifiers) {
idCpt ++;
+
currentEnv = new Environment(idCpt, parentEnv);
+
currentEnv = modifier.applyModifier(currentEnv);
+
currentEnv.getTrace().add(modifier.getName() );
- //for(String str : currentEn)
- System.out.println("--------------------------------------------" +currentEnv.id + " " + currentEnv.trace.toString());
+
+ logger.debug("--------------------------------------------" +currentEnv.id + " " + currentEnv.trace.toString());
+
currentEnv.setProbability(parentEnv.getProbability() * modifier.getProbability());
if(options.getTypeOfCuttOfPlanning().equals("CRITERIA") &&
currentEnv.getProbability() > options.getStopCriteria()){
toExplore.add(currentEnv);
-
}
- if(options.getTypeOfCuttOfPlanning().equals("INT")&&
- cpt <= options.getCuttOfPlanning()){
+ if(options.getTypeOfCuttOfPlanning().equals("INT")) {
toExplore.add(currentEnv);
}
- else{
- break;
- }
fm.createNewFolderSimulation(currentEnv, glueCode);
addEnvToQueue(currentEnv);
@@ -127,8 +130,12 @@ private void createNextEnvironments (Environment baseEnv){
}
cpt ++;
- System.out.println("CPT : " + cpt);
- Collections.sort(toExplore);
+ logger.debug("CPT : " + cpt);
+
+ /* We sort the environments by reverse order,
+ to put the most probable one in first position */
+ toExplore.sort(Collections.reverseOrder());
+
}
}
@@ -160,11 +167,10 @@ private void addEnvToQueue(Environment e){
@Override
public void run() {
-
-
//Generate the number of Environment that we want
long currentTime = System.currentTimeMillis();
+ logger.debug("option = " + options.getTypeOfCuttOfPlanning());
switch(options.getTypeOfCuttOfPlanning()){
case "INT" :
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentResultHandler.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentResultHandler.java
index 46c362f..0e1851e 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentResultHandler.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentResultHandler.java
@@ -23,16 +23,16 @@
import java.util.Vector;
import java.util.concurrent.BlockingQueue;
+import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import ch.hevs.silab.structuredsim.util.FileManagement;
/**
* Name : ExperimentResultHandler
*
- * Description : This thread is for displaying where the results are save
+ * Description : This thread is for displaying where the results are saved
*
* Date : 25 july 2017
*
@@ -46,8 +46,8 @@ public class ExperimentResultHandler implements Runnable {
protected ASimulationSystemHandler glueCode;
private FileManagement fm;
private static final Logger logger = LogManager.getLogger(ExperimentResultHandler.class.getName());
- protected Options options;
+ protected Options options;
/**
@@ -57,8 +57,6 @@ public class ExperimentResultHandler implements Runnable {
* : BlockingQueue to get the list fulfilled
* @param glueCode
* : Class of the glueCode
- * @param options
- * : options object
*/
public ExperimentResultHandler(BlockingQueue resultsQueue, Object glueCode, FileManagement fm, Options o) {
this.resultsQueue = resultsQueue;
@@ -88,7 +86,6 @@ public void run() {
*/
if(!resultsQueue.isEmpty()){
for (String str : resultsQueue) {
- // System.out.println("result queue string : " + str);
logger.debug("Result queue string : " + str);
Vector measures = glueCode.extractMeasures(str);
int positionOfLastSlash = str.lastIndexOf("/");
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentSimulatorHandler.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentSimulatorHandler.java
index af371a1..c84d7dd 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentSimulatorHandler.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/ExperimentSimulatorHandler.java
@@ -20,12 +20,11 @@
package ch.hevs.silab.structuredsim.experimenthandling;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.PriorityBlockingQueue;
+import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import ch.hevs.silab.structuredsim.util.FileManagement;
/**
@@ -43,6 +42,7 @@ public class ExperimentSimulatorHandler implements Runnable {
protected BlockingQueue environnmentQueue;
protected BlockingQueue resultsQueue;
protected ASimulationSystemHandler glueCode;
+
protected Options options;
private FileManagement fm;
private static final Logger logger = LogManager.getLogger(ExperimentSimulatorHandler.class.getName());
@@ -54,8 +54,6 @@ public class ExperimentSimulatorHandler implements Runnable {
*
* @param environnementQueue
* : The BlockignQueue where the environment will be saved
- * @param simulationHandler
- * : Thread of the simulation
* @param o
* : options object
* @param glueCode
@@ -67,15 +65,13 @@ public ExperimentSimulatorHandler(BlockingQueue environnementQueue,
this.options = o;
this.glueCode = (ASimulationSystemHandler) glueCode;
this.resultsQueue = resultsQueue;
- // resultsQueue = new PriorityBlockingQueue();
this.fm = fm;
this.plan = plan;
}
/**
* Method to save the result
- * @param e : Environment
- * @return path where the file will be save
+ * @return path where the file will be saved
*/
@Override
public void run() {
@@ -86,22 +82,17 @@ public void run() {
do {
try {
- System.out.println("Size of the Simulation Queue : " + environnmentQueue.size());
+ logger.debug("Size of the Simulation Queue : " + environnmentQueue.size());
Environment env = environnmentQueue.take();
- //glueCode.startSimulation(env);
+
glueCode.startSimulation(options.getPathParameters());
String resultPathForThisSimulation = env.pathSaveResult+"/results_sim"+ env.getId()+ ".txt";
- System.out.println(resultPathForThisSimulation);
+ logger.debug(resultPathForThisSimulation);
fm.copyFile(options.pathToSimulatorResultFile,resultPathForThisSimulation);
fm.copyFile(options.pathToSimulatorResultFile, options.pathSimulator + "/"+env.pathSaveResult.substring(env.pathSaveResult.lastIndexOf("/")+1, env.pathSaveResult.length())+"/results_sim"+ env.id +".txt");
-
- //String pathResult = saveResult(env);
- //env.setPathSaveResult(pathResult);
resultsQueue.add(resultPathForThisSimulation);
-
-
// to get out of the loop
if (plan.isFinish) {
if (environnmentQueue.isEmpty()) {
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Measure.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Measure.java
index 2ebe09a..03da2b0 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Measure.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Measure.java
@@ -33,7 +33,7 @@
public class Measure {
- // Variable
+ // Variables
protected String key;
protected String value;
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Options.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Options.java
index 6c16eb6..f96f171 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Options.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Options.java
@@ -170,11 +170,10 @@ public String getPathToSimulatorResultFile() {
/**
* Setter for pathToSimulatorResultFolder
- * @param pathToSimulatorResultFolder
+ * @param pathToSimulatorResultFile
* */
public void setPathToSimulatorResultFile(String pathToSimulatorResultFile) {
this.pathToSimulatorResultFile = pathToSimulatorResultFile;
}
-
}
\ No newline at end of file
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Parameter.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Parameter.java
index e4f2a84..7a69f29 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Parameter.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/experimenthandling/Parameter.java
@@ -36,7 +36,6 @@ public class Parameter {
/**
* Constructor of the class Parameters
- *
* @param key : key of the parameter
* @param value : value of the parameter
*/
@@ -44,7 +43,7 @@ public Parameter(String key, double value) {
this.key = key;
this.value = value;
}
-
+
/**
* Constructor
* @param p : parameters
@@ -54,8 +53,6 @@ public Parameter (Parameter p){
this.value = p.value;
}
-
-
@Override
public String toString() {
return "key : " + key + " value : " + value;
@@ -93,6 +90,4 @@ public void setValue(double value) {
this.value = value;
}
-
-
}
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/ConcreteModifier.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/ConcreteModifier.java
new file mode 100644
index 0000000..d655f9c
--- /dev/null
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/ConcreteModifier.java
@@ -0,0 +1,79 @@
+package ch.hevs.silab.structuredsim.gluecode;
+
+import ch.hevs.silab.structuredsim.experimenthandling.Environment;
+import ch.hevs.silab.structuredsim.experimenthandling.ExperimentPlanGenerator;
+import ch.hevs.silab.structuredsim.experimenthandling.Parameter;
+import ch.hevs.silab.structuredsim.interfaces.AModifier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.Vector;
+
+public class ConcreteModifier extends AModifier {
+
+
+ private static final Logger logger = LogManager.getLogger(ConcreteModifier.class.getName());
+
+ String keyToChange;
+ char operator;
+
+ /**
+ * Value to add/substract/multiply/divide to the key
+ */
+ double delta;
+
+ public ConcreteModifier(String keyToChange, char operator, double delta, double probability) {
+ super(probability, operator + "" + delta);
+ this.keyToChange=keyToChange;
+ this.probability = probability;
+ this.operator = operator;
+ this.delta=delta;
+ }
+
+ public ConcreteModifier(String keyToChange, char operator, double delta) {
+ this(keyToChange, operator, delta, 1);
+ }
+
+ public ConcreteModifier(double delta) {
+ this("val1", '*', delta, delta);
+ }
+ public ConcreteModifier() {
+ }
+
+
+ @Override
+ public Environment applyModifier(Environment env) {
+ Vector params = env.getSetOfParameters();
+ for (Parameter p : params) {
+ logger.debug("param=" + p.getKey() + " keyToChange=" + keyToChange);
+ if (p.getKey().equals(keyToChange)) {
+ switch(operator) {
+ case '+':
+ p.setValue(p.getValue() + delta);
+ break;
+ case '-':
+ p.setValue(p.getValue() - delta);
+ break;
+ case '*':
+ p.setValue(p.getValue() * delta);
+ break;
+ case '/':
+ p.setValue(p.getValue() / delta);
+ break;
+ }
+ }
+ }
+ return env;
+ }
+
+ public static double findValue(Vector params, String key) {
+ String value = null;
+ for (Parameter p : params) {
+ if (p.getKey().equals(key)) {
+ return p.getValue();
+ }
+ }
+ return -1;
+ }
+
+}
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/MySimulator.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/MySimulator.java
new file mode 100644
index 0000000..39254db
--- /dev/null
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/MySimulator.java
@@ -0,0 +1,36 @@
+package ch.hevs.silab.structuredsim.gluecode;
+
+import java.io.*;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MySimulator {
+
+ public static void run(String pathToInputFile, String pathToResultFile) {
+ Map params = new HashMap<>();
+
+ try {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(new FileInputStream(pathToInputFile), "UTF-8"));
+ String line;
+ while ((line = in.readLine()) != null) {
+ int pos = line.indexOf("=");
+ String key = line.substring(0, pos).trim();
+ double value = Double.parseDouble(line.substring(pos + 1).trim());
+ params.put(key, value);
+ }
+ in.close();
+
+ double result = params.get("val1") * params.get("val2");
+
+ BufferedWriter bw = new BufferedWriter(new FileWriter(pathToResultFile));
+ bw.write("result=" + result);
+ bw.newLine();
+ bw.flush();
+ bw.close();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/SimpleSimulationHandler.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/SimpleSimulationHandler.java
new file mode 100644
index 0000000..1fcdad1
--- /dev/null
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/SimpleSimulationHandler.java
@@ -0,0 +1,139 @@
+package ch.hevs.silab.structuredsim.gluecode;
+
+import ch.hevs.silab.structuredsim.experimenthandling.Measure;
+import ch.hevs.silab.structuredsim.interfaces.AModifier;
+import ch.hevs.silab.structuredsim.experimenthandling.Parameter;
+import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+public class SimpleSimulationHandler extends ASimulationSystemHandler {
+
+ private List modifiers = new ArrayList();
+
+ public SimpleSimulationHandler() {
+ }
+
+ public SimpleSimulationHandler(List modifiers) {
+ this.modifiers = modifiers;
+ }
+
+
+ @Override
+ public Vector extractMeasures(String resultsFilePath) {
+ String separator = "=";
+ Vector measuresList = new Vector();
+ String measureKey;
+ String measureValue;
+ BufferedReader in;
+ try {
+ in = new BufferedReader(
+ new InputStreamReader(new FileInputStream(resultsFilePath), "UTF-8"));
+ String line = "";
+ while ((line = in.readLine()) != null) {
+
+ int pos = line.indexOf(separator);
+ measureKey = line.substring(0, pos);
+ measureValue = (line.substring(pos + 1, line.length()));
+ measuresList.add(new Measure(measureKey, measureValue));
+ }
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return measuresList;
+ }
+
+ @Override
+ public List initiateModifierList() {;
+ listModifierClass = modifiers;
+ return listModifierClass;
+ }
+
+
+ @Override
+ public Vector readParametersFile(String parametersFilePath) {
+ String separator = "=";
+ Vector parametersList = new Vector();
+ String key;
+ double value;
+ BufferedReader in;
+ try {
+ in = new BufferedReader(
+ new InputStreamReader(new FileInputStream(parametersFilePath), "UTF-8"));
+ String line = "";
+ while ((line = in.readLine()) != null) {
+ int pos = line.indexOf(separator);
+ key = line.substring(0, pos);
+ value = Double.parseDouble(line.substring(pos + 1, line.length()));
+ parametersList.add(new Parameter(key, value));
+ }
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return parametersList;
+
+ }
+
+ public Vector readParametersFile(InputStream inputStream) {
+ String separator = "=";
+ Vector parametersList = new Vector<>();
+ String key;
+ double value;
+
+ try {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(inputStream, "UTF-8"));
+ String line = "";
+ while ((line = in.readLine()) != null) {
+ int pos = line.indexOf(separator);
+ key = line.substring(0, pos);
+ value = Double.parseDouble(line.substring(pos + 1, line.length()));
+ parametersList.add(new Parameter(key, value));
+ }
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return parametersList;
+ }
+
+
+ @Override
+ public void writeParametersFile(Vector setOfParameters, String locationToStore) {
+
+ try {
+ BufferedWriter bw = new BufferedWriter(new FileWriter(locationToStore + "/myParamFile.txt"));
+ for (Parameter p: setOfParameters) {
+ bw.write(p.getKey() + "=" + p.getValue());
+ bw.newLine();
+ }
+ bw.flush();
+ bw.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void startSimulation(String pathToInputFile) {
+ String resultFile = options.getPathToSimulatorResultFile();
+ new File(resultFile).getParentFile().mkdirs();
+ try {
+ new File(resultFile).createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void stopProgram() {
+
+ }
+}
+
+
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/Simulation.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/Simulation.java
new file mode 100644
index 0000000..6ad7696
--- /dev/null
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/gluecode/Simulation.java
@@ -0,0 +1,31 @@
+package ch.hevs.silab.structuredsim.gluecode;
+
+import ch.hevs.silab.structuredsim.interfaces.AModifier;
+import ch.hevs.silab.structuredsim.interfaces.StartProgram;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Simulation extends StartProgram {
+
+ // Mock-up code for a simple simulation
+ public static void main(String[] args) throws IOException {
+
+ InputStream pathConfigFile = Simulation.class
+ .getClassLoader()
+ .getResourceAsStream("config.properties");
+
+ List modifiers = new ArrayList();
+
+ modifiers.add(new ConcreteModifier("val2", '+', 1.0, 0.5));
+ modifiers.add(new ConcreteModifier("val2", '+', 10.0, 0.5));
+
+ //Custom class
+ SimpleSimulationHandler ssh = new SimpleSimulationHandler(modifiers);
+
+ startProgram(pathConfigFile, ssh);
+
+ }
+}
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/AModifier.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/AModifier.java
index d103060..4a3519a 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/AModifier.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/AModifier.java
@@ -45,6 +45,16 @@ public AModifier(){
this.name ="AModifier";
}
+ /**
+ * This constructor is used in the integration tests
+ * @param probability
+ * @param name
+ */
+ public AModifier(double probability, String name) {
+ this.probability=probability;
+ this.name=name;
+ }
+
/**
@@ -61,8 +71,7 @@ public AModifier(){
* use the method getParameterToModify to get the Parameter.
Example : Parameters newParam = getParameterToModify(env.getSetOfParameters(), options.getValueToChange);
*
*
- * @param env : Environment. An Environment is one state of the simulation at the instant T.
- * @param o : options for the simulation
+ * @param env : Environment. An Environment is one state of the simulation at the instant T.
* @return : environment.
*/
public abstract Environment applyModifier(Environment env);
@@ -82,22 +91,11 @@ public double getProbability() {
public void setProbability(double probability) {
this.probability = probability;
}
-
-
-
public String getName() {
return name;
}
-
-
-
public void setName(String name) {
this.name = name;
}
-
-
-
-
-
}
\ No newline at end of file
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IManageParametersFile.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IManageParametersFile.java
index 272d8d1..6ca7e38 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IManageParametersFile.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IManageParametersFile.java
@@ -19,6 +19,7 @@
* */
package ch.hevs.silab.structuredsim.interfaces;
+import java.io.InputStream;
import java.util.Vector;
import ch.hevs.silab.structuredsim.experimenthandling.Parameter;
@@ -44,6 +45,15 @@ public interface IManageParametersFile {
*/
public Vector readParametersFile(String parametersFilePath);
+
+
+ /**
+ * Method to read parameters from an InputStream instead
+ * @author Matthias Gaillard
+ */
+ public Vector readParametersFile(InputStream inputStream);
+
+
/**
* Method to write a new file of parameters that will be used by your
* simulator EACH TIME that a Parameter change !
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IStartSimulation.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IStartSimulation.java
index fa996b8..8b64304 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IStartSimulation.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/IStartSimulation.java
@@ -33,7 +33,6 @@ public interface IStartSimulation {
/**
*Method to start the simulation that is an external application. The result are save in file txt
- * @param baseEnvToSimulate : Environment that will get the simulation
*/
public void startSimulation(String pathToInputFile);
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/StartProgram.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/StartProgram.java
index 724c7b0..5a2af40 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/StartProgram.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/interfaces/StartProgram.java
@@ -21,16 +21,17 @@
import java.io.IOException;
+import java.io.InputStream;
import java.util.Vector;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import ch.hevs.silab.structuredsim.experimenthandling.Environment;
import ch.hevs.silab.structuredsim.experimenthandling.ExperimentPlanGenerator;
-import ch.hevs.silab.structuredsim.experimenthandling.ExperimentResultHandler;
import ch.hevs.silab.structuredsim.experimenthandling.ExperimentSimulatorHandler;
import ch.hevs.silab.structuredsim.experimenthandling.Options;
import ch.hevs.silab.structuredsim.experimenthandling.Parameter;
+import ch.hevs.silab.structuredsim.gluecode.Simulation;
import ch.hevs.silab.structuredsim.util.FileManagement;
/**
@@ -52,13 +53,12 @@ public class StartProgram {
* @param glueCode : glue code object
* @throws IOException
*/
- public static void startProgram(String pathConfigFile, Object glueCode) throws IOException {
+ public static void startProgram(InputStream pathConfigFile, Object glueCode) throws IOException {
FileManagement fm = new FileManagement();
// Create an instance of the "GlueCode"
ASimulationSystemHandler glueCodeClass = (ASimulationSystemHandler) glueCode;
-// glueCodeClass.fileManagement = fm;
// Load the configuration properties file
Options o = fm.loadDataFromPropertiesFile(pathConfigFile);
@@ -67,8 +67,10 @@ public static void startProgram(String pathConfigFile, Object glueCode) throws I
// Get the List of the Parameters
Vector listParam = null;
- listParam = glueCodeClass.readParametersFile(o.getPathParameters());
-
+ InputStream isParams = Simulation.class
+ .getClassLoader()
+ .getResourceAsStream(o.getPathParameters());
+ listParam = glueCodeClass.readParametersFile(isParams);
// Select the Parameter to change
Environment baseEnv = new Environment(0, listParam, 1);
@@ -77,25 +79,28 @@ public static void startProgram(String pathConfigFile, Object glueCode) throws I
BlockingQueue resultQueue = new PriorityBlockingQueue();
glueCodeClass.setOptions(o);
-
- ExperimentPlanGenerator planning = new ExperimentPlanGenerator(queue, baseEnv, o, glueCodeClass, fm);
- Thread planningThread = new Thread(planning);
- planningThread.setName("Planning Thread");
- planningThread.start();
-
- ExperimentSimulatorHandler simulator = new ExperimentSimulatorHandler(queue, resultQueue, o, glueCodeClass, fm, planning);
- Thread simultationThread = new Thread(simulator);
- simultationThread.setName("Simulation Thread");
- simultationThread.start();
-
- /***
- * This thread was moved in the run method of ExperimentSimulatorHandler.
- * Because all results need to be analyse and measures extracted only after simulations done.
- * ExperimentResultHandler result = new ExperimentResultHandler(resultQueue, glueCodeClass, fm, o);
- * Thread resultThread = new Thread(result);
- * resultThread.setName("Result Thread");
- * resultThread.start();
- */
+
+ // This if statement prevents generation of theoretically infinite tree
+ if(!o.getTypeOfCuttOfPlanning().equals("CRITERIA") || o.getStopCriteria()>0) {
+ ExperimentPlanGenerator planning = new ExperimentPlanGenerator(queue, baseEnv, o, glueCodeClass, fm);
+ Thread planningThread = new Thread(planning);
+ planningThread.setName("Planning Thread");
+ planningThread.start();
+
+ ExperimentSimulatorHandler simulator = new ExperimentSimulatorHandler(queue, resultQueue, o, glueCodeClass, fm, planning);
+ Thread simultationThread = new Thread(simulator);
+ simultationThread.setName("Simulation Thread");
+ simultationThread.start();
+
+ /***
+ * This thread was moved in the run method of ExperimentSimulatorHandler.
+ * Because all results need to be analyse and measures extracted only after simulations done.
+ * ExperimentResultHandler result = new ExperimentResultHandler(resultQueue, glueCodeClass, fm, o);
+ * Thread resultThread = new Thread(result);
+ * resultThread.setName("Result Thread");
+ * resultThread.start();
+ */
+ }
}
}
\ No newline at end of file
diff --git a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/util/FileManagement.java b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/util/FileManagement.java
index f1a122d..ab51927 100644
--- a/structSimV1/src/main/java/ch/hevs/silab/structuredsim/util/FileManagement.java
+++ b/structSimV1/src/main/java/ch/hevs/silab/structuredsim/util/FileManagement.java
@@ -39,16 +39,14 @@
import java.util.LinkedHashMap;
import java.util.Properties;
import java.util.Vector;
-import java.util.concurrent.BlockingQueue;
+import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ch.hevs.silab.structuredsim.experimenthandling.Environment;
import ch.hevs.silab.structuredsim.experimenthandling.Measure;
import ch.hevs.silab.structuredsim.experimenthandling.Options;
-import ch.hevs.silab.structuredsim.experimenthandling.Parameter;
-import ch.hevs.silab.structuredsim.interfaces.ASimulationSystemHandler;
/**
* The goal of this class is to manage parameters and/or results files.
@@ -69,6 +67,7 @@ public class FileManagement {
// Variables
protected String filename;
+
protected Options options;
private String pathResult, pathSimulator;
private static final Logger logger = LogManager.getLogger(FileManagement.class.getName());
@@ -119,13 +118,13 @@ public String contentOfAFile() throws IOException {
*/
public void moveFile(String originFile, String destinationFile) {
Path originPath = Paths.get(originFile);
+ if (!Files.exists(originPath)) return;
Path destinationPath = Paths.get(destinationFile);
try {
Files.move(originPath, destinationPath, REPLACE_EXISTING);
} catch (IOException e) {
logger.error("Impossible to move this file");
- //System.out.println("Impossible to move this file");
e.printStackTrace();
}
}
@@ -143,32 +142,13 @@ public void copyFile(String file, String destination) {
File dest = new File(destination);
try {
- Files.copy(fileToCopy.toPath(), dest.toPath());
+ Files.copy(fileToCopy.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
logger.error("This file in this folder already exist");
- //e.printStackTrace();
}
}
- /**
- * This method create a new empty file in a specific folder. If the folder
- * is not existing, the method create it.
- *
- * @param folderPath
- * : The path to the folder
- * @param filename
- * : The name of the file to save.
- */
- /*
- * public void createFile(String folderPath, String filename) { File file =
- * new File(folderPath + filename); file.getParentFile().mkdir(); try {
- * file.createNewFile(); } catch (IOException e) {
- * System.out.println("Sorry but this folder already exist!!!!");
- * e.printStackTrace(); } }
- *
- */
-
/** Method to create an empty Folder
*
* @param folderPath : Path
@@ -207,38 +187,6 @@ public String saveSimultationResult(String result, Environment env) throws IOExc
}
- /**
- * Method to save a summaryFile where all the result will be summarized.
- *
- * @param resultQueue : the queue with results of simulations
- */
- /* public void saveSummaryFile(BlockingQueue resultQueue) {
-
- do {
-
- try {
- BufferedWriter bw = new BufferedWriter(new FileWriter(options.getFolderPathOUT() + "/SummaryFile.txt"));
- bw.write("RunId \t ParameterChanged \t Value \t Probability \t Path");
- bw.newLine();
-
- for (Environment env : resultQueue) {
- String line = env.toString();
- bw.write(line);
- bw.newLine();
- }
-
- bw.flush();
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- logger.error("Error to save the summary File");
- }
-
- } while (resultQueue.isEmpty());
-
- }
- */
-
/**
* Method to load data from a properties file and put in an Hashmap
*
@@ -258,7 +206,8 @@ public Options loadDataFromPropertiesFile(String filePath) {
e.printStackTrace();
logger.error("Error to load Data from Properties file");
}
- String cuttOfValue = "";
+
+ String cuttOfValue = properties.getProperty("cuttOfPlanning", "");
for (String key : properties.stringPropertyNames()) {
@@ -311,6 +260,61 @@ public Options loadDataFromPropertiesFile(String filePath) {
return options;
}
+ /**
+ * Same method as the previous one,
+ * but using an InputStream instead of a String
+ * @param ips
+ * @return Options
+ */
+ public Options loadDataFromPropertiesFile(InputStream ips) {
+ Properties properties = new Properties();
+ try {
+ properties.load(ips);
+ ips.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ logger.error("Error to load Data from Properties file");
+ }
+
+ // 1. Read all simple values
+ options.setPathParameters(properties.getProperty("pathParameters"));
+ options.setFolderPathOUT(properties.getProperty("pathOUT"));
+ options.setPathSimulator(properties.getProperty("pathSimulator"));
+ options.setPathToSimulatorResultFile(properties.getProperty("pathToSimulatorResultFile"));
+
+ // 2. Treat independant values
+ String cuttOfValue = properties.getProperty("cuttOfPlanning", "");
+ String typeCuttOf = properties.getProperty("typeCuttOfPlanning", "");
+
+ options.setTypeOfCuttOfPlanning(typeCuttOf);
+
+ switch (typeCuttOf) {
+ case "INT":
+ options.setCuttOfPlanning(Integer.parseInt(cuttOfValue));
+ break;
+ case "DAY":
+ Calendar cal1 = Calendar.getInstance();
+ cal1.set(Calendar.DATE, Integer.parseInt(cuttOfValue));
+ options.setCuttOfPlanningH(cal1);
+ break;
+ case "HOURS":
+ Calendar cal2 = Calendar.getInstance();
+ cal2.set(Calendar.HOUR_OF_DAY, Integer.parseInt(cuttOfValue));
+ options.setCuttOfPlanningH(cal2);
+ break;
+ case "MINUTES":
+ Calendar cal3 = Calendar.getInstance();
+ cal3.set(Calendar.MINUTE, Integer.parseInt(cuttOfValue));
+ options.setCuttOfPlanningH(cal3);
+ break;
+ case "CRITERIA":
+ options.setStopCriteria(Double.parseDouble(cuttOfValue));
+ break;
+ }
+
+ return options;
+ }
+
/**
* Method to write something in a properties file parameters :
*