Title: Introduction To Planning
1Introduction To Planning State-Space Search
- G51IAI Introduction to AI
- Andrew Parkes
- http//www.cs.nott.ac.uk/ajp/
2UCS for Graph Search
- From last lecture
- Uniform Cost Search finds a min-cost path to a
goal in a graph - Search pattern
- Search all nodes of cost c before those of cost
c1 - Method
- store the cost g of the path used to reach the
node - use such costs in deciding the ordering in the
queue
3Uniform Cost Search (UCS)
- Explicitly store the cost of a node with that
node convention g is the path-cost - Queue Processing Always remove the smallest cost
node first
4Uniform Cost Search in Graph
- fringe ? MAKE-EMPTY-QUEUE()
- fringe ? INSERT( root_node ) // with g0
- loop
- if fringe is empty then return false // finished
without goal - node ? REMOVE-SMALLEST-COST(fringe)
- if node is a goal
- print node and g
- return true // that found a goal
- Lg ? EXPAND(node) // Lg is set of neighbours with
their g costs //
NOTE do not check Lg for goals here!! - fringe ? INSERT-IF-NEW(Lg, fringe ) // ignore
revisited nodes // unless is with new
better g -
5Properties of UCS
- Completeness
- If there is a path to a goal then UCS will find
it - If there is no path, then UCS will eventually
report that the goal is unreachable - Optimality
- UCS will report a minimum cost path (there might
be many) - Systematic
- With appropriate code to prevent re-visiting
nodes UCS will only expand each node once
6Complexity of UCS on a Graph
- Suppose graph has n nodes and e edges
- e.g. n cities, and e roads
- Worst case (e.g. no goal is reachable)
- nodes expanded n
- work per node O(n) (check that not already
visited) - edges visited O(e) O(n2)
- overall O(n2)
- So UCS is polynomial time in size of graph
- But AI is hard because of problems for which
time needed is exponential in the size of the
problem - Paradox?
7When is UCS exponentially hard?
- The graph itself can be exponentially sized!
- The size of the natural description of the
problem might be a number S - but the graph itself has size exponential in S
- the graph itself is not given directly
- only get a set of rules to generate the graph
- Planning is an example of this
- First an easier example the hypercube
8Example of Implicit Graph
- Hypercube in n dimensions
- nodes
- any binary (0s and 1s) string with n digits
- e.g. 1000101 for n7
- edge between nodes n1 and n2 if and only if they
differ only in one digit - e.g. 1000101 has an edge to 1000111 but
not to 1000011
9Hypercube Example Cube
- Example n3, a cube,
- nodes 000, 001, 010, etc for xyz coordinates
- e.g. 001 means (x,y,z)(0,0,1)
- edges node 000 has edges to 001,010,100
10Example of Implicit Graph
- Hypercube in n dimensions
- node binary number with n digits
- edge between nodes n1 and n2 iff they differ only
in one digit - Size of description just the space to write the
value of n - Number of nodes 2n
- Number of edges 2n 3 / 2
- The graph itself is exponentially bigger than our
description of it. - On discussing polynomial or exponential in the
size we need to be careful what we mean by the
size - Similar things do happen with planning problems
puzzles
11Planning Puzzles
- These are search problems in which we have some
system and - the system can be in many different states
- want to transform it from one state into another
- by applying a sequence of actions
- Examples
- Towers of Hanoi
- Tile Puzzles
- Coursework TWO
12Planning Problem - Towers of Hanoi
State The positions of the
ringsAction Move one ring at a timeRules
No ring can ever be on top of a smaller
ringGoal Move the tower to peg 2
13Planning Problem - Towers of Hanoi
14Planning Problem - Towers of Hanoi
Note it was illegal to move the green on top of
the red
15Planning Problem - Towers of Hanoi
16Planning Problem - Towers of Hanoi
Note finally we get to move blue to its final
place
17Planning Problem - Towers of Hanoi
18Planning Problem - Towers of Hanoi
19Planning Problem - Towers of Hanoi
Note SUCCESS in 7 moves
20Planning Problem - Towers of Hanoi
- Analysis of the problem shows that the lower
bound for the number of moves is - 2N-1
- Since N appears as the exponent we have an
exponential function - The number of reachable states is at least this
large
21Planning Problem Definition - 1
- Initial State
- The initial state of the problem, defined in some
suitable manner - Operator
- a.k.a. action, or move
- A set of actions that moves the problem from one
state to another
22Planning Problem Definition - 1
- Neighbourhood (Successor Function)
- The set of all possible states reachable from a
given state with one move - State Space
- The set of all legal states
23Planning Problem Definition - 2
- Goal Test
- A test applied to a state which returns if we
have reached a state that solves the problem - Path Cost
- How much it costs to take a particular path
24Planning Problem Definition - 2
- Plan
- A sequence of actions applied to a state to
transform it into another state - Takes us from the initial state to the goal state
- Optimal Plan
- A mincost plan, i.e. a plan with minimal path cost
25Problem Definition Tile Puzzle Example
Initial State
Goal State
26Problem Definition - Example
- States
- A description of each of the eight tiles in each
location that it can occupy. It is also useful to
include the blank - Operators
- The blank moves left, right, up or down
27Problem Definition - Example
- Goal Test
- The current state matches a certain state (e.g.
one of the ones shown on previous slide) - Path Cost
- Each move of the blank costs 1
28Planning Graphs 1
- How does the tile puzzle relate to previous
lectures on searching a graph? - Regard each puzzle state as a node of a graph
- Actions, move blank, correspond to legal moves
between the states. - actions generate edges between the nodes
29Planning Graphs 2
- Actions, move blank, correspond to legal moves
between the states. - actions generate edges between the nodes
- Finding a plan ...
- find a legal sequence of actions from initial to
final state - ... becomes find a path to a goal
- find a path from initial to final node
- Find an optimal plan, becomes
- find a mincost path through the planning graph
30Tile Puzzle - History
- Why is the puzzle so popular?
- Invented by Sam Loyd in 1870s
- On the 4x4 version, the 15-puzzle, he offered a
prize of 1000 prize to transform a particular
initial state to a particular final state - Trick Question
- The problem was unsolvable
- The state space splits into two disconnected
pieces - The planning graph is not connected
- Only half the potential states are reachable from
any state - The reachable state space is 9!/2 181440
31Planning Representations 1
- Paradox? Consider the 24-puzzle.
- In very little space we managed to describe a
planning problem for which the graph has 25!
nodes and about 425! edges - This takes far too much space to write down
explicitly - Instead
- we are describing the state logically
- val(2,2) 9 means the 9 tile is at coords
(2,2) - these are function of time
- That is we can describe the state sequence by
means of val(x,y,t)
32Planning Representations 2
- Actions are described by rules for changing the
state - move blank from (1,1) at time t to (1,2) at time
t1 becomes - if val(1,1,t) B then permit
- val(1,2,t1) B
- val(1,1,t1 ) val(1,2,t)
-
- And nothing else changed
- Note that such a move applies independently of
the values for the other squares and so describes
many edges in the graph
33Planning Representations 3
- In general representing the effects of change in
the real-world is very hard - E.g. Ramification problem
- e.g. if I drive to derby some things will
automatically change, but not others - cell phone tower
- but not cell phone number
- in real-world then this can be hard to represent
- Puzzles and simple planning domains do not have
this problem
34Planning Representations 4
- The standard way in AI to formally express a
planning problem is using the STRIPS notation - STRIPS contains
- fluents the logical quantities that describe
the state and change as a function of time - Actions are described using
- preconditions circumstances in which the action
applies - add delete rules for the changes to the
fluents
35Planning Representations 5
- The standard way in AI to formally express a
planning problem is using the STRIPS notation - A lot of work has gone into solving planning
problems expressed in STRIPS notation - There are general purpose solvers that take any
problem expressed in STRIPS - STRIPS forms an important part of AI history and
current usage - You do not need to know how to use STRIPS for
this course just how to do actions by hand - But (clue!), a part of the history of STRIPS is
relevant to coursework TWO
36Why are planning/puzzles hard?
- The associated graph is exponential in the
number of tiles - We can still use the same blind search methods
- BFS, UCS
- On realistic size problems blind search will use
far too much memory and time - Need to improve the search methods
- planning problems, and puzzles such as tile
puzzle, have driven a lot of progress in search
methods - improved methods are heuristic and use
information about the likely location of goals
37Summary
- Planning problems
- States
- Operators (a.k.a. actions, successor, etc)
- Can be thought of as defining implicitly a graph
- node state
- edge action
- But the graphs are much bigger than maps, mazes,
etc - These drive the need for better search methods
- Next Lecture Informed search methods
38Questions?