-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_infeasibility.py
More file actions
35 lines (25 loc) · 919 Bytes
/
debug_infeasibility.py
File metadata and controls
35 lines (25 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gurobipy as gp
import os
def write_iis(path: str, file_name: str):
gurobi_model = gp.read(path + file_name)
gurobi_model.optimize()
# Check if the model is infeasible
print(f"Status: {gurobi_model.Status}")
if gurobi_model.Status == 4:
print("Model is Unbounded!")
if gurobi_model.Status in [gp.GRB.INFEASIBLE, gp.GRB.INF_OR_UNBD]:
print("Model is infeasible. Computing IIS...")
# Compute the IIS
gurobi_model.computeIIS()
# Write the IIS to a file
gurobi_model.write(path + "ISS.ilp")
# Read and print the IIS file
with open(path + "ISS.ilp", "r") as iis_file:
iis = iis_file.read()
print("IIS:\n", iis)
else:
print("Model is not infeasible. No need to compute IIS")
if __name__ == "__main__":
path = os.getcwd() + '\\'
file_name = 'model.lp'
write_iis(path, file_name)