Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser

Similar presentations


Presentation on theme: "1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser"— Presentation transcript:

1 1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser http://cs.indiana.edu/~hauserk

2 2 Recap  Agent Frameworks  Problem Solving with Search

3 3 Agenda   Search problems   Searching, data structures, and algorithms   Breadth-first search   Depth-first search   Uniform-cost search

4 4 Search problems

5 5 Defining a Search Problem  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

6 6 State Graph  Each state is represented by a distinct node  An arc (or edge) connects a node s to a node s’ if s’  SUCC (s)  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

7 7 8-Queens Problem  State repr. 1 Any placement of 0-8 queensAny placement of 0-8 queens  State repr. 2 Any non- conflicting placement of 0-8 queensAny non- conflicting placement of 0-8 queens

8 8 Representation 1  State: any placement of 0-8 queens  Initial state: 0 queens  Successor function: Place queen in empty squarePlace queen in empty square  Goal test: Non-conflicting placement of 8 queensNon-conflicting placement of 8 queens  # of states ~ 64x63x…x57 ~ 3x10 14

9 9 Representation 2  State: any placement of non-conflicting 0-8 queens in columns starting from left  Initial state: 0 queens  Successor function: A queen placed in leftmost empty column such that it causes no conflictsA queen placed in leftmost empty column such that it causes no conflicts  Goal test: Any state with 8 queensAny state with 8 queens  # of states = 2057

10 10 Path Planning What is the state space ?

11 11 Formulation #1 Cost of one horizontal/vertical step = 1 Cost of one diagonal step =  2

12 12 Optimal Solution This path is the shortest in the discretized state space, but not in the original continuous space

13 13 Formulation #2 Cost of one step: length of segment

14 14 Formulation #2 Cost of one step: length of segment Visibility graph

15 15 Solution Path The shortest path in this state space is also the shortest in the original continuous space

16 16 Example: 8-Puzzle 1 2 34 56 7 8123 456 78 Initial stateGoal state State: Any arrangement of 8 numbered tiles and an empty tile on a 3x3 board

17 17 15-Puzzle Introduced (?) in 1878 by Sam Loyd, who dubbed himself “America’s greatest puzzle-expert”

18 18 15-Puzzle Sam Loyd offered $1,000 of his own money to the first person who would solve the following problem: 12 14 11 15 10 13 9 5678 4321 12 15 11 14 10 13 9 5678 4321 ?

19 19 But no one ever won the prize !!

20 20 How big is the state space of the (n 2 -1)-puzzle?  8-puzzle  ?? states

21 21 How big is the state space of the (n 2 -1)-puzzle?  8-puzzle  9! = 362,880 states  15-puzzle  16! ~ 2.09 x 10 13 states  24-puzzle  25! ~ 10 25 states But only half of these states are reachable from any given state (but you may not know that in advance)

22 22  Wlg, let the goal be:  A tile j appears after a tile i if either j appears on the same row as i to the right of i, or on another row below the row of i.  For every i = 1, 2,..., 15, let n i be the number of tiles j < i that appear after tile i (permutation inversions)  N = n 2 + n 3 +  + n 15 + row number of empty tile Permutation Inversions 12 15 11 14 10 13 9 5678 4321 12 15 11 14 6 13 9 51078 4321 n 2 = 0n 3 = 0n 4 = 0 n 5 = 0n 6 = 0n 7 = 1 n 8 = 1n 9 = 1n 10 = 4 n 11 = 0n 12 = 0n 13 = 0 n 14 = 0n 15 = 0  N = 7 + 4

23 23  Proposition: (N mod 2) is invariant under any legal move of the empty tile  Proof: Any horizontal move of the empty tile leaves N unchangedAny horizontal move of the empty tile leaves N unchanged A vertical move of the empty tile changes N by an even increment (  1  1  1  1)A vertical move of the empty tile changes N by an even increment (  1  1  1  1) 1215 11 14 10 13 9 567 8 4321 s = 1215 11 14 10 13 9 567 8 4321 s’ = N(s’) = N(s) + 3 + 1

24 24  Proposition: (N mod 2) is invariant under any legal move of the empty tile   For a goal state g to be reachable from a state s, a necessary condition is that N(g) and N(s) have the same parity  It can be shown that this is also a sufficient condition   The state graph consists of two connected components of equal size

25 25 Searching the State Space  It is often not feasible (or too expensive) to build a complete representation of the state graph

26 26 8-puzzle  362,880 states 15-puzzle  2.09 x 10 13 states 24-puzzle  10 25 states 100 millions states/sec 0.036 sec ~ 55 hours > 10 9 years 8-, 15-, 24-Puzzles

27 27 Searching

28 28 Searching the State Space  Often it is not feasible (or too expensive) to build a complete representation of the state graph  A problem solver must construct a solution by exploring a small portion of the graph

29 29 Searching the State Space Search tree

30 30 Searching the State Space Search tree

31 31 Searching the State Space Search tree

32 32 Searching the State Space Search tree

33 33 Searching the State Space Search tree

34 34 Searching the State Space Search tree

35 35 Search Nodes and States 1 2 34 56 7 8 1 2 34 56 7 8 1 2 34 56 78 1 3 56 8 1 3 4 56 7 8 2 47 2 1 2 34 56 7 8 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

36 36 Data Structure of a Node PARENT-NODE 1 2 34 56 7 8 STATE Depth of a node N = length of path from root to N (depth of the root = 0) BOOKKEEPING5Path-Cost 5Depth RightAction Expanded yes... CHILDREN

37 37 Node expansion The expansion of a node N of the search tree consists of: 1)Evaluating the successor function on STATE (N) 2)Generating a child of N for each state returned by the function node generation  node expansion 1 2 34 56 7 8 N 1 3 56 8 1 3 4 56 7 8 2 47 2 1 2 34 56 7 8

38 38 Fringe of Search Tree  The fringe is the set of all search nodes that haven’t been expanded yet 1 2 3 4 56 7 8 1 2 34 56 7 8 1 2 34 56 78 1 3 56 8 1 3 4 5 6 7 8 2 47 2 1 2 34 5 6 7 8

39 39 Is it identical to the set of leaves?

40 40 Search Strategy  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)INSERT(node,FRINGE) REMOVE(FRINGE)REMOVE(FRINGE)  The ordering of the nodes in FRINGE defines the search strategy

41 41 Search Algorithm #1 SEARCH#1 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,FRINGE) 3. Repeat: a.If empty(FRINGE) then return failure b.N  REMOVE(FRINGE) c.s  STATE(N) d.For every state s’ in SUCCESSORS(s) i. Create a new node N’ as a child of N ii. If GOAL?(s’) then return path or goal state iii. INSERT(N’,FRINGE) Expansion of N

42 42 Performance Measures  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

43 43 Blind Search Strategies

44 44 Blind Strategies  Breadth-first BidirectionalBidirectional  Depth-first Depth-limitedDepth-limited Iterative deepeningIterative deepening  Uniform-Cost (variant of breadth-first) Arc cost = 1 Arc cost = c(action)    0

45 45 Breadth-First Strategy New nodes are inserted at the end of FRINGE New nodes are inserted at the end of FRINGE 23 45 1 67 FRINGE = (1)

46 46 Breadth-First Strategy New nodes are inserted at the end of FRINGE New nodes are inserted at the end of FRINGE FRINGE = (2, 3) 23 45 1 67

47 47 Breadth-First Strategy New nodes are inserted at the end of FRINGE New nodes are inserted at the end of FRINGE FRINGE = (3, 4, 5) 23 45 1 67

48 48 Breadth-First Strategy New nodes are inserted at the end of FRINGE New nodes are inserted at the end of FRINGE FRINGE = (4, 5, 6, 7) 23 45 1 67

49 49 Important Parameters 1) Maximum number of successors of any state  branching factor b of the search tree 2) Minimal length (≠ cost) of a path between the initial and a goal state  depth d of the shallowest goal node in the search tree

50 50 Evaluation  b: branching factor  d: depth of shallowest goal node  Breadth-first search is: Complete? Not complete?Complete? Not complete? Optimal? Not optimal?Optimal? Not optimal?

51 51 Evaluation  b: branching factor  d: depth of shallowest goal node  Breadth-first search is: CompleteComplete Optimal if step cost is 1Optimal if step cost is 1  Number of nodes generated: ???

52 52 Evaluation  b: branching factor  d: depth of shallowest goal node  Breadth-first search is: CompleteComplete Optimal if step cost is 1Optimal if step cost is 1  Number of nodes generated: 1 + b + b 2 + … + b d = ???

53 53 Evaluation  b: branching factor  d: depth of shallowest goal node  Breadth-first search is: CompleteComplete Optimal if step cost is 1Optimal 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 )

54 54 Time and Memory Requirements d # Nodes TimeMemory 2111.01 msec 11 Kbytes 411,111 1 msec 1 Mbyte 6 ~10 6 1 sec 100 Mb 8 ~10 8 100 sec 10 Gbytes 10 ~10 10 2.8 hours 1 Tbyte 12 ~10 12 11.6 days 100 Tbytes 14 ~10 14 3.2 years 10,000 Tbytes Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

55 55 Time and Memory Requirements d # Nodes TimeMemory 2111.01 msec 11 Kbytes 411,111 1 msec 1 Mbyte 6 ~10 6 1 sec 100 Mb 8 ~10 8 100 sec 10 Gbytes 10 ~10 10 2.8 hours 1 Tbyte 12 ~10 12 11.6 days 100 Tbytes 14 ~10 14 3.2 years 10,000 Tbytes Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

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

57 57 Bidirectional Strategy 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?

58 58 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45 FRINGE = (1)

59 59 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45 FRINGE = (2, 3)

60 60 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45 FRINGE = (4, 5, 3)

61 61 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

62 62 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

63 63 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

64 64 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

65 65 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

66 66 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

67 67 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

68 68 Depth-First Strategy New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE 1 23 45

69 69 Evaluation  b: branching factor  d: depth of shallowest goal node  m: maximal depth of a leaf node  Depth-first search is:  Complete?  Optimal?

70 70 Evaluation  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]

71 71 Depth-Limited Search  Depth-first with depth cutoff k (depth at which nodes are not expanded)  Three possible outcomes: SolutionSolution Failure (no solution)Failure (no solution) Cutoff (no solution within cutoff)Cutoff (no solution within cutoff)

72 72 Iterative Deepening Search Provides the best of both breadth-first and depth-first search Provides the best of both breadth-first and depth-first search Main idea: 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 !

73 73 Iterative Deepening

74 74 Iterative Deepening

75 75 Iterative Deepening

76 76 Performance  Iterative deepening search is: CompleteComplete Optimal if step cost =1Optimal 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)

77 77 Calculation 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

78 78 d = 5 and b = 2 BFID 1 1 x 6 = 6 2 2 x 5 = 10 4 4 x 4 = 16 8 8 x 3 = 24 16 16 x 2 = 32 32 32 x 1 = 32 63120 120/63 ~ 2 Number of Generated Nodes (Breadth-First & Iterative Deepening)

79 79 Number of Generated Nodes (Breadth-First & Iterative Deepening) d = 5 and b = 10 BFID 16 1050 100400 1,0003,000 10,00020,000 100,000100,000 111,111123,456 123,456/111,111 ~ 1.111

80 80 Recap  BFS: Complete, optimal O(b d ) time and spaceO(b d ) time and space  DFS: Not complete nor optimal O(bd) space, unbounded timeO(bd) space, unbounded time  ID: Complete, optimal O(bd) space, O(b d ) timeO(bd) space, O(b d ) time

81 81 Homework  Readings: R&N Ch. 3.4-3.5  HW1 due on 9/22


Download ppt "1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser"

Similar presentations


Ads by Google