Skip to content

Commit 9c66abd

Browse files
committed
fixed types for NonLinMPC closures (except Dual variables)
1 parent 0c8642a commit 9c66abd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/controller/nonlinmpc.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)