How a run works#
openmobisim is a simulation core written in Rust with a Python package on top. You work in Python: you build a
openmobisim.Scenario from a network, the demand and settings, and call
openmobisim.Scenario.run(), which returns a openmobisim.Run holding the results and writes
the output files. Everything that is computed per vehicle, link or trip happens in Rust; Python reads inputs, checks
them, sets the defaults and shapes the results.
The two layers#
Layer |
What it is |
What it holds |
|---|---|---|
The Python package |
The public interface |
|
The compiled module |
The bridge to Rust |
Private: its shape may change between versions; everything you use is re-exported by |
The Rust crates |
The simulator |
Networks, demand, route sets, choice, the loading, transit, the run, the readers and writers |
The figures need matplotlib (pip install "openmobisim[viz]") and are imported on demand, so import openmobisim
never needs it.
Inside the simulator#
The loading never computes a route: every vehicle arrives with its route already chosen. The choice models do not know what they choose: routes, itineraries and modes are all offered to them as alternatives with named attributes. The run is the only part that connects the two. Each part is a Rust crate that can be built and tested without Python; which crate does what, and how to extend them, is in The Rust crates.
Data flow: from files to results#
The inputs are read into four objects, a Scenario combines them with the settings, and a run turns them into results:
a Run in Python and the output files on disk.
Object |
Made by |
Holds |
Used by the run for |
|---|---|---|---|
|
|
The road network (links, nodes, signals, turns, each link’s traffic parameters) and its walk and bike layers ( |
Car routes and the loading (road); walking and cycling legs (layers); placing trips, stops and parkings |
|
|
Stops, routes, runs and their calls on one service day |
Transit journeys (RAPTOR); buses loaded on the roads |
|
|
Car and bike parkings: position, capacity, fees |
Park-and-ride and bike-and-ride; parking occupancy |
Trips |
|
One row per trip: traveller, departure, origin, destination, mode (optional), class, weight |
Everything: each trip becomes a vehicle, a walk, a ride or an itinerary |
A network can be written back out with network_write_gmns and trips with demand_write_trips, so a case built here
can be used elsewhere.
Interactions in a run#
Inside a run, its driver calls the other parts in a loop. The figure shows one run with equilibration (msa, the
default): what is done once at the start, the loop of loadings, and the end. Iteration 0 is everyone’s first choice,
and at iteration \(i \geq 1\) each traveller chooses again with probability \(1/(i+1)\), decided by a random draw keyed to
the traveller and the iteration.
Component |
Reads |
Produces |
|---|---|---|
Route sets |
The road network; link times of the last loading (route update) |
Routes per origin–destination pair, with their length and overlap (path size) |
Itineraries |
Layers, timetable, parkings, the last loading’s times |
Each itinerary trip’s candidate chains of legs, and their expected times and costs |
Choice model |
Alternatives with named attributes (times, lengths, costs, transfers, your own values) and the class’s coefficients |
One chosen alternative per choosing trip |
Loading |
Vehicles with routes and departures; the network’s traffic parameters; the loading rules |
Link travel times by time of day, per-link results by time bin, trip outcomes, realised bus times |
Equilibration |
The chosen routes of two iterations; link times |
Who chooses again; the gap; whether to stop |
Writers |
The run’s results |
The output files |
What a run does, stage by stage#
A run goes through the stages below, in this order, the reading and setup first. Their names are the ones timings.csv and
openmobisim.Run.timings() record, with the wall-clock time each took.
Stage |
When |
What happens |
|---|---|---|
|
once |
Bike and walk trips get their routes on the bike and walk layers. Their costs do not depend on traffic, so this happens once per run |
|
once, with transit, parkings or mode choice |
The trips that travel by transit, park-and-ride or bike-and-ride, or that choose their mode, get their candidate itineraries (chains of legs by mode, joined at hubs) |
|
once |
A set of car routes for every origin–destination pair the car trips need |
|
each loading |
Each car trip chooses a route from its pair’s set, with the choice model |
|
each loading, with itineraries |
Each itinerary trip chooses among its itineraries (and, with mode choice, among modes) on the expected times |
|
before the first full loading |
The free-flow loading’s groups: travellers loaded group by group, each group choosing on the congestion of the groups before it |
|
each iteration |
Every vehicle through the network over the simulation window |
|
between loadings |
New routes found on the last loading’s times are added to the route sets |
|
after the last loading |
A sample of trips tested against the whole network: whether the choice sets missed a route traffic made worthwhile (the stopping rule reads the in-set gaps, not this) |
|
once, with disruptions travellers do not know in advance |
The day loaded once more with the disruptions, every choice as the run left it |
|
once, first |
The network’s reading, if it recorded how long it took (read before the run, and not in the total); the demand read and checked; the layers, timetable and parkings prepared, and the fingerprint |
|
once |
The results gathered into the |
|
once |
The output files written |
|
once |
The run’s whole time, as its one-line message says it |
How the loadings repeat is the subject of Equilibration; the loading itself, of The loading.
One setting for detail: the flow level#
How detailed the traffic model is depends on one setting, flow_level, not on separate models. The levels are the same
code with parameters changed: from level 2 up, the link transmission model (Yperman 2007) applied to individual
vehicles, event by event in continuous time, as Raadsen, Bliemer and Bell (2016) do for flows; at level 2 the end of
every link is a bottleneck in Vickrey’s (1969) sense (The loading). It
has no time step: the 300-second settings are the resolution of the per-link outputs (link_bin_s) and of the costs
the next iteration chooses on (cost_bin_s), not of the traffic (The loading).
|
Name |
What it models |
|---|---|---|
0 |
free flow |
Every vehicle at free-flow speed; no capacity, no queues |
2 |
point queue (the default) |
Capacities at every link and junction; queues form but take no road space |
3 |
spatial queue |
Queues take road space and can fill a link, without the delay of the backward wave |
4 |
full model |
Spillback with the backward wave, rerouting on the way (turn pockets at every level) |
Level 1 does not exist. A Scenario refuses any other value.
Defaults: the core’s and the package’s#
The Rust core’s own defaults are the simplest: free flow, a deterministic choice and no equilibration. The Python
Scenario sets its own on top, and those are the defaults this manual describes: the point queue, the nested logit
when the run offers more than one mode and the path-size logit otherwise, and msa equilibration with the route update
best_response. Every value is listed in
Parameters.
Parallel and repeatable#
The core runs its parallel work on all processor cores. Results do not depend on how many cores are used, or in what order threads finish:
sums over many items are taken in a fixed order;
every random draw comes from a stream addressed by what it is for (the traveller, the trip, the iteration and the alternative), never by a thread.
The same inputs on the same platform give the same results, bit for bit. See Reproducibility.
For bikes#
Bikes travel on their own layer, a network over the same geometry as the roads with its own costs, which take the kind
of cycling facility into account. Bike routes do not depend on traffic, so they are found once per run
(static_routes), not in every loading. A bike trip still takes part in mode choice, and in bike-and-ride, where the
bike leg ends at a parking.
Limits#
Level 1 of the flow levels (a volume–delay model) is not built.
kpis.parquet’sdesign_idandreplicationare labels a run is given (Scenario.run(design_id=…, replication=…)),"default"and 0 for a single run; a replication differs from another only through itsmaster_seed. A design space is run as a loop of runs: there is no batch runner yet.