IMO Test 2 — Walking speed upstairs¶
Definition¶
One occupant travels along a 10 m long and 2 m wide staircase at 1 m/s. The expected travel time is 10 s.
The project represents the staircase as a flat speed-factor zone with factor 0.5. The desired speed is adjusted so that the effective walking speed is 1 m/s. Stair direction is not explicitly modelled.
Source: IMO MSC.1/Circ.1533, Annex 3, Test 2.
In [1]:
from datetime import datetime
print(f"Executed on {datetime.now().astimezone()}")
Executed on 2026-12-01 15:29:59.786250+00:00
In [2]:
import sys
from pathlib import Path
from types import SimpleNamespace
import matplotlib.pyplot as plt
import numpy as np
from shapely import wkt
sys.path.insert(0, str(Path.cwd().parent))
from imo.scenario_builders.imo_stair_speed import (
build_scenario,
run_stair_scenario,
)
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]:
SPEED_FACTOR = 0.5
LOWER, UPPER = 9.5, 10.5
walkable, raw = build_scenario(SPEED_FACTOR)
scenario = SimpleNamespace(
walkable_polygon=wkt.loads(walkable),
distributions=raw["distributions"],
exits=raw["exits"],
zones=raw["zones"],
)
In [5]:
with plt.rc_context(VV_RC):
fig, ax = plt.subplots(figsize=(10, 3))
handles = vv_draw_scenario(ax, scenario)
for zone in scenario.zones.values():
ax.add_patch(MplPolygon(
zone["coordinates"],
closed=True,
facecolor=to_rgba(VV_ORANGE, 0.2),
edgecolor=VV_ORANGE,
hatch="///",
zorder=1.5,
))
handles.append(Patch(
facecolor=to_rgba(VV_ORANGE, 0.2),
edgecolor=VV_ORANGE,
label=f"Speed factor {SPEED_FACTOR}",
))
ax.set_title("Staircase speed-factor zone")
ax.legend(handles=handles, loc="upper center",
bbox_to_anchor=(0.5, -0.3), ncol=4)
plt.tight_layout()
plt.show()
Simulation¶
In [6]:
result = run_stair_scenario(SPEED_FACTOR)
travel_time = result["evacuation_time"]
df = result["trajectory"]
print(f"Travel time: {travel_time:.2f} s")
Travel time: 9.86 s
Results¶
In [7]:
with plt.rc_context(VV_RC):
fig, ax = plt.subplots(figsize=(8, 4))
for agent_id, sub in df.groupby("id"):
ax.plot(
sub.frame / result["frame_rate"],
sub.x,
label=f"Agent {agent_id}",
)
ax.set(
xlabel="Time [s]",
ylabel="Position [m]",
title="Position along the staircase",
)
ax.legend()
plt.show()
In [8]:
with plt.rc_context(VV_RC):
fig, ax = plt.subplots(figsize=(8, 3))
ax.axvspan(
LOWER, UPPER,
color=VV_GREEN,
alpha=0.2,
label="Acceptance interval",
)
ax.axvline(
10.0,
color="black",
linestyle="--",
label="Expected time",
)
ax.scatter(
[travel_time], [0],
color=VV_BLUE,
s=90,
label=f"Measured: {travel_time:.2f} s",
)
ax.set(
xlabel="Travel time [s]",
yticks=[],
ylim=(-1, 1),
xlim=(min(7, travel_time - 1),
max(13, travel_time + 1)),
title="Travel-time acceptance criterion",
)
ax.legend()
plt.tight_layout()
plt.show()
Acceptance criterion¶
The measured travel time must be between 9.5 and 10.5 seconds, inclusive.
In [9]:
print(f"Measured travel time: {travel_time:.3f} s")
assert LOWER <= travel_time <= UPPER, travel_time
print("Acceptance criterion passed.")
Measured travel time: 9.860 s Acceptance criterion passed.