A Fast and Simple Algorithm for Bounds Consistency of the AllDifferent Constraint

Alejandro López-Ortiz, Claude-Guy Quimper, John Tromp, Peter van BeekIJCAI 2003

Introduction

Constraint Programming (CP) is a powerful paradigm for solving complex combinatorial problems by defining variables and the constraints they must satisfy. One of the most ubiquitous constraints is alldifferent(x1, ..., xn), which mandates that every variable in a set must take a unique value. To solve these problems efficiently, solvers use "propagators" to prune the search space by removing values from variable domains that cannot be part of a solution.

There is a classic trade-off in propagator design: Domain Consistency (DC) prunes the most values but is computationally expensive, while Bounds Consistency (BC) only examines the minimum and maximum possible values (the "bounds") of a variable. BC is much faster but prunes fewer values. This paper introduces a new BC algorithm that achieves the optimal theoretical complexity of $O(n \log n)$ while being significantly faster in practice than previous state-of-the-art implementations.

Algorithmic Approach

The core of the new algorithm is the efficient identification of Hall intervals. A Hall interval is a range of $k$ values that must be consumed by exactly $k$ variables; once identified, these $k$ values can be removed from the domains of all other variables.

Figure 1: Step-by-step execution of the algorithm identifying Hall intervals and updating variable bounds through successive variable assignments.

Key technical innovations include:

  • Relevant Counters: Unlike previous algorithms that track all possible values, this algorithm recognizes that only a "critical set" of values needs to be monitored.
  • Efficient Data Structures: The algorithm uses a specialized linked-list structure with path compression (similar to the Union-Find algorithm). This allows the solver to jump over already-processed intervals and update bounds in nearly constant time per operation.
  • Sorting Advantage: By processing variables sorted by their upper bounds, the algorithm maintains a "capacity" for each interval, signaling a Hall interval the moment that capacity hits zero.

While the basic version is $O(n \log n)$ due to initial sorting, the authors also implemented a version using Gabow-Tarjan linear-time union-find to achieve $O(n)$ complexity (plus sorting), though the simpler $O(n \log n)$ version often remains faster in real-world usage due to lower overhead.

Performance and Scaling

The algorithm was evaluated against several benchmarks, including pathological "worst-case" scenarios, Golomb rulers, and real-world instruction scheduling tasks from compiler optimization. The results consistently showed that the new BC algorithm is approximately 2 times faster than the previous best (Mehlhorn and Thiel) and roughly 5 times faster than Puget’s landmark 1998 algorithm.

Figure 2: Scaling comparison showing time to first solution as the number of variables (n) increases. BC maintains near-linear scaling compared to the quadratic growth of DC and RC.

As shown in Figure 2, on problems without significant domain "holes," the BC algorithm scales near-linearly. In contrast, stronger consistency methods like Range Consistency (RC) and Domain Consistency (DC) scale quadratically, becoming computationally unusable as the number of variables grows beyond a few hundred. The new algorithm outperformed state-of-the-art commercial propagators in the ILOG Solver, particularly on instruction scheduling and problems with identifiable interval properties.

Insights and Limitations

A primary insight of this work is that practicality trumps theory. Even when two algorithms share the same big-O complexity, the constant factors and data structure overhead (e.g., simple arrays with path compression vs. complex balanced binary trees) make a massive difference in industrial applications.

The main limitation is inherent to bounds consistency itself: the "hole" problem. If a problem's constraints create many missing values between the min and max of a domain, BC will not prune as much as a DC propagator, potentially leading to a larger search tree. The authors suggest that future solvers could be "self-aware," automatically switching between this fast BC algorithm and more powerful DC algorithms based on the "porosity" (number of holes) of the variable domains during the search.

Conclusion

By combining optimal theoretical complexity with highly efficient data structures, this algorithm provides a new gold standard for industrial solvers. It offers a significant speedup for one of the most common constraints in CP, enabling the solution of larger and more complex combinatorial problems than was previously practical.

Summary updated

BibTeX
@inproceedings{lopezortiz2003fast,
  author = {Alejandro López-Ortiz and Claude-Guy Quimper and John Tromp and Peter van Beek},
  title = {{A Fast and Simple Algorithm for Bounds Consistency of the AllDifferent Constraint}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2003},
}
Figure