<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=AC-3_algorithm</id>
	<title>AC-3 algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=AC-3_algorithm"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=AC-3_algorithm&amp;action=history"/>
	<updated>2026-05-04T16:24:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=AC-3_algorithm&amp;diff=1267625&amp;oldid=prev</id>
		<title>imported&gt;Ollybritton: Remove unnecessary apostrophe</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=AC-3_algorithm&amp;diff=1267625&amp;oldid=prev"/>
		<updated>2025-01-08T11:55:30Z</updated>

		<summary type="html">&lt;p&gt;Remove unnecessary apostrophe&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Algorithms in constraint satisfaction}}&lt;br /&gt;
In [[constraint satisfaction]], the &amp;#039;&amp;#039;&amp;#039;AC-3 algorithm&amp;#039;&amp;#039;&amp;#039; (short for [[Arc consistency|Arc Consistency]] Algorithm #3) is one of a series of [[algorithm]]s used for the solution of [[constraint satisfaction problem]]s (or CSPs). 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 AC-3 algorithm is not to be confused with the similarly named A3C algorithm in machine learning.&amp;lt;ref&amp;gt;{{cite arXiv |eprint=gr-qc/0610068 |first=Volodymyr |last=Minh |title=Asynchronous Methods for Deep Reinforcement Learning |date=16 Jun 2016}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The algorithm ==&lt;br /&gt;
&lt;br /&gt;
AC-3 operates on [[Constraint (mathematics)|constraint]]s, [[Variable (mathematics)|variables]], and the variables&amp;#039; domains (scopes). A &amp;#039;&amp;#039;&amp;#039;variable&amp;#039;&amp;#039;&amp;#039; can take any of several discrete values; the set of values for a particular variable is known as its &amp;#039;&amp;#039;&amp;#039;domain&amp;#039;&amp;#039;&amp;#039;. A &amp;#039;&amp;#039;&amp;#039;constraint&amp;#039;&amp;#039;&amp;#039; is a [[Relation (mathematics)|relation]] that limits or constrains the values  a variable may have. The constraint may involve the values of other variables.&lt;br /&gt;
&lt;br /&gt;
The current status of the CSP during the algorithm can be viewed as a [[directed graph]], 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 [[Arc consistency|consistency]]. AC-3 proceeds by examining the arcs between pairs of variables (&amp;#039;&amp;#039;x&amp;#039;&amp;#039;, &amp;#039;&amp;#039;y&amp;#039;&amp;#039;). It removes those values from the domain of &amp;#039;&amp;#039;x&amp;#039;&amp;#039; that aren&amp;#039;t consistent with the constraints between &amp;#039;&amp;#039;x&amp;#039;&amp;#039; and &amp;#039;&amp;#039;y&amp;#039;&amp;#039;. 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 [[Termination analysis|terminate]].&lt;br /&gt;
&lt;br /&gt;
For illustration, here is an example of a    very simple constraint problem:&lt;br /&gt;
&amp;#039;&amp;#039;X&amp;#039;&amp;#039; (a variable) has the possible values {0, 1, 2, 3, 4, 5}—the set of these values are the domain of &amp;#039;&amp;#039;X&amp;#039;&amp;#039;, or D(&amp;#039;&amp;#039;X&amp;#039;&amp;#039;). The variable &amp;#039;&amp;#039;Y&amp;#039;&amp;#039; has the domain D(&amp;#039;&amp;#039;Y&amp;#039;&amp;#039;) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Together with the constraints &amp;#039;&amp;#039;C1&amp;#039;&amp;#039; = &amp;quot;&amp;#039;&amp;#039;X&amp;#039;&amp;#039; must be even&amp;quot; and &amp;#039;&amp;#039;C2&amp;#039;&amp;#039; = &amp;quot;&amp;#039;&amp;#039;X&amp;#039;&amp;#039; + &amp;#039;&amp;#039;Y&amp;#039;&amp;#039; must equal 4&amp;quot; we have a CSP that AC-3 can solve.  Notice that the actual constraint graph representing this problem must contain two edges between &amp;#039;&amp;#039;X&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Y&amp;#039;&amp;#039; since &amp;#039;&amp;#039;C2&amp;#039;&amp;#039; is undirected but the graph representation being used by AC-3 is directed.&lt;br /&gt;
&lt;br /&gt;
AC-3 solves the problem by first removing the non-even values from of the domain of &amp;#039;&amp;#039;X&amp;#039;&amp;#039; as required by &amp;#039;&amp;#039;C1&amp;#039;&amp;#039;, leaving D(&amp;#039;&amp;#039;X&amp;#039;&amp;#039;) = { 0, 2, 4 }. It then examines the arcs between &amp;#039;&amp;#039;X&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Y&amp;#039;&amp;#039; implied by &amp;#039;&amp;#039;C2&amp;#039;&amp;#039;. Only the pairs (&amp;#039;&amp;#039;X&amp;#039;&amp;#039;=0, &amp;#039;&amp;#039;Y&amp;#039;&amp;#039;=4), (&amp;#039;&amp;#039;X&amp;#039;&amp;#039;=2, &amp;#039;&amp;#039;Y&amp;#039;&amp;#039;=2), and (&amp;#039;&amp;#039;X&amp;#039;&amp;#039;=4, &amp;#039;&amp;#039;Y&amp;#039;&amp;#039;=0) match the constraint &amp;#039;&amp;#039;C2&amp;#039;&amp;#039;. AC-3 then terminates, with D(&amp;#039;&amp;#039;X&amp;#039;&amp;#039;) = {0, 2, 4} and D(&amp;#039;&amp;#039;Y&amp;#039;&amp;#039;) = {0, 2, 4}.&lt;br /&gt;
&lt;br /&gt;
AC-3 is expressed in pseudocode as follows:&lt;br /&gt;
&lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;Input:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    A set of [[Variable (mathematics)|variables]] X&lt;br /&gt;
    A set of [[domain of a function|domain]]s D(x) for each variable x in X. D(x) contains vx0, vx1... vxn, the possible values of x&lt;br /&gt;
    A set of unary constraints R1(x) on variable x that must be satisfied&lt;br /&gt;
    A set of binary constraints R2(x, y) on variables x and y that must be satisfied&lt;br /&gt;
    &lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;Output:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
    Arc consistent domains for each variable.&lt;br /&gt;
  &lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;function&amp;#039;&amp;#039;&amp;#039; ac3(X, D, R1, R2)&lt;br /&gt;
      &amp;#039;&amp;#039;// Initial domains are made consistent with unary constraints.&amp;#039;&amp;#039;&lt;br /&gt;
      &amp;#039;&amp;#039;&amp;#039;for each&amp;#039;&amp;#039;&amp;#039; x &amp;#039;&amp;#039;&amp;#039;in&amp;#039;&amp;#039;&amp;#039; X&lt;br /&gt;
          D(x) := { vx in D(x) | vx satisfies R1(x) }   &lt;br /&gt;
      &amp;#039;&amp;#039;// &amp;#039;worklist&amp;#039; contains all arcs we wish to prove consistent or not.&amp;#039;&amp;#039;&lt;br /&gt;
      worklist := { (x, y) | there exists a relation R2(x, y) or a relation R2(y, x) }&lt;br /&gt;
  &lt;br /&gt;
      &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
          select any arc (x, y) from worklist&lt;br /&gt;
          worklist := worklist - (x, y)&lt;br /&gt;
          &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; arc-reduce (x, y) &lt;br /&gt;
              &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; D(x) is empty&lt;br /&gt;
                  &amp;#039;&amp;#039;&amp;#039;return&amp;#039;&amp;#039;&amp;#039; failure&lt;br /&gt;
              &amp;#039;&amp;#039;&amp;#039;else&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
                  worklist := worklist + { (z, x) | z != y and there exists a relation R2(x, z) or a relation R2(z, x) }&lt;br /&gt;
      &amp;#039;&amp;#039;&amp;#039;while&amp;#039;&amp;#039;&amp;#039; worklist &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; empty&lt;br /&gt;
  &lt;br /&gt;
  &amp;#039;&amp;#039;&amp;#039;function&amp;#039;&amp;#039;&amp;#039; arc-reduce(x, y)&lt;br /&gt;
      &amp;#039;&amp;#039;&amp;#039;bool&amp;#039;&amp;#039;&amp;#039; change = &amp;#039;&amp;#039;&amp;#039;false&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
      &amp;#039;&amp;#039;&amp;#039;for each&amp;#039;&amp;#039;&amp;#039; vx &amp;#039;&amp;#039;&amp;#039;in&amp;#039;&amp;#039;&amp;#039; D(x)&lt;br /&gt;
          find a value vy in D(y) such that vx and vy satisfy the constraint R2(x, y)&lt;br /&gt;
          &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; there is no such vy {&lt;br /&gt;
              D(x) := D(x) - vx&lt;br /&gt;
              change := &amp;#039;&amp;#039;&amp;#039;true&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
          }&lt;br /&gt;
      &amp;#039;&amp;#039;&amp;#039;return&amp;#039;&amp;#039;&amp;#039; change&lt;br /&gt;
&lt;br /&gt;
The algorithm has a worst-case [[time complexity]] of &amp;#039;&amp;#039;&amp;#039;[[big O notation|O]]&amp;#039;&amp;#039;&amp;#039;(&amp;#039;&amp;#039;ed&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&amp;#039;&amp;#039;) and [[space complexity]] of &amp;#039;&amp;#039;&amp;#039;[[big O notation|O]]&amp;#039;&amp;#039;&amp;#039;(&amp;#039;&amp;#039;e&amp;#039;&amp;#039;), where &amp;#039;&amp;#039;e&amp;#039;&amp;#039; is the number of arcs and &amp;#039;&amp;#039;d&amp;#039;&amp;#039; is the size of the largest domain.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
* A.K. Mackworth. [https://www.sciencedirect.com/science/article/abs/pii/0004370277900078 Consistency in networks of relations]. &amp;#039;&amp;#039;[[Artificial Intelligence (journal)|Artificial Intelligence]]&amp;#039;&amp;#039;, 8:99-118, 1977.&lt;br /&gt;
* [[Stuart J. Russell]] and [[Peter Norvig]]. &amp;#039;&amp;#039;[[Artificial Intelligence: A Modern Approach]]&amp;#039;&amp;#039;, 202-233, 2003.&lt;br /&gt;
&lt;br /&gt;
[[Category:Constraint programming]]&lt;br /&gt;
[[Category:Articles with example pseudocode]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Ollybritton</name></author>
	</entry>
</feed>