IMO Test 12 — Flow-density relation¶
Definition¶
Pedestrian flow in an unobstructed corridor should decrease at sufficiently high pedestrian densities compared with moderate densities.
Source: IMO MSC.1/Circ.1533, Annex 3, Test 12.
The project evaluates this relationship using local density and flow measurements aggregated over five-second intervals.
from datetime import datetime, timezone
print(datetime.now(timezone.utc).isoformat())
2026-12-01T15:30:40.086474+00:00
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.patches import Rectangle
from scenario_builders.imo12_flow_density import (
build_imo12_corridor,
run_imo12_corridor,
measure_imo12_flow_density,
)
plt.rcParams.update({
"figure.facecolor": "white",
"axes.facecolor": "#f7f7f5",
"axes.spines.top": False,
"axes.spines.right": False,
"font.size": 11,
"figure.dpi": 120,
})
Scenario¶
An unobstructed corridor measuring 30 × 2 m is initialized with five different pedestrian densities.
Local density is measured between x = 13 m and x = 17 m. Flow is measured at x = 15 m.
densities = [0.5, 1.0, 2.0, 3.0, 3.5]
simulations = {
density: build_imo12_corridor(
density=density, seed=42,
)
for density in densities
}
initial_counts = {
density: sim.agent_count()
for density, sim in simulations.items()
}
pd.DataFrame({
"Initial density [persons/m²]": densities,
"Occupants": [
initial_counts[density] for density in densities
],
})
| Initial density [persons/m²] | Occupants | |
|---|---|---|
| 0 | 0.5 | 30 |
| 1 | 1.0 | 60 |
| 2 | 2.0 | 120 |
| 3 | 3.0 | 180 |
| 4 | 3.5 | 210 |
fig, axes = plt.subplots(
len(densities), 1, figsize=(12, 8),
sharex=True,
)
for ax, density in zip(axes, densities):
sim = simulations[density]
positions = np.array([
agent.position for agent in sim.agents()
])
ax.add_patch(Rectangle(
(0, 0), 30, 2,
fill=False, edgecolor="black",
))
ax.axvspan(13, 17, color="tab:orange", alpha=0.2)
ax.axvline(15, color="tab:red", linestyle="--")
ax.add_patch(Rectangle(
(29.7, 0.2), 0.25, 1.6,
facecolor="tab:green",
))
ax.scatter(
positions[:, 0], positions[:, 1],
s=7, alpha=0.7,
)
ax.set(
xlim=(-0.5, 30.5), ylim=(-0.2, 2.2),
aspect="equal", ylabel="y [m]",
title=(
f"{density:g} persons/m² — "
f"{initial_counts[density]} occupants"
),
)
axes[-1].set_xlabel("x [m]")
plt.tight_layout()
plt.show()
Simulation¶
Each density case is simulated using the same scenario builder and trajectory recorder as pytest. Local density and flow are measured using the shared measurement function.
all_measurements = []
for density, simulation in simulations.items():
trajectories = run_imo12_corridor(simulation)
measurements = measure_imo12_flow_density(
trajectories, interval=5.0,
)
for measurement in measurements:
all_measurements.append({
**measurement,
"initial_density": density,
})
print(f"Completed initial density {density:g}")
results = pd.DataFrame(all_measurements)
results.head()
Completed initial density 0.5 Completed initial density 1
Completed initial density 2
Completed initial density 3
Completed initial density 3.5
| time_start | time_end | density | flow | initial_density | |
|---|---|---|---|---|---|
| 0 | 0.0 | 5.0 | 0.40625 | 0.8 | 0.5 |
| 1 | 5.0 | 10.0 | 0.66750 | 1.8 | 0.5 |
| 2 | 10.0 | 15.0 | 0.53000 | 1.2 | 0.5 |
| 3 | 15.0 | 20.0 | 0.01000 | 0.0 | 0.5 |
| 4 | 20.0 | 25.0 | 0.00000 | 0.0 | 0.5 |
Results¶
The flow-density diagram uses the measured local density, rather than the initial corridor density.
Moderate-density measurements are selected from 1.5–2.5 persons/m² and high-density measurements from densities of at least 3.0 persons/m².
moderate = results.loc[
results.density.between(1.5, 2.5), "flow"
]
high = results.loc[
results.density >= 3.0, "flow"
]
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
for density, group in results.groupby("initial_density"):
axes[0].scatter(
group.density, group.flow,
alpha=0.7, s=22,
label=f"{density:g} persons/m²",
)
axes[0].axvspan(1.5, 2.5, color="tab:green", alpha=0.1)
axes[0].axvspan(
3.0, max(3.1, results.density.max()),
color="tab:red", alpha=0.1,
)
axes[0].set(
xlabel="Measured density [persons/m²]",
ylabel="Flow [persons/s]",
title="Flow-density relationship",
)
axes[0].legend(title="Initial density", fontsize=8)
axes[1].bar(
["Moderate density", "High density"],
[moderate.mean(), high.mean()],
)
axes[1].set(
ylabel="Mean flow [persons/s]",
title="Acceptance criterion comparison",
)
plt.tight_layout()
plt.show()
Acceptance criteria¶
- Each scenario contains the expected initial number of occupants.
- Measurements exist in both density ranges.
- Mean flow at high density is lower than mean flow at moderate density.
for density in densities:
assert initial_counts[density] == int(density * 30 * 2)
assert not moderate.empty, "No moderate-density measurements"
assert not high.empty, "No high-density measurements"
mean_moderate_flow = moderate.mean()
mean_high_flow = high.mean()
print(f"Moderate-density flow: {mean_moderate_flow:.3f} persons/s")
print(f"High-density flow: {mean_high_flow:.3f} persons/s")
assert mean_high_flow < mean_moderate_flow, (
"Flow at high density is not lower than at moderate density"
)
print("All acceptance criteria passed.")
Moderate-density flow: 2.533 persons/s High-density flow: 1.950 persons/s All acceptance criteria passed.