CPLEX python API 热启动

CPLEX python API warmstart

我正在尝试在 CPLEX 中实施热启动 python API。

我知道我必须使用以下功能:

set_start(self, col_status, row_status, col_primal, row_primal, col_dual, row_dual)

假设我有五个变量 ["x1"、"x2"、"x3"、"x4"、"x5"],我想为它们赋值热启动的以下值 [0, 1, 0, 0, 1]。

我想做这样的事情:

set_start(col_status=[],
          row_status=[],
          col_primal=["x1", "x2", "x3", "x4", "x5"],
          row_primal=[0, 1, 0, 0, 1],
          col_dual=[],
          row_dual=[])

但在文档中写道:

Each entry of col_primal and row_primal must be a float specifying the starting primal values for the columns and rows, respectively.

我不明白为什么。

我如何在实践中做到这一点?

set_start 的文档中还说:

The arguments col_status, col_primal, and col_dual are lists that either have length equal to the number of variables or are empty. If col_status is empty, then row_status must also be empty. If col_primal is empty, then row_primal must also be empty.

例如,我们可以调用set_status,像这样:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names=["x" + str(i) for i in range(5)])
>>> c.start.set_start(col_status=[],
...                   row_status=[],
...                   col_primal=[0., 1., 0., 0., 1],
...                   row_primal=[],
...                   col_dual=[],
...                   row_dual=[])

结合示例,注意["x1", "x2", "x3", "x4", "x5"]对应的变量索引为[0, 1, 2, 3, 4],模型中共有5个变量。传递给 col_primal 的值也必须与该索引列表相对应(例如,对于索引为 0 的变量,值为 0.0,对于索引为 1 的变量,值为 1.0,等等)。