简体   繁体   English

Cplex 给出了两种不同的结果?

[英]Cplex gives two different results?

I use Python API in Cplex to solve a Linear programing problem.我在 Cplex 中使用 Python API 来解决线性规划问题。 When using Cplex, I had the result below:使用 Cplex 时,我得到了以下结果:

结果直接用Python API解决

But then I saved my LP prolem as a lp file and use Cplex to solve again, the result was a little bit difference from the first one:但是后来我把我的LP问题保存为一个lp文件,再次用Cplex求解,结果和第一个有点不同:

在此处输入图片说明 Anyone gives an explanation?有没有人给解释一下?

Below is my function:下面是我的功能:

def SubProblem(myobj,myrow,mysense,myrhs,mylb):
c = cplex.Cplex()
c.objective.set_sense(c.objective.sense.minimize)
c.variables.add(obj = myobj,lb = mylb)
c.linear_constraints.add(lin_expr = myrow, senses = mysense,rhs = myrhs)
c.solve()
lpfile = "Save_models\clem.lp"
c.write(lpfile)
print("\nFile '%s' was saved"%(lpfile))

If I understand correctly, you are solving the second time using the LP file you exported in the first run.如果我理解正确,您将使用第一次运行时导出的 LP 文件进行第二次求解。 You can loose precision when writing to LP format.写入 LP 格式时可能会降低精度。 Try with SAV format instead.请尝试使用SAV格式。

Just to add to rkersh's comment.只是为了添加到 rkersh 的评论中。 CPLEX when run in deterministic mode should give identical answers every time. CPLEX 在确定性模式下运行时每次都应给出相同的答案。 However, if you write the model out as an LP file you will lose some precision in some of the numbers and this will perturb the problem even if only slightly, and that will often lead to different answers.但是,如果您将模型写成 LP 文件,您将在某些数字上失去一些精度,这会扰乱问题,即使只是轻微的,这通常会导致不同的答案。 The SAV format is the closest you can get to a faithful copy of the model that was inside CPLEX at the time it was saved. SAV 格式是您可以获得的最接近模型在保存时位于 CPLEX 中的忠实副本的格式。 But even then I am not certain that the behaviour of CPLEX through the interactive solver will be identical to that through the API.但即便如此,我也不确定 CPLEX 通过交互式求解器的行为是否与通过 API 的行为相同。 If you run them on the same hardware, I would hope that they would be the same, but on a different machine you might still get different behaviour (different cpu, memory etc)如果你在相同的硬件上运行它们,我希望它们是相同的,但是在不同的机器上你可能仍然会得到不同的行为(不同的 CPU、内存等)

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

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