Appearance
Event-based simulation
grABM is an agent-based model (ABM) executed as a discrete-event simulation. An agent represents one person with a resolved profile, placement, agenda, and activity decisions. Agents interact indirectly through shared destinations, capacity, and network use. Their authored rules produce aggregate trips and occupancy.
The engine advances directly to the next queued event. It does not update every person once per minute or once per rendered frame. Event times can be fractional minutes: a 100-metre walk at 1.4 m/s takes about 1.19 minutes.
From input to execution
Scenario describes people and behavior; Simulation combines it with graph and facility data. Every run() starts fresh state and follows these phases:
- Validate the complete input, references, modes, and schedules.
- Resolve population from explicit agents and cohorts, inherit profiles, assign initial placement, and sample schedule templates.
- Assign anchors to reachable facilities for fixed agenda items that do not already specify a destination. Home uses the assigned home; other assignments consider activity fit and overlapping anchor capacity.
- Schedule events for agenda departures, decisions, and gateway presence.
- Process events in time order. Each event reads current state, changes it, records outcomes, and may enqueue later events.
- Prepare results with trips, observations, diagnostics, need outcomes, and hashes.
The event queue and mutable agent state are private implementation details. Applications use Simulation.run(); they do not construct events or drive the engine frame by frame. Local and worker execution use the same kernel. See workers for progress, cancellation, and ownership.
Events and their effects
| Event | Effect |
|---|---|
| Decision | Consider an activity destination, route, capacity, and available time. A feasible choice can start a trip immediately; otherwise record why no trip started. |
| Departure | Attempt a scheduled trip to an assigned destination. Reserve a destination slot, release origin occupancy, calculate traversals, and enqueue arrival. |
| Arrival | Convert the destination reservation to occupancy, mark the trip completed, and enqueue activity completion. |
| Completion | End the planned dwell period. A declared anchor break schedules its return trip. Ordinary completion does not automatically send the person home. |
| Break return | Attempt the trip back using the held anchor reservation. |
| Entry | Admit an outside agent at its gateway if capacity allows, then schedule a decision at that time. |
| Exit | Remove an agent from the modeled area and release its occupancy and reservations. This is a presence boundary, not a simulated onward journey. |
A person's location is either a facility, a trip in progress, or outside the modeled area. Protected activities and breaks add scheduling constraints to those states. After an ordinary activity ends, the person remains at the facility until another trip or exit. Ending dwell does not free physical capacity. Author a home-return agenda item if people should go home.
Follow one person
The first simulation supplies one shopping decision at minute 10, a 100-metre walking edge, 20 minutes of dwell, no congestion, and no later agenda. Its timeline is:
| Simulation minute | What happens |
|---|---|
| 0 | The person occupies home. |
| 10 | The shopping decision selects the shop. One shop slot is reserved; home occupancy drops to zero. |
| Approximately 11.19 | Arrival converts the reservation to shop occupancy. The trip outcome becomes completed. |
| Approximately 31.19 | The planned shopping dwell ends. The person stays at the shop because there is no further trip. |
| 120 | The run ends. The shop still has one occupant. |
There are three processed events in this example: decision, arrival, and completion. The decision starts travel directly, so it does not need a separate departure event. There is also no event for every intermediate position on the edge. Traversal times are calculated when the trip starts; playback interpolates the recorded movement.
Simultaneous events
The queue orders currently pending events by:
- Simulation time.
- Event priority: completion, arrival, entry, break return, departure, decision, exit.
- Resolved agent order.
- Insertion sequence.
An event can enqueue another event at the same time; that new event is ordered among those still pending. This is sequential processing, not a simultaneous negotiation among agents. Earlier agents can reserve scarce capacity before later agents. Explicit agents retain input order; generated cohorts are processed in stable cohort-ID order. Reordering authored agents is therefore a model change, not just formatting.
Three different clocks
| Clock | Meaning |
|---|---|
| Simulation time | Minutes within the modeled time window; drives event ordering and schedules. |
| Execution time | Real elapsed time spent calculating the run. Progress callbacks report phases and simulated time, not a reliable remaining-time estimate. |
| Playback time | A viewer's position in an already computed result. Seeking, pausing, and playback speed do not rerun the model. |
observationIntervalMinutes groups results into reporting buckets; it is not an agent update timestep. Events still occur at their own times. Congestion uses a separate scenario.mobility.congestion.windowMinutes setting, defaulting to five minutes. Observation resolution does not change movement or decisions. Read routing and capacity for the calculation.
Run boundaries and stopping
The window ends at startMinute + durationMinutes; events exactly at the end are processed, while later events are not. A trip still in progress at the horizon is recorded as cancelled, with interruptedAtMinute and interruptionReason. A partial traversal has completed: false and retains its plannedExitMinute for correct interpolation. Observations include its entry and elapsed travel, but no completed exit. Presence exits use the same accounting; stale arrivals cannot revive an exited agent. Reservations are released exactly once. This is different from aborting execution: an AbortSignal or dispose() cancels the run promise with an AbortError, rather than returning a partial result.
A new run does not resume a saved result or replay history before its start time. Author placement and schedules for the intended window. There is no automatic daily repeat, warm-up period, live stepping, or execution pause/resume.
Continue with schedules and decisions, routing and capacity, and reading results.
Opt-in routed gateway exits
mobility.householdTravel.gatewayExitPolicy: "route-to-gateway" changes the interpretation of an inbound agent's planned exitMinute: it starts the return to that agent's gateway. The ordinary mode, network, seat and vehicle-location constraints still apply. An active trip completes before the return is attempted; future ordinary activity requests cannot divert a pending return. A person already at the gateway exits immediately. Use vehicleTourPolicy: "return-home" when a chosen household car must remain with its driver throughout the tour.
Resolved result agents carry typed gatewayReturn metadata with the planned exit, completion status and actual exit time when completed. Their result exitMinute is the actual departure from the modeled district. Failed or horizon-interrupted returns omit that actual exit, so playback does not falsely hide the traveler. The input snapshot retains the authored planned exit. An unreachable return is recorded as unmet travel; the engine does not create a road connection, driver, vehicle or instantaneous gateway jump. This policy does not infer full journeys outside the modeled boundary or household escorts for independent arrivals.
Omitting the policy preserves legacy presence-exit interruption and replay interpretation. Existing result documents need no new fields.
Optional school escort duties
mobility.householdTravel.escortPlanning: 'school-round-trips' adds conservative home–school–home drop-off and pickup duties after school anchors are assigned. It uses an existing adult household driver, a household vehicle with a passenger seat, and routed travel time. Authored adult and child commitments are preserved; conflicts and missing resources prevent new duties. Existing compatible journeys may still serve the child. Resolved child agents expose schoolEscortPlans with the planned driver or exclusion reason.
Planning does not reserve a vehicle or guarantee boarding. The ordinary runtime vehicle location, reservation, seat, mode-choice and shared-journey checks remain authoritative. Person trips and vehicle movements retain separate counts. Omit the option to preserve legacy scheduling exactly.
This first policy requires round trips from home. It does not rearrange work, combine siblings into a single duty, chain a school drop-off directly to work, or arrange walking/transit accompaniment. Those limitations must be reported when evaluating a population; planning a duty is not evidence that its trip was completed or that household travel has been calibrated.
After an intervening discretionary visit completes, the next generated escort departure is recalculated from the actual arrival facility and activity end. The obsolete departure event is ignored; the pickup appointment and shared passenger departure remain unchanged. This correction is specific to generated escort duties and does not provide general dynamic rescheduling of every authored agenda.
Generated drop-off, pickup and home agenda markers last one minute. That is an explicit scheduling assumption, not a measured NHTS duration or a calibrated parking cost. Actual travel durations still come from the routed journey.
Conditioned local journeys
Explicit agents may opt into conditionedJourneys: ordered records with a stable id, sourceRevisionId, local departureMinute, origin/destination facility IDs, activity, mode, scope (entry, internal, exit) and vehicle contribution. These are supplied demand, not independent predictions of trip volume, mode, purpose or departure time. The caller resolves geography and separates any external journey from the simulated local leg before submitting the input.
One person retains one identity across repeated visits. Entry is allowed only while outside; internal and exit journeys must start at the person's actual facility. A trip still in progress, missing prior exit or mismatched origin produces a diagnostic; the engine does not relocate the person to repair a diary. An exit removes presence only after the local trip actually reaches its destination. Routing, enabled/available modes and destination capacity remain enforced. A conditioned journey within the same facility reuses the traveler’s occupied place rather than requiring a second place. Arrivals by other people still require available capacity. Conditioned agents cannot also carry household membership, generated schedules, legacy presence windows or independent activity needs. Other agents retain their normal household and behavior rules.
source-driver counts a supplied vehicle movement without claiming to reconstruct its household inventory or vehicle identity. source-passenger-unknown preserves the person trip without inventing a driver or adding a car to congestion. Its actual vehicle allocation and marginal congestion contribution remain unknown, not zero. Trips retain this label and edge observations expose unknownVehicleContributionPersonEntries separately from known vehicleEntries and personEntries. Congestion consequently represents known contributions only. Use not-applicable for movement without this road-vehicle interpretation.
Results record actual conditionedPresence intervals, including the entry facility. Portable replay datasets and headless position sampling preserve multiple visits and hide the person between visits. Legacy scenarios and results omit these fields and retain their existing interpretation. This feature does not establish joint passenger/driver feasibility or validate a conditional model against its own inputs.
Supplied purpose and primary mode
Conditioned journeys may include sourcePurpose and sourcePrimaryMode. These optional descriptive labels survive completed and failed trip records, archive round-trips and dataset inspection. They do not change routing, capacity activity, mode availability or vehicle accounting. For example, a supplied transit journey may have a walking local last mile, or a supplied social visit may use a residential facility. Keep the original source labels separate from the actual local activity and routed mode; reproducing them is input reproduction, not independent validation. Legacy inputs without these labels retain their existing output shape.
A first internal or exit journey may set initialObservation: true when the source only establishes a local origin at departure. Tracking begins there at that departure, preserving the journey's internal/exit lifecycle. This avoids inventing midnight occupancy or retaining a person after an initial outbound trip. It is an explicit initial-state assumption, not an observed boundary entry. Only the first journey may use it; later missing connections cannot reset location.