@@ -121,12 +121,11 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
121121 Ȳ, Ū = similar (mpc. Yop), similar (mpc. Uop)
122122 Ŷe, Ue = Vector {NT} (undef, nŶe), Vector {NT} (undef, nUe)
123123 Ŷ0, x̂0end = predict! (Ŷ0, x̂0, x̂0next, u0, û0, mpc, model, mpc. ΔŨ)
124- Ue, Ŷe = extended_predictions! (Ue, Ŷe , Ū, mpc, model, Ŷ0, mpc. ΔŨ)
124+ Ŷe, Ue = extended_predictions! (Ŷe, Ue , Ū, mpc, model, Ŷ0, mpc. ΔŨ)
125125 J = obj_nonlinprog! (Ȳ, Ū, mpc, model, Ue, Ŷe, mpc. ΔŨ)
126- U = Ū
127- U .= @views Ue[1 : end - model. nu]
128- Ŷ = Ȳ
129- Ŷ .= @views Ŷe[model. ny+ 1 : end ]
126+ U, Ŷ = Ū, Ȳ
127+ U .= mul! (U, mpc. S̃, ΔŨ) .+ mpc. T_lastu
128+ Ŷ .= Ŷ0 .+ mpc. Yop
130129 oldF = copy (mpc. F)
131130 F = predictstoch! (mpc, mpc. estim)
132131 Ŷs .= F # predictstoch! init mpc.F with Ŷs value if estim is an InternalModel
@@ -376,24 +375,38 @@ function predict!(Ŷ0, x̂0, x̂0next, u0, û0, mpc::PredictiveController, mod
376375end
377376
378377"""
379- extended_predictions!(Ue, Ŷe , Ū, mpc, model, Ŷ0, ΔŨ) -> Ŷe, Ue
378+ extended_predictions!(Ŷe, Ue , Ū, mpc, model, Ŷ0, ΔŨ) -> Ŷe, Ue
380379
381- Compute the extended vectors `Ue ` and `Ŷe` and for the nonlinear optimization.
380+ Compute the extended vectors `Ŷe ` and `Ue` for the nonlinear optimization.
382381
383- The function mutates `Ue`, `Ŷe` and `Ū` in arguments, without assuming any initial values.
382+ The function mutates `Ŷe`, `Ue` and `Ū` in arguments, without assuming any initial values
383+ for them. Using `nocustomfcts = mpc.weights.iszero_E && mpc.con.nc == 0`, there is two
384+ special cases in which `Ŷe`, `Ue` and `Ū` are not mutated:
385+
386+ - If `mpc.weights.iszero_M_Hp[] && nocustomfcts`, the `Ŷe` vector is not computed to reduce
387+ the burden in the optimization problem.
388+ - If `mpc.weights.iszero_L_Hc[] && nocustomfcts`, the `Ue` vector is not computed for the
389+ same reason as above.
384390"""
385- function extended_predictions! (Ue, Ŷe , Ū, mpc, model, Ŷ0, ΔŨ)
391+ function extended_predictions! (Ŷe, Ue , Ū, mpc, model, Ŷ0, ΔŨ)
386392 ny, nu = model. ny, model. nu
387- # --- extended manipulated inputs Ue = [U; u(k+Hp-1)] ---
388- U = Ū
389- U .= mul! (U, mpc. S̃, ΔŨ) .+ mpc. T_lastu
390- Ue[1 : end - nu] .= U
391- # u(k + Hp) = u(k + Hp - 1) since Δu(k+Hp) = 0 (because Hc ≤ Hp):
392- Ue[end - nu+ 1 : end ] .= @views U[end - nu+ 1 : end ]
393+ nocustomfcts = (mpc. weights. iszero_E && mpc. con. nc== 0 )
393394 # --- extended output predictions Ŷe = [ŷ(k); Ŷ] ---
394- Ŷe[1 : ny] .= mpc. ŷ
395- Ŷe[ny+ 1 : end ] .= Ŷ0 .+ mpc. Yop
396- return Ue, Ŷe
395+ if ! (mpc. weights. iszero_M_Hp[] && nocustomfcts)
396+ Ŷe[1 : ny] .= mpc. ŷ
397+ Ŷe[ny+ 1 : end ] .= Ŷ0 .+ mpc. Yop
398+ end
399+ # --- extended manipulated inputs Ue = [U; u(k+Hp-1)] ---
400+ if ! (mpc. weights. iszero_L_Hp[] && nocustomfcts)
401+ U = Ū
402+ U .= mul! (U, mpc. S̃, ΔŨ) .+ mpc. T_lastu
403+ Ue[1 : end - nu] .= U
404+ # u(k + Hp) = u(k + Hp - 1) since Δu(k+Hp) = 0 (because Hc ≤ Hp):
405+ Ue[end - nu+ 1 : end ] .= @views U[end - nu+ 1 : end ]
406+ else
407+ print (" yo" )
408+ end
409+ return Ŷe, Ue
397410end
398411
399412"""
0 commit comments