Skip to content

Commit c6d2410

Browse files
committed
doc: more details on NonLinMPC vector sizes
1 parent fabf0e0 commit c6d2410

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/controller/nonlinmpc.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ the weights to 0 except ``E`` creates a pure economic model predictive controll
125125
As a matter of fact, ``J_E`` can be any nonlinear function to customize the objective, even
126126
if there is no economic interpretation to it. The arguments of ``J_E`` and ``\mathbf{g_c}``
127127
include the manipulated inputs, predicted outputs and measured disturbances, extended from
128-
``k`` to ``k + H_p`` (inclusively):
128+
``k`` to ``k + H_p`` (inclusively, see Extended Help for more details):
129129
```math
130130
\mathbf{U_e} = \begin{bmatrix} \mathbf{U} \\ \mathbf{u}(k+H_p-1) \end{bmatrix} , \quad
131131
\mathbf{Ŷ_e} = \begin{bmatrix} \mathbf{ŷ}(k) \\ \mathbf{Ŷ} \end{bmatrix} , \quad
@@ -197,24 +197,27 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
197197
algebra instead of a `for` loop. This feature can accelerate the optimization, especially
198198
for the constraint handling, and is not available in any other package, to my knowledge.
199199
200-
The optimization relies on [`JuMP`](https://github.com/jump-dev/JuMP.jl) automatic
201-
differentiation (AD) to compute the objective and constraint derivatives. Optimizers
202-
generally benefit from exact derivatives like AD. However, the [`NonLinModel`](@ref)
203-
state-space functions must be compatible with this feature. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
204-
for common mistakes when writing these functions.
205-
206-
If `LHS` represents the result of the left-hand side in the inequality
207-
``\mathbf{g_c}(\mathbf{U_e}, \mathbf{Ŷ_e}, \mathbf{D̂_e}, \mathbf{p}, ϵ) ≤ \mathbf{0}``,
208-
the function `gc` can be implemented in two ways:
200+
The economic cost ``J_E`` and custom constraint ``\mathbf{g_c}`` functions receive the
201+
extended vectors ``\mathbf{U_e}`` (`nu*(Hp+1)` elements), ``\mathbf{Ŷ_e}`` (`ny*(Hp+1)`
202+
elements) and ``\mathbf{D̂_e}`` (`nd*(Hp+1)` elements) as arguments. If `LHS` represents
203+
the left-hand side result in the inequality ``\mathbf{g_c}(\mathbf{U_e}, \mathbf{Ŷ_e},
204+
\mathbf{D̂_e}, \mathbf{p}, ϵ) ≤ \mathbf{0}``, `gc` can be implemented in two ways:
209205
210206
1. **Non-mutating function** (out-of-place): define it as `gc(Ue, Ŷe, D̂e, p, ϵ) -> LHS`.
211207
This syntax is simple and intuitive but it allocates more memory.
212208
2. **Mutating function** (in-place): define it as `gc!(LHS, Ue, Ŷe, D̂e, p, ϵ) -> nothing`.
213209
This syntax reduces the allocations and potentially the computational burden as well.
214210
215211
The keyword argument `nc` is the number of elements in the `LHS` vector, and `gc!`, an
216-
alias for the `gc` argument (both accepts non-mutating and mutating functions). Note
217-
that if `Cwt≠Inf`, the attribute `nlp_scaling_max_gradient` of `Ipopt` is set to
212+
alias for the `gc` argument (both accepts non-mutating and mutating functions).
213+
214+
The optimization relies on [`JuMP`](https://github.com/jump-dev/JuMP.jl) automatic
215+
differentiation (AD) to compute the objective and constraint derivatives. Optimizers
216+
generally benefit from exact derivatives like AD. However, the [`NonLinModel`](@ref)
217+
state-space functions must be compatible with this feature. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
218+
for common mistakes when writing these functions.
219+
220+
Note that if `Cwt≠Inf`, the attribute `nlp_scaling_max_gradient` of `Ipopt` is set to
218221
`10/Cwt` (if not already set), to scale the small values of ``ϵ``.
219222
"""
220223
function NonLinMPC(

0 commit comments

Comments
 (0)