0% found this document useful (0 votes)
348 views38 pages

Uninformed Search Strategies-20211124125231

Depth-first search explores as far as possible along each branch before backtracking. It recursively explores successors until it reaches a goal or a dead end, then backtracks and tries another branch. 21 Uninformed Search Strategies 4. Depth-Limited Search Algorithm - Similar to depth-first search but with a depth limit d - Recursively explore successors up to depth d before backtracking - If goal found within depth limit, return solution - If all nodes at depth d explored with no goal, return failure Properties: - Completeness only up to depth d - Time complexity: O(bd) where b is branching factor - Space complexity: O(bd) to store

Uploaded by

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

Uninformed Search Strategies-20211124125231

Depth-first search explores as far as possible along each branch before backtracking. It recursively explores successors until it reaches a goal or a dead end, then backtracks and tries another branch. 21 Uninformed Search Strategies 4. Depth-Limited Search Algorithm - Similar to depth-first search but with a depth limit d - Recursively explore successors up to depth d before backtracking - If goal found within depth limit, return solution - If all nodes at depth d explored with no goal, return failure Properties: - Completeness only up to depth d - Time complexity: O(bd) where b is branching factor - Space complexity: O(bd) to store

Uploaded by

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

Course : COMP6227-Artificial Intelligence

Effective Period : September 2016

Uninformed Search
Strategies

Session 02

1
Learning Outcomes

At the end of this session, students will be able to:


• LO 2 : Describe what is AI and identify concept of intelligent
agent
• LO 3 : Explain various intelligent search algorithms to solve
the problems

2
Outline

1. Problems Example
2. Searching Algorithms for Solutions
3. Uninformed Search Strategies
4. Summary

3
Problem Example 1

9l
5l
3l

Problem:
Using these three buckets, how to measure 7 liters of water

4
Problem Example 1
• Which Solution do you prefer?
• Solution 1: • Solution 2:
__a b c___ a b c
0 00 start 0 0 0 start
3 00
0 5 0
0 03
3 2 0
3 03
3 0 2
0 06
3 06 3 5 2
0 36 3 0 7 goal
3 36
1 56
0 57
goal
5
Problem Example 2
• Farmer, Goat, Tiger and Vegetables
• A farmer is going to take a goat, a tiger, and vegetables
across a river using raft. The raft can only take farmer, and
one passenger.
If the farmer is being left by, goat will be eaten by tiger, and
vegetables will be eaten by goat.

Make a state space representation so that all of those 4


objects can be saved to arrive at the river side completely.

6
Problem Example 3
• Traveling from Arad to Bucharest
• Find solution:
sequence of cities, such that total driving distance is minimized

7
Problem Example 4
• 8-Puzzle

• State : integer location of tiles


(ignore intermediate locations)
• Operators : moving blank left, right, up, down
(ignore jamming)
• Goal test : does state match to goal state?
• Path cost : 1 per move
8
Searching Algorithms
for Solution
• Solution: is a sequence of operators that bring you from
current state to the goal state
• Basic idea: offline, systematic exploration of simulated state-
space by generating successors of explored states
(expanding)
• Strategy: The search strategy is determined by the order in
which the nodes are expanded.
Function General-Search(problem, strategy) returns a solution, or failure
initialize the search tree using the initial state problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add resulting nodes to the search tree
end
9
Searching Algorithms
for Solution
• Implementation of search algorithms
Function General-Search(problem, Queuing-Fn) returns a solution, or failure
nodes  make-queue(make-node(initial-state[problem]))
loop do
if nodes is empty then return failure
node  Remove-Front(nodes)
if Goal-Test[problem] applied to State(node) succeeds then return
node
nodes  Queuing-Fn(nodes, Expand(node, Operators[problem]))
end

• Queuing-Fn(queue, elements) is a queuing function that


inserts a set of elements into the queue and determines the
order of node expansion. Varieties of the queuing function
produce varieties of the search algorithm.
10
Uninformed Search
Strategies

• Use only information available in the problem


formulation
1. Breadth-First Search
2. Uniform-Cost
3. Depth-First Search
4. Depth-Limited Search
5. Iterative Deepening

11
Uninformed Search
Strategies
1. Breadth-First Search Algorithm
1. Set Node-List to the initial state
2. Until a goal is found or Node-List is empty, do :
a. Remove the first element of Node-List and call it
E. If Node-List was empty, quit
b. For each rule match against E, do :
• Apply the rule to generate a new state
• If the new state is a goal, quit and return it
• Else, add the new state to the end of Node-List

12
Uninformed Search
Strategies
• Breadth-First Search Algorithm Illustration
S

A D

B D A E

C E E B B F

D F B F C E A C G

G C G F
G
Move downwards, level by level, until goal is reached. 13
Uninformed Search
Strategies
• Example of Breadth-First Search Tree

14
Uninformed Search
Strategies
• Time Complexity of Breadth-First Search
• If a goal node is found on depth d of the tree, all nodes up till
that depth are created.

d
m
b G

• Thus: O(bd)
15
Uninformed Search
Strategies
• Space Complexity of Breadth-First Search
• Largest number of nodes in QUEUE is reached on the level d
of the goal node.

d
b G
m

• QUEUE contains all and G nodes. (Thus: 4) .


• In General: bd
16
Uninformed Search
Strategies
2. Uniform-cost Search Algorithm
• If all the edges in the search graph do not have the same
cost then breadth-first search generalizes to uniform-cost
search. Instead of expanding nodes in order of their depth
from the root, uniform-cost search expands nodes in order
of their cost from the root. At each step, the next step n to
be expanded is one whose cost g(n) is lowest where g(n) is
the sum of the edge costs from the root to node n. The
nodes are stored in a priority queue.
• Whenever a node is chosen for expansion by uniform cost
search, a lowest-cost path to that node has been found.

17
Uninformed Search
Strategies
• 2. Uniform-cost Search Algorithm
procedure UniformCostSearch(Graph, root, goal)
node := root, cost = 0
frontier := priority queue containing node only
explored := empty set
do
if frontier is empty
return failure
node := frontier.pop()
if node is goal
return solution
explored.add(node)
for each of node's neighbors n
if n is not in explored
if n is not in frontier
frontier.add(n)
else if n is in frontier with higher cost
replace existing node with n 18
Uninformed Search
Strategies
Properties of Uniform-cost Search
• Completeness : Yes, if step cost   >0
• Time complexity : # nodes with g  cost of optimal
solution,  O(b d)
• Space complexity : # nodes with g  cost of optimal
solution,  O(b d)
• Optimality : Yes, as long as path cost never decreases

g(n) is the path cost to node n


Remember:
b = branching factor
d = depth of least-cost solution

19
Uninformed Search
Strategies
Implementation of Uniform-cost Search
• Initialize Queue with root node (built from start state)
• Repeat until (Queue empty) or (first node has Goal state):
– Remove first node from front of Queue
– Expand node (find its children)
– Reject those children that have already been
considered, to avoid loops
– Add remaining children to Queue, in a way that keeps
entire queue sorted by increasing path cost
• If Goal was reached, return success, otherwise failure

20
Uninformed Search
Strategies
3. Depth-First Search Algorithm
1. If the initial state is a goal state, quit and return
success
2. Otherwise, do the following until success or failure is
signaled :
a. Generate a successors, E, of the initial state. If
there are no more successors, signal failure
b. Call Depth-First Search with E as the initial state
c. If success is returned, signal success. Otherwise
continue in this loop

21
Uninformed Search
Strategies
3. Depth-First Search Algorithm

C E

D F
G
22
Uninformed Search
Strategies
Properties of Depth-First Search Algorithm
• Completeness : No, fails in infinite state-space
(yes if finite state space)
• Time complexity : O (b m)
• Space complexity : O (bm)
• Optimality : No

Remember:
b = branching factor
m = max depth of search tree

23
Uninformed Search
Strategies
Time Complexity of Depth-First: details
• In the worst case:
• The (only) goal node may be on the right-most branch,

b m

b-1
24
Uninformed Search
Strategies
Space Complexity of Depth-First
• Largest number of nodes in QUEUE is reached in bottom left-most
node.
• Example: m = 3, b = 3 :

...
• QUEUE contains all nodes. Thus: 7.
• In General: ((b-1) * m) + 1
• Order: O(m*b) 25
Uninformed Search
Strategies
4. Depth Limited Search (DLS)
• Depth-limited search algorithm is to explore the vertices of a
graph. It is a modification of depth-first search and is used for
example in the iterative deepening depth-first search algorithm.
• Depth-limited search is works exactly like depth-first search, but
avoids its drawbacks regarding completeness by imposing a
maximum limit on the depth of the search. Even if the search
could still expand a vertex beyond that depth, it will not do so
and thereby it will not follow infinitely deep paths or get stuck in
cycles.
• Depth-limited search will find a solution if it is within the depth
limit, which guarantees at least completeness on all graphs.

26
Uninformed Search
Strategies
DLS Algorithm (Informal)
1. Determine the vertex where the search should start and
assign the maximum search depth
2. Check if the current vertex is the goal state
– If not: Do nothing
– If yes: return
3. Check if the current vertex is within the maximum search
depth
– If not: Do nothing
– If yes:
• Expand the vertex and save all of its successors in a stack
• Call DLS recursively for all vertices of the stack and go
back to Step 2
27
Uninformed Search
Strategies
Pseudocode of DLS
DLS(node, goal, depth) {
if ( depth >= 0 ) {
if ( node == goal )
return node
for each child in expand(node)
DLS(child, goal, depth-1)
}
}

28
Uninformed Search
Strategies
Properties of DLS
Space complexity
• Since depth-limited search internally uses
depth-first search, the space complexity is equivalent to
that of normal depth-first search.
Time complexity
• Since depth-limited search internally uses depth-first-
search, the time complexity is equivalent to that of normal
depth-first search, and is O(|V| + |E|) where |V| stands
for the number of vertices and for the number of edges in
the explored graph. Note that depth-limited search does
not explore the entire graph, but just the part that lies
within the specified bound.
29
Uninformed Search
Strategies
5. Iterative Deepening Search
Function Iterative-deepening-Search(problem) returns a solution, or failure
for depth = 0 to  do
result  Depth-Limited-Search(problem, depth)
if result succeeds then return result
end
return failure

Combines the best of breadth-first and depth-first search


strategies.
• Completeness : Yes,
• Time complexity : O(b d)
• Space complexity : O(bd)
• Optimality : Yes, if step cost = 1
30
Uninformed Search
Strategies
Iterative Deepening Complexity
• Iterative deepening search may seem wasteful because so
many states are expanded multiple times.

• In practice, however, the overhead of these multiple


expansions is small, because most of the nodes are
towards leaves (bottom) of the search tree:
thus, the nodes that are evaluated several times (towards top
of tree) are in relatively small number.

31
Uninformed Search
Strategies
Iterative Deepening Complexity
• In iterative deepening, nodes at bottom level are expanded
once, level above twice, etc. up to root (expanded d+1
times) so total number of expansions is:
(d+1)1 + (d)b + (d-1)b^2 + … + 3b^(d-2) + 2b^(d-1) + 1b^d =
O(b^d)

• In general, iterative deepening is preferred to depth-first or


breadth-first when search space large and depth of
solution not known.

32
Uninformed Search
Strategies
Comparing Uninformed Search Strategies
Criterion Breadth Uniform Depth- Depth- Iterative Bidirectional
-First Cost First Limited Deepening (if applicable)
Time b^d b^d b^m b^l b^d b^(d/2)
Space b^d b^d bm bl bd b^(d/2)
Optimal? Yes Yes No No Yes Yes
Complete? Yes Yes No Yes if l≥d Yes Yes

• b – max branching factor of the search tree


• d – depth of the least-cost solution
• m – max depth of the state-space (may be infinity)
• l – depth cutoff
33
Summary

• Problem formulation usually requires abstracting away


real-world details to define a state space that can be
explored using computer algorithms.
• Once problem is formulated in abstract form, complexity
analysis helps us picking out best algorithm to solve
problem.
• Variety of uninformed search strategies; difference lies in
method used to pick node that will be further expanded.
• Iterative deepening search only uses linear space and not
much more time than other uniformed search strategies.

34
Uninformed Search Strategies
(Case Study)

35
Case Study (1)
• Find the path from S to G by using BFS and DFS method

S
L
A K
C

B D

G
H E

J I F
36
Case Study (2)
• Simulate the node expansion from start state (S) to reach
goal state (G) by using Uniform Cost Search (UCS) algorithm

2.0 S 2.0
1.0 L
1.0
A K
C
2.0 1.0
B D
3.0
2.0 1.0
G
H E
1.0
2.0 5.0 1.0
J I F
1.0 37
References
• Stuart Russell, Peter Norvig,. 2010. Artificial intelligence : a modern
approach. PE. New Jersey. ISBN:9780132071482, Chapter 1 & 2
• Elaine Rich, Kevin Knight, Shivashankar B. Nair. 2010. Artificial
Intelligence. MHE. New York. , Chapter 1 & 2
• Uninformed Search Strategies:
http://artint.info/html/ArtInt_52.html
• Simple Implementation of Uninformed Search Strategies:
http://www.codeproject.com/Articles/203828/AI-Simple-Implemen
tation-of-Uninformed-Search-Stra
• UCS:
http://intelligence.worldofcomputing.net/ai-search/uniform-cost-sear
ch.html
» Widodo Budiharto, Derwin Suhartono. Artificial Intelligence:
Konsep dan Penerapannya. PT. Andi Yogyakarta, Indonesia. 2014.
ISBN: 978-979-29-4222-4. Chapter 2.
38

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