Initializing help system before first use

# Callbacks

Callbacks are a way to interact with the solver during the solve. By using callbacks the solver behavior can be changed to some degree while a solve is running and without the need to interrupt it.

Callbacks are represented by functional interfaces, that is, anything that can be treated as a function with the signature specified by the interface.

Callbacks are handled by member functions of the XpressProblem.callbacks field.

Here is an example that uses lambda expressions to register a callback that prints a message every time a feasible solution is found.

    prob.callbacks.addIntSolCallback((p) -> {
      System.out.printf("New integer solution with objective %f%n",
                         p.attributes().getObjVal());
    });
    prob.optimize();

The same can be achieved by using references to functions with an appropriate signature:

    public class MyClass {
      private static void myIntSolCallback(XpressProblem p) {
        System.out.printf("New integer solution with objective %f%n",
                          p.attributes().getObjVal());
      }
      public static void main(String[] args) {
        try (XpressProblem prob = new XpressProblem()) {
          ...
          prob.callbacks.addIntSolCallback(MyClass::myIntSolCallback);
          prob.optimize();
        }
      }
    }

As suggested by the examples above, callbacks only take action during a solve, so adding a callback without calling any kind of optimization function is pointless. An exception to this is the message callback because warning and error messages may be printed through this callback even before a solve is started.

To get a list of callbacks that can be registered, refer to the reference documentation of class XpressProblem.CallbackAPI.

Parent Topic Solver Java User Guide

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