Error in computing IIS
AnsweredHello,
I am trying to code a program from the following model:
\[\text{max}\, \nu_t\]
\[\text{st.}\]
\[\sum S_{ij}*v_j = b_j\]
\[-\nu_j \leq -LB_j\]
\[\nu_j \leq UB_j\]
\[-\nu_t \leq \nu_{threshold}\]
by solving the Dual associated with it, which results tin the following model:
\[\text{min}\,\sum b_{j}*\lambda_j + \sum-LB_{i}*\mu_i + \sum UB_{i}*\rho_i - \nu_{threshold}*\eta_t\]
\[\text{st}\]
\[\sum S_{i,j}^t * \lambda_{j} + (- \mu_i) + \rho_i \geq c_i \, \forall i \neq t\]
\[\sum S_{t,j}^t * \lambda_{j} + (- \mu_t) + \rho_t +\eta_t \geq c_t \, \forall i = t\]
I tried with an easy example, however I get an error,
GurobiError Traceback (most recent call last) <ipython-input-13-edd83fd226f2> in <module> 51
52 if d.status in (GRB.INFEASIBLE,GRB.INF_OR_UNBD,GRB.UNBOUNDED):
---> 53 d.computeIIS()
54 if d.IISMinimal:
55 print('IIS is minimal\n')
src\gurobipy\model.pxi in gurobipy.gurobipy.Model.computeIIS()
GurobiError: Cannot compute IIS on a feasible model
How can this be possible? Help will be much appreciated
The reproducible example is the following:
import gurobipy as gp
from gurobipy import GRB
import numpy as np
ob = [0,0,0,1,0,0,0]
b = [0,0,0,0,0]
S = np.array([[-1,0,1,0,0,0,0],
[1,-1,0,-1,0,0,0],
[0,1,0,0,1,0,0],
[-1,0,0,0,0,1,0],
[1,0,0,0,0,0,1]])
LB =[0,-10,0,0,-10,-10,-10]
UB =[10,10,10,10,10,10,10]
meta = [i for i in range(len(b))]
react = [i for i in range(len(ob))]
d = gp.Model()
l = d.addVars(meta,lb=-GRB.INFINITY,ub=GRB.INFINITY, name='lambda')
m = d.addVars(react,lb=-GRB.INFINITY,ub=GRB.INFINITY,name='mu')
p = d.addVars(react,lb=-GRB.INFINITY,ub=GRB.INFINITY,name='rho')
e = d.addVar(lb=-GRB.INFINITY,ub=GRB.INFINITY,name='eta')
d.setObjective((sum(b[i]*l[i] for i in meta)
+ sum(-LB[j]*m[j] for j in react)
+ sum(UB[j]*p[j] for j in react)
- 10*e),GRB.MINIMIZE)
d.addConstrs((gp.quicksum(S.transpose()[i,j]*l[j] for j in meta)
+ m[i]
+ p[i]
+ ce[i] == ob[i] for i in react if i !=3)
,name='S_dual')
d.addConstr((gp.quicksum(S.transpose()[3,j]*l[j] for j in meta)
+ m[3]
+ p[3]
+e == ob[3]), name='Sdual_t')
d.optimize()
if d.status == GRB.OPTIMAL:
obj = d.getObjective()
vari = d.getAttr('X',d.getVars())
if d.status in (GRB.INFEASIBLE,GRB.INF_OR_UNBD,GRB.UNBOUNDED):
d.computeIIS()
if d.IISMinimal:
print('IIS is minimal\n')
else:
print('IIS is not minimal\n')
print('\nThe folllowing constraint(s) cannot be satisfied:')
for c in d.getConstrs():
if c.IISConstr:
print('%s'%d.constrName)
###Thank you!
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
What is d.status? If it is GRB.INF_OR_UNBD or GRB.UNBOUNDED, then you won't be able to compute an IIS. You will only get an IIS for a provably infeasible model.
If the status is GRB.INF_OR_UNBD, then you can check whether the model is infeasible by discarding the objective function and calling optimize() again.
Regards,
Tobias
0 -
Hello Tobias,
Thank you for your response,
I discarded the objective function and the optimal objective reported in the log is equal to zero
Gurobi Optimizer version 9.1.0 build v9.1.0rc0 (win64)
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 49 rows, 34 columns and 82 nonzeros
Model fingerprint: 0xb5f532da
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [0e+00, 0e+00]
Bounds range [0e+00, 0e+00]
RHS range [1e+00, 1e+01]
Presolve removed 49 rows and 34 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 0.0000000e+00 0.000000e+00 6.000000e-0 60s
Extra simplex iterations after uncrush: 5
5 0.0000000e+00 0.000000e+00 0.000000e+00 0s
Solved in 5 iterations and 0.01 seconds
Optimal objective 0.000000000e+000 -
Sorry to keep bothering you, on a different model I got a key error = 1805, but I can't find that code in the documentation, could you help me?
Using license file C:\Users\alexa\gurobi.lic
Academic license - for non-commercial use only - expires 2021-09-12
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-5-7e5ab484b266> in <module>
31 # Stoichiometry Constraints
32
---> 33 x.addConstrs((gp.quicksum(S[i,j] * v[j] for j in M) == 0 for i in N), name='St') #Stoichimetry
34
35
src\gurobipy\model.pxi in gurobipy.gurobipy.Model.addConstrs()
<ipython-input-5-7e5ab484b266> in <genexpr>(.0)
31 # Stoichiometry Constraints
32
---> 33 x.addConstrs((gp.quicksum(S[i,j] * v[j] for j in M) == 0 for i in N), name='St') #Stoichimetry
34
35
src\gurobipy\gurobi.pxi in gurobipy.gurobipy.quicksum()
<ipython-input-5-7e5ab484b266> in <genexpr>(.0)
31 # Stoichiometry Constraints
32
---> 33 x.addConstrs((gp.quicksum(S[i,j] * v[j] for j in M) == 0 for i in N), name='St') #Stoichimetry
34
35
KeyError: 18050 -
The KeyError is not from Gurobi. I guess this comes directly from Python and is triggered in the gurobipy module. Could it be that there is some j in M and i in N for which S[i,j] or v[j] does not exist?
0 -
Sorry, such a mistake I typed wrong when defining v in \(addVars\) it had the wrong length. Now I managed to create the lp file that I wanted. Coming back to the first question, after I dropped the objective function and the solution is zero, does it mean that the model is not infeasible but might be unbounded?
Thank you!
0 -
Yes. You really should take a look at the optimization status code in d.status. If it is GRB.INFEASIBLE, then the model is infeasible. If it is GRB.UNBOUNDED, then the model has an unbounded ray (but can still be either feasible or infeasible). It if is GRB.INF_OR_UNBD, then presolve has concluded that there is an unbounded direction without knowing whether the model is infeasible or not. So, if the status is either GRB.UNBOUNDED or GRB.INF_OR_UNBD, you can discard the objective function and try again to find out whether the model is infeasible or not.
0
Post is closed for comments.
Comments
7 comments