@@ -204,16 +204,20 @@ function init_optimization!(mpc::NonLinMPC)
204204 b = con. b[con. i_b]
205205 @constraint (optim, linconstraint, A* ΔŨvar .≤ b)
206206 # --- nonlinear optimization init ---
207+ model = mpc. estim. model
207208 ncon = length (mpc. con. Ŷmin) + length (mpc. con. Ŷmax)
208- Jfunc, Cfunc = let mpc= mpc, model= mpc. estim. model, nvar= nvar, ncon= ncon
209- last_ΔŨtup, C, Ŷ = nothing , nothing , nothing
209+ npred = mpc. Hp* mpc. estim. model. ny
210+ Jfunc, Cfunc = let mpc= mpc, model= model, nvar= nvar, ncon= ncon, npred= npred
211+ last_ΔŨ:: Vector{Float64} = zeros (nvar)
212+ Ŷ:: Vector{Float64} = zeros (npred)
213+ C:: Vector{Float64} = zeros (ncon)
210214 last_dΔŨtup, dC, dŶ = nothing , nothing , nothing
211215 function Jfunc (ΔŨtup:: Float64... )
212216 ΔŨ = collect (ΔŨtup)
213- if ΔŨtup != = last_ΔŨtup
217+ if ΔŨ ≠ last_ΔŨ
214218 Ŷ = predict (mpc, model, ΔŨ)
215219 C = con_nonlinprog (mpc, model, Ŷ, ΔŨ)
216- last_ΔŨtup = ΔŨtup
220+ last_ΔŨ = ΔŨ
217221 end
218222 return obj_nonlinprog (mpc, model, Ŷ, ΔŨ)
219223 end
@@ -227,11 +231,11 @@ function init_optimization!(mpc::NonLinMPC)
227231 return obj_nonlinprog (mpc, model, dŶ, dΔŨ)
228232 end
229233 function con_nonlinprog_i (i, ΔŨtup:: NTuple{N, Float64} ) where {N}
230- if ΔŨtup != = last_ΔŨtup
231- ΔŨ = collect (ΔŨtup)
234+ ΔŨ = collect (ΔŨtup)
235+ if ΔŨ ≠ last_ΔŨ
232236 Ŷ = predict (mpc, model, ΔŨ)
233237 C = con_nonlinprog (mpc, model, Ŷ, ΔŨ)
234- last_ΔŨtup = ΔŨtup
238+ last_ΔŨ = ΔŨ
235239 end
236240 return C[i]
237241 end
0 commit comments