2

I use Python API in Cplex to solve a Linear programing problem. When using Cplex, I had the result below:

The result is solved directly by 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:

enter image description here 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))
Cœur
  • 37,241
  • 25
  • 195
  • 267
Tuan Pham
  • 49
  • 4
  • That's always possible due to randomness in the algorithms. In this case, it seems to work in a **deterministic mode**. You have to check the docs what this means exactly (deterministic + concurrent is kind of a paradoxon; but maybe it's really deterministic). Also check if both approaches are using the same random-seed! – sascha Sep 13 '16 at 22:07
  • I have find this: "Deterministic means that multiple runs with the same model at the same parameter settings on the same platform will reproduce the same solution path and results". But in this my such of case, both are deterministic but give diffirent results. Does Cplex should give the same results? – Tuan Pham Sep 13 '16 at 23:41

2 Answers2

2

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.

rkersh
  • 4,447
  • 2
  • 22
  • 31
0

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)

TimChippingtonDerrick
  • 2,042
  • 1
  • 12
  • 13