Soft Constraints of Difference and Equality
In many combinatorial problems one may need to model the diversity or similarity of assignments in a solution. For example, one may wish to maximise or minimise the number of distinct values in a solution. To formulate problems of this type, we can use soft variants of the well known AllDifferent and AllEqual constraints. We present a taxonomy of six soft global constraints, generated by combining the two latter ones and the two standard cost functions, which are either maximised or minimised. We characterise the complexity of achieving arc and bounds consistency on these constraints, resolving those cases for which NP-hardness was neither proven nor disproven. In particular, we explore in depth the constraint ensuring that at least k pairs of variables have a common value. We show that achieving arc consistency is NP-hard, however achieving bounds consistency can be done in polynomial time through dynamic programming. Moreover, we show that the maximum number of pairs of equal variables can be approximated by a factor 1/2 with a linear time greedy algorithm. Finally, we provide a fixed parameter tractable algorithm with respect to the number of values appearing in more than two distinct domains. Interestingly, this taxonomy shows that enforcing equality is harder than enforcing difference.
💡 Research Summary
The paper tackles a common modeling need in combinatorial optimization: quantifying how diverse or similar the values assigned to a set of variables should be. Classical global constraints AllDifferent (enforcing pairwise distinctness) and AllEqual (enforcing pairwise equality) capture the extreme cases, but many real‑world problems require a “soft” version where the number of distinct values or the number of equal pairs is bounded or optimized.
To this end the authors construct a taxonomy of six soft global constraints obtained by crossing two dimensions – the underlying hard constraint (difference vs. equality) – with two cost objectives (minimisation vs. maximisation) and two consistency notions (arc consistency, AC, and bounds consistency, BC). The six constraints can be described as “at most k distinct values”, “at least k distinct values”, “at most k equal pairs”, and “at least k equal pairs”, each considered under both minimisation and maximisation of the corresponding cost.
The main technical contribution is a complete complexity map for achieving AC and BC on each of these constraints, filling several gaps that were previously unresolved. The most striking result concerns the soft equality constraint that requires at least k pairs of variables to share a value (SoftAllEqual ≥ k). The authors prove that enforcing AC for this constraint is NP‑hard by a reduction from a classic NP‑complete problem (e.g., Clique or 3‑SAT). Consequently, exact AC propagation cannot be expected to run in polynomial time for general instances.
In contrast, the same constraint admits a polynomial‑time BC algorithm. The authors design a dynamic‑programming (DP) scheme that processes variables sequentially, maintaining for each prefix the feasible range of the number of equal pairs that can be achieved. The DP table has size O(n·|D|), where n is the number of variables and |D| the total domain size, and yields the tightest possible bounds on each variable’s domain that satisfy the “≥ k equal pairs” requirement. This shows that, while full arc consistency is intractable, a weaker but still useful consistency level can be enforced efficiently.
For the maximisation version (maximising the number of equal pairs) the paper presents a linear‑time greedy algorithm that achieves a 1/2‑approximation ratio. The algorithm repeatedly selects an unassigned variable and pairs it with the value that currently yields the largest increase in the number of equal pairs, updating counts accordingly. A simple combinatorial argument based on matching theory guarantees that the greedy solution is at least half of the optimal. This result is valuable because it provides a fast, provably good heuristic for large‑scale instances where exact optimisation is prohibitive.
The authors also explore fixed‑parameter tractability. They identify the number k of values that appear in more than two distinct domains as a natural parameter. By isolating the “high‑frequency” values into a core set of size k and enumerating all possible assignments for this core (2^k possibilities), they obtain an FPT algorithm with runtime O(2^k·poly(n,|D|)). When the overlap of values across domains is limited—a situation common in scheduling or resource allocation problems—this algorithm solves the soft equality constraint exactly in practical time.
A broader insight emerging from the taxonomy is that enforcing equality is computationally harder than enforcing difference. AllSix soft‑AllDifferent constraints admit polynomial‑time AC (or are already known to do so), whereas several soft‑AllEqual variants are NP‑hard for AC. This asymmetry stems from the fact that equality constraints must simultaneously control the number of coincident pairs and the distribution of values, leading to a richer combinatorial structure.
The paper concludes with a discussion of practical implications. The BC algorithm can be plugged into existing constraint‑programming solvers to improve pruning without incurring exponential cost. The 1/2‑approximation greedy method offers a lightweight heuristic for large‑scale applications such as timetabling, exam scheduling, or product line configuration where similarity among assignments is desirable. The FPT result suggests that, in domains with limited value overlap, exact solutions are feasible. Finally, the authors point to future work: designing approximation schemes for the hard AC cases, extending the taxonomy to other global constraints (e.g., cardinality or symmetry), and investigating parameterised algorithms based on alternative parameters such as treewidth of the variable‑value incidence graph.