3. Solving Problems by Searching Problem

advertisement
Contents
Foundations of Artificial Intelligence
1
Problem-Solving Agents
2
Formulating Problems
3
Problem Types
4
Example Problems
5
Search Strategies
3. Solving Problems by Searching
Problem-Solving Agents, Formulating Problems, Search Strategies
Wolfram Burgard, Bernhard Nebel, and Martin Riedmiller
Albert-Ludwigs-Universität Freiburg
April 27, 2012
3
(University of Freiburg)
Problem-Solving Agents
Foundations of AI
April 27, 2012
2 / 47
A Simple Problem-Solving Agent
→ Goal-based agents
Formulation: problem as a state-space and goal as a particular condition
on states
Given: initial state
Goal: To reach the specified goal (a state) through the execution
of appropriate actions
→ Search for a suitable action sequence and execute the actions
(University of Freiburg)
SOLVING PROBLEMS BY
SEARCHING
Foundations of AI
April 27, 2012
3 / 47
function S IMPLE -P ROBLEM -S OLVING -AGENT( percept ) returns an action
persistent: seq, an action sequence, initially empty
state, some description of the current world state
goal , a goal, initially null
problem, a problem formulation
state ← U PDATE -S TATE(state , percept )
if seq is empty then
goal ← F ORMULATE -G OAL(state )
problem ← F ORMULATE -P ROBLEM(state, goal )
seq ← S EARCH( problem)
if seq = failure then return a null action
action ← F IRST(seq )
seq ← R EST(seq)
return action
Figure 3.1
A simple problem-solving agent. It first formulates a goal and a problem, sea
sequence
of
actions
that would
solve the problem, and then executes
the actions
one at a ti
(University of Freiburg)
Foundations of AI
April 27, 2012
4 / 47
this is complete, it formulates another goal and starts over.
Properties of this Agent
Problem Formulation
Goal formulation
World states with certain properties
Stationary environment
Definition of the state space
(important: only the relevant aspects → abstraction)
Observable environment
Definition of the actions that can change the world state
Discrete states
Definition of the problem type, which depends on the knowledge of the
world states and actions
→ states in the search space
Deterministic environment
Specification of the search costs (search costs, offline costs) and the
execution costs (path costs, online costs)
Note: The type of problem formulation can have a serious influence on
the difficulty of finding a solution.
(University of Freiburg)
Foundations of AI
April 27, 2012
5 / 47
Example Problem Formulation
(University of Freiburg)
Foundations of AI
April 27, 2012
6 / 47
Alternative Problem Formulation
Given an n × n board from which two diagonally opposite corners have
been removed (here 8 × 8):
Question:
Goal: Cover the board completely with dominoes, each of which covers
two neighboring squares.
Can a chess board consisting of n2 /2 black and n2 /2 − 2 white squares be
completely covered with dominoes such that each domino covers one black
and one white square?
→ Goal, state space, actions, search, . . .
. . . clearly not.
(University of Freiburg)
Foundations of AI
April 27, 2012
7 / 47
(University of Freiburg)
Foundations of AI
April 27, 2012
8 / 47
Problem Formulation for the Vacuum Cleaner World
Problem Types: Knowledge of States and Actions
State is completely observable
Complete world state knowledge
Complete action knowledge
→ The agent always knows its world state
World state space:
2 positions, dirt or no dirt
→ 8 world states
1
Actions:
Lef t (L), Right (R), or Suck (S)
2
3
4
Goal:
no dirt in the rooms
5
6
Path costs:
one unit per action
7
State is partially observable
Incomplete world state knowledge
Incomplete action knowledge
→ The agent only knows which group of world states it is in
Contingency problem
It is impossible to define a complete sequence of actions that constitute
a solution in advance because information about the intermediary states
is unknown.
8
Exploration problem
State space and effects of actions unknown. Difficult!
(University of Freiburg)
Foundations of AI
April 27, 2012
9 / 47
The Vacuum Cleaner Problem
R
L
R
L
S
S
L
R
L
L
S
S
S
If the vacuum cleaner has
no sensors, it doesn’t
know where it or the dirt
is.
April 27, 2012
10 / 47
L
R
L
In spite of this, it can still
solve the problem. Here,
states are knowledge
states.
R
R
R
Foundations of AI
The Vacuum Cleaner World as a Partially Observable State
Problem
If the environment is completely observable, the vacuum cleaner always
knows where it is and where the dirt is. The solution then is reduced to
searching for a path from the initial state to the goal state.
L
(University of Freiburg)
S
S
S
S
L
R
L
S
R
L
States for the search: The
power set of the world
states 1-8.
R
L
S
R
S
S
R
R
L
L
S
L
R
S
R
States for the search: The world states 1-8.
(University of Freiburg)
Foundations of AI
April 27, 2012
11 / 47
(University of Freiburg)
Foundations of AI
April 27, 2012
12 / 47
Concepts (1)
L
R
L
R
Initial State: The state from which the agent infers that it is at the
beginning
S
State Space: Set of all possible states
S
Actions: Description of possible actions. Available actions might
be a function of the state.
S
L
R
Transition Model: Description of the outcome of an action
(successor function)
L
S
S
R
R
L
L
S
L
Goal Test: Tests whether the state description matches a goal state
R
S
R
(University of Freiburg)
Concepts (2)
Foundations of AI
April 27, 2012
14 / 47
Example: The 8-Puzzle
7
2
5
4
1
2
6
3
4
5
1
6
7
8
Path: A sequence of actions leading from one state to another
8
Path Costs: Cost function g over paths. Usually the sum of the costs of
the actions along the path
Search Costs: Time and storage requirements to find a solution
Total Costs: Search costs + path costs
Foundations of AI
April 27, 2012
Goal State
Start State
States: Description of the location of each of the eight tiles and (for
efficiency) the blank square.
Initial State: Initial configuration of the puzzle.
Actions (transition model defined accordingly): Moving the blank left,
right, up, or down.
Goal Test: Does the state match the configuration on the right (or any
other configuration)?
Path Costs: Each step costs 1 unit (path costs corresponds to its
length).
Solution: Path from an initial to a goal state
(University of Freiburg)
3
15 / 47
(University of Freiburg)
Foundations of AI
April 27, 2012
16 / 47
Example: 8-Queens Problem
Example: 8-Queens Problem
Almost a solution:
A solution:
States:
Any arrangement of 0 to 8 queens on the board.
Initial state:
No queen on the board.
Successor function:
Add a queen to an empty field on the board.
Goal test:
8 queens on the board such that no queen attacks another.
Path costs:
0 (we are only interested in the solution).
States:
Any arrangement of 0 to 8 queens on the board.
Initial state:
No queen on the board.
Successor function:
Add a queen to an empty field on the board.
Goal test:
8 queens on the board such that no queen attacks another.
Path costs:
0 (we are only interested in the solution).
(University of Freiburg)
Foundations of AI
April 27, 2012
17 / 47
Alternative Formulations
Foundations of AI
April 27, 2012
18 / 47
Example: Missionaries and Cannibals
Informal problem description:
Naı̈ve formulation
States: any arrangement of 0–8 queens
Problem: 64 × 63 × · · · × 57 ≈ 1014 possible states
Three missionaries and three cannibals are on one side of a river that
they wish to cross.
Better formulation
States: any arrangement of n queens (0 ≤ n ≤ 8) one per column in
the leftmost n columns such that no queen attacks another.
Successor function: add a queen to any square in the leftmost empty
column such that it is not attacked by any other queen.
Problem: 2, 057 states
Sometimes no admissible states can be found.
(University of Freiburg)
(University of Freiburg)
Foundations of AI
April 27, 2012
19 / 47
A boat is available that can hold at most two people.
You must never leave a group of missionaries outnumbered by cannibals
on the same bank.
→ Find an action sequence that brings everyone safely to the opposite
bank.
(University of Freiburg)
Foundations of AI
April 27, 2012
20 / 47
Formalization of the M&C Problem
Examples of Real-World Problems
States: triple (x, y, z) with 0 ≤ x, y, z ≤ 3, where x, y and z
represent the number of missionaries, cannibals and
boats currently on the original bank.
Route Planning, Shortest Path Problem
Simple in principle (polynomial problem). Complications arise when path
costs are unknown or vary dynamically (e.g., route planning in Canada)
Travelling Salesperson Problem (TSP)
A common prototype for NP-complete problems
Initial State: (3, 3, 1)
Successor function: from each state, either bring one missionary, one
cannibal, two missionaries, two cannibals, or one of
each type to the other bank.
VLSI Layout
Another NP-complete problem
Goal State: (0, 0, 0)
Robot Navigation (with high degrees of freedom)
Difficulty increases quickly with the number of degrees of freedom.
Further possible complications: errors of perception, unknown
environments
Path Costs: 1 unit per crossing
Assembly Sequencing
Planning of the assembly of complex objects (by robots)
Note: not all states are attainable (e.g., (0, 0, 1)) and some
are illegal.
(University of Freiburg)
Foundations of AI
April 27, 2012
21 / 47
General
Search Search
General
(University of Freiburg)
Foundations of AI
April 27, 2012
22 / 47
Some notations
From From
the initial
all successive
states step states
by step step
→ search
the state,
initialproduce
state, produce
all successive
tree. by step  search tree.
(a) initial state
(b) after expansion
of (3,3,1)
(2,3,0) (3,2,0)
(3,3,1)
node expansion
generating all successor nodes considering the available actions
(3,3,1)
frontier
set of all nodes available for expansion
(2,2,0)
search strategy
defines which node is expanded next
(1,3,0) (3,1,0)
tree-based search
it might happen, that within a search tree a state is entered repeatedly,
leading even to infinite loops. To avoid this,
(3,3,1)
(c) after expansion
of (3,2,0)
(2,3,0) (3,2,0)
(2,2,0)
graph-based search keeps a set of already visited states, the so-called
explored set.
(1,3,0) (3,1,0)
(3,3,1)
03/23
(University of Freiburg)
Foundations of AI
April 27, 2012
23 / 47
(University of Freiburg)
Foundations of AI
April 27, 2012
24 / 47
Implementing the Search Tree
Nodes in the Search Tree
Data structure for each node n in the search tree:
n.State: the state in the state space to which the node corresponds
n.Parent: the node in the search tree that generated this node
PARENT-NODE
n.Action: the action that was applied to the parent to generate the node
n.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
Operations on a queue:
Empty?(queue): returns true only if there are no more elements in the
queue
Node
5
4
6
1
88
7
3
22
ACTION = right
DEPTH = 6
PATH-COST = 6
STATE
Pop(queue): removes the first element of the queue and returns it
Insert(element, queue): inserts an element (various possibilities) and returns
the resulting queue
(University of Freiburg)
Foundations of AI
April 27, 2012
25 / 47
Foundations of AI
April 27, 2012
26 / 47
function T REE -S EARCH( problem) returns a solution, or failure
initialize the frontier using the initial state of problem
General
Procedure
loopGraph-Search
do
5
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
expand the chosen node, adding the resulting nodes to the frontier
General Tree-Search Procedure
function G RAPH -S EARCH( problem) returns a solution, or failure
initialize the frontier using the initial state of problem
initialize the explored set to be empty
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
add the node to the explored set
expand the chosen node, adding the resulting nodes to the frontier
only if not in the frontier or explored set
function T REE -S EARCH( problem) returns a solution, or failure
initialize the frontier using the initial state of problem
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
expand the chosen node, adding the resulting nodes to the frontier
function G RAPH -S EARCH( problem) returns a solution, or failure
initialize the frontier using the initial state of problem
initialize the explored set to be empty
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
(University of Freiburg)
Foundations of AI
April 27, 2012
add the node to the explored set
(University of Freiburg)
Figure 3.7
An informal description of the general tree-search and graph-search algorithm
parts of G RAPH -S EARCH marked in bold italic are the additions needed to handle repeated sta
27 / 47
(University of Freiburg)
Foundations of AI
April 27, 2012
28 / 47
Criteria for Search Strategies
Search Strategies
function T REE -S EARCH( problem) returns a solution, or failure
initialize the frontier using the initial state of problem
loop do
if theor
frontier
then return failure
Uninformed
blindis empty
searches
choose a leaf node and remove it from the frontier
No information
oncontains
the length
or cost
a path
to the solution.
if the node
a goal state
then of
return
the corresponding
solution
expand the chosen node, adding the resulting nodes to the frontier
Completeness: Is the strategy guaranteed to find a solution when
there is one?
Time Complexity: How long does it take to find a solution?
Space Complexity: How much memory does the search require?
breadth-first search, uniform cost search, depth-first search,
depth-limited
search,
iterative
searchor and
function G RAPH
-S EARCH
( problem)deepening
returns a solution,
failure
Optimality: Does the strategy find the best solution (with the
lowest path cost)?
initialize the frontier using the initial state of problem
bi-directional
search.
initialize the explored set to be empty
loop do
if the
frontier is empty
then return
failure
In contrast:
informed
or heuristic
approaches
problem describing quantities
b: branching factor
d: depth of shallowest goal node
m: maximum length of any path in the state space
(University of Freiburg)
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
add the node to the explored set
expand the chosen node, adding the resulting nodes to the frontier
only if not in the frontier or explored set
Foundations of AI
April 27, 2012
29 / 47
Breadth-First Search (1)
A
B
D
C
E
F
G
D
C
E
function B READTH -F IRST-S EARCH( problem) returns a solution, or failure
A
B
F
informal description
of oftheAI general tree-search andApril
graph-search
algorithms.
Th
Foundations
27, 2012
30
/ 47
parts of G RAPH -S EARCH marked in bold italic are the additions needed to handle repeated states.
Breadth-First Search (2)
Nodes are expanded in the order they were produced
(f rontier ← a FIFO queue).
A
Figure
3.7
An
(University
of Freiburg)
A
B
G
D
C
E
F
B
G
D
C
E
F
G
Always finds the shallowest goal state first.
Completeness is obvious.
The solution is optimal, provided every action has identical,
non-negative costs.
node ← a node with S TATE = problem.I NITIAL -S TATE, PATH -C OST = 0
if problem.G OAL -T EST(node.S TATE) then return S OLUTION(node)
frontier ← a FIFO queue with node as the only element
explored ← an empty set
loop do
if E MPTY ?( frontier ) then return failure
node ← P OP( frontier ) /* chooses the shallowest node in frontier */
add node.S TATE to explored
for each action in problem.ACTIONS(node.S TATE) do
child ← C HILD -N ODE( problem, node, action)
if child .S TATE is not in explored or frontier then
if problem.G OAL -T EST(child .S TATE) then return S OLUTION(child)
frontier ← I NSERT(child, frontier )
Figure 3.11
(University of Freiburg)
Foundations of AI
April 27, 2012
31 / 47
(University of Freiburg)
Breadth-first search on a graph.
Foundations of AI
April 27, 2012
32 / 47
Breadth-First Search (3)
Breadth-First Search (4)
Time Complexity:
Let b be the maximal branching factor and d the depth of a solution path.
Then the maximal number of nodes expanded is
Example: b = 10; 10, 000 nodes/second; 1, 000 bytes/node:
2
3
d
d
b + b + b + · · · + b ∈ O(b )
(Note: If the algorithm were to apply the goal test to nodes when selected
for expansion rather than when generated, the whole layer of nodes at
depth d would be expanded before the goal was detected and the time
complexity would be O(bd+1 ))
Space Complexity:
Every node generated is kept in memory. Therefore space needed for the
frontier is O(bd ) and for the explored set O(bd−1 ).
(University of Freiburg)
Foundations of AI
April 27, 2012
33 / 47
Uniform-Cost Search
Depth
Nodes
Time
2
1,100
.11
seconds
1
4
111,100
11
seconds
106
megabytes
6
107
19
minutes
10
gigabytes
8
9
31
hours
1
terabyte
10
11
129
days
101
12
10
13
35
years
10
14
1015
3,523
years
1
10
10
(University of Freiburg)
megabyte
terabytes
petabytes
exabyte
Foundations of AI
April 27, 2012
34 / 47
Depth-First Search (1)
if step costs for doing an action are equal, then breadth-first search finds
path with the optimal costs.
if step costs are different (e.g., map: driving from one place to another
might differ in distance), then uniform-cost search is a mean to find the
optimal solution.
uniform-cost search expands the node with the lowest path costs g(n).
Realization: priority queue.
Always expands an unexpanded node at the greatest depth
(f rontier ← a LIFO queue).
It is common to realize depth-first search as a recursive function
Example (Nodes at depth 3 are assumed to have no successors):
A
A
B
C
D
H
E
I
J
F
K
L
N
C
D
G
M
O
H
E
I
J
H
C
E
I
J
F
K
L
G
N
M
J
O
H
I
J
L
G
N
M
Foundations of AI
April 27, 2012
35 / 47
H
(University of Freiburg)
J
N
M
O
H
E
I
J
L
G
O
H
E
I
L
G
J
M
N
O
H
F
K
J
N
M
G
N
M
O
H
E
I
J
F
L
K
O
G
N
M
B
F
K
L
O
A
E
I
O
C
D
C
D
G
N
M
B
F
K
L
A
B
F
K
K
C
D
G
C
D
C
E
I
J
A
B
Always finds the cheapest solution, given that g(successor(n)) ≥ g(n) for
all n.
L
K
A
D
I
B
F
B
F
K
H
F
A
E
C
E
I
O
E
A
B
H
N
M
C
D
C
D
A
D
L
G
B
F
K
B
A
B
D
A
B
A
(University of Freiburg)
Memory
L
G
M
N
Foundations of AI
C
D
O
H
E
I
J
F
K
L
G
M
N
O
April 27, 2012
36 / 47
Depth-First Search (2)
6
in general, solution found is not optimal
Completeness can be guaranteed only for graph-based search and finite
state spaces
Algorithm: see later (depth-limited search)
Depth-First Search (3)
Chapter 3.
Solving Problems by Searching
Time Complexity:
in graph-based search bounded by the size of the state space (might be
infinite!)
function U NIFORM -C OST-S EARCH( problem) returns a solution, m
in tree-based
search, algorithm might generate O(b or )failure
nodes in the
node ← a node with S TATE = problem.I NITIAL -S TATE, PATH -C OST = 0
search tree which might be much larger than the size of the state space.
frontier ← a priority queue ordered by PATH -C OST, with node as the only element
(m isexplored
the maximum
of a path in the state space)
← an empty length
set
loop do
if E MPTY ?( frontier ) then return failure
Space Complexity:
node ← P OP( frontier ) /* chooses the lowest-cost node in frontier */
if problem.G
-T EST(node.S
TATE
) thenthe
return
S OLUTION
(node)
tree-based
search:OAL
needs
to store
only
nodes
along
the path from
add node.S TATE to explored
the rootfor
toeach
theaction
leaf innode.
Once
a
node
has
been
expanded,
it can be
problem.ACTIONS(node.S TATE) do
removed from
memory
soon
as all
itsaction)
descendants have been fully
child ←
C HILD -Nas
ODE
( problem,
node,
if child .S TATEmemory
is not in explored
or frontieristhen
explored. Therefore,
requirement
only O(b m). This is the
frontier ← I NSERT(child, frontier )
reason, why
it is practically so relevant despite all the other
else if child.S TATE is in frontier with higher PATH -C OST then
shortcomings!replace that frontier node with child
graph-based search: in worst case, all states need to be stored in the
Figure
a graph. The algorithm is identical to the general graph search
explored
set3.13
(no Uniform-cost
advantagesearch
overonbreadth-first)
(University of Freiburg)
Foundations of AI
April 27, 2012
37 / 47
Depth-Limited Search (1)
algorithm in Figure ??, except for the use of a priority queue and the addition of an extra check in case
Foundations of AI
April 27, 2012
38 / 47
a shorter path to a frontier state is discovered.
The data structure for frontier
needs to support
efficient
membership testing, so it should combine the capabilities of a priority queue and a hash table.
(University of Freiburg)
Depth-Limited Search (2)
Depth-first search with an imposed cutoff on the maximum depth of a
path. e.g., route planning: with n cities, the maximum depth is n − 1.
Oradea
function D EPTH -L IMITED -S EARCH( problem, limit) returns a solution, or failure/cutoff
return R ECURSIVE -DLS(M AKE -N ODE(problem.I NITIAL -S TATE), problem, limit)
Neamt
Zerind
function R ECURSIVE -DLS(node, problem, limit) returns a solution, or failure/cutoff
if problem.G OAL -T EST(node.S TATE) then return S OLUTION(node)
else if limit = 0 then return cutoff
else
cutoff occurred ? ← false
for each action in problem.ACTIONS(node.S TATE) do
child ← C HILD -N ODE( problem, node, action)
result ← R ECURSIVE -DLS(child, problem, limit − 1)
if result = cutoff then cutoff occurred ? ← true
else if result 6= failure then return result
if cutoff occurred ? then return cutoff else return failure
Iasi
Arad
Sibiu
Fagaras
Vaslui
Rimnicu Vilcea
Timisoara
Pitesti
Lugoj
Hirsova
Mehadia
Urziceni
Bucharest
Dobreta
Craiova
Giurgiu
Eforie
Figure 3.16
A recursive implementation of depth-limited tree search.
Sometimes, the search depth can be refined. E.g., here, a depth of 9 is
sufficient (you can reach every city in at most 9 steps).
(University of Freiburg)
Foundations of AI
April 27, 2012
39 / 47
(University of Freiburg)
Foundations of AI
April 27, 2012
40 / 47
Iterative Deepening Search (1)
Example
idea: use depth-limited search and in every iteration increase search
depth by one
A
Limit = 0
A
Limit = 1
looks a bit like a waste of resources (since the first steps are always
repeated), but complexity-wise it is not so bad as it might seem
Combines depth- and breadth-first searches
A
B
7
C
C
C
E
G
C
D
E
C
E
G
E
E
I
J
G
M
L
D
O
N
H
J
Iterative Deepening Search (2)
J
O
N
H
J
J
G
M
L
L
G
J
M
N
O
(University of Freiburg)
H
E
I
J
F
H
O
N
C
D
G
M
L
H
E
I
J
F
K
J
B
F
K
L
G
G
M
L
M
N
O
H
H
E
I
J
F
K
J
B
F
K
G
M
L
O
N
A
E
I
O
N
C
D
O
N
C
D
G
M
L
A
E
I
G
B
F
K
B
F
K
E
C
D
O
N
C
D
C
D
A
B
F
K
E
I
G
A
B
F
K
G
A
E
I
C
E
I
H
A
B
D
O
N
C
D
G
M
L
F
B
F
C
D
G
M
L
B
F
K
A
H
Figure 3.17
The iterative deepening search algorithm, which repeatedly applies depth-limited search
withofincreasing
limits. It terminates
whenof aAIsolution is found or if April
the depth-limited
returns
(University
Freiburg)
Foundations
27, 2012
41 /search
47
failure, meaning that no solution exists.
C
E
I
E
A
B
D
H
E
A
B
F
K
C
D
A
E
I
G
C
D
C
A
function I TERATIVE -D EEPENING -S EARCH( problem) returns a solution, or failure
for depth = 0 to ∞ do
result ← D EPTH -L IMITED -S EARCH( problem, depth )
if result 6= cutoff then return result
G
B
F
K
B
F
A
C
D
E
B
F
A
B
H
C
D
C
D
C
A
B
F
Limit = 3
G
A
B
B
A
B
F
A
D
C
A
B
F
A
B
A
B
D
A
B
A
Limit = 2
Optimal and complete like breadth-first search, but requires much less
memory: O(b d)
Time complexity only little worse than breadth-first (see later)
A
L
G
M
N
C
D
O
H
E
I
Foundations of AI
J
F
K
L
G
M
N
O
April 27, 2012
42 / 47
Bidirectional Searches
Number of expansions
Iterative Deepening Search
(d)b + (d − 1)b2 + · · · + 3bd−2 + 2bd−1 + 1bd
Breadth-First-Search
b + b2 + · · · + bd−1 + bd
Example: b = 10, d = 5
Breadth-First-Search
10EARCH
+ 100
+ 1, 000
+ 10,a000
+ 100,
000
function
R ECURSIVE -B EST-F IRST-S
( problem)
returns
solution,
or failure
return RBFS(problem, M AKE -N
(problem.I
=ODE
111,
110 NITIAL -S TATE), ∞)
IterativeRBFS(problem,
Deepening Search
50 +returns
400 +a3,solution,
000 + or
20,
000 and
+ 100,
000
failure
a new
f -cost limit
function
node, f limit)
if problem.G OAL -T EST(node.S TATE
)
then
return
S
OLUTION(node)
= 123, 450
successors ← [ ]
action
in problem.A
CTIONS(node.S TATE) do
For b =for
10,each
IDS
expands
only 11%
more than the number of nodes
add C HILD -N ODE( problem, node, action) into successors
expanded
by (optimized)
breadth-first-search.
if successors
is empty then
return failure, ∞
for each s in successors do /* update f with value from previous search, if any */
→ Iteratives.fdeepening
general
is))the preferred uninformed search
← max(s.g in
+ s.h,
node.f
do there is a large search space and the depth of the solution is
methodloop
when
← the lowest f -value node in successors
not known.best
if best .f > f limit then return failure, best .f
f -value
(Universityalternative
of Freiburg) ← the second-lowest
Foundations
of AIamong successors
April 27, 2012
43 / 47
result , best .f ← RBFS(problem, best , min( f limit, alternative))
Goal
Start
As long as forwards and backwards searches are symmetric, search times of
O(2 · bd/2 ) = O(bd/2 ) can be obtained.
E.g., for b = 10, d = 6, instead of 1, 111, 110 only 2, 220 nodes!
(University of Freiburg)
Foundations of AI
April 27, 2012
44 / 47
Problems with Bidirectional Search
Comparison of Search Strategies
Time complexity, space complexity, optimality, completeness
The operators are not always reversible, which makes calculation the
predecessors very difficult.
Criterion
In some cases there are many possible goal states, which may not be
easily describable. Example: the predecessors of the checkmate in chess.
Complete?
Time
There must be an efficient way to check if a new node already appears
in the search tree of the other half of the search.
Space
What kind of search should be chosen for each direction (the previous
figure shows a breadth-first search, which is not always optimal)?
b
d
m
l
C∗
(University of Freiburg)
Foundations of AI
April 27, 2012
45 / 47
Summary
Before an agent can start searching for solutions, it must formulate a
goal and then use that goal to formulate a problem.
A problem consists of five parts: The state space, initial situation,
actions, goal test and path costs. A path from an initial state to a goal
state is a solution.
A general search algorithm can be used to solve any problem. Specific
variants of the algorithm can use different search strategies.
Search algorithms are judged on the basis of completeness, optimality,
time complexity and space complexity.
(University of Freiburg)
Foundations of AI
April 27, 2012
47 / 47
Breadth-
Uniform-
Depth-
Depth-
Iterative
Bidirectional
First
Cost
First
Limited
Deepening
(if applicable)
Yesa
Yesa,b
No
No
Yesa
Yesa,d
O(bd )
∗
O(b1+bC /c )
O(bm )
O(bl )
O(bd )
O(bd/2 )
O(bm)
O(bl)
O(bd)
O(bd/2 )
No
Yesc
Yesc,d
O(bd )
Optimal?
Yesc
O(b1+bC
∗
/c )
Yes
No
branching factor
depth of solution
maximum depth of the search tree
depth limit
cost of the optimal solution
minimal cost of an action
(University of Freiburg)
Superscripts:
a b is finite
b if step costs not less than c if step costs are all identical
d if both directions use breadth-first search
Foundations of AI
April 27, 2012
46 / 47
Download