You are on page 1of 24

Omar Arif

SOLVING PROBLEMS BY SEARCHING Reading: Chapter 3


EXAMPLE - NAVIGATION PROBLEM
vGiven a map, pick the best route from start state to the goal
state
vAssumptions
vEnvironment is Fully observable
vState space Known
vEnvironment is Discrete
vEnvironment is Deterministic
vEnvironment is static
EXAMPLE: NAVIGATION PROBLEM
vOn holiday in Romania; currently in Arad.
vFlight leaves tomorrow from Bucharest
vFormulate goal:
vbe in Bucharest
vFormulate problem:
vstates: various cities
vactions: drive between cities
vFind solution:
vsequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
EXAMPLE: ROMANIA
vOn holiday in Romania; currently in Arad.
vFlight leaves tomorrow from Bucharest
vFormulate goal:
vbe in Bucharest
v
vFormulate problem:
vstates: various cities
vactions: drive between cities
v
vFind solution:
vsequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
v
PROBLEM FORMULATION

A problem is defined by five items:


1. initial state e.g., "at Arad”
2. Actions A description of possible actions. Given a state s, Actions(s) returns set of
actions that can be executed in s
3. Transition Model: A description of what action does. Specified by a function Result(s,a) that returns the state
that results from doing action a in state s.
4. Goal test Determines whether a given state is a goal. goaltest(s) à T|F
5. path cost
­ e.g., sum of distances, number of actions executed, etc.
­ c(s,a,ś) is the step cost, assumed to be ≥ 0
A solution is a sequence of actions leading from the initial state to a goal state
Set of all states is called state space
EXAMPLE: VACUUM WORLD

nStates?
nactions?
ngoal test?
npath cost?
EXAMPLE: VACUUM WORLD

nstates? dirt and robot location (8 states)


nInitial State Any state can be designated
as initial state
nactions? Left, Right, Suck
nTransition Model (Next slide)
ngoal test? no dirt at all locations
npath cost? 1 per action
EXAMPLE: VACUUM WORLD
EXAMPLE: THE 8-PUZZLE

nstates?
nActions?
ngoal test?
npath cost?
EXAMPLE: THE 8-PUZZLE

nstates? locations of tiles (9!/2)


nActions? move blank left,
right, up, down
ngoal test? =goal state (given)
npath cost? 1 per move
8-QUEEN PROBLEM
The goal of the 8-queens problem is to place
eight queens on a chessboard such that no queen
attacks any other.
nstates?
nInitial state?
nActions?
ngoal test?
npath cost?
8-QUEEN PROBLEM
The goal of the 8-queens problem is to place
eight queens on a chessboard such that no queen
attacks any other.
nstates? Any arrangement of 0 to 8 queens
64!/(64−8)!8!
nInitial state? No queens on the board.
nActions? Add a queen to any empty square.
ngoal test? 8 queens are on the board, none attacked.
npath cost? 1 per move
TREE SEARCH ALGORITHMS
nBasic idea:
noffline, simulated exploration of state space by generating
successors of already-explored states (a.k.a.~expanding states)
TREE SEARCH EXAMPLE
TREE SEARCH EXAMPLE
TREE SEARCH EXAMPLE
TREE SEARCH ALGORITHM
Tree-search (problem p) returns path
frontier = [p.initial]
loop:
if frontier is empty; return fail
path = frontier.pop()
s = path.end
if p.goaltest(s); return path
for a in p.action(s)
add [path+p.result(s,a)]to frontier
EXAMPLE: DRY RUN
vOn holiday in Romania; currently in Arad.
vFlight leaves tomorrow from Bucharest
vFormulate goal:
vbe in Bucharest
v
vFormulate problem:
vstates: various cities
vactions: drive between cities
v
vFind solution:
vsequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
v
GRAPH SEARCH ALGORITHM
Graph-search (problem p) returns path
frontier = [p.initial], explored = {}
loop:
if frontier is empty; return fail
path = frontier.pop()
s = path.end
if s is not in explored list: add s to explored list
if goaltest(s); return path
for a in p.action(s)
if p.result(s,a) not in explored list:
frontier.update([path+p.result(s,a)])
Where Frontier.update(path):
if path in not in frontier, add it to frontier
else add lower-cost path to frontier
Start state: S
EXAMPLE Goal state: G2
Run tree search algorithm and draw
the resultant tree.
GRAPH SEARCH ALGORITHM
Different Search Strategies
Graph-search (problem p) returns path differ in the way elements are
removed from the frontier
frontier = [p.initial], explored = {}
loop:
if frontier is empty; return fail
path = frontier.pop()
s = path.end
if s is not in explored list: add s to explored list
if goaltest(s); return path
for a in p.action(s)
if p.result(s,a) not in explored list:
frontier.update([path+p.result(s,a)])
SEARCH 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?
­ space complexity: How much memory is needed to perform search?
­ 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 ∞)
SUMMARY
vProblem formulation
vTree-search algorithm
vGraph-search algorithm

Coming up Next
vUninformed search strategies
vInformed search strategies
QUESTIONS

You might also like