2 Search2 EN
2 Search2 EN
Informed search
} Informed search
o Uses additional information from the problem to guide the search
o Uses a function 𝑓(𝑛) to evaluate the potential of node 𝑛, then
choose the best node to expand first
§ Best-first search
§ How to construct function 𝑓(𝑛)?
2 http://www.ptit.edu.vn
Outline
} Greedy search
} A* search
} Heuristic functions
} Iterative deepening A* (IDA*)
3 http://www.ptit.edu.vn
Example
4 http://www.ptit.edu.vn
Greedy search
} Principle: expand the node with the cheapest path to a
goal first
o 𝑓 𝑛 = ℎ(𝑛): heuristic function, estimated cost of the path from 𝑛
to a goal node
o Example: ℎ(𝑛) = straight-line distance from 𝑛 to a goal node
5 http://www.ptit.edu.vn
Example of greedy search (1/4)
S
125
6 http://www.ptit.edu.vn
Example of greedy search (2/4)
Expand S S
A B C E
123 82 118 72
7 http://www.ptit.edu.vn
Example of greedy search (3/4)
Expand S S
Expand E A B C E
123 82 118
D G
115 0
8 http://www.ptit.edu.vn
Example of greedy search (4/4)
Expand S S
Expand E A B C E
123 82 118
Expand G: Goal D G
115 0
9 http://www.ptit.edu.vn
Properties of greedy search
} Completeness?
o No (can have a loop, or have a branch of infinite nodes with small
value of function ℎ but do not lead to a goal)
} Optimality?
o No
} Time?
o 𝑂(𝑏 ! )
o If the heuristic function is good, the algorithm can be much faster
} Space?
o 𝑂(𝑏 ! ): store all nodes in the memory
o If the heuristic function is good, the number of nodes to store can be
reduced significantly
10 http://www.ptit.edu.vn
Exercise 1
} Use greedy search algorithm to find the path from 𝑆 to 𝐺?
11 http://www.ptit.edu.vn
Outline
} Greedy search
} A* search
} Heuristic functions
} Iterative deepening A* (IDA*)
12 http://www.ptit.edu.vn
A* search: idea
} Overcome the disadvantage of greedy search
o Greedy: only care about the path to the goal
o A*: also care about the path from the initial node to the current
node
§ avoid expanding paths that are already expensive
} Method: 𝑓 𝑛 = 𝑔 𝑛 + ℎ(𝑛)
o 𝑔 𝑛 : cost so far to reach 𝑛
o ℎ(𝑛): heuristic function, estimated cost from 𝑛 to a goal node
o 𝑓 𝑛 : estimated total cost of the path from the initial node,
through 𝑛, to a goal node
13 http://www.ptit.edu.vn
Example of A* search (1/5)
S
0+125=125
14 http://www.ptit.edu.vn
Example of A* search (2/5)
Expand S S
A B C E
55+123=178 42+82=124 48+118=166 72+72=144
15 http://www.ptit.edu.vn
Example of A* search (3/5)
Expand S S
Expand B A B C E
55+123=178 48+118=166 72+72=144
F
82+40=122
16 http://www.ptit.edu.vn
Example of A* search (4/5)
Expand S S
Expand B A B C E
55+123=178 48+118=166 72+72=144
Expand F F
G
137+0=137
17 http://www.ptit.edu.vn
Example of A* search (5/5)
Expand S S
Expand B A B C E
55+123=178 48+118=166 72+72=144
Expand F F
G
Expand G: Goal
137
18 http://www.ptit.edu.vn
A* search algorithm
𝐴 ∗ (𝑄, 𝑆, 𝐺, 𝑃, 𝑐, ℎ)
(𝑄: state space, 𝑆: initial state, 𝐺: goals, 𝑃: successor function, c: cost,
h: heuristic)
Input: search problem, heuristic function ℎ
Output: goal state (path to the goal state)
Initialize: 𝑂 ← 𝑆 (𝑂: the open node list)
while (𝑂 ≠ Ø) do
1. take node 𝑛 whose 𝑓(𝑛) is the smallest from 𝑂
2. if 𝑛 ∈ 𝐺, return (path to 𝑛)
3. for each 𝑚 ∈ 𝑃(𝑛)
a) 𝑔(𝑚) = 𝑔(𝑛) + 𝑐(𝑛, 𝑚)
b) 𝑓(𝑚) = 𝑔(𝑚) + ℎ(𝑚)
c) add 𝑚 along with 𝑓(𝑚) to 𝑂
return no solution
19 http://www.ptit.edu.vn
Properties of A* search
} Complete?
o Yes (unless there are infinite nodes 𝑛 with 𝑓(𝑛) ≤ 𝑓(𝐺))
} Optimality?
o Yes (if heuristic function ℎ is admissible)
} Time?
o 𝑂(𝑏 ! )
o If the heuristic function is good, the algorithm can be much faster
} Space?
o 𝑂(𝑏 ! ): store all nodes in the memory
o If the heuristic function is good, the number of nodes to store can be
reduced significantly
20 http://www.ptit.edu.vn
The optimality of A* search
} Admissible heuristic function
o For every node 𝑛, ℎ 𝑛 ≤ ℎ∗(𝑛), where ℎ∗(𝑛) is the true cheapest
cost from 𝑛 to a goal node
o Example: straight-line distance is an admissible heuristic function
21 http://www.ptit.edu.vn
Exercise 2
} Use A* search to find the path from 𝑆 to 𝐺?
22 http://www.ptit.edu.vn
Outline
} Greedy search
} A* search
} Heuristic functions
} Iterative deepening A* (IDA*)
23 http://www.ptit.edu.vn
Heuristic functions
} Heuristic functions are constructed depending on each
specific problem
o A problem may have some heuristic functions
o The quality of the heuristic function greatly affects the search
process
} Dominance
o If ℎ# (𝑛) and ℎ$ (𝑛) are 2 admissible heuristic functions satisfying
ℎ# (𝑛) ≤ ℎ$ (𝑛) for all nodes n, then ℎ$ dominates (is better than)
ℎ#
24 http://www.ptit.edu.vn
Example of heuristic functions
25 http://www.ptit.edu.vn
Outline
} Greedy search
} A* search
} Heuristic functions
} Iterative deepening A* (IDA*)
26 http://www.ptit.edu.vn
Iterative deepening A* – IDA*
} Goal: deals with the memory problem in A* search
o a variant of IDS (uses the heuristic function from A* search to
limit nodes)
27 http://www.ptit.edu.vn
IDA* algorithm
𝐼𝐷𝐴∗(𝑄, 𝑆, 𝐺, 𝑃, 𝑐, ℎ)
Input: search problem, heuristic function ℎ
Output: goal state (path to the goal state)
Initialize: 𝑂 ← 𝑆 (𝑂: the open node list)
Threshold 𝑖 ← 0
while (1) do
1. while (𝑂 ≠ ∅) do
a) Take the first node 𝑛 from 𝑂
b) if 𝑛 ∈ 𝐺, return (path to 𝑛)
c) For each 𝑚 ∈ 𝑃(𝑛)
i) 𝑔(𝑚) = 𝑔(𝑛) + 𝑐(𝑚, 𝑛)
ii) 𝑓(𝑚) = 𝑔(𝑚) + ℎ(𝑚)
iii) if 𝑓(𝑚) ≤ 𝑖 then add 𝑚 to the head of 𝑂
2. 𝑖 ¬ 𝑖 + b, 𝑂 ¬ 𝑆
28 http://www.ptit.edu.vn
Properties of IDA*
} Completeness?
o Yes
} Optimality?
o 𝛽-optimal (cost of the found solution does not exceed 𝛽 compared
to cost of the optimal solution)
} Time?
o Computational complexity is greater than that of A* search
} Space?
o Requires linear memory
29 http://www.ptit.edu.vn
Exercise 3
} Use IDA* search to find the path from 𝑆 to 𝐺 with 𝛽 = 2?
30 http://www.ptit.edu.vn
When to add repeated nodes
to the open node list?
} Greedy
o No: adding repeated nodes does not change the algorithm (may
lead to loops)
} A*
o In cases the repeated node has better cost, it will be added to the
list (if it is already expanded) or updated to replace the old node
(if it is on the list)
} IDA*:
o Yes
31 http://www.ptit.edu.vn