Commit f3d1d31d authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Merge branch 'develop' into jsonTransform

parents 0a5cdb64 af25b04e
Pipeline #64167 failed with stages
in 6 minutes and 29 seconds
# # GitLab CI Jobs
#
# Each of the jobs defined here is triggered by GitLab's CI pipeline.
#
# ## GitLab YAML Job Description Syntax
#
# <job_name>: # Job name which is displayed in web interface.
# stage: <stage_name> # <build|test|deploy>: these stages are executed
# # one after another. A stage can contain multiple
# # jobs.
# script:
# - <arbitrary_commands> # Here you can execute arbitratry terminal
# # commands. If any of the commands return a
# # non-zero exit code, the job fails.
#
# ## Maven Syntax for Skipping Unit Tests
#
# General syntax to execute unit tests:
#
# ```
# mvn test
# ```
#
# The comma-separated list of tests after "-Dtest=<list>" is skipped. All other
# tests are executed normally:
#
# ```
# mvn -Dtest=!TestClassA,!TestClassB,!TestClassC
# ```
#
# **Note:** on some CI instances the exclamation mark must be escaped by a
# backslash. Otherwise, it is interpreted by the executing shell as special
# command.
#
# ## Unit Test Limitations
#
# **Watch out:** OpenCL code cannot be run on virtual machines where tests are
# executed. Therefore, skip this tests.
unit_tests_with_coverage:
# A job is always executed within a stage.
# If no stage is set, it defaults to 'test'.
stage: test
# Here you can execute arbitrate terminal commands.
# If any of the commands returns a non zero exit code the job fails.
#
# Watch out: OpenCL code cannot be run on virtual machine. Therefore,
# skip this tests.
#
# The comma-separated list of tests after "-Dtest=<list>" is skipped.
# All other tests are executed normally.
#
# Watch out: on some CI instances the exclamation mark must be escaped by a
# backslash. Otherwise, it is interpreted by the executing shell as special
# command.
#
# Following syntaxes allow you to skip whole classes and single methods:
#
# #Exclude one test class
# mvn test -Dtest=!LegacyTest
# # Exclude one test method
# mvn verify -Dtest=!LegacyTest#testFoo
# # Exclude two test methods
# mvn verify -Dtest=!LegacyTest#testFoo+testBar
# # Exclude a package with a wildcard (*)
# mvn test -Dtest=!com.mycompany.app.Legacy*
script:
- mvn clean
- mvn test -Dtest=!TestConvolution,!TestBitonicSort,!TestCLLinkedList
- python3 Tools/collect_line_and_branch_coverage.py
- mvn -Dtest=!TestConvolution,!TestBitonicSort,!TestCLLinkedList test
- python3 Tools/ContinuousIntegration/collect_line_and_branch_coverage.py
run_scenario_files:
stage: deploy
script:
- mvn clean
- mvn package -Dmaven.test.skip=true
- python3 Tools/run_vadere_console_with_all_scenario_files.py
- mvn -Dmaven.test.skip=true package
- python3 Tools/ContinuousIntegration/run_vadere_console_with_all_scenario_files.py
......@@ -67,8 +67,9 @@ def print_averaged_line_coverage(coverage_data):
averaged_line_coverage = int(round(summed_line_coverage_data / total_modules, 0))
averaged_branch_coverage = int(round(summed_branch_coverage_data / total_modules, 0))
print("Analyzed modules: {}".format(sorted(coverage_data.keys())))
print("Line Coverage: Total {}%".format(averaged_line_coverage))
print("Branch Coverage: {}%".format(averaged_branch_coverage))
print("Branch Coverage: Total {}%".format(averaged_branch_coverage))
if __name__ == "__main__":
module_names = get_modules_from_pom_file()
......
......@@ -13,6 +13,7 @@ import os
import re
import shutil
import subprocess
import time
def find_scenario_files(path="VadereModelTests"):
scenario_search_pattern = "*.scenario"
......@@ -33,7 +34,7 @@ def find_scenario_files(path="VadereModelTests"):
print("Total scenario files: {}".format(len(scenario_files)))
print("Exclude patterns: {}".format(exclude_patterns))
return scenario_files
return sorted(scenario_files)
def run_scenario_files_with_vadere_console(scenario_files, vadere_console="VadereGui/target/vadere-console.jar", scenario_timeout_in_sec=60):
output_dir = "output"
......@@ -45,13 +46,21 @@ def run_scenario_files_with_vadere_console(scenario_files, vadere_console="Vader
for i, scenario_file in enumerate(scenario_files):
print("Running scenario file ({}/{}): {}".format(i + 1, total_scenario_files, scenario_file))
# Measure wall time and not cpu because it is the easiest.
wall_time_start = time.time()
# Use timout feature, check return value and capture stdout/stderr to a PIPE (use completed_process.stdout to get it).
completed_process = subprocess.run(args=["java", "-jar", vadere_console, scenario_file, output_dir],
completed_process = subprocess.run(args=["java", "-enableassertions", "-jar", vadere_console, scenario_file, output_dir],
timeout=scenario_timeout_in_sec,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
print("Finished scenario file: {}".format(scenario_file))
wall_time_end = time.time()
wall_time_delta = wall_time_end - wall_time_start
print("Finished scenario file ({:.1f} s): {}".format(wall_time_delta, scenario_file))
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
......
......@@ -97,10 +97,11 @@
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<enableAssertions>true</enableAssertions>
<excludes>
<exclude></exclude>
</excludes>
<failIfNoTests>false</failIfNoTests>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
......
......@@ -171,10 +171,11 @@
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<enableAssertions>true</enableAssertions>
<excludes>
<exclude></exclude>
</excludes>
<failIfNoTests>false</failIfNoTests>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
......
......@@ -6,13 +6,22 @@ import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.simulator.projects.dataprocessing.processor.PedestrianOSMStrideLengthProcessor;
import org.vadere.state.scenario.*;
import org.vadere.state.simulation.Step;
import org.vadere.state.simulation.Trajectory;
import org.vadere.util.geometry.shapes.VPoint;
import javax.swing.text.html.Option;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;
import java.io.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.awt.geom.PathIterator.*;
......@@ -57,7 +66,7 @@ public class TikzGenerator {
translationTable[SEG_LINETO] = "to (%f,%f) ";
translationTable[SEG_QUADTO] = ".. controls (%f,%f) .. (%f,%f) ";
translationTable[SEG_CUBICTO] = ".. controls (%f,%f) and (%f,%f) .. (%f,%f) ";
translationTable[SEG_CLOSE] = "to cycle;";
translationTable[SEG_CLOSE] = "";
}
public void generateTikz(final File file, final boolean generateCompleteDocument) {
......@@ -118,7 +127,7 @@ public class TikzGenerator {
DefaultSimulationConfig config = model.getConfig();
Topography topography = model.getTopography();
// Draw background elements first, then agents.
// Draw background elements first, then other scenario elements on toph.
generatedCode += "% Ground\n";
String groundTextPattern = (config.isShowGrid()) ? "\\draw[help lines] (%f,%f) grid (%f,%f);\n" : "\\fill[white] (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(groundTextPattern,
......@@ -130,7 +139,7 @@ public class TikzGenerator {
if (config.isShowSources()) {
generatedCode += "% Sources\n";
for (Source source : topography.getSources()) {
generatedCode += String.format("\\fill[SourceColor] %s\n", generatePathForScenarioElement(source));
generatedCode += String.format("\\fill[SourceColor] %s;\n", generatePathForScenarioElement(source));
}
} else {
generatedCode += "% Sources (not enabled in config)\n";
......@@ -139,7 +148,7 @@ public class TikzGenerator {
if (config.isShowTargets()) {
generatedCode += "% Targets\n";
for (Target target : topography.getTargets()) {
generatedCode += String.format("\\fill[TargetColor] %s\n", generatePathForScenarioElement(target));
generatedCode += String.format("\\fill[TargetColor] %s;\n", generatePathForScenarioElement(target));
}
} else {
generatedCode += "% Targets (not enabled in config)\n";
......@@ -148,7 +157,7 @@ public class TikzGenerator {
if (config.isShowObstacles()) {
generatedCode += "% Obstacles\n";
for (Obstacle obstacle : topography.getObstacles()) {
generatedCode += String.format("\\fill[ObstacleColor] %s\n", generatePathForScenarioElement(obstacle));
generatedCode += String.format("\\fill[ObstacleColor] %s;\n", generatePathForScenarioElement(obstacle));
}
} else {
generatedCode += "% Obstacles (not enabled in config)\n";
......@@ -163,7 +172,18 @@ public class TikzGenerator {
generatedCode += "% Stairs (not enabled in config)\n";
}
// TODO: maybe, draw also trajectories.
if (config.isShowTrajectories()) {
generatedCode += "% Trajectories\n";
if (model instanceof PostvisualizationModel) {
generatedCode += drawTrajectories((PostvisualizationModel)model);
} else {
generatedCode += String.format("%% Passed model %s does not contain trajectories\n", model.getClass().getSimpleName());
}
} else {
generatedCode += "% Trajectories (not enabled in config)\n";
}
if (config.isShowPedestrians()) {
generatedCode += "% Agents\n";
generatedCode += drawAgents(config);
......@@ -174,6 +194,51 @@ public class TikzGenerator {
return generatedCode;
}
private String drawTrajectories(PostvisualizationModel model) {
// Use a thread-safe string implementation because streams are used here.
final StringBuffer generatedCode = new StringBuffer("");
Stream<Trajectory> trajectoryStream = model.getAlivePedestrians();
Step currentTimeStep = model.getStep().orElseGet(null);
if (currentTimeStep != null) {
trajectoryStream.forEach(trajectory -> {
Stream<VPoint> trajectoryPoints = trajectory.getPositionsReverse(currentTimeStep);
// Use a newline ("to\n") for joining because TeX could possibly choke up on long lines.
String trajectoryAsTikzString = trajectoryPoints
.map(point -> String.format("(%f,%f)", point.x, point.y))
.collect(Collectors.joining(" to\n"));
String coloredTrajectory = applyAgentColorToTrajectory(trajectoryAsTikzString, trajectory.getAgent(currentTimeStep));
int pedestrianId = trajectory.getPedestrianId();
Optional<Step> trajectoryEndStep = trajectory.getEndStep();
String trajectoryEndStepAsString = (trajectoryEndStep.isPresent()) ? "" + trajectoryEndStep.get().toString() : "unknown end step" ;
String currentTimeStepAsString = currentTimeStep.toString();
generatedCode.append(String.format("%% Trajectory Agent %d @ step %s of %s\n", pedestrianId, currentTimeStepAsString, trajectoryEndStepAsString));
generatedCode.append(coloredTrajectory);
});
}
return generatedCode.toString();
}
private String applyAgentColorToTrajectory(String trajectory, Optional<Agent> agent) {
String colorString = "AgentColor";
if (agent.get() instanceof Pedestrian) {
Pedestrian pedestrian = (Pedestrian)agent.get();
Color pedestrianColor = renderer.getAgentRender().getColor(pedestrian);
colorString = String.format("{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
}
return String.format("\\draw[draw=%s]\n%s;\n", colorString, trajectory);
}
@NotNull
private String drawAgents(DefaultSimulationConfig config) {
String generatedCode = "";
......@@ -185,8 +250,8 @@ public class TikzGenerator {
Color pedestrianColor = renderer.getAgentRender().getColor(pedestrian);
Shape pedestrianShape = renderer.getAgentRender().getShape(pedestrian);
String colorString = String.format("{rgb,255:red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
generatedCode += String.format("\\fill[fill=%s] %s\n", colorString, generatePathForShape(pedestrianShape));
String colorString = String.format("{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
generatedCode += String.format("\\fill[fill=%s] %s;\n", colorString, generatePathForShape(pedestrianShape));
} catch (ClassCastException cce) {
logger.error("Error casting to Pedestrian");
cce.printStackTrace();
......@@ -222,7 +287,7 @@ public class TikzGenerator {
pathIterator.next();
}
return generatedPath;
return generatedPath.trim();
}
private String generatePathForShape(Shape shape) {
......@@ -239,7 +304,7 @@ public class TikzGenerator {
pathIterator.next();
}
return generatedPath;
return generatedPath.trim();
}
private String convertJavaToTikzPath(int type, float[] coords) {
......
......@@ -103,10 +103,11 @@
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<enableAssertions>true</enableAssertions>
<excludes>
<exclude></exclude>
</excludes>
<failIfNoTests>false</failIfNoTests>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
......
......@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class GroupSourceControllerTest extends TestSourceControllerUsingConstantSpawnRate {
......@@ -230,7 +231,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
pedestrianCountEquals(3);
}
@Test
@Test(expected = RuntimeException.class)
public void testSpawnNumber() {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setSpawnNumber(10)
......@@ -240,8 +241,11 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
first().sourceController.update(1);
pedestrianCountEquals(10 * 4);
first().sourceController.update(2);
pedestrianCountEquals(20 * 4);
first().sourceController.update(2); // use random positioning thus not
// not optimal and thus not enough
// space for all
fail("should not be reached. Exception expected");
}
@Test
......
......@@ -67,10 +67,11 @@
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<enableAssertions>true</enableAssertions>
<excludes>
<exclude></exclude>
</excludes>
<failIfNoTests>false</failIfNoTests>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
......
......@@ -80,7 +80,7 @@ import java.util.stream.IntStream;
public class SpawnArray {
private static Logger logger = LogManager.getLogger(SpawnArray.class);
private static final double EPSILON = 0.01;
public static final double OVERLAPP_EPSILON = 0.4;
private final VPoint[] spawnPoints;
private final VRectangle spawnElementBound;
// number of spawn elements in x and y Dimension.
......@@ -159,7 +159,7 @@ public class SpawnArray {
public LinkedList<VPoint> getNextSpawnPoints(int maxPoints, final List<DynamicElement> neighbours) {
return spawnPoints(maxPoints,
neighbours,
(n, p) -> n.getShape().getCentroid().equals(p, EPSILON) ,
(n, p) -> n.getShape().getCentroid().equals(p, OVERLAPP_EPSILON) ,
len -> startWith(nextIndex, len)); // define spawn order (use next index)
}
......@@ -170,7 +170,7 @@ public class SpawnArray {
public LinkedList<VPoint> getNextRandomSpawnPoints(int maxPoints, Random rnd, final List<DynamicElement> neighbours) {
return spawnPoints(maxPoints,
neighbours,
(n, p) -> n.getShape().getCentroid().equals(p, EPSILON) ,
(n, p) -> n.getShape().getCentroid().equals(p, OVERLAPP_EPSILON) ,
len -> shufflePoints(rnd, len)); // define spawn order (use random index)
}
......@@ -262,7 +262,7 @@ public class SpawnArray {
GroupPlacementHelper pHelper = getHelper(groupSize);
return nextFreeGroupPos(pHelper,
neighbours,
(n,p) -> n.getShape().getCentroid().equals(p, EPSILON),
(n,p) -> n.getShape().getCentroid().equals(p, OVERLAPP_EPSILON),
len -> startWith(nextGroupPos.getOrDefault(pHelper.getGroupSize(), 0), len));
}
......@@ -270,7 +270,7 @@ public class SpawnArray {
GroupPlacementHelper pHelper = getHelper(groupSize);
return nextFreeGroupPos(pHelper,
neighbours,
(n,p) -> n.getShape().getCentroid().equals(p, EPSILON),
(n,p) -> n.getShape().getCentroid().equals(p, OVERLAPP_EPSILON),
len -> shufflePoints(rnd, len));
}
......
......@@ -126,10 +126,10 @@ public class SpawnArrayTest {
VPoint[] spawnPoints = spawnArray.getSpawnPoints();
List<DynamicElement> dynamicElements2 = createMock(0.5,
spawnPoints[12], // direct match (use next)
spawnPoints[13].add(new VPoint(0, 0.0003)), // match within Epsilon (use next)
spawnPoints[14].add(new VPoint(0.3, 0)) // match outside Epsilon (use this one)
spawnPoints[13].add(new VPoint(0, SpawnArray.OVERLAPP_EPSILON - 0.1)), // match within Epsilon (use next)
spawnPoints[14].add(new VPoint(SpawnArray.OVERLAPP_EPSILON + 0.1, 0)) // match outside Epsilon (use this one)
);
assertEquals("Point does not match", spawnArray.getNextSpawnPoints(1, dynamicElements2).getFirst(), spawnPoints[14]);
assertEquals("Point does not match", spawnPoints[14], spawnArray.getNextSpawnPoints(1, dynamicElements2).getFirst());
assertEquals("Next Element does not match", 15, spawnArray.getNextSpawnPointIndex());
}
......@@ -326,8 +326,8 @@ public class SpawnArrayTest {
// do not directly overlap with each other.
List<DynamicElement> dynamicElements2 = createMock(0.5,
spawnPoints[1], // direct match (use next)
spawnPoints[2].add(new VPoint(0.0003, 0)), // match within Epsilon (use next)
spawnPoints[3].add(new VPoint(0.3, 0.3)) // match outside Epsilon (use this one)
spawnPoints[2].add(new VPoint(SpawnArray.OVERLAPP_EPSILON - 0.1, 0)), // match within Epsilon (use next)
spawnPoints[3].add(new VPoint(SpawnArray.OVERLAPP_EPSILON + 0.1, SpawnArray.OVERLAPP_EPSILON + 0.1)) // match outside Epsilon (use this one)
);
group = spawnArray.getNextGroup(6, dynamicElements2);
assertEquals(spawnPoints[3], group.pollFirst());
......
......@@ -72,10 +72,11 @@
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<enableAssertions>true</enableAssertions>
<excludes>
<exclude></exclude>
</excludes>
<failIfNoTests>false</failIfNoTests>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment