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

 Basic Idea: simulating the exploration of state space by generating

successors of already-explored states ( or expanding states)

function Tree-Search (problem, strategy) returns a solution, or failure

initialize the search tree using the initial state of problem


loop do
if there are no candidates for expansion then return failure

choose a child node for expansion according to strategy

if the node contains a goal state then return the corresponding solution

else expand the node and add the resulting nodes to the search tree
end
 A state is a physical configuration

 A node is a data structure : a part of a search tree which is


defined by a parent, children, depth, path cost g(x)

 States do not have parents, children, depth, or path cost!


Parent

7 8 3
Depth = 3
2 1 Path_Cost = 3
4 5 6
Children

State Node
 Expand Function : creates new nodes, filling in the various
fields and using the Successor_Function of the problem to
create the corresponding new states
function Tree-Search (problem) returns a solution, or failure

List_toExplore ← Insert(Make-Node (Initial_State[problem]))

loop do
if List_toExplore is empty then return failure

node ← Remove(List_toExplore)

if Goal-Test(problem, State(node)) then return node

List_toExplore ←InsertAll(Expand(node, problem), List_toExplore)


EndLoop
function Expand( node, problem) returns a set of nodes

successors← 

for each action, result in Successor-Function(problem, State[node]) do

N← new Node
Parent [N] ← node;
Action[N]←action;
State[N]←result
Path_Cost[N]←Path-Cost[node] + Step_Cost(State[node], action, result)
Depth[N]←Depth[node] + 1
add N to successors

return successors
 A strategy is defined by picking the order of
node expansion

 Two types of exploration strategies

◦ Uninformed Explorations: Blind Search Methods

◦ Informed Explorations: Heuristic Search Methods


 Evaluation Criteria: search methods are evaluated
according to the following criteria:

Completeness: Does the method always find a solution if


one exists?
Complexity in time: How long does it take to find the
solution? ⇨ Number of expanded nodes
Complexity in space: Which memory size does it take to
perform the search? ⇨ Maximum Number of nodes in
memory
Optimality: Does the method always find the best
solution with the least cost?
 Time and space complexities are measured in terms
of:

◦ b = maximum branching factor of the search tree


◦ d = depth level of the best (or least cost) solution
node
◦ m = maximum depth level of the search space
(state space or search tree) → can be infinite
 Uninformed strategies use only the information
available in the problem definition

 Breadth-first search
 Depth-first search
 Depth-limited search
 Iterative deepening search
 Basic Idea: Priority to expand the least recently
(shallowest) generated nodes

 Implementation : List_toExplore is implemented as


a FIFO queue : new successor go at end
List_toExplore : A List_toExplore : B C

List_toExplore : C D E List_toExplore : D E F G

Expanding Order : A B C D E F G
 Complete ??
 Time ??
 Space ??
 Optimal ??
 Complete ? Yes (if b is finite)
 Time ?? 1 + b + b2 + b3 + … + bd = O(bd) (exp.
In d)
 Space ?? O(bd) (each expanded node must be
kept in memory)
 Optimal ?? Yes (if cost = 1 per step); not
optimal in general

⇨Space is the big problem;


 Apply the Breadth First strategy to the solve the
following problem

1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
1 2 3

8 6 Initial State
7 5 4
(0)

1 2 1 2 3 1 2 3
(1) 8 6 3 (2) 8 6 4 (3) 8 6

7 5 4 7 5 7 5 4

1 2 1 2 2 1 3 1 2 2 1 2 2
(4) 8 6 3 (5) 8 6 4 (6) 8 2 6 (7) 8 5 6 (8) 8 6

7 5 4 7 5 7 5 4 7 4 7 5 4

1 6 2 1 2 1 2 3

(9) 8 3 (10) 8 6 3 (11) 8 4 Goal State


7 5 4 7 5 4 7 6 5

57
 Basic Idea : Expand the deepest unexpanded
node
 Implementation: List_toExplore is LIFO queue,
i.e., put successors at front

Warning : for infinite cycles!


• The search space must be finite and non-cyclic

⇨ Already expanded nodes must be eliminated to


avoid cycles
……………..
 Nodes in this example are indicated according to
visit order
 Complete ??
 Time ??
 Space ??
 Optimal ??
 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


but if solutions are shallower, may be much faster
than breadth-first

 Space ?? O(bm), i.e., linear space!


 Optimal ?? No
⇨ Modest requirement for a memory space

 For instance : if b = 10, d = 12 and the space of


100 octets/node:
◦ Depth Search requires 12 Kbyte * 1010 !!!
◦ Breadth Search requires 111 Tera-byte
 Basic Idea : it corresponds to a depth-first search
with a depth limit l ,
⇨ i.e., nodes at depth l have no successors
 Recursive Implementation
 Complete ??
 Time ??
 Space ??
 Optimal ??
 Complete ?? Yes if L ≥ d
 Time ?? O(bL)
 Space ?? O(b * L)
 Optimal ?? No
 Apply the Depth Limited Search strategy to the
solve the following problem with L =3

1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
1 2 3

8 6 Initial State
7 5 4
(0)

1 2 1 2 3

(1) 8 6 3 (5) 8 6 4

7 5 4 7 5

1 2 1 2 2
(2) 8 6 3 6
(6) 8 4
7 5 4 7 5

1 6 2 1 2 2 3
(3) 1
8 3 (4) 8 6 3 (7) 8 4
7 5 4 7 5 4 7 6 5
Goal State
 Basic Idea :
The problem of Depth Limited Search is : How to define
the good value of L ?

Solution : Iterative Deepening : trying every value of L


from 0 with iterative increment

 Combine avantages of Breadth First Search and


Depth First Search
◦ optimal and complete as the Breadth First Search
◦ Economic in memory space as the Depth First Search
 This strategy is convenient for problems with

◦ Great search space


◦ Deepth of the solution is unknown
 Implementation
Visit Order :
 Complete ??
 Time ??
 Space ??
 Optimal ??
 Complete ?? Yes
 Time ?? (d+1)b0 + db1 + (d-1)b2 + … + bd =
O(bd)

 Space ?? O(b * d)

 Optimal ?? Yes if cost = 1 per step


⇨ Uninformed methods have practical limits in
terms of time and space to be applied for a wide
category of problems

 Informed or guided methods achieve better


performances in terms of :
◦ Space and/or
◦ Time

⇨The search is guided with a heuristic


 Basic Idea: use an evaluation function for each
node
◦ To estimate its promising level (or desirability)
◦ To Expand most promising unexpanded node

 Implementation: List_toExplore is a queue sorted


in decreasing order of desirability

 Special cases:
◦ greedy search
◦ A∗ search
 Use of a criterion to reorder any nodes to be
explored (instead of a LIFO or a FIFO list)

⇨ Heuristic

 A certain measure must be established to evaluate


the "promise" of a node.

⇨ Evaluation Function f
 The search is guided by the the best node
according to the evaluation function

 Centered on the node with the best


chance of reaching the goal
 A heurisctic function h is integrated in the
evaluation function f

 h(u) : heuristic that estimate the cost of moving


from one state u to the final state.

 h(n) = 0 if n is a goal state.

 This function defines order in the exploration


process
 Expand the states that seem closest to a goal
state, in order to achieve a solution more
quickly.

 In this case, f(n) = h(n)


 Assume the following configurations

1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
Initial State Final State
f(n)=h(n)
h ???

 h: number of misplaced tokens


1 2 3

Initial State 8 6 f(n)= h(n) = 3


7 5 4

1 2 1 2 3 1 2 3

8 6 3 8 6 4 8 6

7 5 4 7 5 (2) 7 5 4
(3)

f(n)= h(n) =4 f(n)= h(n) =2 f(n)= h(n) =3


1 2 2

8 6 4

7 5 f(n)= h(n) =1

1 2 3

Goal State 8 4 f(n)= h(n) =0


7 6 5
 Find the shortest path from the initial state to
the final goal.

 In this case, f(n) = h(n) + g(n)


Initial
I State
g*(n)

f*(n) n Node n
h*(n)
Goal
B State

f*(n) = g*(n) + h*(n)

⇨ f*(n) represents the ideal cost (best cost) of the path crossing a
node n to reach the goal
 g*(n): the cost of the best path already
crossed from the initial state to the state n

 The choice of g depends on the studied field

 Example : Puzzle
g(n) : the number of moved tokens
→ the length of path from the root to n
By using A* Algo. f(n)=g(n) +h(n)
with :
◦ g : number of moved tokens de jetons déplacés
◦ h: number of misplaced tokens

1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
Initial State Final State
1 2 3

Initial State 8 6 f(n)=(0+3)


7 5 4

1 2 1 2 3 1 2 3

8 6 3 8 6 4 8 6
(1+4) 7 5 4 7 5 (1+2) 7 5 4
(1+3)

1 2 2

8 6 4
(2+1)
7 5

1 2 3
(3+0)
Goal State 8 4

7 6 5
2 8 3 1 2 3
1 6 4 8 4
7 5 7 6 5
Initial Configuration Final Configuration

Path ???

91
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 925 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 935 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 945 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 955 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 965 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 975 6 5
puzzle with A* Algorithm 2 8 3
m(A) d(x)
1 6 4
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x) 1 4
m(E)
=3
1 8 4
m(F)
=3
1 4
m(G) d(x)
=4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 985 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 995 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 61005 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5

1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 61015 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5

8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5

1 2 3
m(L) d(x)
8 4
=1 =4

Final
7 6 5

State 1
8
2 3
4
m(M)
=0
1
7
2
8
3
4
m(N) d(x)
=2 =5
7 61025 6 5
 Assume a postman initially in the city of Arad in
Romania
 the goal is to attain Bucharest with the minimal
cost path
 The shortest path ???

 Greedy Search ?
 A* Algorithm ?
Romania Step Straight-line
Cost in Km distance to
Bucharest

You might also like