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 registered as instances of std::function, so anything that can be converted to such an instance. This includes closures (lambdas), function pointers (including pointers to members which may require binding the first argument for non-static members), and classes that implement an appropriate operator().
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([](XpressProblem &p){ std::cout << "New integer solution with objective " << p.attributes.getObjVal() << std::endl; }); prob.optimize();
The same can be achieved by using references to functions with an appropriate signature:
void myIntsolCallback(XpressProblem &p) { std::cout << "New integer solution with objective " << p.attributes.getObjVal() << std::endl; } int main(void) { XpressProblem prob; ... prob.callbacks.addIntSolCallback(myIntsolCallback); prob.optimize(); }
Or with a functor class that implements operator():
struct IntsolCallback { void operator()(XpressProblem &p) const { std::cout << "New integer solution with objective " << p.attributes.getObjVal() << std::endl; } }; int main(void) { XpressProblem prob; ... IntsolCallback cb; prob.callbacks.addIntSolCallback(cb); 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.
© 2001-2025 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.