Skip to content

Commit af70b67

Browse files
authored
Merge pull request #294 from JuliaControl/nl_con_getinfo
added: optimal nonlinear constraint vectors in `getinfo`
2 parents ea1f2e3 + 7d5952f commit af70b67

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/ModelPredictiveControl.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ using RecipesBase
1010
using DifferentiationInterface: ADTypes.AbstractADType, AutoForwardDiff
1111
using DifferentiationInterface: AutoSparse, SecondOrder
1212
using DifferentiationInterface: gradient, jacobian, hessian
13-
using DifferentiationInterface: value_and_gradient, value_gradient_and_hessian
13+
using DifferentiationInterface: value_and_gradient, value_and_jacobian
14+
using DifferentiationInterface: value_gradient_and_hessian
1415
using DifferentiationInterface: gradient!, value_and_gradient!, prepare_gradient
1516
using DifferentiationInterface: jacobian!, value_and_jacobian!, prepare_jacobian
1617
using DifferentiationInterface: hessian!, value_gradient_and_hessian!, prepare_hessian

src/controller/execute.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ are also available:
112112
- `:gc`: custom nonlinear constraints values at the optimum, ``\mathbf{g_c}``
113113
- `:∇J` or *`:nablaJ`* : optimal gradient of the objective function, ``\mathbf{\nabla} J``
114114
- `:∇²J` or *`:nabla2J`* : optimal Hessian of the objective function, ``\mathbf{\nabla^2}J``
115+
- `:g` : optimal nonlinear inequality constraint values, ``\mathbf{g}``
115116
- `:∇g` or *`:nablag`* : optimal Jacobian of the inequality constraint, ``\mathbf{\nabla g}``
116117
- `:∇²ℓg` or *`:nabla2lg`* : optimal Hessian of the inequality Lagrangian, ``\mathbf{\nabla^2}\ell_{\mathbf{g}}``
118+
- `:geq` : optimal nonlinear equality constraint values, ``\mathbf{g_{eq}}``
117119
- `:∇geq` or *`:nablageq`* : optimal Jacobian of the equality constraint, ``\mathbf{\nabla g_{eq}}``
118120
- `:∇²ℓgeq` or *`:nabla2lgeq`* : optimal Hessian of the equality Lagrangian, ``\mathbf{\nabla^2}\ell_{\mathbf{g_{eq}}}``
119121

src/controller/nonlinmpc.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ end
526526
"""
527527
addinfo!(info, mpc::NonLinMPC) -> info
528528
529-
For [`NonLinMPC`](@ref), add `:sol`, the custom nonlinear objective `:JE`, the custom
530-
constraint `:gc`, and the various derivatives.
529+
For [`NonLinMPC`](@ref), add `:sol`, the custom nonlinear objective `:JE`, the nonlinear
530+
constraint vectors and the various derivatives.
531531
"""
532532
function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
533533
# --- variables specific to NonLinMPC ---
@@ -585,7 +585,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
585585
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
586586
return nothing
587587
end
588-
∇g = jacobian(g!, g, mpc.jacobian, mpc.Z̃, ∇g_cache...)
588+
g, ∇g = value_and_jacobian(g!, g, mpc.jacobian, mpc.Z̃, ∇g_cache...)
589589
if !isnothing(mpc.hessian) && any(old_i_g)
590590
@warn(
591591
"Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n"*
@@ -618,7 +618,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
618618
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
619619
return nothing
620620
end
621-
∇geq = jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
621+
geq, ∇geq = value_and_jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
622622
if !isnothing(mpc.hessian) && con.neq > 0
623623
@warn(
624624
"Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n"*
@@ -642,8 +642,10 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
642642
end
643643
info[:∇J] = ∇J
644644
info[:∇²J] = ∇²J
645+
info[:g] = g
645646
info[:∇g] = ∇g
646647
info[:∇²ℓg] = ∇²ℓg
648+
info[:geq] = geq
647649
info[:∇geq] = ∇geq
648650
info[:∇²ℓgeq] = ∇²ℓgeq
649651
# --- non-Unicode fields ---

src/estimator/mhe/execute.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,11 @@ following fields:
9494
- `:D` : measured disturbances over ``N_k``, ``\mathbf{D}``
9595
- `:sol` : solution summary of the optimizer for printing
9696
97-
For [`NonLinModel`](@ref), it also includes the following derivative fields:
97+
For [`NonLinModel`](@ref), it also includes the following fields:
9898
99-
- `:JE`: economic cost value at the optimum, ``J_E``
100-
- `:gc`: custom nonlinear constraints values at the optimum, ``\mathbf{g_c}``
10199
- `:∇J` or *`:nablaJ`* : optimal gradient of the objective function, ``\mathbf{\nabla} J``
102100
- `:∇²J` or *`:nabla2J`* : optimal Hessian of the objective function, ``\mathbf{\nabla^2}J``
101+
- `:g` : optimal nonlinear inequality constraint values, ``\mathbf{g}``
103102
- `:∇g` or *`:nablag`* : optimal Jacobian of the inequality constraint, ``\mathbf{\nabla g}``
104103
- `:∇²ℓg` or *`:nabla2lg`* : optimal Hessian of the inequality Lagrangian, ``\mathbf{\nabla^2}\ell_{\mathbf{g}}``
105104
@@ -220,7 +219,7 @@ function addinfo!(
220219
update_prediction!(V̂, X̂0, û0, k0, ŷ0, g, estim, Z̃)
221220
return nothing
222221
end
223-
∇g = jacobian(g!, g, estim.jacobian, estim.Z̃, ∇g_cache...)
222+
g, ∇g = value_and_jacobian(g!, g, estim.jacobian, estim.Z̃, ∇g_cache...)
224223
if !isnothing(estim.hessian) && any(old_i_g)
225224
@warn(
226225
"Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n"*
@@ -241,6 +240,7 @@ function addinfo!(
241240
estim.con.i_g .= old_i_g # restore original finite/infinite constraint indices
242241
info[:∇J] = ∇J
243242
info[:∇²J] = ∇²J
243+
info[:g] = g
244244
info[:∇g] = ∇g
245245
info[:∇²ℓg] = ∇²ℓg
246246
# --- non-Unicode fields ---

0 commit comments

Comments
 (0)