Title: Solving problems by searching
1Solving problems by searching
- Chapter 3, part 2
- Modified by Vali Derhami
2Implementation general tree search
- ?????? ??? ?? ?????? ??? ???? ????? ?? ????
???????? ?????. - ????? ????? ?? ??? ???? ??? ???????.
- ??? ??? ??????? ? ??? ?? ??
3Implementation general tree search
- The operations on a queue are as follows
- MAKE-QUEUE(elemen,...) creates a queue with the
given element(s). - EMPTY?(queue) returns true only if there are no
more elements in the queue. - FlRST(queue) returns the first element of the
queue. - REMOVE-FiRST (queue) returns First(queue) and
removes it from the queue. - lNSERT(element, queue) inserts an element into
the queue and returns the resulting queue. (We
will see that different types of queues insert
elements in different orders.) - Insert- ALL(elements, queue) inserts a set of
elements into the queue and returns the resulting
queue.
4Implementation general tree search
5Search strategies
- A search strategy is defined by picking the order
of node expansion - Strategies are evaluated along the following
dimensions - completeness does it always find a solution if
one exists? - time complexity How long does it take to find
solution (number of nodes generated) - space complexity How much memory is needed to
perform the search? maximum number of nodes in
memory - optimality does it always find a optimal
solution?
- Time and space complexity are measured in terms
of - b maximum branching factor of the search tree
- ?????? ????? ???? ??? ?? ????
- d depth of the least-cost solution
- ?? ???? ??? ???.
- m maximum depth of the state space (may be 8)
- ?????? ???? ???? ?? ???? ????
6Uninformed search strategies
- Uninformed search strategies use only the
information available in the problem definition
Breadth-first search Uniform-cost search Depth-fir
st search Depth-limited search Iterative deepening
search
7Breadth-first search?????? ??? ???
- Expand shallowest unexpanded node
- ????? ???? ???? ???? ??? ??? ????? ??????
- Implementation
- fringe is a FIFO queue, i.e., new successors go
at end
8Breadth-first search?????? ??? ???
- Expand shallowest unexpanded node
- ????? ???? ???? ???? ??? ??? ????? ??????
- Implementation
- fringe is a FIFO queue, i.e., new successors go
at end
9Breadth-first search?????? ??? ???
- Expand shallowest unexpanded node
- ????? ???? ???? ???? ??? ??? ????? ??????
- Implementation
- fringe is a FIFO queue, i.e., new successors go
at end
10Breadth-first search?????? ??? ???
- Expand shallowest unexpanded node
- ????? ???? ???? ???? ??? ??? ????? ??????
- Implementation
- fringe is a FIFO queue, i.e., new successors go
at end
11Properties of breadth-first search
- Complete? Yes (if b is finite)
- Time?
- ????? ??? ??? ????? ???bb2b3 bd b(bd-1)
O(bd1)
- Space? O(bd1) (keeps every node in memory)
Optimal? Yes (if cost 1 per step)
- Space is the bigger problem (more than time)
????? ?? ?????? ??????? ????? ?? ?? ???? ?????
??? ???? ???? ?????? ????????? ???? ?? ??????
12(No Transcript)
13Uniform-cost search?????? ????? ???????
- Expand least-cost unexpanded nodeImplementation
- fringe queue ordered by path cost
- Equivalent to breadth-first if step costs all
equal Complete? Yes, if step cost e Time? of n
odes with g cost of optimal solution,
O(b1(C/ e)) where C is the cost of the
optimal solution - O(b1(C/ e)) can be much greater than O(bd)
- Space? of nodes with g cost of optimal
solution, - O(b (C/ e))Optimal? Yes if step cost e
14Depth-first search?????? ??? ???
- Expand deepest unexpanded node ????? ???? ???? ???
????? ?????? - Implementation
- fringe LIFO queue, i.e., put successors at
front
15Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
16Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
17Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
18Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
19Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
??? ?? ??? ???? ??????? ??? ?? ???.
20Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
21Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
22Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
23Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
24Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
25Depth-first search
- Expand deepest unexpanded nodeImplementation
- fringe LIFO queue, i.e., put successors at
front
26Properties of depth-first search
- Complete? No fails in infinite-depth spaces,
spaces with loops - Modify to avoid repeated states along path
- ? complete in finite spaces
- Time? O(bm) terrible if m is much larger than d
- m?????? ??? ?? ???
- but if solutions are dense, may be much faster
than breadth-first - Space? bm1, O(bm), i.e., linear space!
Optimal? No
27Depth-first search
- Back tracking search A type of Depth- firt
search - Back Traking only one successor is generated at
a time rather than all successors - Space O(m)
28Depth-limited search
- depth-first search with depth limit l,i.e.,
nodes at depth l - ??? dgtl ????? ???? ???? ??? ??? m ????? ????
- ??? dltl ?????? ??? ??? ????? ???.
- Time? O(b l ),
- Space? bl1, O(bl),
- L8 gt Depth firth
29Depth-limited search
30Iterative deepening search?????? ???? ?????
??????
?????? ??? ??? ?? ?????? ??????? ??? ?? ?? ??????
?????? ??????? ?? ????? ?? ?? ??? ??? ??? ????.
?????? ?? ?? ??? ??? ??? ? ?????? ??? ???.
31Iterative deepening search l 0
32Iterative deepening search l 1
33Iterative deepening search l 2
34Iterative deepening search l 3
35Iterative deepening search
- Number of nodes generated in a depth-limited
search to depth d with branching factor b - NDLS b1 b2 bd-2 bd-1 bd
- Number of nodes generated in an iterative
deepening search to depth d with branching factor
b - NIDS d b1 (d-1)b2 3bd-2 2bd-1 1bd
- For b 10, d 5,
- NIDS 50 400 3,000 20,000 100,000
123,450 - NBFS 10 100 1,000 10,000 100,000
999,990 1,111,100. - Overhead (123,456 - 111,111)/111,111 11
36Properties of iterative deepening search
- Complete? Yes
- Time? d b1 (d-1)b2 bd O(bd)
- Space? O(bd)
- Optimal? Yes, if step cost 1
37Bidirectional search?????? ?? ????
- ????? ?????? ?????? ??? ?? ???? ????? ?? ??? ???
? ????? ?? ??? ?? ??? ??? - ???? ???? ?? ?? ????? ?? ?? ?? ????.
- Time O(bd/2) O(bd/2) O(bd/2) ltlt O(bd)
- Space O(bd/2)
- ??????? ??? ?? ??? ???? ?? ??? ???.
- Complete and optimal (for uniform step costs) if
both searches are breadth-first other
combinations may sacrifice completeness,
optimality, or both.
38Summary of algorithms
39Repeated states
- Failure to detect repeated states can turn a
linear problem into an exponential one!
40Graph search
41????? ?????
- 1- ????? ?? ?????
- ?? ???? ??? ???? ? ????? ???? ???? Deterministic,
fully observable - ???? ??????? ???? (Global information)?? ???? ?
??? ?????? ??? ?? ?? ????. - 2- ????? ???? ?? ?? (?????) (??? ????? ?? ??????
?? ???.) - ?? ??????? ????
- ???? ????? ???? ??? ?? ??????? ??? ??? ?????? ???
?? ?? ????. - 3- ????? ??????? Contingency
- ???? ???? ???? ???? ? ?? ??? ????
- ???? ??? ?????? ??? ?? ??? ????.
- ??? ??????? ???? ?? ????? ???? ???? ????? ??
?????? (Adversarial) ?????. - 4- ????? ??????? exploration Problem
- ?????? ? ??????? ????????
42Example vacuum world
- Single-state, start in 5. Solution?
43Example vacuum world
- Single-state, start in 5. Solution? Right,
Suck
- Sensorless, start in 1,2,3,4,5,6,7,8 e.g.,
Right goes to 2,4,6,8 Solution?
44Example vacuum world
- Sensorless, start in 1,2,3,4,5,6,7,8 e.g.,
Right goes to 2,4,6,8 Solution?
Right,Suck,Left,Suck - Contingency
- Nondeterministic Suck may dirty a clean carpet
- Partially observable location, dirt at current
location. - Percept L, Clean, i.e., start in 5 or
7Solution?
45Example vacuum world
- Sensorless, start in 1,2,3,4,5,6,7,8 e.g.,
Right goes to 2,4,6,8 Solution?
Right,Suck,Left,Suck - Contingency
- Nondeterministic Suck may dirty a clean carpet
- Partially observable location, dirt at current
location. - Percept L, Clean, i.e., start in 5 or
7Solution? Right, if dirt then Suck