简体   繁体   English

如何获得最佳绑定和 mipgap (CPLEX_CMD)?

[英]How get to bestbound and mipgap (CPLEX_CMD)?

I´m working with CPLEX_CMD because i Needed to use MIP_start.我正在使用 CPLEX_CMD,因为我需要使用 MIP_start。 Before I used CPLEX_PY and the command that did these:在我使用 CPLEX_PY 和执行这些操作的命令之前:

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我如何从 CPLEX_CMD 获取此信息?,因为我对
a = prob.solverModel

Thanks, a lot非常感谢

you can do mip start with the docplex python API .你可以用docplex python API做 mip start 。

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:让我使用zoo 示例向您展示如何获得您所要求的内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM