How to convert a qualitative temporal CSP into a finite domain binary CSP André Trudel Jodrey School of Computer Science, Acadia University Wolf Ville, Nova Scotia, B4P 2R6, Canada Andre.Trudel@AcadiaU.ca Table 1: Allen’s interval relations Abstract We show how to convert a qualitative temporal CSP problem into an equivalent binary CSP problem. The main benefit is that binary CSP solution techniques can be applied to the equivalent problem. Once a solution is found, the transformations can be applied in reverse to generate a solution to the original qualitative CSP problem. 1 Introduction Allen [1984] defines a temporal reasoning approach based on intervals and the possible binary relations between them, which are shown in table 1. Each relation, except for equals, has an inverse for a total of 13 possible relations. The inverse symbol for b is bi and similarly for the others: mi, oi, di, si, and fi. Relation Sy mbol Exampl e X before b XXX X meets m YYY XXX o YYY XXXX Y Y X overlaps Y X during d X starts s Y Y X finishes Y X equals Y YYYY XXX YYYY YYY XXX YYYY YYY f = XXX YYYY YYY XXX YYY The relation between two intervals is allowed to be a disjunction of the basic relations, which is represented as a set. For example, (A m B) V (A o B) is written as A {m,o} B. The relation between two intervals is allowed to be any subset of I = {b,bi,m,mi,o,oi,d,di,s,si,f,fi,=} including I itself. It is interesting to note that Allen [1984] does not provide a semantics for the intervals. For example, he does not commit to intervals of the form (x,y) where x<y and the endpoints are from say the integers, rationals, or reals. An IA (interval algebra) network is a graph where each node represents an interval. Directed edges in the network are labeled with subsets of I. By convention, edges labeled with I are not shown. van Beek and Manchak [1996], and Nebel [1997] define an IA network to be consistent (or satisfiable) if each interval in the network can be mapped to a real interval such that all the constraints on the edges hold (i.e., one disjunct on each edge is true). We adopt Tsang’s [1993] binary CSP definition. A binary CSP of n variables x1,…,xn has a domain Di of possible values associated with each variable xi. Each Di is finite, and it may not necessarily be the case that all the domains are equal. A binary constraint, Rij, between variables xi and xj is a subset of the Cartesian product of their domains. Each Rij is finite. We also require that (a,b) Rij if and only if (b,a) Rji. An IA network is a binary CSP with infinite domains. The intervals are the variables. The domain of each variable is the set of pairs of reals of the form (x,y) where x<y. The constraint between two variables i and j is the label on the edge (i,j) in the IA network. During the past two decades, research on IA networks and binary CSPs has progressed relatively independently. The reason is that algorithms specifically designed for finite domains are usually not applicable to infinite domains. For example, van Beek and Manchak [1996] write that “two of their heuristics cannot be applied in our context as the heuristics assume a constraint satisfaction problem with finite domains, whereas IA networks are examples of constraint satisfaction problems with infinite domains”. Recently, Thornton et. al. [2003] show how to convert an IA network into an equivalent non-binary CSP with finite integer domains. We extend their work by presenting a conversion between IA networks and binary CSPs. Corollary 1: Each of the n intervals in an IA network can be mapped to an interval with integer end-points in the range 1…2n such that all the constraints on the edges hold if and only if its corresponding interval-CSP is consistent. 2 End-point ordering 4 From an interval-CSP to a standard integer binary CSP Thornton et. al. [2003] observe that the relative positions of the interval endpoints in an IA network can be used to determine consistency. For example, X=(10,15) and Y=(100.5,110) is a solution to X{b}Y. This solution imposes the ordering X- < X+ < Y- < Y+ on the endpoints where X= (X-,X+) and similarly for Y. A simpler solution is to number the endpoints from left to right which results in X=(1,2) and Y=(3,4). An IA network with two intervals is consistent if and only if each interval can be mapped to a pair of integers (a, b) where a<b, and a,b{1,2,3,4} such that the constraint on the edge holds. Note that it might be the case that endpoints from different intervals get mapped to the same integer (e.g., as in the case of X{=}Y). Thornton et. al. [2003] generalize the integer mapping to: We now convert an interval-CSP to a typical binary CSP with integer domains. To accomplish this, we lexicographically order each element in the domain of the interval-CSP and then associate an integer with each element based on its ordering. The constraints on the edges are then changed accordingly. The resulting CSP is called an integer-CSP. The integer-CSP associated with the interval-CSP in figure 1 is constructed as follows. We first order and number the elements of the domain as shown in table 2. Theorem 1: Each interval in an IA network with n intervals can be mapped to a real interval such that all the constraints on the edges hold if and only if each interval in the IA network can be mapped to an interval with integer end-points in the range 1…2n such that all the constraints on the edges hold. We then replace each interval in figure 1 with its corresponding ranking integer from table 2. The integerCSP is shown in figure 2. The constraints in the interval-CSP are translated as follows. The first tuple in the edge constraint in figure 1 is ((1,2), (2,3)). From table 2, (1,2) is mapped to 1 and (2,3) to 4. Thus, the first tuple in the edge constraint of the integer-CSP in figure 2 is (1,4). Similarly for the other tuples in the constraint. Note that each tuple in the constraint in figure 2 has its first element less than its second element (i.e., they have the syntax of an interval). This need not be the case in general. For example, the integer-CSP for X{bi}Y has {(6,1)} as its constraint. 3 From an IA network to a binary CSP Based on theorem 1, Thornton et. al. [2003] convert an IA network to a non-binary CSP with finite domains. Each endpoint becomes a variable with domain {1,…,2n}. A label on an edge (X,Y) in the IA network imposes a constraint on the variables X-, X+, Y-, and Y+. We use a different approach to convert an n interval IA network to a binary CSP. We call the resulting CSP an interval-CSP. In the interval-CSP, each interval X is a variable with domain {(X-, X+) | X-<X+, and X-, X+{1,…,2n}}. The constraint between variables X and Y is the set of pairs ((X-, X+), ( Y-, Y+)) that satisfy the label on the edge (X,Y) in the original IA network. For example, the interval-CSP associated with X {m} Y is given in figure 1. The domain for each variable is shown below its node. The edge is labeled with the set of tuples that satisfy the constraint. Based on the construction of the interval-CSP, we have: 1 2 3 4 5 6 (1,2) (1,3) (1,4) (2,3) (2,4) (3,4) Table 2: Lexicographic ordering of the domain In general, each variable domain in an n node integerCSP is the set {1,…,n(2n-1)}. The renaming of the domain does not affect consistency: Corollary 2: An interval-CSP is consistent if and only if its corresponding integer-CSP is consistent. From theorem 1 and corollaries 1 and 2 it follows that: Theorem 2: An IA network is consistent if and only if its corresponding integer-CSP is consistent. Since an integer-CSP is a standard binary CSP, any binary CSP algorithm can be used to solve the integerCSP. By then applying the above transformations in reverse, we can convert an integer-CSP solution to a solution for the original IA network. Therefore, an IA network can be solved using binary CSP techniques. X Y {((1,2),(2,3)), ((1,2),(2,4)), ((1,3),(3,4)), ((2,3),(3,4))} {(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)} {(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)} Figure 1: X{m}Y and its interval-CSP X Y {1,…,6} {(1,4), (1,5), (2,6), (4,6)} {1,…,6} Figure 2: The integer-CSP for X{m}Y 5 Example B {o} {m} {b,d} A C Figure 3: IA network An IA network is shown in figure 3. In the intervalCSP, each node has domain {(X-, X+) | X-<X+, and X-, X+{1,…,6}}. The constraints on the edges are: Edge (A,B): {((1,2),(2,3)), ((1,2),(2,4)), ((1,2),(2,5)), ((1,2),(2,6)), ((1,3),(3,4)), ((1,3),(3,5)), ((1,3),(3,6)), ((1,4),(4,5)), ((1,4),(4,6)), ((1,5),(5,6)), ((2,3),(3,4)), ((2,3),(3,5)), ((2,3),(3,6)), ((2,4),(4,5)), ((2,4),(4,6)), ((2,5),(5,6)), ((3,4),(4,5)), ((3,4),(4,6)), ((3,5),(5,6)), ((4,5),(5,6))} Edge (B,C): {((1,3),(2,4)), ((1,3),(2,5)), ((1,3),(2,6)), ((1,4),(2,5)), ((1,4),(2,6)), ((1,4),(3,5)), ((1,4),(3,6)), ((1,5),(2,6)), ((1,5),(3,6)), ((1,5),(4,6)), ((2,4),(3,5)), ((2,4),(3,6)), ((2,5),(3,6)), ((2,5),(4,6)), ((3,5),(4,6))} Edge (A,C): {((1,2),(3,4)), ((1,2),(3,5)), ((1,2),(3,6)), ((1,2),(4,5)), ((1,2),(4,6)), ((1,2),(5,6)), ((1,3),(4,5)), ((1,3),(4,6)), ((1,3),(5,6)), ((1,4),(5,6)), ((2,3),(4,5)), ((2,3),(4,6)), ((2,3),(5,6)), ((2,4),(5,6)), ((3,4),(5,6)), ((2,3),(1,4)), ((2,3),(1,5)), ((2,3),(1,6)), ((2,4),(1,5)), ((2,4),(1,6)), ((2,5),(1,6)), ((3,4),(1,5)), ((3,4),(1,6)), ((3,4),(2,5)), ((3,4),(2,6)), ((3,5),(1,6)), ((3,5),(2,6)), ((4,5),(1,6)), ((4,5),(2,6)), ((4,5),(3,6))} To construct the integer-CSP, we first order the domain as shown in Table 3. ( 1 ( 2 ( 3 ( 4 ( 5 ( 6 ( 7 ( 8 ( 9 1,2) 1,3) In the integer-CSP, each variable has the domain {1,…,15}. The constraints on the edges are: Edge (A,B): {(1,6), (1,7), (1,8), (1,9), (2,10), (2,11), (2,12), (3,13), (3,14), (4,15), (6,10), (6,11), (6,12), (7,13), (7,14), (8,15), (10,13), (10,14), (11,15), (13,15)} Edge (B,C): {(2,7), (2,8), (2,9), (3,8), (3,9), (3,11), (3,12), (4,9), (4,12), (4,14), (7,11), (7,12), (8,12), (8,14), (11,14)} Edge (A,C): {(1,10), (1,11), (1,12), (1,13), (1,14), (1,15), (2,13), (2,14), (2,15), (3,15), (6,13), (6,14), (6,15), (7,15), (10,15), (6,3), (6,4), (6,5), (7,4), (7,5), (8,5), (10,4), (10,5), (10,8), (10,9), (11,5), (11,9), (13,5), (13,9), (13,12)} Edge Integer-CSP (A,B) {(1,7)} (B,C) {(7,11)} (A,C) {(1,11)} IntervalCSP {((1,2),(2, 4))} {((2,4),(3, 5))} {((1,2),(3, 5))} IA Network {m} {o} {b} Table 4: Solution A solution to the integer-CSP is shown in the column labeled “Integer-CSP” in table 4. Applying the transformations in reverse, the corresponding interval-CSP solution is shown in the next column, and the IA network solution in the last column. 1,4) 1,5) 1,6) 2,3) 2,4) 2,5) 2,6) ( 3,4) 1 0 ( 3,5) 1 1 ( 3,6) 1 2 ( 4,5) 6 Conclusion In this paper, we showed how to convert an IA network into an equivalent binary CSP. Using standard binary CSP algorithms, we can find a solution which can then be converted back to a solution to the original IA network. Future empirical studies will investigate the relative performance of IA network and binary CSP algorithms on equivalent problems. The bottleneck in IA network path consistency algorithms is performing the composition operation between subsets of Allen’s relations. There may be a speedup by avoiding this particular bottleneck by performing arc and path consistency on the equivalent binary CSP. 1 3 ( 4,6) 1 Acknowledgements 4 ( 1 5,6) 5 Table 3: Lexicographic ordering of the tuples Research supported by an NSERC grant References [Allen, 1984] J.F. Allen. Towards a general model of action and time, Artificial Intelligence, 23(2), 1984, p. 123154. [Nebel, 1997] B. Nebel. Solving hard qualitative temporal reasoning problems: evaluating the efficiency of using the ORD-Horn class, Constraints, 1, 1997, p. 175-190. [Thornton et al., 2003] J. Thornton, M. Beaumont, A. Sattar, and M. Maher. A local search approach to modeling and solving interval algebra problems, to appear in The journal of logic and computation, 2003. [Tsang, 1993] E. Tsang. Foundations of constraint satisfaction, Academic Press, 1993. [van Beek and Manchak, 1996] P. van Beek and D.W. Manchak. The design and experimental analysis of algorithms for temporal reasoning, Journal of Artificial Intelligence Research, 4, 1996, p. 1-18.