@@ -118,7 +118,7 @@ controller minimizes the following objective function at each discrete time ``k`
118118```
119119subject to [`setconstraint!`](@ref) bounds, and the custom inequality constraints:
120120```math
121- \m athbf{g_c}\B ig (\m athbf{U_e}, \m athbf{Ŷ_e}, \m athbf{D̂_e}, \m athbf{p}, ϵ(k) \B ig ) ≤ \m athbf{0}
121+ \m athbf{g_c}(\m athbf{U_e}, \m athbf{Ŷ_e}, \m athbf{D̂_e}, \m athbf{p}, ϵ) ≤ \m athbf{0}
122122```
123123The economic function ``J_E`` can penalizes solutions with high economic costs. Setting all
124124the weights to 0 except ``E`` creates a pure economic model predictive controller (EMPC).
@@ -198,18 +198,19 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
198198 for the constraint handling, and is not available in any other package, to my knowledge.
199199
200200 The economic cost ``J_E`` and custom constraint ``\m athbf{g_c}`` functions receive the
201- extended vectors ``\m athbf{U_e}`` (`nu*(Hp+1)` elements), ``\m athbf{Ŷ_e}`` (`ny*(Hp+1)`
202- elements) and ``\m athbf{D̂_e}`` (`nd*(Hp+1)` elements) as arguments. If `LHS` represents
203- the left-hand side result in the inequality ``\m athbf{g_c}(\m athbf{U_e}, \m athbf{Ŷ_e},
204- \m athbf{D̂_e}, \m athbf{p}, ϵ) ≤ \m athbf{0}``, `gc` can be implemented in two ways:
201+ extended vectors ``\m athbf{U_e}`` (`nu*Hp+nu` elements), ``\m athbf{Ŷ_e}`` (`ny+ny*Hp`
202+ elements) and ``\m athbf{D̂_e}`` (`nd+nd*Hp` elements) as arguments. If `LHS` represents
203+ the result of the left-hand side in the inequality ``\m athbf{g_c}(\m athbf{U_e},
204+ \m athbf{Ŷ_e}, \m athbf{D̂_e}, \m athbf{p}, ϵ) ≤ \m athbf{0}``, the function `gc` can be
205+ implemented in two possible ways:
205206
206207 1. **Non-mutating function** (out-of-place): define it as `gc(Ue, Ŷe, D̂e, p, ϵ) -> LHS`.
207208 This syntax is simple and intuitive but it allocates more memory.
208209 2. **Mutating function** (in-place): define it as `gc!(LHS, Ue, Ŷe, D̂e, p, ϵ) -> nothing`.
209210 This syntax reduces the allocations and potentially the computational burden as well.
210211
211- The keyword argument `nc` is the number of elements in the `LHS` vector , and `gc!`, an
212- alias for the `gc` argument (both accepts non-mutating and mutating functions).
212+ The keyword argument `nc` is the number of elements in `LHS`, and `gc!`, an alias for
213+ the `gc` argument (both `gc` and `gc!` accepts non-mutating and mutating functions).
213214
214215 The optimization relies on [`JuMP`](https://github.com/jump-dev/JuMP.jl) automatic
215216 differentiation (AD) to compute the objective and constraint derivatives. Optimizers
@@ -391,6 +392,17 @@ function test_custom_functions(JE, gc!, uop; Uop, dop, Dop, ΔŨ, p)
391392 # but there is no similar function for the custom functions of NonLinMPC)
392393 Ue = [Uop; uop]
393394 D̂e = [dop; Dop]
395+
396+ Ŷ0, x̂0end = predict! (Ȳ, x̂0, x̂0next, u0, û0, mpc, model, ΔŨ)
397+ Ŷe, Ue = extended_predictions! (Ŷe, Ue, Ū, mpc, model, Ŷ0, ΔŨ)
398+ ϵ = (nϵ == 1 ) ? ΔŨ[end ] : zero (JNT) # ϵ = 0 if nϵ == 0 (meaning no relaxation)
399+ mpc. con. gc! (gc, Ue, Ŷe, mpc. D̂e, mpc. p, ϵ)
400+ g = con_nonlinprog! (g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
401+ J = obj_nonlinprog! (Ȳ, Ū, mpc, model, Ŷe, Ue, ΔŨ)
402+
403+
404+
405+
394406 Ŷ0, x̂0next =
395407 Ŷ0, x̂0end = predict! (Ŷ0, x̂0, x̂0next, u0, û0, mpc, model, mpc. ΔŨ)
396408 JE = JE (Uop, Uop, Dop, p)
0 commit comments