Arc consistency for factorable relations

An optimal arc consistency algorithm AC-4 was given by R. Mohr and T.C. Henderson (1986). AC-4 has costO(ea/sup 2/), and cost(na/sup 2/) for scene labeling. Although their algorithm is indeed optimal, under certain conditions a constraint satisfaction problem can be transformed into a less complex problem. Conditions and mechanisms are presented for such transformations, and it is shown how to factor relations into more manageable components. A description is given of how factorization can reduce AC-4's cost to O(ea), and this result is applied to RETE match.<<ETX>>


Introduction
There are search problems that entail the generation and testing of the cartesian product of n sets. Following [8] Suppose a partial solution k-tuple, k<n, is not admissible. Then any extension of this k-tuple is not admissible. Backtrack control is a strategy that reduces search by eliminating these inadmissible extensions from the cartesian product computation.
Since CSP is NP-complete, additional preprocessing can be helpful [6], such as decreasing the initial size of each Ai set prior to forming the cartesian product. One mechanism for this filtering is arc consistency, which examines the Rij to eliminate any b€ Ai which lacks support in an Aj. Arc consistency is used, for example, in machine vision problems [17].
Waltz's original arc consistency algorithm for scene labelling [17] was based on the successive consideration of each variable's value set Ai. This had a computational complexity of 0(ena 3 ). Mackworth and Freuder [7] introduced algorithm AC-3, which used the edges in E, rather than the variables in N, to guide the filtering. This reduced the complexity to 0(ea 3 ). Mohr and Henderson [8] introduced AC-4, which used the edges between values (instead of variables) to direct the filtering, further reducing the cost to 0(ea 2 ). Since scene labelling employs a planar graph, 0(e) = 0(n), and AC-4 f s complexity for scene labelling is 0(na 2 ).
In building a Waltz scene labelling application within a graphical user interface methodology [10], we implemented an O(na) arc consistency algorithm. In this paper, we first motivate our algorithm by considering the graph of supporting relations. We present AC-5, a version of AC-4 that explicates the underlying graph. We then examine how, under certain circumstances, edge relations can be factorable. For some problems, this can reduce the 0(ea 2 ) cost to O(ea). We apply this factorization to scene labelling, obtaining an O(na) cost, and also describe how our arc consistency method can be applied to RETE matching [3].

Support for Values
We write the set images under a binary relation B as: B(x,*) = {y I B(x,y)}, B(*,y) = {x I B(x,y)}.
After filtering with the unary relations, we have the sets Ai. The relations Rij are between the values in Ai and Aj. We construct the union of the Rij, forming the relation R on values, defined for be Ai and ce Aj as R(ibJc) <=> Rij(b,c). If it is not the case that Rij(b,c), then no n-tuple t with t(i)=b and t(j)=c is admissible. Identically, R(ib jc) is necessary for a tuple t with t(i)=b and t(j)=c to be admissible.
Suppose that for no ce Aj, R(ib jc). Then no tuple t with t(i)=b will be admissible. Therefore, ib can be removed from Ai, and not affect the CSP. This can be used as a filtering strategy [17] for reducing the Ai. We define supported'pdb) <=> V j e E(i,*), AjnR(ib,*) * 0. When supported-p(ib) is false, value ib can be removed from Ai, and ib's relations removed from R. Now, for efficient implementation, we view the set of values uAi as the nodes of a graph G, and the relation R as the links between them. Ordinarily in arc consistency algorithms [8], a graph Go is employed that uses the variables {i} as node set, and E as edge set. Our G, however, refines Go by using values instead of variables, linking the values in AixAj according to Rij.
Our algorithm AC-5 for arc consistency is given in Figure 1. It roughly replicates algorithm AC-4 [8]. However, instead of using counters, sets, and flags, AC-5 makes explicit use of G. Specifically, in our formulation, AC-4's • Counter[(i j),b] = # ApRGb,*), • set Sj c = R(* jc), • flag M(i,b) = 0, if b€ Ai, and 1 otherwise. Our unit of complexity is the use of a node or link in G.
Step 1. INITIALIZER, R) 1 Construct the nodes and links of the graph from the values in uAi and the relation R.
Procedure for removing a value node and its relation links. In Step 1, the cost of initialization is proportional to the size of graph G, or 0( IGI). Line 1, constructing G, has cost 0(na+XE r ij)> the number of nodes and links; this is precisely 0( I GI). Line 2 iterates over the nodes, and line 3 iterates over the outdegree of each node, i.e., the links. This, again, has cost 0( IGI).
Step 4 performs the test AjnRttb,*) = 0, which can be done in constant time by checking whether the set (e.g., a list) of links from value ib to variable j is empty.
When a node ib is found to violate supported-p(ib), it is placed on the control queue. The queue is maintained as a set (e.g., by marking deleted nodes). ENQUEUE-UNSUPPORTED(ib) and DEQUEUE-UNSUPPORTEDO can be each done in constant time (e.g., by using a stack representation). In Step 2, the cost of arc consistency filtering is also 0( IGI).
Step 6's WHILE loop considers each node jc at most once. Line 7 then examines all the links emanating from jc. These links can occur in this way at most once, since jc is to be deleted from the graph. Therefore, the constant time operation in Steps 8 and 9 can occur no more than IGI times. By similar counting, the SPLICE-OUT operation in line 10 can occur at most once for each node and link in the graph.
The total space cost is also 0( IGI). The only two data structures are G, and the queue. G's representation is clearly 0( IGI). The queue size is bounded by the number of nodes, hence by IGI.

3, Factoring Relations
The cost of our AC-5 algorithm (and the equivalent AC-4) is 0( IGI), the size of the graph comprised of variable values and their relations. Further, as shown in [8], this is a minimal algorithm. How, then, is it possible to decrease the complexity of arc consistency?
If relation B between two sets is factorable, then B may be rewritten as the product PxQ, where P and Q are two new relations. In some cases, P and Q are sparser thanB. If IPI + IQI < IBI, then the factorization will reduce the total number of links connecting the two sets. Such factorizations appear in other divide-and-conquer [5] algorithms. For example, the Fast Fourier Transform works by factoring a matrix with n 2 nonzero entries into log(n) matrices, each having O(n) nonzero entries [1].
The relations Rij used in arc consistency may be factorable in this way. Factorization introduces new variables, and extends the graph G to a new graph G'. Importantly, our arc consistency algorithm AC-5 (or AC-4) can operate on this new graph G 1 without modification. Since the complexity of arc consistency is bounded by the number of links in G, if G' has fewer links than G, the factorization may reduce the execution cost of AC-5, In general, there may be no useful factorization of G's link relations. However, for certain key situations, such as scene labelling and RETE match, the relations are factorable. We now develop two general classes of factorizations.

Using Tuples as Values
In many situations, the values used as variable bindings are not atomic. Rather, they are actually formed as tuples of slot-values. This occurs when the role of each tuple component is to provide information about a neighboring edge. Specifically, for each edge j in E(i,*), the value ibe Ai has for its j t h component the slot-value ib(j). That is, The key idea is to partition the elements of Ai (and Aj) into equivalence classes, and then connect the classes, instead of connecting the elements [14]. Given Ai, the inverse image of a slot-value v is 7cij-l(v) = {ib€Ai I ib(j)=v}. If v and w are two compatible slot values, then Rij connects every ib in the subset rcyHv) of Ai to every jc in the subset rcifKw) of Aj. However, relation Rij between tuples can be compactly summarized by a core relation R°ij that connects compatible slot-values. The single link R°ij(v,w) can then replace the complete bipartite graph between subsets T&yHv) and riJf^v).

Equality Relations
When R°ij represents an equality relation, then r°y is small. In fact, R°ij then becomes the identity relation I. This is shown in Figure 3.A, where the factorization Rij = Py x Iy x QyT has the number of links py + k + qij T <: 2a + k, where k is the number of common slot-values, #Vy, and Vij=Pij(Ai)nQjj(Aj). We can do better. In Figure 3.B, we collapse the identity Iy relation into the single set Vy, and reduce the factorization to Rij = Pij x Qij T . Here, the number of links is py + qij T < 2a, Thus, when Ry is an equality relation, the upper bound on the number of links is lowered from a 2 to 2a.
When all the Ry are equality relations on tuple slots, then all the Ry can be factored. This adds e variables, one for each factored edge, and describes a new constraint graph G f . The key property of G' is that every relation has at most a links between values in it. Therefore, n f = n + e, e' = 2e, ri/<a. Thus, the size of G f is at most IG' I = #nodes + #links = n + XE* rij' < (n + e) + (2e x a) = 0(ea). Therefore, we arrive at the reduced upper bound 0(IG'l) = 0(ea). And, for a graph with bounded out-degree (e.g., a planar graph), 0(IG'l) = 0(na).

4, Applicable Situations
In applications of arc consistency, situations arise where • variable bindings are comprised of tuples, • the role of each tuple component is to provide information about a neighboring edge, and • the slot values constrain tuples to have equal components along neighboring edges. In these cases, factorization can construct a new graph G\ for which the cost of AC-5 is O(ea).

Waltz Scene Labelling
In scene labelling [17], each junction in a line drawing is a variable i with a set Aj of physically realizable edge labellings. Suppose junction i has h neighboring edges. A value in Ai is then an h-tuple of possible labels for these edges. The slot values belong the set {+,-,-»,<-}, denoting convex, concave, or boundary edge labels.
Slot values along neighboring edges are constrained to be equal. Therefore, as shown in Figure 4, we can factor a scene labelling problem's graph G into a new graph G\ in which 0(IG'l) = 0(ea). Since a line drawing is a two-dimensional projection, i.e., a planar graph, e is proportional to the number of variables n, and 0(IG , l) = 0(na).
This linear dependence of arc consistency on the number of candidate bindings a is a new result for the scene labelling problem.

RETE Match
The conjunctive matching of rules against working memory (WM) employed in production systems [18] is a CSP that computes all solutions. In fact, in languages such as OPS-5, it is a binary CSP [12]. The usual recursive construction of conjunctive match uses a backtrack control to filter inadmissible extensions of ktuples [13]. When this recursion is transformed into an incremental network program [11], the RETE match [3] algorithm results.
The key computation of RETE is incremental construction of the cartesian product IlNAi. Therefore, arc consistency can be of use: preliminary filtering of the Ai can reduce the cost of n-tuple formation. In RETE terminology, each variable i is called a condition element, and the Ai contain values called working memory elements (WMEs). The relations Rij are determined by binary join tests between variables. One can construct a CSP graph having one edge per binary join test.
A variable binding value (or WME) is itself a tuple. Each join test compares the slot-value of a tuple binding of variable i with a tuple's slot-value from variable j. Therefore, the Ry are factorable into Py x R°y x Qy T via equivalence classes of slotvalues, as in Section 3.1. (There are other optimizations for conjunctive match that exploit slot-value equivalence classes, such as hashed. RETE [16], copy and constrain [9], and MatchBox [14].) Interestingly, 90% of join tests are for equality [4]. If just these are used for arc consistency, then, by Section 3.2, the cost of AC-5 is reduced to O(ea). This is our improved linear bound, finding application to an important computation in AI: RETE match. Figure 5 shows the factoring of a rule's CSP.
(B) Ai Figure 5. A. A graphical rule specification, following [15]. There are three variables (condition elements), and two equality relations (join tests). B. The graph G of the associated CSP. The relations are incorporated into the edges. C. The graph G f after factoring the equality relations. The join tests now explicitly appear as CSP variables. The topology is identical to the specification shown in (A).

Conclusions
Arc consistency is an important and ubiquitous algorithm in AI, used to reduce the combinatorics of cartesian product formation. There has been steady improvement in arc consistency algorithms. Mohr and Henderson [8] presented an optimal algorithm for arc consistency AC-4, that has cost 0(ea 2 ), and only 0(na 2 ) for scene labelling applications. We improved this bound to a linear cost in a for factorable relations. Recently, an analogous improvement [2], also applicable to scene labelling, was developed for Constraint Logic Programming; the authors exploit functions as we do, but do not describe factorable relations.
In this paper, we motivated and presented a variant of AC-4, called AC-5, that made explicit the use of the relation links between variable binding values, thus forming the graph G. We showed when and how the relations Rij were factorable, transforming G into a new G\ With equality relations, IG' I < IGI, and the cost of scene labelling is reduced to O(na). This result extends to other applications, such as RETE match, for which we showed a factorization reducing the arc consistency cost from 0(ea 2 ) to O(ea).