Download presentation

Presentation is loading. Please wait.

Published byJayda Newbrough Modified over 3 years ago

1
CS B551: E LEMENTS OF A RTIFICIAL I NTELLIGENCE Instructor: Kris Hauser http://cs.indiana.edu/~hauserk 1

2
A GENDA Searching, data structures, and algorithms Breadth-first search Depth-first search Uniform-cost search 2

3
D EFINING A S EARCH P ROBLEM 3 State space S Successor function: x S SUCC (x) 2 S Initial state s 0 Goal test: x S GOAL? (x) =T or F Arc cost S

4
S TATE G RAPH 4 Each state is represented by a distinct node An arc (or edge) connects a node s to a node s’ if s’ SUCC (s) The state graph may contain more than one connected component

5
S OLUTION TO THE S EARCH P ROBLEM A solution is a path connecting the initial node to a goal node (any one) The cost of a path is the sum of the arc costs along this path An optimal solution is a solution path of minimum cost There might be no solution ! 5 I G

6
S EARCH G RAPH != S TATE G RAPH 6 8 3 5 2 47 16 8 3 5 2 47 16 8 3 5 2 4 7 16 8 3 5 2 47 16 8 3 5 24 7 16 8 3 5 2 47 16 If states are allowed to be revisited, the search tree may be infinite even when the state space is finite If states are allowed to be revisited, the search tree may be infinite even when the state space is finite

7
S EARCH G RAPH N ODE != S TATE 7 PARENT-NODE 8 3 5 2 47 16 STATE Depth of a node N = length of path from root to N (depth of the root = 0) BOOKKEEPING 5Path-Cost 5Depth RightAction Expanded yes... CHILDREN

8
F RINGE OF S EARCH T REE The fringe is the set of all search nodes that haven’t been expanded yet 8 3 5 2 47 16 8 3 5 2 47 16 8 3 5 2 4 7 16 8 3 5 2 47 16 8 3 5 72 4 16 8 3 5 2 47 16

9
S EARCH S TRATEGY The fringe is the set of all search nodes that haven’t been expanded yet The fringe is implemented as a priority queue FRINGE INSERT(node,FRINGE) REMOVE(FRINGE) The ordering of the nodes in FRINGE defines the search strategy 9

10
S EARCH A LGORITHM #1 SEARCH#1 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,FRINGE) 3. Repeat: 4. If empty(FRINGE) then return failure 5.N REMOVE(FRINGE) 6.s STATE(N) 7.For every state s’ in SUCCESSORS(s) 8.Create a new node N’ as a child of N 9.If GOAL?(s’) then return path or goal state 10.INSERT(N’,FRINGE) 10 Expansion of N

11
B LIND S EARCH S TRATEGIES 11

12
B LIND S TRATEGIES Breadth-first Bidirectional Depth-first Depth-limited Iterative deepening Uniform-Cost (variant of breadth-first) 12 Arc cost = 1 Arc cost = c(action) 0

13
B READTH -F IRST S TRATEGY New nodes are inserted at the end of FRINGE 13 23 45 1 67 FRINGE = (1)

14
B READTH -F IRST S TRATEGY New nodes are inserted at the end of FRINGE 14 FRINGE = (2, 3) 23 45 1 67

15
B READTH -F IRST S TRATEGY New nodes are inserted at the end of FRINGE 15 FRINGE = (3, 4, 5) 23 45 1 67

16
B READTH -F IRST S TRATEGY New nodes are inserted at the end of FRINGE 16 FRINGE = (4, 5, 6, 7) 23 45 1 67

17
P ERFORMANCE M EASURES Completeness A search algorithm is complete if it finds a solution whenever one exists [What about the case when no solution exists?] Optimality A search algorithm is optimal if it returns a minimum-cost path whenever a solution exists Complexity It measures the time and amount of memory required by the algorithm 17

18
I MPORTANT P ARAMETERS Maximum number of successors of any state branching factor b of the search tree Minimal length (≠ cost) of a path between the initial and a goal state depth d of the shallowest goal node in the search tree 18

19
E VALUATION b: branching factor d: depth of shallowest goal node Breadth-first search is: Complete? Not complete? Optimal? Not optimal? 19

20
E VALUATION b: branching factor d: depth of shallowest goal node Breadth-first search is: Complete Optimal if step cost is 1 Number of nodes generated: ??? 20

21
E VALUATION b: branching factor d: depth of shallowest goal node Breadth-first search is: Complete Optimal if step cost is 1 Number of nodes generated: 1 + b + b 2 + … + b d = ??? 21

22
E VALUATION b: branching factor d: depth of shallowest goal node Breadth-first search is: Complete Optimal if step cost is 1 Number of nodes generated: 1 + b + b 2 + … + b d = (b d+1 -1)/(b-1) = O(b d ) Time and space complexity is O(b d ) 22

23
T IME AND M EMORY R EQUIREMENTS d# NodesTimeMemory 2111.01 msec11 Kbytes 411,1111 msec1 Mbyte 6~10 6 1 sec100 Mb 8~10 8 100 sec10 Gbytes 10~10 10 2.8 hours1 Tbyte 12~10 12 11.6 days100 Tbytes 14~10 14 3.2 years10,000 Tbytes 23 Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

24
T IME AND M EMORY R EQUIREMENTS d# NodesTimeMemory 2111.01 msec11 Kbytes 411,1111 msec1 Mbyte 6~10 6 1 sec100 Mb 8~10 8 100 sec10 Gbytes 10~10 10 2.8 hours1 Tbyte 12~10 12 11.6 days100 Tbytes 14~10 14 3.2 years10,000 Tbytes 24 Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

25
R EMARK If a problem has no solution, breadth-first may run forever (if the state space is infinite or states can be revisited arbitrary many times) 25 12 14 11 15 10 13 9 5678 4321 12 15 11 14 10 13 9 5678 4321 ?

26
B IDIRECTIONAL S TRATEGY 26 2 fringe queues: FRINGE1 and FRINGE2 s Time and space complexity is O(b d/2 ) O(b d ) if both trees have the same branching factor b Question: What happens if the branching factor is different in each direction?

27
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 27 1 23 45 FRINGE = (1)

28
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 28 1 23 45 FRINGE = (2, 3)

29
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 29 1 23 45 FRINGE = (4, 5, 3)

30
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 30 1 23 45

31
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 31 1 23 45

32
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 32 1 23 45

33
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 33 1 23 45

34
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 34 1 23 45

35
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 35 1 23 45

36
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 36 1 23 45

37
D EPTH -F IRST S TRATEGY New nodes are inserted at the front of FRINGE 37 1 23 45

38
E VALUATION b: branching factor d: depth of shallowest goal node m: maximal depth of a leaf node Depth-first search is: Complete? Optimal? 38

39
E VALUATION b: branching factor d: depth of shallowest goal node m: maximal depth of a leaf node Depth-first search is: Complete only for finite search tree Not optimal Number of nodes generated (worst case): 1 + b + b 2 + … + b m = O(b m ) Time complexity is O(b m ) Space complexity is O(bm) [or O(m)] [Reminder: Breadth-first requires O(b d ) time and space] 39

40
D EPTH -L IMITED S EARCH Depth-first with depth cutoff k (depth at which nodes are not expanded) Three possible outcomes: Solution Failure (no solution) Cutoff (no solution within cutoff) 40

41
I TERATIVE D EEPENING S EARCH Provides the best of both breadth-first and depth-first search Main idea: 41 IDS For k = 0, 1, 2, … do: Perform depth-first search with depth cutoff k (i.e., only generate nodes with depth k) Totally horrifying !

42
I TERATIVE D EEPENING 42

43
I TERATIVE D EEPENING 43

44
I TERATIVE D EEPENING 44

45
P ERFORMANCE Iterative deepening search is: Complete Optimal if step cost =1 Time complexity is: (d+1)(1) + db + (d-1)b 2 + … + (1) b d = O(b d ) Space complexity is: O(bd) or O(d) 45

46
C ALCULATION db + (d-1)b 2 + … + (1) b d = b d + 2b d-1 + 3b d-2 +… + db = (1 + 2b -1 + 3b -2 + … + db -d ) b d ( i=1,…, ib (1-i) ) b d = b d (b/(b-1)) 2 46

47
N UMBER OF G ENERATED N ODES (B READTH - F IRST & I TERATIVE D EEPENING ) d = 5 and b = 2 47 BFID 11 x 6 = 6 22 x 5 = 10 44 x 4 = 16 88 x 3 = 24 1616 x 2 = 32 3232 x 1 = 32 63120 120/63 ~ 2

48
N UMBER OF G ENERATED N ODES (B READTH - F IRST & I TERATIVE D EEPENING ) d = 5 and b = 10 48 BFID 16 1050 100400 1,0003,000 10,00020,000 100,000 111,111123,456 123,456/111,111 ~ 1.111

49
R ECAP BFS: Complete, optimal O(b d ) time and space DFS: Not complete nor optimal O(bd) space, unbounded time ID: Complete, optimal O(bd) space, O(b d ) time 49

50
R ELATED T OPICS Non-unit costs Revisited states Heuristic search 50

51
N ON - UNIT C OSTS Each arc has cost c > 0 The cost of the path to each node N is g(N) = costs of arcs Breadth-first is no longer optimal 51 Why?

52
U NIFORM -C OST S EARCH Expand node in FRINGE with the cheapest path 52 S 0 1 A 5 B 15 C SG A B C 5 1 10 5 5 G 11 G 10 Suboptimal path!

53
S EARCH A LGORITHM #2 SEARCH#2 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,FRINGE) 3. Repeat: 4. If empty(FRINGE) then return failure 5.N REMOVE(FRINGE) 6.s STATE(N) 7.If GOAL?(s) then return path or goal state 8.For every state s’ in SUCCESSORS(s) 9.Create a new node N’ as a child of N 10.INSERT(N’,FRINGE) 53 The goal test is applied to a node when this node is expanded, not when it is generated.

54
R EVISITED S TATES 54 8-queens No assembly planning Few 123 45 678 8-puzzle and robot navigation Many search tree is finitesearch tree is infinite

55
A VOIDING R EVISITED S TATES Requires comparing state descriptions Breadth-first search: Store all states associated with generated nodes in VISITED If the state of a new node is in VISITED, then discard the node 55

56
A VOIDING R EVISITED S TATES Requires comparing state descriptions Breadth-first search: Store all states associated with generated nodes in VISITED If the state of a new node is in VISITED, then discard the node 56 Implemented as hash-table or as explicit data structure with flags

57
E XPLICIT D ATA S TRUCTURES Robot navigation VISITED: array initialized to 0, matching grid When grid position (x,y) is visited, mark corresponding position in VISITED as 1 Size of the entire state space! 57

58
H ASH T ABLES 58 1 2 34 56 7 8 123 45 678 012N-1 VISITED: Hash table of size N Hash function: map from S to {0,…,N-1} If hash function is chosen carefully to minimize chance of collision, then membership testing on M states averages O(M/N) time

59
A VOIDING R EVISITED S TATES Depth-first search: Solution 1: Store all states associated with nodes in current path in VISITED If the state of a new node is in VISITED, then discard the node ?? 59

60
A VOIDING R EVISITED S TATES Depth-first search: Solution 1: Store all states associated with nodes in current path in VISITED If the state of a new node is in VISITED, then discard the node Only avoids loops Solution 2: Store all generated states in VISITED If the state of a new node is in VISITED, then discard the node Same space complexity as breadth-first ! 60

61
A VOIDING R EVISITED S TATES IN U NIFORM -C OST S EARCH For any state S, when the first node N such that STATE(N) = S is expanded, the path to N is the best path from the initial state to S So: When a node is expanded, store its state into VISITED When a new node N is generated: If STATE(N) is in VISITED, discard N If there exits a node N’ in the fringe such that STATE(N’) = STATE(N), discard the node -- N or N’ -- with the highest- cost path 61

62
S EARCH A LGORITHM #3 SEARCH#3 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,FRINGE) 3. Repeat: 4. If empty(FRINGE) then return failure 5.N REMOVE(FRINGE) 6.s STATE(N) 7.Add s to VISITED 7.If GOAL?(s) then return path or goal state 8.For every state s’ in SUCCESSORS(s) 9.Create a new node N’ as a child of N 10.If s’ is in VISITED then discard N’ 11.If there is N’’ in FRINGE with STATE(N’)=STATE(N’’) 12. If g(N’’) is lower than g(N’) then discard N’ 13.Otherwise discard N’’ 14.INSERT(N’,FRINGE) 62

63
H OMEWORK Readings: R&N Ch. 3.5 63

Similar presentations

Presentation is loading. Please wait....

OK

Turing Machines.

Turing Machines.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Download ppt on strings in c language A ppt on pollution Ppt on statistics in maths Ppt on personality development and communication skills Ppt on regular expression validator Ppt on classical economics adam Ppt on endangered species of wildlife in india Ppt on circles for class 9 download Historical backgrounds for ppt on social media Ppt on e governance in india