Arc Consistency and Constraint Propagation

Author

Your Name

Published

February 5, 2025

Introduction

This lecture introduces the concept of arc consistency, a cornerstone of constraint propagation techniques in Constraint Satisfaction Problems (CSPs). We will explore how arc consistency reduces the search space by enforcing local consistency on binary constraints. The discussion will cover the formal definition of arc consistency, its algorithmic implementation, and practical examples, including the N-Queens problem, to demonstrate its effectiveness. Additionally, we will showcase a demonstration using the Minizinc tool to highlight the efficiency of constraint propagation.

  • Arc Consistency: A local consistency property for binary constraints.

  • Constraint Propagation: Techniques to reduce the search space in CSPs.

  • Binary Constraints: Constraints involving two variables.

  • Minizinc: A constraint modeling language used for demonstration.

Arc Consistency

Definition 1 (Arc Consistency). A binary constraint \(C\) between variables \(X\) and \(Y\), with respective domains \(\mathcal{D}_X\) and \(\mathcal{D}_Y\), is considered arc consistent if, for every value \(A\) in \(\mathcal{D}_X\), there exists at least one value \(B\) in \(\mathcal{D}_Y\) such that the pair \((A, B)\) satisfies \(C\), and vice versa. Formally, this can be expressed as:

  • \(\forall A \in \mathcal{D}_X, \exists B \in \mathcal{D}_Y: (A, B) \text{ satisfies } C\)

  • \(\forall B \in \mathcal{D}_Y, \exists A \in \mathcal{D}_X: (A, B) \text{ satisfies } C\)

In this context, we say that \(B\) supports \(A\), and conversely, \(A\) supports \(B\).

Arc consistency is a local consistency property. It is applied to individual constraints, not to the entire set of constraints within a CSP. Consequently, a CSP can be arc consistent across all its binary constraints but still be globally inconsistent, meaning it has no solution that satisfies all constraints simultaneously.

Example 1 (Non-arc consistent constraint). Consider the constraint \(X < Y\) with domains \(\mathcal{D}_X= \{5, 10\}\) and \(\mathcal{D}_Y= \{3, 7\}\).

  • The value \(5 \in \mathcal{D}_X\) is supported by \(7 \in \mathcal{D}_Y\) because \(5 < 7\).

  • However, \(10 \in \mathcal{D}_X\) is not supported by any value in \(\mathcal{D}_Y\), as no value in \(\mathcal{D}_Y\) is greater than 10.

Therefore, this constraint is not arc consistent. To achieve arc consistency, the value 10 must be removed from \(\mathcal{D}_X\), resulting in \(\mathcal{D}_X= \{5\}\).

Example 2 (Arc consistent but globally inconsistent CSP). Consider a CSP with the constraints \(X \neq Y\), \(Y \neq Z\), and \(X \neq Z\), where the domains are \(\mathcal{D}_X= \mathcal{D}_Y= \mathcal{D}_Z= \{0, 1\}\). This CSP is arc consistent because:

  • For \(X \neq Y\): If \(X = 0\), \(Y\) can be 1, and if \(X = 1\), \(Y\) can be
  • Similarly, the constraints \(Y \neq Z\) and \(X \neq Z\) are also arc consistent.

Despite being arc consistent, this CSP has no solution. If \(X=0\), then \(Y\) must be 1, and \(Z\) must be 0, but this violates \(X \neq Z\). This example illustrates that arc consistency is a necessary but not sufficient condition for global consistency.

  • Arc consistency ensures that each value in a variable’s domain has a supporting value in the domain of the other variable involved in the constraint.

  • Arc consistency is a local property and does not guarantee global consistency.

  • Achieving arc consistency involves filtering domains to remove unsupported values.

Achieving Arc Consistency

To achieve arc consistency, it is necessary to filter the domains of the variables involved in a constraint. This involves removing any values that do not have support in the domain of the other variable.

Proposition 1 (Domain Filtering for Arc Consistency). Let \(C\) be a binary constraint between variables \(X\) and \(Y\), with domains \(\mathcal{D}_X\) and \(\mathcal{D}_Y\), respectively. Arc consistency can be achieved by updating the domains as follows:

  • \(\mathcal{D}'_X= \{A \in \mathcal{D}_X\mid \exists B \in \mathcal{D}_Y: (A, B) \text{ satisfies } C\}\)

  • \(\mathcal{D}'_Y= \{B \in \mathcal{D}_Y\mid \exists A \in \mathcal{D}_X: (A, B) \text{ satisfies } C\}\)

Here, \(\mathcal{D}'_X\) and \(\mathcal{D}'_Y\) represent the filtered domains of \(X\) and \(Y\), respectively, after enforcing arc consistency.

The rules defined in Proposition 1 are at a semantic level, specifying what needs to be achieved. However, they do not provide a concrete algorithm for computing \(\mathcal{D}'_X\) and \(\mathcal{D}'_Y\). The actual implementation requires an algorithmic approach to systematically check for support and filter the domains.

Algorithmic Complexity

To filter the domain \(\mathcal{D}_X\) and obtain \(\mathcal{D}'_X\), we must verify each element \(A \in \mathcal{D}_X\) for the existence of a supporting value in \(\mathcal{D}_Y\). For each \(A\), we potentially need to iterate through all values in \(\mathcal{D}_Y\) to find a suitable \(B\) such that \((A, B)\) satisfies the constraint \(C\). This process requires a number of steps bounded by \(|\mathcal{D}_X| \times |\mathcal{D}_Y|\). Similarly, filtering \(\mathcal{D}_Y\) to obtain \(\mathcal{D}'_Y\) also requires at most \(|\mathcal{D}_X| \times |\mathcal{D}_Y|\) steps.

Let \(D\) represent the maximum size of the domains, i.e., \(D = \max(|\mathcal{D}_X|, |\mathcal{D}_Y|)\). Then, the complexity of achieving arc consistency for a single binary constraint is \(O(D^2)\), as we perform at most \(D \times D\) checks.

  • Filtering \(\mathcal{D}_X\) requires at most \(|\mathcal{D}_X| \times |\mathcal{D}_Y|\) steps.

  • Filtering \(\mathcal{D}_Y\) requires at most \(|\mathcal{D}_X| \times |\mathcal{D}_Y|\) steps.

  • The complexity of achieving arc consistency for a single constraint is \(O(D^2)\), where \(D\) is the maximum domain size.

Iterative Arc Consistency Enforcement

Enforcing arc consistency on a single constraint can alter the domains of variables, potentially affecting the arc consistency of other constraints. Therefore, achieving arc consistency for an entire CSP often requires an iterative process.

Example 3 (Iterative Arc Consistency). Consider a CSP with the following constraints: \[X_1 < X_2, \quad X_2 < X_3, \quad X_3 < X_4, \quad X_4 < X_5, \quad X_5 < X_1\] The initial domains for all variables are \(\mathcal{D}_{X_i} = \{1, 2, 3, 4, 5\}\) for \(i = 1, \dots, 5\).

Applying arc consistency iteratively:

  1. First Pass:

    • \(X_1 < X_2\): Remove 5 from \(\mathcal{D}_{X_1}\) and 1 from \(\mathcal{D}_{X_2}\).

    • \(X_2 < X_3\): Remove 5 from \(\mathcal{D}_{X_2}\) and 1, 2 from \(\mathcal{D}_{X_3}\).

    • \(X_3 < X_4\): Remove 5 from \(\mathcal{D}_{X_3}\) and 1, 2, 3 from \(\mathcal{D}_{X_4}\).

    • \(X_4 < X_5\): Remove 5 from \(\mathcal{D}_{X_4}\) and 1, 2, 3, 4 from \(\mathcal{D}_{X_5}\).

    • \(X_5 < X_1\): Remove 5, 4 from \(\mathcal{D}_{X_5}\) and 1 from \(\mathcal{D}_{X_1}\).

  2. Second Pass:

    • \(X_1 < X_2\): Remove 4 from \(\mathcal{D}_{X_1}\).

    • \(X_2 < X_3\): Remove 4 from \(\mathcal{D}_{X_2}\).

    • \(X_3 < X_4\): Remove 4 from \(\mathcal{D}_{X_3}\).

    • \(X_4 < X_5\): Remove 4 from \(\mathcal{D}_{X_4}\).

    • \(X_5 < X_1\): Remove 2 from \(\mathcal{D}_{X_1}\).

  3. Third Pass:

    • \(X_1 < X_2\): Remove 3 from \(\mathcal{D}_{X_2}\).

    • \(X_2 < X_3\): Remove 3 from \(\mathcal{D}_{X_3}\).

As we can see, multiple passes are required to reach a stable state. In this specific case, the domains eventually become empty, indicating that the CSP has no solution.

Algorithm for Arc Consistency Propagation

\(P \gets\) initial CSP \(P \gets \text{NodeConsistency}(P)\) \(P' \gets P\) \(\mathcal{D}'_X\gets \{A \in \mathcal{D}_X\mid \exists B \in \mathcal{D}_Y: (A, B) \text{ satisfies } C\}\) \(\mathcal{D}'_Y\gets \{B \in \mathcal{D}_Y\mid \exists A \in \mathcal{D}_X: (A, B) \text{ satisfies } C\}\) Update \(\mathcal{D}_X\) with \(\mathcal{D}'_X\) and \(\mathcal{D}_Y\) with \(\mathcal{D}'_Y\) in \(P\) \(P\)

Complexity Analysis

Let \(C\) be the number of binary constraints in the CSP, and \(n\) be the number of variables. In each iteration of the repeat loop in Algorithm [alg:arc_consistency], we enforce arc consistency on each constraint, which, as discussed in Section 3.1, takes \(O(D^2)\) time. Therefore, each iteration of the loop has a time complexity of \(O(C D^2)\).

In the worst-case scenario, each iteration might remove at least one element from a domain. Since there are \(n\) variables and each variable has a domain of size at most \(D\), there can be at most \(n \times D\) elements to remove. Thus, the maximum number of iterations is bounded by \(n \times D\).

The overall time complexity of the iterative arc consistency algorithm is therefore \(O(C D^2 \times n D) = O(n C D^3)\).

The complexity analysis above provides a raw upper bound. In practice, the number of iterations is often significantly smaller than \(n \times D\). Moreover, for specific types of constraints, such as \(X < Y\) on intervals, more efficient algorithms exist that exploit the structure of the domains and constraints, as will be discussed later. These specialized algorithms can achieve arc consistency without scanning the entire domain, leading to better performance.

  • Arc consistency enforcement may require multiple iterations.

  • The iterative process continues until a stable state is reached.

  • The worst-case time complexity is \(O(nCD^3)\), but in practice, it is often much lower.

  • Specialized algorithms can improve efficiency for specific constraint types.

Example: N-Queens Problem

The N-Queens problem is a classic Constraint Satisfaction Problem (CSP) where the goal is to place \(N\) queens on an \(N \times N\) chessboard such that no two queens threaten each other. This means no two queens can share the same row, column, or diagonal.

Example 4 (4-Queens Problem). Consider the 4-Queens problem, where we need to place four queens on a \(4 \times 4\) chessboard. Let \(X_i\) represent the column position of the queen in row \(i\). The constraints are as follows:

  • Column Constraint: \(X_i \neq X_j\) for \(i \neq j\) (no two queens in the same column).

  • Diagonal Constraint: \(|X_i - X_j| \neq |i - j|\) for \(i \neq j\) (no two queens on the same diagonal). This constraint can be expressed as two separate constraints:

    • \(X_i - X_j \neq i - j\) for \(i \neq j\) (no two queens on the same diagonal).

    • \(X_i - X_j \neq j - i\) for \(i \neq j\) (no two queens on the same anti-diagonal).

The domains for each variable are \(\mathcal{D}_{X_i} = \{1, 2, 3, 4\}\) for \(i = 1, 2, 3, 4\).

Applying Arc Consistency: Let’s explore how arc consistency can be applied to solve the 4-Queens problem.

  1. Initial Assignment: Suppose we start by assigning \(X_1 = 1\). Node consistency removes 1 from the domain of \(X_1\) (although in practice we don’t remove the assigned value, but we consider it as fixed).

  2. Arc Consistency with \(X_1\) and \(X_2\): The constraints between \(X_1\) and \(X_2\) imply that \(X_2\) cannot be 1 (same column) or 2 (same diagonal). Thus, the domain of \(X_2\) is reduced to \(\{3, 4\}\).

  3. Arc Consistency with \(X_1\) and \(X_3\): Similarly, \(X_3\) cannot be 1 (same column) or 3 (same diagonal). The domain of \(X_3\) is reduced to \(\{2, 4\}\).

  4. Arc Consistency with \(X_1\) and \(X_4\): \(X_4\) cannot be 1 (same column) or 4 (same diagonal). The domain of \(X_4\) is reduced to \(\{2, 3\}\).

  5. Arc Consistency with \(X_2\) and \(X_3\): Considering the updated domains, \(X_3\) cannot be 2 (same diagonal with \(X_2=3\)) or 4 (same diagonal with \(X_2=4\)). This leaves no valid value for \(X_3\), indicating that assigning \(X_1=1\) leads to a dead end.

We conclude that the initial assignment \(X_1 = 1\) leads to no solution, and the search space is pruned effectively by arc consistency.

Now, let’s try \(X_1 = 2\):

  1. Initial Assignment: We set \(X_1 = 2\).

  2. Arc Consistency with \(X_1\) and \(X_2\): \(X_2\) cannot be 1, 2, or 3. Therefore, \(\mathcal{D}_{X_2} = \{4\}\).

  3. Arc Consistency with \(X_1\) and \(X_3\): \(X_3\) cannot be 2 or

  4. Arc Consistency with \(X_1\) and \(X_4\): \(X_4\) cannot be 2.

  5. Arc Consistency with \(X_2\) and \(X_3\): With \(X_2 = 4\), \(X_3\) cannot be 4. Thus, \(\mathcal{D}_{X_3} = \{1\}\).

  6. Arc Consistency with \(X_2\) and \(X_4\): With \(X_2 = 4\), \(X_4\) cannot be 3 or 4.

  7. Arc Consistency with \(X_3\) and \(X_4\): With \(X_3 = 1\), \(X_4\) cannot be 1. Thus, \(\mathcal{D}_{X_4} = \{3\}\).

We find a solution \((2, 4, 1, 3)\), which corresponds to placing queens at positions (1,2), (2,4), (3,1), and (4,3).

This example illustrates how arc consistency significantly reduces the search space in the N-Queens problem. By iteratively enforcing arc consistency, we can quickly identify inconsistencies and prune branches of the search tree that do not lead to a solution, making the search process more efficient.

A solution to the 4-Queens problem with queens at positions (1,2), (2,4), (3,1), and (4,3).

Minizinc Demonstration

This section demonstrates the use of Minizinc, a constraint modeling language, to solve a Constraint Satisfaction Problem (CSP) with constraints of the form \(X_i < X_{i+1}\). This example highlights how constraint propagation techniques, such as arc consistency, are implemented in practice and how they affect the performance of constraint solvers.

Minizinc Code: The following Minizinc code defines a CSP with \(n\) variables, where each variable \(X_i\) must be less than \(X_{i+1}\).

int: n = 5;
array[1..n] of var 1..n: X;

constraint forall(i in 1..n-1)(X[i] < X[i+1]);
% constraint X[n] < X[1];

solve satisfy;

output [
  "X1 = ", show(X[1]), "\n",
  "X2 = ", show(X[2]), "\n",
  "...\n",
  "Xn = ", show(X[n]), "\n"
];

In this code:

  • int: n = 5; declares an integer parameter n with a value of 5, representing the number of variables.

  • array[1..n] of var 1..n: X; declares an array X of n variables, each with a domain from 1 to n.

  • constraint forall(i in 1..n-1)(X[i] < X[i+1]); defines the constraints that each variable \(X_i\) must be less than the next variable \(X_{i+1}\).

  • % constraint X[n] < X[1]; is a commented-out constraint that, if uncommented, would add the constraint that \(X_n < X_1\), creating a cycle.

  • solve satisfy; instructs the solver to find a solution that satisfies all constraints.

  • The output section specifies how the solution should be displayed, showing the values of the first two and the last variables.

Observations:

  • Quadratic Growth: When running the Minizinc code with only the constraints \(X_i < X_{i+1}\), the running time increases quadratically with the number of variables. This is because the solver needs to propagate the constraints and filter the domains, which takes more time as the number of variables and domain sizes increase.

  • Inconsistency Detection: Adding the constraint \(X_n < X_1\) (by uncommenting the line % constraint X[n] < X[1];) makes the problem inconsistent, as it introduces a cycle in the less-than constraints. In this case, the running time drastically decreases. This is because Minizinc can detect the inconsistency efficiently through specialized algorithms that identify cycles in the constraint graph.

  • Specialized Algorithms: The efficiency of Minizinc in detecting the inconsistency is due to specialized algorithms for handling specific constraint types, such as \(X < Y\). These algorithms do not need to scan the entire domain to enforce arc consistency; instead, they can use properties of the constraint and the domain to propagate information more efficiently. In particular, the solver can detect that a cycle of less-than constraints has no solution in linear time by analyzing the strongly connected components of the constraint graph.

Graph showing the quadratic growth of running time with the number of variables for the (X_i < X_{i+1}) constraint and the linear time when adding the (X_n < X_1) constraint, which creates a cycle.
  • Minizinc demonstrates the practical application of constraint propagation.

  • The running time for simple less-than constraints grows quadratically.

  • Adding a cyclic constraint allows for efficient inconsistency detection.

  • Specialized algorithms significantly improve the performance of constraint solvers.

Conclusion

Arc consistency is a fundamental and powerful technique for reducing the search space in Constraint Satisfaction Problems (CSPs). By enforcing local consistency on binary constraints, it effectively removes unsupported values from the domains of variables. Although the worst-case time complexity for achieving arc consistency is \(O(n C D^3)\), in practice, the process is often much faster, particularly for specific constraint types where specialized algorithms can be applied. The N-Queens example demonstrated how arc consistency can significantly prune the search space, leading to more efficient solutions. The Minizinc demonstration further highlighted the efficiency of constraint propagation techniques in modern constraint solvers.

  • Local Consistency: Arc consistency is a local consistency property enforced on individual binary constraints.

  • Domain Filtering: It involves removing unsupported values from variable domains, reducing the search space.

  • Iterative Process: Achieving arc consistency is an iterative process that may require multiple passes over the constraints.

  • Specialized Algorithms: Specialized algorithms can exploit the structure of constraints to improve efficiency.

  • Fundamental Technique: Constraint propagation, including arc consistency, is a fundamental technique in constraint solving.

Follow-up Questions

Here are some questions to consider for further exploration:

  • How can we extend the concept of arc consistency to non-binary constraints?

  • What are some other local consistency properties beyond arc consistency, and how do they compare?

  • How do constraint solvers handle different types of constraints efficiently, and what are the underlying techniques?

  • What are the limitations of arc consistency, and when might it be insufficient to solve a CSP effectively?

Topics for the Next Lecture

The following topics will be covered in the next lecture:

  • Generalized arc consistency for non-binary constraints.

  • Path consistency and other higher-order consistency techniques.

  • Constraint optimization problems, where the goal is to find the best solution according to some objective function.

  • Search algorithms for constraint satisfaction, including backtracking search and other advanced techniques.