The Complexity of Planning Problems With Simple Causal Graphs
aa r X i v : . [ c s . A I] O c t Journal of Artificial Intelligence Research 31 (2008) 319-351 Submitted 09/07; published 02/08
The Complexity of Planning ProblemsWith Simple Causal Graphs
Omer Gim´enez [email protected]
Dept. de Llenguatges i Sistemes Inform`aticsUniversitat Polit`ecnica de CatalunyaJordi Girona, 1-308034 Barcelona, Spain
Anders Jonsson [email protected]
Dept. of Information and Communication TechnologiesPasseig de Circumval · laci´o, 808003 Barcelona, Spain Abstract
We present three new complexity results for classes of planning problems with simplecausal graphs. First, we describe a polynomial-time algorithm that uses macros to gen-erate plans for the class of planning problems with binary state variables and acycliccausal graphs. This implies that plan generation may be tractable even when a planningproblem has an exponentially long minimal solution. We also prove that the problem ofplan existence for planning problems with multi-valued variables and chain causal graphsis NP-hard. Finally, we show that plan existence for planning problems with binary statevariables and polytree causal graphs is NP-complete.
1. Introduction
Planning is an area of research in artificial intelligence that aims to achieve autonomouscontrol of complex systems. Formally, the planning problem is to obtain a sequence oftransformations for moving a system from an initial state to a goal state, given a descriptionof possible transformations. Planning algorithms have been successfully used in a varietyof applications, including robotics, process planning, information gathering, autonomousagents and spacecraft mission control. Research in planning has seen significant progressduring the last ten years, in part due to the establishment of the International PlanningCompetition.An important aspect of research in planning is to classify the complexity of solvingplanning problems. Being able to classify a planning problem according to complexitymakes it possible to select the right tool for solving it. Researchers usually distinguishbetween two problems: plan generation, the problem of generating a sequence of transfor-mations for achieving the goal, and plan existence, the problem of determining whethersuch a sequence exists. If the original STRIPS formalism is used, plan existence is unde-cidable in the first-order case (Chapman, 1987) and PSPACE-complete in the propositionalcase (Bylander, 1994). Using PDDL, the representation language used at the InternationalPlanning Competition, plan existence is EXPSPACE-complete (Erol, Nau, & Subrahma-nian, 1995). However, planning problems usually exhibit structure that makes them much c (cid:13) im´enez & Jonsson easier to solve. Helmert (2003) showed that many of the benchmark problems used at theInternational Planning Competition are in fact in P or NP.A common type of structure that researchers have used to characterize planning prob-lems is the so called causal graph (Knoblock, 1994). The causal graph of a planningproblem is a graph that captures the degree of independence among the state variablesof the problem, and is easily constructed given a description of the problem transforma-tions. The independence between state variables can be exploited to devise algorithms forefficiently solving the planning problem. The causal graph has been used as a tool fordescribing tractable subclasses of planning problems (Brafman & Domshlak, 2003; Jonsson& B¨ackstr¨om, 1998; Williams & Nayak, 1997), for decomposing planning problems intosmaller problems (Brafman & Domshlak, 2006; Jonsson, 2007; Knoblock, 1994), and as thebasis for domain-independent heuristics that guide the search for a valid plan (Helmert,2006).In the present work we explore the computational complexity of solving planning prob-lems with simple causal graphs. We present new results for three classes of planning prob-lems studied in the literature: the class (Jonsson & B¨ackstr¨om, 1998), the class C n (Domshlak & Dinitz, 2001), and the class of planning problems with polytree causal graphs(Brafman & Domshlak, 2003). In brief, we show that plan generation for instances of thefirst class can be solved in polynomial time using macros, but that plan existence is notsolvable in polynomial time for the remaining two classes, unless P = NP. This work firstappeared in a conference paper (Gim´enez & Jonsson, 2007); the current paper providesmore detail and additional insights as well as new sections on plan length and CP-nets.A planning problem belongs to the class if its causal graph is acyclic and all statevariables are either static , symmetrically reversible or splitting (see Section 3 for a pre-cise definition of these terms). The class was introduced and studied by Jonsson andB¨ackstr¨om (1998) as an example of a class for which plan existence is easy (there exists apolynomial-time algorithm that determines whether or not a particular planning problemof that class is solvable) but plan generation is hard (there exists no polynomial-time algo-rithm that generates a valid plan for every planning problem of the class). More precisely,Jonsson and B¨ackstr¨om showed that there are planning problems of the class for whichevery valid plan is exponentially long. This clearly prevents the existence of an efficientplan generation algorithm.Our first contribution is to show that plan generation for is in fact easy if we areallowed to express a valid plan using macros . A macro is simply a sequence of operators andother macros. We present a polynomial-time algorithm that produces valid plans of thisform for planning problems of the class . Namely, our algorithm outputs in polynomialtime a system of macros that, when executed, produce the actual valid plan for the planningproblem instance. The algorithm is sound and complete, that is, it generates a valid planif and only if one exists. We contrast our algorithm to the incremental algorithm proposedby Jonsson and B¨ackstr¨om (1998), which is polynomial in the size of the output.We also investigate the complexity of the class C n of planning problems with multi-valued state variables and chain causal graphs. In other words, the causal graph is just adirected path. Domshlak and Dinitz (2001) showed that there are solvable instances of thisclass that require exponentially long plans. However, as it is the case with the class ,there could exist an efficient procedure for generating valid plans for C n instances using omplexity of Planning Problems macros or some other novel idea. We show that plan existence in C n is NP-hard, henceruling out that such an efficient procedure exists, unless P = NP.We also prove that plan existence for planning problems whose causal graph is a poly-tree (i.e., the underlying undirected graph is acyclic) is NP-complete, even if we restrict toproblems with binary variables. This result closes the complexity gap that appears in Braf-man and Domshlak (2003) regarding planning problems with binary variables. The authorsshow that plan existence is NP-complete for planning problems with singly connected causalgraphs, and that plan generation is polynomial for planning problems with polytree causalgraphs of bounded indegree. We use the same reduction to prove that a similar problem onpolytree CP-nets (Boutilier, Brafman, Domshlak, Hoos, & Poole, 2004) is NP-complete. Several researchers have used the causal graph to devise algorithms for solving planningproblems or to study the complexity of planning problems. Knoblock (1994) used thecausal graph to decompose a planning problem into a hierarchy of increasingly abstractproblems. Under certain conditions, solving the hierarchy of abstract problems is easier thansolving the original problem. Williams and Nayak (1997) introduced several restrictions onplanning problems to ensure tractability, one of which is that the causal graph should beacyclic. Jonsson and B¨ackstr¨om (1998) defined the class of planning problems, whichalso requires the causal graphs to be acyclic, and showed that plan existence is polynomialfor this class.Domshlak and Dinitz (2001) analyzed the complexity of several classes of planningproblems with acyclic causal graphs. Brafman and Domshlak (2003) designed a polynomial-time algorithm for solving planning problems with binary state variables and acyclic causalgraph of bounded indegree. Brafman and Domshlak (2006) identified conditions underwhich it is possible to factorize a planning problem into several subproblems and solvethe subproblems independently. They claimed that a planning problem is suitable forfactorization if its causal graph has bounded tree-width.The idea of using macros in planning is almost as old as planning itself (Fikes & Nilsson,1971). Minton (1985) developed an algorithm that measures the utility of plan fragmentsand stores them as macros if they are deemed useful. Korf (1987) showed that macros canexponentially reduce the search space size of a planning problem if chosen carefully. Vidal(2004) used relaxed plans generated while computing heuristics to produce macros thatcontribute to the solution of planning problems. Macro-FF (Botea, Enzenberger, M¨uller,& Schaeffer, 2005), an algorithm that identifies and caches macros, competed at the fourthInternational Planning Competition. The authors showed how macros can help reduce thesearch effort necessary to generate a valid plan.Jonsson (2007) described an algorithm that uses macros to generate plans for planningproblems with tree-reducible causal graphs. There exist planning problems for which thealgorithm can generate exponentially long solutions in polynomial time, just like our algo-rithm for . Unlike ours, the algorithm can handle multi-valued variables, which enables itto solve problems such as Towers of Hanoi. However, not all planning problems in havetree-reducible causal graphs, so the algorithm cannot be used to show that plan generationfor is polynomial. im´enez & Jonsson A contribution of this paper is to show that plan generation may be polynomial even whenplanning problems have exponential length minimal solutions, provided that solutions maybe expressed using a concise notation such as macros. We motivate this result below anddiscuss the consequences. Previously, it has been thought that plan generation for planningproblems with exponential length minimal solutions is harder than NP, since it is notknown whether problems in NP are intractable, but it is certain that we cannot generateexponential length output in polynomial time.However, for a planning problem with exponential length minimal solution, it is notclear if plan generation is inherently hard, or if the difficulty just lies in the fact that theplan is long. Consider the two functional problems f ( F ) = w ( , | F | ) ,f ( F ) = w ( t ( F ) , | F | ) , where F is a 3-CNF formula, | F | is the number of clauses of F , w ( σ, k ) is a word containing k copies of the symbol σ , and t ( F ) is if F is satisfiable (i.e., F is in ), and if it isnot. In both cases, the problem consists in generating the correct word. Observe that both f and f are provably intractable, since their output is exponential in the size of the input.Nevertheless, it is intuitive to regard problem f as easier than problem f . One wayto formalize this intuition is to allow programs to produce the output in some succinctnotation. For instance, if we allow programs to write “ w ( σ,k )” instead of a string containing k copies of the symbol σ , then problem f becomes polynomial, but problem f does not(unless P = NP).We wanted to investigate the following question: regarding the class , is plan genera-tion intractable because solution plans are long, like f , or because the problem is intrinsi-cally hard, like f ? The answer is that plan generation for can be solved in polynomialtime, provided that one is allowed to give the solution in terms of macros, where a macrois a simple substitution scheme: a sequence of operators and/or other macros. To back upthis claim, we present an algorithm that solves plan generation for in polynomial time.Other researchers have argued intractability using the fact that plans may have expo-nential length. Domshlak and Dinitz (2001) proved complexity results for several classes ofplanning problems with multi-valued state variables and simple causal graphs. They arguedthat the class C n of planning problems with chain causal graphs is intractable since plansmay have exponential length. Brafman and Domshlak (2003) stated that plan generationfor STRIPS planning problems with unary operators and acyclic causal graphs is intractableusing the same reasoning. Our new result puts in question the argument used to prove thehardness of these problems. For this reason, we analyze the complexity of these problemsand prove that they are hard by showing that the plan existence problem is NP-hard.
2. Notation
Let V be a set of state variables, and let D ( v ) be the finite domain of state variable v ∈ V .We define a state s as a function on V that maps each state variable v ∈ V to a value s ( v ) ∈ D ( v ) in its domain. A partial state p is a function on a subset V p ⊆ V of state omplexity of Planning Problems variables that maps each state variable v ∈ V p to p ( v ) ∈ D ( v ). For a subset C ⊆ V ofstate variables, p | C is the partial state obtained by restricting the domain of p to V p ∩ C .Sometimes we use the notation ( v = x , . . . , v k = x k ) to denote a partial state p defined by V p = { v , . . . , v k } and p ( v i ) = x i for each v i ∈ V p . We write p ( v ) = ⊥ to denote that v / ∈ V p .Two partial states p and q match, which we denote p ▽ q , if and only if p | V q = q | V p ,i.e., for each v ∈ V p ∩ V q , p ( v ) = q ( v ). We define a replacement operator ⊕ such that if q and r are two partial states, p = q ⊕ r is the partial state defined by V p = V q ∪ V r , p ( v ) = r ( v )for each v ∈ V r , and p ( v ) = q ( v ) for each v ∈ V q − V r . Note that, in general, p ⊕ q = q ⊕ p .A partial state p subsumes a partial state q , which we denote p ⊑ q , if and only if p ▽ q and V p ⊆ V q . We remark that if p ⊑ q and r ⊑ s , it follows that p ⊕ r ⊑ q ⊕ s . The differencebetween two partial states q and r , which we denote q − r , is the partial state p defined by V p = { v ∈ V q | q ( v ) = r ( v ) } and p ( v ) = q ( v ) for each v ∈ V p .A planning problem is a tuple P = h V, init, goal, A i , where V is the set of variables, init is an initial state, goal is a partial goal state, and A is a set of operators. An operator a = h pre ( a ); post ( a ) i ∈ A consists of a partial state pre ( a ) called the pre-condition and apartial state post ( a ) called the post-condition . Operator a is applicable in any state s suchthat s ▽ pre ( a ), and applying operator a in state s results in the new state s ⊕ post ( a ). Avalid plan Π for P is a sequence of operators that are sequentially applicable in state init such that the resulting state s ′ satisfies s ′ ▽ goal .The causal graph of a planning problem P is a directed graph ( V, E ) with state variablesas nodes. There is an edge ( u, v ) ∈ E if and only if u = v and there exists an operator a ∈ A such that u ∈ V pre ( a ) ∪ V post ( a ) and v ∈ V post ( a ) .
3. The Class 3S
Jonsson and B¨ackstr¨om (1998) introduced the class of planning problems to study therelative complexity of plan existence and plan generation. In this section, we introduceadditional notation needed to describe the class and illustrate some of the properties of planning problems. We begin by defining the class : Definition 3.1
A planning problem P belongs to the class if its causal graph is acyclicand each state variable v ∈ V is binary and either static, symmetrically reversible, orsplitting. Below, we provide formal definitions of static , symmetrically reversible and splitting .Note that the fact that the causal graph is acyclic implies that operators are unary, i.e., foreach operator a ∈ A , | V post ( a ) | = 1. Without loss of generality, we assume that planningproblems are in normal form , by which we mean the following: • For each state variable v , D ( v ) = { , } and init ( v ) = 0. • post ( a ) = ( v = x ), x ∈ { , } , implies that pre ( a )( v ) = 1 − x .To satisfy the first condition, we can relabel the values of D ( v ) in the initial and goalstates as well as in the pre- and post-conditions of operators. To satisfy the second condition,for any operator a with post ( a ) = ( v = x ) and pre ( a )( v ) = 1 − x , we either remove it if im´enez & Jonsson w =0 ww =1 v =0 v =0 v V v u st w V w V w w =0 ww =1 v =0 v =0 V w * v u stv u st (a) (b)Figure 1: Causal graph with splitting variable partitions for (a) v , (b) w . pre ( a )( v ) = x , or we let pre ( a )( v ) = 1 − x if previously undefined. The resulting planningproblem is in normal form and is equivalent to the original one. This process can be donein time O ( | A || V | ).The following definitions describe the three categories of state variables in : Definition 3.2
A state variable v ∈ V is static if and only if one of the following holds: There does not exist a ∈ A such that post ( a )( v ) = 1 , goal ( v ) = 0 and there does not exist a ∈ A such that post ( a )( v ) = 0 . Definition 3.3
A state variable v ∈ V is reversible if and only if for each a ∈ A such that post ( a ) = ( v = x ) , there exists a ′ ∈ A such that post ( a ′ ) = ( v = 1 − x ) . In addition, v is symmetrically reversible if pre ( a ′ ) | ( V − { v } ) = pre ( a ) | ( V − { v } ) . From the above definitions it follows that the value of a static state variable cannot ormust not change, whereas the value of a symmetrically reversible state variable can changefreely, as long as it is possible to satisfy the pre-conditions of operators that change itsvalue. The third category of state variables is splitting . Informally, a splitting state variable v splits the causal graph into three disjoint subgraphs, one which depends on the value v = 1, one which depends on v = 0, and one which is independent of v . However, theprecise definition is more involved, so we need some additional notation.For v ∈ V , let Q v be the subset of state variables, different from v , whose value ischanged by some operator that has v = 0 as a pre-condition. Formally, Q v = { u ∈ V − { v } |∃ a ∈ A s . t . pre ( a )( v ) = 0 ∧ u ∈ V post ( a ) } . Define Q v in the same way for v = 1. Let G v = ( V, E v ) be the subgraph of ( V, E ) whose edges exclude those between v and Q v − Q v .Formally, E v = E − { ( v, w ) | w ∈ Q v ∧ w / ∈ Q v } . Finally, let V v ⊆ V be the subset of statevariables that are weakly connected to some state variable of Q v in the graph G v . Define V v in the same way for v = 1. Definition 3.4
A state variable v ∈ V is splitting if and only if V v and V v are disjoint. Figure 1 illustrates the causal graph of a planning problem with two splitting statevariables, v and w . The edge label v = 0 indicates that there are operators for changingthe value of u that have v = 0 as a pre-condition. In other words, Q v = { u, w } , the graph G v = ( V, E v ) excludes the two edges labeled v = 0, and V v includes all state state variables, omplexity of Planning Problems since v is weakly connected to u and w connects to the remaining state variables. The set Q v is empty since there are no operators for changing the value of a state variable otherthan v with v = 1 as a pre-condition. Consequently, V v is empty as well. Figure 1(a) showsthe resulting partition for v .In the case of w , Q w = { s } , G w = ( V, E w ) excludes the edge labeled w = 0, and V w = { s } , since no other state variable is connected to s when the edge w = 0 is removed.Likewise, V w = { t } . We use V w ∗ = V − V w − V w to denote the set of remaining statevariables that belong neither to V w nor to V w . Figure 1(b) shows the resulting partitionfor w . Lemma 3.5
For any splitting state variable v , if the two sets V v and V v are non-empty, v belongs neither to V v nor to V v . Proof
By contradiction. Assume that v belongs to V v . Then v is weakly connected tosome state variable of Q v in the graph G v = ( V, E v ). But since E v does not exclude edgesbetween v and Q v , any state variable in Q v is weakly connected to the same state variable of Q v in G v . Consequently, state variables in Q v belong to both V v and V v , which contradictsthat v is splitting. The same reasoning holds to show that v does not belong to V v . Lemma 3.6
The value of a splitting state variable never needs to change more than twiceon a valid plan.
Proof
Assume Π is a valid plan that changes the value of a splitting state variable v atleast three times. We show that we can reorder the operators of Π in such a way that thevalue of v does not need to change more than twice. We need to address three cases: v belongs to V v (cf. Figure 1(a)), v belongs to V v , or v belongs to V v ∗ (cf. Figure 1(b)).If v belongs to V v , it follows from Lemma 3.5 that V v is empty. Consequently, nooperator in the plan requires v = 1 as a pre-condition. Thus, we can safely remove alloperators in Π that change the value of v , except possibly the last, which is needed in case goal ( v ) = 1. If v belongs to V v , it follows from Lemma 3.5 that V v is empty. Thus, nooperator in the plan requires v = 0 as a pre-condition. The first operator in Π that changesthe value of v is necessary to set v to 1. After that, we can safely remove all operators in Πthat change the value of v , except the last in case goal ( v ) = 0. In both cases the resultingplan contains at most two operators changing the value of v .If v belongs to V v ∗ , then the only edges between V v , V v , and V v ∗ are those from v ∈ V v ∗ to Q v ⊆ V v and Q v ⊆ V v . Let Π , Π , and Π ∗ be the subsequences of operators in Π thataffect state variables in V v , V v , and V v ∗ , respectively. Write Π ∗ = h Π ′∗ , a v , Π ′′∗ i , where a v isthe last operator in Π ∗ that changes the value of v from 0 to 1. We claim that the reordering h Π , Π ′∗ , a v , Π , Π ′′∗ i of plan Π is still valid. Indeed, the operators of Π only require v = 0,which holds in the initial state, and the operators of Π only require v = 1, which holdsdue to the operator a v . Note that all operators changing the value of v in Π ′∗ can be safelyremoved since the value v = 1 is never needed as a pre-condition to change the value of astate variable in V v ∗ . The result is a valid plan that changes the value of v at most twice(its value may be reset to 0 by Π ′′∗ ). im´enez & Jonsson Variable Operators V v i V v i v a v = h ( v = 0); ( v = 1) i V Va v = h ( v = 1); ( v = 0) i v a v = h ( v = 1 , v = 0); ( v = 1) i ∅ Vv a v = h ( v = 0 , v = 1 , v = 0); ( v = 1) i { v , v } { v , v , v } v V − { v } ∅ v a v = h ( v = 0 , v = 0 , v = 0); ( v = 1) i ∅ ∅ v a v = h ( v = 1 , v = 0); ( v = 1) i V Va v = h ( v = 1 , v = 1); ( v = 0) i v a v = h ( v = 1 , v = 0); ( v = 1) i ∅ Vv a v = h ( v = 0 , v = 1 , v = 0); ( v = 1) i ∅ ∅ Table 1: Operators and the sets V v i and V v i for the example planning problem. v v v v v v v v Figure 2: Causal graph of the example planning problem.The previous lemma, which holds for splitting state variables in general, provides someadditional insight into how to solve a planning problem with a splitting state variable v .First, try to achieve the goal state for state variables in V v while the value of v is 0, as inthe initial state. Then, set the value of v to 1 and try to achieve the goal state for statevariables in V v . Finally, if goal ( v ) = 0, reset the value of v to 0. We illustrate the class using an example planning problem. The set of state variablesis V = { v , . . . , v } . Since the planning problem is in normal form, the initial state is init ( v i ) = 0 for each v i ∈ V . The goal state is defined by goal = ( v = 1 , v = 1), andthe operators in A are listed in Table 1. Figure 2 shows the causal graph ( V, E ) of theplanning problem. From the operators it is easy to verify that v is static and that v and v are symmetrically reversible. For the planning problem to be in , the remainingstate variables have to be splitting. Table 1 lists the two sets V v i and V v i for each statevariable v i ∈ V to show that indeed, V v i ∩ V v i = ∅ for each of the state variables in the set { v , v , v , v , v } . omplexity of Planning Problems
4. Plan Generation for 3S
In this section, we present a polynomial-time algorithm for plan generation in . Thealgorithm produces a solution to any instance of in the form of a system of macros. Theidea is to construct unary macros that each change the value of a single state variable. Themacros may change the values of other state variables during execution, but always resetthem before terminating. Once the macros have been generated, the goal can be achievedone state variable at a time. We show that the algorithm generates a valid plan if and onlyif one exists.We begin by defining macros as we use them in the paper. Next, we describe thealgorithm in pseudo-code (Figures 3, 4, and 5) and prove its correctness. To facilitatereading we have moved a straightforward but involving proof to the appendix. Followingthe description of the algorithm we analyze the complexity of all steps involved. In whatfollows, we assume that planning problems are in normal form as defined in the previoussection. A macro-operator, or macro for short, is an ordered sequence of operators viewed as a unit.Each operator in the sequence has to respect the pre-conditions of operators that followit, so that no pre-condition of any operator in the sequence is violated. Applying a macrois equivalent to applying all operators in the sequence in the given order. Semantically,a macro is equivalent to a standard operator in that it has a pre-condition and a post-condition, unambiguously induced by the pre- and post-conditions of the operators in itssequence.Since macros are functionally operators, the operator sequence associated with a macrocan include other macros, as long as this does not create a circular definition. Consequently,it is possible to create hierarchies of macros in which the operator sequences of macros onone level include macros on the level below. The solution to a planning problem can itselfbe viewed as a macro which sits at the top of the hierarchy.To define macros we first introduce the concept of induced pre- and post-conditions ofoperator sequences. If Π = h a , . . . , a k i is an operator sequence, we write Π i , 1 ≤ i ≤ k , todenote the subsequence h a , . . . , a i i . Definition 4.1
An operator sequence
Π = h a , . . . , a k i induces a pre-condition pre (Π) = pre ( a k ) ⊕ · · · ⊕ pre ( a ) and a post-condition post (Π) = post ( a ) ⊕ · · · ⊕ post ( a k ) . In addition,the operator sequence is well-defined if and only if ( pre (Π i − ) ⊕ post (Π i − )) ▽ pre ( a i ) for each < i ≤ k . In what follows, we assume that P = ( V, init, goal, A ) is a planning problem such that V post ( a ) ⊆ V pre ( a ) for each operator a ∈ A , and that Π = h a , . . . , a k i is an operator sequence. Lemma 4.2
For each planning problem P of this type and each Π , V post (Π) ⊆ V pre (Π) . Proof
A direct consequence of the definitions V pre (Π) = V pre ( a ) ∪· · ·∪ V pre ( a k ) and V post (Π) = V post ( a ) ∪ · · · ∪ V post ( a k ) . im´enez & Jonsson Lemma 4.3
The operator sequence Π is applicable in state s if and only if Π is well-definedand s ▽ pre (Π) . The state s k resulting from the application of Π to s is s k = s ⊕ post (Π) . Proof
By induction on k . The result clearly holds for k = 1. For k >
1, note that pre (Π) = pre ( a k ) ⊕ pre (Π k − ), post (Π) = post (Π k − ) ⊕ post ( a k ), and Π is well-defined ifand only if Π k − is well-defined and ( pre (Π k − ) ⊕ post (Π k − )) ▽ pre ( a k ).By hypothesis of induction the state s k − resulting from the application of Π k − to s is s k − = s ⊕ post (Π k − ). It follows that s k = s k − ⊕ post ( a k ) = s ⊕ post (Π).Assume Π is applicable in state s . This means that Π k − is applicable in s and that a k is applicable in s k − = s ⊕ post (Π k − ). By hypothesis of induction, the former implies that s ▽ pre (Π k − ) and Π k − is well-defined, and the latter that ( s ⊕ post (Π k − )) ▽ pre ( a k ). Thislast condition implies that ( pre (Π k − ) ⊕ post (Π k − )) ▽ pre ( a k ) if we use that pre (Π k − ) ⊑ s ,which is a consequence of s ▽ pre (Π k − ) and s being a total state. Finally, we deduce s ▽ ( pre ( a k ) ⊕ pre (Π k − )) from s ▽ pre (Π k − ) and ( s ⊕ post (Π k − )) ▽ pre ( a k ), by using that V post (Π k − ) ⊆ V pre (Π k − ) . It follows that Π is well-defined and that s ▽ pre (Π).Conversely, assume that Π is well-defined and s ▽ pre (Π). This implies that Π k − iswell-defined and s ▽ pre (Π k − ), so by hypothesis of induction, Π k − is applicable in state s .It remains to show that a k is applicable in state s k − , that is, ( s ⊕ post (Π k − )) ▽ pre ( a k ).From ( pre (Π k − ) ⊕ post (Π k − )) ▽ pre ( a k ) it follows that post (Π k − ) ▽ pre ( a k ). The fact that s ▽ ( pre ( a k ) ⊕ pre (Π k − )) and V post (Π k − ) ⊆ V pre (Π k − ) completes the proof.Since macros have induced pre- and post-conditions, Lemmas 4.2 and 4.3 trivially extendto the case for which the operator sequence Π includes macros. Now we are ready tointroduce our definition of macros: Definition 4.4
A macro m is a sequence Π = h a , . . . , a k i of operators and other macrosthat induces a pre-condition pre ( m ) = pre (Π) and a post-condition post ( m ) = post (Π) − pre (Π) . The macro is well-defined if and only if no circular definitions occur and Π iswell-defined. To make macros consistent with standard operators, the induced post-condition shouldonly include state variables whose values are indeed changed by the macro, which is achievedby computing the difference between post (Π) and pre (Π). In particular, it holds that for a planning problem in normal form, derived macros satisfy the second condition of normalform, namely that post ( m ) = ( v = x ), x ∈ { , } , implies pre ( m )( v ) = 1 − x . Definition 4.5
Let
Anc v be the set of ancestors of a state variable v in a planningproblem. We define the partial state pre v on V pre v = Anc v as1. pre v ( u ) = 1 if u ∈ Anc v is splitting and v ∈ V u ,2. pre v ( u ) = 0 otherwise. Definition 4.6
A macro m is a -macro if it is well-defined and, for x ∈ { , } , post ( m ) =( v = x ) and pre ( m ) ⊑ pre v ⊕ ( v = 1 − x ) . omplexity of Planning Problems Macro Sequence Pre-condition Post-condition m v h a v i ( v = 0) ( v = 1) m v h a v i ( v = 1) ( v = 0) m v h m v , a v , m v i ( v = 0 , v = 0) ( v = 1) m v h a v i ( v = 0 , v = 1 , v = 0) ( v = 1) m v h a v i ( v = 0 , v = 0 , v = 0) ( v = 1) m v h a v i ( v = 1 , v = 0) ( v = 1) m v h a v i ( v = 1 , v = 1) ( v = 0) m v h m v , a v , m v i ( v = 1 , v = 0 , v = 0) ( v = 1) m v h a v i ( v = 1 , v = 0 , v = 1 , v = 0) ( v = 1)Table 2: Macros generated by the algorithm in the example planning problem.The algorithm we present only generates -macros. In fact, it generates at most onemacro m = m vx with post ( m ) = ( v = x ) for each state variable v and value x ∈ { , } . Toillustrate the idea of -macros and give a flavor of the algorithm, Table 2 lists the macrosgenerated by the algorithm in the example planning problem from the previous section.We claim that each macro is a -macro. For example, the operator sequence h a v i induces a pre-condition ( v = 1 , v = 0) and a post-condition ( v = 1 , v = 0) ⊕ ( v = 1) =( v = 1 , v = 1). Thus, the macro m v induces a pre-condition pre ( m v ) = ( v = 1 , v = 0)and a post-condition post ( m v ) = ( v = 1 , v = 1) − ( v = 1 , v = 0) = ( v = 1). Since v and v are splitting and since v ∈ V v and v ∈ V v , it follows that pre v ⊕ ( v = 0) =( v = 0 , v = 1 , v = 1 , v = 0), so pre ( m v ) = ( v = 1 , v = 0) ⊑ pre v ⊕ ( v = 0).The macros can be combined to produce a solution to the planning problem. The ideais to identify each state variable v such that goal ( v ) = 1 and append the macro m v to thesolution plan. In the example, this results in the operator sequence h m v , m v i . However,the pre-condition of m v specifies v = 1 and v = 1, which makes it necessary to insert m v and m v before m v . In addition, the pre-condition of m v specifies v = 1, which makesit necessary to insert m v before m v , resulting in the final plan h m v , m v , m v , m v , m v i .Note that the order of the macros matter; m v requires v to be 0 while m v requires v to be 1. For a splitting state variable v , the goal state should be achieved for statevariables in V v before the value of v is set to 1. We can expand the solution plan so thatit consists solely of operators in A . In our example, this results in the operator sequence h a v , a v , a v , a v , a v , a v , a v , a v , a v i . In this case, the algorithm generates an optimalplan, although this is not true in general. We proceed by providing a detailed description of the algorithm for plan generation in .We first describe the subroutine for generating a unary macro that sets the value of a statevariable v to x . This algorithm, which we call GenerateMacro , is described in Figure 3.The algorithm takes as input a planning problem P , a state variable v , a value x (either 0 im´enez & Jonsson function GenerateMacro ( P , v , x , M )2 for each a ∈ A such that post ( a )( v ) = x do S ← S ← hi satisf y ← true5 U ← { u ∈ V pre ( a ) − { v } | pre ( a )( u ) = 1 } for each u ∈ U in increasing topological order do if u is static or m u / ∈ M then satisf y ← false9 else if u is not splitting and m u ∈ M and m u ∈ M then S ← h S , m u i S ← h m u , S i if satisf y then return h S , a, S i return f ail Figure 3: Algorithm for generating a macro that sets the value of v to x .or 1), and a set of macros M for v ’s ancestors in the causal graph. Prior to executing thealgorithm, we perform a topological sort of the state variables. We assume that, for each v ∈ V and x ∈ { , } , M contains at most one macro m vx such that post ( m vx ) = ( v = x ). Inthe algorithm, we use the notation m vx ∈ M to test whether or not M contains m vx .For each operator a ∈ A that sets the value of v to x , the algorithm determines whetherit is possible to satisfy its pre-condition pre ( a ) starting from the initial state. To do this, thealgorithm finds the set U of state variables to which pre ( a ) assigns 1 (the values of all otherstate variables already satisfy pre ( a ) in the initial state). The algorithm constructs twosequences of operators, S and S , by going through the state variables of U in increasingtopological order. If S is an operator sequence, we use h S, o i as shorthand to denote anoperator sequence of length | S | + 1 consisting of all operators of S followed by o , which canbe either an operator or a macro. If it is possible to satisfy the pre-condition pre ( a ) of someoperator a ∈ A , the algorithm returns the macro h S , a, S i . Otherwise, it returns f ail . Lemma 4.7 If v is symmetrically reversible and GenerateMacro ( P , v , 1, M ) success-fully generates a macro, so does GenerateMacro ( P , v , 0, M ). Proof
Assume that
GenerateMacro ( P , v , 1, M ) successfully returns the macro h S , a, S i for some operator a ∈ A such that post ( a ) = 1. From the definition of symmetricallyreversible it follows that there exists an operator a ′ ∈ A such that post ( a ′ ) = 0 and pre ( a ′ ) | V − { v } = pre ( a ) | V − { v } . Thus, the set U is identical for a and a ′ . Asa consequence, the values of S , S , and satisf y are the same after the loop, whichmeans that GenerateMacro ( P , v , 0, M ) returns the macro h S , a ′ , S i for a ′ . Notethat GenerateMacro ( P , v , 0, M ) may return another macro if it goes through the op-erators of A in a different order; however, it is guaranteed to successfully return a macro. Theorem 4.8
If the macros in M are -macros and GenerateMacro ( P , v , x , M )generates a macro m vx = f ail , then m vx is a -macro. omplexity of Planning Problems function Macro-3S ( P )2 M ← ∅ for each v ∈ V in increasing topological order do m v ← GenerateMacro ( P , v , 1, M )5 m v ← GenerateMacro ( P , v , 0, M )6 if m v = f ail and m v = f ail then M ← M ∪ { m v , m v } else if m v = f ail and goal ( v ) = 0 then M ← M ∪ { m v } return GeneratePlan ( P , V , M )Figure 4: The algorithm Macro-3S .The proof of Theorem 4.8 appears in Appendix A.Next, we describe the algorithm for plan generation in , which we call Macro-3S .Figure 4 shows pseudocode for
Macro-3S . The algorithm goes through the state variablesin increasing topological order and attempts to generate two macros for each state variable v , m v and m v . If both macros are successfully generated, they are added to the currentset of macros M . If only m v is generated and the goal state does not assign 0 to v , thealgorithm adds m v to M . Finally, the algorithm generates a plan using the subroutine GeneratePlan , which we describe later.
Lemma 4.9
Let P be a planning problem and let v ∈ V be a state variable. If thereexists a valid plan for solving P that sets v to 1, Macro-3S ( P ) adds the macro m v to M .If, in addition, the plan resets v to 0, Macro-3S ( P ) adds m v to M . Proof
First note that if m v and m v are generated, Macro-3S ( P ) adds them both to M .If m v is generated but not m v , Macro-3S ( P ) adds m v to M unless goal ( v ) = 0. However, goal ( v ) = 0 contradicts the fact that there is a valid plan for solving P that sets v to 1without resetting it to 0. It remains to show that GenerateMacro ( P , v , 1, M ) alwaysgenerates m v = f ail and that GenerateMacro ( P , v , 0, M ) always generates m v = f ail if the plan resets v to 0.A plan for solving P that sets v to 1 has to contain an operator a ∈ A such that post ( a )( v ) = 1. If the plan also resets v to 0, it has to contain an operator a ′ ∈ A suchthat post ( a ′ )( v ) = 0. We show that GenerateMacro ( P , v , 1, M ) successfully generates m v = f ail if a is the operator selected on line 2. Note that the algorithm may return anothermacro if it selects another operator before a ; however, if it always generates a macro for a ,it is guaranteed to successfully return a macro m v = f ail . The same is true for m v and a ′ .We prove the lemma by induction on state variables v . If v has no ancestors in thecausal graph, the set U is empty by default. Thus, satisf y is never set to false and GenerateMacro ( P , v , 1, M ) successfully returns the macro m v = h a i for a . If a ′ exists, GenerateMacro ( P , v , 0, M ) successfully returns m v = h a ′ i for a ′ .If v has ancestors in the causal graph, let U = { u ∈ V pre ( a ) − { v } | pre ( a )( u ) = 1 } .Since the plan contains a it has to set each u ∈ U to 1. By hypothesis of induction, Macro-3S ( P ) adds m u to M for each u ∈ U . As a consequence, satisf y is never set to im´enez & Jonsson function GeneratePlan ( P , W , M )2 if | W | = 0 then return hi v ← first variable in topological order present in W if v is splitting then v ← Generate-Plan ( P , W ∩ ( V v − { v } ), M )7 Π v ← Generate-Plan ( P , W ∩ ( V v − { v } ), M )8 Π v ∗ ← Generate-Plan ( P , W ∩ ( V − V v − V v − { v } ), M )9 if Π v = f ail or Π v = f ail or Π v ∗ = f ail or ( goal ( v ) = 1 and m v / ∈ M ) then return f ail else if m v / ∈ M then return h Π v ∗ , Π v , Π v i else if goal ( v ) = 0 then return h Π v ∗ , Π v , m v , Π v , m v i else return h Π v ∗ , Π v , m v , Π v i
14 Π ← Generate-Plan ( P , W − { v } , M )15 if Π = f ail or ( goal ( v ) = 1 and m v / ∈ M ) then return f ail else if goal ( v ) = 1 then return h Π , m v i else return ΠFigure 5: Algorithm for generating the final planfalse and thus,
GenerateMacro ( P , v , 1, M ) successfully returns m v for a . If a ′ exists,let W = { w ∈ V pre ( a ′ ) − { v } | pre ( a ′ )( w ) = 1 } . If the plan contains a ′ , it has to set each w ∈ W to 1. By hypothesis of induction, Macro-3S ( P ) adds m w to M for each w ∈ W and consequently, GenerateMacro ( P , v , 0, M ) successfully returns m v for a ′ .Finally, we describe the subroutine GeneratePlan ( P , W , M ) for generating the finalplan given a planning problem P , a set of state variables W and a set of macros M . Ifthe set of state variables is empty, GeneratePlan ( P , W , M ) returns an empty operatorsequence. Otherwise, it finds the state variable v ∈ W that comes first in topological order.If v is splitting, the algorithm separates W into the three sets described by V v , V v , and V v ∗ = V − V v − V v . The algorithm recursively generates plans for the three sets and ifnecessary, inserts m v between V v and V v in the final plan. If this is not the case, thealgorithm recursively generates a plan for W − { v } . If goal ( v ) = 1 and m v , the algorithmappends m v to the end of the resulting plan. Lemma 4.10
Let Π W be the plan generated by GeneratePlan ( P , W , M ), let v be thefirst state variable in topological order present in W , and let Π V = h Π a , Π W , Π b i be the finalplan generated by Macro-3S ( P ). If m v ∈ M it follows that ( pre (Π a ) ⊕ post (Π a )) ▽ pre ( m v ) . Proof
We determine the content of the operator sequence Π a that precedes Π W in the finalplan by inspection. Note that the call GeneratePlan ( P , W , M ) has to be nested withina sequence of recursive calls to GeneratePlan starting with
GeneratePlan ( P , V , M ).Let Z be the set of state variables such that each u ∈ Z was the first state variable intopological order for some call to GeneratePlan prior to
GeneratePlan ( P , W , M ).Each u ∈ Z has to correspond to a call to GeneratePlan with some set of state variables U such that W ⊂ U . If u is not splitting, u does not contribute to Π a since the only omplexity of Planning Problems possible addition of a macro to the plan on line 16 places the macro m u at the end of theplan generated recursively.Assume that u ∈ Z is a splitting state variable. We have three cases: W ⊆ V u , W ⊆ V u ,and W ⊆ V u ∗ = V − V u − V u . If W ⊆ V u ∗ , u does not contribute to Π a since it never placesmacros before Π u ∗ . If W ⊆ V u , the plan Π u ∗ is part of Π a since it precedes Π u on lines 11,12, and 13. If W ⊆ V u , the plans Π u ∗ and Π u are part of Π a since they both precede Π u inall cases. If m u ∈ M , the macro m u is also part of Π a since it precedes Π u on lines 12 and13. No other macros are part of Π a .Since the macros in M are unary, the plan generated by GeneratePlan ( P , U , M )only changes the values of state variables in U . For a splitting state variable u , there areno edges from V u ∗ − { u } to V u , from V u ∗ − { u } to V u , or from V u to V u . It follows that theplan Π u ∗ does not change the value of any state variable that appears in the pre-conditionof a macro in Π u . The same holds for Π u ∗ with respect to Π u and for Π u with respect to Π u .Thus, the only macro in Π a that changes the value of a splitting state variable u ∈ Anc v is m u in case W ⊆ V u .Recall that pre v is defined on Anc v and assigns 1 to u if and only if u is splitting and v ∈ V u . For all other ancestors of v , the value 0 holds in the initial state and is notaltered by Π a . If u is splitting and v ∈ V u , it follows from the definition of -macros that pre ( m v )( u ) = 1 or pre ( m v )( u ) = ⊥ . If pre ( m v )( u ) = 1, it is correct to append m u before m v to satisfy pre ( m v )( u ). If m u / ∈ M it follows that u / ∈ V pre ( m v ) , since pre ( m v )( u ) = 1would have caused GenerateMacro ( P , v , 1, M ) to set satisf y to false on line 8. Thus,the pre-condition pre ( m v ) of m v agrees with pre (Π a ) ⊕ post (Π a ) on the value of each statevariable, which means that the two partial states match. Lemma 4.11
GeneratePlan ( P , V , M ) generates a well-defined plan. Proof
Note that for each state variable v ∈ V , GeneratePlan ( P , W , M ) is calledprecisely once such that v is the first state variable in topological order. From Lemma 4.10it follows that ( pre (Π a ) ⊕ post (Π a )) ▽ pre ( m v ), where Π a is the plan that precedes Π W inthe final plan. Since v is the first state variable in topological order in W , the plans Π v ,Π v , Π v ∗ , and Π, recursively generated by GeneratePlan , do not change the value of anystate variable in pre ( m v ). It follows that m v is applicable following h Π a , Π v ∗ , Π v i or h Π a , Π i .Since m v only changes the value of v , m v is applicable following h Π a , Π v ∗ , Π v , m v , Π v i . Theorem 4.12
Macro-3S ( P ) generates a valid plan for solving a planning problem in if and only if one exists. Proof
GeneratePlan ( P , V , M ) returns f ail if and only if there exists a state variable v ∈ V such that goal ( v ) = 1 and m v / ∈ M . From Lemma 4.9 it follows that there doesnot exist a valid plan for solving P that sets v to 1. Consequently, there does not exist aplan for solving P . Otherwise, GeneratePlan ( P , V , M ) returns a well-defined plan dueto Lemma 4.11. Since the plan sets to 1 each state variable v such that goal ( v ) = 1 andresets to 0 each state variable v such that goal ( v ) = 0, the plan is a valid plan for solvingthe planning problem. im´enez & Jonsson v v v v v Figure 6: Causal graph of the planning problem P . We illustrate the algorithm on an example introduced by Jonsson and B¨ackstr¨om (1998) toshow that there are instances of with exponentially sized minimal solutions. Let P n = h V, init, goal, A i be a planning problem defined by a natural number n , V = { v , . . . , v n } ,and a goal state defined by V goal = V , goal ( v i ) = 0 for each v i ∈ { v , . . . , v n − } , and goal ( v n ) = 1. For each state variable v i ∈ V , there are two operators in A : a v i = h ( v = 0 , . . . , v i − = 0 , v i − = 1 , v i = 0); ( v i = 1) i ,a v i = h ( v = 0 , . . . , v i − = 0 , v i − = 1 , v i = 1); ( v i = 0) i . In other words, each state variable is symmetrically reversible. The causal graph of the plan-ning problem P is shown in Figure 6. Note that for each state variable v i ∈ { v , . . . , v n − } , pre ( a v i +1 )( v i ) = 1 and pre ( a v i +2 )( v i ) = 0, so v i +1 ∈ Q v i and v i +2 ∈ Q v i . Since there isan edge in the causal graph between v i +1 and v i +2 , no state variable in { v , . . . , v n − } issplitting. On the other hand, v n − and v n are splitting since V v n − = ∅ and V v n = V v n = ∅ .B¨ackstr¨om and Nebel (1995) showed that the length of the shortest plan solving P n is 2 n − v i ∈ { v , . . . , v n − } , our algorithm generates two macros m v i and m v i . There is a single operator, a v i , that changes the value of v i from 0 to 1. pre ( a v i )only assigns 1 to v i − , so U = { v i − } . Since v i − is not splitting, m v i is defined as m v i = h m v i − , a v i , m v i − i . Similarly, m v i is defined as m v i = h m v i − , a v i , m v i − i . For state variable v n , U = { v n − } , which is splitting, so m v n is defined as m v n = h a v n i .To generate the final plan, the algorithm goes through the state variables in topolog-ical order. For state variables v through v n − , the algorithm does nothing, since thesestate variables are not splitting and their goal state is not 1. For state variable v n − ,the algorithm recursively generates the plan for v n , which is h m v n i since goal ( v n ) = 1.Since goal ( v n − ) = 0, the algorithm inserts m v n − before m v n to satisfy its pre-condition v n − = 1 and m v n − after m v n to achieve the goal state goal ( v n − ) = 0. Thus, the final planis h m v n − , m v n , m v n − i . If we expand the plan, we end up with a sequence of 2 n − with polynomial lengthsolutions for which our algorithm may generate exponential length solutions. To do this,we modify the planning problem P n by letting goal ( v i ) = 1 for each v i ∈ V . In addition,for each state variable v i ∈ V , we add two operators to A : b v i = h ( v = 1 , . . . , v i − = 1 , v i = 0); ( v i = 1) i ,b v i = h ( v = 1 , . . . , v i − = 1 , v i = 1); ( v i = 0) i . omplexity of Planning Problems We also add an operator c v n = h ( v n − = 0 , v n = 0); ( v n = 1) i to A . As a conse-quence, state variables in { v , . . . , v n − } are still symmetrically reversible but not splitting. v n − is also symmetrically reversible but no longer splitting, since pre ( a v n )( v n − ) = 1 and pre ( c v n )( v n − ) = 0 implies that v n ∈ V v n − ∩ V v n − . v n is still splitting since V v n = V v n = ∅ .Assume that GenerateMacro ( P , v i , x , M ) always selects b v i x first. As a consequence, foreach state variable v i ∈ V and each x ∈ { , } , GenerateMacro ( P , v i , x , M ) generatesthe macro m v i x = h m v i − , . . . , m v , b v i x , m v , . . . , m v i − i .Let L i be the length of the plan represented by m v i x , x ∈ { , } . From the definition of m v i x above we have that L i = 2( L + . . . + L i − ) + 1. We show by induction that L i = 3 i − .The length of any macro for v is L = 1 = 3 . For i > L i = 2(3 + . . . + 3 i − ) + 1 = 2 3 i − − − i − −
12 + 1 = 3 i − − i − . To generate the final plan the algorithm has to change the value of each state variablefrom 0 to 1, so the total length of the plan is L = L + . . . + L n = 3 + . . . + 3 n − =(3 n − /
2. However, there exists a plan of length n that solves the planning problem,namely h b v , . . . , b v n i . In this section we prove that the complexity of our algorithm is polynomial. To do thiswe analyze each step of the algorithm separately. A summary of the complexity result foreach step of the algorithm is given below. Note that the number of edges | E | in the causalgraph is O ( | A || V | ), since each operator may introduce O ( | V | ) edges. The complexity result O ( | V | + | E | ) = O ( | A || V | ) for topological sort follows from Cormen, Leiserson, Rivest, andStein (1990).Constructing the causal graph G = ( V, E ) O ( | A || V | ) Lemma 4.13Calculating V v and V v for each v ∈ V O ( | A || V | ) Lemma 4.14Performing a topological sort of G O ( | A || V | ) GenerateMacro ( P , v , x , M ) O ( | A || V | ) Lemma 4.15 GeneratePlan ( P , V , M ) O ( | V | ) Lemma 4.16 Macro-3S ( P ) O ( | A || V | ) Theorem 4.17 Lemma 4.13
The complexity of constructing the causal graph G = ( V, E ) is O ( | A || V | ) . Proof
The causal graph consists of | V | nodes. For each operator a ∈ A and each statevariable u ∈ V pre ( a ) , we should add an edge from u to the unique state variable v ∈ V post ( a ) .In the worst case, | V pre ( a ) | = O ( | V | ), in which case the complexity is O ( | A || V | ). Lemma 4.14
The complexity of calculating the sets V v and V v for each state variable v ∈ V is O ( | A || V | ) . Proof
For each state variable v ∈ V , we have to establish the sets Q v and Q v , which requiresgoing through each operator a ∈ A in the worst case. Note that we are only interested inthe pre-condition on v and the unique state variable in V post ( a ) , which means that we do not im´enez & Jonsson need to go through each state variable in V pre ( a ) . Next, we have to construct the graph G v .We can do this by copying the causal graph G , which takes time O ( | A || V | ), and removingthe edges between v and Q v − Q v , which takes time O ( | V | ).Finally, to construct the set V v we should find each state variable that is weakly con-nected to some state variable u ∈ Q v in the graph G v . For each state variable u ∈ Q v ,performing an undirected search starting at u takes time O ( | A || V | ). Once we have per-formed search starting at u , we only need to search from state variables in Q v that werenot reached during the search. This way, the total complexity of the search does not exceed O ( | A || V | ). The case for constructing V v is identical. Since we have to perform the sameprocedure for each state variable v ∈ V , the total complexity of this step is O ( | A || V | ). Lemma 4.15
The complexity of
GenerateMacro ( P , v , x , M ) is O ( | A || V | ) . Proof
For each operator a ∈ A , GenerateMacro ( P , v , x , M ) needs to check whether post ( a )( v ) = x . In the worst case, | U | = O ( | V | ), in which case the complexity of thealgorithm is O ( | A || V | ). Lemma 4.16
The complexity of
GeneratePlan ( P , V , M ) is O ( | V | ) . Proof
Note that for each state variable v ∈ V , GeneratePlan ( P , V , M ) is called re-cursively exactly once such that v is the first variable in topological order. In other words, GeneratePlan ( P , V , M ) is called exactly | V | times. GeneratePlan ( P , V , M ) containsonly constant operations except the intersection and difference between sets on lines 6-8.Since intersection and set difference can be done in time O ( | V | ), the total complexity of GeneratePlan ( P , V , M ) is O ( | V | ). Theorem 4.17
The complexity of
Macro-3S ( P ) is O ( | A || V | ) . Proof
Prior to executing
Macro-3S ( P ), it is necessary to construct the causal graph G ,find the sets V v and V v for each state variable v ∈ V , and perform a topological sortof G . We have shown that these steps take time O ( | A || V | ). For each state variable v ∈ V , Macro-3S ( P ) calls GenerateMacro ( P , v , x , M ) twice. From Lemma 4.15 itfollows that this step takes time O (2 | V || A || V | ) = O ( | A || V | ). Finally, Macro-3S ( P ) calls GeneratePlan ( P , V , M ), which takes time O ( | V | ) due to Lemma 4.16. It follows thatthe complexity of Macro-3S ( P ) is O ( | A || V | ).We conjecture that it is possible to improve the above complexity result for Macro-3S ( P ) to O ( | A || V | ). However, the proof seems somewhat complex, and our main objectiveis not to devise an algorithm that is as efficient as possible. Rather, we are interested inestablishing that our algorithm is polynomial, which follows from Theorem 4.17. In this section we study the length of the plans generated by the given algorithm. To beginwith, we derive a general bound on the length of such plans. Then, we show how to computethe actual length of some particular plan without expanding its macros. We also presentan algorithm that uses this computation to efficiently obtain the i -th action of the plan omplexity of Planning Problems from its macro form. We start by introducing the concept of depth of state variables in thecausal graph. Definition 4.18
The depth d ( v ) of a state variable v is the longest path from v to anyother state variable in the causal graph. Since the causal graph is acyclic for planning problems in , the depth of each state variableis unique and can be computed in polynomial time. Also, it follows that at least one statevariable has depth 0, i.e., no outgoing edges. Definition 4.19
The depth d of a planning problem P in equals the largest depth ofany state variable v of P , i.e., d = max v ∈ V d ( v ) . We characterize a planning problem based on the depth of each of its state variables. Let n = | V | be the number of state variables, and let c i denote the number of state variableswith depth i . If the planning problem has depth d , it follows that c + . . . + c d = n . As anexample, consider the planning problem whose causal graph appears in Figure 2. For thisplanning problem, n = 8, d = 5, c = 2, c = 2, c = 1, c = 1, c = 1, and c = 1. Lemma 4.20
Consider the values L i for i ∈ { , . . . , d } defined by L d = 1 , and L i =2( c i +1 L i +1 + c i +2 L i +2 + . . . + c d L d ) + 1 when i < d . The values L i are an upper bound onthe length of macros generated by our algorithm for a state variable v with depth i . Proof
We prove it by a decreasing induction on the value of i . Assume v has depth i = d .It follows from Definition 4.18 that v has no incoming edges. Thus, an operator changingthe value of v has no pre-condition on any state variable other than v , so L d = 1 is an upperbound, as stated.Now, assume v has depth i < d , and that all L i + k for k > a ∈ A be an operator that changes the value of v .From the definition of depth it follows that a cannot have a pre-condition on a state variable u with depth j ≤ i ; otherwise there would be an edge from u to v in the causal graph, causingthe depth of u to be greater than i . Thus, in the worst case, a macro for v has to changethe values of all state variables with depths larger than i , change the value of v , and resetthe values of state variables at lower levels. It follows that L i = 2( c i +1 L i +1 + . . . + c d L d ) + 1is an upper bound. Theorem 4.21
The upper bounds L i of Lemma 4.20 satisfy L i = Π dj = i +1 (1 + 2 c j ) . Proof
Note that L i = 2( c i +1 L i +1 + c i +2 L i +2 + . . . + c d L d ) + 1 == 2 c i +1 L i +1 + 2( c i +2 L i +2 + . . . + c d L d ) + 1 == 2 c i +1 L i +1 + L i +1 = (2 c i +1 + 1) L i +1 . The result easily follows by induction. im´enez & Jonsson
Now we can obtain an upper bound L on the total length of the plan. In the worstcase, the goal state assigns a different value to each state variable than the initial state,i.e., goal ( v ) = init ( v ) for each v ∈ V . To achieve the goal state the algorithm applies onemacro per state variable. Hence L = c L + c L + . . . + c d L d = c L + L −
12 = (1 + 2 c ) L −
12 = 12 d Y j =0 (1 + 2 c j ) − . The previous bound depends on the distribution of the variables on depths accordingto the causal graph. To obtain a general bound that does not depend on the depths of thevariables we first find which distribution maximizes the upper bound L . Lemma 4.22
The upper bound L = Q dj =0 (1+2 c j ) − on planning problems on n variablesand depth d is maximized when all c i are equal, that is, c i = n/ ( d + 1) . Proof
Note that c i > i , and that c + · · · + c d = n . The result follows from a directapplication of the well known AM-GM (arithmetic mean-geometric mean) inequality, whichstates that the arithmetic mean of positive values x i is greater or equal than its geometricmean, with equality only when all x i are the same. This implies that the product of positivefactors x i = (1 + 2 c i ) with fixed sum A = P dj =0 x j = 2 n + d is maximized when all areequal, that is, c i = n/ ( d + 1). Theorem 4.23
The length of a plan generated by the algorithm for a planning problem in with n state variables and depth d is at most ((1 + 2 n/ ( d + 1)) d +1 − / . Proof
This is a direct consequence of Lemma 4.22. Since c , . . . , c d are discrete, it may notbe possible to set c = . . . = c d = n/ ( d + 1). Nevertheless, ((1 + 2 n/ ( d + 1)) d +1 − / L in this case.Observe that the bound established in Theorem 4.23 is an increasing function of d . Thisimplies that for a given d , the bound also applies to planning problems in with depthsmaller than d . As a consequence, if the depth of a planning problem in is boundedfrom above by d , our algorithm generates a solution plan for the planning problem withpolynomial length O ( n d +1 ). Since the complexity of executing a plan is proportional tothe plan length, we can use the depth d to define tractable complexity classes of planningproblems in with respect to plan execution. Theorem 4.24
The length of a plan generated by the algorithm for a planning problem in with n state variables is at most (3 n − / . Proof
In the worst case, the depth d of a planning problem is n −
1. It follows from Theorem4.23 that the length of a plan is at most ((1 + 2 n/n ) n − / n − / n − / omplexity of Planning Problems function Operator ( S , i )2 o ← first operator in S while length ( o ) < i do i ← i − length ( o )5 o ← next operator in S if primitive ( o ) then return o else return Operator ( o , i )Figure 7: An algorithm for determining the i -th operator in a sequence Lemma 4.25
The complexity of computing the total length of any plan generated by ouralgorithm is O ( | V | ) . Proof
The algorithm generates at most 2 | V | = O ( | V | ) macros, 2 for each state variable. Theoperator sequence of each macro consists of one operator and at most 2( | V | −
1) = O ( | V | )other macros. We can use dynamic programming to avoid computing the length of a macromore than once. In the worst case, we have to compute the length of O ( | V | ) macros, eachof which is a sum of O ( | V | ) terms, resulting in a total complexity of O ( | V | ). Lemma 4.26
Given a solution plan of length l and an integer ≤ i ≤ l , the complexity ofdetermining the i -th operator of the plan is O ( | V | ) . Proof
We prove the lemma by providing an algorithm for determining the i -th operator,which appears in Figure 7. Since operator sequences S consist of operators and macros,the variable o represents either an operator in A or a macro generated by Macro-3S . Thefunction primitive ( o ) returns true if o is an operator and f alse if o is a macro. The function length ( o ) returns the length of o if o is a macro, and 1 otherwise. We assume that the lengthof macros have been pre-computed, which we know from Lemma 4.25 takes time O ( | V | ).The algorithm simply finds the operator or macro at the i -th position of the sequence,taking into account the length of macros in the sequence. If the i -th position is part ofa macro, the algorithm recursively finds the operator at the appropriate position in theoperator sequence represented by the macro. In the worst case, the algorithm has to gothrough O ( | V | ) operators in the sequence S and call Operator recursively O ( | V | ) times,resulting in a total complexity of O ( | V | ). The general view of plan generation is that an output should consist in a valid sequence ofgrounded operators that solves a planning problem. In contrast, our algorithm generates asolution plan in the form of a system of macros. One might argue that to truly solve theplan generation problem, our algorithm should expand the system of macros to arrive at thesequence of underlying operators. In this case, the algorithm would no longer be polynomial,since the solution plan of a planning problem in may have exponential length. In fact, ifthe only objective is to execute the solution plan once, our algorithm offers only marginalbenefit over the incremental algorithm proposed by Jonsson and B¨ackstr¨om (1998). im´enez & Jonsson On the other hand, there are several reasons to view the system of macros generated byour algorithm as a complete solution to a planning problem in . The macros collectivelyspecify all the steps necessary to reach the goal. The solution plan can be generated andverified in polynomial time, and the plan can be stored and reused using polynomial memory.It is even possible to compute the length of the resulting plan and determine the i -thoperator of the plan in polynomial time as shown in Lemmas 4.25 and 4.26. Thus, for allpractical purposes the system of macros represents a complete solution. Even if the onlyobjective is to execute the solution plan once, our algorithm should be faster than that ofJonsson and B¨ackstr¨om (1998). All that is necessary to execute a plan generated by ouralgorithm is to maintain a stack of currently executing macros and select the next operatorto execute, whereas the algorithm of Jonsson and B¨ackstr¨om has to perform several stepsfor each operator output.Jonsson and B¨ackstr¨om (1998) proved that the bounded plan existence problem for is NP-hard. The bounded plan existence problem is the problem of determining whether ornot there exists a valid solution plan of length at most k . As a consequence, the optimalplan generation problem for is NP-hard as well; otherwise, it would be possible tosolve the bounded plan existence problem by generating an optimal plan and comparingthe length of the resulting plan to k . In our examples we have seen that our algorithmdoes not generate an optimal plan in general. In fact, our algorithm is just as bad as theincremental algorithm of Jonsson and B¨ackstr¨om, in the sense that both algorithms maygenerate exponential length plans even though there exists a solution of polynomial length.Since our algorithm makes it possible to compute the total length of a valid solutionin polynomial time, it can be used to generate heuristics for other planners. Specifically,Katz and Domshlak (2007) proposed projecting planning problems onto provably tractablefragments and use the solution to these fragments as heuristics for the original problem. Wehave shown that is such a tractable fragment. Unfortunately, because optimal planningfor is NP-hard, there is no hope of generating an admissible heuristic. However, theheuristic may still be informative in guiding the search towards a solution of the originalproblem. In addition, for planning problems with exponential length optimal solutions, astandard planner has no hope of generating a heuristic in polynomial time, making ourmacro-based approach (and that of Jonsson, 2007) the only (current) viable option.
5. The Class C n Domshlak and Dinitz (2001) defined the class C n of planning problems with multi-valuedstate variables and chain causal graphs. Since chain causal graphs are acyclic, it follows thatoperators are unary. Moreover, let v i be the i -th state variable in the chain. If i >
1, foreach operator a such that V post ( a ) ⊆ { v i } it holds that V pre ( a ) = { v i − , v i } . In other words,each operator that changes the value of a state variable v i may only have pre-conditions on v i − and v i .The authors showed that there are instances of C n with exponentially sized minimalsolutions, and therefore argued that the class is intractable. In light of the previous section,this argument on the length of the solutions does not discard the possibility that instancesof the class can be solved in polynomial time using macros. We show that this is not thecase, unless P = NP. omplexity of Planning Problems v w v k Figure 8: Causal graph of P ( F ). C C’ C n C’ n C’ C , C n C’ n , C n C’ n , C’ C ,10 SS S
Figure 9: Domain transition graph for v i .We define the decision problem Plan-Existence- C n as follows. A valid input of Plan-Existence- C n is a planning instance P of C n . The input P belongs to Plan-Existence- C n if and only if P is solvable. We show in this section that the problem Plan-Existence- C n is NP-hard. This implies that, unless P = NP, solving instances of C n is a trulyintractable problem, namely, no polynomial-time algorithm can distinguish between solvableand unsolvable instances of C n . In particular, no polynomial-time algorithm can solve C n instances by using macros or any other kind of output format. We prove that
Plan-Existence- C n is NP-hard by a reduction from Cnf-Sat , that is,the problem of determining whether a CNF formula F is satisfiable. Let C , . . . , C n be theclauses of the CNF formula F , and let v , . . . , v k be the variables that appear in F . Webriefly describe the intuition behind the reduction. The planning problem we create fromthe formula F has a state variable for each variable appearing in F , and plans are forcedto commit a value (either 0 or 1) to these state variables before actually using them. Then,to satisfy the goal of the problem, these variables are used to pass messages. However, theoperators for doing this are defined in such a way that a plan can only succeed when thestate variable values it has committed to are a satisfying assignment of F .We proceed to describe the reduction. First ,we define a planning problem P ( F ) = h V, init, goal, A i as follows. The set of state variables is V = { v , . . . , v k , w } , where D ( v i ) = { S, , , C , C ′ , . . . , C n , C ′ n } for each v i and D ( w ) = { S, , . . . , n } . The initial state defines init ( v ) = S for each v ∈ V and the goal state defines goal ( w ) = n . Figure 8 shows thecausal graph of P ( F ).The domain transition graph for each state variable v i is shown in Figure 9. Each noderepresents a value in D ( v i ), and an edge from x to y means that there exists an operator a such that pre ( a )( v i ) = x and post ( a )( v i ) = y . Edge labels represent the pre-condition ofsuch operators on state variable v i − , and multiple labels indicate that several operatorsare associated with an edge. We enumerate the operators acting on v i using the notation a = h pre ( a ); post ( a ) i (when i = 1 any mention of v i − is understood to be void):
1. A valid output format is one that enables efficient distinction between an output representing a validplan and an output representing the fact that no solution was found. im´enez & Jonsson C n C’ n , C’ C , S n n Figure 10: Domain transition graph for w .(1) Two operators h v i − = S, v i = S ; v i = 0 i and h v i − = S, v i = S ; v i = 1 i that allow v i to move from S to either 0 or 1.(2) Only when i >
1. For each clause C j and each X ∈ { C j , C ′ j } , two operators h v i − = X, v i = 0; v i = C j i and h v i − = X, v i = 1; v i = C ′ j i . These operators al-low v i to move to C j or C ′ j if v i − has done so.(3) For each clause C j and each X ∈ { , } , an operator h v i − = X, v i = 0; v i = C j i if v i occurs in clause C j , and an operator h v i − = X, v i = 1; v i = C ′ j i if v i occurs in clause C j . These operators allow v i to move to C j or C ′ j even if v i − has not done so.(4) For each clause C j and each X = { , } , two operators h v i − = X, v i = C j ; v i = 0 i and h v i − = X, v i = C ′ j ; v i = 1 i . These operators allow v i to move back to 0 or 1.The domain transition graph for state variable w is shown in Figure 10. For every clause C j the only two operators acting on w are h v k = X, w = j − w = j i , where X ∈ { C j , C ′ j } (if j = 1, the pre-condition w = j − w = S ). Proposition 5.1
A CNF formula F is satisfiable if and only if the planning instance P ( F ) is solvable. Proof
The proof follows from a relatively straightforward interpretation of the variablesand values of the planning instance P ( F ). For every state variable v i , we must use anoperator of (1) to commit to either 0 or 1. Note that, once this choice is made, variable v i cannot be set to the other value. The reason we need two values C j and C ′ j for each clauseis to enforce this commitment ( C j corresponds to v i = 0, while C ′ j corresponds to v i = 1).To reach the goal the state variable w has to advance step by step along the values 1 , . . . , n .Clearly, for every clause C j there must exist some variable v i that is first set to values C j or C ′ j using an operator of (3). Then, this “message” can be propagated along variables v i +1 , . . . , v k using operators of (2). Note that the existence of an operator of (3) acting on v i implies that the initial choice of 0 or 1 for state variable v i , when applied to the formulavariable v i , makes the clause C j true. Hence, if Π is a plan solving P ( F ), we can use theinitial choices of Π on state variables v i to define a (partial) assignment σ that satisfies allclauses of F .Conversely, if σ is some assignment that satisfies F , we show how to obtain a plan Πthat solves P ( F ). First, we set every state variable v i to value σ ( v i ). For every one of theclauses C j , we choose a variable v i among those that make C j true using assignment σ .Then, in increasing order of j , we set the state variable v i corresponding to clause C j to avalue C j or C ′ j (depending on σ ( v i )), and we pass this message along v i +1 , . . . , v k up to w . Theorem 5.2
Plan-Existence- C n is NP -hard. omplexity of Planning Problems v v v v v v x v x v v v v y y z z v C v C v C v C v C v C Figure 11: Causal graph of P F when F = C ∧ C ∧ C on three variables x, y, z . Proof
Producing a planning instance P ( F ) from a CNF formula F can be easily done inpolynomial time, so we have a polynomial-time reduction Cnf-Sat ≤ p Plan-Existence- C n .
6. Polytree Causal Graphs
In this section, we study the class of planning problems with binary state variables andpolytree causal graphs. Brafman and Domshlak (2003) presented an algorithm that findsplans for problems of this class in time O ( n κ ), where n is the number of variables and κ is the maximum indegree of the polytree causal graph. Brafman and Domshlak (2006)also showed how to solve in time roughly O ( n ωδ ) planning domains with local depth δ andcausal graphs of tree-width ω . It is interesting to observe that both algorithms fail to solvepolytree planning domains in polynomial time for different reasons: the first one fails whenthe tree is too broad (unbounded indegree), the second one fails when the tree is too deep (unbounded local depth, since the tree-width ω of a polytree is 1).In this section we prove that the problem of plan existence for polytree causal graphswith binary variables is NP-hard. Our proof is a reduction from to this class ofplanning problems. As an example of the reduction, Figure 11 shows the causal graph ofthe planning problem P F that corresponds to a formula F with three variables and threeclauses (the precise definition of P F is given in Proposition 6.2). Finally, at the end of thissection we remark that the same reduction solves a problem expressed in terms of CP-nets(Boutilier et al., 2004), namely, that dominance testing for polytree CP-nets with binaryvariables and partially specified CPTs is NP-complete.Let us describe briefly the idea behind the reduction. The planning problem P F has twodifferent parts. The first part (state variables v x , v x , . . . , v C , v ′ C , . . . , and v ) depends onthe formula F and has the property that a plan may change the value of v from 0 to 1 asmany times as the number of clauses of F that a truth assignment can satisfy. However, thiscondition on v cannot be stated as a planning problem goal. We overcome this difficultyby introducing a second part (state variables v , v , . . . , v t ) that translates it to a regularplanning problem goal.We first describe the second part. Let P be the planning problem h V, init, goal, A i where V is the set of state variables { v , . . . , v k − } and A is the set of 4 k − { α , . . . , α k − , β , . . . , β k − } . For i = 1, the operators are defined as α = h v = 1; v = 0 i im´enez & Jonsson and β = h v = 0; v = 1 i . For i >
1, the operators are α i = h v i − = 0 , v i = 1; v i = 0 i and β i = h v i − = 1 , v i = 0; v i = 1 i . The initial state is init ( v i ) = 0 for all i , and the goal stateis goal ( v i ) = 0 if i is even and goal ( v i ) = 1 if odd. Lemma 6.1
Any valid plan for planning problem P changes state variable v from 0 to 1at least k times. There is a valid plan that achieves this minimum. Proof
Let A i and B i be, respectively, the sequences of operators h α , . . . , α i i and h β , . . . , β i i .It is easy to verify that the plan h B k − , A k − , B k − , . . . , B , A , B i solves the planningproblem P . Indeed, after applying the operators of A i (respectively, the operators of B i ),variables v , . . . , v i become 0 (respectively, 1). In particular, variable v i attains its goalstate (0 if i is even, 1 if i is odd). Subsequent operators in the plan do not modify v i , sothe variable remains in its goal state until the end. The operator β appears k times in theplan (one for each sequence of type B i ), thus the value of v changes k times from 0 to 1.We proceed to show that k is the minimum. Consider some plan Π that solves theplanning problem P , and let λ i be the number of operators α i and β i appearing in Π (inother words, λ i is the number of times that the value of v i changes, either from 0 to 1 orfrom 1 to 0). Note that the number of times operator β i appears is equal to or precisely onemore than the number of occurrences of α i . We will show that λ i − > λ i . Since λ k − ≤ λ ≥ k −
1, so that plan Π has, at least, k occurrences of β , completingthe proof.We show that λ i − > λ i . Let S i be the subsequence of operators α i and β i in plan Π.Clearly, S i starts with β i (since the initial state is v i = 0), and the same operator cannotappear twice consecutively in S i , so S i = β i , α i , β i , α i , etc. Also note that, for i > β i has v i − = 1 as a pre-condition, and α i has v i − = 0, hence there must be at least one operator α i − in plan Π betweeen any two operators β i and α i . For the same reason we must haveat least one operator β i − between any two operators α i and β i , and one operator β i − before the first operator β i . This shows that λ i − ≥ λ i . On the other hand, variables v i and v i − have different values in the goal state, so subsequences S i and S i − must have differentlengths, that is, λ i − = λ i . Together, this implies λ i − > λ i , as desired. Proposition 6.2 reduces to plan existence for planning problems with binary vari-ables and polytree causal graphs.
Proof
Let F be a CNF formula with k clauses and n variables. We produce a planningproblem P F with 2 n + 4 k − n + 14 k − v x and v x for every variable x in F , two state variables v C and v ′ C for every clause C in F , and 2 k − v , . . . , v k − . All variablesare 0 in the initial state. The (partial) goal state is defined by V goal = { v , . . . , v k − } , goal ( v i ) = 0 when i is even, and goal ( v i ) = 1 when i is odd, like in problem P of Lemma6.1. The operators are:(1) Operators h v x = 0; v x = 1 i and h v x = 0; v x = 1 i for every variable x of F .(2) Operators h v ′ C = 0; v ′ C = 1 i , h v ′ C = 0 , v C = 0; v C = 1 i and h v ′ C = 1 , v C = 1; v C = 0 i for every clause C of F . omplexity of Planning Problems (3) Seven operators for every clause C , one for each partial assignment that satisfies C .Without loss of generality, let x , y , and z be the three variables that appear in clause C .Then for each operator a among these seven, V pre ( a ) = { v x , v x , v y , v y , v z , v z , v C , v } , V post ( a ) = { v } , pre ( a )( v C ) = 1, pre ( a )( v ) = 0, and post ( a )( v ) = 1. The pre-condition on state variables v x , v x , v y , v y , v z , v z depends on the corresponding satis-fying partial assignment. For example, the operator corresponding to the partialassignment { x = 0 , y = 0 , z = 1 } of the clause C = x ∨ y ∨ z has the pre-condition( v x = 0 , v x = 1 , v y = 0 , v y = 1 , v z = 1 , v z = 0) . (4) An operator h ( ∀ C, v C = 0) , v = 1; v = 0 i .(5) Operators α i = h v i − = 0 , v i = 1; v i = 0 i and β i = h v i − = 1 , v i = 0; v i = 1 i for2 ≤ i ≤ k − P except for α and β ).We note some simple facts about problem P F . For any variable x , state variables v x and v x in P F start at 0, and by applying the operators in (1) they can change into 1 but notback to 0. In particular, a plan Π cannot reach both of the partial states h v x = 1 , v x = 0 i and h v x = 0 , v x = 1 i during the course of its execution.Similarly, if C is a clause of F , state variable v C can change from 0 to 1 and, by firstchanging v ′ C into 1, v C can change back to 0. No further changes are possible, since nooperator brings back v ′ C to 0.Now we interpret operators in (3) and (4), which are the only operators that affect v .To change v from 0 to 1 we need to apply one of the operators in (3), thus we require v C = 1 for a clause C . But the only way to bring back v to 0 is applying the operator in(4) which has as pre-condition that v C = 0. We deduce that every time that v changes itsvalue from 0 to 1 and then back to 0 in plan Π, at least one of the k state variables v C is used up , in the sense that v C has been brought from 0 to 1 and then back to 0, and cannotbe used again for the same purpose.We show that F is in if and only if there is a valid plan for problem P F . Assume F is in , and let σ be a truth assignment that satisfies F . Consider the following planΠ ′ . First, we set v x = σ ( x ) and v x = 1 − σ ( x ) for all variables x using the operators of (1).Then, for a clause C in F , we set v C = 1, we apply the operator of (3) that corresponds to σ restricted to the variables of clause C (at this point, v changes from 0 to 1), then we set v ′ C = 1 and v C = 0, and we apply the operator of (4) (at this point, v change from 1 to0). By repeating this process for every clause C of F we are switching the state variable v exactly k times from 0 to 1. Now, following the proof of Lemma 6.1, we can easily extendthis plan Π ′ to a plan Π that sets all variables v i to their goal values.We show the converse, namely, that the existence of a valid plan Π in P F implies that F is satisfiable. Define an assignment σ by setting σ ( x ) = 1 if the partial state { v x = 1 , v x = 0 } appears during the execution of Π, and σ ( x ) = 0 otherwise. (Recall that at most one of thepartial states { v x = 1 , v x = 0 } and { v x = 0 , v x = 1 } can appear during the execution of anyplan). By Lemma 6.1, Π must be such that state variable v changes from 0 to 1 at least k times. This implies that k operators of (3), all of them corresponding to different clauses,have been used to move v from 0 to 1. But to apply such an operator, the values of statevariables { v x , v x } must satisfy the corresponding clause. Thus the assignment σ satisfies allthe k clauses of F . im´enez & Jonsson Theorem 6.3
Plan existence for planning problems with binary variables and polytreecausal graph is NP -complete. Proof
Due to Proposition 6.2 we only need to show that the problem is in NP. ButBrafman and Domshlak (2003) showed that this holds in the more general setting of planningproblems with causal graphs where each component is directed-path singly connected (thatis, there is at most one directed path between any pair of nodes). Their proof exploits anon-trivial auxiliary result: solvable planning problems on binary variables with a directed-path singly connected causal graph have plans of polynomial length (the same is not truefor non-binary variables, or unrestricted causal graphs).
Boutilier et al. (2004) introduced the notion of a CP-net as a graphical representation ofuser preferences. In brief, a CP-net is a network of dependences on a set of variables: thepreferences the user has for a variable depend on the values of some of the others, under the ceteris paribus (all else being equal) assumption, that is, the user preferences on the variableare completely independent of the values of the variables not mentioned. The preferencesfor a variable given its parent variables in the network are stored in conditional preferencetables, or CPTs.Boutilier et al. (2004) showed that the dominance query problem in acyclic CP-nets,that is, the problem of deciding if one variable outcome is preferable to another, can beexpressed in terms of a planning problem. The network of dependences of the CP-netbecomes the causal graph of the planning problem.However, under certain conditions, we can perform the opposite process: transforma planning problem into a CP-net and a dominance query problem, such that answeringthe query amounts to solving the planning problem. This is possible under the followingconditions on planning problems with acyclic causal graph and binary variables:1. Two operators that modify the same variable in opposing directions must have non-matching prevail conditions (the prevail condition of an operator a is the partial state pre ( a ) | V − V post ( a ) ).2. We must allow partially specified CPTs in the CP-net description.The first condition guarantees that we obtain consistent CPTs from the planning instanceoperators. The second condition ensures that the reduction is polynomial-size preserving,since fully specified CPTs are exponential in the maximum node indegree of the CP-net.In particular, the planning instance P F we reduced F to satisfies the first condition.(Note that this is not true for the planning problem P of Lemma 6.1, but we drop thereversing operators α and β when constructing P F in Proposition 6.2.) As a consequence,we can claim the following: Theorem 6.4
Dominance testing for polytree CP-nets with binary variables and partiallyspecified CPTs is NP -complete. omplexity of Planning Problems
7. Conclusion
We have presented three new complexity results for planning problems with simple causalgraphs. First, we provided a polynomial-time algorithm that uses macros to generate solu-tion plans for the class . Although the solutions are generally suboptimal, the algorithmcan generate representations of exponentially long plans in polynomial time. This has sev-eral implications for theoretical work in planning, since it has been generally accepted thatexponentially sized minimal solutions imply that plan generation is intractable. Our workshows that this is not always the case, provided that one is allowed to express the solutionin a succinct notation such as macros. We also showed that plan existence for the class C n is NP-hard, and that plan existence for the class of planning problems with binary variablesand polytree causal graph is NP-complete.Jonsson and B¨ackstr¨om (1998) investigated whether plan generation is significantlyharder than plan existence. Using the class , they demonstrated that plan existencecan be solved in polynomial time, while plan generation is intractable in the sense thatsolution plans may have exponential length. Our work casts new light on this result: eventhough solution plans have exponential length, it is possible to generate a representationof the solution in polynomial time. Thus, it appears as if for the class , plan generationis not inherently harder than plan existence. We are not aware of any other work thatdetermines the relative complexity of plan existence and plan generation, so the questionof whether plan generation is harder that plan existence remains open.A potential criticism of our algorithm is that a solution in the form of macros is notstandard, and that it is intractable to expand the system of macros to arrive at the possiblyexponentially long sequence of underlying operators. Although this is true, we have shownthat the system of macros share several characteristics with a proper solution. It is possibleto generate and validate the solution in polynomial time, and the solution can be storedusing polynomial memory. We also showed that it is possible to compute the total lengthof the solution in polynomial time, as well as determine which is the i -th operator in theunderlying sequence.Since they are relatively simple, the class C n and the class of planning problems withbinary state variables and polytree causal graphs could be seen as promising candidates forproving the relative complexity of plan existence and plan generation. However, we haveshown that plan existence for C n is NP-hard, and that plan existence for planning problemswith polytree causal graphs is NP-complete. Consequently, these classes cannot be usedto show that plan generation is harder than plan existence, since plan existence is alreadydifficult. Our work also closes the complexity gaps that appear in the literature regardingthese two classes.It is however possible that there exist subsets of planning problems in these classesfor which plan existence can be solved in polynomial time. In fact, for polytree causalgraphs in binary variables we know that this is the case, due to the algorithms of Brafmanand Domshlak (2003, 2006) mentioned in Section 6. Hence the plan generation problemis polynomial if we restrict to polytree causal graphs with either bounded indegree κ orbounded local depth δ . Consequently, our reduction from exhibits both unboundedindegree and unbounded local depth. im´enez & Jonsson Similarly, one may ask if the class C n of planning problems has some parameter that,when bounded, would yield a tractable subclass. The state variables in our reduction havedomains whose size depends on the number of clauses of the corresponding CNF formula,so the domain size appears as an interesting candidate. Planning problems of C n withbinary variables are tractable due to the work of Brafman and Domshlak (2003), but theideas they use do not extend to domain sizes other than 2. Hence it would be interestingto investigate whether the problem of plan existence for the class C n is easier if the size ofthe state variable domains is bounded by a constant. Appendix A. Proof of Theorem 4.8
Assume that
GenerateMacro ( P , v , x , M ) successfully returns the macro m vx = h S , a, S i .Let U = { u ∈ V pre ( a ) − { v } | pre ( a )( u ) = 1 } and let W = { w , . . . , w k } ⊆ U be the setof state variables in U such that w i is not splitting, { m w i , m w i } ∈ M , and w i comes be-fore w j in topological order if and only if i < j . It follows that no u ∈ U is static, that S = h m w k , . . . , m w i and that S = h m w , . . . , m w k i . Since each state variable w i ∈ W isnot splitting, it has to be symmetrically reversible. Lemma A.1
For each w i ∈ W , pre w i ⊑ pre v . Proof
Since w i ∈ V pre ( a ) and v ∈ V post ( a ) , there is an edge from w i to v in the causal graph.Thus, any ancestor of w i is also an ancestor of v , so Anc w i ⊂ Anc v . For a state variable u ∈ Anc w i , pre w i ( u ) = 1 if and only if u is splitting and w i ∈ V u . The graph G u = ( V, E u )includes the edge from w i to v , which means that v ∈ V u if and only if w i ∈ V u . It followsthat pre w i ( u ) = 1 if and only if pre v ( u ) = 1, and as a consequence, pre w i ⊑ pre v .Let Π = h S , a, S i . For each w i ∈ W and y ∈ { , } , let Π w i y be the sequence precedingthe macro m w i y in Π, that is, Π w i = h m w k , . . . , m w i +1 i and Π w i = h S , a, m w , . . . , m w i − i .Further, let Π a be the sequence appearing before a , that is, Π a = h S i . Lemma A.2
For each ≤ i ≤ k , the post-conditions of sequences Π w i , Π a , and Π w i are • post (Π w i ) = ( w i +1 = 1 , . . . , w k = 1) , • post (Π a ) = ( w = 1 , . . . , w k = 1) , • post (Π w i ) = ( w = 0 , . . . , w i − = 0 , w i = 1 , . . . , w k = 1 , v = x ) . Proof
A direct consequence of post ( h a , . . . , a k i ) = post ( a ) ⊕· · ·⊕ post ( a k ) and post ( m w i y ) =( w i = y ), post ( a ) = ( v = x ). Lemma A.3
For each ≤ i ≤ k , the pre-conditions of sequences Π w i , Π a , Π w i , and Π satisfy pre (Π w i ) ⊑ pre (Π a ) ⊑ pre (Π w i ) ⊑ pre (Π) ⊑ pre v ⊕ ( v = 1 − x ) . Proof
Since pre ( h a , . . . , a k i ) = pre ( a k ) ⊕· · ·⊕ pre ( a ), it follows that pre (Π w i ) ⊑ pre (Π a ) ⊑ pre (Π w i ) ⊑ pre (Π). We prove that pre (Π) ⊑ pre v ⊕ ( v = 1 − x ). For a state variable u such that pre (Π)( u ) = ⊥ , let m u be the first operator in h S , a, S i such that u ∈ V pre ( m u ) ,so that pre (Π)( u ) = pre ( m u )( u ). omplexity of Planning Problems If m u = m w i , then it follows that pre ( m u ) ⊑ pre w i ⊕ ( w i = 0) ⊑ pre v , where we haveused that m w i is a -macro, w i is symmetrically reversible, and that pre w i ⊑ pre v due toLemma A.1. In particular, pre ( m u )( u ) = pre v ( u ).Since we assume that planning problems are in normal form, u = w i implies that u ∈ V pre ( m wi ) . It follows that if m u = m w i for all i , then u = w i for all i . If m u = m w i we have that pre ( m u ) ⊑ pre w i ⊕ ( w i = 1), but due to u = w i , we deduce pre ( m u )( u ) = pre w i ( u ) = pre v ( u ).Finally, consider the case m u = a . If u = v then pre ( m u )( u ) = 1 − x , as desired. If u = v is splitting, then either v belongs to V u and pre ( m u )( u ) = 0, or v belongs to V u and pre ( m u )( u ) = 1. That is, pre ( m u )( u ) = pre v ( u ). If u = v is symmetrically reversible itfollows that pre ( m u )( u ) = 0, since the case pre ( m u )( u ) = 1 would have forced the algorithmto either fail or include u in W . If u = v is static, pre ( m u )( u ) = 0, else the algorithm wouldhave failed. Lemma A.4
Let p, p ′ , q and r be partial states. If p ⊑ p ′ and ( p ′ ⊕ q ) ▽ r , then ( p ⊕ q ) ▽ r . Proof
A direct consequence of p ⊕ q ⊑ p ′ ⊕ q . Lemma A.5
The macro m vx generated by the algorithm is well-defined. Proof
Since Π only includes macros for the ancestors of v in the causal graph, and sincethe causal graph is acyclic, no cyclic definitions occur. It remains to show that, for a macro m in Π and a sequence Π m preceding m in Π, it holds that ( pre (Π m ) ⊕ post (Π m )) ▽ pre ( m ).Note that due to Lemmas A.3 and A.4 it is enough to show that(a) ( pre v ⊕ ( v = 1 − x ) ⊕ post (Π w i )) ▽ pre ( m w i ) , (b) ( pre v ⊕ ( v = 1 − x ) ⊕ post (Π a )) ▽ pre ( a ) , (c) ( pre v ⊕ ( v = 1 − x ) ⊕ post (Π w i )) ▽ pre ( m w i ) . Case (a) follows easily since V post (Π wi ) ∩ V pre ( m wi ) = ∅ and pre ( m w i ) = pre w i ⊕ ( w i = 0) ⊑ pre v . Case (c) is similar, although this time we must use that post (Π w i )( w i ) = 1 and post (Π w i )( w j ) = 0 for j < i , as required by pre ( m w i ) = pre w i ⊕ ( w i = 1). Finally, case (b)holds because a variable u ∈ V pre ( a ) can be either u = v , which is covered by ( v = 1 − x ),splitting or static, which is covered by pre v , or symmetrically reversible, which is coveredby pre v ( u ) = 0 if pre ( a )( u ) = 0, and by post (Π a )( u ) = 1 if pre ( a )( u ) = 1.In remains to show that m vx is a -macro. It follows from Lemmas A.3 and A.5 that itis well-defined and it satisfies pre ( m vx ) = pre (Π) ⊑ pre v ⊕ ( v = 1 − x ). Finally, post ( m vx ) = post (Π) − pre (Π) = ( v = x ) is a direct consequence of post (Π) = ( w = 0 , . . . , w k = 0 , v = x )from Lemma A.2, and pre (Π)( w i ) = 0, pre (Π)( v ) = 1 − x from the proof of Lemma A.3. Acknowledgments
This work was partially funded by MEC grants TIN2006-15387-C03-03 and TIN2004-07925-C03-01 (GRAMMARS). im´enez & Jonsson
References
B¨ackstr¨om, C., & Nebel, B. (1995). Complexity Results for SAS + Planning.
ComputationalIntelligence , (4), 625–655.Botea, A., Enzenberger, M., M¨uller, M., & Schaeffer, J. (2005). Macro-FF: Improving AIPlanning with Automatically Learned Macro-Operators. Journal of Artificial Intelli-gence Research , , 581–621.Boutilier, C., Brafman, R., Domshlak, C., Hoos, H., & Poole, D. (2004). CP-nets: A Tool forRepresenting and Reasoning with Conditional Ceteris Paribus
Preference Statements.
Journal of Artificial Intelligence Research , , 135–191.Brafman, R., & Domshlak, C. (2003). Structure and Complexity in Planning with UnaryOperators. Journal of Artificial Intelligence Research , , 315–349.Brafman, R., & Domshlak, C. (2006). Factored Planning: How, When, and When Not. In Proceedings of the 21st National Conference on Artificial Intelligence .Bylander, T. (1994). The computational complexity of propositional STRIPS planning.
Artificial Intelligence , , 165–204.Chapman, D. (1987). Planning for conjunctive goals. Artificial Intelligence , , 333–377.Cormen, T., Leiserson, C., Rivest, R., & Stein, C. (1990). Introduction to Algorithms . MITPress and McGraw Hill.Domshlak, C., & Dinitz, Y. (2001). Multi-Agent Off-line Coordination: Structure and Com-plexity. In
Proceedings of the 6th European Conference on Planning , pp. 277–288.Erol, K., Nau, D., & Subrahmanian, V. (1995). Complexity, decidability and undecidabilityresults for domain-independent planning.
Artificial Intelligence , , 75–88.Fikes, R., & Nilsson, N. (1971). STRIPS: A new approach to the application of theoremproving to problem solving. Artificial Intelligence , (2), 189–208.Gim´enez, O., & Jonsson, A. (2007). On the Hardness of Planning Problems With SimpleCausal Graphs. In Proceedings of the 17th International Conference on AutomatedPlanning and Scheduling , pp. 152–159.Helmert, M. (2003). Complexity results for standard benchmark domains in planning.
Artificial Intelligence , , 219–262.Helmert, M. (2006). The Fast Downward Planning System. Journal of Artificial IntelligenceResearch , , 191–246.Jonsson, A. (2007). The Role of Macros in Tractable Planning Over Causal Graphs. In Proceedings of the 20th International Joint Conference on Artificial Intelligence , pp.1936–1941.Jonsson, P., & B¨ackstr¨om, C. (1998). Tractable plan existence does not imply tractableplan generation.
Annals of Mathematics and Artificial Intelligence , , 281–296.Katz, M., & Domshlak, C. (2007). Structural Patterns Heuristics: Basic Idea and ConcreteInstance. In Workshop on Heuristics for Domain-independent Planning: Progress,Ideas, Limitations, Challenges (ICAPS-07) . omplexity of Planning Problems Knoblock, C. (1994). Automatically generating abstractions for planning.
Artificial Intel-ligence , , 243–302.Korf, R. (1987). Planning as search: A quantitative approach. Artificial Intelligence , ,65–88.Minton, S. (1985). Selectively generalizing plans for problem-solving. In Proceedings of the9th International Joint Conference on Artificial Intelligence , pp. 596–599.Vidal, V. (2004). A Lookahead Strategy for Heuristic Search Planning. In
Proceedings of the14th International Conference on Automated Planning and Scheduling , pp. 150–159.Williams, B., & Nayak, P. (1997). A reactive planner for a model-based executive. In
Proceedings of the 15th International Joint Conference on Artificial Intelligence , pp.1178–1185., pp.1178–1185.