Initializing help system before first use

# 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. This functionality is not available for the hybrid gradient method.
Topic areas
Callback, Barrier
Synopsis
`int XPRS_CC XPRSaddcbbariteration (XPRSprob prob, void (XPRS_CC *bariteration)( XPRSprob cbprob, void *cbdata, int *p_action), void *data, int priority);`
Arguments

prob | The current problem.
bariteration | The callback function, which takes arguments cbprob, cbdata, and p_action serving as an integer return value. This function is called at every barrier iteration.
cbprob | The problem passed to the callback function, bariteration.
cbdata | The user-defined data passed as data when setting up the callback.
p_action | Defines a return value controlling barrier:
<0 | continue with the next iteration;
=0 | let barrier decide (use default stopping criteria);
1 | barrier stops with status not defined;
2 | barrier stops with optimal status;
3 | barrier stops with dual infeasible status;
4 | barrier stops wih primal infeasible status.
data | A user-defined data to be passed to the callback function, 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 cbprob,
                      void *cbdata, int *p_action) {
      int currentIteration, nCols, nRows;
      double primalObj, dualObj, gap, primalInf, dualInf,
        complementaryGap;

      my_object_s *my = (my_object_s *) cbdata;

      XPRSgetintattrib(cbprob, XPRS_BARITER, &currentIteration);
      XPRSgetintattrib(cbprob, XPRS_INPUTCOLS, &nCols);
      XPRSgetintattrib(cbprob, XPRS_INPUTROWS, &nRows);

      // try to get all the solution values
      XPRSgetcallbacksolution(cbprob, NULL, my->x, 0, nCols - 1);
      XPRSgetcallbackslacks(cbprob, NULL, my->slacks, 0, nRows - 1);
      XPRSgetcallbackduals(cbprob, NULL, my->y, 0, nRows - 1);
      XPRSgetcallbackredcosts(cbprob, NULL, my->dj, 0, nCols - 1);

      XPRSgetdblattrib(cbprob, XPRS_BARPRIMALOBJ, &primalObj);
      XPRSgetdblattrib(cbprob, XPRS_BARdUALOBJ, &dualObj);
      gap = dualObj - primalObj;
      XPRSgetdblattrib(cbprob, XPRS_BARPRIMALINF, &primalInf);
      XPRSgetdblattrib(cbprob, XPRS_BARDUALINF, &dualInf);
      XPRSgetdblattrib(cbprob, XPRS_BARCGAP, &complementaryGap);

      // decide if stop or continue
      *p_action = BARRIER_CHECKSTOPPING;
      if (currentIteration >= 50
          || gap <= 0.1*max(fabs(primalObj),fabs(dualObj))) {
        *p_action = BARRIER_OPTIMAL;
      }
    }

    // To set callback:
    XPRSaddcbbariteration(xprob, BarrierIterCallback, (void *) &my, 0);

Further information
1. Only the functions for retrieving the solution and the attribute/control value retrieving and setting routines are expected to be called from the callback.
2. General barrier iteration values are available via the following attributes:

- 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 XPRSgetcallbacksolution.
Related topics
XPRSremovecbbariteration.
Parent Topic Console and Library Functions

© 2001-2026 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.