Gurobipy 问题:无法将 IIS 写入 .ilp 文件
Gurobipy issue: fails to write IIS to .ilp file
我们正在使用 Gurobipy
(来自其 Gurobi 云产品)。我们正在利用其 IIS feature 来处理不可行性调试。
但是 Gurobipy
无法将 IIS 写入 .ilp
文件(即生成一个完全空的文件)。
下面是最小的可重现代码:
main.py
import gurobipy
my_model = gurobipy.read("my_problem.lp", conf_env())
# Note: conf_env() is custom func to set secret key
my_model.optimize()
my_model.computeIIS()
my_model.write('my_iis.ilp') # Generates an empty file: my_iis.ilp
my_problem.lp
\ENCODING=ISO-8859-1
\Problem name:
Minimize
obj: x1 + x2
Subject To
c1: - x1 <= -20
c2: - x2 <= -20
c3: - x1 <= -60
c4: - x2 <= -60
c5: x1 + x2 <= 110
Bounds
x1 Free
x2 Free
End
在我的机器上(同时使用 Gurobi 云和本地优化)您的代码运行良好并生成此 ILP 文件:
Minimize
Subject To
c3: - x1 <= -60
c4: - x2 <= -60
c5: x1 + x2 <= 110
Bounds
x1 free
x2 free
End
这是对应的输出:
Using license file C:\gurobi\gurobi.lic
Read LP format model from file inf.lp
Reading time = 0.00 seconds
obj: 5 rows, 2 columns, 6 nonzeros
Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (win64)
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 5 rows, 2 columns and 6 nonzeros
Model fingerprint: 0xd8caa76c
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [1e+00, 1e+00]
Bounds range [0e+00, 0e+00]
RHS range [2e+01, 1e+02]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Solved in 0 iterations and 0.00 seconds
Infeasible or unbounded model
Iteration Objective Primal Inf. Dual Inf. Time
0 handle free variables 0s
IIS computed: 3 constraints and 0 bounds
IIS runtime: 0.00 seconds
你的设置一定有问题,因为代码和模型文件都是正确的。您应该检查解算器输出是否有任何线索。
编辑:
更新 Gurobi 解决了这个问题。
我们正在使用 Gurobipy
(来自其 Gurobi 云产品)。我们正在利用其 IIS feature 来处理不可行性调试。
但是 Gurobipy
无法将 IIS 写入 .ilp
文件(即生成一个完全空的文件)。
下面是最小的可重现代码:
main.py
import gurobipy
my_model = gurobipy.read("my_problem.lp", conf_env())
# Note: conf_env() is custom func to set secret key
my_model.optimize()
my_model.computeIIS()
my_model.write('my_iis.ilp') # Generates an empty file: my_iis.ilp
my_problem.lp
\ENCODING=ISO-8859-1
\Problem name:
Minimize
obj: x1 + x2
Subject To
c1: - x1 <= -20
c2: - x2 <= -20
c3: - x1 <= -60
c4: - x2 <= -60
c5: x1 + x2 <= 110
Bounds
x1 Free
x2 Free
End
在我的机器上(同时使用 Gurobi 云和本地优化)您的代码运行良好并生成此 ILP 文件:
Minimize
Subject To
c3: - x1 <= -60
c4: - x2 <= -60
c5: x1 + x2 <= 110
Bounds
x1 free
x2 free
End
这是对应的输出:
Using license file C:\gurobi\gurobi.lic
Read LP format model from file inf.lp
Reading time = 0.00 seconds
obj: 5 rows, 2 columns, 6 nonzeros
Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (win64)
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 5 rows, 2 columns and 6 nonzeros
Model fingerprint: 0xd8caa76c
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [1e+00, 1e+00]
Bounds range [0e+00, 0e+00]
RHS range [2e+01, 1e+02]
Presolve removed 4 rows and 2 columns
Presolve time: 0.00s
Solved in 0 iterations and 0.00 seconds
Infeasible or unbounded model
Iteration Objective Primal Inf. Dual Inf. Time
0 handle free variables 0s
IIS computed: 3 constraints and 0 bounds
IIS runtime: 0.00 seconds
你的设置一定有问题,因为代码和模型文件都是正确的。您应该检查解算器输出是否有任何线索。
编辑:
更新 Gurobi 解决了这个问题。