IMO Test 5 — Response time¶
Definition¶
Occupants must respect their assigned pre-movement response times before starting to evacuate.
This implementation uses ten occupants in an 8 m × 5 m room with a single exit. Response times are sampled from a uniform distribution between 10 and 100 seconds.
Source: IMO MSC.1/Circ.1533, Annex 3, Test 5.
In [1]:
from datetime import datetime
print(f"Executed on {datetime.now().astimezone()}")
Executed on 2026-12-01 15:30:08.475204+00:00
In [2]:
import sys
from pathlib import Path
from types import SimpleNamespace
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from shapely import wkt
repository = Path.cwd().parents[1]
sys.path.insert(0, str(repository / "standards"))
sys.path.insert(0, str(repository / "standards" / "rimea"))
sys.path.insert(0, str(repository / "tests" / "vv"))
In [3]:
import numpy as np
# House style for the V&V figures (plain matplotlib; applied per figure via rc_context).
from matplotlib.colors import to_rgba
from matplotlib.lines import Line2D
from matplotlib.patches import Patch, PathPatch
from matplotlib.patches import Polygon as MplPolygon
from matplotlib.path import Path as MplPath
VV_BLUE, VV_ORANGE, VV_RED, VV_GREEN = "#0072B2", "#E69F00", "#D55E00", "#009E73"
VV_RC = {
"figure.facecolor": "white", "axes.facecolor": "white", "figure.dpi": 150,
"font.family": "DejaVu Sans", "font.size": 10,
"axes.grid": True, "grid.color": "#e5e5e5", "grid.linewidth": 0.8, "axes.axisbelow": True,
"axes.edgecolor": "lightgrey", "axes.labelcolor": "dimgrey",
"axes.titlecolor": "#333333", "axes.titleweight": "normal", "axes.titlesize": 11,
"axes.spines.left": False, "axes.spines.bottom": False,
"axes.spines.top": False, "axes.spines.right": False,
"xtick.color": "dimgrey", "ytick.color": "dimgrey",
"xtick.major.size": 0, "ytick.major.size": 0,
"legend.frameon": True, "legend.facecolor": "white", "legend.framealpha": 0.8,
"legend.edgecolor": "lightgrey", "legend.labelcolor": "dimgrey", "legend.fontsize": 9,
}
def vv_polygon_patch(geom, **kwargs):
"""Matplotlib patch for a shapely (Multi)Polygon, holes included."""
verts, codes = [], []
for part in getattr(geom, "geoms", [geom]):
for ring in [part.exterior, *part.interiors]:
xy = np.asarray(ring.coords)
verts.extend(xy)
codes += [MplPath.MOVETO] + [MplPath.LINETO] * (len(xy) - 2) + [MplPath.CLOSEPOLY]
return PathPatch(MplPath(verts, codes), **kwargs)
def vv_draw_scenario(ax, scenario, starts=True, pad=0.04):
"""Draw walkable area, exits and start areas of a loaded scenario; return legend handles."""
ax.add_patch(vv_polygon_patch(scenario.walkable_polygon, facecolor="#eeeeee",
edgecolor="dimgrey", linewidth=1.4, zorder=1))
handles = [Patch(facecolor="#eeeeee", edgecolor="dimgrey", label="walkable area")]
if starts:
for dist in scenario.distributions.values():
ax.add_patch(MplPolygon(dist["coordinates"], closed=True,
facecolor=to_rgba(VV_BLUE, 0.15), edgecolor=VV_BLUE,
linestyle="--", linewidth=1.2, hatch="..", zorder=2))
handles.append(Patch(facecolor=to_rgba(VV_BLUE, 0.15), edgecolor=VV_BLUE,
linestyle="--", hatch="..", label="start area"))
for ex in scenario.exits.values():
ax.add_patch(MplPolygon(ex["coordinates"], closed=True,
facecolor=to_rgba(VV_RED, 0.35), edgecolor=VV_RED,
linewidth=1.2, hatch="///", zorder=3))
if scenario.exits:
handles.append(Patch(facecolor=to_rgba(VV_RED, 0.35), edgecolor=VV_RED,
hatch="///", label="exit"))
minx, miny, maxx, maxy = scenario.walkable_polygon.bounds
m = pad * max(maxx - minx, maxy - miny)
ax.set_xlim(minx - m, maxx + m)
ax.set_ylim(miny - m, maxy + m)
ax.set_aspect("equal")
ax.grid(False)
ax.set_xlabel("x [m]")
ax.set_ylabel("y [m]")
return handles
def vv_agent_count(scenario):
"""Total number of agents placed by the scenario's start areas."""
return sum(int(d.get("parameters", {}).get("number", 0)) for d in scenario.distributions.values())
Scenario¶
In [4]:
import json
import tempfile
from jupedsim_scenarios import load_scenario, run_scenario
from imo.scenario_builders.imo05_response_time import (
build_scenario,
)
walkable, raw = build_scenario()
scenario_view = SimpleNamespace(
walkable_polygon=wkt.loads(walkable),
distributions=raw["distributions"],
exits=raw["exits"],
)
In [5]:
with plt.rc_context(VV_RC):
fig, ax = plt.subplots(figsize=(8, 5))
handles = vv_draw_scenario(ax, scenario_view)
ax.set_title("Room with 10 occupants and one exit")
ax.legend(handles=handles, loc="upper center",
bbox_to_anchor=(0.5, -0.15), ncol=3)
plt.tight_layout()
plt.show()
Simulation¶
In [6]:
with tempfile.TemporaryDirectory() as tmpdir:
path = Path(tmpdir)
(path / "config.json").write_text(
json.dumps(raw), encoding="utf-8"
)
(path / "geometry.wkt").write_text(
walkable, encoding="utf-8"
)
scenario = load_scenario(str(path))
result = run_scenario(scenario, seed=42)
try:
frame_rate = result.frame_rate
df = result.trajectory_dataframe().sort_values(
["id", "frame"]
).copy()
finally:
result.cleanup()
Measuring response times¶
Movement begins when an occupant's Euclidean displacement from their initial position exceeds 0.05 m.
The expected response times are reconstructed using the same random seed and sampling order as pytest.
In [7]:
expected = np.random.default_rng(12345).uniform(
10.0, 100.0, 10
)
agent_ids = sorted(df["id"].unique())
assert len(agent_ids) == 10
movement_start = {}
for agent_id in agent_ids:
sub = df[df["id"] == agent_id]
x0 = float(sub.iloc[0]["x"])
y0 = float(sub.iloc[0]["y"])
displacement = np.hypot(
sub["x"] - x0,
sub["y"] - y0,
)
moved = sub[displacement > 0.05]
assert not moved.empty, (
f"Agent {agent_id} never moved"
)
movement_start[agent_id] = (
float(moved.iloc[0]["frame"]) / frame_rate
)
observed = np.array([
movement_start[agent_id]
for agent_id in agent_ids
])
deltas = np.abs(observed - expected)
table = pd.DataFrame({
"agent": agent_ids,
"assigned [s]": expected,
"observed [s]": observed,
"absolute error [s]": deltas,
})
print(table.round(3).to_string(index=False))
agent assigned [s] observed [s] absolute error [s]
1 30.460 30.6 0.140
2 38.508 38.6 0.092
3 81.763 81.9 0.137
4 70.863 71.0 0.137
5 45.200 45.3 0.100
6 39.953 40.1 0.147
7 63.848 64.1 0.252
8 26.806 26.9 0.094
9 70.548 70.6 0.052
10 94.762 94.9 0.138
Results¶
In [8]:
with plt.rc_context(VV_RC):
fig, ax = plt.subplots(figsize=(7, 6))
limits = np.linspace(9, 102, 200)
ax.fill_between(
limits, limits - 0.5, limits + 0.5,
color=VV_GREEN, alpha=0.25,
label="Accepted deviation: ±0.5 s",
)
ax.plot(
limits, limits,
linestyle="--", color="dimgrey",
label="Exact agreement",
)
ax.scatter(
expected, observed,
color=VV_BLUE, s=45, zorder=4,
label="Occupants",
)
ax.set(
xlabel="Assigned response time [s]",
ylabel="Observed response time [s]",
title="Assigned versus observed response times",
xlim=(9, 102),
ylim=(9, 102),
)
ax.set_aspect("equal")
ax.legend()
plt.tight_layout()
plt.show()
In [9]:
with plt.rc_context(VV_RC):
fig, ax = plt.subplots(figsize=(8, 4))
ax.bar(
range(len(agent_ids)),
deltas,
color=VV_BLUE,
)
ax.axhline(
0.5, color=VV_RED, linestyle="--",
label="Maximum permitted deviation",
)
ax.set_xticks(
range(len(agent_ids)), agent_ids
)
ax.set(
xlabel="Agent ID",
ylabel="Absolute deviation [s]",
title="Individual response-time deviations",
)
ax.legend()
plt.tight_layout()
plt.show()
Acceptance criterion¶
All ten occupants must begin moving within the accepted interval of 9.9–101.0 seconds.
Each observed response time must differ from its individually assigned value by no more than 0.5 seconds.
In [10]:
print(f"Maximum deviation: {deltas.max():.3f} s")
assert len(agent_ids) == 10
assert np.all(observed >= 9.9), observed
assert np.all(observed <= 101.0), observed
assert np.all(deltas <= 0.5), deltas
print("Acceptance criterion passed.")
Maximum deviation: 0.252 s Acceptance criterion passed.