XPRSaddcbgapnotify
XPRSaddcbgapnotify |
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
int XPRS_CC XPRSaddcbgapnotify(XPRSprob prob, void (XPRS_CC *f_gapnotify)(XPRSprob my_prob, void* my_object, double* newRelGapNotifyTarget, double* newAbsGapNotifyTarget, double* newAbsGapNotifyObjTarget, double* newAbsGapNotifyBoundTarget), void* object, int priority);
Arguments
prob
|
The current problem.
|
f_gapnotify
|
The callback function.
|
my_prob
|
The current problem.
|
my_object
|
The user-defined object passed as
object when setting up the callback with
XPRSaddcbgapnotify.
|
newRelGapNotifyTarget
|
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.
|
newAbsGapNotifyTarget
|
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.
|
newAbsGapNotifyObjTarget
|
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.
|
newAbsGapNotifyBoundTarget
|
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%
void XPRS_CC gapnotify(XPRSprob prob, void* object, double* newRelGapNotifyTarget, double* newAbsGapNotifyTarget, double* newAbsGapNotifyObjTarget, double* newAbsGapNotifyBoundTarget) { double obj, bound, relgap; XPRSgetdblattrib(prob, XPRS_MIPOBJVAL, &obj); XPRSgetdblattrib(prob, XPRS_BESTBOUND, &bound); relgap = fabs( (obj-bound)/obj ); if (relgap<=0.10) { printf("Gap reached 10%"); *newRelGapNotifyTarget = 0.1; } if (relgap<=0.01) { printf("Gap reached 1%"); *newRelGapNotifyTarget = -1; /* Don't call gapnotify again */ } } XPRSsetdblcontrol( prob, XPRS_MIPRELGAPNOTIFY, 0.10 ); XPRSaddcbgapnotify( prob, gapnotify, NULL, 0 ); XPRSmipoptimize(prob, "");
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