Allen's Interval Algebra Makes the Difference
aa r X i v : . [ c s . A I] S e p Allen’s Interval Algebra Makes the Difference
Tomi Janhunen , − − − and Michael Sioutis − − − Department of Computer Science, Aalto University, Espoo, Finland Computing Sciences Unit, Tampere University, Tampere, Finland [email protected]
Abstract.
Allen’s Interval Algebra constitutes a framework for reason-ing about temporal information in a qualitative manner. In particular,it uses intervals, i.e., pairs of endpoints, on the timeline to represententities corresponding to actions, events, or tasks, and binary relationssuch as precedes and overlaps to encode the possible configurations be-tween those entities. Allen’s calculus has found its way in many aca-demic and industrial applications that involve, most commonly, plan-ning and scheduling, temporal databases, and healthcare. In this paper,we present a novel encoding of Interval Algebra using answer-set pro-gramming (ASP) extended by difference constraints, i.e., the fragmentabbreviated as ASP(DL), and demonstrate its performance via a prelim-inary experimental evaluation. Although our ASP encoding is presentedin the case of Allen’s calculus for the sake of clarity, we suggest thatanalogous encodings can be devised for other point-based calculi, too.
Keywords:
Answer Set Programming, Difference Constraints, Qualita-tive Constraints, Spatial and Temporal Reasoning, Symbolic AI
Qualitative Spatial and Temporal Reasoning (QSTR) is a Symbolic AI approachthat deals with the fundamental cognitive concepts of space and time in a qualita-tive, human-like, manner [10,20]. As an illustration, the first constraint languageto deal with time on a qualitative level was proposed by Allen in [1], called Inter-val Algebra. Allen wanted to define a framework for reasoning about time in thecontext of natural language processing that would be reliable and efficient enoughfor reasoning about temporal information in a qualitative manner. In particular,Interval Algebra uses intervals on the timeline to represent entities correspond-ing to actions, events, or tasks, and relations such as precedes and overlaps toencode the possible configurations between those entities. Interval Algebra hasbecome one of the most well-known qualitative constraint languages, due toits use for representing and reasoning about temporal information in variousapplications. More specifically, typical applications of Interval Algebra involveplanning and scheduling [2,3,9,26,29], natural language processing [8,33], tem-poral databases [7,32], multimedia databases [22], molecular biology [13] (e.g.,arrangement of DNA segments/intervals along a linear chain involves particulartemporal-like problems [4]), workflow [23], and healthcare [18,25,30].
T. Janhunen and M. Sioutis
Answer-set programming (ASP) is a declarative programming paradigm [6,17]designed for solving computationally hard search and optimization problemsfrom the first two levels of polynomial hierarchy. Typically, one encodes the so-lutions of a given problem as a logic program and then uses an answer-set solverfor their computation. The idea of representing Allen’s Interval Algebra in termsof rules is not new; existing encodings can be found in [5,19]. However, these en-codings do not scale well when the number of intervals is increased beyond 20 [5,Section 6]. The likely culprit for decreasing performance is the explicit represen-tation of compositions of base relations, which tends to cause cubic blow-upswhen instantiating the encoding for a particular problem instance. In this pa-per, we circumvent such negative effects by using an appropriate extension ofASP to encode the underlying constraints of Allen’s calculus. The crucial prim-itive is provided by difference logic (DL) [28] featuring difference constraints ofform x − y ≤ k . The respective fragment of ASP is known as ASP(DL) [16]and it has been efficiently implemented within the clingo solver family. Whenencoding Allen’s calculus in ASP(DL), the transitive effects of relation composi-tion can be delegated to propagators implementing difference constraints. Hence,no blow-ups result when instantiating the ASP rules for a particular constraintnetwork and the resulting ground logic program remains linear in network size.The rest of this article is organized as follows. The basic notions of qualitativeconstraint networks ( QCN s) and, in particular, Allen’s Interval Algebra are firstrecalled in Section 2. Then, difference constrains are introduced in Section 3 andwe also show how they are available in ASP, i.e., the fragment abbreviated asASP(DL). The actual encodings of
QCN s in ASP(DL) are presented in Section 4.The preliminary experimental evaluation of the resulting encodings takes place inSection 5. Finally, we present our conclusions and future directions in Section 6.
A binary qualitative constraint language is based on a finite set B of jointlyexhaustive and pairwise disjoint relations, called the set of base relations [21],that is defined over an infinite domain D . These base relations represent definiteknowledge between two entities with respect to the level of granularity providedby the domain D ; indefinite knowledge can be specified by a union of possible baserelations, and is represented by the set containing them. The set B contains theidentity relation Id , and is closed under the converse operation ( − ). The total setof relations 2 B is equipped with the usual set-theoretic operations of union andintersection, the converse operation, and the weak composition operation denotedby ⋄ [21]. For all r ∈ B , r − = S { b − | b ∈ r } . The weak composition ( ⋄ ) oftwo base relations b, b ′ ∈ B is defined as the smallest (i.e., strongest) relation r ∈ B that includes b ◦ b ′ , or, formally, b ⋄ b ′ = { b ′′ ∈ B | b ′′ ∩ ( b ◦ b ′ ) = ∅} , where b ◦ b ′ = { ( x, y ) ∈ D × D | ∃ z ∈ D such that ( x, z ) ∈ b ∧ ( z, y ) ∈ b ′ } is the (true)composition of b and b ′ . For all r, r ′ ∈ B , r ⋄ r ′ = S { b ⋄ b ′ | b ∈ r, b ′ ∈ r ′ } .As an illustration, consider the well-known qualitative temporal constraintlanguage of Interval Algebra ( IA ), introduced by Allen in [1]. The domain D llen’s Interval Algebra Makes the Difference 3 x x x x { p, m } B { d, s, fi } { oi }{ oi, m }{ pi, e } (a) A satisfiable QCN N x x x x (b) A solution σ of N Fig. 1: Examples of
QCN terminology using Interval Algebra; symbols p , e , m , o , d , s ,and f correspond to the base relations precedes , equals , meets , overlaps , during , starts ,and finishes respectively, with · i denoting the converse of · (note that ei = e ) of Interval Algebra is defined to be the set of intervals on the line of rationalnumbers, i.e., D = { x = ( x − , x + ) ∈ Q × Q | x − < x + } . Each base relation can bedefined by appropriately constraining the endpoints of the two intervals at hand,which yields a total of 13 base relations comprising the set B = { e , p , pi , m , mi , o , oi , s , si , d , di , f , f i } ; these symbols are explained in the caption of Figure 1.For example, d is defined as d = { ( x, y ) ∈ D × D | x − > y − and x + < y + } . Theidentity relation Id of Interval Algebra is e and its converse is again e . Definition 1. A qualitative constraint network ( QCN ) is a tuple ( V, C ) where: – V = { v , . . . , v n } is a non-empty finite set of variables, each representingan entity of an infinite domain D ; – and C is a mapping C : V × V → B such that C ( v, v ) = { Id } for all v ∈ V and C ( v, v ′ ) = ( C ( v ′ , v )) − for all v, v ′ ∈ V . An example of a
QCN of IA is shown in Figure 1a; for clarity, neither converserelations nor Id loops are mentioned or shown in the figure.Given a QCN N = ( V, C ), a solution of N is a mapping σ : V → D such that ∀ ( u, v ) ∈ V × V , ∃ b ∈ C ( u, v ) so that ( σ ( u ) , σ ( v )) ∈ b (see Figure 1b). We assume that the reader is already familiar with the basics of ASP (cf. [6,17])and merely concentrate on extending ASP in terms of difference constraints .Such a constraint is an expression of the form x − y ≤ k where x and y arevariables and k is a constant. Intuitively, the difference of x and y should beless than or equal to k . Potential domains for x and y are integers and reals,for instance. The domain is usually determined by the application and, for thepurposes of this paper, the set of integers is assumed in the sequel. The givenform of difference constraints can be taken as a normal form for such constraints.However, with a little bit of elaboration some other and very natural constraintsconcerning x and y become expressible. While x ≤ y is equivalent to x − y ≤ x < y translates into x − y ≤ −
1. To state the equality x = y ,two difference constraints emerge, since x = y ⇐⇒ x − y ≤ y − x ≤ T. Janhunen and M. Sioutis
Difference constraints can be implemented very efficiently, since they enablea linear-time check for unsatisfiability. Given a set S of such constraints, one canuse the Bellman-Ford algorithm to check if S has a loop of variables x , . . . , x n where x n = x along with difference constraints x − x ≤ d , . . . , x n − x n − ≤ d n − such that P n − i =1 d i <
0. When carrying out the check for satisfiability, itis not necessary to find concrete values for the variables in S . This is in perfectline with the idea of reasoning about QCN s on a qualitative, symbolic, level.
Example 1.
The set of difference constraints S = { y − x ≤ , z − y ≤ , x − z ≤− } is unsatisfiable, since 1 + 1 − <
0. However, if the second differenceconstraint is revised to z − y ≤
2, the resulting set of difference constraints S is satisfiable, as witnessed by an assignment with x = 0, y = 1, and z = 3. (cid:4) More formally, an assignment τ is a mapping from variables to integers anda difference constraint x − y ≤ k is satisfied by τ , denoted τ | = x − y ≤ k , if τ ( x ) − τ ( y ) ≤ k . Also, we write τ | = S for a set of difference constraints S , if τ | = x − y ≤ k for every constraint x − y ≤ k in S . If τ | = S , we also say that S is satisfiable and that τ is a solution to S . Moreover, it is worth pointing outthat if τ | = S then also τ ′ | = S where τ ′ ( x ) = τ ( x ) + k for some integer k . Thus S has infinitely many solutions if it has at least one solution. If S is satisfiable,it is easy to compute one concrete solution by using a particular variable z as apoint of reference via the intuitive assignment τ ( z ) = 0. Difference logic (DL) extends classical propositional logic in the satisfiabilitymodulo theories (SMT) framework [28]. A propositional formula φ in DL isformed in terms of usual atomic propositions a and difference constraints x − y ≤ k . A model of φ is a pair h ν, τ i such that (i) ν, τ | = a iff ν ( a ) = ⊤ , (ii) ν, τ | = x − y ≤ k iff τ | = x − y ≤ k , and (iii) ν, τ | = φ by the recursive rulesof propositional logic. Difference logic lends itself for applications where integervariables are needed in addition to Boolean ones. Thus, it serves as a potentialtarget formalism when it comes to implementing ASP via translations [14,15].The rule-based language of ASP can be generalized in an analogous way byusing difference constraints as additional conditions in rules. The required theoryextension of the clingo solver is documented in [12]. For instance, a differenceconstraint x − y ≤ &diff { x-y } <= 5 where x and y areconstants in the syntax of ASP but understood as integer variables of differencelogic. However, using such fixed names for variables is often too restrictive fromapplication perspective. It is possible to use function symbols to introduce collec-tions of integer variables for a particular application. For instance, if the arcs ofa digraph are represented by the predicate arc/2 , we could introduce a variable w(X,Y) for the weight for each pair of first-order variables X and Y satisfying arc(X,Y) . Recall that free variables in rules are universally quantified in ASP.More details about the theory extension corresponding to difference logic can befound in [16] whereas its implementation is known as the clingo-dl solver. This distinguished variable z can be used as a name for 0 in other differenceconstraints. Then, e.g., x − z ≤ k and z − x ≤ − k express together that x = k . https://potassco.org/labs/clingodl/llen’s Interval Algebra Makes the Difference 5Listing 1.1: Choice of Base Relations1 % Domains var (X) :- brel (X ,Y ,R) . var (Y) :- brel (X ,Y ,R) . arc (X ,Y) :- brel (X ,Y , R). % Intervals for every variable X: sp (X) <= ep (X) & diff { sp (X) -ep (X) } <= 0 :- var (X) . % Choose base relations { chosen (X ,Y ,R): brel (X ,Y ,R) } = 1 :- arc (X ,Y). Listing 1.2: Difference Constraints Expressing Base Relations1 % Relation eq (X ,Y): sp (X) = sp (Y) and ep (X) = ep ( Y) & diff { sp (X) -sp (Y) } <= 0 :- chosen (X ,Y , eq ). & diff { sp (Y) -sp (X) } <= 0 :- chosen (X ,Y , eq ). & diff { ep (X) -ep (Y) } <= 0 :- chosen (X ,Y , eq ). & diff { ep (Y) -ep (X) } <= 0 :- chosen (X ,Y , eq ). % Relation during (X ,Y ): sp (Y) < sp ( X) and ep (X) < ep (Y) & diff { sp (Y) -sp (X) } <= -1 :- chosen (X ,Y ,d). & diff { ep (X) -ep (Y) } <= -1 :- chosen (X ,Y ,d). In what follows, we present our novel encoding of temporal networks using ASPextended by difference constraints. To encode base relations from B in a system-atic fashion, we introduce constants eq , p , pi , m , mi , o , oi , s , si , d , di , f , and fi as names for the base relations (see again Section 2). The structure of networksthemselves is described in terms of predicate brel/3 whose first two argumentsare variables from the network and the third argument is one possible base rela-tion for the pair of variables in question. Then, for instance, the base relationsassociated with variables x and x in Figure 1a could be encoded in terms offacts brel(1,2,p) and brel(1,2,m) . Given any such collection of facts, somebasic inferences are made using the ASP rules in Listing 1.1. First, the rulesin lines 2–3 extract the identities of variables for later reference. Secondly, therule in line 4 defines the arc relation for the underlying digraph of the network.Given these pieces of information, we are ready to formalize the solutions of thetemporal network. For each interval X , we introduce integer variables sp(X) and ep(X) to capture the respective starting and ending points of the interval. Therelative order of theses points is then determined using the difference constraintexpressed by the rule in line 7. Interestingly, there is no need to constrain thedomain of time points otherwise, e.g., by specifying lower and upper bounds;arbitrary integer values are assumed. In addition, the choice rule in line 10 picksexactly one base relation for each arc of the constraint network. T. Janhunen and M. Sioutis
Fig. 2: Runtime scaling: checking satisfiability vs computing intersection of solutions d Table 1: Median runtimes for IA instances with 100 variables
The satisfaction of the chosen base relations is enforced by further differenceconstraints, which are going to be detailed next. Rather than covering all 13, wepicked two representatives for more detailed discussion (see Listing 1.2). In caseof equality, the starting and ending points of intervals X and Y must coincide.The difference constraints introduced in lines 2–3, whenever activated by thesatisfaction of chosen(X,Y,eq) , enforce the equality of the starting points andthose of lines 4–5 cover the respective ending points. The case of the during relation is simpler since the relationships of starting/ending points are strict andonly two rules are needed for a pair of intervals X and Y . The rule in line 8 ordersthe starting points. The rule in line 9 puts the ending points in the oppositeorder. The encodings for the remaining base relations are obtained similarly. We generated
QCN instances using model A ( n = 100 , ≤ d ≤ , s = 6 .
5) [27],where n denotes the number of variables, d the average degree, and s the av-erage size (number of base relations) of a constraint of a given instance. Foreach d ∈ { , . . . , } , we report runtimes based on 10 random instances becausethe runtime distribution is heavy tailed , i.e., the severity of outliers encounteredincreases along the number of instances generated. As a consequence, the max-imum and average runtimes tend to infinity as can be seen from the plots inFigure 2. The graphs have been smoothened using gnuplot ’s option bezier .The graph on the left shows the runtime scaling for checking the existence of asolution, and the graph on the right concerns the computation of the intersectionof solutions, which amounts to the identification of backbones for QCN s [31].The clingo-dl solver supports the computation of the intersection as one of llen’s Interval Algebra Makes the Difference 7
Fig. 3: Runtime scaling (median): computing intersection of solutions vs computingunion of solutions its command-line options. It is also worth noting a phase transition aroundthe value d = 14 where instances turn from satisfiable to unsatisfiable, whichaffects the complexity of reasoning. Moreover, due to outliers, it is perhaps moreinformative to check the median runtimes as given in Table 1. It is clear thatintersection of solutions computation is more demanding, but the difference is nottremendous. Moreover, to contrast the performance of our encoding with respectto [5], we note that only 10% of 190 instances exceeded the timeout of 300 seconds(this same timeout was used in that work). In addition, the experiments of [5]covered instances from 20 to 50 variables only and the encodings were alreadyperforming poorly by the time 50 variables were considered. On the other hand,our encoding still underperforms with respect to native QSTR tools and, atleast as far as satisfiability checking is concerned, the state-of-the-art qualitativereasoner gqr [11] tackles each of the 190 instances in a few seconds on average.To the best of our knowledge, there is no native QSTR tool for calculatingintersection of solutions and in this way the advanced reasoning modes of the clingo-dl solver enable new kinds of inference and for free, since the sameencoding can be used and no further implementation work is incurred.Our second experiment studies the scalability of our ASP(DL) encoding whenthe number of variables is gradually increased from 50 to 90. The results areillustrated in Figure 3. The plots on the left illustrate the scaling of the backbonecomputation, i.e., the intersection of solutions. It turned out that this kind ofreasoning is easier than computing the union of solutions, also known as the minimum labeling problem [24], as depicted by the graphs on the right. Therandom instances used so far are relatively easy, and for that reason we takeinto consideration a modified scheme H ( n, ≤ d ≤
20) [27] that yields muchharder network instances. The difference with respect to model A used aboveis that constraints are picked from a set of relations expressible in 3- CNF whentransformed into first-order formulae. As a consequence, we are only able toanalyze instances up to n = 50 variables in reasonable time. Table 2 showsthe performance difference when computing the intersection and the union ofsolutions. In most cases, the intersection of solutions can be computed faster. T. Janhunen and M. Sioutis
Although d = 15 is kind of an exception, its significance is diminished by the mostdemanding instances encountered: 8 477 vs 24 199 seconds spent on computingthe intersection and the union, respectively. d Union 25.6 46.9 105.5 298.5 7226.3 5636.5
In this paper, we encoded qualitative constraint networks (
QCN s) based onAllen’s Interval Algebra in ASP(DL), which is an extension of answer set pro-gramming (ASP) by difference constraints. Due to native implementation of suchconstraints as propagators in the clingo-dl solver, the transitive effects of rela-tion composition are avoided when it comes to the space complexity of represent-ing
QCN instances. This contrasts with existing encodings in pure ASP [19,5]and favors computational performance, which rises to a new level due to ourASP(DL) encoding. As regards other positive signs, it seems that the presentedencoding scales for other reasoning modes as well. Since ASP encodings arehighly elaboration tolerant, we expect that it is relatively easy to modify andextend our basic encodings for other reasoning tasks as well. As regards futurework, we aim to investigate more thoroughly the performance characteristics ofour ASP(DL) encoding, and to use it for establishing collaborative frameworksamong ASP-based and native QSTR tools.
References
1. Allen, J.F.: Maintaining Knowledge about Temporal Intervals. Commun. ACM ,832–843 (1983)2. Allen, J.F.: Planning as Temporal Reasoning. In: KR (1991)3. Allen, J.F., Koomen, J.A.G.M.: Planning Using a Temporal World Model. In:IJCAI (1983)4. Benzer, S.: On the Topology of the Genetic Fine Structure. Proc. Natl. Acad. Sci.USA , 1607–1620 (1959)5. Brenton, C., Faber, W., Batsakis, S.: Answer Set Programming for QualitativeSpatio-Temporal Reasoning: Methods and Experiments. In: ICLP (Technical Com-munications) (2016)6. Brewka, G., Eiter, T., Truszczynski, M.: Answer set programming at a glance.Commun. ACM , 92–103 (2011)7. Chen, C.X., Zaniolo, C.: Universal Temporal Data Languages. In: DDLP (1998)8. Denis, P., Muller, P.: Predicting Globally-Coherent Temporal Structures fromTexts via Endpoint Inference and Graph Decomposition. In: IJCAI (2011)9. Dorn, J.: Dependable Reactive Event-Oriented Planning. Data Knowl. Eng. ,27–49 (1995)llen’s Interval Algebra Makes the Difference 910. Dylla, F., Lee, J.H., Mossakowski, T., Schneider, T., van Delden, A., van de Ven,J., Wolter, D.: A Survey of Qualitative Spatial and Temporal Calculi: Algebraicand Computational Properties. ACM Comput. Surv. , 7:1–7:39 (2017)11. Gantner, Z., Westphal, M., W¨olfl, S.: GQR-A Fast Reasoner for Binary QualitativeConstraint Calculi. In: AAAI Workshop on Spatial and Temporal Reasoning (2008)12. Gebser, M., Kaminski, R., Kaufmann, B., Ostrowski, M., Schaub, T., Wanko, P.:Theory Solving Made Easy with Clingo 5. In: ICLP (Technical Communications)(2016)13. Golumbic, M.C., Shamir, R.: Complexity and Algorithms for Reasoning aboutTime: A Graph-Theoretic Approach. J. ACM , 1108–1133 (1993)14. Janhunen, T.: Cross-translating answer set programs using the ASPTOOLS col-lection. K¨unstliche Intelligenz , 183–184 (2018)15. Janhunen, T., Niemel¨a, I., Sevalnev, M.: Computing Stable Models via Reductionsto Difference Logic. In: LPNMR (2009)16. Janhunen, T., Kaminski, R., Ostrowski, M., Schellhorn, S., Wanko, P., Schaub, T.:Clingo goes linear constraints over reals and integers. TPLP , 872–888 (2017)17. Janhunen, T., Niemel¨a, I.: The Answer Set Programming Paradigm. AI Magazine , 13–24 (2016)18. Kostakis, O., Papapetrou, P.: On searching and indexing sequences of temporalintervals. Data Min. Knowl. Discov. , 809–850 (2017)19. Li, J.J.: Qualitative Spatial and Temporal Reasoning with Answer Set Program-ming. In: ICTAI (2012)20. Ligozat, G.: Qualitative Spatial and Temporal Reasoning. Wiley (2013)21. Ligozat, G., Renz, J.: What Is a Qualitative Calculus? A General Framework. In:PRICAI (2004)22. Little, T.D.C., Ghafoor, A.: Interval-Based Conceptual Models for Time-Dependent Multimedia Data. IEEE Trans. Knowl. Data Eng. , 551–563 (1993)23. Lu, R., Sadiq, S.W., Padmanabhan, V., Governatori, G.: Using a temporal con-straint network for business process execution. In: ADC (2006)24. Montanari, U.: Networks of constraints: Fundamental properties and applicationsto picture processing. Inf. Sci. (1974)25. Moskovitch, R., Shahar, Y.: Classification of multivariate time series via temporalabstraction and time intervals mining. Knowl. Inf. Syst. , 35–74 (2015)26. Mudrov´a, L., Hawes, N.: Task scheduling for mobile robots using interval algebra.In: ICRA (2015)27. Nebel, B.: Solving Hard Qualitative Temporal Reasoning Problems: Evaluating theEfficiency of Using the ORD-Horn Class. Constraints , 175–190 (1997)28. Nieuwenhuis, R., Oliveras, A.: DPLL(T) with Exhaustive Theory Propagation andIts Application to Difference Logic. In: CAV (2005)29. Pelavin, R.N., Allen, J.F.: A Model for Concurrent Actions Having Temporal Ex-tent. In: AAAI (1987)30. Sioutis, M., Alirezaie, M., Renoux, J., Loutfi, A.: Towards a Synergy of QualitativeSpatio-Temporal Reasoning and Smart Environments for Assisting the Elderly atHome. In: IJCAI Workshop on Qualitative Reasoning (2017)31. Sioutis, M., Janhunen, T.: Towards Leveraging Backdoors in Qualitative Con-straint Networks. In: KI (2019), to appear32. Snodgrass, R.T.: The Temporal Query Language TQuel. ACM Trans. DatabaseSyst.12