---
title: FOCUS Algorithm in Constraint Programming
url: https://www.emergentmind.com/topics/focus-algorithm
type: topic
---

# FOCUS Algorithm in Constraint Programming

The FOCUS algorithm in constraint programming is a global constraint that enforces concentration of high (or penalized) values within short contiguous segments of a variable sequence. Since its introduction, FOCUS and its generalizations have been instrumental in modeling problems where concentration or clustering of certain events is desirable, while also managing computational tractability via efficient filtering algorithms. The formalism supports a wide array of combinatorial applications, especially within scheduling and sequencing, by precisely controlling "clustering" behaviors through tunable parameters.

## 1. Formal Definition of the FOCUS Constraint

The original FOCUS constraint operates over a sequence of $n$ integer variables $X = [x_0, \ldots, x_{n-1}]$ and introduces three parameters: a threshold $k$, maximum interval length $\mathit{len}$, and an interval bound variable $y_c$. Specifically, FOCUS$(X, y_c, \mathit{len}, k)$ is satisfied if there exists a collection $S_X$ of disjoint intervals $[i,j]$ such that:

1. $|S_X| \leq y_c$.
2. For each $\ell < n$: $x_\ell > k \iff \exists s \in S_X: \ell \in s$.
3. For all $s_{i,j} \in S_X$: $j - i + 1 \leq \mathit{len}$.

All occurrences of $x_{\ell} > k$ must thus be "concentrated" within at most $y_c$ intervals, each of maximum allowed length $\mathit{len}$ [1304.5970].

## 2. Generalizations of the FOCUS Constraint

Recognizing the restrictive nature of the original definition, three significant generalizations have been developed:

- **Springy FOCUS**: Allows up to $h$ values not exceeding $k$ within each covering interval but still requires endpoints $x_i, x_j > k$. The constraint can be written as $\text{SpringyFocus}(X, y_c, \mathit{len}, h, k)$. For $h=0$, it recovers the original FOCUS constraint.
- **Weighted FOCUS**: Introduces a total covered length variable $z_c$, bounding the aggregate length of the intervals: $ \sum_{s\in S_X} |s| \leq z_c $, in addition to the original interval count constraint.
- **Weighted + Springy FOCUS**: Integrates both extensions: bounded total covered length and allowance for up to $h$ low values within each covering interval.

These relaxations permit modeling problems where strict interval purity or length limitations are overly severe, increasing modeling flexibility while preserving efficient propagation [1304.5970].

## 3. Filtering Algorithms and Complexity

Each variant admits a dedicated filtering (propagator) algorithm ensuring bounds consistency (BC) on $y_c$ (and $z_c$ where present) and on each $x_\ell$. The main contributions are:

| Constraint Type         | Asymptotic Complexity | Key State Structures         |
|------------------------|----------------------|-----------------------------|
| Original FOCUS         | $O(n)$               | $p_\leq(\ell), p_>(\ell)$   |
| Springy FOCUS          | $O(n)$               | $p_\leq, p_S, p_>$          |
| Weighted/Weighted+Spr. | $O(n \cdot z_c^U)$   | 2D DPs $f[c,\ell], b[c,\ell]$|

- Original FOCUS: Employs a forward dynamic program to compute, for each position, the minimum number of intervals needed to cover penalizing values up to position $\ell$ under different scenarios, followed by backward scans to prune unsupported variable values.
- Springy: Expands the dynamic state to accommodate up to $h$ low values per interval.
- Weighted types: Introduce dynamic programming tables parametrized by both interval count and total cost, with forward and backward passes for full bounds consistency.

Natural decomposition into binaries and aggregate constraints is provably weaker than direct filtering, and incurs higher computational overhead for large $y_c$ or $z_c$ domains [1304.5970].

## 4. Implementation Considerations

Practical implementation uses flat arrays for dynamic programming states, recycled across pre- and post-scans. Incrementalization is feasible when only narrow changes occur in bounds, but for small- to mid-size $n$ standard $O(n)$ passes remain computationally cheap. Parameter tuning for $\mathit{len}$ or $z_c$ is advised to control the DP table size, while $h$ should be minimal to preserve the original semantics. Early instantiation of $y_c$ and $z_c$ can substantially simplify the filtering logic.

## 5. Applications and Expressiveness

The FOCUS constraint family is well-suited for modeling:

- Temporal or spatial concentration of events (e.g., scheduling maintenance during limited time slots, cluster-based legacy maintenance, or spatially contiguous facility placement).
- Scenarios requiring sparse "bursts" of activity but limited overall intervention (via $y_c$) and/or aggregate effort (via $z_c$).
- Softening classical "no interruption" or "all at once" constraints in process control.

By switching among original, springy, weighted, and combined generalizations, a modeler can flexibly trade between expressive power and computational efficiency [1304.5970].

## 6. Comparative Evaluation and Worked Examples

Worked examples provided in the reference text reveal:

- For $X=[1,0,0,1,1,0,1]$, $k=0$, $\mathit{len}=2$, at most $y_c=2$ intervals are strictly necessary: e.g., $[0,0]$, $[3,4]$, $[6,6]$.
- Springy FOCUS with $h=1$ and len=2 permits coverage with fewer intervals if tolerance for low values is increased, sometimes at the expense of solution purity.
- Weighted FOCUS enforces not just the interval count but their total length, supporting nuanced trade-offs between segment count and their spatial/temporal duration in the solution space.

Empirical results demonstrate that direct propagators consistently outperform decomposed models, especially as domain sizes grow or additional flexibility (via $h$ or $z_c$) is introduced [1304.5970].

## 7. Synthesis and Impact

The FOCUS constraint and its generalizations stand as foundational elements in constraint programming for enforcing concentration and contiguity in sequence assignments. Their clear semantics, linear or quasi-linear filtering, and support for controllable relaxations enable practical use in demanding combinatorial settings. The full family trades only modestly increased overhead for significant modeling flexibility. Real-world adoption benefits from efficient propagators whose performance is robust against a variety of domain sizes and constraint tightness settings. These developments collectively enhance both the expressive and computational capabilities of modern constraint-solving environments [1304.5970].

Source: https://www.emergentmind.com/topics/focus-algorithm