MIP 在 Gurobi 启动

MIP start in Gurobi

我正在尝试使用 Gurobi MILP 求解器设置 MIP 启动。我有一组二进制变量:

tupledict_m = master.addVars(list_m, name="m", vtype=GRB.BINARY)

其中 master 是一个 Gurobi 模型,list_m 是一个整数元组。我运行以下设置起始值:

for i in list_m: tupledict_m[i].start = bool(m_values[i])

其中 m_values[i] 为浮点数据类型的 1.0 或 0.0。 在那之后如果我打印 :print([tupledict_m[i].start for i in list_m]) 我到处都得到 1e+101。知道为什么以及如何解决这个问题吗?

From the docs:

[...] Recall that the Gurobi optimizer employs a lazy update approach, so changes to attributes don't take effect until the next call to Model.update, Model.optimize, or Model.write on the associated model.

因此,在为变量设置 mip 开始后,您需要 运行 master.update()

示例:

In [1]: from gurobipy import *

In [2]: m = Model()
Academic license - for non-commercial use only

In [3]: x = m.addVars(3, vtype=GRB.BINARY, name="x")

In [4]: x[2].start = 0

In [5]: print(x[2].start)
1e+101

In [6]: m.update()

In [7]: print(x[2].start)
0.0