Skip to content

Commit

Permalink
Add IIS example code, ref jump-dev#235
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Aug 6, 2014
1 parent 0395c36 commit a125302
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions examples/iis.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#############################################################################
# JuMP
# An algebraic modelling langauge for Julia
# See http://github.com/JuliaOpt/JuMP.jl
#############################################################################
# iis.jl
#
# Extract an Irreducible Inconsistent Subsystem (IIS)
# from an infeasible model.
# This code is specific to Gurobi.
#############################################################################

using JuMP, Gurobi
import MathProgBase

function print_iis_gurobi(m::Model)

grb = MathProgBase.getrawsolver(getInternalModel(m))
Gurobi.computeIIS(grb)
numconstr = Gurobi.num_constrs(grb)
numvar = Gurobi.num_vars(grb)

iisconstr = Gurobi.get_intattrarray(grb, "IISConstr", 1, numconstr)
iislb = Gurobi.get_intattrarray(grb, "IISLB", 1, numvar)
iisub = Gurobi.get_intattrarray(grb, "IISUB", 1, numvar)

println("Irreducible Inconsistent Subsystem (IIS)")
println("Variable bounds:")
for i in 1:numvar
v = Variable(m, i)
if iislb[i] != 0 && iisub[i] != 0
println(getLower(v), " <= ", getName(v), " <= ", getUpper(v))
elseif iislb[i] != 0
println(getName(v), " >= ", getLower(v))
elseif iisub[i] != 0
println(getName(v), " <= ", getUpper(v))
end
end


println("Constraints:")
for i in 1:numconstr
if iisconstr[i] != 0
println(m.linconstr[i])
end
end
println("End of IIS")
end

# The function below produces the following output:
#=
Irreducible Inconsistent Subsystem (IIS)
Variable bounds:
x <= 1.0
y <= 1.0
Constraints:
x + y >= 3
End of IIS
=#

function iis_example()
m = Model(solver=GurobiSolver())

@defVar(m, 0 <= x <= 1)
@defVar(m, 0 <= y <= 1)

@addConstraint(m, x+y >= 3)

status = solve(m)
@assert status == :Infeasible

print_iis_gurobi(m)
end

0 comments on commit a125302

Please sign in to comment.