BIM309 AI Week5a
BIM309 AI Week5a
2024
Outline
§ Heuristic Search
1
22.10.2024
Informed Search
Basic Idea: Beyond the definition of the problem itself use domain knowledge!
we may have about the problem to guide the search
§ Are we getting close to the goal?
§ What if we know something about the search?
§ How should we include that knowledge?
§ In what form should it be expressed to be useful?
§ Use a heuristic function that estimates how close a state is to the goal
§ A heuristic is designed for a particular search problem
§ Problem specific (hence informed)
§ Example: Manhattan distance, Euclidean distance for pathing
§ A heuristic does NOT have to be perfect!
§ Example of informed search strategies:
1. Greedy best-first search
2. A* search
3. IDA*
2
22.10.2024
h1(n)
§ Evaluation function h(n) (heuristic)
goal h2(n)
§ h(n) = estimates the cost from n to the closest goal
§ Example: ℎ!"# (𝑛) = straight-line distance from n to Bucharest
3
22.10.2024
Example:
Greedy Best-First Search
(a) The initial state Nodes are labeled
with their h-values
Example:
Greedy Best-First Search
(b) After expanding Arad
4
22.10.2024
Example:
Greedy Best-First Search
(c) After expanding Sibiu
Example:
Greedy Best-First Search
(d) After expanding Fagaras
10
5
22.10.2024
11
A* Search g(n)
n
§ Minimize the total estimated solution cost h(n)
§ Use a heuristic, but consider the path cost for each node goal
§ Optimal if heuristic is admissible (tree search)/consistent (graph search)
§ Combines:
ü g(n): cost to reach node n
ü h(n): cost to get from n to the goal
ü f(n) = g(n) + h(n) ß Evaluation Function
g(n) gives the path cost from the start node to node n, and
h(n) is the estimated cost of the cheapest path from n to the goal, so
f(n) is the estimated cost of the cheapest solution through n
12
6
22.10.2024
A* Search
13
14
7
22.10.2024
16
393=140+253
17
8
22.10.2024
413=220+193
18
Example:
A* Search
(e) After expanding Fagaras
19
9
22.10.2024
417=317+100
20
Admissible Heuristics
21
10
22.10.2024
Admissible Heuristics
§ An admissible heuristic never overestimates the cost to reach the
goal, that is, it is optimistic
§ A heuristic h is admissible if
∀ 𝑛𝑜𝑑𝑒 𝑛, ℎ 𝑛 ≤ ℎ∗ (𝑛)
where 𝒉∗ is true cost to reach the goal from n
§ Example
ℎ"#$ (used as a heuristic in the map example) is admissible, because
it is by definition the shortest distance between two points
§ Never overestimates the actual road distance
22
A* Search Criteria
§ Complete Yes
§ Time exponential (depends on heuristic)
§ Space Keeps every node in memory (the biggest problem)
§ Optimal Yes
23
11
22.10.2024
§ 𝒉𝟏 (𝒏) = ??
§ 𝒉𝟐 (𝒏) = ??
24
§ 𝒉𝟏 (𝑺) = 8
§ 𝒉𝟐 (𝑺) = Tiles 1 to 8 in the start state gives:
𝒉𝟐 (𝑺) = 3+1+2+2+2+3+3+2 = 18
which does not overestimate the true solution
25
12
22.10.2024
27
DFS
28
13
22.10.2024
DFS
29
DFS
30
14
22.10.2024
DFS
31
DFS
32
15
22.10.2024
DFS
33
DFS
34
16
22.10.2024
DFS
35
DFS
36
17
22.10.2024
IDS
37
IDS
38
18
22.10.2024
IDS
39
IDS
40
19
22.10.2024
IDS
41
IDS
42
20
22.10.2024
IDS
43
IDS
44
21
22.10.2024
IDS
45
IDS
46
22
22.10.2024
IDS
47
IDS
48
23
22.10.2024
IDS
49
IDS
50
24
22.10.2024
BFS
51
BFS
52
25
22.10.2024
BFS
53
BFS
54
26
22.10.2024
BFS
55
BFS
56
27
22.10.2024
BFS
57
BFS
58
28
22.10.2024
BFS
59
BFS
60
29
22.10.2024
BFS
61
BFS
62
30
22.10.2024
BFS
63
UCS
64
31
22.10.2024
UCS
65
UCS
66
32
22.10.2024
UCS
67
UCS
68
33
22.10.2024
UCS
69
UCS
70
34
22.10.2024
UCS
71
UCS
72
35
22.10.2024
UCS
73
UCS
74
36
22.10.2024
UCS
75
UCS
76
37
22.10.2024
UCS
77
UCS
78
38
22.10.2024
Recap
We can organize the algorithms into pairs where the first proceeds by
layers, and the other proceeds by subtrees
79
Recap
Which cost function?
f = g + h
the path from the the estimated costs from
root to the node the node to the goal
80
39
22.10.2024
Summary
§ Before an agent can start searching for solutions, a goal must be identified
and a well-defined problem must be formulated
§ A problem consists of five parts:
§ the initial state
§ a set of actions
§ a transition model describing the results of those actions
§ a goal test function
§ a path cost function
§ The environment of the problem is represented by a state space
§ A path through the state space from the initial state to a goal state is a solution
§ Search algorithms treat states and actions as atomic: they do not consider
any internal structure they might possess
§ A general TREE-SEARCH algorithm considers all possible paths to find a
solution, whereas a GRAPH-SEARCH algorithm avoids consideration of
redundant paths
81
Summary
§ Search algorithms are judged on the basis of completeness, optimality, time
complexity, and space complexity
§ Complexity depends on b - the branching factor in the state space, and d - the depth of
the shallowest solution
§ Uninformed search methods have access only to the problem definition
§ Breadth-first search (BFS) expands the shallowest nodes first; it is complete, optimal
for unit step costs, but has exponential space complexity
§ Uniform-cost search (UCS) expands the node with lowest path cost, g(n), and is
optimal for general step costs
§ Depth-first search (DFS) expands the deepest unexpanded node first, neither
complete nor optimal, but has linear space complexity
§ Depth-limited search (DLS) adds a depth bound
§ Iterative deepening search (IDS) calls depth-first search with increasing depth limits
until a goal is found. It is complete, optimal for unit step costs, has time complexity
comparable to breadth-first search, and has linear space complexity
§ Bidirectional search can enormously reduce time complexity, but it is not always
applicable and may require too much space
82
40
22.10.2024
Summary
§ Informed search methods may have access to a heuristic function h(n)
that estimates the cost of a solution from n
§ The generic best-first search algorithm selects a node for expansion according
to an evaluation function
§ Greedy best-first search expands nodes with minimal h(n)
§ It is not optimal but is often efficient
§ A∗ search expands nodes with minimal f(n) = g(n) + h(n)
§ A∗ is complete and optimal, provided that h(n) is admissible (for TREE-SEARCH) or
consistent (for GRAPH-SEARCH)
§ The space complexity of A∗ is still prohibitive
§ The performance of heuristic search algorithms depends on the quality
of the heuristic function
83
41