Skip to content

Commit 6d4691e

Browse files
authored
Merge pull request #72 from JuliaControl/mhe_notation_dev_var
cleanup MHE append 0 to deviation vector variables
2 parents baf963f + 7add304 commit 6d4691e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/estimator/mhe/construct.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,38 +1115,38 @@ function get_optim_functions(
11151115
nx̂, nym, nŷ, nu, He = estim.nx̂, estim.nym, model.ny, model.nu, estim.He
11161116
nV̂, nX̂, ng, nZ̃ = He*nym, He*nx̂, length(con.i_g), length(estim.Z̃)
11171117
Nc = nZ̃ + 3
1118-
Z̃_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nZ̃), Nc)
1119-
V̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nV̂), Nc)
1120-
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), Nc)
1121-
X̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nX̂), Nc)
1122-
x̄_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nx̂), Nc)
1123-
û_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nu), Nc)
1124-
ŷ_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nŷ), Nc)
1118+
Z̃_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nZ̃), Nc)
1119+
V̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nV̂), Nc)
1120+
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), Nc)
1121+
X̂0_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nX̂), Nc)
1122+
x̄_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nx̂), Nc)
1123+
û0_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nu), Nc)
1124+
ŷ0_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nŷ), Nc)
11251125
function Jfunc(Z̃tup::T...)::T where {T <: Real}
11261126
Z̃1 = Z̃tup[begin]
11271127
Z̃, g = get_tmp(Z̃_cache, Z̃1), get_tmp(g_cache, Z̃1)
11281128
for i in eachindex(Z̃tup)
11291129
Z̃[i] = Z̃tup[i] # Z̃ .= Z̃tup seems to produce a type instability
11301130
end
1131-
V̂, = get_tmp(V̂_cache, Z̃1), get_tmp(X̂_cache, Z̃1)
1132-
û, ŷ = get_tmp(û_cache, Z̃1), get_tmp(ŷ_cache, Z̃1)
1133-
V̂, = predict!(V̂, X̂, û, ŷ, estim, model, Z̃)
1131+
V̂, X̂0 = get_tmp(V̂_cache, Z̃1), get_tmp(X̂0_cache, Z̃1)
1132+
û0, ŷ0 = get_tmp(û0_cache, Z̃1), get_tmp(ŷ0_cache, Z̃1)
1133+
V̂, X̂0 = predict!(V̂, X̂0, û0, ŷ0, estim, model, Z̃)
11341134
g = get_tmp(g_cache, Z̃1)
1135-
g = con_nonlinprog!(g, estim, model, , V̂, Z̃)
1135+
g = con_nonlinprog!(g, estim, model, X̂0, V̂, Z̃)
11361136
= get_tmp(x̄_cache, Z̃1)
11371137
return obj_nonlinprog!(x̄, estim, model, V̂, Z̃)::T
11381138
end
11391139
function gfunc_i(i, Z̃tup::NTuple{N, T})::T where {N, T <:Real}
11401140
Z̃1 = Z̃tup[begin]
11411141
Z̃, g = get_tmp(Z̃_cache, Z̃1), get_tmp(g_cache, Z̃1)
11421142
if any(new !== old for (new, old) in zip(Z̃tup, Z̃)) # new Z̃tup, update predictions:
1143-
V̂, = get_tmp(V̂_cache, Z̃1), get_tmp(X̂_cache, Z̃1)
1144-
û, ŷ = get_tmp(û_cache, Z̃1), get_tmp(ŷ_cache, Z̃1)
1143+
V̂, X̂0 = get_tmp(V̂_cache, Z̃1), get_tmp(X̂0_cache, Z̃1)
1144+
û0, ŷ0 = get_tmp(û0_cache, Z̃1), get_tmp(ŷ0_cache, Z̃1)
11451145
for i in eachindex(Z̃tup)
11461146
Z̃[i] = Z̃tup[i] # Z̃ .= Z̃tup seems to produce a type instability
11471147
end
1148-
V̂, = predict!(V̂, X̂, û, ŷ, estim, model, Z̃)
1149-
g = con_nonlinprog!(g, estim, model, , V̂, Z̃)
1148+
V̂, X̂0 = predict!(V̂, X̂0, û0, ŷ0, estim, model, Z̃)
1149+
g = con_nonlinprog!(g, estim, model, X̂0, V̂, Z̃)
11501150
end
11511151
return g[i]
11521152
end

0 commit comments

Comments
 (0)