Uninformed Search Introduction to Artificial Intelligence Dr Robin
Uninformed Search Introduction to Artificial Intelligence Dr. Robin Burke
Review l Problem domain ¡Static l only our actions change the world ¡Deterministic l actions always work the way we expect ¡Fully-observable l we always know everything we need about the world l To solve ¡World = state representation ¡Solution = sequence of operators l transform the initial state into the goal state
State Space l The collection of all world states l Connected by edges which are operations l Solution ¡a path through the state space ¡leads from initial state to goal state l Problem solving = graph search
Farmer State Space MFN (S, S, S, S) MG N MFS MCN MG S X. . . X (N, S, S, S) (S, N, N, S) MWN (S, S, N, N) MWS (N, N, S, S) (N, S, N, S) MFS (S, S, S, N) MFN (S, S, N, S) MWN MWS (N, N, N, S) MCS (N, S, S, N) (N, S, N, N) (N, N, S, N) (S, N, S, S) (S, N, N, N) (S, N, S, N) (N, N, N, N) Illegal nodes
Search Tree l For better bookkeeping ¡transform the state space into a search tree l Nodes ¡not just states but ¡state, parent, action, cost, depth l. I said path, but you really don’t want a million copies of the same path l(parent, edge) are sufficient to reconstruct
Search Tree (ignore illegal states) N 1: (S, S, S, S), {} MG N N 2: (N, S, N, S), (N 1, MGN) MFS N 3: (S, S, N, S), (N 2, MFS) MWN N 4: (N, N, N, S), (N 3, MWN) MCN N 9: (N, S, N, N), (N 3, MCN) MG S MG N 10: (S, S, S, N ), (N 9, MGS) S N 5: (S, N, S, S), (N 4, MGS) MWN MCN N 6: (N, N, S, N ), (N 5, MCN) N 11: (N, N, S, N ), (N 10, MWN) MFS N 7: (S, N, S, N ), (N 6, MFS) N 12: (S, N, S, N ), (N 11, MFS) MG N N 8: (N, N, N, N ), (N 7, MGN)) N 13: (N, N, N, N ), (N 12, MGN)
Basic idea l Given ¡ a set of nodes N ¡ a successor function f that l takes a node n l returns all of the nodes S reachable from n in a single action l Algorithm ¡ ¡ ¡ pick n from N (somehow) s = state(n) p = path(n) S = f(s) for all s’, a S l if s is solution, done l if s is illegal, discard l else • create new node na = <s’, (n, a)> l N = N – n + na ¡ repeat
Search strategies l All of the interesting action is ¡maintenance of the active nodes l“search frontier” l Classes of strategies ¡uninformed search lno knowledge of the search space is assumed ldo not prefer one state over another ¡informed search luse knowledge of the search space lheuristic search
Uninformed Strategies l Depth-first search l Breadth-first search l Iterative deepening
Characterizing search strategies l Completeness ¡ does it always find the answer? l Time ¡ how long does it take? ¡ worst-case run time performance / complexity l Space ¡ how much memory do we need? ¡ worst-case space complexity l Parameters ¡ b: branching factor of the search space l choices at each node ¡ d: depth of the solution l # of steps ¡ m: maximum depth of the tree l could be infinite
Depth-first search l Unexamined nodes ¡last-in first-out stack l Meaning ¡grab the top node on the node list ¡replace with its children ¡grab the top one of these ¡etc.
Example: path planning l states = positions l initial state v 2 v 1 start v 5 v 4 v 3 ¡v 5 l goal state ¡v 6 target v 7
Search Tree?
Search Tree n 1: v 5, init n 2: v 7, n 1 n 3: v 4, n 1 n 5: v 6, n 2 n 6: v 7, n 3 n 4: v 1, n 11: v 2, n 4 n 7: v 6, n 3 n 8: v 3, n 3 n 13: v 3, n 4 n 15: v 5, n 11 n 16: v 4, n 11 n 9: v 6, n 6 n 10: v 6, n 6 n 14: v 6, n 13 n 17: v 6, n 16 n 18: v 7, n 16 n 20: v 3, n 16 n 19: v 6, n 18 n 21: v 6, n 20
DFS l Start with search node n 1 l Add successors to stack ¡assume we enumerate clockwise from right ¡n 2, n 3, n 4 l Pop off the most recent one ¡n 4 l Expand that node l etc.
n 1: v 5, init open closed n 4: v 1, n 11: v 2, n 4 n 21: v 6, n 20: v 3, n 16 repeated state n 17: v 6, n 16 n 18: v 7, n 16: v 4, n 11 n 15: v 5, n 11 n 16: v 4, n 11: v 2, n 4 n 20: v 3, n 16 n 13: v 3, n 4: v 1, n 1 n 3: v 4, n 1 n 2: v 7, n 1 goal state n 21: v 6, n 20 n 1: v 5, init path: v 5, v 1, v 2, v 4, v 3, v 6 n 15: v 5, n 11
Properties of DFS l Complete? ¡ Not always l fails in infinite-depth spaces ¡ Must avoid repeated states along path l Time? ¡ O(bm): terrible if m is much larger than d ¡ but if solutions are dense, may be OK l Space? ¡ O(bm), i. e. , linear space, if no repeated states ¡ but closed list makes it O(bm) in worst case l Optimal? ¡ No ¡ Returns first answer, not necessarily shortest path
Breadth-first search l Unexamined nodes ¡first-in first-out queue l Meaning ¡grab the first thing on the queue ¡put its children on the end ¡grab the next thing l Effect ¡we don’t examine any paths of length k ¡until we’ve looked at all paths of length k-1 ¡achieves optimality
n 1: v 5, init open closed n 2: v 7, n 1 n 3: v 4, n 1 n 5: v 6, n 2 n 11: v 2, n 4 goal state n 13: v 3, n 4 n 7: v 6, n 3 n 8: v 3, n 3 n 6: v 7, n 3 n 5: v 6, n 2 n 4: v 1, n 1 n 3: v 4, n 1 n 2: v 7, n 1: v 5, init path: v 5, v 7, v 6 n 4: v 1, n 1
Properties of BFS l Complete ¡If b is finite l Time ¡ 1+b+b 2+b 3+… +bd + b(bd-1) = O(bd+1) ¡Looks better than O(bm) l Space Often a bigger ¡Worst case = all nodes in memory problem ¡O(bd+1) l Optimal ¡Yes, for uniform cost case than time
Iterative Deepening l How to get optimality of BFS ¡without the space penalty l Counter-intuitive idea ¡create a depth limit for DFS l DFS(k) l fails if solution is deeper than k ¡do DFS(k) over and over again l as k increases from 1 to d l Seems inefficient ¡throw away bk nodes after DFS(k) ¡re-generate them for DFS(k+1)
k=1 open n 1: v 5, init closed n 2: v 7, n 1 n 3: v 4, n 1 failure n 4: v 1, n 1 n 3: v 4, n 1 n 2: v 7, n 1: v 5, init n 4: v 1, n 1
n 1: v 5, init open closed n 3: v 4, n 1 n 4: v 1, n 11: v 2, n 4 n 7: v 6, n 3 n 8: v 3, n 3 n 13: v 3, n 4 goal state n 6: v 7, n 3 n 11: v 2, n 4 n 13: v 3, n 4: v 1, n 1 n 3: v 4, n 1 n 2: v 7, n 1: v 5, init path: v 5, v 4, v 6
Wasted time? l Number of nodes generated in a depth-limited search to depth d with branching factor b: NDLS = b 0 + b 1 + b 2 + … + bd-2 + bd-1 + bd l Number of nodes generated in an iterative deepening search to depth d with branching factor b: NIDS = (d+1)b 0 + db 1 + (d-1)b 2 + … + 3 bd-2 +2 bd-1 + 1 bd l For b = 10, d = 5, ¡ NDLS = 1 + 100 + 1, 000 + 100, 000 = 111, 111 ¡ NIDS = 6 + 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 456 l Overhead = (123, 456 - 111, 111)/111, 111 = 11% l In general ¡ NIDS is dominated by bd term ¡ O(bd)
Properties of IDS l Complete? ¡ Yes l Time? ¡ O(bd) ¡ same as BFS, maybe some overhead l Space? ¡ O(bm), i. e. , linear space, if no repeated states l Optimal? ¡ Yes, for uniform cost
Bi-directional search l In some (but not all) search spaces ¡steps are reversible ¡goal state unique l Counter-example ¡get to work l If so ¡we can work backwards from end state ¡as well as forward from inital state ¡two BFS operations
Properties of Bidirectional BFS l Complete? ¡ Yes l Time? ¡ O(bd/2) ¡ can be a big savings l Space? ¡ O(bd/2) ¡ space still a problem l Optimal? ¡ Yes, for uniform cost
Paths with costs l What if different operations have different costs / benefits? ¡distance ¡$$ ¡energy ¡in games, health
1 v 1 4 v 3 3 1 2 start 6 v 4 1 v 5 4 3 1 v 6 target 1 v 2 5 v 7
Costs l If costs are not uniform ¡then search must take this into account ¡otherwise, optimality is lost ¡shortest in terms of # operations may be very expensive l Question ¡how to organize search to take cost into account?
Thursday l Read Chapter 4. 1 -4. 2
- Slides: 31