Active set and list of (NL) constraints in JuMP

Is there a convenient way to access all of the constraints (including @NLconstraint) in a JuMP (v0.18.4) model? I’ve tried accessing model.linconstr etc, but it doesn’t give the nonlinear constraints. I’d also like to get the list of dual variables for every constraint and have just been using getdual(model[:constraint_name]), but this depends on having the name of the constraints, and I’m wondering if there’s an easier way of doing this. Do I have to convert the NL model to another form? Thanks!

Here is where getdual is defined for non-linear constraints:
https://github.com/JuliaOpt/JuMP.jl/blob/2cab520104c8742a30b99a48075d2d636d6acd64/src/nlp.jl#L55-L64
You could access .nlconstrDuals, but this is pretty fragile so we wouldn’t recommend it.

The proper way to do this would be either to access the constraints from the model dictionary like you’re doing, or to maintain your own datastructure that stores all of the constraint references.

1 Like