Commit 3d351721 authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

Merge branch 'master' into...

Merge branch 'master' into 241-new-flag-to-compute-metric-for-the-quality-of-the-stepcircleoptimizer
parents d5d08866 0f0d9a0a
......@@ -70,7 +70,7 @@ stages:
artifacts:
when: on_failure
paths:
- "log_dir"
- "vadere_logs"
expire_in: 1 week
when: on_success
......
......@@ -69,6 +69,7 @@
* vadere.jar -> vadere-gui.jar
* postvis.jar -> vadere-postvis.jar
* vadere-console.jar -> remained unchanged
- Header in output file have now the following form "[NAME]-PID[ID]". This avoids name conflicts and makes mapping to the relevant processor easy and fast.
- Migration to Java 11 (OpenJDK).
- Removed directory `Documentation/version-control` which contained the Git hooks. The Git hooks are not required anymore. Instead, added `git rev-parse HEAD` to file `VadereSimulator/pom.xml` to create `VadereSimulator/resources/current_commit_hash.txt` during each build via `mvn compile`.
**Note:** The file `current_commit_hash.txt` is created during Maven's validation phase, i.e., before the actual build.
......
......@@ -21,7 +21,7 @@ short_timeout_in_seconds = 2 * 60
def parse_command_line_arguments():
parser = argparse.ArgumentParser(description="Run all scenario files.")
parser.add_argument("--scenario", "-s", type=str, nargs="?", help="Run only the given scenario file and not all. E.g. \"VadereModelTests/TestOSM/scenarios/basic_2_density_discrete_ca.scenario\"")
parser.add_argument("scenario", type=str, nargs="?", help="Run only the given scenario file and not all. E.g., \"VadereModelTests/TestOSM/scenarios/basic_2_density_discrete_ca.scenario\"")
args = parser.parse_args()
......@@ -80,13 +80,10 @@ def find_scenario_files(path="VadereModelTests", scenario_search_pattern = "*.sc
def run_scenario_files_with_vadere_console(scenario_files, vadere_console="VadereSimulator/target/vadere-console.jar", scenario_timeout_in_sec=short_timeout_in_seconds):
output_dir = "output"
log_dir = "log_dir"
log_base_dir = "vadere_logs"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
makedirs_if_non_existing(output_dir)
makedirs_if_non_existing(log_base_dir)
total_scenario_files = len(scenario_files)
......@@ -98,10 +95,18 @@ def run_scenario_files_with_vadere_console(scenario_files, vadere_console="Vader
try:
print("Running scenario file ({}/{}): {}".format(i + 1, total_scenario_files, scenario_file))
# A scenario filename has the form "VadereModelTests/TestOSM/scenarios/chicken_floorfield_ok.scenario"
# Use second-level directory as subdirectory for logging (e.g., "TestOSM").
log_sub_dir = scenario_file.split(os.path.sep)[1]
log_dir = os.path.join(".", log_base_dir, log_sub_dir)
makedirs_if_non_existing(log_dir)
scenario_name = os.path.basename(scenario_file).split('.')[0]
log_file = os.path.join(".", log_dir, scenario_name + ".log")
log_file = os.path.join(log_dir, scenario_name + ".log")
print(log_file)
print(" Log file: " + log_file)
# Measure wall time and not CPU time.
wall_time_start = time.time()
......@@ -124,17 +129,16 @@ def run_scenario_files_with_vadere_console(scenario_files, vadere_console="Vader
except subprocess.TimeoutExpired as exception:
print("Scenario file failed: {}".format(scenario_file))
print("-> Reason: timeout after {} s".format(exception.timeout))
failed_summary.append("Scenario file failed: {}".format(scenario_file))
failed_summary.append("-> Reason: timeout after {} s".format(exception.timeout))
failed_scenarios_with_exception.append((scenario_file, exception))
except subprocess.CalledProcessError as exception:
prefix = ""
if "TestOSM" in scenario_file:
prefix = " * OSM * "
print(prefix + "Scenario file failed: {}".format(scenario_file))
print("Scenario file failed: {}".format(scenario_file))
print("-> Reason: non-zero return value {}".format(exception.returncode))
print(" {}".format(read_first_error_linies(exception.stderr)))
failed_summary.append(prefix + "Scenario file failed: {}".format(scenario_file))
failed_summary.append("Scenario file failed: {}".format(scenario_file))
failed_summary.append("-> Reason: non-zero return value {}".format(exception.returncode))
failed_summary.append(" {}".format(read_first_error_linies(exception.stderr)))
......@@ -145,6 +149,10 @@ def run_scenario_files_with_vadere_console(scenario_files, vadere_console="Vader
return {"passed": passed_scenarios, "failed": failed_scenarios_with_exception, "failed_summary": failed_summary}
def makedirs_if_non_existing(directory):
if not os.path.exists(directory):
os.makedirs(directory)
def read_first_error_linies(error_byte_string):
err_string_lines = error_byte_string.decode('utf-8').split('\n')
if len(err_string_lines) >= 2:
......
%% Cell type:code id: tags:
``` python
import json
import numpy as np
import pandas as pd
import math
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
file = "./data/trajectories_distance.txt"
real_file = "./data/KO/ko-240-120-240/ko-240-120-240_combined_MB.txt"
f = open(file, "r")
header = f.readline();
trajectories = dict({});
for row in f:
s = row.split(" ");
pedId = int(s[0]);
footsteps = json.loads(s[1]);
trajectories[pedId] = footsteps[0]['footSteps'];
def get_trajectory(pedId):
return trajectories[pedId]
def get_footstep(trajectory, i):
return trajectory[i];
def start_time(trajectory):
return trajectory[0]['startTime'];
def max_start_time(trajectories):
return max(map(lambda i: start_time(trajectories[i]), trajectories))
def end_time(trajectory):
return trajectory[-1]['endTime'];
def min_end_time(trajectories):
return min(map(lambda i: end_time(trajectories[i]), trajectories))
def length(fs):
start = fs['start'];
end = fs['end'];
x1 = start['x'];
y1 = start['y'];
x2 = end['x'];
y2 = end['y'];
dx = x1-x2;
dy = y1-y2;
return np.sqrt(dx*dx + dy*dy);
def trajectory_length(trajectory):
return sum(map(lambda fs : length(fs), trajectory))
def direction(fs):
start = fs['start'];
end = fs['end'];
x1 = start['x'];
y1 = start['y'];
x2 = end['x'];
y2 = end['y'];
return np.array([x2-x1, y2-y1]);
def duration(fs):
startTime = fs['startTime'];
endTime = fs['endTime'];
return endTime-startTime;
def speed(fs):
return length(fs) / duration(fs);
def is_between(fs, time):
startTime = fs['startTime'];
endTime = fs['endTime'];
return startTime <= time and time < endTime;
def footstep(trajectory, time):
l = list(filter(lambda fs : is_between(fs, time), trajectory))
assert len(l) <= 1;
if len(l) == 1:
return l[0];
def position(trajectory, time):
fs = footstep(trajectory, time);
if fs != None:
startTime = fs['startTime'];
endTime = fs['endTime'];
dur = duration(fs);
partial_dur = time - startTime;
ratio = partial_dur / dur;
start = fs['start'];
x1 = start['x'];
y1 = start['y'];
l = length(fs);
if l == 0.0:
return np.array([x1, y1])
else:
partial_l = l * ratio;
v = direction(fs) / l * partial_l;
return np.array([x1, y1]) + v;
def cut(trajectory, sTime, eTime):
return list(filter(lambda fs : fs['startTime'] >= sTime and fs['endTime'] < eTime, trajectory))
def cut_soft(trajectory, sTime, eTime):
return list(filter(lambda fs : fs['startTime'] >= sTime and fs['startTime'] < eTime, trajectory))
def euclid_d(traj1, traj2, times):
"""Computes the total (Euclidean) distance between two trajectories at certain times."""
return 0
sT = max([start_time(traj1), start_time(traj2)])
eT = min([end_time(traj1), end_time(traj2)])
filtered_times = list(filter(lambda t: t >= sT and t <= eT, times))
overlaps = len(filtered_times)
if overlaps == 0: