What Are Callbacks and How Are They Used in Optimization?
Callbacks play a pivotal role in modern optimization but they are rarely used - here's how they work and how they benefit data scientists and operations research professionals
Callbacks play a pivotal role in modern optimization and decision intelligence systems and serve as anchors for seamlessly integrating business logic directly within the complex search algorithms of optimization solvers like FICO Xpress. Callbacks provide a standardized mechanism for interacting with software, extracting intermediate search states from the solver, and injecting user-defined logic and information into the solver. These capabilities foster adaptability across a range of programming environments and optimization software solutions. Callbacks are useful in all kinds of industries, including supply chain, transportation, and energy, where operational complexity and changing business requirements demand speed and precision from optimization tools. Understanding and leveraging callbacks is fundamental for building robust, flexible, and transparent optimization processes that drive critical business decisions.
What Are Callbacks?
Callbacks are specialized functions that are passed to the solver (as arguments of an “add callback” function) and then invoked (or "called back") from the solver to complete a specific action (e.g., check a solution for feasibility regarding some business logic that is not explicitly represented in the model), allowing for customized execution at specific, well-defined points during a process or algorithm. Callbacks exist in all language-specific APIs, be it Python, Java, C, C++, .NET, R, modelling languages such as Mosel and some (not all!) third-party interfaces such as JuMP.
Callbacks form a fundamental mechanism for extending or modifying the behavior of the optimization solver, across all APIs, which is essential for both advanced development and operational excellence in domains like mathematical optimization and prescriptive analytics.
Despite their value, callbacks are often underused. In our experience with FICO Xpress, even among advanced users, only a relatively small group take advantage of them.
Why? Callbacks have a bit of a learning curve, and since their benefits depend on the specific problem at hand, it's not always obvious upfront, even to operations research experts, whether the investment will pay off. Our hope is that this post will demonstrate some of the value callbacks bring and encourage greater usage.
How Do Callbacks Work?
In optimization, callbacks allow users to inject custom logic into core routines such as branch-and-bound, cut generation, or heuristic searches. This approach provides fine-grained control over complex workflows and enables tailored interventions (for example, updating incumbent solutions, logging progress, or dynamically adjusting algorithmic parameters). Callbacks also allow for fundamentally extending the optimization algorithm and changing its behavior. Users can define their own branching operations (including multi-way branching and branching on constraints), add their own cutting planes, and run their own heuristics inside the optimization solver. This custom logic and these customized algorithms are triggered automatically at predefined points during the execution of the search algorithm.
These trigger points include the start or end of a solver phase, each node-processing step in a branch-and-bound algorithm, or events such as finding a new incumbent solution.
The user can request relevant contextual information (such as current variable values, constraint states, or objective bounds) from the callback to make informed decisions in real time and to feed back into the live optimization process. Communication back to the solver can occur in two ways: the user can call specific solver API functions from within the callback. Additionally, some callbacks require communicating information back via the output argument (or, in C, via a pointer). For example, the optimal node callback is called when a branch-and-bound node has been solved to optimality, and it shall return whether the user declares this node infeasible. Callbacks effectively act as hooks that interface between the core solver routines and custom user logic.
Typical Use Cases for Callbacks in Optimization
Typical use cases for callbacks in optimization span a broad spectrum of needs, from enhanced solution monitoring to fine-tuned solver control.
In mixed-integer programming, callbacks are often used to inject custom cuts or heuristics, which can accelerate convergence and improve solution quality when compact model approaches fall short.
Callbacks also facilitate advanced progress tracking by enabling users to log key metrics, such as node counts, incumbent objective values, or time stamps, at each significant stage of the solve process. This capability is particularly valuable in real-time decision intelligence applications, where operational status and solution quality must be visible and actionable throughout lengthy solve cycles.
Let’s look at a couple of concrete use cases! For all technical details of how the various types of callbacks are interweaved with the algorithmic flow of the Xpress MIP and Global Solver, see the image below.
Use Case 1: Logging and Just-in-Time Processing of Intermediate Solutions
Imagine running a real-time optimization application in which the MIP solver works continuously in the background, searching for improving solutions. Rather than waiting for the optimization run to finish, you may want to start working with the best solution found so far (the current incumbent) as soon as it becomes available or do your own logging.
For example, you might visualize the solution to a facility location problem on a map, evaluate it against operational KPIs that are not represented by the solver’s optimality gap, or simply provide your own progress report. Slightly more advanced, you might want to collect the solution to some sort of solution pool or pass it to a custom improvement heuristic that uses domain-specific knowledge. If that heuristic finds a better solution, it can feed the improved solution back into the solver. You might also decide to terminate the optimization early once the incumbent satisfies all relevant business criteria, even if the solver has not yet proved it optimal.
An integer solution callback provides exactly this kind of just-in-time access. The solver invokes the callback whenever it finds a new feasible MIP solution, allowing the application to inspect, process, improve, or act on that solution immediately.
Check out our online example for solution enumeration, which collects the n-best solutions for an optimization problem.
Use Case 2: Strengthening the Model on the Fly
Subtour elimination constraints are perhaps the poster child for solver callbacks.
Consider a vehicle routing problem. For any vehicle tour and any partition of the visited locations into two (nonempty) sets, the vehicle must cross from one set to the other and later return. Constraints that express this requirement are very strong, but they come with a substantial drawback: there are exponentially many potential partitions, and therefore exponentially many corresponding constraints. Adding all of them to the original model would be prohibitive.
Fortunately, only a small fraction of these constraints is usually relevant at any particular point in the search. Instead of generating them in advance, a smart separation algorithm can inspect the LP relaxation solutions produced by the solver, identify the subtour-elimination constraints currently violated, and add only those constraints.
An optimal-node callback is a natural place to implement this separation procedure. The same general pattern applies to many other dynamically generated valid inequalities. Closely related callback mechanisms can also be used for lazy-constraint separation or as a building block for a custom Bender’s decomposition: solve a relaxation, analyze the current solution, and strengthen the model only where necessary. Also see our example for TSP modeled via delayed rows/lazy constraints and our example for a custom Bender’s decomposition.
Use Case 3: Shaping the Search by Reviewing and Refining Solver Decisions
MIP solving ultimately proceeds by exploring a search tree. Therefore, the solver recursively divides the remaining solution space. The choice of variable—or, more generally, branching object—to split the search space on can have a substantial effect on the size and shape of the search tree. It is therefore one of the algorithmic components for which incorporating business logic can be especially valuable.
Consider a network design problem with binary variables indicating whether individual edges are activated. A domain expert may know that decisions on certain critical edges have a particularly large downstream impact: fixing whether one of these edges is open or closed may determine much of the remaining network structure. Given the current partial assignment and the LP relaxation (which indicates which edges are still undecided and how strongly the model currently favors opening them), a user-written code may be able to identify the next strategically important edge more effectively than a generic branching rule.
A branching callback makes it possible to inject this knowledge directly into the search. Whenever the solver is about to branch, the callback can inspect the current search state and serve as a review layer. It can:
- accept the solver’s proposed branching object unchanged;
- replace it with a user-defined branching object; or
- augment the proposed branches with additional implications.
The third option is particularly useful when business logic implies relationships that are difficult or inconvenient to express explicitly as model constraints. For example, fixing one network decision may force several other edges to be opened or closed by some business logic that is not directly expressed via model constraints. Adding these implications directly to the corresponding branches can communicate that knowledge to the solver exactly when it becomes relevant. Our online example for search tree visualization uses newnode and messaging callbacks.
What Are FICO Xpress's Callback Capabilities?
FICO® Xpress offers the most comprehensive suite of callback capabilities in the industry, allowing users to tailor both the behavior and performance of their optimization engines precisely to their needs. By exposing a wide range of callback interfaces (spanning node, cut, incumbent, and heuristic events), FICO Xpress allows practitioners to seamlessly inject custom logic into the heart of mixed-integer linear and nonlinear programming, and other classes of optimization problems.
FICO Xpress also supports integration with external data sources and provides mechanisms for fine-tuned memory and process management within callback routines, ensuring robust, scalable deployments even with large, complex models.
FICO Xpress’s callback framework has been designed to support decision intelligence professionals and operations research teams looking to enhance model transparency, improve audit capability, and achieve optimization outcomes that meet business requirements.
Learn More About FICO Xpress Optimization
- Explore the FICO Xpress Optimization Community
- Download our FICO Xpress Solver solution sheet to learn more about Xpress's high-performance solving capabilities
- Test-drive FICO Xpress with our 60-days free Xpress trial license
- Visit our help center to learn how to define and use callback functions from the Xpress Python interface and check out our examples repository for examples in your favorite programming language and our Python notebook repository
Popular Posts
Has the Reporting of Rental Data to the Credit Reporting Agencies (CRAs) Increased?
FICO Score 10T includes rental data, but consumers can only experience the benefit of this to the extent that their rental data is reported to the CRAs
Read more
Average U.S. FICO® Score at 716, Indicating Improvement in Consumer Credit Behaviors Despite Pandemic
The FICO Score is a broad-based, independent standard measure of credit risk
Read more
FICO Statement on FHFA and FHA Updates to Credit Score Modernization
FICO supports FHFA’s announcement that the long-anticipated historical data for FICO® Score 10T will be released to the mortgage market.
Read moreTake the next step
Connect with FICO for answers to all your product and solution questions. Interested in becoming a business partner? Contact us to learn more. We look forward to hearing from you.