From: AAAI Technical Report WS-02-17. Compilation copyright © 2002, AAAI (www.aaai.org). All rights reserved. Direct Conversions among Multi-Granularity Temporal Constraints Claudio Bettini and Simone Ruffini DSI - Università di Milano, Milan, Italy bettini@dsi.unimi.it s.ruffini@infinito.it Abstract Temporal constraints are part of the specification of many complex application frameworks including planning, scheduling, real-time systems, workflow and cooperative systems. This paper investigates the problem of converting among quantitative temporal constraints expressed in terms of different time granularities. An expressive formal model for time granularities is assumed including common granularities like hours and days as well as user-defined granularities like business-days and academic semesters. Keywords: temporal constraints, time granularity, temporal abstraction. Introduction Temporal constraints are part of the specification of many complex application frameworks including activities to be scheduled, real-time components, temporal data management, and workflow management. Integrated e-commerce applications are an example of such frameworks where an advanced and efficient management of temporal aspects may be a significant advantage over the competition. In these complex systems the temporal relationships between events and activities involving different components are often described in terms of different time units. For example, the time between the receipt of an online order and the forwarding of item orders to the warehouses is described in minutes, while the time between the shipment of the order and the delivery is described in business-days. This paper considers a formalization of the notion of temporal constraint with granularity and investigates the problem of converting constraints in terms of different granularities. This may be desirable for at least two reasons: a) there are well-known algorithms to process temporal constraint networks where all the constraints are in terms of the same granularity (DMP91), and b) it may be useful for the sake of application process monitoring to view all the constraints in terms of a particular granularity. It will be immediately clear to the reader that the conversion problem is not a trivial one, even if we only consider common granularities like hours and days. For example, by saying that one event should occur the next day with respect to another one, we do not mean that the event should occur 24 hours after the other. Nor it is satisfactory to allow a range between 1 and 47 hours, as it may be suggested. Indeed 1 and 47 hours are actually the minimum and maximum distance between the occurrence of two events if they occur in consecutive days. However, a distance of 47 hours may also be the distance between two events whose occurrence is 2 days apart. This example actually says that an exact conversion does not exist, i.e., the constraint we obtain is not equivalent to the one we take as input. Hence, our goal is, given a constraint in terms of a source granularity , and given a target granularity , to identify which is the tightest among the constraint in terms of those implied by the input constraint or a good approximation of it. Being the tightest means that the set of distances allowed by the constraint is contained by any other logically represents the constraint imimpled constraint. If posing a distance of at least and at most time units of , hour is the tightest among then in the above example day. Inthe constraints in terms of hour implied by hour are logdeed, other constraints, as for example, day, but none of them can exclude ically implied by distances between and . The concept of granularity as an abstraction tool has been deeply investigated in the AI and DB literature probably starting from (Hob85). The formalization of time granularity as adopted in this paper has been defined in (BWJ98) and used in several papers on the subject. Interesting recent work on this topic can also be found in (MPP99; GL+01; BWJ02). Symbolic formalisms to represent time granularities have been proposed among others in (LMF86; CSS94). The complex mathematical relations among granularities and calendars have been studied also in (DR90). There are few approaches considering temporal constraints in terms of different granularities (e.g., (Dea89; GL+01)), but in most cases they are restricted to common granularities. Our goal is to admit powerful constraints and very general user-defined granularities both to accurately model the new application domains and to select appropriate abstraction levels. A first comprehensive solution to this problem has been given in (BWJ98) proposing two alternative algorithms for constraint conversion. The main contribution of this paper with respect to (BWJ98) is the construction of a set of formulas based on granularity relationships enabling an efficient implementation of the direct conversion algorithm for a significant set of periodical granularities. As a secondary contribution, we fix a bug in the original algorithm proposed in (BWJ98) for the case of the constraint minimum distance equal to zero. A prototype system has been developed at the University of Milan and used for extensive testing. The results of this paper can be applied in several application areas where multi-granularity temporal constraints have been shown to be useful: data mining (BW+98), workflow management (BWJ02), and clinical data management (CC99) among others. The rest of the paper is organized as follows. In the next section we introduce the formal notions of granularity and temporal constraints with granularities. In Section we illustrate a general algorithm for granularity conversion, while in Section we show how the algorithm can be implemented exploiting the periodicity of granularities. In Section we give an example of constraint network conversion, and Section concludes the paper. For lack of space, proofs are omitted, but can be found in (BR02). Temporal Constraint Networks with Granularities We first define a granularity system, called (General Granularities on Reals) in (BWJ98), as the set of granularities satisfying the following definition. set of the Definition. A granularity is a mapping from the of reals) such that integers to (i.e., all subsets for each non-positive integer , and for all positive integers , the following two conditions are satisfied: and with and imply thateach real number in is less than all real numbers in , and implies . This is a very general notion of granularity modeling standard ones like hour, day, week and month as well as more specific ones like academic semester, b-day (business day), or b-week (business week), and arbitrarily user-defined granularities. For example, b-week may be defined by the mapping of each positive integer (index) to a set of elements of the temporal domain denoting the period from a Monday through the next Friday every week. Each set of these sets of elements is called a granule of the granularity. If we decide to model time starting from Monday 2001/1/1, then the index is mapped to the instants denoting the period from 2001/1/1 through 2001/1/5, forming the first granule b-week(1), the index is mapped to b-week(2), denoting 2001/1/8 through 2001/1/12, and so on. In order to have finite representations of the granularities suitable to be automatically manipulated, we further restrict the granularities to those whose granules can be defined as a periodical pattern with respect to the granules of a fixed bottom granularity. For this purpose we first need to introduce a granularity relationship. Definition. A granularity groups periodically into a granularity if , there exists a (possi1. for each non-empty granule of positive integers such that bly infinite) set , and 2. there exist ! #"%$&(' , where ! is less than the number of granules of , such that for all $) +, .- / 43 (5 +43 &*' , if # / 2 0 1 and then ! ! - / 3 /6071 " . is the union of Condition 1 says that any granule ; for instance, assume some granules of +8:9; +8=<> A8 - it is the union @?;?;? . The periodicity of the granules property (condition 2) Densures 3 EF that if the !B+C granule after +8G9Hexists 3 (i.e., +8=<(3 ! +8 - ), 3 then it is the union of " " ;?@?;? " . This results in a periodic “pattern” of the composition of ! granules of in terms of granules of . The pattern repeats along the time domain by “shifting” each granule of by " granules of . The integer " is called the period. Many common granularities are in this kind of relationship, for example, both days and months group periodically into years. In general, this relationship guarantees that granularity can be finitely described providing the specification of granules of in terms of granules of in an arbitrary period and the period value. For example, b-week can be described by the five business days in the first week of the time domain, and by the value for the period. A granularity 1 is called bottom granularity if 1 groups periodically into each other granularity in the system. We can now define a temporal constraint with granularity. 3 I$J&LKNM OQP PSR with FT and Definition. Let a granularity. Then , called a temporal constraint with granularity (TCG), is the binary relation on 9 positive < integers 96W>X U and<YW>U X , 9 <@ defined as follows: For positive integers U #U satisfies if and only <YW>X if (1) 96V W\U XD and V U V U O[V U T . are both defined, and (2) ZT WX function The V^] returns the index of the granule of that includes 1 ] , where 1 is the bottom In< 9 granularity. satisfies the tuitively, to check if a pair of instants U _U TCG 9 , we < derive the indexes of the granules of containing U and U , respectively, and then we take the difference. If it is at least and at most , then the pair of instants 9 < For example, the pair 9 <@ is said to satisfy the constraint. U #U satisfies 9 >`<@b adc if U and U are within 9 the same < if U and U are day. Similarly, U _U satisfies eO ;f:gdhbi at most 9 one< hour apart (and their order < is immaterial). FiY k j d g b l 4 m f if U is in the next month nally, U _U satisfies 9 with respect to U . Definition. A constraint network An (with n granularities) is a directed graph nw6vL o 6n p #qsr , where is a finite set of a set of arcs, p is a mapping from variables, out o to the finite sets of temporal constraints with granularin is a mapping from to a possibly bounded ties, and qsr periodical set of positive integers. A set of positive integers is said to be periodical if there exists a granularity such that thebottom x yW>X granularity periis defined R . The odically groups into and M V set is bounded if an integer z is given such that each value in the set must be less than z . Intuitively, a constraint network specifies n a complex temrepresents a poral relationship where each variable in specific instant (for example the occurrence time of an event) X1 [0,0]b-day [2,2]b-week [-1,1]b-day X0 X X3 [0,0]day [0,0]b-day [0,3]day [1,6]b-day X2 Z Figure 1: A constraint network with granularities Figure 2: A network to illustrate conversion conditions in terms of the bottom granularity. The domain of each variable is essentially a set of granules of the bottom granularity, represented through the positive integers corresponding to the granule indexes. The set of TCGs assigned to an edge is taken as conjunction. That is, for each TCG in the set as, the instants assigned to and signed to the edge must satisfy the TCG. Fig. 1 shows an example of a constraint network withN granularities , with no explicit constraint on domains (q r P for each variable ). Conversion of Constraints in Different Granularities As we have pointed out in the introduction, in general, given a TCG, it does not exists an equivalent one in terms of a different granularity. 9 However, we9 are interested in convertinto a logically implied ing a< given TCG in < terms of . Note that a TCG o logically imTCG in terms of plies a TCG if any pair of time instants satisfying o also satisfy . Among all the logically implied TCGs we prefer the tightest or a good approximation of it. For example, and @f:ghbi are logically implied by both@fGgdhbi \`ba c , with the first being preferable since, in this case it is the tightest, and, indeed, it provides a more precise conversion of the original one. If we only have a total order of granularities with uniform granules, like e.g., minute, hour, and day, then the conversion algorithm is trivial since fixed conversion factors can be used. However, if incomparable granularities like week and month, or granularities with non-contiguous granules like b-day and b-week are considered, the conversion becomes more9 complex. Moreover, given an arbitrary TCG , and a granularity < , it is not always possible to find a logically implied TCG in terms of . For example, \`ba c does not logically - `=a c no matter what and are. The reason imply is that ^`=a c is satisfied by any two events that happen during the same day, whether the day is a business day or a weekend day. Y Allowed conversions In our framework, we allow the conversion of a TCG of a constraint network into another TCG if the resulting constraint is implied by the set of all the TCGs in . More on arc in a network is specifically, a TCG as long as allowed to be converted into is implied by , i.e., for any pair of values U and U assatisfies signed to and respectively, if U _U also and U and U belong to a solution of , then U _U . To guarantee that only allowed conversatisfies sions are performed, we assign to each variable of a constraint network, a periodical set which is the intersection of the domain of and all the periodical sets defined by the granularities appearing in TCGs involving . Then, a TCG on variables and can be converted in terms of a target is contained in a granularity if each element in JK granule of . It is easily seen that this condition guarantees the existence of an allowed conversion; indeed any pair of and respectively which values U and U assigned to (we only excluded is part of a solution must be in NK values which could not satisfy TCGs), and if both values are contained in granules of , their distance in terms of can be evaluated. Example 1 Consider the constraint network in Fig. 2. Both and are b-day. Hence, the constraint \`ba c can be converted in terms of b-day since the target granularity b-day covers a span of time equal to that covered by and . Similarly, consider the network in Fig. 1. The TCG in terms of day cannot be converted in terms of bday or b-week without considering the other constraints in the network. However, both and evaluate to the granularity obtained from day by dropping all granules that are not a business day. Since both b-day and b-week cover the same span of time as this granularity, the constraint \`ba c can be converted in terms of b-day and - , respecb-week, obtaining -`ba c and tively. The conversion algorithm In Fig. 3 we propose a general ! conversion y 8 method. # A It is based on the #functions < U and ]" U . Intu 9 denotes the< minimal distance itively, U (in terms of the number of granules of ) between all pairs 9 and of instants in a granule of in# the th granule after it, respectively. For example, U -$% 6`=a c , i.e., the minimum distance in terms of days between two events that occur in two different business weeks is 3 (one instant on Friday and the other on Monday). The definition restricts the considered pairs of instants to those in which the first instant is included in and the second in . Indeed, only these & pairs are candidate solutions for the constraint on , and this restriction improves the precision the arc of the conversion some inconsistencies. 9 as it< detects 8 #as well ]' U is the corresponding maxiThe value 9 3 $S&Q'sW>K X M PSR , . V^U INPUT: a network with a TCG , with < %$S&JK M4OQP R and ; a target granularity , s.t. U UD$ associated with an arc K < for or undefined. OUTPUT: a logically implied TCG METHOD: OQP then OQ#P 9 Step 1 if < else if then 8 # 9 x x U < else O 3 ]' U 3 5 Step 2 if < P 8 P # then 9 else ]" U Step 3 if either or < is undefined, then return undefined else return where U 9 < < W>,X M V U 8 9 ] U <\< ,W\X ! M V^U L q r ' # # 9 W> X O ^V U 8] O[V U 9 @?;?;? granularities in the TCGs of , undefined otherwise, < W\X where 9 W\ < X O V^U R; U $ _U $ , and V U , undefined otherwise, < W>X where O[V U 9 W>X T R ; 9 W\! X ifx ! 9 < U $ #U $ , and V^U 9 if ;?@?;? - are the periodical sets corresponding to the ifx 9 involving node . (Similarly for .) Figure 3: A general method for the conversion of constraints 8 # mum distance. 8 # For example, ]' U -$% 6`=a c ]" U (b-day, 1,day)= 3. , and The values of these functions cannot be automatically obtained for general (infinite) granularities, however, they can be computed efficiently when the involved granularities are periodic, cases. The computation of # Aas in most 8 practical # A U and ]' U is more involved when we want to9 check the condition, appearing in their specification, i.e., < U $ and U $ . Note that omitting this check leads to a still sound but less precise conversion. The other condition involving and appears in the input description. This cannot be ignored since it guarantees an allowed conversion. 3 $ &(' if P for the inThe method imposes put constraint. This is not a limitation since any constraint eO ;O on with can be expressed as L on . When only the lower bound is negative, it is sufficient to consider its absolute value and treat it exactly as the upper bound except for reversing the sign of the result. For example, for O % we derive the upper bound for day according to the method. Since the absoeO \`ba c as the implied lute value for O is , we derive must be treated exactly as for constraint. The case of negative values. 3 When OQP and/or P the conversion method simply keeps these constants also for the TCG in the target granularity. It is easily seen that .9 this always is bounded, leads to an implied TCG. However, when more precisely into fithe P constants may be converted 3 P j gdlbm f - , where nite values. For example, month-b2000 denotes the months3 before year 2000, is 3 P \c =a i , while P in this last TCG converted into may be safely substituted with the number of years from the beginning of the time line and year 2000. This refinement is left as an optimization which may be useful in implementing the method. Theorem 1 The general conversion method is correct: Any constraint obtained as output is implied by the original network. Implementation In this section, we show how the conversion algorithm can be implemented. Essentially, this can be done by exploiting the periodicity of granularities and variable domains. First of all, we need to ensure that the conversion is allowed, as required by the condition specified on the INPUT in Fig. 3. Secondly, we need # y to compute 8 #theA values of the distance functions U and ]" U for arbitrary parameters. Excluding illegal conversions From Section , we know that the conversion of a constraint < is alon the distance from to with target granularity < . If we consider lowed if each element in K is in < < as the periodical set induced it is easily seen that < by ,and < . this condition holds if Intersection of periodical sets can be easily implemented by considering their common period, and similarly can be implemented equivalence. (See (BR02) for details.) Computation of distance functions # A 8 # A The computation of U and ]' U following the formulas in their definition may be computationally very inefficient. Our choice is to devise an efficient computa 9 and tion which return values equivalent to 8 method ] ! < respectively, assuming that the conditions U $ , U $ , appearing in the definitions of the distance Origin day Destination hour week hour bday hour bweek hour day bday day bweek week day day week year day year month month year bweek bday bday bweek bweek week bday day bweek day Computation of mindist(), maxdist() 23 mindist(day, k, hour) = O 3 maxdist(day, k, hour) = O 23 mindist(week, k, hour) = O 3 maxdist(week, k, hour) = 23 O 3 mindist(bday, k, hour) = O 3 23 _ DIV 3 maxdist(bday, k, hour) = DIV 23 O mindist(bweek, k, hour) = 3 maxdist(week, k, hour) = 3 O 3_ mindist(day, k, bday) = if MOD _ 3 then O else 3 O HO DIV _ maxdist(day, k, bday) = if 3 MOD _ 3 then O DIV else 3 HO mindist(day, k, bweek) = 3 DIV maxdist(day, k, bweek) = DIV 3 mindist(week, k, day) = 3 O maxdist(week, k, day) = mindist(day, k, week) = DIV 3 maxdist(day, k, week) = DIV23 35_ mindist(year, k, day) = % O DIV O 3 23 maxdist(year, k, day) = 23 DIV mindist(year, k, month) = \ O 3 O maxdist(year, k, month) = \ \ mindist(month, k, year) = DIV 3 maxdist(month, k, year) = DIV 3 \ mindist(bweek, k, bday) = 3 O maxdist(bweek, k, bday) = mindist(bday, k, bweek) = DIV 3 maxdist(bday, k, bweek) = DIV mindist(bweek, k, week) = maxdist(bweek, k, week) =3 _ mindist(bday, k, day) = 3 3# DIV 3 # maxdist(bday, k, day) = DIV 23 mindist(bweek, k, day) = 3 O maxdist(bweek, k, day) = functions, are always satisfied. Note that, if this is not the case, we derive a constraint which is looser than the optimal constraint, but still logically implied by the input constraint network. Based on extensive experiments we have seen that the resulting approximation is very good, and hence the trade-off between efficiency and precision favors our solution, except for special critical applications. The method we have implemented is based on a table lookup for each pair of source and target granularities. # G and Each a formula for U 8 table # : entry contains ]' U having as the only variable. Intuitively, each formula is based on the relationship between the structures of the two granularities. In some cases the formulas are trivial, but this is not true For in order to in! general. example, 8 r 7U , it is sufficient derive the formula U to consider that each year is made of 12 months; indeed that formula is DIV \ . # 8 , Less intuitive is how to evaluate U :r since we have to take into account noncontiguous granules. # y U 3 O DIV DIV Table 1: Computation of and 8 ]" ! y U In Table 1 we report some of the formulas involving a quite rich set of granularities. There are pairs of source and target granularities for which is particularly complex to derive a direct formula. This happens in particular when the granules of the source granularity have different sizes in terms of the target !granularity, as 8 for example, in the computation of U r 7U . Our choice in this case is to precompute the value of the distance functions for some values of (less than the number of granules of the source granularity in the common period of the# two granularities). 8 U r 7U . For example, in order to compute 8 # 8 ]" U r 7U , we precompute them for and based on their definition, and obtain all other val;?@?;? ues by the formulas in Table 2. A library of formulas for common granularities can definitely speed up the conversion process. For cases in which formulas do not exist yet, and are not trivial to derive, we may consider an alternative conversion algorithm based on 8 #3 r 7U 2MOD 35_ >3 8 DIV > 8 DIV 63 U r 7U MOD \ maxdist(month, k, day) = ] DIV > 235_ 3 DIV 8 8 8 U r 7 U and ] U r 7 U Table 2: Computation of Origin month Destination day Computation of mindist(), maxdist() # mindist(month, k, day) = U " ! the relationship of each of the source and target granularities with the bottom granularity. A preliminary version of such an algorithm was illustrated in (BWJ98), and a refinement is proposed in the extended version of this paper (BR02); However, that method introduces an additional source of approximation. Example 2 Suppose we want to derive from the network in Fig. 1 an implied network in terms & 9 @of business < days. @ This and must means the constraints on arcs be converted. Considering -$#% , the lower bound is 2, hence we must compute U -3 % #6 -`ba c . Looking at Table 1, this value 8 is # O . For ' ] U - % 6 b ` a c the lower bound, we have 3 . Accordingly to the algorithm, we obtain the new TCG -`ba c . In Example 1, we have seen that, < @ considering the whole network, the TCG on arc can be converted in terms of b-day and b-week, despite its granularity is day. Its conversion accordingly to the algorithm and Table 1 is -`ba c , and the resulting implied network in terms of b-day is shown in Fig. 4. X1 [6,14]b−day [−1,1]b−day X0 X3 [0,3]b−day [1,6]b−day X2 Figure 4: Implied network in terms of b-day Similarly, we can obtain an implied network in terms of b-week shown in Fig. 5. In this case, 1 the9 constraints 1 < , to be& converted are those on arcs < ; and . Accordingly to the algorithm, we ob -% , 6 - , and - % , respectain eO tively. " ! X1 [−1,1]b−week [2,2]b−week X0 X3 [0,1]b−week X2 Given a constraint network, we can derive a logically implied network in terms of a target granularity by applying the conversion algorithm to each constraint for which a conversion into is allowed. The following example shows the derivation of an implied network following the steps of the algorithm and the implementation techniques illustrated in the previous section. # [0,2]b−week Application of direct conversions Figure 5: Implied network in terms of b-week Conclusion In this paper we proposed an algorithm and implementation techniques for the conversion of temporal constraints in terms of different granularities. By applying the algorithm, it is possible to derive a new constraint network in terms of a single target granularity which is implied by the original set of constraints. The conversion algorithm can also be integrated with arc and path consistency techniques for constraint propagation (DMP91; BWJ02), leading to the derivation of implicit constraints, and to the refinement of existing ones. References C. Bettini, X. Wang, S. Jajodia, Solving Multi-Granularity constraint networks, Artificial Intelligence, to appear. C. Bettini, S. Ruffini. Granularity conversion of quantitative temporal constraints. DSI Technical Report N. 276-02, University of Milan, Italy, 2002. C. Bettini, X. S. Wang, S. Jajodia. Temporal Reasoning for Supporting Workflow Systems. Distributed and Parallel Databases, Kluwer Academic Publishers, 2002. C. Bettini, X. Wang, S. Jajodia. A general framework for time granularity and its application to temporal reasoning. Annals of Mathematics and Artificial Intelligence, 22(1,2):29–58, 1998. C. Bettini, X. Wang, J. Lin, S. Jajodia, Discovering Frequent Event Patterns With Multiple Granularities in Time Sequences. IEEE Transactions on Knowledge and Data Engineering, 10(2):222–237, 1998. R. Chandra, A. Segev, and M. Stonebraker, Implementing calendars and temporal rules in next generation databases, in Proc. of ICDE, 1994, pp. 264-273. C. Combi, L. Chittaro, Abstraction on clinical data sequences: an object-oriented data model and a query language based on the event calculus Artificial Intelligence in Medicine, 17(3): 271-301, 1999. T. Dean, Using temporal hierarchies to efficiently maintain large temporal databases Journal of the ACM, 36(4):687– 718, 1989. R. Dechter, I. Meiri, and J. Pearl, Temporal constraint networks, Artificial Intelligence, 49:61–95, 1991. Nachum Dershowitz, Edward M. Reingold, Calendrical Calculations, Software - Practice and Experience 20(9): 899–928, 1990. I.A. Goralwalla, Y. Leontiev, M.T. Ozsu, D. Szafron, C. Combi, Temporal Granularity: Completing the Puzzle. JIIS, 16(1): 41-63, 2001. J.R. Hobbs, Granularity, in Proc. of IJCAI, Los Angeles, CA, 1985, pp. 432–435. B. Leban, D. Mcdonald, and D. Foster, A representation for collections of temporal intervals, in Proc. of AAAI, 1986, pp. 367–371. A. Montanari, A. Peron, A. Policriti. Theories of OmegaLayered Metric Temporal Structures: Expressiveness and Decidability. The Logic Journal of IGPL, 7(1):79–102, 1999.