@@ -9,6 +9,7 @@ struct NonLinMPC{
99 GCfunc<: Function
1010} <: PredictiveController{NT}
1111 estim:: SE
12+ transcription:: Symbol
1213 # note: `NT` and the number type `JNT` in `JuMP.GenericModel{JNT}` can be
1314 # different since solvers that support non-Float64 are scarce.
1415 optim:: JM
@@ -47,7 +48,8 @@ struct NonLinMPC{
4748 buffer:: PredictiveControllerBuffer{NT}
4849 function NonLinMPC {NT} (
4950 estim:: SE ,
50- Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE:: JEfunc , gc!:: GCfunc , nc, p:: P , optim:: JM
51+ Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE:: JEfunc , gc!:: GCfunc , nc, p:: P ,
52+ transcription, optim:: JM
5153 ) where {
5254 NT<: Real ,
5355 SE<: StateEstimator ,
@@ -62,7 +64,7 @@ struct NonLinMPC{
6264 weights = ControllerWeights {NT} (model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt)
6365 # dummy vals (updated just before optimization):
6466 R̂y, R̂u, T_lastu = zeros (NT, ny* Hp), zeros (NT, nu* Hp), zeros (NT, nu* Hp)
65- S, T = init_ΔUtoU (model , Hp, Hc)
67+ S, T = init_ZtoU (estim , Hp, Hc, transcription )
6668 E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat (estim, model, Hp, Hc)
6769 # dummy vals (updated just before optimization):
6870 F, fx̂ = zeros (NT, ny* Hp), zeros (NT, nx̂)
@@ -81,7 +83,7 @@ struct NonLinMPC{
8183 ΔŨ = zeros (NT, nΔŨ)
8284 buffer = PredictiveControllerBuffer {NT} (nu, ny, nd, Hp, Hc, nϵ)
8385 mpc = new {NT, SE, JM, P, JEfunc, GCfunc} (
84- estim, optim, con,
86+ estim, transcription, optim, con,
8587 ΔŨ, ŷ,
8688 Hp, Hc, nϵ,
8789 weights,
@@ -122,9 +124,8 @@ subject to [`setconstraint!`](@ref) bounds, and the custom inequality constraint
122124```
123125and the slack ``ϵ`` and the ``\m athbf{Z}`` vector as the decision variables:
124126
125- - ``\m athbf{Z} = \m athbf{ΔŨ}`` if the transcription method is `:singleshooting`
126- - ``\m athbf{Z} = [\b egin{smallmatrix} \m athbf{ΔŨ}' & \m athbf{X̂}' \e nd{smallmatrix}]'`` if the transcription method is `:multipleshoting`
127- - ``\m athbf{Z} = [\b egin{smallmatrix} \m athbf{ΔŨ}' & \m athbf{X̂}' & \m athbf{Ĉ}' \e nd{smallmatrix}]'`` if the transcription method is `:directcollocation`
127+ - ``\m athbf{Z} = \m athbf{ΔU}`` if the transcription method is `:singleshooting`
128+ - ``\m athbf{Z} = [\b egin{smallmatrix} \m athbf{ΔU}' & \m athbf{X̂}' \e nd{smallmatrix}]'`` if the transcription method is `:multipleshoting`
128129
129130The economic function ``J_E`` can penalizes solutions with high economic costs. Setting all
130131the weights to 0 except ``E`` creates a pure economic model predictive controller (EMPC).
@@ -176,7 +177,7 @@ This controller allocates memory at each time step for the optimization.
176177- `nc=0` : number of custom inequality constraints.
177178- `p=model.p` : ``J_E`` and ``\m athbf{g_c}`` functions parameter ``\m athbf{p}`` (any type).
178179- `transcription=:singleshooting` : transcription method for the nonlinear optimization
179- problem, can be `:singleshooting`, `:multipleshoting` or `:directcollocation `.
180+ problem, can be `:singleshooting` or `:multipleshoting `.
180181- `optim=JuMP.Model(Ipopt.Optimizer)` : nonlinear optimizer used in the predictive
181182 controller, provided as a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.Model)
182183 (default to [`Ipopt`](https://github.com/jump-dev/Ipopt.jl) optimizer).
@@ -254,13 +255,15 @@ function NonLinMPC(
254255 gc :: Function = gc!,
255256 nc:: Int = 0 ,
256257 p = model. p,
258+ transcription = :singleshooting ,
257259 optim:: JuMP.GenericModel = JuMP. Model (DEFAULT_NONLINMPC_OPTIMIZER, add_bridges= false ),
258260 kwargs...
259261)
260262 estim = UnscentedKalmanFilter (model; kwargs... )
261263 return NonLinMPC (
262264 estim;
263- Hp, Hc, Mwt, Nwt, Lwt, Cwt, Ewt, JE, gc, nc, p, M_Hp, N_Hc, L_Hp, optim
265+ Hp, Hc, Mwt, Nwt, Lwt, Cwt, Ewt, JE, gc, nc, p, M_Hp, N_Hc, L_Hp,
266+ transcription, optim
264267 )
265268end
266269
@@ -281,13 +284,15 @@ function NonLinMPC(
281284 gc :: Function = gc!,
282285 nc:: Int = 0 ,
283286 p = model. p,
287+ transcription = :singleshooting ,
284288 optim:: JuMP.GenericModel = JuMP. Model (DEFAULT_NONLINMPC_OPTIMIZER, add_bridges= false ),
285289 kwargs...
286290)
287291 estim = SteadyKalmanFilter (model; kwargs... )
288292 return NonLinMPC (
289293 estim;
290- Hp, Hc, Mwt, Nwt, Lwt, Cwt, Ewt, JE, gc, nc, p, M_Hp, N_Hc, L_Hp, optim
294+ Hp, Hc, Mwt, Nwt, Lwt, Cwt, Ewt, JE, gc, nc, p, M_Hp, N_Hc, L_Hp,
295+ transcription, optim
291296 )
292297end
293298
@@ -332,6 +337,7 @@ function NonLinMPC(
332337 gc :: Function = gc!,
333338 nc = 0 ,
334339 p:: P = estim. model. p,
340+ transcription = :singleshooting ,
335341 optim:: JM = JuMP. Model (DEFAULT_NONLINMPC_OPTIMIZER, add_bridges= false ),
336342) where {
337343 NT<: Real ,
@@ -347,7 +353,8 @@ function NonLinMPC(
347353 validate_JE (NT, JE)
348354 gc! = get_mutating_gc (NT, gc)
349355 return NonLinMPC {NT} (
350- estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE, gc!, nc, p, optim
356+ estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE, gc!, nc, p,
357+ transcription, optim
351358 )
352359end
353360
0 commit comments