-1

Community,

I have the next problem I want to do a improvement heuristic (Fix and Optimize) and I need to use the initial solution to start, my problem is MIP having binary and continuous variables. I asked him how I would do to use the previous solution as an initial and how I leave some of those variables unfix for your optimization.

Ps: I use --> prob.solve(CPLEX_PY(timeLimit = '3600', epgap = 0.001))

Thanks.

Juan S. P.
  • 31
  • 5

2 Answers2

1

You said you were using PuLP to solve it. You can actually just tell PuLP to use current values of the variables as a warmStart by adding the corresponding argument.

So, for the line you put you would do as follows:

prob.solve(CPLEX_PY(timeLimit = 3600, gapRel = 0.001, warmStart=True))

This assumes that the variables have a value already (because you already solved a model with them or because you set it out yourself.

For more information on warm-starting as well as an example you can go to the docs: https://coin-or.github.io/pulp/guides/how_to_mip_start.html

More information on what you can pass to each solver (including CPLEX_PY): https://coin-or.github.io/pulp/technical/solvers.html

pchtsp
  • 794
  • 1
  • 6
  • 15
0

with docplex python API you can do this :

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*460 + nbbus30*360)

mdl.get_cplex().MIP_starts.read("c:/file.mst")

sol=mdl.solve(log_output=True)

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)

Full example at https://github.com/AlexFleischerParis/zoodocplex/blob/master/zooreadMST.py

Or you can use APIs

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)

in https://github.com/AlexFleischerParis/zoodocplex/blob/master/zoowarmstartapi.py

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thanks for your answer. Now I can´t see the line 1 of 1 MIP starts provided solutions. MIP start 'm1' defined initial solution with objective ...... How can I have this resume in my cplex.log ? – Juan S. P. Mar 02 '20 at 03:37
  • How have you written your warmstart ? With the example I gave you I get "1 of 1 MIP starts provided solutions. MIP start 'm1' defined initial solution with objective 4000.0000." – Alex Fleischer Mar 02 '20 at 08:47
  • Is there a way to obtain the objective value of the warmstart (in this case the 4000.0000) without starting `solve()`? i have seen that you can check for the feasability of a warmstart, but i also would like to have it's objective value. – Finn Jan 26 '21 at 12:13
  • 1
    If you use the objective function you can: https://github.com/AlexFleischerParis/zoodocplex/blob/master/zooobjectivefunction.py – Alex Fleischer Jan 26 '21 at 12:57