IMO MSC.1/Circ.1533 — Test 7: Assignment of population demographics¶

Verify that walking speeds assigned to a population are consistent with the specified demographic characteristics. This implementation uses 50 male occupants aged 30–50 years on flat terrain, with desired walking speeds uniformly distributed between 0.97 and 1.62 m/s.

Source: IMO MSC.1/Circ.1533, Annex 3, Test 7 and Table 3.4.

In [1]:
from datetime import datetime

print(f"Executed on {datetime.now().astimezone().strftime('%d %B %Y, %H:%M %Z')}")
Executed on 01 December 2026, 15:30 UTC
In [2]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.stats import kstest

from scenario_builders.imo07_demographics import (
    build_scenario,
    WALKING_SPEED_MIN,
    WALKING_SPEED_MAX,
    NUMBER_OF_AGENTS,
    SEED,
)
In [3]:
plt.rcParams.update({
    "figure.facecolor": "white",
    "axes.facecolor": "#f7f7f5",
    "axes.edgecolor": "#3a3a3a",
    "axes.labelcolor": "#1d1d1d",
    "axes.titleweight": "bold",
    "axes.grid": True,
    "grid.alpha": 0.3,
    "font.size": 11,
    "figure.figsize": (8, 5),
})

Scenario setup¶

The scenario consists of a 40 m × 10 m corridor containing 50 occupants. The simulation is constructed using the same scenario builder as the corresponding pytest verification test.

The test evaluates assigned desired walking speeds rather than observed movement speeds. Advancing the simulation is therefore unnecessary.

In [4]:
simulation, geometry, exit_polygon, starting_region = build_scenario()

positions = np.array([
    agent.position for agent in simulation.agents()
])

print(f"Number of agents: {simulation.agent_count()}")
print(f"Random seed: {SEED}")
Number of agents: 50
Random seed: 42
In [5]:
fig, ax = plt.subplots(figsize=(10, 4))

gx, gy = geometry.exterior.xy
ax.fill(
    gx, gy, facecolor="#eef2f7", edgecolor="k",
    lw=1.5, zorder=0,
)

sx, sy = starting_region.exterior.xy
ax.fill(
    sx, sy, facecolor="tab:blue", alpha=0.15,
    edgecolor="tab:blue", label="Starting region",
)

ex, ey = exit_polygon.exterior.xy
ax.fill(
    ex, ey, facecolor="tab:green", alpha=0.6,
    label="Exit",
)

ax.scatter(
    positions[:, 0], positions[:, 1],
    s=15, color="tab:blue", label="Occupants",
    zorder=3,
)

ax.set_aspect("equal")
ax.set_xlabel("x [m]")
ax.set_ylabel("y [m]")
ax.set_title("IMO 7 — Population demographics scenario")

ax.legend(
    loc="upper center",
    bbox_to_anchor=(0.5, -0.25),
    ncol=3,
    frameon=False,
)

plt.tight_layout()
plt.show()
No description has been provided for this image

Assigned walking speeds¶

Retrieve the desired walking speeds directly from the JuPedSim agents. Compare the assigned speeds with the specified uniform distribution using a one-sample Kolmogorov–Smirnov test.

In [6]:
assigned_speeds = np.array([
    agent.model.desired_speed
    for agent in simulation.agents()
])

statistic, p_value = kstest(
    assigned_speeds,
    "uniform",
    args=(
        WALKING_SPEED_MIN,
        WALKING_SPEED_MAX - WALKING_SPEED_MIN,
    ),
)

summary = pd.DataFrame([{
    "Number of agents": simulation.agent_count(),
    "Minimum speed [m/s]": assigned_speeds.min(),
    "Maximum speed [m/s]": assigned_speeds.max(),
    "Mean speed [m/s]": assigned_speeds.mean(),
    "KS statistic": statistic,
    "KS p-value": p_value,
}])

summary
Out[6]:
Number of agents Minimum speed [m/s] Maximum speed [m/s] Mean speed [m/s] KS statistic KS p-value
0 50 0.998472 1.604155 1.317901 0.111664 0.524804
In [7]:
fig, axes = plt.subplots(1, 2, figsize=(11, 4.5))

a = WALKING_SPEED_MIN
b = WALKING_SPEED_MAX

# Probability density
ax = axes[0]

ax.hist(
    assigned_speeds,
    bins=np.linspace(a, b, 9),
    density=True,
    alpha=0.6,
    label="Assigned speeds",
)

ax.hlines(
    1 / (b - a), a, b,
    color="tab:orange",
    linewidth=2,
    label="Uniform reference",
)

ax.set_xlabel("Desired walking speed [m/s]")
ax.set_ylabel("Probability density")
ax.set_title("Assigned speed distribution")
ax.legend(fontsize=9)

# Cumulative distribution
ax = axes[1]

sorted_speeds = np.sort(assigned_speeds)
ecdf = np.arange(1, len(sorted_speeds) + 1) / len(sorted_speeds)

ax.step(
    np.r_[a, sorted_speeds, b],
    np.r_[0, ecdf, 1],
    where="post",
    label="Empirical CDF",
)

x = np.linspace(a, b, 200)

ax.plot(
    x, (x - a) / (b - a),
    color="tab:orange",
    linewidth=2,
    label="Uniform reference",
)

ax.set_xlabel("Desired walking speed [m/s]")
ax.set_ylabel("Cumulative probability")
ax.set_title(f"KS test: p = {p_value:.4f}")
ax.legend(fontsize=9)

fig.tight_layout()
plt.show()
No description has been provided for this image

Acceptance¶

The acceptance criteria follow the corresponding pytest implementation:

  • Exactly 50 occupants must be created.
  • Every assigned desired speed must be at least 0.97 m/s.
  • Every assigned desired speed must be at most 1.62 m/s.
  • The one-sample Kolmogorov–Smirnov test against the specified uniform distribution must produce a p-value of at least 0.05.

The KS significance threshold is the verification suite's statistical acceptance criterion.

In [8]:
ALPHA = 0.05

assert simulation.agent_count() == NUMBER_OF_AGENTS
assert np.all(assigned_speeds >= WALKING_SPEED_MIN)
assert np.all(assigned_speeds <= WALKING_SPEED_MAX)

assert p_value >= ALPHA, (
    "IMO 7 failed: assigned walking speeds are inconsistent "
    "with the specified uniform distribution."
)

print("IMO 7: All acceptance criteria satisfied.")
IMO 7: All acceptance criteria satisfied.