Skip to content

Commit aaf3f10

Browse files
committed
idem MHE
1 parent ca7aafe commit aaf3f10

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
368368
function gfunc_i(i, ΔŨtup::NTuple{N, T}) where {N, T<:Real}
369369
ΔŨ1 = ΔŨtup[begin]
370370
ΔŨ, g = get_tmp(ΔŨ_cache, ΔŨ1), get_tmp(g_cache, ΔŨ1)
371-
if any(new old for (new, old) in zip(ΔŨtup, ΔŨ)) # new ΔŨtup, update predictions:
371+
if any(new !== old for (new, old) in zip(ΔŨtup, ΔŨ)) # new ΔŨtup, update predictions:
372372
for i in eachindex(ΔŨtup)
373373
ΔŨ[i] = ΔŨtup[i] # ΔŨ .= ΔŨtup seems to produce a type instability
374374
end

src/estimator/mhe/construct.jl

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,6 @@ function get_optim_functions(
10461046
nx̂, nym, nŷ, nu, He = estim.nx̂, estim.nym, model.ny, model.nu, estim.He
10471047
nV̂, nX̂, ng, nZ̃ = He*nym, He*nx̂, length(con.i_g), length(estim.Z̃)
10481048
Nc = nZ̃ + 3
1049-
last_Z̃tup_float, last_Z̃tup_dual = nothing, nothing
10501049
Z̃_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nZ̃), Nc)
10511050
V̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nV̂), Nc)
10521051
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), Nc)
@@ -1056,17 +1055,12 @@ function get_optim_functions(
10561055
ŷ_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nŷ), Nc)
10571056
function Jfunc(Z̃tup::T...)::T where {T <: Real}
10581057
Z̃1 = Z̃tup[begin]
1059-
if T == JNT
1060-
last_Z̃tup_float = Z̃tup
1061-
else
1062-
last_Z̃tup_dual = Z̃tup
1063-
end
1064-
Z̃, V̂ = get_tmp(Z̃_cache, Z̃1), get_tmp(V̂_cache, Z̃1)
1065-
= get_tmp(X̂_cache, Z̃1)
1066-
û, ŷ = get_tmp(û_cache, Z̃1), get_tmp(ŷ_cache, Z̃1)
1058+
Z̃, g = get_tmp(Z̃_cache, Z̃1), get_tmp(g_cache, Z̃1)
10671059
for i in eachindex(Z̃tup)
10681060
Z̃[i] = Z̃tup[i] # Z̃ .= Z̃tup seems to produce a type instability
10691061
end
1062+
V̂, X̂ = get_tmp(V̂_cache, Z̃1), get_tmp(X̂_cache, Z̃1)
1063+
û, ŷ = get_tmp(û_cache, Z̃1), get_tmp(ŷ_cache, Z̃1)
10701064
V̂, X̂ = predict!(V̂, X̂, û, ŷ, estim, model, Z̃)
10711065
g = get_tmp(g_cache, Z̃1)
10721066
g = con_nonlinprog!(g, estim, model, X̂, V̂, Z̃)
@@ -1075,17 +1069,9 @@ function get_optim_functions(
10751069
end
10761070
function gfunc_i(i, Z̃tup::NTuple{N, T})::T where {N, T <:Real}
10771071
Z̃1 = Z̃tup[begin]
1078-
g = get_tmp(g_cache, Z̃1)
1079-
if T == JNT
1080-
isnewvalue = (Z̃tup !== last_Z̃tup_float)
1081-
isnewvalue && (last_Z̃tup_float = Z̃tup)
1082-
else
1083-
isnewvalue = (Z̃tup !== last_Z̃tup_dual)
1084-
isnewvalue && (last_Z̃tup_dual = Z̃tup)
1085-
end
1086-
if isnewvalue
1087-
Z̃, V̂ = get_tmp(Z̃_cache, Z̃1), get_tmp(V̂_cache, Z̃1)
1088-
= get_tmp(X̂_cache, Z̃1)
1072+
Z̃, g = get_tmp(Z̃_cache, Z̃1), get_tmp(g_cache, Z̃1)
1073+
if any(new !== old for (new, old) in zip(Z̃tup, Z̃)) # new Z̃tup, update predictions:
1074+
V̂, X̂ = get_tmp(V̂_cache, Z̃1), get_tmp(X̂_cache, Z̃1)
10891075
û, ŷ = get_tmp(û_cache, Z̃1), get_tmp(ŷ_cache, Z̃1)
10901076
for i in eachindex(Z̃tup)
10911077
Z̃[i] = Z̃tup[i] # Z̃ .= Z̃tup seems to produce a type instability

0 commit comments

Comments
 (0)