@@ -297,20 +297,22 @@ function init_optimization!(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where
297297 end
298298 end
299299 model = mpc. estim. model
300- ny, nx̂, Hp, ng = model. ny, mpc. estim. nx̂, mpc. Hp, length (con. i_g)
300+ nu, ny, nx̂, Hp, ng = model . nu, model. ny, mpc. estim. nx̂, mpc. Hp, length (con. i_g)
301301 # inspired from https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/tips_and_tricks/#User-defined-operators-with-vector-outputs
302- Jfunc, gfunc = let mpc= mpc, model= model, ng= ng, nΔŨ= nΔŨ , nŶ= Hp* ny, nx̂= nx̂
302+ Jfunc, gfunc = let mpc= mpc, model= model, ng= ng, nΔŨ= nΔŨ , nŶ= Hp* ny, nx̂= nx̂, nu = nu
303303 last_ΔŨtup_float, last_ΔŨtup_dual = nothing , nothing
304- Ŷ_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nŶ), nΔŨ + 3 )
305- g_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, ng), nΔŨ + 3 )
306- x̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nx̂), nΔŨ + 3 )
304+ Ŷ_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nŶ), nΔŨ + 3 )
305+ g_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, ng), nΔŨ + 3 )
306+ x̂_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nx̂), nΔŨ + 3 )
307+ u0_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nu), nΔŨ + 3 )
307308 function Jfunc (ΔŨtup:: JNT... )
308309 Ŷ = get_tmp (Ŷ_cache, ΔŨtup[1 ])
309310 ΔŨ = collect (ΔŨtup)
310311 if ΔŨtup != = last_ΔŨtup_float
311- x̂ = get_tmp (x̂_cache, ΔŨtup[1 ])
312- g = get_tmp (g_cache, ΔŨtup[1 ])
313- Ŷ, x̂end = predict! (Ŷ, x̂, mpc, model, ΔŨ)
312+ x̂ = get_tmp (x̂_cache, ΔŨtup[1 ])
313+ u0 = get_tmp (u0_cache, ΔŨtup[1 ])
314+ g = get_tmp (g_cache, ΔŨtup[1 ])
315+ Ŷ, x̂end = predict! (Ŷ, x̂, u0, mpc, model, ΔŨ)
314316 g = con_nonlinprog! (g, mpc, model, x̂end , Ŷ, ΔŨ)
315317 last_ΔŨtup_float = ΔŨtup
316318 end
@@ -321,8 +323,9 @@ function init_optimization!(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where
321323 ΔŨ = collect (ΔŨtup)
322324 if ΔŨtup != = last_ΔŨtup_dual
323325 x̂ = get_tmp (x̂_cache, ΔŨtup[1 ])
326+ u0 = get_tmp (u0_cache, ΔŨtup[1 ])
324327 g = get_tmp (g_cache, ΔŨtup[1 ])
325- Ŷ, x̂end = predict! (Ŷ, x̂, mpc, model, ΔŨ)
328+ Ŷ, x̂end = predict! (Ŷ, x̂, u0, mpc, model, ΔŨ)
326329 g = con_nonlinprog! (g, mpc, model, x̂end , Ŷ, ΔŨ)
327330 last_ΔŨtup_dual = ΔŨtup
328331 end
@@ -332,9 +335,10 @@ function init_optimization!(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where
332335 g = get_tmp (g_cache, ΔŨtup[1 ])
333336 if ΔŨtup != = last_ΔŨtup_float
334337 x̂ = get_tmp (x̂_cache, ΔŨtup[1 ])
338+ u0 = get_tmp (u0_cache, ΔŨtup[1 ])
335339 Ŷ = get_tmp (Ŷ_cache, ΔŨtup[1 ])
336340 ΔŨ = collect (ΔŨtup)
337- Ŷ, x̂end = predict! (Ŷ, x̂, mpc, model, ΔŨ)
341+ Ŷ, x̂end = predict! (Ŷ, x̂, u0, mpc, model, ΔŨ)
338342 g = con_nonlinprog! (g, mpc, model, x̂end , Ŷ, ΔŨ)
339343 last_ΔŨtup_float = ΔŨtup
340344 end
@@ -344,9 +348,10 @@ function init_optimization!(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where
344348 g = get_tmp (g_cache, ΔŨtup[1 ])
345349 if ΔŨtup != = last_ΔŨtup_dual
346350 x̂ = get_tmp (x̂_cache, ΔŨtup[1 ])
351+ u0 = get_tmp (u0_cache, ΔŨtup[1 ])
347352 Ŷ = get_tmp (Ŷ_cache, ΔŨtup[1 ])
348353 ΔŨ = collect (ΔŨtup)
349- Ŷ, x̂end = predict! (Ŷ, x̂, mpc, model, ΔŨ)
354+ Ŷ, x̂end = predict! (Ŷ, x̂, u0, mpc, model, ΔŨ)
350355 g = con_nonlinprog! (g, mpc, model, x̂end , Ŷ, ΔŨ)
351356 last_ΔŨtup_dual = ΔŨtup
352357 end
0 commit comments