DoCplex: Using subset of variables in warm start

Viewed 100

I am using warm start in DoCplex. In the warm start, my intention is to use a subset of the decision variables from the previous model that resulted in non-empty values. For example, if I have decision binary variables, x_1,...,x_5 and the solution in the first model is x_1=1,x_2=1, and the rest is zero. So, in the warm start, I only want to have decision variables x_1 and x_2. In this way, I can reduce the dimension of the model and have a faster performance. Considering I have thousands of decision variables, how can I choose a subset of these variables in the warm start?

1 Answers

A Docplex solution can be exported to a MIP start file (MST format), with a write_level parameter. This optional parameter is an enumerated value from the docplex.mp.constants/WriteLevel class.

This enum has four values implementing the cartesian product of two flags:

  • keep only discrete variables or keep all
  • keep zero values or all values

In particular: value WriteLevel.DiscreteNonZeroVars saves as MST only discrete variables with non-zero values. The code for this is:

sol = mdl.solve
mst1 = sol.export_as_mst(write_level=WriteLevel.DiscreteNonZeroVars)

Note that passing 4 (the enum numeric value) will also work, although less readable.

If none of these options fit your needs, you can always build a MST solution with custom code, as Tim suggested.

Related