You are on page 1of 1

4.

2 Node and Arc-consistency Achieving Algorithms 83

4.2.3 Improved AC achievement algorithms

AC-1 could be very inefficient because the removal of any value from any domain
would cause all the elements of Q to be re-examined. This algorithm is improved to
AC-2, and AC-3 in the literature. The idea behind these algorithms is to examine
only those binary-constraints which could be affected by the removal of values. We
shall skip AC-2 (as it uses a similar principle but is inferior to AC-3 in time com-
plexity), and look at AC-3 below:

PROCEDURE AC-3((Z, D, C))


BEGIN
NC-1(Z, D, C);
Q ← {x→y | Cx,y ∈ C};
/* x→y is an arc; Cy,x is the same object as Cx,y */
WHILE (Q ≠ { }) DO
BEGIN
delete any element x→y from Q;
IF Revise_Domain(x→y, (Z, D, C)) THEN
Q ← Q ∪ {z→x | Cz,x ∈ C ∧ z ≠ x ∧ z ≠ y};
/* side effect of Revise_Domain: Dx may be reduced */
END
return(Z, D, C);
END /* of AC-3 */

If Revise_Domain((x,y)) removes any value from the domain of x, then the domain
of any third variable z which is constrained by x must be examined. This is because
the removed value may be the only one which is compatible with some values c in
the domain of z (in which case, c has to be removed). That is why z→x (except
when z = y) is added to the queue Q if Revise_Domain(x→y, (Z, D, C)) returns True.
y→x is not added to Q as Dx was reduced because of y. This will not, in turn, cause
Dy to be reduced.

As mentioned above, the length of Q is 2e (where e is the number of edges in the


constraint graph), and in each call of Revise_Domain, a2 pairs of labels are exam-
ined. So the lower bound of the time complexity of AC-3 is Ω(a2e).

In the worst case, each call of Revise_Domain deletes one value from a domain.
Each arc x→y will be processed only when the domain of y is reduced. Since we
assume that the constraint graph has 2e arcs, and the maximum size of the domain
of the variables is a, a maximum of 2ea arcs will be added to Q. With each call of
Revise_Domain examining a2 pairs of labels, the upper bound of the time complex-

You might also like