Professional Documents
Culture Documents
Introduction To Planning & State-Space Search
Introduction To Planning & State-Space Search
Introduction To Planning & State-Space Search
G51IAI – Introduction to AI
Andrew Parkes
http://www.cs.nott.ac.uk/~ajp/
UCS for Graph Search
• From last lecture:
• Search pattern:
“Search all nodes of cost c before those of cost c+1”
• Method:
1. store the cost g of the path used to reach the node
2. use such costs in deciding the ordering in the queue
Uniform 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
3
Uniform Cost Search in Graph
1. fringe MAKE-EMPTY-QUEUE()
2. fringe INSERT( root_node ) // with g=0
3. loop {
1. if fringe is empty then return false // finished without goal
2. node REMOVE-SMALLEST-COST(fringe)
3. if node is a goal
1. print node and g
2. return true // that found a goal
4. Lg EXPAND(node) // Lg is set of neighbours with their g costs
// NOTE: do not check Lg for goals here!!
5. fringe INSERT-IF-NEW(Lg, fringe ) // ignore revisited nodes
// unless is with new better g
}
4
Properties 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
5
Complexity 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?
6
When 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
7
Example of “Implicit Graph”
• “Hypercube in n dimensions”
– nodes
• any binary (0’s and 1’s) string with n digits
• e.g. 1000101 for n=7
– 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
8
Hypercube Example: Cube
• Example: n=3, 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
(0,0,1)
(0,1,0)
(0,0,0) (1,0,0)
9
Example 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
10
Planning & 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
11
G51IAI Planning
2N-1
• Operator
– a.k.a. “action”, or “move”
– A set of actions that moves the
problem from one state to
another
G51IAI Planning
• State Space
– The set of all legal states
G51IAI Planning
• Path Cost
– How much it costs to take a
particular path
G51IAI Planning
• Optimal Plan
– A mincost plan, i.e. a plan with
minimal path cost
G51IAI Planning
5 4 1 4
2 7
3
6 1 8 4
2
8 5 6
8
4
7 3 2 7
3 8
6 5
• “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
30
Planning 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 4*25! 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)
31
Planning Representations 2
• Actions are described by rules for changing the state
• “move blank from (1,1) at time t to (1,2) at time
t+1” becomes
if val(1,1,t) = B then permit {
val(1,2,t+1) := B
val(1,1,t+1 ) := 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
32
Planning 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
33
Planning 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
34
Planning 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
35
Why 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
36
Summary
• 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
37
Questions?
38