Reformulating Temporal Plans for Efficient Execution

3 downloads 0 Views 378KB Size Report
1. Masters Project. Intelligent Systems Program. University of Pittsburgh. Reformulating Temporal Plans for Efficient Execution. Ioannis Tsamardinos. July 1998 ...
Masters Project

Intelligent Systems Program

University of Pittsburgh

Reformulating Temporal Plans for Efficient Execution Ioannis Tsamardinos July 1998

1

Table of Contents 1. Introduction .............................................................................................................................................. 4 2. Background............................................................................................................................................... 5 2.1 Simple Temporal Networks.................................................................................................................. 5 2.2 Temporal Plans..................................................................................................................................... 6 2.3 Execution of Temporal Plans ............................................................................................................... 7 Controllable and Observable actions ...................................................................................................... 8 Executive decisions ................................................................................................................................ 8 Execution Example................................................................................................................................. 9 Executive Efficiency .............................................................................................................................. 9 3. The research problem and context........................................................................................................ 10 3.1 The Greedy Executive ........................................................................................................................ 10 Time complexity of the Greedy Executive ........................................................................................... 10 3.2 The problem with the Greedy Executive ............................................................................................ 11 3.3 Possible Solutions............................................................................................................................... 12 Global Propagation............................................................................................................................... 12 Off-line Expansion ............................................................................................................................... 13 Plan Reformulation............................................................................................................................... 13 4. The equivalent, minimal, dispatchable network algorithm ................................................................ 14 4.1 Dispatchability Results ....................................................................................................................... 14 4.2 The Triangle Rule and the Dominance Relation ................................................................................ 16 4.4 Towards the main algorithm and the Minimality of the filtered network........................................... 19 4.5 The main algorithm ............................................................................................................................ 21 Correctness ........................................................................................................................................... 21 Complexity ........................................................................................................................................... 21 5. The Fast Minimal, Equivalent, Dispatchable network algorithm (Fast-MED)................................. 21 5.1 The Predecessor Graph....................................................................................................................... 23 5.2 Identifying and Using Rigid Components .......................................................................................... 25 Identifying Rigid Components ............................................................................................................. 26 Rigid Component Contraction.............................................................................................................. 26 Rigid Component Edge Rearrangement ............................................................................................... 27 Correctness of Rigid Component Contraction...................................................................................... 27 Consequences of Contraction ............................................................................................................... 28 6. Minimizing the real-time performance................................................................................................. 29 7. Experimental Results ............................................................................................................................. 30 7.1 Experimental Design .......................................................................................................................... 30 7.2 Discussion .......................................................................................................................................... 36 Execution Time .................................................................................................................................... 36 Number of output edges ....................................................................................................................... 37 8. Conclusions and Future Work .............................................................................................................. 37 Appendix A: Definition and Theorems Reference................................................................................... 39 A.1 Definitions ......................................................................................................................................... 39 A.2 Theorems, Lemmas, and Corollaries ................................................................................................. 40

2

Acknowledgements ..................................................................................................................................... 42 References ................................................................................................................................................... 42

3

1. Introduction Temporal plans, which use the Simple Temporal Network (STN) formalism, permit significant flexibility in specifying the occurrence time of events. However, the advantage of retaining execution flexibility is counterbalanced by the cost, during execution, of propagating the time of occurrence of events throughout the flexible plan. To minimize execution latency this propagation needs to be very efficient. This work deals with the problem of reformulating temporal plans that use the STN formalism so that they can be executed efficiently, i.e. requiring minimal propagation of information. The problem can be restated as reformulating a temporal plan to acquire two properties: a) dispatchability, i.e., it can always be executed correctly even when information is propagated only to the immediate neighbors of a node and, b) minimality, i.e., it has minimal1 number of edges among all other dispatchable networks. The small number of edges is a core factor in the execution speed of the network. The project examines five main aspects of the problem. The first one is the theoretical analysis of when and how plans can be reformulated to achieve dispatchability and minimality. The result is a necessary and sufficient condition for removing edges from a fully connected network. The immediate application of the condition provides a simple algorithm that solves the research problem in time O(V3), where V is the number of nodes in the network. The second aspect focuses on the efficiency of the reformulation process itself and improves its complexity by providing a new faster (but more complicated) algorithm called Fast-MED. Fast-MED runs in time O(VEin+V2lgV), where Ein is the number of edges of the input network. This complexity is the same as Johnson’s [Cormen et al., p. 569] algorithm for all-pairs shortest path and constitutes a great improvement when the network is sparse. The fast algorithm also has a memory complexity which is linear to the size of the input and output network compared to the O(V2) complexity of the first algorithm. The third and fourth aspects of this work are experimental. First, the efficiency of the fast algorithm is experimentally researched and second, we gather experimental results to provide practical expectations on the size of the output networks. Finally, the fifth aspect deals with providing real-time guarantees when executing the networks. Executing the minimal, dispatchable network guarantees optimal average performance. We also discuss, without including experimentation, a modification to the algorithm that guarantees optimal real-time performance. The structure of this paper is as follows. Section 2 provides a brief introduction and related background information. Section 3 presents the research problem in detail. Section 4 presents the theoretical results that lead to the design of the algorithm. Section 5 deals with the Fast-MED. Section 6 discusses the real-time performance issues and presents the modification that guarantees optimal real-time behavior. Section 7 contains the experimental results and discussion. Section 8 concludes the paper. Appendix A provides an easy reference of definitions, theorems, lemmas, and corollaries. This project is the result of a collaborating work with Nicola Muscettola and Paul Morris both at NASA Ames.

1

The term “minimal network” has been used in the literature [Dechter et al.] to denote the distance graph, a concept introduced in a later section. Here minimality means minimal number of edges unless stated otherwise. 4

The results of this project led to the publication of two papers [Muscettola et al 1998] and [Tsamardinos et al 1998] that can also be found at http://www.cs.pitt.edu/~tsamard/. The fast transformation algorithm has been scheduled to fly as part of the Remote Agent, a intelligent agent intended to experimentally fly the spacecraft of Deep Space One mission of NASA.

2. Background 2.1 Simple Temporal Networks A Simple Temporal Network (STN) is the graph representation of a Simple Temporal Problem (STP) as defined in [Dechter et al 1991.]. STNs are used in many applications and systems to represent and reason about temporal information ([Muscettola et al.], [Muscettola et al. 1995], [Pell et al 1998]). In particular, the STN formalism is used by the Remote Agent (RA) [Pell et al 1998], the system that inspired this work, to represent information related to planning and execution in an autonomous spacecraft. Definition 1: STN and bound of an edge. A Simple Temporal Network is a directed edge-weighted graph where V is the set of nodes and E the set of edges2. The nodes represent time-points and have continuous domains. Each edge is labeled by a real value weight that is called the bound of the edge. The bound of the edge from node X to node Y is denoted as d XY and the edge as XY. The value assigned to a node X is denoted as TX . Each edge imposes the following constraint on the values assigned to its end-points:

T y − Tx ≤ d XY In an STN no self-referencing edges or multiple edges (i.e. edges starting and ending with at the same nodes) are allowed. Figure 1 displays a small STN with two nodes and two edges. It is easy to see that the two edges impose the following constraints:

6 ≤ T y − Tx ≤ 10

X

10 -6

Y

Figure 1: A Simple Temporal Network

In other words y has to be assigned a value (occur) between 6 and 10 time units after X. This example is characteristic of how pairs of edges between two nodes should be “read”. Definition 2: Solution of an STN, consistent STN, and equivalent STNs Let N be an STN and V={p1, ...,pn} the set of nodes. A tuple X=(x1, ..., xn) is called a solution iff the assignment {T p1 = x1 ,..., T pn = x n } satisfies all the constraints. The network N is consistent iff there is at least one solution. Two networks are equivalent iff they represent the same solution set.

2

V and E will also be used to denote |V| and |E| (i.e. the number of elements in the sets) respectively, whenever it is clear from the context what is meant. For example, O(V) will mean O(|V|). 5

The following discussion summarizes some major results on STNs, parts of which are taken from [Dechter et al 1991]. Each path from X to Y in an STN N, i0=X, i1, ..., ik=Y, induces the following constraint on the distance Ty – Tx: k

TY − T X ≤ ∑ d il −1 ,il

Equation 1

l =1

If there is more than one path from X to Y, the shortest one will induce the tightest constraint. For each pair (X,Y) of nodes we can find the tightest constraint (the weight of the shortest path) which is called the distance between the two nodes (equation 2). If there is no path between two nodes, their distance is assumed infinity. The notation for expressing the distance between nodes X and Y is |XY|. By definition therefore:

TY − T X ≤ XY

Equation 2

Definition 3: Distance Array, Distance Graph Let N be an STN. The array defined by the equation a IJ = X I X J , where aIJ is the array element at I row and J column and XI, YJ nodes in N, is called the distance array of N. The fully connected STN defined on the same set of nodes as N, and with bounds dXY=|XY| for each edge XY is called the distance graph of N. The distance graph is the graph representation of the distance array. Since the two objects represent the same information the two terms will be used interchangeably. Calculating the distance array of a network is equal to solving an all-pairs shortest path problem as described above. It can therefore be accomplished in time O(V3) by the Floyd-Warshall’s all-pairs shortest-paths algorithm [Cormen et al 1990, p. 558] or by Johnson’s algorithm [Cormen et al 1990,p. 569]. Once the distance array for an STN is available, assembling a solution for it requires time O(V2) (the issue of finding a solution of an STN will arise again at subsection 3.3). The consistency of the network can be checked in time O(V) by the following theorem [Dechter et al 1991]: Theorem 1: A given STN, N, is consistent if and only if its distance graph has no negative cycles. The distance graph is the fully connected graph with bounds the elements of the distance array. Therefore, if all diagonal elements of the distance array are non-negative there are no negative cycles in the distance graph and the original network is consistent. Corollary 1 (from Theorem 1): For any time-points X and Y in a consistent STN the relation XY + YX ≥ 0 holds. Proof: If the relation did not hold there would be a negative cycle, which is impossible (by theorem 1) since the network is assumed consistent.

2.2 Temporal Plans In many domains it is necessary to augment the representation of partially ordered plans to include temporal constraints. For example, some actions should follow other actions after a specified time interval has elapsed or an action should be performed during the execution of another action. All these relations are not expressed in the classic partially ordered plan formalism but can

6

be captured using the STN formalism presented in the previous subsection. In the discussion below, we will use the term task to refer to classical planning actions and reserve the term action for other purposes. Nodes in an STN refer to time-points that have no temporal extent while tasks in plans are time intervals since they require some time to complete. Therefore, we cannot directly associate tasks with STN nodes. Nodes are associated instead with actions of starting or finishing a task or a set of tasks (see [Muscettola et al.][Pell et al 1998]). Such an association is represented with an association tuple where v is a node, t a task, and a is one of the actions Begin or End. The edges of the network therefore, impose constraints on when these tasks can begin or finish execution. We say a node is executed when the associated actions are taken. There are cases when the plan is mis-specified, such as when a node that ends a task is executed before the node that starts the task can arise. It is up to the planner to generate temporal plans with the necessary constraints (edges) so that if node A starts a task, then the node that finishes the task is always executed after A. Figure 2 will help to pictorially explain how constraints on tasks can be interpreted. Suppose that the set of association tuples for both 5 5 networks (a) and (b) is the following A B A B -3 5 {, , }. (a) (b) Combining the constraints of the edges in the network of Figure 2(a), we conclude Figure 2 that 3 ≤ TB − T A ≤ 5 . Therefore, for edges to be respected task t3 has to end between 3 and 5 time-units after task t1 has begun and t2 has ended. Consider now the network at Figure 2(b). The corresponding equation for the times of the nodes is − 5 ≤ TB − T A ≤ 5 . Therefore, either A and B may be executed first. There is no constraint on the relative order of execution of tasks t1, t2, or t3. In the following sections, we will use the next definition of temporal plan: Definition 4: Temporal Plan A tuple is called temporal plan, where G is an STN, T a set of tasks, and A is a set of association tuples defined on the nodes of G and on the tasks of T.

2.3 Execution of Temporal Plans A number of control systems distinguish between a deliberative layer (planner) and a reactive layer (executive) [Pell et al 1998, Bonasso et al 1997, Wilkins et al 1995, Drabble et al 1996, Simmons 1990, Musliner et al 1993, Bresina et al 1993]. We will call the system responsible for executing a temporal plan expressed as STN the executive. The function of a plan is to provide robust and effective directives to the executive on how to control a system toward desired behaviors. To be robust against uncertainty in the execution environment a plan must be flexible, i.e., must specify a set of possible acceptable behaviors. The executive should be able to choose among such behaviors based on the actual execution conditions. The STN formalism is one way of representing flexible temporal plans.

7

Controllable and Observable actions

In the Remote Agent [Pell et al 1998] the actions of starting or ending a task attached to a time-point can be either controllable or observable. Controllable actions are the ones which the executive has the ability to perform such as turning on the engine. Observable actions are the ones that the executive can only observe happening due to physical processes, such as the completion of a spacecraft turn, or a comet entering the camera’s visual field. The temporal plan definition given previously does not make the distinction between observable and controllable actions. When an observable action occurs, the associated time-point is “executed” although not by the executive. A representation that explicitly considers observable and controllable actions is discussed in [Vidal et al. 1995, Vidal et al. 1997]. However, these papers do not deal with the efficiency of the execution of the temporal plans. The presence of observable actions is the reason a temporal plan has to be flexible. If all actions could be determined by the executive, then we could preassign values for the time-points before execution starts. In absence of uncertainty, the problem of consistent execution resembles the scheduling problem. However, because uncertainty exists in many real-worlds applications, the executive should in effect incrementally and dynamically generate a solution to the input network. Executive decisions

We define the time-window of a node to be the time interval in absolute time within which the node is allowed to be executed given the constraints of the network and the values of the already executed nodes. For example if dxy=5, dyx=-3, and Tx=7 then the time-window of y is the interval [10,12]. We denote the time-window of a node x as w(x)=[l, u], where l , u ∈ ℜ ∪ {+∞,−∞} . Notice that the time-window of a node is a dynamically determined quantity. When a node X is executed at time TX, the executive propagates this value to the rest of the network. Implicitly or explicitly, the time-windows of all other nodes are updated to reflect the decision of executing x at TX. The exact time the executive chooses to execute a node depends on a number of factors. The execution time has to be within the time-window so that it respects the constraints of the network. If the node has at least one observable action associated with it, then the executive has to execute the rest of the associated actions when the observation occurs. If there are no other actions associated then it just signals that the node has been executed. Obviously, in the case where a node has more than one observable actions associated with it, it is very improbable that they will both occur at the same time. This is another case where the plan is mis-specified. If an observed action occurs outside the time-window of the associated node then some constraint is being violated and then we say that the plan breaks. The network does not have a solution any more but this is not executive’s fault. This situation can arise from an irrecoverable system failure. If, for example, a switch is stuck in the on position then the task of turning off will take more than allowed by the plan. In the Remote Agent, when a plan breaks the executive requests for a new plan. If the node has only controllable actions associated with it, the executive is allowed to make an arbitrary decision as to when exactly it will execute this node within its time-window. Usually this will depend on the semantics of the actions of the node. For example, if a node starts a task such as “turn-communication-antenna-to-earth” then the executive will probably execute this

8

node as soon as possible. If, on the other hand, a node ends the task “keep-solar-panels-pointingto-the-sun” then the executive will execute the node as late as possible, trying this way to maximize the available power in the batteries. The exact details of these decisions are domain dependent and will not concern us in this paper. The only assumption we will make is that the executive executes a node sometime within its time-window. Execution Example

We will now present an example of the exe2min 10sec cution of a simple temporal plan. Since the ReB C D -2sec mote Agent is the system that inspired this work, 0min most of the examples in this paper will be within its context. The temporal plan describes how to Figure 3 acquire a photograph of an asteroid from the spacecraft. In order for the photograph to be taken, the camera has to be still, which means that the engine has to be turned off since it causes vibrations. After the photograph is taken we would like to turn the engine back on so that we will remain in a predefined trajectory. The temporal plan to execute is where G is the graph at Figure 3, T={t1=”turn-off engine”, t2=”take-picture”, t3=”turn-on engine”}, and A={, , , , }. The bounds of the engines derive from the specifics of the domain. Under normal conditions, it takes no more than 2 minutes for the engine to shut off. The executive should wait until the sensors signal that the engine is completely off before executing C. If the task takes more than the time allocated by the planner, i.e. 2 minutes, then the constraint of the edge dBC=2min is violated and the plan breaks. If the engine shuts off at time 1min, the executive can go ahead and execute node C. This means ending the task “turn-off engine” and staring the task “take picture”. It takes at least 2 seconds for the picture to be taken and there are no sensors to let us know that the picture has been taken properly. So the planner imposed the constraint dDC=-2sec to make sure the executive will spend at least 2 seconds taking the picture. But, the longer we leave the camera’s diaphragm on, the brighter the picture will be and this is why we provide the executive the flexibility to end the task 10 seconds after it started. Finally, if the executive decided to spend only 5 seconds taking the picture, node D will be executed at time 1min 5sec which means closing the diaphragm and starting the engine back on. Executive Efficiency

In space and other real-world applications, the execution of plans has to be efficient. Efficient execution of plans does not mean fast execution of temporal plans since any correct execution of a plan must respect the temporal constraints. For example, any executive will wait 10 hours to execute Y after executing X if the edge dyx=-10hours is included in the graph. Instead, executive efficiency is defined as the ability of the executive to quickly deduce which node to execute next, and when. All else being equal (and most notably the available computing power) a more efficient system can cope with tighter edges. If, for example, the time-window of a node X is shrunk at time t=1hour to w(x)=[1hour, 1hour 100milliseconds], the executive has 100 milliseconds to make the decision and execute this node. Delaying execution more than 100 milliseconds means violating some constraint. The next section deals with executive efficiency in more detail. It will become apparent that the efficiency depends on the number of edges of the STN. Ideally, we 9

would like the performance of the executive to be independent of the size and the structure of network. The work presented in this paper improves the average and worst-case performance to the theoretical maximum. The experimental results indicate that in most practical cases the efficiency is indeed independent of the network size but depends on the network structure.

3. The research problem and context 3.1 The Greedy Executive An executive that updates the time-windows of all nodes yet to be executed clearly does not meet the goals of efficiency. Propagating the execution time of a node to the rest of the network does not scale up as desired and large networks will have very weak real-time guarantees. Only a greedy, locally propagating executive can possibly meet the efficiency requirements. When a node X is executed, the greedy executive updates only the time-windows of the nodes directly connected to X. The greedy executive is the simplest executive and an algorithm that implements it is presented at Figure 4. The lower_bound and upper_bound functions in step 6 of Figure 4 return the lower and upper bound of a node’s time-window respectively. Consider the edge dxy=-2. This imposes the constraint T y − Tx ≤ −2 ⇒ T y < Tx . In other words Y has to be executed before X. Any constraint dxy=a, where a is negative, imposes such an ordering constraint. This is the justification for step 5 of Figure 4. We put in set A only the nodes that have already met their ordering constraints, i.e. all nodes that should be executed before them, have already been executed. As presented the algorithm ignores the details of how specific tasks are executed and concentrates on the steps that ensure that the temporal constraints of the STN will be respected. Steps 2 and 6 involve two non-deterministic choices and their implementation depends on the domain dependent details of the executive. These steps determine when exactly a node is executed within its time-window. Step 5 raises the issue of deadlock. It 1. Let A={start-time-point}, current-time = 0, might be the case that there is a set of nodes S={} with negative edges to each other in a circular 2. Arbitrarily remove a node X from A such that current-time is within X’s time-window manner. Then, none of them will ever be put 3. Execute the actions associated with X and in set A and be executed. This is impossible add X to S. however in a consistent network since in a 4. Propagate TX to X’s immediate neighbors in the STN. consistent network there are no negative cy5. Put in A all nodes Y such that all negative cles (see theorem 1). Time complexity of the Greedy Executive 6.

edges starting from Y have a destination that is already in S. Wait until current-time has advanced to some time between Min{lower_bound(Y): Y in A} and Min{upper_bound(Y): Y in A} Go to 2 until every node is in S.

The time it takes for the executive to make the decisions in steps 2 and 6 depends on the domain specific part of the implementation. 7. We assume it takes constant time. In the RA a Figure 4: The greedy executive node is executed as soon as possible so once the time-window of a node is known, it takes constant time to decide when to execute it. We also assume that spawning new tasks and ending 10

old ones takes constant time. In the RA this is the time, it takes to create a new thread that will take care of the low-level details of the task’s execution or to destroy an old thread. If the number of the actions associated with a node is at most a, then step 3 takes time at most O(a). The actual implementation of the algorithm can retain two priority queues, one with key lower_bound(X) and one with key upper_bound(X), where X is a node in the set A. This way finding the minimums at step 6 requires only constant time. Updating the structures takes time O(logV) for each insertion (step 5) and deletion (step 2). If we let k and k’ be the average and maximum, respectively, number of neighbors a node can have, then steps 2 and 5 takes on average time O(klogV) and O(k’logV) in the average and worst case respectively. After a node is executed at step 4, its execution time is used to calculate the time-windows of all of its neighbors. This means following at most k edges and updating at most k time-windows. Each time-window update takes constant time since it is just the operation of checking if the new information imposes a tighter constraint that the current value of lower_bound(X) or upper_bound(X). Step 4 therefore takes time Θ(k) (for the average case analysis). The total time complexity of the algorithm is Θ(a+klogV). The performance of the executive is therefore acceptable since in practice we expect k to be a small constant.

3.2 The problem with the Greedy Executive The greedy executive achieves the performance goal we have set assuming the maximum number of neighbors of any node is a small constant. What has been left out of the discussion of the algorithm at Figure 4 however, is the question of the algorithm correctness. Will the greedy executive always be able to dynamically construct a solution to an STN if one exists? Two examples are presented below, one in which the greedy executive always succeeds in finding a solution, and one in which there are cases where it fails to do so. In both networks (a) and (b) of Figure 5, we assume that X is the start-time-point of step 1 of the algorithm. This is possible since X does not has any negative edges emanating from it so there are no other nodes that should be executed before X. We will trace the algorithm as it tries to exe10

10

7

X

Y

Z -1

-8 10 -6

Y

Z -4

-5 11

5 W

4

X

-4

(a) A dispatchable network

-7

3 W

-3

(b) A non-dispatchable network Figure 5

cute the network of Figure 5(a). If X is executed at time 0, then w(Y)=[8,10] and w(W)=[6,10]. Next, suppose that the executive picks Y to be executed at time 8 which makes w(Z)=[9,15]. W will be executed any time in [6,10] and we will assume it will be executed at time 7. The timewindow of Z now becomes [11,12]. Executing Z at any time within [11,12] results a correct execution. It is left to the reader to verify (since a formal proof would require numerous results from later sections) that no matter what the executive’s arbitrary decisions are, the network will be correctly executed. In other words, at any point in time, no matter what partial solution the executive chooses, there will always be a way to complete this to a full solution.

11

Consider now the network of Figure 5(b). Assume X is again executed at time 0 and so w(Y)=[5,10] and w(W)=[7,11]. Suppose Y is then executed at time 5, which will shrink the timewindow of Z to [9,9]. W will be the next node to be executed supposedly at time 7. Trying to update the time-window of Z the executive realizes that it becomes the null set. No matter when Z is executed, one of the constraints between Y and Z, or W and Z will be broken. The partial assignment of {TX=0, TY=5, TW=7} cannot be completed to a full solution. We will call networks such as the one in Figure 5(b) non-dispatchable. In contrast, networks that can always be executed correctly by the greedy executive of Figure 4, we will call dispatchable. Notice that the network 5(b) does have a solution: {TX=0, TY=6, TW=7, TZ=10}; it is just that the executive may fail to dynamically construct it. The reason there are non-dispatchable networks is the existence of implicit constraints. In Figure 5(b) one can intuitively check that Y should always be executed exactly one time unit before W. To achieve this synchronization we should add the edges dYW=1 and dWY=-1. In addition, consider the constraint imposed on X from Y (i.e. the edge dYX) by the path Y-Z-W-X. By equation 1, this is:

T X − TY ≤ d YZ + d ZW + d WX = 4 − 3 − 7 = −6 The explicit constraint in the network is dYX=-5. The path Y-Z-W-X is therefore shorter and imposes a tighter constraint. Actually it is the shortest path from Y to X and therefore |YX|=-6. This is a case where the explicit constraint (i.e. the bound of the edge) is looser than an implicit constraint imposed by other paths. We can transform the network of Figure 5(b) so that it becomes dispatchable by adding the edges dYW=1 and dWY=-1 and by tightening the bound of the edge XY to dYX=-6. Notice that the original and the transformed networks describe the same sets of solutions, i.e. they are logically equivalent. Section 3 will prove that every consistent network can always be transformed to a logically equivalent one that is dispatchable. Moreover, the transformation algorithm will output the dispatchable network with the minimum number of edges.

3.3 Possible Solutions Given the incorrectness of the greedy executive’s algorithm when given an arbitrary network, there are a number of solutions. Namely these are global propagation, off-line expansion, and plan reformulation. Global Propagation

Instead of executing temporal plans using the greedy algorithm of Figure 4, other more complicated algorithms could be used. The basic difference is between local propagation as done in Figure 4, and global propagation. We will trace the execution of the network of Figure 5(b) by a globally propagating algorithm. X is again executed at time 0. Next, the time-windows of all nodes are calculated by propagating the value TX=0 to the rest of the network. Consider the timewindow of node Y. By running a single source shortest path algorithm twice from X to Y and from Y to X we find |XY|=10 and |YX|=-6. The time-window of Y is therefore w[6,10]. In a similar fashion w(W)=[7,11] and w(Z)=[10,14]. Assume that the executive will next pick Y to execute at time 7. Propagating this constraint to the rest of the network by running the single source shortest path algorithm will result in w(W)=[8,8] and w(Z)=[11,11]. Notice that Y and W are not

12

neighbors but by propagating constraints throughout the network, we calculate the correct timewindows. In the same case, the greedy executive would not update W’s time-window since there is no edge from Y to W or from W to Y. Continuing execution, W will be the next node executed at time 8, and Z the last node executed at time 11. It therefore takes time Ω(E+V) for this algorithm to decide which node to execute next and when since it runs two single source shortest paths algorithms for each such decision. This solution is therefore unacceptable for systems with high performance demands. Off-line Expansion

Another approach would be to perform the constraint propagation off-line. By constructing the distance graph, we are making all implicit constraints explicit. In other words, for each pair of nodes X and Y, we add an edge between them with the tightest bound (i.e. |XY|). This calculation is equivalent to running an all-pairs shortest path algo14 rithm and its time-complexity is O(V3) (Floyd-Warshall -10 4 10 algorithm) or O(V2logV+EV) (Johnson’s algorithm, see X Y Z -6 -4 section 1). The preprocessing can be done off line and -1 1 10 3 -3 would transform the network of Figure 5(b) to the one -7 W in Figure 6. Next section will prove that distance graph is indeed Figure 6: A fully connected network dispatchable. This approach increases the number of edges in any processed network to the maximum of Θ(V2). In the previous section, we showed that the worst-case time-complexity of the greedy executive is O(a+k’logV), where k’ is the maximum number of neighbors of a node. With off-line expansion therefore, the time-complexity of the greedy executive becomes O(a+VlogV) and so it does not constitute an improvement over the previous approach. Plan Reformulation

In spite of the disadvantages of the later approach, the main idea can still be refined for potentially better results. After adding the edges YW and WY the edges YZ, ZY, XZ, and YZ are not needed. In other words, the preprocessing step of the off-line expansion adds some superfluous edges. The solution proposed in this project is the design of an algorithm that transforms any STN to an equivalent, dispatchable network with the minimum number of edges. There are potentially many such networks. Figure 7 displays two of them given the original network 5(b) used so far in

X

10 -6

4

Y -1

-4

10 -6

X

Z

Y -1

1

Z 1

W

W (a) One of the minimal, equivalent, dispatchable network.

3 -3

(b) Another minimal, equivalent, dispatchable network.

Figure 7

our examples. 13

Recall from the previous section that k and k’ is the average and maximum number of neighbors of the nodes. It still might be possible that in the worst case, k or k’ is not bounded by a small constant. However, this is not expected to occur very frequently in practice and the experiments performed during this project indicate that the conjecture is true. The dispatchable network with the minimum number of edges minimizes k and consequently the average performance of the greedy executive. To minimize worst case performance the algorithm should output a dispatchable network with the minimum k’. Consider the class of all equivalent, dispatchable networks with minimum k (i.e. minimum number of edges). Section 5 argues that some equivalent dispatchable networks with minimum k’ exist in that class, i.e. there are equivalent, dispatchable networks that minimize k and k’ simultaneously. In the same section an additional transformation step is provided that modifies a network with minimum k to have minimum k’. This step guarantees that the output network will have optimal average and worst-case performance, thus providing accurate expectations on the real-time performance of the execution of the output network.

4. The equivalent, minimal, dispatchable network algorithm For the theoretical results of this section we will assume that the time required to carry out the execution steps (execution latency) is negligible and does not cause schedule overruns in step 6 of the algorithm at Figure 4. With a coarse time granularity, several time-points may be given the same execution time, even though the algorithm executes them sequentially.

4.1 Dispatchability Results Consider a pair of time-points X and Y. By the definition of the bound of an edge:

TY − T X ≤ d XY   ⇒ TY − d XY ≤ T X ≤ TY + d YX T X − TY ≤ d YX 

Equation 3

Equation 3 can be used to formally define the concept of propagation of the execution time of a node: Definition 5: Propagation of execution time of a node. Let X and Y be two nodes in an STN N. Suppose node Y has just been executed at time TY and that node X is Y’s neighbor, i.e. the edge XY and/or the edge are present in the graph with bounds dYX and dXY respectively. If the time-window of X is w(X)=[l,u] we say that we propagate the execution time of Y to X, if w(X) is updated according to the following rules: • w( X ) = [max(l , TY − d XY ), u ] , if only the edge XY is present in N, • w( X ) = [l , min(u , TY + d YX )] , if only the edge YX is present in N, • w( X ) = [max(l , TY − d XY ), min(u , TY + d YX ] , if both edges XY and YX are present in N. In a distance graph all nodes are neighbors and the edges’ bounds are the distances between the nodes. After Yi, i=1,...,n time-points of a distance graph have been executed, the time-window of X should therefore be

w( X ) = [max{TYi − | XYi |}, min{TYi + | Yi X |}] i

i

Equation 4

Equation 4 will become useful while trying to prove that the distance graph is dispatchable.

14

The first observation is that propagating constraints only locally does not exclude any solutions or, in other words, the greedy executive is able to find all solutions of an STN. Of course, sometimes executions will result in failures i.e. the STN will break. However, for each solution of the STN there will be an appropriate execution that will reveal it. Lemma 1: Given any solution for an STN, there is an execution of the greedy executive that finds this solution. Proof: By definition of the distance |XY|, if there is an edge dXY between the two nodes, the relationship XY ≤ d XY holds. Therefore, local propagation though (explicit) edges can never narrow the time-window of a node so that it excludes a value that can lead to a solution.  Lemma 2: The distance graph of any consistent STN satisfies the triangle inequality: ∀X , Y , Z ∈ V , XY ≤ XZ + ZY Proof: By definition of the distance, |XY| is the sum of the shortest path from X to Y. It is therefore less or equal to any path from X to Y that goes though Z.  Theorem 2: Every distance graph of a consistent STN is dispatchable. Proof: The distance graph is, as defined earlier, the fully connected graph where the bounds on the nodes are the distances between the nodes of the underlying STN. The proof will be by induction on the number of nodes n already executed. When n=1 the theorem holds. The first time-point to be executed is the start-time-point (see Figure 4). Notice that since the start-time-point is assumed not to have any negative edges emanating from it, no node is constrained to be executed before that. Since no other nodes are executed yet there are no constraints broken. Suppose now that the theorem holds for n ≤ k − 1 . That is any partial execution of k-1 (or less) nodes of a consistent STN is dispatchable3. We will prove that the network is dispatchable by proving that the theorem holds for n=k . Suppose the executive has just executed the last of the k-1 nodes and so the current-time is the time assigned to this node. A failure can occur only if the time-window of the node belongs solely in the past (i.e. before another node which is already executed) or it is the empty set. Suppose that the nodes Xi, i=1,..,k-1 have already been executed and we are about to execute node X. In order for the time-window of X to be pushed in the past, there must be a negative edge from one of the nodes Xi to X: T X − T X i ≤ X i X < 0 ⇒ T X < T X i . But, by the definition of the distance graph the edge d X i X = X i X is included in the network which would have made X be executed before Xi (step 5, Figure 4) contradicting our assumptions (see Figure 8). What is left to show now is that the time-window of the time-point cannot be the empty set. If the maximum at equation 4 is achieved by time-point Y and the minimum by timepoint Z, then by equation 4 we get: w( X ) = [TY − XY , TZ + ZX ) . For this not to be the empty set the relation TY − XY ≤ TZ + ZX ⇒ TY − TZ ≤ XY + ZX (rel. 1) should hold. Since we assumed that the execution so far has been dispatchable, that means that the constraint between Z and Y has been respected or TY − TZ ≤ ZY (rel. 2). From the triangle inequality we also have that ZY ≤ ZX + XY (rel. 3). By combining (2) and (3) it is easy to derive (1). 3

Since we have not defined dispatchability for partial executions, a better way to say this is that the partial execution respects all the constraints defined between pairs of nodes that belong to the set of the k-1 nodes. 15

Already executed nodes

Yet to be executed nodes

All bold edges hare non-negative t

k-1

k

Time

Last executed Current Time node

Node of induction step

The graph is a distance graph but only the edges to and from the node with index k are shown. The figure is a snapshot of execution immediately after node with index k-1 has just been executed. For node with index k to be “pushed” to the past, some of the bold edges have to be negative. But then the executive would have executed node with index k before the node that is the starting point of this negative edge. Figure 8

Corollary 2: Every consistent STN can be transformed to an equivalent, dispatchable STN. Proof: Every consistent STN has a distance graph which is equivalent to the original network. Since the distance graph is dispatchable by the previous theorem, every STN can be transformed to an equivalent, dispatchable STN.

4.2 The Triangle Rule and the Dominance Relation The results from the previous subsection suggest that in identifying the minimal, dispatchable network, an algorithm can begin by considering the distance graph. The distance graph is dispatchable but not minimal. The algorithm can then start filtering the distance graph by dropping edges in such a way that the network remains dispatchable, until we reach minimality. This section will provide the major result of this work which is a sufficient and necessary condition for removing an edge from the distance graph while retain dispatchability. The condition will be called the Triangle Rule for reasons to become obvious. Theorem 3: In a consistent execution, negative edges can affect only the lower bound of a time-window, and non-negative edges can affect only the upper bound of a time-window. Proof: Suppose that dXY