Hi,
let's go on with the example from https://www.linkedin.com/pulse/what-optimization-how-can-help-you-do-more-less-zoo-buses-fleischer/
Warmstart is essential and let's see how we can do that through files with docplex.
In https://www.ibm.com/developerworks/community/forums/html/topic?id=41691ae0-9179-4c5f-86cc-5f389cdfc394
we saw how to do warm start with MST files , let's now use APIs in docplex
from docplex.mp.model import Model
mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)
warmstart=mdl.new_solution()
warmstart.add_var_value(nbbus40,8)
warmstart.add_var_value(nbbus30,0)
mdl.add_mip_start(warmstart)
sol=mdl.solve(log_output=True)
for v in mdl.iter_integer_vars():
print(v," = ",v.solution_value)
gives
1 of 1 MIP starts provided solutions.
MIP start 'm1' defined initial solution with objective 4000.0000.
and then we see
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 12 threads.
Root relaxation solution time = 0.00 sec. (0.00 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
* 0+ 0 4000.0000 0.0000 100.00%
0 0 3750.0000 1 4000.0000 3750.0000 0 6.25%
* 0+ 0 3900.0000 3750.0000 3.85%
* 0 0 integral 0 3800.0000 3800.0000 0 0.00%
Elapsed time = 0.09 sec. (0.02 ticks, tree = 0.01 MB, solutions = 3)
Root node processing (before b&c):
Real time = 0.11 sec. (0.02 ticks)
Parallel b&c, 12 threads:
Real time = 0.00 sec. (0.00 ticks)
Sync time (average) = 0.00 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.11 sec. (0.02 ticks)
nbBus40 = 6.0
nbBus30 = 2.0
regards
PS:
Many similar examples at https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/
#CPLEXOptimizers#DecisionOptimization