Repository navigation
Add the tram route model to the experimental examples - #3796
Merged
Merged
Conversation
Demonstrates continuous states and thresholds: a tram accelerates, coasts, brakes and dwells its way along a route, with every transition solved for analytically and scheduled on the event queue rather than polled for on each tick.
Collaborator
Author
|
The core logic resides in |
|
Performance benchmarks:
|
jackiekazil
approved these changes
Aug 13, 2026
jackiekazil
left a comment
Member
There was a problem hiding this comment.
This looks good.
Thank you for breaking this into another PR & for adding the UI & the little tram icon is a nice touch.
Member
|
Thank you @codebreaker32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Tram Route Model under
mesa/examples/experimental/, as a worked demonstration ofmesa.experimental.states—ContinuousStateandThreshold( ref #3766 )What it models
A single tram runs an ordered route of stations. Leaving a stop it accelerates at a fixed rate, coasts once it reaches cruise speed, brakes at an analytically-computed point, arrives, dwells, and departs for the next stop.
Why this example
Every transition is a
Thresholdcrossing rather than a per-tick check:The two things it is meant to show:
speed' = accelerationandposition' = speed, so position extrapolates as a piecewise quadratic and is exact at any time between events — never a stale value waiting for the next tick.cruise_speedandbrake_pointareObservables, andbrake_pointis rewritten at the start of every segment. The thresholds observe those attributes and re-solve for the new crossing time themselves; nothing re-arms them.The result is a model with no per-agent step logic.
TransitSystem.stepexists only to sample for theDataCollectorbehind the plots, delete it and the tram still runs the route with identical timings, driven entirely by the event queue.The brake point is derived from the segment's peak speed,
min(cruise_speed, sqrt(2d / (1/a + 1/b))), not from cruise speed. On a short segment, or with weak acceleration, the tram never reaches cruise speed; assuming it does puts the brake point outside the segment, and a rising threshold that begins already past its limit never fires at all. This matters because the app exposes all four kinematic parameters as sliders.Visualization