How to report optimality gap

582 views
Skip to first unread message

Suleyman Demirel

unread,
Aug 29, 2010, 1:20:37 PM8/29/10
to AMPL Modeling Language
Hi All,

I have a very quick question, which I was unable to find on the web. I
am solving a MINLP using the solver Bonmin. I specify an "allowable
fraction gap" so that the the algorithm terminates after getting a
reasonable solution, without spending hours to find the optimal
solution.

In an instance, the algorithm shows up the following message at
termination.

"Cbc0011I Exiting as integer gap of 44289.4 less than 0 or 2%".

Cbc is the MIP solver that Bonmin employs.Here, the integer gap of
44289.4 is indeed 1.7% away from the optimal.

What I want to do is to report the integer gap 44289.4, using a
variable in Ampl. Later, I want to export that variable to a text
file.

Do you know, if it is possible to get hold of the integer gap?

Thanks.

Robert Fourer

unread,
Sep 2, 2010, 2:31:20 AM9/2/10
to am...@googlegroups.com, Suleyman Demirel

It would be possible for Bonmin to return the gap using a solver-defined
suffix, so that the gap value would be accessible as, perhaps, "Cost.gap"
(if "Cost" is the objective function). However this feature is not in the
current AMPL-Bonmin interface. So the best you can do is to see if the gap
value is returned as part of the builtin function solve_message; then AMPL's
string functions can be used to extract that value and turn it into a
number. The details are solver-specific, but as an example the following
finds a string like "12345 MIP" in a certain solver's solve_message using
the "sub" function and then makes it into a number (ignoring the alphabetic
part) using the "num0" function:

num0(sub(solve_message, '(.|\n)*^([0-9]+) MIP(.|\n)*', '\2'))

A recent extension lets you use "@" in place of "(.|\n)" in the regular
expression that appears as the second argument of "sub".

Bob Fourer
4...@ampl.com

Reply all
Reply to author
Forward
0 new messages