Skip to content

Commit 98e485e

Browse files
committed
added: do not call gc! if nc==0
1 parent 0c1cc82 commit 98e485e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/controller/nonlinmpc.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
530530
Ŷ0, x̂0end = predict!(Ȳ, x̂0, x̂0next, u0, û0, mpc, model, ΔŨ)
531531
Ue, Ŷe = extended_predictions!(Ue, Ŷe, Ū, mpc, model, Ŷ0, ΔŨ)
532532
ϵ = (nϵ 0) ? ΔŨ[end] : zero(T) # ϵ = 0 if nϵ == 0 (meaning no relaxation)
533-
mpc.con.gc!(gc, Ue, Ŷe, mpc.D̂e, mpc.p, ϵ)
534-
g = con_nonlinprog!(g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
533+
gc = con_custom!(gc, mpc, Ue, Ŷe, ϵ)
534+
g = con_nonlinprog!(g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
535535
return obj_nonlinprog!(Ȳ, Ū, mpc, model, Ue, Ŷe, ΔŨ)::T
536536
end
537537
function gfunc_i(i, ΔŨtup::NTuple{N, T}) where {N, T<:Real}
@@ -549,8 +549,8 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
549549
Ŷ0, x̂0end = predict!(Ȳ, x̂0, x̂0next, u0, û0, mpc, model, ΔŨ)
550550
Ue, Ŷe = extended_predictions!(Ue, Ŷe, Ū, mpc, model, Ŷ0, ΔŨ)
551551
ϵ = (nϵ 0) ? ΔŨ[end] : zero(T) # ϵ = 0 if nϵ == 0 (meaning no relaxation)
552-
mpc.con.gc!(gc, Ue, Ŷe, mpc.D̂e, mpc.p, ϵ)
553-
g = con_nonlinprog!(g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
552+
gc = con_custom!(gc, mpc, Ue, Ŷe, ϵ)
553+
g = con_nonlinprog!(g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
554554
end
555555
return g[i]::T
556556
end
@@ -659,7 +659,7 @@ function set_nonlincon!(
659659
end
660660

661661
"""
662-
con_nonlinprog!(g, mpc::NonLinMPC, model::LinModel, _ , _ , gc, ϵ)
662+
con_nonlinprog!(g, mpc::NonLinMPC, model::LinModel, _ , _ , gc, ϵ) -> g
663663
664664
Nonlinear constrains for [`NonLinMPC`](@ref) when `model` is a [`LinModel`](@ref).
665665
@@ -705,6 +705,17 @@ function con_nonlinprog!(g, mpc::NonLinMPC, ::SimModel, x̂0end, Ŷ0, gc, ϵ)
705705
return g
706706
end
707707

708+
709+
@doc raw"""
710+
con_custom!(gc, mpc::NonLinMPC, Ue, Ŷe, ϵ) -> gc
711+
712+
Evaluate the custom inequality constraint `gc` in-place and return it.
713+
"""
714+
function con_custom!(gc, mpc::NonLinMPC, Ue, Ŷe, ϵ)
715+
mpc.con.nc 0 && mpc.con.gc!(gc, Ue, Ŷe, mpc.D̂e, mpc.p, ϵ)
716+
return gc
717+
end
718+
708719
"Evaluate the economic term `E*JE` of the objective function for [`NonLinMPC`](@ref)."
709720
function obj_econ(
710721
mpc::NonLinMPC, model::SimModel, Ue, Ŷe::AbstractVector{NT}

0 commit comments

Comments
 (0)