How to find the Irreducible Inconsistent Subsystem (IIS) from Gurobi, with JuMP and Gurobi.jl

478 views
Skip to first unread message

Lyndon White

unread,
Jan 29, 2016, 4:24:34 AM1/29/16
to julia-opt
Hi,
I felt it was worth sharing this.
I really wanted to work out which constraints in my system couldn't be solved.

I knew Gurobi could tell me this, as C# instructions on how to are available at https://nathanbrixius.wordpress.com/2012/09/28/detecting-the-sources-of-model-infeasibility-using-gurobi/

So based on those, and some digging around in the innards of Gurobi.jl
I worked out how.

and it goes like this:


using JuMP
using Gurobi

function get_irreducible_inconsistent_subsystem(m::JuMP.Model)    
    grb_model
= m.internalModel.inner
    num_constrs
= Gurobi.num_constrs(grb_model)
   
Gurobi.computeIIS(grb_model)
    iis_constrs
= Gurobi.get_intattrarray(grb_model, "IISConstr",  1, num_constrs)
    m
.linconstr[find(iis_constrs)]
end


An example of use:

m
=Model(solver=GurobiSolver())
@defVar(m,x, Int)
@defVar(m,y, Int)
@addConstraint(m,y<=1000) #This one won't cause problems
@addConstraint(m,x>=6)    #This will
@addConstraint(m,y>=6)    #This will
@addConstraint(m,x+y<=11) #This will

status
= solve(m)

@assert status==:Infeasible
get_irreducible_inconsistent_subsystem
(m)

Output:
3-element Array{JuMP.GenericRangeConstraint{JuMP.GenericAffExpr{Float64,JuMP.Variable}},1}:
 x
6,
 y
6,
 x
+ y 11

Note that the first constraint is not listed, as that caused no problems.

I'm not certain this code works all the time.
(I'm not 100% sure this isn't in Gurobi.jl either)

Maybe this will come in handy for someone at some stage.

All code found is this post is released under the MIT License:


Copyright (c) 2016 Lyndon White (AKA oxinabox)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



Miles Lubin

unread,
Jan 29, 2016, 8:53:05 AM1/29/16
to julia-opt
I should also point to our example file here.

MathProgBase.getrawsolver(getInternalModel(m)) is preferred over m.internalModel.inner.

Lyndon White

unread,
Jan 31, 2016, 11:23:57 PM1/31/16
to julia-opt
Ah, cool, thanks.
If I had have found that, it would have saved me a few hours of messing around.
Hopefully this post will make it more easy to find on google.
(I only looked at the Gurobi.jl examples, not the JuMP examples)

Lyndon White

unread,
Jan 31, 2016, 11:24:06 PM1/31/16
to julia-opt
Reply all
Reply to author
Forward
0 new messages