Skip to content

Commit ef2c67f

Browse files
committed
changed: better testing function for MHE
1 parent 4dd600f commit ef2c67f

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

src/estimator/mhe/construct.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,24 +653,35 @@ end
653653
Test the custom functions `gc!` at the operating points.
654654
655655
This function is called at the end of `MovingHorizonEstimator` construction. It warns the
656-
user if the custom constraint `gc!` function crashes at `model` operating points. This
657-
should ease troubleshooting of simple bugs e.g.: the user forgets to set the `nc` argument.
656+
user if the custom constraint `gc!` function crashes at `model` operating points. It
657+
will also verify the custom function work with the growing windows. It should ease
658+
troubleshooting of simple bugs e.g.: the user forgets to set the `nc` argument.
658659
"""
659660
function test_custom_function_mhe(NT, model::SimModel, i_ym, He, gc!, nc, x̂op, p)
660-
nŵ, nym = length(x̂op), length(i_ym)
661+
nx̂, nŵ, nym = length(x̂op), length(x̂op), length(i_ym)
662+
nu, nd = model.nu, model.nd
661663
uop, dop, yop = model.uop, model.dop, model.yop
662664
yopm = yop[i_ym]
663-
X̂e, V̂e, Ŵe = repeat(x̂op, He+1), zeros(NT, (He+1)*nym), zeros(NT, (He+1)*nŵ)
664-
Ue, Yem, De = repeat(uop, He+1), repeat(yopm, He+1), repeat(dop, He+1)
665+
X̂e_He, V̂e_He, Ŵe_He = repeat(x̂op, He+1), zeros(NT, (He+1)*nym), zeros(NT, (He+1)*nŵ)
666+
Ue_He, Yem_He, De_He = repeat(uop, He+1), repeat(yopm, He+1), repeat(dop, He+1)
667+
= zeros(NT, nx̂)
668+
= Hermitian(Matrix{NT}(I, 4, 4), :L)
669+
ε = zero(NT)
665670
gc = Vector{NT}(undef, nc)
666671
try
667-
gc!(gc, X̂e, V̂e, Ŵe, Ue, Yem, De, I, x̂op, p, zero(NT))
672+
for i in 2:He+1
673+
X̂e, V̂e, Ŵe = X̂e_He[1:(i*nx̂)], V̂e_He[1:(i*nym)], Ŵe_He[1:(i*nŵ)]
674+
Ue, Yem, De = Ue_He[1:(i*nu)], Yem_He[1:(i*nym)], De_He[1:(i*nd)]
675+
gc!(gc, X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ε)
676+
end
668677
catch err
669678
@warn(
670679
"""
671-
Calling the gc function with Ue, Ŷe, D̂e, ϵ arguments fixed at uop=$uop,
672-
yop=$yop, dop=$dop, ϵ=0 failed with the following stacktrace. Did you
673-
forget to set the keyword argument p or nc?
680+
Calling the gc function with X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, ε arguments
681+
fixed at x̂op=$x̂op, uop=$uop, yop=$yop, dop=$dop,
682+
P̄=I, x̄=0, p=$p, ϵ=0 failed with the following stacktrace.
683+
Did you forget to set the keyword argument p or nc?
684+
Did you handle the growing data windows in your function?
674685
""",
675686
exception=(err, catch_backtrace())
676687
)

0 commit comments

Comments
 (0)