HOME

TheInfoList



OR:

In
constraint satisfaction In artificial intelligence and operations research, constraint satisfaction is the process of finding a solution through a set of constraints that impose conditions that the variables must satisfy. A solution is therefore a set of values for the ...
, the AC-3 algorithm (short for
Arc Consistency In constraint satisfaction, local consistency conditions are properties of constraint satisfaction problems related to the consistency of subsets of variables or constraints. They can be used to reduce the search space and make the problem easier t ...
Algorithm #3) is one of a series of
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
s used for the solution of
constraint satisfaction problem Constraint satisfaction problems (CSPs) are mathematical questions defined as a set of objects whose state must satisfy a number of constraints or limitations. CSPs represent the entities in a problem as a homogeneous collection of finite constr ...
s (or CSP's). It was developed by Alan Mackworth in 1977. The earlier AC algorithms are often considered too inefficient, and many of the later ones are difficult to implement, and so AC-3 is the one most often taught and used in very simple constraint solvers.


The algorithm

AC-3 operates on
constraint Constraint may refer to: * Constraint (computer-aided design), a demarcation of geometrical characteristics between two or more entities or solid modeling bodies * Constraint (mathematics), a condition of an optimization problem that the solution ...
s, variables, and the variables' domains (scopes). A variable can take any of several discrete values; the set of values for a particular variable is known as its domain. A constraint is a relation that limits or constrains the values a variable may have. The constraint may involve the values of other variables. The current status of the CSP during the algorithm can be viewed as a
directed graph In mathematics, and more specifically in graph theory, a directed graph (or digraph) is a graph that is made up of a set of vertices connected by directed edges, often called arcs. Definition In formal terms, a directed graph is an ordered pai ...
, where the nodes are the variables of the problem, with edges or arcs between variables that are related by symmetric constraints, where each arc in the worklist represents a constraint that needs to be checked for
consistency In classical deductive logic, a consistent theory is one that does not lead to a logical contradiction. The lack of contradiction can be defined in either semantic or syntactic terms. The semantic definition states that a theory is consistent ...
. AC-3 proceeds by examining the arcs between pairs of variables (''x'', ''y''). It removes those values from the domain of ''x'' which aren't consistent with the constraints between ''x'' and ''y''. The algorithm keeps a collection of arcs that are yet to be checked; when the domain of a variable has any values removed, all the arcs of constraints pointing to that pruned variable (except the arc of the current constraint) are added to the collection. Since the domains of the variables are finite and either one arc or at least one value are removed at each step, this algorithm is guaranteed to terminate. For illustration, here is an example of a very simple constraint problem: ''X'' (a variable) has the possible values -- the set of these values are the domain of ''X'', or D(''X''). The variable ''Y'' has the domain D(''Y'') = . Together with the constraints ''C1'' = "''X'' must be even" and ''C2'' = "''X'' + ''Y'' must equal 4" we have a CSP which AC-3 can solve. Notice that the actual constraint graph representing this problem must contain two edges between ''X'' and ''Y'' since ''C2'' is undirected but the graph representation being used by AC-3 is directed. It does so by first removing the non-even values out of the domain of ''X'' as required by ''C1'', leaving D(''X'') = . It then examines the arcs between ''X'' and ''Y'' implied by ''C2''. Only the pairs (''X''=0, ''Y''=4), (''X''=2, ''Y''=2), and (''X''=4, ''Y''=0) match the constraint ''C2''. AC-3 then terminates, with D(''X'') = and D(''Y'') = . AC-3 is expressed in pseudocode as follows: Input: A set of variables X A set of
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined ** Domain of definition of a partial function **Natural domain of a partial function **Domain of holomorphy of a function *Do ...
s D(x) for each variable x in X. D(x) contains vx0, vx1... vxn, the possible values of x A set of unary constraints R1(x) on variable x that must be satisfied A set of binary constraints R2(x, y) on variables x and y that must be satisfied Output: Arc consistent domains for each variable. function ac3 (X, D, R1, R2) ''// Initial domains are made consistent with unary constraints.'' for each x in X D(x) := ''// 'worklist' contains all arcs we wish to prove consistent or not.'' worklist := do select any arc (x, y) from worklist worklist := worklist - (x, y) if arc-reduce (x, y) if D(x) is empty return failure else worklist := worklist + while worklist not empty function arc-reduce (x, y) bool change = false for each vx in D(x) find a value vy in D(y) such that vx and vy satisfy the constraint R2(x, y) if there is no such vy { D(x) := D(x) - vx change := true } return change The algorithm has a worst-case time complexity of O(''ed3'') and space complexity of O(''e''), where ''e'' is the number of arcs and ''d'' is the size of the largest domain.


References

* A.K. Mackworth
Consistency in networks of relations
''Artificial Intelligence'', 8:99-118, 1977. * Stuart Russell and Peter Norvig. '' Artificial Intelligence : A Modern Approach'', 202-233, 2003. Constraint programming Articles with example pseudocode