Initializing help system before first use

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(callback, data, priority)

(RelGapNotify, AbsGapNotify, AbsGapNotifyObj, AbsGapNotifyBound) = callback(my_prob, my_object)


Arguments
callback 
The callback function.
object 
A user-defined object that wil be passed into the callback callback.
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.
data 
A user-defined object to be passed to the callback function, callback.
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.

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.