问题
I use Python API in Cplex to solve a Linear programing problem. When using Cplex, I had the result below:
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:
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))
回答1:
If I understand correctly, you are solving the second time using the LP file you exported in the first run. You can loose precision when writing to LP format. Try with SAV format instead.
回答2:
Just to add to rkersh's comment. CPLEX when run in deterministic mode should give identical answers every time. 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. 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. But even then I am not certain that the behaviour of CPLEX through the interactive solver will be identical to that through the 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)
来源:https://stackoverflow.com/questions/39479632/cplex-gives-two-different-results