Reputation: 725
I'm trying to implement a warmstart in CPLEX python API.
I know I have to use the following function:
set_start(self, col_status, row_status, col_primal, row_primal, col_dual, row_dual)
Let's assume that I have five variables ["x1", "x2", "x3", "x4", "x5"] and I want to assigned them the following values [0, 1, 0, 0, 1] for the warmstart.
I would like to do something like:
set_start(col_status=[],
row_status=[],
col_primal=["x1", "x2", "x3", "x4", "x5"],
row_primal=[0, 1, 0, 0, 1],
col_dual=[],
row_dual=[])
but in the documentation it's written that:
Each entry of col_primal and row_primal must be a float specifying the starting primal values for the columns and rows, respectively.
and I don't understand why.
How can I do it in practice?
Upvotes: 1
Views: 509
Reputation: 4465
In the documentation for set_start it also says:
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.
For example, we can call set_status
, like so:
>>> 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=[])
With the example, note that the variable indices that correspond with ["x1", "x2", "x3", "x4", "x5"]
are [0, 1, 2, 3, 4]
, and that there are a total of 5
variables in the model. The values passed to col_primal
must also correspond with that list of indices (e.g., for variable with index 0, the value is 0.0, for variable with index 1, the value is 1.0, etc.).
Upvotes: 3