How to reference JuMP constraint from solver index?

Some solvers will indicate the constraints causing infeasibilities (e.g. Gurobi, Xpress, …) like this:

User MIP start violates constraint R33048 by 0.493000000

Is there a way to retrieve the JuMP constraint ref corresponding to “R33048”?
I know that I can use write_to_file and inspect the JSON, but in this case that file is quite large and I’m looking for a more direct way to debug.


You can build a dictionary using JuMP.optimizer_index to get the optimizer index of all your constraints and then search it for specific constraints.

Thanks, but doesn’t seem very straightforward…

I tried this, but am not having much luck.

I get the following output from the CPLEX log:
Infeasibility row 'c47180': 0 = -1.

So, I did the following to find it (NOTE: since CPLEX is 0-indexed, I increase the index value by 1 from 47180 to 47181):

julia> cons=vcat([all_constraints(model, i...) for i in list_of_constraint_types(model)]...);

julia> con_dict=Dict(con => optimizer_index(con).value for con in cons);

julia> findall(i -> i==47181, con_dict)
1-element Vector{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable, MathOptInterface.EqualTo{Float64}}, ScalarShape}}:
 OS[-19,5,20] = 0.0

I noticed this is a variable fixing constraint in my model (using fix), so I removed it from the model. I reran the problem and get the same CPLEX output
Infeasibility row 'c47180': 0 = -1.

Any thoughts??

There is no good way to do this, because the .value of a variable or constraint may not correspond to its row in the matrix.

You could call set_name on your constraints to pass a meaningful name to the inner CPLEX optimizer?


I see. All of my constraints are named (name(ConstraintRef) returns a valid string name), but these don’t seem to be passed to CPLEX. Is there something I need to do to pass these over?

Use direct_model(CPLEX.Optimizer()). Upcoming releases of JuMP and MOI will push more information to the solver. At present they sometimes aren’t if bridges and caches are used.


Got it. Thanks @odow !