Multimodal Routing Constraints
Real-world trips often combine multiple modes of transportation—such as walking a few blocks to a bus stop, riding shared micromobility to a rail station, being dropped off at a transit hub (kiss-and-ride), or taking an on-demand microtransit shuttle to connect with regional transit.
BAMBAM represents each transportation mode (walk, bike, drive, transit, gbfs, gtfs-flex) as a separate edge list sharing a common set of network vertices. Travelers can switch modes at any vertex that connects edges from two different mode networks. To ensure simulated trips reflect realistic traveler behavior—and to keep the multimodal search space tractable—BAMBAM pairs a multimodal traversal model with a multimodal constraint model (and a multimodal label model).
1. How Multimodal Traversal and Constraint Models Work
Every mode’s [[search]] block in bambam.toml includes a multimodal entry in both traversal.models and constraint.models:
[[search]]
traversal.type = "combined"
traversal.models = [
{ type = "distance", distance_unit = "miles" },
{ type = "fixed_speed", name = "walk", speed = 5.0, speed_unit = "kph" },
{ type = "time", time_unit = "minutes" },
{ type = "multimodal", this_mode = "walk", available_modes = ["walk", "bike", "drive", "transit", "gbfs", "gtfs-flex"] },
]
constraint.type = "combined"
constraint.models = [
{ type = "multimodal", this_mode = "walk", available_modes = ["walk", "bike", "drive", "transit", "gbfs", "gtfs-flex"] },
]
The Multimodal Traversal Model: Link-Level Accounting
As a search expands across an edge belonging to this_mode, the multimodal traversal model performs link-level accounting on the search state:
- Mode Transition Detection: Compares
this_mode(and, for scheduled transit, the edge’sroute_id) against the mode of the current active trip leg (active_leg). Whenever the traveler switches modes—or transfers between two different transit routes—the model incrementsactive_legand records the new mode inleg_<idx>_mode. - Leg-Level Accumulators: Adds the link’s
edge_distanceandedge_timeto the active leg’s accumulators (leg_<idx>_distanceandleg_<idx>_time). - Mode-Level Accumulators: Adds the link’s
edge_distanceandedge_timeto the cumulative totals for that mode across the entire trip (mode_<mode>_distanceandmode_<mode>_time), even if that mode is used across multiple non-contiguous legs (e.g., walking on both the first and last legs of a transit trip).
The Multimodal Constraint Model: Rules on Mode Transitions & Budgets
Before the search is allowed to traverse a candidate edge, the multimodal constraint model inspects the accumulated state variables and enforces two categories of rules:
- Mode Transition Rules: Determines whether transitioning into
this_modeis legal given the sequence of modes used so far, the maximum number of trip legs (max_trip_legs), and whether any minimum time/distance requirement on the outgoing leg has been satisfied before switching modes. - Resource Budget Rules: Verifies that adding the candidate link will not push the trip’s total, per-mode, or per-leg distance or travel time past its configured maximum limit.
Multimodal Labels (multimodal_label)
In a single-mode search, only the fastest path to each vertex needs to be retained (multimodal_label = false). In complex multimodal trips, however, a traveler who reaches a vertex quickly by driving may no longer be allowed to board transit, whereas a traveler who walked to that same vertex can. Setting multimodal_label = true on a mode in trip_modes instructs BAMBAM’s [label] model to include the sequence of leg modes ([walk], [walk, transit], etc.) in the search label so valid mode sequences are not pruned prematurely.
2. Multimodal Constraint Configurations
Constraints are declared per travel mode inside the trip_modes input plugin ([[plugin.input_plugins]] with type = "trip_modes"). Shared constraints placed under [plugin.input_plugins.defaults] are automatically prepended to every mode’s constraint list.
Below are all available constraint types and their TOML syntax.
Mode & Sequence Constraints
Constraint type | Purpose | Example |
|---|---|---|
allowed_modes | Restricts the trip to a set of permitted modes in any order (up to max_trip_legs). | { type = "allowed_modes", values = ["walk", "transit"] } |
exact_sequences | Requires the trip’s leg sequence to match one of the listed mode sequences (or a prefix thereof). Automatically infers max_trip_legs if omitted. | { type = "exact_sequences", values = [["drive"], ["walk", "drive"]] } |
mode_counts | Caps how many distinct legs can use each mode during a trip. | { type = "mode_counts", values = { walk = 2, transit = 1 } } |
Whole-Trip Resource Limits
Whole-trip limits constrain total trip_time or trip_distance summed across all legs. Each accepts min and/or max bounds (plus optional min_exclusive = true / max_exclusive = true) and a unit:
constraints = [
{ type = "time_limit", max = 40.0, unit = "minutes" },
{ type = "distance_limit", max = 25.0, unit = "miles" },
]
Cumulative Per-Mode Limits (mode_time_limit & mode_distance_limit)
Cumulative mode limits cap (or set a floor on) the total time or distance spent in a specific mode summed across all legs of the trip. You can write them using either inline single-mode syntax (mode = "...") or multi-mode values map syntax:
constraints = [
# Inline syntax: spend no more than 10 minutes walking across the entire trip
{ type = "mode_time_limit", mode = "walk", max = 10.0, unit = "minutes" },
# Map syntax: cap total walking distance at 1.0 mile and total biking distance at 5.0 miles
{ type = "mode_distance_limit", values = { walk = { max = 1.0, unit = "miles" }, bike = { max = 5.0, unit = "miles" } } },
]
Per-Leg Mode Limits (mode_leg_time_limit & mode_leg_distance_limit)
Per-leg limits constrain the time or distance spent in a mode on a specific trip leg. The leg selector supports:
"first": The departing leg of the trip (leg index0)."last": The final leg of the trip (max_trip_legs - 1)."any"(default iflegis omitted): Applies independently to every leg that uses that mode.- An integer index (
0,1,2, …) or{ type = "leg_index", index = 1 }: Targets a specific 0-based leg number.
How
minbounds work on legs: Aminbound on a leg (such as requiring at least 3 minutes on atransitleg) is evaluated when switching out of that leg—preventing trivial 1-stop hops while allowing the leg to build up from 0 minutes as it starts.
constraints = [
# Walk at most 0.5 km on the first leg
{ type = "mode_leg_distance_limit", mode = "walk", leg = "first", max = 0.5, unit = "kilometers" },
# Every transit leg must be at least 3 minutes long
{ type = "mode_leg_time_limit", mode = "transit", leg = "any", min = 3.0, unit = "minutes" },
]
3. Combining Constraints for Multimodal Travel Behaviors
Using the trip_modes input plugin, you can evaluate unimodal and complex multimodal behaviors side-by-side in a single BAMBAM run.
[[plugin.input_plugins]]
type = "trip_modes"
[plugin.input_plugins.defaults]
multimodal_label = false
constraints = [
{ type = "time_limit", max = 40.0, unit = "minutes" },
]
Standard Unimodal & Park-Access Modes (walk, bike, drive)
[plugin.input_plugins.modes.walk]
constraints = [
{ type = "allowed_modes", values = ["walk"] },
]
[plugin.input_plugins.modes.bike]
constraints = [
{ type = "allowed_modes", values = ["bike"] },
]
# Drive: allow up to 0.5 km of walking on the first leg to reach a parked vehicle
[plugin.input_plugins.modes.drive]
constraints = [
{ type = "mode_leg_distance_limit", mode = "walk", leg = "first", max = 0.5, unit = "kilometers" },
{ type = "exact_sequences", values = [["drive"], ["walk", "drive"]] },
]
Scheduled Transit with Walk Access/Egress (transit)
Allows up to 4 legs (e.g., walk -> transit -> transit -> walk or walk -> transit -> walk), caps total walking across the trip at 10 minutes, and requires each transit ride to last at least 3 minutes:
[plugin.input_plugins.modes.transit]
multimodal_label = true
max_trip_legs = 4
constraints = [
{ type = "mode_time_limit", mode = "walk", max = 10.0, unit = "minutes" },
{ type = "mode_leg_time_limit", mode = "transit", min = 3.0, unit = "minutes" },
{ type = "allowed_modes", values = ["walk", "transit"] },
]
First- and Last-Mile Transit + Shared Micromobility (transit_gbfs)
Shared bikes and e-scooters (gbfs) can dramatically expand the catchment area of high-frequency transit stations compared to walking alone. Here, a traveler can walk or ride micromobility to reach transit, transfer, and use micromobility or walk at the destination end:
[plugin.input_plugins.modes.transit_gbfs]
multimodal_label = true
max_trip_legs = 5
constraints = [
# Allowed modes across the trip
{ type = "allowed_modes", values = ["walk", "gbfs", "transit"] },
# Cap total walking at 10 minutes and total micromobility riding at 15 minutes
{ type = "mode_time_limit", mode = "walk", max = 10.0, unit = "minutes" },
{ type = "mode_time_limit", mode = "gbfs", max = 15.0, unit = "minutes" },
# Require each transit ride to be at least 3 minutes
{ type = "mode_leg_time_limit", mode = "transit", min = 3.0, unit = "minutes" },
]
Kiss-and-Ride / Park-and-Ride (kiss_and_ride)
In a kiss-and-ride (or park-and-ride) trip, a traveler uses a private automobile for the first-mile access leg to reach a transit station (drive -> transit -> walk, or walk -> drive -> transit -> walk), then completes the trip on transit and foot without driving at the destination end. Using exact_sequences and per-leg limits prevents the model from driving all the way to the destination or using a car after alighting from transit:
[plugin.input_plugins.modes.kiss_and_ride]
multimodal_label = true
max_trip_legs = 4
constraints = [
# Only allow driving on the access side before boarding transit
{ type = "exact_sequences", values = [
["drive", "transit", "walk"],
["drive", "transit", "transit", "walk"],
["walk", "drive", "transit", "walk"],
] },
# Cap the first-mile drive access leg at 10 minutes (or 5 miles)
{ type = "mode_leg_time_limit", mode = "drive", max = 10.0, unit = "minutes" },
{ type = "mode_leg_distance_limit", mode = "drive", max = 5.0, unit = "miles" },
# Cap total walking at 10 minutes and require at least 5 minutes on transit
{ type = "mode_time_limit", mode = "walk", max = 10.0, unit = "minutes" },
{ type = "mode_leg_time_limit", mode = "transit", min = 5.0, unit = "minutes" },
]
On-Demand Microtransit + Fixed-Route Transit (flex_transit)
Many transit agencies deploy GTFS-Flex microtransit zones in lower-density suburbs to feed riders into trunk bus or rail corridors (transit). Combining walk, gtfs-flex, and transit models both direct on-demand trips and first-/last-mile feeder trips into the scheduled transit network:
[plugin.input_plugins.modes.flex_transit]
multimodal_label = true
max_trip_legs = 4
constraints = [
# Allow walking, on-demand microtransit, and fixed-route transit
{ type = "allowed_modes", values = ["walk", "gtfs-flex", "transit"] },
# Limit on-demand microtransit to a single feeder leg of at most 15 minutes
{ type = "mode_counts", values = { "gtfs-flex" = 1, transit = 2, walk = 2 } },
{ type = "mode_leg_time_limit", mode = "gtfs-flex", max = 15.0, unit = "minutes" },
# Limit walking to 10 minutes total
{ type = "mode_time_limit", mode = "walk", max = 10.0, unit = "minutes" },
]