Skip to content

Commit 007fd17

Browse files
committed
debug: call set_nonlincon! at the end of MHE construction
1 parent 149cb15 commit 007fd17

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

src/estimator/mhe/construct.jl

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -718,36 +718,6 @@ function init_matconstraint_mhe(::SimModel{NT},
718718
return i_b, i_g, A
719719
end
720720

721-
"By default, no nonlinear constraints in the MHE, thus return nothing."
722-
set_nonlincon!(::MovingHorizonEstimator, ::SimModel, ::JuMP.GenericModel) = nothing
723-
724-
"Set the nonlinear constraints on the output predictions `Ŷ` and terminal states `x̂end`."
725-
function set_nonlincon!(
726-
estim::MovingHorizonEstimator, ::NonLinModel, optim::JuMP.GenericModel{JNT}
727-
) where JNT<:Real
728-
optim, con = estim.optim, estim.con
729-
Z̃var = optim[:Z̃var]
730-
nonlin_constraints = JuMP.all_constraints(optim, JuMP.NonlinearExpr, MOI.LessThan{JNT})
731-
map(con_ref -> JuMP.delete(optim, con_ref), nonlin_constraints)
732-
for i in findall(.!isinf.(con.X̂0min))
733-
gfunc_i = optim[Symbol("g_X̂0min_$(i)")]
734-
@constraint(optim, gfunc_i(Z̃var...) <= 0)
735-
end
736-
for i in findall(.!isinf.(con.X̂0max))
737-
gfunc_i = optim[Symbol("g_X̂0max_$(i)")]
738-
@constraint(optim, gfunc_i(Z̃var...) <= 0)
739-
end
740-
for i in findall(.!isinf.(con.V̂min))
741-
gfunc_i = optim[Symbol("g_V̂min_$(i)")]
742-
JuMP.@constraint(optim, gfunc_i(Z̃var...) <= 0)
743-
end
744-
for i in findall(.!isinf.(con.V̂max))
745-
gfunc_i = optim[Symbol("g_V̂max_$(i)")]
746-
JuMP.@constraint(optim, gfunc_i(Z̃var...) <= 0)
747-
end
748-
return nothing
749-
end
750-
751721
"""
752722
init_defaultcon_mhe(
753723
model::SimModel, He, C, nx̂, nym, E, ex̄, Ex̂, Fx̂, Gx̂, Jx̂, Bx̂
@@ -1289,6 +1259,7 @@ function init_optimization!(
12891259
)
12901260
end
12911261
end
1262+
set_nonlincon!(estim, model, optim)
12921263
return nothing
12931264
end
12941265

@@ -1421,4 +1392,34 @@ function get_optim_functions(
14211392
end
14221393
end
14231394
return Jfunc, ∇Jfunc!, gfuncs, ∇gfuncs!
1395+
end
1396+
1397+
"By default, no nonlinear constraints in the MHE, thus return nothing."
1398+
set_nonlincon!(::MovingHorizonEstimator, ::SimModel, ::JuMP.GenericModel) = nothing
1399+
1400+
"Set the nonlinear constraints on the output predictions `Ŷ` and terminal states `x̂end`."
1401+
function set_nonlincon!(
1402+
estim::MovingHorizonEstimator, ::NonLinModel, optim::JuMP.GenericModel{JNT}
1403+
) where JNT<:Real
1404+
optim, con = estim.optim, estim.con
1405+
Z̃var = optim[:Z̃var]
1406+
nonlin_constraints = JuMP.all_constraints(optim, JuMP.NonlinearExpr, MOI.LessThan{JNT})
1407+
map(con_ref -> JuMP.delete(optim, con_ref), nonlin_constraints)
1408+
for i in findall(.!isinf.(con.X̂0min))
1409+
gfunc_i = optim[Symbol("g_X̂0min_$(i)")]
1410+
@constraint(optim, gfunc_i(Z̃var...) <= 0)
1411+
end
1412+
for i in findall(.!isinf.(con.X̂0max))
1413+
gfunc_i = optim[Symbol("g_X̂0max_$(i)")]
1414+
@constraint(optim, gfunc_i(Z̃var...) <= 0)
1415+
end
1416+
for i in findall(.!isinf.(con.V̂min))
1417+
gfunc_i = optim[Symbol("g_V̂min_$(i)")]
1418+
JuMP.@constraint(optim, gfunc_i(Z̃var...) <= 0)
1419+
end
1420+
for i in findall(.!isinf.(con.V̂max))
1421+
gfunc_i = optim[Symbol("g_V̂max_$(i)")]
1422+
JuMP.@constraint(optim, gfunc_i(Z̃var...) <= 0)
1423+
end
1424+
return nothing
14241425
end

0 commit comments

Comments
 (0)