Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.class
ResultSim/
all.log
structSimV1/target/
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions examples/simple/config.properties
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/simple/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
val1=1
val2=2
val3=3
val4=4
val5=5
37 changes: 37 additions & 0 deletions examples/simple/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>example</groupId>
<artifactId>simple-simulation</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>hevs.ch.silab</groupId>
<artifactId>hevs.ch.silab</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>example.Simulation</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
31 changes: 31 additions & 0 deletions examples/simple/run.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions examples/simple/src/main/java/example/Simulation.java
Original file line number Diff line number Diff line change
@@ -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<AModifier> 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);
}
}
6 changes: 6 additions & 0 deletions examples/simple/src/main/resources/config.properties
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/simple/src/main/resources/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
val1=1
val2=2
val3=3
val4=4
val5=5
36 changes: 27 additions & 9 deletions structSimV1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,33 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.24.3</version>
</dependency>
<dependency>
<groupId>com.hynnet</groupId>
<artifactId>jacob</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading
Loading