← Lesson diary · Process Identification and Control
Process Identification and Control · Lesson 2
The storage tank of Lesson 2, controlled twice at the same time: a classical PID on the left, the constrained MPC of the lecture on the right. Same tank, same demand, same pump limit — the only difference is that MPC solves an optimization problem over a prediction window at every sampling time. The simulation runs on its own; every parameter below can be changed while it runs.
| Controller | Mean |x − xref| | Lowest level | Highest level | Time outside limits | Worst excursion | Water pumped |
|---|---|---|---|---|---|---|
| PID | — | — | — | — | — | — |
| MPC | — | — | — | — | — | — |
The two controllers pump almost the same total water, and they must: over a run that starts and ends near the reference, mass balance fixes the total at whatever the demand took out. What separates them is when they pump it.
KKT certificate: —
The MPC problem has stayed feasible so far: every level limit it was asked to respect was still reachable with the pump it has.
Exactly the formulation of the lecture, with the absolute time k and the relative time i inside the window.
Only u0|k is applied and the rest of the sequence is discarded, then the whole problem is rebuilt one minute later — the receding horizon of Lesson 1. Sampling time T = 1 min, tank capacity 100 m³, limits 20–90 m³.
A quadratic program with inequalities has no closed-form solution, because which constraints are active is not known in advance — that is the content of the complementarity conditions. So the page solves it in two phases. First a projected Newton method, with the pump limits enforced exactly by projection and the level band as a heavily penalized soft constraint, gives a solution in fewer than ten iterations and tells us which constraints are active. Then the KKT system of that active set is solved exactly, once, and the result is checked: every constraint satisfied, every multiplier with the right sign. When the check passes, the applied control is provably optimal.
An MPC algorithm is recursively feasible when a problem that admits a solution at one sampling time keeps admitting one at every future time. This tank shows how that property can be lost. Take 07:45 with a short window: the level is 36 m³, the demand is 2.35 m³/min against a pump that gives at most 1.20, so the tank keeps emptying at 1.15 m³/min whatever the controller does, and the peak still has 25 minutes to run. The level will reach 7 m³, and no admissible sequence of inputs can respect the 20 m³ limit. The feasible set is empty, and no solver can do anything about it. With the default window the same controller sees the end of the peak already at 07:00 and fills the tank while it still can.
Watch the limit unreachable badge appear on the MPC readout: it lights up while the constraint is impossible, usually a few minutes before the level actually crosses the limit.
Two ways out, both standard. Give the problem a longer window and a terminal condition, so the controller commits early enough to keep a solution available — this is how recursive feasibility is proved. Or accept that the constraint may become impossible and write it as a soft constraint, with a slack variable that is heavily penalized in the objective: the problem stays feasible and the controller minimizes the violation instead of failing.
This page takes the second road: the level band is written as a soft constraint, penalized so heavily that the controller respects it to within centimetres whenever it can, and minimizes the violation when it cannot. Nothing saturates the pump by hand — the optimizer arrives at maximum flow on its own, because that is the best it can do.