最近,我正在研究MISOCP。最初,我尝试使用python建立模型并通过调用CPLEX来解决它。但是我对CPLEX解决的目标有疑问,我的教授告诉我检查日志文件中答案的容忍度。同时,我的教授给我发送了他的日志文件(由IDE创建)的示例,但是当我打开由python创建的日志文件时,我发现信息存在很大差异。然后我将添加差异的一部分,并真的希望有人可以给我一些建议来解决我的问题,或者告诉我存在差异的原因以及是否可以解决它(差异只是在最后一部分发生了,所以我只是复制最后一部分) 由Professor(IDE)创建的示例文件:
Real time = 18.64 sec. (12682.02 ticks)
Parallel b&c, 24 threads:
Real time = 12251.58 sec. (2317064.29 ticks)
Sync time (average) = 197.11 sec.
Wait time (average) = 0.30 sec.
------------
Total (root+branch&cut) = 12270.22 sec. (2329746.31 ticks)
Solution pool: 50 solutions saved.
MIP - Integer optimal, tolerance (1e-08/1e-06): Objective = 2.3086668423e+01
Current MIP best bound = 2.3086667423e+01 (gap = 9.99915e-07, 0.00%)
Solution time = 12270.22 sec. Iterations = 98522464 Nodes = 8530098 (2567)
Deterministic time = 2329746.32 ticks (189.87 ticks/sec)
和我的示例文件:
Real time = 0.53 sec. (470.96 ticks)
Parallel b&c, 8 threads:
Real time = 3.69 sec. (3396.36 ticks)
Sync time (average) = 0.77 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 4.22 sec. (3867.32 ticks)
Solution status = 101:
MIP_optimal
我们可以看到,与教授的文件相比,我丢失了一些信息
Solution pool: 50 solutions saved.
MIP - Integer optimal, tolerance (1e-08/1e-06): Objective = 2.3086668423e+01
Current MIP best bound = 2.3086667423e+01 (gap = 9.99915e-07, 0.00%)
Solution time = 12270.22 sec. Iterations = 98522464 Nodes = 8530098 (2567)
Deterministic time = 2329746.32 ticks (189.87 ticks/sec)
。我不知道为什么会这样,真的希望有人能帮助我。非常感谢。
答案 0 :(得分:0)
您标识的额外信息不是来自IDE,而是来自CPLEX interactive。使用编程API(例如Python,Java,C ++等)时,输出中不包含这些额外的摘要信息。
但是,您可以使用Python API和以下代码自行打印出此信息:
c = cplex.Cplex()
# <- Your model building logic here.
start = c.get_time()
c.solve()
time = c.get_time() - start
epgap = c.parameters.mip.tolerances.mipgap.get()
epagap = c.parameters.mip.tolerances.absmipgap.get()
print("Solution pool: {0} solutions saved.".format(
c.solution.pool.get_num()))
print("MIP - {0} ({1}/{2}): Objective = {3:19.10e}".format(
c.solution.get_status_string(),
epgap,
epagap,
c.solution.get_objective_value()))
left = c.solution.progress.get_num_nodes_remaining()
if left > 0:
print("Solution time = {:.2} sec. Iterations = {} Nodes = {} ({})".format(
time,
c.solution.progress.get_num_iterations(),
c.solution.progress.get_num_nodes_processed(),
left))
else:
print("Solution time = {:.2} sec. Iterations = {} Nodes = {}".format(
time,
c.solution.progress.get_num_iterations(),
c.solution.progress.get_num_nodes_processed()))
print("Deterministic time = {:.2} ({:.2} ticks/sec)".format(
c.get_dettime(), c.get_dettime()/time))
注意:上面的代码段进行了许多假设,并且并非针对所有问题类型(例如LP)通用。这仅仅是可以做的一个例子。