1

I have a MIP model with name "MyModel", i used these commands too( before the solve statement).

 file opts cplex option file/ cplex.opt /;

 MyModel.Optfile =1;
 putclose opts /'epgap=0' /'epagap=0';

after solving it with CPLEX, the status model was 8,(INTEGER SOLUTION : A feasible solution to a problem with discrete variables has been found).

How can I get the difference between upper and lower bounds for this feasible solution? In other words, I want to have the gap.

Thanks

Richard
  • 177
  • 1
  • 9

1 Answers1

1

You can see it in your lst file and in the log. In both cases you should find something like this:

Solution satisfies tolerances.

MIP Solution:           21.000000    (4720 iterations, 100 nodes)
Final Solve:            21.000000    (0 iterations)

Best possible:          23.000000
Absolute gap:            2.000000
Relative gap:            0.086957

In the lst file this should be directly after the "S O L V E S U M M A R Y" and in the log you can see it at the end of the Cplex Output.

Edit: You can also calculate it inside your model like this:

Scalar gap;
gap = abs(MyModel.objEst - MyModel.objVal);
Display gap;
Lutz
  • 2,197
  • 1
  • 10
  • 12
  • Hi @lutz thanks! I saw this page https://support.gams.com/solver:what_is_optca_optcr a few minutes ago. Do you know when we use "optcr_cp" ? What does the optcr_cp formulation means? – Richard Oct 25 '18 at 11:53
  • 2
    I just looked at that page: In that example it is used to show, that GAMS and Cplex use different formulas to calculate the relative gap: optcr_cp is calculated in the way, Cplex does it, while optcr is calculated in the way, GAMS does it. This is also described here: https://www.gams.com/latest/docs/S_CPLEX.html#CPLEX_GAMS_OPTIONS (scroll a little down and look for "ModelName.OptCR") – Lutz Oct 25 '18 at 12:25
  • Yes! Thanks a lot! – Richard Oct 25 '18 at 16:51