0% found this document useful (0 votes)
13 views60 pages

03 - AI - Week2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views60 pages

03 - AI - Week2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

CS 235: Artificial Intelligence

Week 2

Blind (Uninformed) Search

Dr. Moumita Roy


CSE Dept., IIITG

Reference: http://ai.stanford.edu/~latombe/cs121/2011/schedule.htm
Simple Problem-Solving-Agent
Agent Algorithm

1. s0  sense/read initial state


2. GOAL?  select/read goal test
3. Succ  read successor function
4. solution  search(s0, GOAL?, Succ)
5. perform(solution)

2
Search Tree

State graph Search tree

Note that some states may


be visited multiple times
3
Search Nodes and States

8 2
3 4 7
5 1 6

8 2 7
3 4
5 1 6

8 2 8 2 8 4 2 8 2
3 4 7 3 4 7 3 7 3 4 7
5 1 6 5 1 6 5 1 6 5 1 6
4
Search Nodes and States

8 2
3 4 7
5 1 6

8 2 7
If states are allowed to be revisited,
3 4
the search tree may be infinite even
5 1 6 when the state space is finite

8 2 8 2 8 4 2 8 2
3 4 7 3 4 7 3 7 3 4 7
5 1 6 5 1 6 5 1 6 5 1 6
5
Data Structure of a Node
8 2
STATE
3 4 7 PARENT-NODE

5 1 6
BOOKKEEPING
CHILDREN
Action Right
Depth 5
... Path-Cost 5
yes
Expanded

Depth of a node N
= length of path from root to N
(depth of the root = 0) 6
Node expansion 8 2
The expansion of a node N of the 3 4 7
search tree consists of: 5 1 6
1) Evaluating the successor
function on STATE(N) N
2) Generating a child of N for
each state returned by the
function
node generation  node expansion

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

8 2 7
3 4
5 1 6

8 2 8 2 8 4 2 8 2
3 4 7 3 4 7 3 7 3 4 7
5 1 6 5 1 6 5 1 6 5 1 6 8
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)
• REMOVE(FRINGE)
 The ordering of the nodes in FRINGE
defines the search strategy
9
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) Expansion of N
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)
10
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
11
Blind vs. Heuristic Strategies

 Blind (or un-informed) strategies do not


exploit state descriptions to order
FRINGE. They only exploit the positions
of the nodes in the search tree

 Heuristic (or informed) strategies


exploit state descriptions to order
FRINGE (the most “promising” nodes
are placed at the beginning of FRINGE)
12
Example
For a blind strategy, N1 and N2
are just two nodes (at some
8 2
position in the search tree)
STATE
3 4 7
N1
5 1 6

1 2 3
1 2 3 4 5 6
STATE
4 5 7 8
N2
7 8 6 Goal state

13
Example
For a heuristic strategy counting
the number of misplaced tiles,
8 2
N2 is more promising than N1
STATE
3 4 7
N1
5 1 6

1 2 3
1 2 3 4 5 6
STATE
4 5 7 8
N2
7 8 6 Goal state

14
Blind Strategies
 Breadth-first
• Bidirectional

 Depth-first Arc cost = 1


• Depth-limited
• Iterative deepening

 Uniform-Cost Arc cost


(variant of breadth-first) = c(action)    0
15
Breadth-First Strategy
New nodes are inserted at the end of FRINGE

2 3 FRINGE = (1)

4 5 6 7

16
Breadth-First Strategy
New nodes are inserted at the end of FRINGE

2 3 FRINGE = (2, 3)

4 5 6 7

17
Breadth-First Strategy
New nodes are inserted at the end of FRINGE

2 3 FRINGE = (3, 4, 5)

4 5 6 7

18
Breadth-First Strategy
New nodes are inserted at the end of FRINGE

2 3 FRINGE = (4, 5, 6, 7)

4 5 6 7

19
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

20
Evaluation

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

21
Evaluation

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

22
Evaluation

 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 + b2 + … + bd = ???

23
Evaluation
 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 + b2 + … + bd = (bd+1-1)/(b-1) = O(bd)
  Time and space complexity is O(bd)
 When we can apply goal test? Node
generation/Node expansion?
24
Evaluation
 If goal test is applied during node
expansion (rather than node generation)

 In this case, the whole layer at depth d


may be expanded before the goal was
detected

 Time complexity: O(bd+1)

25
Time and Memory Requirements

d # Nodes Time Memory


2 111 .01 msec 11 Kbytes
4 11,111 1 msec 1 Mbyte
6 ~106 1 sec 100 Mb
8 ~108 100 sec 10 Gbytes
10 ~1010 2.8 hours 1 Tbyte
12 ~1012 11.6 days 100 Tbytes
14 ~1014 3.2 years 10,000 Tbytes
Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node
26
Time and Memory Requirements

d # Nodes Time Memory


2 111 .01 msec 11 Kbytes
4 11,111 1 msec 1 Mbyte
6 ~106 1 sec 100 Mb
8 ~108 100 sec 10 Gbytes
10 ~1010 2.8 hours 1 Tbyte
12 ~1012 11.6 days 100 Tbytes
14 ~1014 3.2 years 10,000 Tbytes
Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node
27
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)

1 2 3 4 1 2 3 4

5 6 7 8 ? 5 6 7 8

9 10 11 12 9 10 11 12

13 14 15 13 15 14
28
Bidirectional Strategy
2 fringe queues: FRINGE1 and FRINGE2

Time and space complexity is O(bd/2)  O(bd)


if both trees have the same branching factor b
Question: How we can search backward?
reverse action is not possible always.
29
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3
FRINGE = (1)
4 5

30
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3
FRINGE = (2, 3)
4 5

31
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3
FRINGE = (4, 5, 3)
4 5

32
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

33
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

34
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

35
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

36
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

37
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

38
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

39
Depth-First Strategy
New nodes are inserted at the front of FRINGE
1

2 3

4 5

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

41
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 + b2 + … + bm = O(bm)
 Time complexity is O(bm)
 Space complexity is O(bm) [or O(m)]
[Reminder: Breadth-first requires O(bd) time and space]
42
Evaluation
• Space complexity: it needs to store a
single path along with the remaining
unexpanded sibling nodes for each node
on the path

• DFS requires a storage for only O(bm)


nodes

• Can we further reduced it to O(m)?


43
Evaluation
• A variant of DFS: backtracking search

• One successor is generated at a time rather


than all successors
• Each partially expanded node remembers
which successor to generate next.
• Here, only O(m) memory is needed.
• We must able to go back to undo each
modification when we go back to generate the
next successor
44
Depth-Limited Search
 Depth-first with depth cutoff k (depth
at which nodes are not expanded)

 Failure of DFS in infinite state space


can be avoided by fixing a
predetermined depth limit k

 Three possible outcomes:


• Solution
• Failure (no solution)
• Cutoff (no solution within cutoff) 45
Evaluation
• Time complexity: O(bk) and space
complexity: O(bk)

• Introduce incompleteness if k<d and the


shallowest goal node is not within depth
limit

• Non optimal if we choose k>d


46
Iterative Deepening Search
Provides the best of both breadth-first
and depth-first search

IDS
For k = 0, 1, 2, … do:
Perform depth-first search with
depth cutoff k
(i.e., only generate nodes with depth  k)
47
Iterative Deepening

48
Iterative Deepening

49
Iterative Deepening

50
Performance

 Iterative deepening search is:


• Complete
• Optimal if step cost =1
 Time complexity is:
(d+1)(1) + db + (d-1)b2 + … + (1) bd = O(bd)
 Space complexity is: O(bd) or O(d)

51
Number of Generated Nodes
(Breadth-First & Iterative Deepening)
d = 5 and b = 2
BF ID
1 1x6=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
63 120 120/63 ~ 2
53
Number of Generated Nodes
(Breadth-First & Iterative Deepening)
d = 5 and b = 10
BF ID
1 6
10 50
100 400
1,000 3,000
10,000 20,000
100,000 100,000
111,111 123,456 123,456/111,111 ~ 1.111
54
Comparison of Strategies
• Infinite state space: number of states is potentially high.
Branching factor (no of actions) may also be infinite (but
not common) (the search tree --infinite/finite??).
• Finite state space may also lead to the infinite search
tree.
• BFS is complete and optimal (same arc cost) for both the
cases (if there is a shallowest goal node at depth d, it will
eventually find it after expanding all the nodes at the
depth shallower than d)
• DFS is likely to stuck into a wrong path. It is not
complete and optimal even if the state space is infinite
but the shallowest goal sate is in a depth which is much
lower than infinity.
• DFS is complete only if the search tree is finite. 55
Comparison of Strategies
 Breadth-first is complete and optimal,
but has high space complexity
 Depth-first is space efficient, but is
neither complete, nor optimal
 Iterative deepening is complete and
optimal, with the same space complexity
as depth-first and almost the same time
complexity as breadth-first

56
Outline of Search Algorithm(Ver-2)
1. Initialize: Set OPEN/FRINGE = {s0 }
2. Fail: If OPEN = { }, Terminate with Fail
3. Select: Select a state/node, n, from OPEN
4. Terminate: If n ∈ G, terminate with success
5. Expand: Generate the successors of n using
successor function and insert them in OPEN
6. Loop: Go To Step 2.

57
Revisited States
No Few Many

1 2 3
search tree is finite search tree is infinite
4 5
7 8 6

8-queens assembly 8-puzzle and robot navigation


planning
58
Outline of Search Algorithm(Ver-3)
1. Initialize: Set OPEN = {s0}, CLOSED = { }
2. Fail: If OPEN = { }, Terminate with failure
3. Select: Select a state, n, from OPEN
and save n in CLOSED
4. Terminate: If n ∈ G, terminate with success
5. Expand: Generate the successors of n using
successor function
For each successor, m, insert m in OPEN
only if m ∉[OPEN ∪ CLOSED]
6. Loop: Go To Step 2
59
Uniform-Cost Search (UCS)
• BFS can generate the shallowest goal node.
• However, the shallowest goal node is not necessarily
the optimal one.
• BFS is optimal when all actions have the same cost
(commonly).
• Problem: BFS always expands the shallowest
unexpanded node .
• We need a search strategy which is optimal from any
cost.
• Instead of expanding the shallowest goal node, UCS
expands a node n with lowest path cost g(n)
64
Uniform-Cost Search
 Each arc has some cost c   > 0
 The cost of the path to each node n is
g(n) =  costs of arcs
w(n,m)= arc cost between node n and m
 The goal is to generate a solution path of minimal cost
 The nodes n in the queue FRINGE are sorted in
increasing g(n) S
0
A

1 10 A B C
S 1 5 15
5 B 5 G

5 G G
15 C 11 10
65

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy