Dynamic Programming and the Four Driving Regimes
Open the Automatic Train Operation app
Advanced Control Exercise 14 of 30 in Optimal Control · All exercises · Time: 15 minutes
A train must reach the next station on time with as little energy as possible. Optimal control theory says the answer is made of only four regimes, full power, holding speed, coasting and full braking, and the only questions are where to switch. This exercise compares a plan with one coast point against a dynamic program that searches every speed at every 50 m.
Learning Outcomes
- State Bellman's principle and write the recursion a dynamic program solves on a grid.
- Explain from Pontryagin's principle why an energy-optimal drive uses only four regimes.
- Compare flat-out running, a one-coast-point plan and a dynamic program by energy and punctuality.
Book Chapter
Model Predictive Control and Economic Optimization (Volume 9), Chapter 12, Automatic Train Operation Simulator Where the Timetable Decides Where to Coast. Read the chapter, open the PDF, or watch the lecture slides.
Theory in Brief
The train's speed `v` along the distance `s` follows Newton's law with traction `F`, running resistance `R(v)` and grade `\alpha(s)`:
$$\begin{gathered} m\, v \frac{dv}{ds} = F - R(v) - m g \sin\alpha(s), \\ \min_{F} \int_0^{S} F^{+}\, ds \\ \mathrm{s.t.}\quad \int_0^S \frac{ds}{v} = T,\;\; v \le \bar v(s),\;\; F_{min} \le F \le F_{max} \end{gathered}$$
Adjoin the time constraint with a multiplier `\mu`. The Hamiltonian is linear in `F`, so the optimal `F` sits at a bound or on a singular arc: full power, coasting at `F = 0`, full braking, or holding the speed where `F = R + mg\sin\alpha`. Those are the four regimes, and only the switching points are free. A dynamic program finds them numerically by Bellman's principle on a grid of distance `s_i` and speed `v_j`:
$$V_i(v) = \min_{F} \left[ \ell(v, F)\,\Delta s + V_{i+1}\left(v'(v, F)\right) \right], \qquad \ell = F^{+} + \frac{\mu}{v}$$
computed backward from the station. The trade `\mu` prices a second of running time in energy; adjusting it until the arrival time is met turns the time constraint into a cost.
Model: Physics-based. Point-mass train dynamics with running resistance, gradients and speed limits.
Decision: Where to switch between power, hold, coast and brake; one coast point in the analytic plan, every 50 m in the dynamic program.
Learning: None. Value functions like the dynamic program's are what reinforcement learning approximates when the model is unknown.
Exercise
Read 2 min · Predict 1 min · Run 7 min · Explain 3 min · Check your AI 2 min.
Predict. The four-regime plan arrives on time instead of early. How much less energy does it draw than flat out: a tenth, a third or half? Where along the route will the dynamic program save more?
Run the Automatic Train Operation app. Use the fastest speed, 30×, and press Run again to pause at the times in each step.
- Open 3 · The coast point: one decision, and what it saves. Press Run and let it reach B. Read Energy per km and Punctuality, and find the coast point on the Line view.
- Set Planner to Flat out, press Reset, and run to B. Compare with the Previous run tile.
- Open 5 · The dynamic program against the analytic plan and run it to B with the dynamic program. Read the same tiles and look at the Grid view.
Explain.
- Why can one decision, the coast point, save that much energy without losing the timetable?
- Both plans use only the four regimes. Why does the dynamic program spend less on this route?
Generative AI Learning
Check the answer against your run: A good answer writes a Hamiltonian linear in traction and concludes bang-bang or singular arcs. Check that it keeps the time constraint as a multiplier, and compare the energy saving it predicts with your step 2. The assistant is your tutor and reviewer; you answer for every claim you turn in.
What to Turn In
A three-row table (four regimes, flat out, dynamic program) with energy per km and punctuality, your written prediction, and three sentences that answer the two questions.

The four-regime plan reads 3.89 kWh/km · 19.5 kWh and B −3.1 s. Flat out reads 5.65 kWh/km · 28.2 kWh and B −21.0 s. Arriving on time instead of early costs about a third less energy, decided by one point where the power stops. Every second the flat-out run gains is bought with kinetic energy that the brakes later throw away.
The dynamic program reads 3.29 kWh/km · 16.4 kWh and B −1.7 s. It uses the same four regimes but more switches: it stops powering well before the 60 km/h curve and coasts down to it, so it arrives with little speed to brake away, then coasts again after the junction. Where speed limits interleave, more than one coast point pays, and the grid search finds them. On a route with one speed limit the two plans agree.
Measured with the app build of December 3, 2026 by a scripted replay of the steps above. Numbers that no tile shows come from the replay's record; your readings from the trends will be close. A later app release may move the last digit.
Benchmarks II solves minimum-time and minimum-energy problems in GEKKO. Pose this train problem on a flat 5 km line with one speed limit, minimize `\int F^+ ds` with a fixed arrival time, and plot the solution's traction: it should be power, then hold or coast, then brake.
Related
- Check yourself: three-question quiz
- Course pages: Benchmarks II, Reinforcement Learning, RL Algorithms
- Exercises: previous: 13 · Input Shaping Against a Predictive Controller; next: 15 · A Constrained Landing Trajectory
References
- Hedengren, J. D. (ed.), Model Predictive Control and Economic Optimization, Volume 9 of Interactive Control Engineering, Chapter 12, "Automatic Train Operation Simulator Where the Timetable Decides Where to Coast", pp. 287–310, Advanced Process Solutions, 2026. PDF (CC BY 4.0).
- Howlett, P., The optimal control of a train, Annals of Operations Research 98, 65–87, 2000.
