Yapay Zeka - 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 81

Uninformed/Blind Search

Fundamentals of Artificial Intelligence


Example: Romania
Example: Romania

• On holiday in Romania; currently in Arad.


• Flight leaves tomorrow to Bucharest
• Formulate goal:
– be in Bucharest
• Formulate problem:
– states: various cities
– actions: drive between cities
• Find solution:
– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Vacuum world state space graph

• states integer dirt and robot location.


– The agent is in one of two locations, each of which might or might not
contain dirt – 8 possible states
• Initial state: any state
• actions Left, Right, Suck
• goal test no dirt at all locations
• path cost 1 per action
Example: The 8-puzzle

• states: locations of tiles


• Initial state: any state
• actions: move blank left, right, up, down
• goal test: goal state (given)
• path cost: 1 per move

[Note: optimal solution of n-Puzzle family is NP-hard]


Example: 8-queens problem

• states: any arrangement of 0-8 queens on the board is a


state
• Initial state: no queens on the board
• actions: add a queen to any empty square
• goal test: 8 queens are on the board, none attacked

64.63...57 = 1.8x1014 possiblesequences


Example: Route finding problem
• states: each is represented by a location (e.g. An airport) and the
current time
• Initial state: specified by the problem
• Successor function: returns the states resulting from taking any
scheduled flight, leaving later than the current time plus the within
airport transit time, from the current airport to another
• goal test: are we at the destination by some pre-specified time
• Path cost:monetary cost, waiting time, flight time, customs and
immigration procedures, seat quality, time of day, type of airplane,
frequent-flyer mileage awards, etc

• Route finding algorithms are used in a variety of applications, such


as routing in computer networks, military operations planning,
airline travel planning systems
Example: robotic assembly

• states: real-valued coordinates of robot joint angles parts of


the object to be assembled
• actions: continuous motions of robot joints
• goal test: complete assembly
• path cost: time to execute
Tree search algorithms

• Basic idea:
– offline, simulated exploration of state space by generating
successors of already-explored states (a.k.a.~expanding states)
Example: Romania
Tree search example
Tree search example
Tree search example
Implementation: Components of a node

• State: the state in the state space to which the node


corresponds
• Parent-node: the node in the search tree that
generated this node
• Action: the action that was applied to the parent to
generate the node
• Path-cost: the cost, traditionally denoted by g(n), of the
path from the initial state to the node, as indicated by the
parent pointers
• Depth: the number of steps along the path from the initial
state
Uninformed search strategies

• A search strategy is defined by picking the order of node


expansion
• Uninformed search (blind search) strategies use only the
information available in the problem definition
• Can only distinguish goal states from non-goal state
• Breadth-first search
• Uniform-cost search
• Depth-first search
• Depth-limited search
• Iterative deepening search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Analysis of Search strategies

• Strategies are evaluated along the following dimensions:


– completeness: does it always find a solution if one exists?
– time complexity: number of nodes generated
– space complexity: maximum number of nodes in memory
– optimality: does it always find a least-cost 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 ∞)
Properties of breadth-first search
• Complete? Yes (if b is finite)
• Time?
Number of nodes in a b-ary tree of depth d:
(d is the depth of the optimal solution)

• Space? O(bd) (keeps every node in memory)

• Optimal? Yes (if cost = 1 per step)


• Space is the bigger problem (more than time)
Properties of breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Uniform-cost search
Uniform-cost search

• For each frontier node, save the total cost of the path
from the initial state to that node
• Expand the frontier node with the lowest path cost
• Implementation: frontier is a priority queue ordered by
path cost
• Equivalent to breadth-first if step costs all equal
• Equivalent to Dijkstra’s algorithm in general
Uniform-cost search
Uniform-cost search

Create root by start


state
Uniform-cost search

Expand and add


children to queue
Uniform-cost search

Expand R and add


children to queue

Already expended
Uniform-cost search

Already expended
Uniform-cost search

Replace with new


node

Already expended
Uniform-cost search
Uniform-cost search
Properties of uniform-cost search

• Expand least-cost unexpanded node


• Implementation:
– fringe = queue ordered by path cost
• Equivalent to breadth-first if step costs all equal

• Complete?
Yes, if step cost is greater than some positive constant ε (we
don’t want infinite sequences of steps that have a finite total
cost)
• Optimal?
Yes
Uniform-cost search

• Complete? Yes, if step cost ≥ ε

• Time? # of nodes with pathn cost g ≤ cost of optimal


solution,
O(b(C*/ ε)) where C* is the cost of the optimal solution
• This can be greater than O(bd): the search can explore long paths
consisting of small steps before exploring shorter paths consisting
of larger steps

• Space? # of nodes with g ≤ cost of optimal solution,


O(b(C*/ ε))

• Optimal? Yes – nodes expanded in increasing order of g(n)


Uniform-cost search example
Uniform-cost search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search

H is removed from memory and even tree search


Depth-first search

I is removed from memory and even tree search


Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Depth-first search
Properties 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? Could be the time to reach a solution at
maximum depth m:

Terrible if m is much larger than d, But if there are


lots of solutions, may be much faster than BFS
• Space?
• i.e., linear space!

• Optimal? No - – returns the first solution it


finds
Depth-first search
Depth-first search
Depth-first search
Depth-limited search
= depth-first search with depth limit l,
i.e., nodes at depth l have no successors

• Recursive implementation:
Properties of Depth-limited search

• Complete? Yes, if l>=d

• Time?

• Space?

• Optimal? No, like DFS


Depth limited search

The main problem. Determine a suitable depth range!


Iterative deepening search

• Idea: get DFS’s space


advantage with BFS’s time
/shallow-solution advantages
• Run a DFS with depth limit 1. If
no solution…
• Run a DFS with depth limit 2. If
no solution…
• Run a DFS with depth limit 3.
…..

• Isn’t that wastefully redundant?


• Generally most work happens in the
lowest level searched, so not so bad!
Iterative deepening search l =0
Iterative deepening search l =1
Iterative deepening search l =2
Iterative deepening search l =3
Properties of iterative deepening search

• Complete? Yes, like BFS


• Time?

• Space?

• Optimal? Yes, like BFS if step cost = 1


Graph search
Repeated states

• Failure to detect repeated states can turn a linear


problem into an exponential one!
Repeated states

• Failure to detect repeated states can turn a linear


problem into an exponential one!

For m=20
The number of graph state= 800
The number of tree nodes=1099511627776
Repeated states
Repeated states
Handling repeated states
Handling repeated states

• Do not return to the state just you came from

• Do not create paths with cycles in them

• Do not generate any state that was ever generated


before
Summary
• Problem formulation usually requires abstracting away real-world
details to define a state space that can feasibly be explored
• Variety of uninformed search strategies
• Iterative deepening search uses only linear space and not much more
time than other uninformed algorithms

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