Lecture 3 Statespaces and Uninformed Search ICS 271

  • Slides: 58
Download presentation
Lecture 3: State-spaces and Uninformed Search ICS 271 Fall 2006 ICS-271: Notes 3: 1

Lecture 3: State-spaces and Uninformed Search ICS 271 Fall 2006 ICS-271: Notes 3: 1

Overview • Intelligent agents: problem solving as search • • State-space problem formulation consists

Overview • Intelligent agents: problem solving as search • • State-space problem formulation consists of – state space – operators, successor function – start state – goal states – Cost function The search graph • A Search Tree is an efficient way to represent the search process • There a variety of search algorithms, including – Depth-First Search – Breadth-First Search – Others which use heuristic knowledge (in future lectures) ICS-271: Notes 3: 2

Robot block world • • • Given a set of blocks in a certain

Robot block world • • • Given a set of blocks in a certain configuration, Move the blocks into a goal configuration. Example : – (c, b, a) (b, c, a) A A B C C B Move (x, y) ICS-271: Notes 3: 3

Operator Description ICS-271: Notes 3: 4

Operator Description ICS-271: Notes 3: 4

Problem-Solving Agents • Intelligent agents can solve problems by searching a state-space • State-space

Problem-Solving Agents • Intelligent agents can solve problems by searching a state-space • State-space Model – the agent’s model of the world – usually a set of discrete states – e. g. , in driving, the states in the model could be towns/cities • Goal State(s) – a goal is defined as a desirable state for an agent – there may be many states which satisfy the goal • e. g. , drive to a town with a ski-resort – or just one state which satisfies the goal • e. g. , drive to Mammoth • Operators – operators are legal actions which the agent can take to move from one state to another ICS-271: Notes 3: 5

The Traveling Salesperson Problem • • • Find the shortest tour that visits all

The Traveling Salesperson Problem • • • Find the shortest tour that visits all cities without visiting any city twice and return to starting point. State: sequence of cities visited S 0 = A C B A D F E ICS-271: Notes 3: 6

The Traveling Salesperson Problem • • • Find the shortest tour that visits all

The Traveling Salesperson Problem • • • Find the shortest tour that visits all cities without visiting any city twice and return to starting point. State: sequence of cities visited S 0 = A C B A D F • SG = a complete tour E ICS-271: Notes 3: 7

Example: 8 -queen problem ICS-271: Notes 3: 8

Example: 8 -queen problem ICS-271: Notes 3: 8

The Sliding Tile Problem Up Down Left Right ICS-271: Notes 3: 9

The Sliding Tile Problem Up Down Left Right ICS-271: Notes 3: 9

State space of the 8 puzzle problem ICS-271: Notes 3: 10

State space of the 8 puzzle problem ICS-271: Notes 3: 10

Searching the search space • • • Uninformed Blind search – Breadth-first – uniform

Searching the search space • • • Uninformed Blind search – Breadth-first – uniform first – depth-first – Iterative deepening depth-first – Bidirectional – Branch and Bound Informed Heuristic search – Greedy search, hill climbing, Heuristics Important concepts: – Completeness – Time complexity – Space complexity – Quality of solution ICS-271: Notes 3: 11

Breadth-first search • • Expand shallowest unexpanded node Fringe: nodes waiting in a queue

Breadth-first search • • Expand shallowest unexpanded node Fringe: nodes waiting in a queue to be explored, also called OPEN • Implementation: – fringe is a first-in-first-out (FIFO) queue, i. e. , new successors go at end of the queue. Is A a goal state? ICS-271: Notes 3: 12

Breadth-first search • • Expand shallowest unexpanded node Implementation: – fringe is a FIFO

Breadth-first search • • Expand shallowest unexpanded node Implementation: – fringe is a FIFO queue, i. e. , new successors go at end Expand: fringe = [B, C] Is B a goal state? ICS-271: Notes 3: 13

Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO

Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO queue, i. e. , new successors go at end Expand: fringe=[C, D, E] Is C a goal state? ICS-271: Notes 3: 14

Breadth-first search • • Expand shallowest unexpanded node Implementation: – fringe is a FIFO

Breadth-first search • • Expand shallowest unexpanded node Implementation: – fringe is a FIFO queue, i. e. , new successors go at end Expand: fringe=[D, E, F, G] Is D a goal state? ICS-271: Notes 3: 15

Example: Map Navigation A B C G S D E F S = start,

Example: Map Navigation A B C G S D E F S = start, G = goal, other nodes = intermediate states, links = legal transitions ICS-271: Notes 3: 16

Initial BFS Search Tree S D A D B C E E A B

Initial BFS Search Tree S D A D B C E E A B C S G D E F Note: this is the search tree at some particular point in in the search. ICS-271: Notes 3: 17

Search Method 1: Breadth First Search S D A B C A D E

Search Method 1: Breadth First Search S D A B C A D E E S B F (Use the simple heuristic of not generating a child node if that node is a parent to avoid “obvious” loops: this clearly does not avoid all loops and there are other ways to do this) ICS-271: Notes 3: 18

Breadth-First Search ICS-271: Notes 3: 19

Breadth-First Search ICS-271: Notes 3: 19

Breadth-First-Search (*) 1. Put the start node s on OPEN 2. If OPEN is

Breadth-First-Search (*) 1. Put the start node s on OPEN 2. If OPEN is empty exit with failure. 3. Remove the first node n from OPEN and place it on CLOSED. 4. If n is a goal node, exit successfully with the solution obtained by tracing back pointers from n to s. 5. Otherwise, expand n, generating all its successors attach to them pointers back to n, and put them at the end of OPEN in some order. 6. Go to step 2. For Shortest path or uniform cost: 5’ Otherwise, expand n, generating all its successors attach to them pointers back to n, and put them in OPEN in order of shortest cost path. * This simplified version does not check for loops ICS-271: Notes 3: 20

What is the Complexity of Breadth-First Search? • Time Complexity – assume (worst case)

What is the Complexity of Breadth-First Search? • Time Complexity – assume (worst case) that there is 1 goal leaf at the RHS – so BFS will expand all nodes d=0 d=1 = 1 + b 2+ = O (bd) . . + bd d=2 G • Space Complexity – how many nodes can be in the queue (worst-case)? – at depth d-1 there are bd unexpanded nodes in the Q = O (bd) d=0 d=1 d=2 G ICS-271: Notes 3: 21

Examples of Time and Memory Requirements for Breadth-First Search Depth of Solution Nodes Expanded.

Examples of Time and Memory Requirements for Breadth-First Search Depth of Solution Nodes Expanded. Time 0 1 1 millisecond 100 bytes 2 111 0. 1 seconds 11 kbytes 4 11, 111 11 seconds 1 megabyte 8 108 31 hours 11 giabytes 12 1012 35 years 111 terabytes Memory Assuming b=10, 1000 nodes/sec, 100 bytes/node ICS-271: Notes 3: 22

Breadth-First Search (BFS) Properties • • • Solution Length: optimal Expand each node once

Breadth-First Search (BFS) Properties • • • Solution Length: optimal Expand each node once (can check for duplicates) Search Time: O(Bd) Memory Required: O(Bd) Drawback: requires exponential space 1 2 3 4 8 9 10 11 7 6 5 12 13 14 15 ICS-271: Notes 3: 23

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = Last In

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = Last In First Out (LIPO) queue, i. e. , put successors at front Is A a goal state? ICS-271: Notes 3: 24

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[B, C] Is B a goal state? ICS-271: Notes 3: 25

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[D, E, C] Is D = goal state? ICS-271: Notes 3: 26

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[H, I, E, C] Is H = goal state? ICS-271: Notes 3: 27

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[I, E, C] Is I = goal state? ICS-271: Notes 3: 28

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[E, C] Is E = goal state? ICS-271: Notes 3: 29

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[J, K, C] Is J = goal state? ICS-271: Notes 3: 30

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[K, C] Is K = goal state? ICS-271: Notes 3: 31

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[C] Is C = goal state? ICS-271: Notes 3: 32

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[F, G] Is F = goal state? ICS-271: Notes 3: 33

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[L, M, G] Is L = goal state? ICS-271: Notes 3: 34

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue,

Depth-first search • • Expand deepest unexpanded node Implementation: – fringe = LIFO queue, i. e. , put successors at front queue=[M, G] Is M = goal state? ICS-271: Notes 3: 35

Search Method 2: Depth First Search (DFS) S D A B D A E

Search Method 2: Depth First Search (DFS) S D A B D A E D F G C S G D C B E F Here, to avoid repeated states assume we don’t expand any child node which appears already in the path from the root S to the parent. (Again, one could use other strategies) ICS-271: Notes 3: 36

Depth-First Search ICS-271: Notes 3: 37

Depth-First Search ICS-271: Notes 3: 37

ICS-271: Notes 3: 38

ICS-271: Notes 3: 38

Depth-First-Search (*) 1. Put the start node s on OPEN 2. If OPEN is

Depth-First-Search (*) 1. Put the start node s on OPEN 2. If OPEN is empty exit with failure. 3. Remove the first node n from OPEN and place it on CLOSED. 4. If n is a goal node, exit successfully with the solution obtained by tracing back pointers from n to s. 5. Otherwise, expand n, generating all its successors attach to them pointers back to n, and put them at the top of OPEN in some order. 6. Go to step 2. ICS-271: Notes 3: 39

What is the Complexity of Depth-First Search? • Time Complexity (d is deepest path)

What is the Complexity of Depth-First Search? • Time Complexity (d is deepest path) – assume (worst case) that there is 1 goal leaf at the RHS – so DFS will expand all nodes =1 + b 2+ = O (bd) • . . + bd Space Complexity – how many nodes can be in the queue (worst-case)? – at depth l < d we have b-1 nodes – at depth d we have b nodes – total = (d-1)*(b-1) + b = O(bd) d=0 d=1 d=2 G d=0 d=1 d=2 d=3 d=4 ICS-271: Notes 3: 40

Techniques for Avoiding Repeated States S B C State Space • • • C

Techniques for Avoiding Repeated States S B C State Space • • • C C S B S Example of a Search Tree Method 1 – do not create paths containing cycles (loops) Method 2 – never generate a state generated before • must keep track of all possible states (uses a lot of memory) • e. g. , 8 -puzzle problem, we have 9! = 362, 880 states Method 1 is most practical, work well on most problems ICS-271: Notes 3: 41

Example, diamond networks ICS-271: Notes 3: 42

Example, diamond networks ICS-271: Notes 3: 42

Depth-First Search (DFS) Properties • • • Non-optimal solution path Incomplete unless there is

Depth-First Search (DFS) Properties • • • Non-optimal solution path Incomplete unless there is a depth bound Reexpansion of nodes (when the search space is a graph), Exponential time Linear space ICS-271: Notes 3: 43

Comparing DFS and BFS • • • Same worst-case time Complexity, but – In

Comparing DFS and BFS • • • Same worst-case time Complexity, but – In the worst-case BFS is always better than DFS – Sometime, on the average DFS is better if: • many goals, no loops and no infinite paths BFS is much worse memory-wise • DFS is linear space • BFS may store the whole search space. In general • BFS is better if goal is not deep, if infinite paths, if many loops, if small search space • DFS is better if many goals, not many loops, • DFS is much better in terms of memory ICS-271: Notes 3: 44

Iterative Deepening Search (DFS) • Every iteration is a DFS with a depth cutoff.

Iterative Deepening Search (DFS) • Every iteration is a DFS with a depth cutoff. Iterative deepening (ID) 1. 2. 3. 4. i=1 While no solution, do DFS from initial state S 0 with cutoff i If found goal, stop and return solution, else, increment cutoff Comments: • IDS implements BFS with DFS • Only one path in memory • BFS at step i may need to keep 2 i nodes in OPEN ICS-271: Notes 3: 45

Iterative deepening search L=0 ICS-271: Notes 3: 46

Iterative deepening search L=0 ICS-271: Notes 3: 46

Iterative deepening search L=1 ICS-271: Notes 3: 47

Iterative deepening search L=1 ICS-271: Notes 3: 47

Iterative deepening search L=2 ICS-271: Notes 3: 48

Iterative deepening search L=2 ICS-271: Notes 3: 48

Iterative Deepening Search L=3 ICS-271: Notes 3: 49

Iterative Deepening Search L=3 ICS-271: Notes 3: 49

Iterative deepening search ICS-271: Notes 3: 50

Iterative deepening search ICS-271: Notes 3: 50

Comments on Iterative Deepening Search • Complexity – Space complexity = O(bd) • (since

Comments on Iterative Deepening Search • Complexity – Space complexity = O(bd) • (since its like depth first search run different times) – Time Complexity • 1 + (1+b) + (1 +b+b 2) +. . . . (1 +b+. . bd) • = O(bd) (i. e. , asymptotically the same as BFS or DFS to limited depth d in the worst case) • The overhead in repeated searching of the same subtrees is small relative to the overall time – e. g. , for b=10, only takes about 11% more time than BFS • A useful practical method – combines • guarantee of finding an optimal solution if one exists (as in BFS) • space efficiency, O(bd) of DFS • But still has problems with loops like DFS ICS-271: Notes 3: 51

Iterative Deepening (DFS) • Time: ¢ ¢ ¢ ¢ BFS time is O(bn) b

Iterative Deepening (DFS) • Time: ¢ ¢ ¢ ¢ BFS time is O(bn) b is the branching degree IDS is asymptotically like BFS, For b=10 d=5 d=cut-off DFS = 1+10+100, …, =111, 111 IDS = 123, 456 Ratio is ICS-271: Notes 3: 52

Bidirectional Search • Idea – simultaneously search forward from S and backwards from G

Bidirectional Search • Idea – simultaneously search forward from S and backwards from G – stop when both “meet in the middle” – need to keep track of the intersection of 2 open sets of nodes • What does searching backwards from G mean – need a way to specify the predecessors of G • this can be difficult, • e. g. , predecessors of checkmate in chess? – what if there are multiple goal states? – what if there is only a goal test, no explicit list? • Complexity – time complexity is best: O(2 b(d/2)) = O(b (d/2)) – memory complexity is the same ICS-271: Notes 3: 53

Bi-Directional Search ICS-271: Notes 3: 54

Bi-Directional Search ICS-271: Notes 3: 54

Uniform Cost Search • • Expand lowest-cost OPEN node (g(n)) In BFS g(n) =

Uniform Cost Search • • Expand lowest-cost OPEN node (g(n)) In BFS g(n) = depth(n) ¢ Requirement ¢ g(successor)(n)) g(n) ICS-271: Notes 3: 55

Uniform cost search 1. Put the start node s on OPEN 2. If OPEN

Uniform cost search 1. Put the start node s on OPEN 2. If OPEN is empty exit with failure. 3. Remove the first node n from OPEN and place it on CLOSED. 4. If n is a goal node, exit successfully with the solution obtained by tracing back pointers from n to s. 5. Otherwise, expand n, generating all its successors attach to them pointers back to n, and put them in OPEN in order of shortest cost 6. Go to step 2. DFS Branch and Bound At step 4: compute the cost of the solution found and update the upper bound U. at step 5: expand n, generating all its successors attach to them pointers back to n, and put on top of OPEN. Compute cost of partial path to node and prune if larger than U. ICS-271: Notes 3: 56.

Comparison of Algorithms ICS-271: Notes 3: 57

Comparison of Algorithms ICS-271: Notes 3: 57

Summary • A review of search – a search space consists of states and

Summary • A review of search – a search space consists of states and operators: it is a graph – a search tree represents a particular exploration of search space • There are various strategies for “uninformed search” – breadth-first – depth-first – iterative deepening – bidirectional search – Uniform cost search – Depth-first branch and bound • Repeated states can lead to infinitely large search trees – we looked at methods for detecting repeated states • All of the search techniques so far are “blind” in that they do not look at how far away the goal may be: next we will look at informed or heuristic search, which directly tries to minimize the distance to the goal. Example we saw: greedy search ICS-271: Notes 3: 58