Theory
Mathematical Formulation & Transcription¶
Multiphase OCP¶
A multiphase optimal control problem consists of \(N_{\text{phases}}\) sequential or interconnected phases, indexed by \(p \in \{1, \dots, N_{\text{phases}}\}\). The framework solves problems of the general form:
Subject to the following dynamics and constraints for each phase \(p = 1, \dots, N_{\text{phases}}\):
And across-phase linkage constraints (e.g., state continuity, time coordination, or event conditions):
Variable & Function Definitions¶
| Name | Description | Shape |
|---|---|---|
| \(N_{\text{phases}}\) | Total number of phases | \(\mathbb{Z}^+\) |
| \(p\) | Phase index (\(p \in \{1, \dots, N_{\text{phases}}\}\)) | \(\mathbb{Z}^+\) |
| \(t\) | Independent variable (Time) within phase \(p\) | \(\mathbb{R}\) |
| \(t_0^{(p)}\) | Initial time of phase \(p\) | \(\mathbb{R}\) |
| \(t_f^{(p)}\) | Final time of phase \(p\) | \(\mathbb{R}\) |
| \(x^{(p)}(t)\) | State vector in phase \(p\) | \(\mathbb{R}^{n_x^{(p)}}\) |
| \(x_0^{(p)}\) | Initial state of phase \(p\) | \(\mathbb{R}^{n_x^{(p)}}\) |
| \(x_f^{(p)}\) | Final state of phase \(p\) | \(\mathbb{R}^{n_x^{(p)}}\) |
| \(u^{(p)}(t)\) | Control input vector in phase \(p\) | \(\mathbb{R}^{n_u^{(p)}}\) |
| \(J\) | Total objective function / Cost functional | \(\mathbb{R}\) |
| \(L^{(p)}\) | Running cost (Lagrange term) for phase \(p\) | \(\mathbb{R}\) |
| \(E^{(p)}\) | Terminal cost (Mayer term) for phase \(p\) | \(\mathbb{R}\) |
| \(f^{(p)}\) | System dynamics function for phase \(p\) | \(\mathbb{R}^{n_x^{(p)}}\) |
| \(e^{(p)}\) | Boundary / Endpoint constraint function for phase \(p\) | \(\mathbb{R}^{n_e^{(p)}}\) |
| \(h^{(p)}\) | Path constraint function for phase \(p\) | \(\mathbb{R}^{n_h^{(p)}}\) |
| \(g\) | Phase linkage / transition constraint function | \(\mathbb{R}^{n_g}\) |
| \(x_{lb}^{(p)}, x_{ub}^{(p)}\) | State lower and upper bounds for phase \(p\) | \(\mathbb{R}^{n_x^{(p)}}\) |
| \(u_{lb}^{(p)}, u_{ub}^{(p)}\) | Control lower and upper bounds for phase \(p\) | \(\mathbb{R}^{n_u^{(p)}}\) |
| \(e_{lb}^{(p)}, e_{ub}^{(p)}\) | Boundary constraint bounds for phase \(p\) | \(\mathbb{R}^{n_e^{(p)}}\) |
| \(h_{lb}^{(p)}, h_{ub}^{(p)}\) | Path constraint bounds for phase \(p\) | \(\mathbb{R}^{n_h^{(p)}}\) |
| \(g_{lb}, g_{ub}\) | Linkage constraint bounds | \(\mathbb{R}^{n_g}\) |
Transcription: From Multiphase OCP to NLP¶
To solve the infinite-dimensional continuous multiphase OCP on a digital computer, the problem is transcribed into a finite-dimensional Nonlinear Program (NLP) by applying direct collocation or multiple shooting independently across each phase while enforcing phase linkage constraints.
A. Time Grid Discretization¶
For each phase \(p \in \{1, \dots, N_{\text{phases}}\}\), the continuous time horizon \([t_0^{(p)}, t_f^{(p)}]\) is divided into \(n^{(p)}\) intervals of length \(\Delta t^{(p)} = \frac{t_f^{(p)} - t_0^{(p)}}{n^{(p)}}\), generating \(n^{(p)} + 1\) mesh grid points:
(Note: For sequential phases, the final time of phase \(p\) typically coincides with the initial time of phase \(p+1\), i.e., \(t_f^{(p)} = t_0^{(p+1)}\).)
B. NLP Decision Vector (\(W\)) Structure¶
The continuous functions \(x^{(p)}(t)\) and \(u^{(p)}(t)\) for every phase are parameterized by state values at the grid nodes and control values over intervals. The global NLP decision variable vector \(W\) is assembled by concatenating the free time variables, state matrices, and control matrices across all phases:
- Time variables (\(T_{\text{free}}\)): Includes all free initial, final, or duration times across the phases (e.g., \(t_0^{(1)}, t_f^{(1)}, t_f^{(2)}, \dots, t_f^{(N_{\text{phases}})}\)). Fixed times are omitted from \(W\).
- State Matrix (\(X^{(p)}\)) for phase \(p\): Dimensions \(n_x^{(p)} \times (n^{(p)} + 1)\), flattened into a column vector containing all states across all nodes in phase \(p\):
- Control Matrix (\(U^{(p)}\)) for phase \(p\): Dimensions \(n_u^{(p)} \times n^{(p)}\), flattened into a column vector containing control inputs across all intervals in phase \(p\):
C. Objective Function Discretization¶
The continuous cost functional is discretized by summing the approximated integrals (Lagrange terms) and terminal costs (Mayer terms) across all phases:
(Note: Depending on the chosen numerical quadrature rule—such as trapezoidal or Simpson's rule—appropriate quadrature weights replace the uniform interval scaling factor).
D. Constraint Vector (\(G(W)\)) Structure¶
All constraints across all phases are stacked vertically into a single global vector \(G(W)\) bounded by lower and upper limits (\(G_{lb} \leq G(W) \leq G_{ub}\)):
- Phase Boundary / Endpoint Constraints: Evaluated at the start and end of each phase \(p\):
- Inter-Phase Linkage Constraints: Enforces boundary, transition, or matching conditions between connected phases (e.g., state continuity \(x_f^{(p)} = x_0^{(p+1)}\) or time synchronization):
- System Dynamics / Defect Constraints: Enforces physical consistency between nodes using the chosen integration method independently for each phase \(p\) (e.g., \(x_{k+1}^{(p)} - x_k^{(p)} - \Delta t^{(p)} f^{(p)}(\cdot) = 0\)):
- Path Constraints: Evaluated across all grid nodes \(k = 0, \dots, n^{(p)}\) for each phase \(p\) (using zero-order hold extension for control inputs at the final node):
Assembled Final Multiphase NLP Formulation¶
Combining the discretized objective function, stacked multiphase constraints, and decision vector bounds, the fully assembled Nonlinear Program (NLP) solved by CasADi and IPOPT takes the following standard mathematical form:
Subject to the composite constraints:
where the global constraint vector \(G(W)\) aggregates the boundary, linkage, dynamics (defects), and path constraints across all phases:
With corresponding lower and upper constraint bounds:
And subject to simple variable bounds on the global decision vector \(W\):
where:
Discretization & Integration Methods¶
The framework supports flexible transcription strategies where each phase can independently configure its own integration and collocation backend, categorized into Direct Multiple Shooting and Direct Collocation:
- Direct Multiple Shooting (Explicit & Adaptive Integrators):
fw_euler: Forward Euler (explicit 1st-order).exp_mid: Explicit Midpoint (2nd-order Runge-Kutta).rk4: Standard 4th-order Runge-Kutta (via CasADi integrator).cvodes: Adaptive-step ODE/DAE integrator from SUNDIALS (ideal for stiff dynamics).-
collocation: Implicit collocation polynomials via CasADi. -
Direct Collocation (Implicit Methods):
bw_euler: Backward Euler (implicit 1st-order, highly stable).trap: Trapezoidal collocation (implicit 2nd-order).her_sim: Hermite-Simpson collocation (cubic polynomial approximation).