0

I´m working with CPLEX_CMD because i Needed to use MIP_start. Before I used CPLEX_PY and the command that did these:

a = prob.solverModel
GAP = a.solution.MIP.get_mip_relative_gap ()
BestBound = a.solution.MIP.get_best_objective ()

How can I get this information from CPLEX_CMD ?, because I have mistake about
a = prob.solverModel

Thanks, a lot

Juan S. P.
  • 31
  • 5

1 Answers1

2

you can do mip start with the docplex python API.

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)

And let me use the zoo example to show you how to get what you asked for:

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(500*nbbus40+400*nbbus30)
sol=mdl.solve(log_output=True)

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

print("objective = ",sol.get_objective_value())
print("best bound = ",mdl.solve_details.best_bound)
print("mip gap = ",mdl.solve_details.mip_relative_gap)

which gives

nbBus40  =  6.0
nbBus30  =  2.0
objective =  3800
best bound =  3800.0
mip gap =  0.0
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Why am I not surprised Alex is answering this? He is my companies internal knowledgebase as "the guy that can answer questions about docplex". – Pete Cacioppi Oct 14 '20 at 23:07