problem.addcbgapnotify
| problem.addcbgapnotify | 
  Purpose
 
  Declares a gap notification callback, to be called when a MIP solve reaches a predefined target, set using the
 miprelgapnotify,
 mipabsgapnotify,
 mipabsgapnotifyobj, and/or
 mipabsgapnotifybound controls.
 
  Synopsis
 
 problem.addcbgapnotify (f_gapnotify, object, priority)
 (RelGapNotify, AbsGapNotify, AbsGapNotifyObj, AbsGapNotifyBound) = f_gapnotify (my_prob, my_object)
 
 
  Arguments
 
| 
     f_gapnotify 
     | 
     The callback function.
     | 
| 
     object 
     | 
     A user-defined object that wil be passed into the callback
     f_gpanotify.
     | 
| 
     priority 
     | 
     An integer that determines the order in which multiple gap notification callbacks will be invoked. The callback added with the higher priority will be called before a callback with a lower priority. Set to
     0 if not required.
     | 
| 
     my_prob 
     | 
     The current problem.
     | 
| 
     my_object 
     | 
     The user-defined object passed as
     object when setting up the callback with
     addcbgapnotify.
     | 
| 
     RelGapNotify 
     | 
     The value the
     miprelgapnotify control will be set to after this callback. May be modified within the callback in order to set a new notification target.
     | 
| 
     AbsGapNotify 
     | 
     The value the
     mipabsgapnotify control will be set to after this callback. May be modified within the callback in order to set a new notification target.
     | 
| 
     AbsGapNotifyObj 
     | 
     The value the
     mipabsgapnotifyobj control will be set to after this callback. May be modified within the callback in order to set a new notification target.
     | 
| 
     AbsGapNotifyBound 
     | 
     The value the
     mipabsgapnotifybound control will be set to after this callback. May be modified within the callback in order to set a new notification target.
     | 
| 
     object 
     | 
     A user-defined object to be passed to the callback function,
     f_gapnotify.
     | 
| 
     priority 
     | 
     An integer that determines the order in which multiple estimate callbacks will be invoked. The callback added with a higher priority will be called before a callback with a lower priority. Set to 0 if not required.
     | 
  Example
 
 The following example prints a message when the gap reaches 10% and 1%
 
def gapnotify (prob, object):
    obj = prob.attributes.mipobjval
    bound = prob.attributes.bestbound
    relgap = abs ((obj - bound) / obj)
    newRelGapNotifyTarget = -1
    if relgap <= 0.1:
        print ('Gap reached 10%')
        newRelGapNotifyTarget = 0.1
    if relgap <= 0.01:
        print ('Gap reached 1%')
        newRelGapNotifyTarget = -1 # Don't call gapnotify again
    # return a quadruple with new values, or
    # None for those that should not be set
    return (newRelGapNotifyTarget, None, None, None)
prob.controls.miprelgapnotify = 0.1
prob.addcbgapnotify (gapnotify, None, 0)
prob.mipoptimize ('')
  Further information
 
  The target values that caused the callback to be triggered will automatically be reset to prevent the same callback from being fired again.
 
  Related topics
 
 MIPRELGAPNOTIFY,
 MIPABSGAPNOTIFY,
 MIPABSGAPNOTIFYOBJ,
 MIPABSGAPNOTIFYBOUND,
 problem.removecbgapnotify.
 
 
