# How to set combined stop condition in AMPL/CPLEX?

I would like to set a stop condition combined of a timelimit and a relative MIP gap. So I would like AMPL/CPLEX to look for the solution of my LP for an hour and if there isn't a solution stop if or as soon as a relative MIP gap of X percent has been reached.

For clarification, could you try to explain to me the exact meaning of a MIP gap? I was looking for a second stop condition to get at least somewhat close to a solution and not randomly stopping after time X has passed. I understand the relative MIP gap as an educated guess on how much the currently found solution is distant from the best possible solution therefore

$$\frac{\text{current objective function result}}{\text{best possible objective function result}}$$

but the actual relative MIP gap seems to be a little bit more complicated

Relative tolerance for optimizing integer variables: stop if

$$\text{abs}((\text{best bound}) - (\text{best integer})) < \text{mipgap} \times (1 + \text{abs}(\text{best bound})).$$

$$\text{Default} = 1\cdot 10^{-4}$$ must be between $$1\cdot 10^{-9}$$ and $$1$$.

I am not sure how exactly best bound and best integer is defined, on the other hand I am not even close to an expert in optimisation stuff.

The relative gap defined by CPLEX is the absolute difference between the objective solution of the best known solution (the incumbent, "best integer" in the formula you quote) and the best known bound ("best bound" in the formula), divided by the absolute value of the best known solution increased by a small amount ($$10^{-10}$$). The best bound will usually be the smallest objective value (in a min problem; largest in a max problem) of the node LP among all live nodes. Adding $$10^{-10}$$ is just to avoid dividing by zero should the best node LP value be zero.