Metrics¶
Post-run analysis of per-vehicle travel times, derived from each vehicle's
trajectory. collect_trips builds one record per vehicle, summarize_trips
reduces them to network aggregates, and write_trips_csv flattens them to disk.
See Metrics & trip analysis.
collect_trips
¶
collect_trips(sim: Simulation, include_connectors: bool = False) -> list[dict]
Collect travel-time records for every completed trip in a finished run.
Completed trips are gathered from the destination nodes' recorded journeys — one record per completed journey. A vehicle from a static demand profile contributes one journey; a hand-injected vehicle that was re-injected contributes one per trip. Vehicles still en route or waiting in an origin queue at the end of the horizon have no completed journey and are not included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulation
|
A run :class: |
required |
include_connectors
|
bool
|
Passed through to :func: |
False
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of per-journey records (see :func: |
list[dict]
|
|
trip_record
¶
Build the travel-time record for a single completed journey.
The reported travel_time is the time from the vehicle's actual departure
to its arrival, minus the artificial one-step free-flow lag that each
auto-inserted O/D connector imposes (a one-cell connector always costs one
free-flow step to cross, even when empty and unrestricted). The actual departure
(departure_time) is the instant the vehicle entered the origin queue —
stamped by
:meth:~mesoltm.core.nodes.origin_node.OriginNode.prepare_step at the first
step at or after its scheduled_departure — and the arrival (arrival_time)
is stamped at absorption; both are read straight off the journey record (already
in seconds). Measuring from the actual departure (rather than the sub-step
scheduled_departure) keeps travel_time a clean multiple of dt and, for
a vehicle injected with a past departure time, avoids charging travel for time
before the vehicle could exist.
Time a vehicle spends on a connector beyond its one free-flow step is kept:
it is a genuine supply-limited wait to enter or leave the network (downstream
space was the binding constraint). travel_time splits into access_time
(origin-queue wait plus any supply-limited connector wait) and network_time
(time on real links only), so travel_time == access_time + network_time;
network_time reflects only real links and is unaffected by connectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
journey
|
dict
|
A completed journey record as produced by
:meth: |
required |
dt
|
float
|
Simulation step |
required |
include_connectors
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
A dict with keys: |
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
Time fields are seconds; |
dict
|
the vehicle never entered the network). |
summarize_trips
¶
Aggregate a list of trip records into a compact network-level summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trips
|
list[dict]
|
Records as returned by :func: |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dict of headline metrics: trip counts, mean/median/min/max total travel |
dict
|
time (which includes the initial access wait), mean access time, total |
dict
|
vehicle-hours, and the mean travel time per link. Duration fields are |
dict
|
|
write_trips_csv
¶
Write trip records to a CSV file (one row per completed journey).
The route and per-link travel times are flattened into single columns
("l1;l2;..." and "link_id:seconds;...") so the file stays flat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trips
|
list[dict]
|
Records as returned by :func: |
required |
path
|
str
|
Destination file path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The path written to. |