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