TL;DR
Model predictive control (MPC) picks an action by simulating a short window of the future with a model of the system, and choosing the action sequence that gives the lowest cost over that window. It then applies only the first action and throws the rest away. At the next step it measures the new state and plans again, so the plan is always built from where the system actually is.
Where you'll see it: robot and vehicle controllers, chemical plants, and planning modules in model-based reinforcement learning agents.
Intuition
Planning a few moves ahead, then looking again
A driver steering along a winding road does not commit to a full route on the first glance. They look a short distance ahead, pick a steering path that keeps them in the lane, and turn the wheel a little. A moment later they look again, because the car has moved and the road may bend in a way they did not expect. Each decision uses a short plan, but only the first move is carried out.
MPC is that habit written as an algorithm. The "model" is a prediction of how the system responds to actions. The "horizon" is how far ahead the plan looks. The "receding" part is what happens next: the window slides forward one step, and the whole optimisation runs again.
Why not plan once and execute the plan?
Optimal control can solve for the best action sequence over a whole task, once, at the start. This is called open-loop control. It works only if the model is exact and nothing unexpected happens. Real systems drift. A gust of wind pushes the car, a motor is weaker than the model says, or the model simply ignores some effect. The plan built at time zero is then wrong by time five.
Re-planning fixes this. Each new plan starts from the measured state, so errors are corrected as they appear. The price is that you must solve an optimisation at every step, and that the plan only looks as far ahead as the horizon allows. That trade is the heart of MPC: a finite look-ahead, redone often, instead of one perfect plan that cannot adapt.
The loop
flowchart LR A[Measure current state] --> B[Predict H steps ahead with the model] B --> C[Choose the action sequence with lowest cost] C --> D[Apply only the first action] D --> E[System moves to a new state] E --> A
The math
Take a discrete-time system with state and action . The model is a function that predicts the next state:
Here counts steps, is the vector of numbers that describes the system at step , and is the input we choose. (The continuous-time version of this, with a differential equation, is in Optimal Control.)
At time , with measured state and horizon , solve
subject to and any constraints on the states and actions. Here is the running cost, which scores each step, and is the terminal cost, which scores where the plan ends. Apply the first action , discard the rest, and repeat at time .
Three design choices define an MPC controller:
- The cost. A common choice is , which penalises distance from a target and the size of the action. and are weight matrices that set the trade-off.
- The horizon . Too short and the controller is myopic; it may run into a wall it could have avoided. Too long and the optimisation is slow and the model's errors compound over the prediction.
- The constraints. Limits on actuators (for example ) and on the state (for example staying inside a safe region) are written directly into the optimisation. This is the feature that most separates MPC from simpler feedback laws.
Why re-planning gives feedback
Because only the first action is used, and the plan is rebuilt from , the action is a function of the current state: . That makes MPC a feedback law. For an unconstrained linear system with a quadratic cost, the optimal feedback is linear, , with a gain that comes from the Riccati solution of Optimal Control. With a suitable terminal cost (or a long enough horizon), the first action of the finite-horizon problem matches that gain, which is why MPC is often described as a constrained generalisation of linear-quadratic control.
Worked examples
The system is , a position that moves by the action. The cost is with terminal cost . Use horizon , and start at .
- Write the states in terms of the actions. and .
- Write the cost. , where the is and is fixed.
- Minimise over first. Set , which gives , so .
- Substitute. With , the cost in becomes plus constants, where .
- Minimise over . The derivative is , so and .
- Apply only the first action, . The state becomes .
- Re-plan at . The problem is linear and the cost is quadratic, so the optimal first action scales with the state. The gain is , so , and the new state is .
Interpretation: the first action pulls the state toward zero by a factor of per step, and the same rule is applied again each time. Planning two steps ahead produced a simple feedback law, . The figure below shows the closed-loop state.
- closed loop, x_0 = 2
- target
Keep the system, cost and horizon, but add the constraint . The unconstrained rule would ask for , which the actuator cannot deliver.
- Search over action pairs with .
- The cost is .
- Evaluate the candidates that matter. gives , , and . The unconstrained-optimal pair costs , but it is not allowed.
- A grid search over the box confirms that is the best feasible pair, with .
- Apply . The state becomes , and the controller re-plans from there.
Interpretation: the constraint changes the first action from to . Clipping the unconstrained answer to happens to give the same result here, but in general the best feasible first action also depends on how the constraint affects later steps, so the constrained problem has to be solved, not clipped. This is why MPC is used when limits matter: a linear feedback gain cannot respect a hard actuator bound, but a constrained optimisation can.
Tradeoffs and failure modes
MPC is powerful because it handles constraints and nonlinear models. It is expensive because it solves an optimisation at every step. The table gives the common situations.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Fast system, small compute budget | The optimisation takes longer than the control interval, so the action is late | Shorter horizon, warm-start from the previous plan, or explicit MPC with precomputed regions |
| Model is inaccurate over long predictions | Errors grow with the horizon, and the plan is confidently wrong | Shorter horizon, or a model that is accurate near the operating point |
| Nonlinear or non-differentiable model, many actions | Gradient solvers stall at local minima or cannot run | Sampling-based planners such as the Cross-Entropy Method or random shooting |
| Linear system, quadratic cost, no constraints | MPC is overkill, and the optimisation adds delay | Linear-quadratic regulator from Optimal Control |
| Rare but dangerous states | A short horizon does not see the danger until it is too late | Longer horizon, or a terminal constraint that keeps the plan inside a safe set |
There is also a stability question. With a short horizon and no terminal cost, MPC can be unstable even when each plan looks reasonable. Standard designs add a terminal cost and a terminal constraint so that the controller's cost keeps decreasing from step to step. This is a theorem about the design, not a property you get for free, so it must be checked for the specific controller.
When the model is learned rather than given, MPC is combined with a World Model. The planner then depends on the model's accuracy, which is the main reason model-based methods are sensitive to prediction errors. The Model-Based Reinforcement Learning lesson covers how the model is fitted.
History
Model predictive control grew out of process-industry practice in the late 1970s. Engineers in chemical and oil plants needed controllers that could respect limits on temperatures, flows and pressures. Early industrial methods, associated with Richalet and colleagues and with Cutler and Ramaker, used linear models of the plant, so the optimisation stayed simple enough for the computers of the time.
Theory followed in later decades, with stability results built on terminal costs and constraints and extensions to nonlinear models. Faster optimisers and cheaper computers then made MPC practical for fast systems such as robots and vehicles.
In machine learning, the idea reappears as a planning method on top of a learned model. TD-MPC2 plans in the latent space of a learned world model using MPPI, a sampling-based optimiser: it samples action sequences, rolls them out with the model, and executes only the first action before re-planning.
Check yourself
QuestionWhy does MPC apply only the first action of the planned sequence, rather than executing the whole plan?Show answer
Because the model is imperfect and the system is disturbed. Each step, the controller measures the real state and re-plans from it, so errors are corrected before they grow. Executing the full plan would be open-loop control, and small errors would accumulate across the horizon.
QuestionIn the one-dimensional example with x_0 = 2 and H = 2, the first unconstrained action is u_0 = -1.2. What is the state x_1, and what is the cost of the pair (u_0, u_1) = (-1.2, -0.4)?Show answer
x_1 = 2 + (-1.2) = 0.8. The cost of the pair is 4 + 1.44 + (0.64 + 0.16) + 0.16 = 6.4, using x_0 squared, u_0 squared, x_1 squared plus u_1 squared, and x_2 squared with x_2 = 0.4. This is the lowest cost reachable without the constraint.
QuestionA planner with horizon 2 is never able to see a wall that is 5 steps ahead. Why might it still hit the wall, and what changes would help?Show answer
The wall is outside the planned window, so the cost of hitting it is never added to the plan. The controller can drive toward it while every plan it builds looks fine. Lengthening the horizon, or adding a terminal cost or constraint that encodes the safe region, lets the cost see the danger earlier.
QuestionFor a system with a learned model, why does a longer horizon not always give a better plan?Show answer
Model errors compound with each predicted step, so the far end of a long plan is built on inaccurate predictions. The optimiser may then choose actions that exploit those errors. Each re-plan also takes longer as the horizon grows. The horizon should be long enough to see the consequences that matter, and no longer.
QuestionAn unconstrained linear system with a quadratic cost has a closed-loop rule u = -0.6x. Name a constraint that this rule cannot respect, and how MPC handles it.Show answer
An actuator limit such as |u| at most 1. The rule asks for u = -1.2 when x = 2, which the actuator cannot deliver. MPC writes the limit into the optimisation, so the first action it applies is the best feasible one, here u = -1.0, and it re-plans from the resulting state.
Sources
- Wikipedia: Model predictive control
- Wikipedia: Optimal control
- Hansen, Su, Wang (2023), TD-MPC2: Scalable, Robust World Models for Continuous Control: https://arxiv.org/abs/2310.16828