How to get the value of an NLconstraint in JuMP

The value(.) function accepts a ConstraintRef argument, so you can use it to print the value of a JuMP @constraint after the optimization is done. But if you have a @NLconstraint, whose type is e.g. NonlinearConstraintRef{ScalarShape}, calling value() on it gives an error:

ERROR: MethodError: no method matching value(::NonlinearConstraintRef{ScalarShape})
Closest candidates are:
  value(::Number) at ~/.julia/packages/JuMP/Y4piv/src/variables.jl:1327
  value(::Function, ::ConstraintRef{<:AbstractModel, <:MathOptInterface.ConstraintIndex}) at ~/.julia/packages/JuMP/Y4piv/src/constraints.jl:913                                                
  value(::Function, ::VariableRef) at ~/.julia/packages/JuMP/Y4piv/src/variables.jl:1040

How can you get this value?

At the moment there’s no way to do this, but we’re currently refactoring a lot of the nonlinear interface in JuMP (I’ll talk about this at the upcoming JuMP-dev: JuMP-dev 2022 | JuMP), so we should be able to make this happen in the near future.

I opened an issue to track: Add value for nonlinear constraints · Issue #3019 · jump-dev/JuMP.jl · GitHub

1 Like

Ah, thank you.

Here’s some of the back-story, if you’re interested: