Search Combinators

Tom Schrijvers, Guido Tack, Pieter Wuille, Horst Samulowitz, Peter J. Stuckey

TL;DR

This paper introduces Search Combinators, a modular and solver-independent language for defining complex search heuristics in constraint programming. By treating search strategies as "Lego-like" building blocks (combinators), the authors bridge the gap between high-level, expressive modeling and low-level, high-performance implementation, achieving zero performance overhead through static compilation.

What Problem Does This Paper Address?

In Constraint Programming (CP), solving a problem involves two parts: the model (the variables and constraints) and the search heuristic (the strategy for exploring the massive tree of possible solutions).

While modeling languages have become very sophisticated, defining search heuristics remains a "stand-off" between two bad options:

  1. Limited Predefined Heuristics: Users are stuck with a few "off-the-shelf" strategies provided by the solver.
  2. General-Purpose Programming: Users must write complex, low-level code (often in C++) that is tightly coupled to the solver’s internal architecture. This is error-prone, hard to maintain, and requires deep expertise.

The challenge is to create a language that is expressive (can describe complex strategies like restarts or branch-and-bound), modular (can mix and match strategies), and efficient (doesn't slow down the solver).

Methods

The authors propose a Domain-Specific Language (DSL) based on combinators. These are high-level primitives that can be nested and composed.

Key Primitives:

  • Basic: base_search (standard variable/value selection) and prune (cutting a branch).
  • Compositional: and (sequential search), or (disjunctive search), and ifthenelse (conditional logic).
  • Advanced: restart (re-running search with new parameters) and portfolio (trying different strategies in sequence).

The "Secret Sauce": Mixins and Message Protocols

To make these modular, the authors used mixin components. Unlike standard object-oriented inheritance, mixins allow "cross-cutting behavior." For example, a "limit" combinator can wrap a "search" combinator and intercept its messages to stop it once a condition (like a time limit or failure count) is met.

They defined a message protocol (start, enter, exit, init) that every combinator follows. This allows a stack of combinators to communicate as the solver moves up and down the search tree.

The authors implemented this in two ways:

  1. Dynamic Composition: A C++ library using virtual method calls (flexible but has slight overhead).
  2. Static Composition: A Haskell-based compiler that takes the high-level search description and generates a single, optimized C++ loop (zero overhead).

Datasets (Benchmarks)

As this is a systems and languages paper in the field of Constraint Programming, evaluation was performed on classic combinatorial optimization benchmarks:

  • Golomb Rulers: A challenging mathematical problem used to test search efficiency.
  • Radiotherapy Treatment Planning: A real-world medical optimization problem.
  • Job Shop Scheduling: A standard industrial optimization benchmark (specifically the ABZ and mt10 instances).
  • Stress Tests: Artificial trees with millions of nodes designed specifically to measure the per-node overhead of the combinator logic.

Key Insights and Ideas

  • Modularity is not the enemy of performance: By using static compilation, the "abstraction tax" can be completely removed. The solver sees the same code it would have if a human had hand-written a monolithic, non-modular heuristic.
  • Search as a First-Class Citizen: By making search compositional, complex strategies like "Iterative Deepening" or "Dichotomic Search" can be expressed in just a few lines of code rather than hundreds of lines of C++.
  • Solver Independence: The combinator logic is decoupled from how the solver handles memory (e.g., "copying" vs. "trailing"). This makes the DSL portable across different constraint solvers (the authors demonstrated this with Gecode and a prototype for the Gurobi MIP solver).

Key Results

  • Zero Overhead: The statically compiled combinators showed 0% overhead compared to native, hand-coded heuristics in the Gecode solver.
  • Low Dynamic Overhead: Even the interpreted (dynamic) version only added about 70ms per million nodes—a cost usually dwarfed by the time the solver spends on "constraint propagation."
  • Expressive Power: The authors showed that a complex "Restarting Branch-and-Bound" heuristic, which would normally be a monolithic block of code, could be decomposed into 17 simple combinators nested 11 levels deep without losing efficiency.
  • Integration: The system was successfully integrated into the MiniZinc toolchain, a standard in the CP community, allowing users to annotate their models with custom search combinators.

Limitations and Future Work

  • Parallelism: The current work focuses on sequential search. The authors note that extending combinators to handle parallel search on multi-core hardware is a major next step.
  • Optimization: Some specific combinators (like exh_once) currently process nodes that a native solver might discard more aggressively; the authors plan to investigate "short-circuiting" these cases.
  • Broader Domains: While tested on CP, the authors believe the approach could be applied to Mixed Integer Programming (MIP) and A* search, where custom heuristics are equally critical.

Summary updated

BibTeX
@inproceedings{schrijvers2011search,
  author = {Tom Schrijvers and Guido Tack and Pieter Wuille and Horst Samulowitz and Peter J. Stuckey},
  title = {{Search Combinators}},
  booktitle = {CP},
  year = {2011},
  doi = {10.1007/978-3-642-23786-7\_58},
}
Figure