Skip to content

Commit 8e52736

Browse files
committed
removed: specialized obj_nonlinprog! method
1 parent 9984e43 commit 8e52736

2 files changed

Lines changed: 8 additions & 22 deletions

File tree

src/controller/execute.jl

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
155155
U .= U0 .+ mpc.Uop
156156
Ŷ .= Ŷ0 .+ mpc.Yop
157157
D̂ .= mpc.D̂0 + mpc.Dop
158-
J = obj_nonlinprog!(Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ, Z̃)
158+
J = obj_nonlinprog!(Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
159159
Ŷs = similar(mpc.Yop)
160160
predictstoch!(Ŷs, mpc, mpc.estim)
161161
info[:ΔU] = Z̃[1:mpc.Hc*model.nu]
@@ -387,15 +387,18 @@ end
387387
iszero_nc(mpc::PredictiveController) = (mpc.con.nc == 0)
388388

389389
"""
390-
obj_nonlinprog!(Ȳ, Ū, mpc::PredictiveController, model::SimModel, Ue, Ŷe, ΔŨ, Z̃)
390+
obj_nonlinprog!(Ȳ, Ū, mpc::PredictiveController, Ue, Ŷe, ΔŨ)
391391
392392
Nonlinear programming objective method when `model` is not a [`LinModel`](@ref). The
393393
function `dot(x, A, x)` is a performant way of calculating `x'*A*x`. This method mutates
394394
`Ȳ` and `Ū` arguments, without assuming any initial values (it recuperates the values in
395395
`Ŷe` and `Ue` arguments).
396+
397+
Note that a specialized version on [`LinModel`](@ref) that uses the Hessian matrix `mpc.H̃`
398+
is actually slower in the [`MultipleShooting`](@ref) case, so only one method is defined.
396399
"""
397400
function obj_nonlinprog!(
398-
Ȳ, Ū, mpc::PredictiveController, model::SimModel, Ue, Ŷe, ΔŨ, ::AbstractVector{NT}
401+
Ȳ, Ū, mpc::PredictiveController, Ue, Ŷe, ΔŨ::AbstractVector{NT}
399402
) where NT<:Real
400403
nu, ny = model.nu, model.ny
401404
# --- output setpoint tracking term ---
@@ -425,23 +428,6 @@ function obj_nonlinprog!(
425428
return JR̂y + JΔŨ + JR̂u + E_JE
426429
end
427430

428-
"""
429-
obj_nonlinprog!( _ , _ , mpc::PredictiveController, model::LinModel, Ue, Ŷe, ΔŨ, Z̃)
430-
431-
Nonlinear programming objective function when `model` is a [`LinModel`](@ref).
432-
433-
The method is called by the nonlinear optimizer of [`NonLinMPC`](@ref) controllers. It can
434-
also be called on any [`PredictiveController`](@ref)s to evaluate the objective function `J`
435-
at specific `Ue`, `Ŷe` and `Z̃`, values. It does not mutate any argument.
436-
"""
437-
function obj_nonlinprog!(
438-
_, _, mpc::PredictiveController, model::LinModel, Ue, Ŷe, _ , Z̃::AbstractVector{NT}
439-
) where NT <: Real
440-
JQP = obj_quadprog(Z̃, mpc.H̃, mpc.q̃) + mpc.r[]
441-
E_JE = obj_econ(mpc, model, Ue, Ŷe)
442-
return JQP + E_JE
443-
end
444-
445431
"No custom nonlinear constraints `gc` by default, return `gc` unchanged."
446432
con_custom!(gc, ::PredictiveController, _ , _, _ ) = gc
447433

src/controller/nonlinmpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
585585
)
586586
function J!(Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq)
587587
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
588-
return obj_nonlinprog!(Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ, Z̃)
588+
return obj_nonlinprog!(Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
589589
end
590590
if !isnothing(mpc.hessian)
591591
_, ∇J, ∇²J = value_gradient_and_hessian(J!, mpc.hessian, mpc.Z̃, J_cache...)
@@ -800,7 +800,7 @@ function get_nonlinobj_op(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where J
800800
geq::Vector{JNT} = zeros(JNT, neq)
801801
function J!(Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq)
802802
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
803-
return obj_nonlinprog!(Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ, Z̃)
803+
return obj_nonlinprog!(Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
804804
end
805805
Z̃_J = fill(myNaN, nZ̃) # NaN to force update at first call
806806
J_cache = (

0 commit comments

Comments
 (0)