I want to calculate relative optimality Gap of a MIP Problem also i want to abort runs at a certain run time. this method:
F(1)
abs(mymodel.objest - mymodel.objval)/max(abs(mymodel.objest),abs(mymodel.objval))
is not consistent with gap which GAMS calculate in log. GAMS uses "Best Integer" to find gap not current objective value. which one is correct? and How can i save current "Best Integer" into a parameter ( like .objval).
and finally calculating relative optimality Gap in a benders algorithm is right this way?
rgap = (upperBound - lowerBound)/(1 + abs(upperBound));
What GAMS Calculate using "MIP Solution"
MIP Solution: 3334501534.000555 (1625 iterations, 0 nodes)
Final Solve: 56330158.829040 (2561 iterations)
Best possible: 48915652.476336
Absolute gap: 3285585881.524219
Relative gap: 0.985330
F(1) calculated gap using mymodel.objval (mymodel.objval return "Final Solve") so calculated gap is %13 and mymodel.objval value is 5.633016E+7 (GAMS calculated gap is %98). so i need to save "MIP Solution" to a parameter to export it to a excel file.
There are different formulas to calculate the relative optimality gap. It depends on the solver you use, which one is applied. Some info about this can be found in the description of the GAMS option optCR . The solver manual of the solver you use could have more details about the formula actually applied.
EDIT after question was updated:
As you wrote mymodel.objval
returns the Final Solve
value. If you want to see the MIP Solution
value instead (as the Cplex link does it internally), you could deactivate the final solve. However, if Final Solve
and MIP Solution
are so much different as in your example this is often an indication for some problem (usually, they are (nearly) identical). Often, this indicates a poorly scaled model. Maybe you could improve the situation by tightening the Cplex tolerances (see Cplex options epopt
, eprhs
, epint
) and activating aggressive scaling (Cplex option scaind 2
). Activating mipkappastats
(https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXmipkappastats) and quality
(https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXquality) could give you more information. DataCheck=2
(https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXdatacheck) might show some problems.