Scenarios and edits#
A study compares runs that differ in one thing: a closed road, a new cycle track, a more frequent line, an incident. openmobisim makes each change a copy of the network or timetable, so the original stays as it was and the runs line up link by link.
Edit the network#
works = ms.network_edit(network, close=["link-1203", "link-1204"])
wider = ms.network_edit(network, lanes={"link-88": 3})
bottleneck = ms.network_edit(network, capacity_factor={"link-88": 0.6})
track = ms.network_edit(network, bike_facility={"bike-512": "separated"})
Change |
What it does |
|---|---|
|
Road links closed to cars and buses for the whole run; no route uses them, and buses take another way. Walking and cycling keep their own layers. Travellers know in advance |
|
Lanes per direction: capacity, jam density and storage scale with them (at least 1; to remove a road, close it) |
|
Capacity multiplied, storage kept: a bottleneck |
|
A bike link becomes |
Links keep their indices, so run.link_bins() of two runs compare link by link. The changes enter the run’s
fingerprint.
A scenario from another. base.replace(network=works) is the base scenario with only its network changed;
any argument of from_parts can be changed so (base.replace(flow_level=4),
base.replace(choice_options={"beta_time_min": -0.1})), and a misspelt name is refused with the list. base.parts
holds the arguments a scenario was built from.
Edit the timetable#
ms.transit_edit(transit, cancel=[...], headway={...}); see
Transit and parking.
Things that happen at a time of day#
incident = [{"links": ["link-88"], "capacity_factor": 0.0, "from_s": 8 * 3600, "to_s": 9 * 3600}]
late_tram = [{"line": "T1", "delay_s": 600, "from_s": 7.5 * 3600, "to_s": 8.5 * 3600}]
scenario = ms.Scenario.from_parts(network, trips, disruptions=incident + late_tram)
On roads, the links keep a share of their capacity in the window: 0 closes them, 0.5 halves it. Overlapping disruptions multiply.
On lines, runs leaving their first stop in the window are late at every call, or do not run (
"cancel": True). A late bus leaves late and drives on among the cars.
Known or not. By default (disruptions_known=False), travellers do not know: the run reaches its equilibrium
without the disruption, then loads the day once more with it, every choice kept. Only what happens within the day
reacts. With disruptions_known=True, every loading includes it, and travellers plan around it.
At which level. Road disruptions act through capacity, so not at flow_level=0. At the point queue (the default),
a closure’s queue takes no road space: it delays only the vehicles in it. With spillback (flow_level 3 or 4), it
backs up across the junctions behind it.
Your own values#
A choice model can weigh values you give: per link (link_values, summed along each alternative), and per traveller
or trip (person_values, trip_values). Use these for, say, the attractiveness of a street or a traveller’s income.
See Choice.
Compare two runs#
Keep the master seed the same, so every traveller draws the same in both runs and the difference is the change’s (see Experiments and reproducibility).
A worked comparison on Delft#
Delft’s default morning first, then the same morning with its busiest street closed, then with a cycle track on the busiest street where bikes ride among the cars. The three runs share their master seed, so the differences are the changes’.
import openmobisim as ms
import pandas as pd
case = ms.examples.case("delft")
base = case.scenario("base")
before = base.run("delft-base")
network = base.parts["network"]
Run 'delft-base': 8.6 s, window 07:30–09:30, 65,313 of 65,956 trips completed, mean trip 23.7 min, verdict good (run.timings() has every stage)
The street to close is found from the base run’s own link table, and closed whole: every link of its OpenStreetMap way, both directions.
# The busiest street that is not a motorway, closed for the morning: every link of its OpenStreetMap way.
road = before.link_bins_table().to_pandas()
classes = dict(zip(network.link_ids(), (ms.LINK_CLASSES[c] for c in network.link_class())))
streets = road[road["link"].map(classes).isin(["primary", "secondary", "tertiary"])]
busiest = streets.groupby("link")["pcu"].sum().idxmax()
works = [link for link in network.link_ids() if link.split(":")[0] == busiest.split(":")[0]]
closed = base.replace(network=ms.network_edit(network, close=works)).run("delft-closed")
Run 'delft-closed': 6.6 s, window 07:30–09:30, 64,263 of 65,956 trips completed, mean trip 24.0 min, verdict good (run.timings() has every stage)
The cycle track goes on the bike layer: its links are named by the bike layer’s ids.
# The busiest street where bikes ride among the cars, given a cycle track of its own.
bike = network.layer("bike")
mixed = {link for link, kind in zip(bike.link_ids(), bike.link_infrastructure()) if kind == 0}
cyclists = before.link_bins_table(layer="bike").to_pandas().groupby("link")["travellers"].sum()
street = cyclists[cyclists.index.isin(mixed)].idxmax()
track = [link for link in mixed if link.split(":")[0] == street.split(":")[0]]
tracked = base.replace(network=ms.network_edit(network, bike_facility={link: "separated" for link in track})).run(
"delft-track"
)
Run 'delft-track': 8.1 s, window 07:30–09:30, 65,208 of 65,956 trips completed, mean trip 23.7 min, verdict good (run.timings() has every stage)
def summary(run):
"""Completion, the mean trip and the shares of people by mode."""
modes = run.trip_modes().to_pandas()
people = modes.groupby("mode")["weight"].sum() / modes["weight"].sum() * 100
return {
"completed (%)": round(100 * run.completion["completed"] / run.completion["total_trips"], 1),
"mean trip (min)": round(run.mean_travel_time_s / 60, 2),
"car (%)": round(people["car"], 2),
"bike (%)": round(people["bike"], 2),
"transit (%)": round(people["transit"], 2),
}
pd.DataFrame({"base": summary(before), "street closed": summary(closed), "cycle track": summary(tracked)}).T
completed (%) mean trip (min) car (%) bike (%) transit (%)
base 99.0 23.70 53.77 18.75 24.27
street closed 97.4 24.03 53.71 18.77 24.26
cycle track 98.9 23.67 53.76 18.76 24.28
A change to one street moves the city’s totals little; it shows on the street itself:
def passing(run, links, layer="road"):
"""What passed the links in the run: PCU on the road, cyclists on the bike layer."""
table = run.link_bins_table(layer=layer).to_pandas()
return table[table["link"].isin(links)]["pcu" if layer == "road" else "travellers"].sum()
pd.DataFrame(
{
"the closed street (PCU)": [passing(before, works), passing(closed, works)],
"the cycle track (cyclists)": [passing(before, track, "bike"), passing(tracked, track, "bike")],
},
index=["base", "changed"],
)
the closed street (PCU) the cycle track (cyclists)
base 4605.0 964.0
changed 0.0 969.0
viz.map_link(closed) beside viz.map_link(before) shows where the closed street’s traffic went.
For bikes#
bike_facility edits are the way to study cycling infrastructure. Note that in this version an edited bike link
rides at the full facility speed, without the street’s speed limit applied (see Cycling).