An Introduction to Artificial Intelligence CE 40417 Chapter 11 – Planning Ramin Halavati ([email protected]) In which we see how an agent can take advantage of a problem to construct complex plans of actions. 1. We have some Operators. What is planning 2. We have a Current state. 3. We have a Goal State. 4. We want to know: How to arrange the operators to reach the Goal State from Current State. Air Cargo Transfer Example • What’s in Domain: – We have a set of airports as SFO,JFK, ... – We have a set of cargos as C1, C2, … – We have some airplanes as P1, P2, … • State: – Plans and Cargos are at specific airports and we want to change the positions. • Actions: – Load (Cargo, Plane, Airport) – Fly (Plane, Airport1, Airport2) – Unload (Cargo, Plane, Airport) • Domain Objects: Blocks World Example – A set of blocks and a table. • States: – Blocks are stacked on each other and the table and we want to change their positions. C • Actions: – – – – PickUp( Block ), PutDown( Block) Unstack( Block, Block) Stack( Block, Block ) A B A B C Domain Definition Example 1 AIR CARGO TRANPORT DOMAIN: • Objects: – SFO , JFK, C1 , C2 , P1 , P2. • Predicates: – – – – At( C1, SFO ) In( C1, P2 ) Plane( P1) Cargo(C1) • Actions: – … Domain Definition Ex.1(cont.) • Actions: – – – – Name, Parameters, Preconditions, Effects. – LOAD( c, p , a ) • Prec.: At(c,a), At(p,a), Cargo(c),Plane(p),Airport(a). • Effects: ~At(c,a), In(c,p) Domain Definition Ex.1 (cont.) • Actions: – UNLOAD( c, p , a ) • Prec.: In(c,p), At(p,a), Cargo(c),Plane(p),Airport(a). • Effects: At(c,a), ~In(c,p) – FLY( p , a1, a2 ) • Prec.: At(p,a1) Plane(p),Airport(a1) ,Airport(a2). • Effects: ~At(p,a1), At(p,a2) Domain Definition Example 2 BLOCKS WORLD DOMAIN • Objects: – A, B, C, … (the blocks) & the ROBOT. • Predicates: – – – – – – – On( x , y ). OnTable( x ). Holding( x ). HandEmpty. Clear( x ). OnTable( x ). Block( x ). Domain Definition Ex.2(cont.) • Actions: – UnStack( x , y ): X Y • Prec: On(x,y), HandEmpty, Clear( x ). • Effects: ~On(x,y), Holding(x), ~Clear(x), Clear(y). – Stack( x,y ): • Prec: Holding(x), Clear(y) • Effects: On(x,y), HandEmpty, ~Holding(x), Clear( x ), ~Clear(y). NOTE: Nothing about what is block and what’s not. Domain Definition Ex.2(cont.) • Actions: – PickUp( x ): • Prec: HandEmpty, Clear( x ), OnTable( x ). • Effects: Holding(x), ~Clear(x), ~OnTable( x ). – PutDown( x ): • Prec: Holding(x). • Effects: OnTable( x ), HandEmpty, Clear( x ). Propblem Definition Ex.2 • PROBLEM DEFINITION: – Initial State: On(C,A), Clear(C), ~Clear(A), OnTable(A), Clear(B), OnTable(B), HandEmpty. – Goal State: HandEmpty, Clear(A), On(A,B), On(B,C), OnTable(C). C A B A B C • It’s all about SEARCH. Simplest Approach – States: As described before. – Next State Generator: Which actions are applicable, apply every one of em. – Path Cost: One for each action. – Goal Test: Has goal state reached? C B A A C B Initial state C B A B C A C A B C A B C A B C A B B A C A B B C A C A B C Goal B A C • Progression (Forward Search): Simplest Approach – Start from Initial State, move forward till you reach goal state. C A B C A C B A B B C C A B A B A C C B A C B A ... NOTE: Backtracking is mandatory. • Regression (Backward Search): Simplest Approach – Put Goal State’s predicates in Agenda. – Recursively fetch an item from agenda • Find something to satisfy it. • Remove all its effects from agenda. • Add all its preconditions to agenda. On(A,B), On(B,C), OnTable(C) Regression Example 1. Pick Goal: On(A,B) 2. Choose Action: Stack(A,B) 3. Add actions preconditions to agenda and remove its effects from it. On(B,C), OnTable(C), Holding(A), Clear(B). 1. Pick Goal: Holding(A) 2. Choose Action: PickUp(A). 3. ... On(B,C), OnTable(C), Clear(B), HandEmpty, OnTable(A) ... Pure Search Approaches • Heuristics: – Using Relaxed Domain Definition: • Assume actions have no precondition. • Assume actions have no negative effects. • … • (They are all admissible). – Sub-Goal Independence Assumption • Assuming each goal can be achieved with a sub-plan, regardless of other necessities. • (Not necessarily admissible, depends on the domain). • What’s wrong with Search? Simplest Approach – Branching Factor may be too big. – The search space is reversible, resulting in infinite loops and repeated states. – Simple Search is the least that we can do. PARTIAL ORDER PLANNING Partial Order Planning Partial Order Planning • We do not need to start from the beginning of plan and march to end. • Some steps, facts, etc. are more important, we can decide on them ahead. • We can impose least possible commitments during the task. STACK(A,B) C A B START: Holding(A) On(A,B) Clear(B) H.E. A B C Clear(A) On(C,A) OnTable(A) END : OnTable(B) On(A,B) Clear(C) On(B,C) Clear(A) OnTable(C) STACK(B,C) Holding(B) On(B,C) Clear(C) H.E. Clear(B) PickUp(B) OnTable(B) Holding(B) H.E. ~Clear(B) ~OnTable(B) Note: Not all results of each action is mentioned. Ordering • Assume an action called START. Partial Order Planning – No precondition. – All ‘Initial State’ as its effects. • Assume an action called END. – All ‘Goal State’ as its precondition. – No Effect. Partial Order Planning • Partial Plan is a (A,O,L,Agenda) where: – A: set of actions in the plan • Initially {Start, End} – O: temporal orderings between actions • Initially {Start<End} – Agenda: open preconditions that need to be satisfied along with the action which needs them. • Initially all preconditions of End such as {(BeHome,End),(HaveMoney,End)}. Partial Order Planning • L: The set of Causal Links Q – Initially Empty. A1 – Causal Link: Action A2 has precondition Q that is established in the plan by action A1. A2 Clear(B) Unstack(C,B) Putdown(A,B) • Example: Partial Order Planning START: STACK(B,C) On(C,A) Holding(B) On(B,C) OnTable(A) Clear(C) H.E. OnTable(B) Clear(B) END: On(A,B) On(B,C) OnTable(C) Clear(C) Clear(A) – A ={Start, Stack(B,C), End} – O ={Start<End, Stack(B,C)<End} – L ={(Stack(B,C),On(B,C),End)} – Agenda={(On(A,B),End), (OnTable(C),End), (Holding(B),Stack(B,C), (Clear(C),Stack(B,C)}. Partial Order Planning • A causal link (A1, Q, A2) represents the assertion that the role of A1 is to establish proposition Q for A2. This tells future search steps to “protect” Q in the interval between A1 and A2. • Action B threatens causal link (A1, Q, A2) if: 1. B has Q as a delete effect, and 2. B could come between A1 and A2, i.e. O (A1 < B < A2) is consistent. • For example: PutDown(C,B) is a threat for: Unstack(C,B) Clear(B) PutDown(A,B) POP(<A,O,L>, agenda) 1. Termination: If agenda is empty return <A,O,L> Finally, POP’s Code. 2. Goal selection: Let <Q,Aneed> be a pair on the agenda 3. Action selection: Let Aadd = choose an action that adds Q if no such action exists, then return failure Let L’= L {Aadd →Q Aneed}, and let O’ = O {Aadd < Aneed}. If Aadd is newly instantiated, then A’ = A {Aadd} and O’ = O {A0 < Aadd < A} (otherwise, let A’ = A) 4. Updating of goal set: Let agenda’ = agenda -{<Q,Aneed>}. If Aadd is newly instantiated, then for each conjunction, Qi, of its precondition, add <Qi,Aadd> to agenda’ 5. Causal link protection: For every action At that might threaten a causal link Ap →p Ac, add a consistent ordering constraint, either (a) Demotion: Add At < Ap to O’ (b) Promotion: Add Ac < At to O’ (c) Inequality constraints If neither constraint is consistent, then return failure 6. Recursive invocation: POP((<A’,O’,L’>, agenda’) • Using Variables: Last POP Notes. – You need not add UnStack(A,B) when you need Clear(B). Just add Unstack(x,B) and add binding as a next step. • Heuristics: – What to do in ChooseGoal and ChooseAction? • Main Idea: Planning Graph – To construct a graph of possible outcomes. … … … • Initial Conditions: (and (garbage) (cleanHands) (quiet)) Dinner Date Domain • Goal: (and (dinner) (present) (not (garbage)) • Actions: – Cook :precondition (cleanHands) :effect (dinner) – Wrap :precondition (quiet) :effect (present) – Carry :precondition :effect (and (not (garbage)) (not (cleanHands)) – Dolly :precondition :effect (and (not (garbage)) (not (quiet))) Dinner Date Graph Inconsistent Effects Mutual Exclusion Classes Competing Needs Interference (Prec-Effect) Inconsistent Support p Observation 1 ¬q ¬r p A q p A ¬q q A ¬q B ¬r p r ¬q B ¬r Propositions monotonically increase (always carried forward by no-ops) q r ¬r p Observation 2 ¬q ¬r p A q p A ¬q q A ¬q B ¬r p r q ¬q B ¬r Actions monotonically increase r ¬r Observation 3 p p p q q q r r r … … … A Proposition Mutex relationships monotonically decrease A A A Observation 4 p p p p q q q q … B C r s … B C r s … B C r s … Action mutex relationships monotonically decrease Observation 5 (Sum Up) Planning Graph ‘levels off’. • After some time k, all levels are identical. • Because it’s a finite space, the set of literals never decreases and mutexes don’t reappear. Graph Plan Algorithm: Graph Plan Algorithm • Grow the planning graph (PG) until all goals are reachable and not mutex. (If PG levels off first, fail) • Search the PG for a valid plan • If non found, add a level to the PG and try again Search for a solution plan Search for a solution plan • Backward chain on the planning graph • Achieve goals level by level • At level k, pick a subset of non-mutex actions to achieve current goals. Their preconditions become the goals for k-1 level. • Build goal subset by picking each goal and choosing an action to add. Use one already selected if possible. Do forward checking on remaining goals (backtrack if can’t pick non-mutex action) Just Another Planning Approach Planning By Logic (SAT-Plan): 1. Convert the planning problem into a logic problem. 2. Solve the logic problem. SAT Plan Example INITIAL STATE: At(P1,SFO)0 AT(C1,JFK)0 Plane(P1) Cargo(C1) Airport(SFO) Airport(JFK). RULES: At(x,y)t FLY(x,y,z)t Airplane(x) Airport(y) Airport(z) At(x,z)t+1 At(x,y)t+1 … GOAL STATE: AT(C1,SFO)x • POP: Most human-like. • Graph Plan: Winner of planning contests. Sum Up • SAT Plan: Widely used in real problem as: – Hardcode logic solvers. – Mathematics and Optimization. • Note: Combinations are also used. Implement either POP or Graph-Plan. EXERCISES & Projects As Exercise: On a hard-coded domain without variableinstantiating. – Send To: [email protected] – Subject: AIEX-C11 As Project: Read the domain as PDDL, have variable instantiation, and all.
© Copyright 2024 Paperzz