@@ -587,22 +587,31 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
587587 end
588588 g, ∇g = value_and_jacobian (g!, g, mpc. jacobian, mpc. Z̃, ∇g_cache... )
589589 if ! isnothing (mpc. hessian) && any (old_i_g)
590- @warn (
591- " Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n " *
592- " Its nonzero coefficients are random values for now." , maxlog= 1
593- )
594- function ℓ_g (Z̃, λ, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, geq, g)
595- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
596- return dot (λ, g)
590+ nonlincon = optim[:nonlinconstraint ]
591+ λi = try
592+ JuMP. get_attribute (nonlincon, MOI. LagrangeMultiplier ())
593+ catch err
594+ if err isa MOI. GetAttributeNotAllowed{MOI. LagrangeMultiplier}
595+ @warn (
596+ " Retrieving optimal Hessian of the Lagrangian is not supported.\n " *
597+ " Its nonzero coefficients will be random values." , maxlog= 1
598+ )
599+ rand (sum (old_i_g))
600+ else
601+ rethrow ()
602+ end
597603 end
604+ λ = zeros (NT, ng)
605+ λ[old_i_g] = λi
598606 ∇²g_cache = (
599607 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
600608 Cache (Û0), Cache (K0), Cache (X̂0),
601609 Cache (gc), Cache (geq), Cache (g)
602610 )
603- nonlincon = optim[:nonlinconstraint ]
604- λ = JuMP. dual .(nonlincon) # FIXME : does not work for now
605- λ = rand (NT, ng)
611+ function ℓ_g (Z̃, λ, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, geq, g)
612+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
613+ return dot (λ, g)
614+ end
606615 ∇²ℓg = hessian (ℓ_g, mpc. hessian, mpc. Z̃, Constant (λ), ∇²g_cache... )
607616 else
608617 ∇²ℓg = nothing
@@ -620,10 +629,20 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
620629 end
621630 geq, ∇geq = value_and_jacobian (geq!, geq, mpc. jacobian, mpc. Z̃, geq_cache... )
622631 if ! isnothing (mpc. hessian) && con. neq > 0
623- @warn (
624- " Retrieving optimal Hessian of the Lagrangian is not fully supported yet.\n " *
625- " Its nonzero coefficients are random values for now." , maxlog= 1
626- )
632+ nonlinconeq = optim[:nonlinconstrainteq ]
633+ λeq = try
634+ JuMP. get_attribute (nonlinconeq, MOI. LagrangeMultiplier ())
635+ catch err
636+ if err isa MOI. GetAttributeNotAllowed{MOI. LagrangeMultiplier}
637+ @warn (
638+ " Retrieving optimal Hessian of the Lagrangian is not supported.\n " *
639+ " Its nonzero coefficients will be random values." , maxlog= 1
640+ )
641+ rand (con. neq)
642+ else
643+ rethrow ()
644+ end
645+ end
627646 ∇²geq_cache = (
628647 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
629648 Cache (Û0), Cache (K0), Cache (X̂0),
@@ -633,9 +652,6 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
633652 update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
634653 return dot (λeq, geq)
635654 end
636- nonlinconeq = optim[:nonlinconstrainteq ]
637- λeq = JuMP. dual .(nonlinconeq) # FIXME : does not work for now
638- λeq = ones (NT, neq)
639655 ∇²ℓgeq = hessian (ℓ_geq, mpc. hessian, mpc. Z̃, Constant (λeq), ∇²geq_cache... )
640656 else
641657 ∇²ℓgeq = nothing
0 commit comments