XPRSaddcbbariteration
XPRSaddcbbariteration |
Purpose
Declares a barrier iteration callback function, called after each iteration during the interior point algorithm, with the ability to access the current barrier solution/slack/duals or reduced cost values, and to ask barrier to stop. This callback function will be called in addition to any callbacks already added by XPRSaddcbbariteration.
Synopsis
int XPRS_CC XPRSaddcbbariteration (XPRSprob prob, void (XPRS_CC *f_bariteration)( XPRSprob my_prob, void *my_object, int *barrier_action), void *object, int priority);
Arguments
prob
|
The current problem.
|
||||||||||||
f_bariteration
|
The callback function itself. This takes three arguments,
my_prob,
my_object, and
barrier_action serving as an integer return value. This function is called at every barrier iteration.
|
||||||||||||
my_prob
|
The problem passed to the callback function,
f_bariteration.
|
||||||||||||
my_object
|
The user-defined object passed as
object when setting up the callback with
XPRSaddcbbariteration.
|
||||||||||||
barrier_action
|
Defines a return value controlling barrier:
|
||||||||||||
object
|
A user-defined object to be passed to the callback function,
f_bariteration.
|
||||||||||||
priority
|
An integer that determines the order in which callbacks of this type 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
This simple example demonstrates how the solution might be retrieved for each barrier iteration.
// Barrier iteration callback void XPRS_CC BarrierIterCallback(XPRSprob my_prob, void *my_object, int *barrier_action) { int current_iteration; double PrimalObj, DualObj, Gap, PrimalInf, DualInf, ComplementaryGap; my_object_s *my = (my_object_s *) my_object; XPRSgetintattrib(my_prob, XPRS_BARITER, ¤t_iteration); // try to get all the solution values XPRSgetlpsol(my_prob, my->x, my->slacks, my->y, my->dj); XPRSgetdblattrib(my_prob, XPRS_BARPRIMALOBJ, &PrimalObj); XPRSgetdblattrib(my_prob, XPRS_BARDUALOBJ, &DualObj); Gap = DualObj - PrimalObj; XPRSgetdblattrib(my_prob, XPRS_BARPRIMALINF, &PrimalInf); XPRSgetdblattrib(my_prob, XPRS_BARDUALINF, &DualInf); XPRSgetdblattrib(my_prob, XPRS_BARCGAP, &ComplementaryGap); // decide if stop or continue *barrier_action = BARRIER_CHECKSTOPPING; if (current_iteration >= 50 || Gap <= 0.1*max(fabs(PrimalObj),fabs(DualObj))) { *barrier_action = BARRIER_OPTIMAL; } } // To set callback: XPRSaddcbbariteration(xprob, BarrierIterCallback, (void *) &my, 0);
Further information
1. Only the following functions are expected to be called from the callback:
XPRSgetlpsol and the attribute/control value retrieving and setting routines.
2. General barrier iteration values are available by using
XPRSgetdblattrib to retrieve:
- BARPRIMALOBJ - current primal objective
- BARDUALOBJ - current dual objective
- BARPRIMALINF - current primal infeasibility
- BARDUALINF - current dual infeasibility
- BARCGAP - current complementary gap
3. Please note that these values refer to the scaled and presolved problem used by barrier, and may differ from the ones calculated from the postsolved solution returned by
XPRSgetlpsol.
Related topics