LQR & Riccati Equation

When urban dynamics can be linearised and costs are quadratic, the optimal control problem admits a beautiful closed-form solution: the Linear Quadratic Regulator (LQR). The optimal feedback gains come from solving the algebraic Riccati equation, which we derive and apply to traffic signal control of queue lengths.

1. Linear State-Space Model

Consider a network of \(n\) signalised intersections with queue lengths assembled into the state vector \(\mathbf{x}(t) \in \mathbb{R}^n\) and green time allocations forming the control vector \(\mathbf{u}(t) \in \mathbb{R}^m\). Linearising the store-and-forward model about a nominal operating point gives:

$$\frac{d\mathbf{x}}{dt} = A\mathbf{x} + B\mathbf{u}$$

For a corridor with three intersections, the system matrix \(A\) captures queue interactions and the input matrix \(B\) maps green time to queue discharge:

$$A = \begin{pmatrix} -\mu_1 & 0 & 0 \\ \mu_1 & -\mu_2 & 0 \\ 0 & \mu_2 & -\mu_3 \end{pmatrix}, \quad B = \begin{pmatrix} -\mu_1 & 0 & 0 \\ 0 & -\mu_2 & 0 \\ 0 & 0 & -\mu_3 \end{pmatrix}$$

The diagonal of \(A\) represents queue discharge at saturation flow, while the sub-diagonal entries capture platoon transfer from upstream to downstream intersections.

2. Quadratic Cost Functional

The LQR objective balances two competing goals: minimise queue lengths (delay) and minimise control effort (signal changes). The infinite-horizon cost functional is:

$$J = \int_0^\infty \left( \mathbf{x}^T Q \mathbf{x} + \mathbf{u}^T R \mathbf{u} \right) dt$$

The weight matrices encode engineering priorities:

  • State weight \(Q \succeq 0\): Penalises queue lengths. Diagonal entries weight each intersection; off-diagonal entries can penalise differences between neighbouring queues (equity).
  • Control weight \(R \succ 0\): Penalises aggressive signal changes. Larger \(R\) produces smoother, less responsive control. Must be positive definite.

The ratio \(Q/R\) determines how aggressively the controller acts: large ratio means fast queue reduction at the cost of frequent signal changes; small ratio means gentle control with larger residual queues.

3. Deriving the Optimal Feedback Law

We apply the PMP from the previous chapter. The Hamiltonian is:

$$H = \mathbf{x}^T Q \mathbf{x} + \mathbf{u}^T R \mathbf{u} + \boldsymbol{\lambda}^T (A\mathbf{x} + B\mathbf{u})$$

Setting \(\partial H / \partial \mathbf{u} = 0\):

$$2R\mathbf{u} + B^T \boldsymbol{\lambda} = 0 \implies \mathbf{u}^* = -\tfrac{1}{2} R^{-1} B^T \boldsymbol{\lambda}$$

The key ansatz: assume the costate is linear in the state, \(\boldsymbol{\lambda} = 2P\mathbf{x}\), where \(P\) is a symmetric positive definite matrix. Then:

$$\mathbf{u}^* = -R^{-1} B^T P \mathbf{x}$$

This is a state feedback law: the optimal control is a linear function of the current queue lengths, with gain matrix \(K = R^{-1} B^T P\).

4. The Algebraic Riccati Equation

Substituting the feedback law into the costate equation and requiring consistency gives the Continuous Algebraic Riccati Equation (CARE):

$$PA + A^T P - PBR^{-1}B^T P + Q = 0$$

This is a matrix equation for the unknown \(P \in \mathbb{R}^{n \times n}\). Key properties:

  • Existence and uniqueness: A unique stabilising solution \(P \succeq 0\) exists if and only if \((A, B)\) is stabilisable and \((A, Q^{1/2})\) is detectable.
  • Closed-loop stability: The eigenvalues of \(A - BR^{-1}B^T P\) all have negative real parts.
  • Optimality certificate: The optimal cost from state \(\mathbf{x}_0\) is \(J^* = \mathbf{x}_0^T P \mathbf{x}_0\).

To derive CARE, substitute \(\boldsymbol{\lambda} = 2P\mathbf{x}\) into the costate ODE:

$$\dot{\boldsymbol{\lambda}} = 2P\dot{\mathbf{x}} = 2P(A - BR^{-1}B^TP)\mathbf{x}$$

From PMP, \(\dot{\boldsymbol{\lambda}} = -2Q\mathbf{x} - 2A^TP\mathbf{x}\). Equating and requiring the relation to hold for all \(\mathbf{x}\) gives CARE.

5. Solving the Riccati Equation with SciPy

We solve CARE for a 4-intersection network, compute the LQR gain, simulate the closed-loop response, and compare it to an uncontrolled system.

LQR Traffic Signal Control via Riccati Equation

Python
script.py136 lines

Click Run to execute the Python code

Code will be executed with Python 3 on the server

6. Pseudo-Time Integration for the Riccati Equation

An alternative to direct algebraic solvers is pseudo-time integration: we introduce a fictitious time \(\tau\) and solve the matrix differential equation:

$$\frac{dP}{d\tau} = -\left( PA + A^T P - PBR^{-1}B^T P + Q \right)$$

Starting from any \(P(0) \succeq 0\), this flow converges to the steady state \(dP/d\tau = 0\), which is precisely the CARE solution. The right-hand side is the negative of the Riccati residual, so convergence corresponds to the residual vanishing.

This approach is implemented in Fortran below using explicit Euler integration with symmetry enforcement at each step.

Pseudo-Time Integration for Riccati Equation (Fortran-style approach in Python)

Python
script.py94 lines

Click Run to execute the Python code

Code will be executed with Python 3 on the server

7. Robustness Properties of LQR

The LQR controller enjoys remarkable robustness guarantees, often called the “Kalman robustness margins”:

  • Gain margin: The closed-loop system remains stable for any gain perturbation in the range \([\frac{1}{2}, \infty)\).
  • Phase margin: At least \(60°\) per channel.
  • Disk margin: The Nyquist plot of each loop avoids a disk of radius \(\frac{1}{2}\) centred at \(-1\).

These margins mean the LQR signal controller tolerates substantial modelling errors: if the actual saturation flow rates differ by up to a factor of 2 from the design values, the system remains stable. This is critical for urban applications where traffic demand is inherently uncertain.

Key Takeaway

LQR provides the optimal linear feedback law for quadratic cost problems. The Riccati equation encodes the full future cost into a single matrix \(P\), enabling real-time computation of optimal green times from measured queue lengths. The built-in robustness margins make it practical for the uncertain environment of real traffic networks.