Last update: February 14, 2017 Automated Planning and Acting Section 2.7.7 Malik Ghallab, Dana Nau HTN Planning and Paolo Traverso http://www.laas.fr/planning Dana S. Nau University of Maryland Nau – Lecture slides for Automated Planning and Acting Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 1
Motivation = For some planning problems, we may already have ideas for how to look for solutions = Example: travel to a destination that’s far away: Ø Brute-force search: • many combinations of vehicles and routes Ø Experienced human: small number of “ recipes ” e.g., flying: 1. buy ticket from local airport to remote airport 2. travel to local airport 3. fly to remote airport 4. travel to final destination = How can we put such information into an actor? Nau – Lecture slides for Automated Planning and Acting 2
Using Domain-Specific Information in an Actor = Several ways to do it Ø Domain-specific algorithm Ø Refinement methods (RAE and SeRPE, Chapter 3) Ø HTN planning (SHOP, PyHop, Section 2.7.7) Ø Control rules (TLPlan, Section 2.7.8) Nau – Lecture slides for Automated Planning and Acting 3
Total-Order HTN Planning = Planning algorithm = Ingredients: Ø use methods to refine each task Ø states and actions into a set of subtasks Ø tasks : activities to perform • do it recursively Ø HTN methods : ways to Ø bottom level: perform tasks • primitive tasks, i.e., actions = Method format: task method-name ( args ) Task: task-name ( args ) method Pre: preconditions Sub: list of subtasks task task method = Two kinds of tasks Ø Primitive : name of an action task task Ø Compound : need to refine using methods action s 1 action action s 2 s 3 s 0 Nau – Lecture slides for Automated Planning and Acting 4
Total-Order HTN Planning = Special case of refinement methods (Chapter 3) Ø Method body is a list of tasks, not a program = Even with this restriction, Turing-complete Ø To encode loops • use recursion task Ø To encode if-then-else • use multiple methods for a task method task task method task task action s 1 action action s 2 s 3 s 0 Nau – Lecture slides for Automated Planning and Acting 5
Total-Order HTN Planning = HTN planning domain: a pair ( Σ , M ) Ø Σ : state-variable planning domain Ø M : set of methods = Planning problem: ( Σ , M , s 0 , T ) Ø T : list of tasks ⟨ t 1 , t 2 , …, t k ⟩ task = Solution: any executable plan that method can be generated by applying task Ø methods to nonprimitive tasks Ø actions to primitive tasks task method task task action s 1 action action s 2 s 3 s 0 Nau – Lecture slides for Automated Planning and Acting 6
Simple Travel-Planning Problem = Methods home travel-by-foot ( a,x,y ) park Task: travel ( a,x , y ) = Initial state : Pre: loc ( a,x ), distance ( x, y ) ≤ 4 • I’m at home, Sub: walk ( a, x , y ) • I have $20, • there’s a park 8 miles away travel-by-taxi ( a,x,y ) Ø { loc(me) = home, Task: travel ( a,x , y ) cash(me) = 20, dist(home,park) = 8, Pre: loc ( a,x ), loc(taxi) = elsewhere } cash ( a ) ≥ 1.50 + ½ dist ( x,y ) Sub: call-taxi ( a,x ), = Task : travel to the park ride-taxi ( a,x,y ), Ø travel(me,home,park) pay-driver ( a ) Nau – Lecture slides for Automated Planning and Acting 7
Simple Travel-Planning Problem = Actions: walk ( a,x,y ) home Pre: loc ( a ) = x park Eff: loc ( a ) ← y = Parameters call-taxi ( a,x ) Ø a ∈ Agents Pre: — Ø x,y ∈ Locations Eff: loc ( taxi ) ← x Ø r ∈ R (real numbers) ride-taxi ( a,x,y ) Pre: loc ( a ) = x, loc ( taxi ) = x Eff: loc ( a ) ← y, loc ( taxi ) ← y, owe ( a ) ← 1.50 + ½ dist ( x,y ) pay-driver ( a,r ) Pre: owe ( a ) = r , cash ( a ) ≥ r Pre: owe ( a ) ← 0, cash ( a ) ← cash ( a ) – r Nau – Lecture slides for Automated Planning and Acting 8
Simple Travel-Planning Problem = Left-to-right backtracking search home travel(me,home,park) park travel-by-taxi(me,home,park) travel-by-foot(me,home,park) Pre: Pre: ü loc(me,home) ü loc(me,home) s 0 × dist(home,park) ≤ 4 ü cash(me) ≥ 1.5+0.5*dist(home,park) Backtrack call-taxi(me,home) s 1 ride-taxi(me,home,park) s 2 pay-driver(me) s 3 Precond: … Precond: … Precond: … Initial Final Effects: … Effects: … Effects: … state state loc(me) = park loc(me) = park loc(me) = home loc(me) = home cash(me) = 14.5 cash(me) = 20 cash(me) = 20 cash(me) = 20 dist(home,park) = 8 dist(home,park) = 8 dist(home,park) = 8 dist(home,park) = 8 loc(taxi) = park loc(taxi) = park loc(taxi) = elsewhere loc(taxi) = home owe(me) = 0 owe(me) = 5.50 Nau – Lecture slides for Automated Planning and Acting 9
Planning Algorithm = TFD ( Σ , M , s , T ) Ø if T = ⟨ ⟩ then return ⟨ ⟩ Ø let the tasks in T be t 1 , t 2 , …, t k i.e., T = ⟨ t 1 , t 2 , …, t k ⟩ Ø if t 1 is primitive then • Candidates ← { a | head( a ) matches t 1 and a is applicable in s } • if Candidates = ∅ then return failure state s , task list T = ⟨ t 1 , t 2 ,… ⟩ • nondeterministically choose any a ∈ Act • π ← TFD ( Σ , γ ( s,a ), ⟨ t 2 ,…, t k ⟩ ) action a • if π = failure then return failure state g ( s,a ) , task list T = ⟨ t 2 , … ⟩ • else return a • π Ø else t 1 is nonprimitive • Candidates ← { m ∈ M | task( m ) matches t 1 and m is applicable in s } • if Candidates = ∅ then return failure state s , task list T = ⟨ t 1 , t 2 ,… ⟩ • nondeterministically choose any a ∈ Act method m • return TFD ( Σ , M , s , sub( m ) . ⟨ t 2 ,…, t k ⟩ ) state s , task list T = ⟨ u 1 ,…, u k , t 2 ,… ⟩ Nau – Lecture slides for Automated Planning and Acting 10
Pyhop = A simple HTN planner written in Python Ø Works in both Python 2.7 and 3.2 = Implements the algorithm on the previous page Ø HTN operators and methods are ordinary Python functions Ø The current state is a Python object that contains variable bindings • Operators and methods refer to states explicitly • To say c is on a , write s.loc['c'] = 'a' where s is the current state = Easy to implement and understand s Ø Less than 150 lines of code c = Open-source software, Apache license a b Ø http://bitbucket.org/dananau/pyhop Nau – Lecture slides for Automated Planning and Acting 11
def walk(state,a,x,y): Actions if state.loc[a] == x: state.loc[a] = y walk ( a: Agents, x : Locations, y: Locations ) return state Pre: loc ( a ) = x else: return False Eff: loc ( a ) = y def call_taxi(state,a,x): call-taxi ( a: Agents, x: Locations ) state.loc['taxi'] = x Pre: — return state Eff: loc ( taxi ) = x def ride_taxi(state,a,x,y): if state.loc['taxi']==x and state.loc[a]==x: ride-taxi ( a: Agents, x: Locations, state.loc['taxi'] = y y: Locations ) state.loc[a] = y Pre: loc ( a ) = x, loc ( taxi ) = x state.owe[a] = 1.5 + 0.5*state.dist[x][y] Eff: loc ( a ) = y, loc ( taxi ) = y, return state owe ( a ) = 1.50 + ½ distance( x,y ) else: return False def pay_driver(state,a): if state.cash[a] >= state.owe[a]: pay-driver ( a: Agents ) state.cash[a] = state.cash[a] – state.owe[a] Pre: owe ( a ) = r , cash ( a ) ≥ r state.owe[a] = 0 Pre: owe ( a ) = r , return state cash ( a ) = cash ( a ) – r else: return False declare_operators(walk, call_taxi, ride_taxi, pay_driver) Nau – Lecture slides for Automated Planning and Acting 12
Methods def travel_by_foot(state,a,x,y): travel-by-foot ( a, x, y ) if state.dist[x][y] <= 4: Task: travel ( a,x , y ) return [('walk',a,x,y)] Pre: loc ( a,x ), distance ( x,y ) ≤ 4 return False Sub: walk ( a,x , y ) travel-by-taxi ( a,x,y ) def travel_by_taxi(state,a,x,y): Task: travel ( a,x , y ) if state.cash[a] >= 1.5 + 0.5*state.dist[x][y]: Pre: cash ( a ) ≥ 1.5 + 0.5* dist ( x,y ) return [('call_taxi',a,x), Sub: call-taxi ( a,x ), ('ride_taxi',a,x,y), ride-taxi ( a,x,y ), ('pay_driver',a,x,y)] pay-driver ( a ) return False declare_methods('travel’, travel_by_foot, travel_by_taxi) Nau – Lecture slides for Automated Planning and Acting 13
Travel Planning Problem Initial state : loc(me) = home, cash(me) = 20, dist(home,park) = 8 state1 = State('state1’) state1.loc = {'me':'home’} home state1.cash = {'me':20} state1.owe = {'me’:0} state1.dist = {'home':{'park':8}, ’park':{’home':8}} Task : travel(me,home,park) park # Invoke the planner pyhop(state1,[('travel','me','home','park')]) Solution plan : call-taxi(me,home), ride-taxi(me,park), pay-driver(me) [('call_taxi', 'me', 'home'), ('ride_taxi', 'me', 'home', 'park'), ('pay_driver', 'me')] Nau – Lecture slides for Automated Planning and Acting 14
Comparison to Forward and Backward Search = In HTN planning, more possibilities than just forward or backward • A little like the choices to make in parsing algorithms = SHOP, Pyhop, GDP, GoDeL: Ø down, then forward task (like RAE and SeRPE) = SIPE, O-Plan, UMCP task task Ø plan-space (down and backward) task task task task = Angelic Hierarchical A* task Ø use abstract actions to task … task … task task … task task … task produce abstract states Ø forward A*, at the top level Ø forward A*, one level down Ø … Nau – Lecture slides for Automated Planning and Acting 15
Recommend
More recommend