Chapter 3 - Problem Solving by Searching(II)
Chapter 3 - Problem Solving by Searching(II)
1
Informed search algorithms
• We now consider informed search that uses problem-specific
knowledge beyond the definition of the problem itself
• This information helps to find solutions more efficiently than an
uninformed strategy
• An evaluation function f(n) determines how promising a node n
in the search tree appears to be for the task of reaching the goal
• Informed search is a strategy that uses information about the cost
that may incur to achieve the goal state from the current state.
• The information may not be accurate. But it will help the agent to
make better decision
• This information is called heuristic information
2
A key component of an evaluation function is a heuristic
function h(n), which estimates the cost of the cheapest
path from node n to a goal node
In connection of a search problem “heuristics” refers to a
certain (but loose) upper or lower bound for the cost of the
best solution
Goal states are nevertheless identified: in a corresponding
node n it is required that h(n) = 0 (i.e., if n is a goal node,
then h(n)=0)
E.g., a certain lower bound - bringing no information-
would be to set
Heuristic functions are the most common form in which
additional knowledge is imparted to the search algorithm
3
Blind search strategies rely only on exact
information (initial state, operators, goal
predicate)
They don’t make use of additional
information about the nature of the
problem that might make the search more
efficient
If we have a (vague) idea in which direction to
look for the solution, why not use this
information to improve
the search?
4
Heuristics - rules about the nature of the problem, which
are grounded in experience and whose purpose is to direct
the search towards the goal so that it becomes more
efficient
Heuristic function h : S R+ assigns to each state an
estimate of the distance between that state and the goal
state
The smaller the value h(s), the closer is s to the goal state.
If s is the goal state, then h(s) = 0
Search strategies that use heuristics to narrow down the
search are called heuristic (informed, directed) search
strategies
5
Informed Search
• There several algorithms that belongs to this group. Some of
these are:
– Best-first search
1. Greedy best-first search
2. A* search
• Best-first search is an instance of the general TREE-SEARCH
or GRAPH-SEARCH algorithm in which a node is selected for
expansion based on an evaluation function, f (n).
• Traditionally, the node with the lowest evaluation is selected
for expansion, because the evaluation measures distance to the
goal
• Best-first search can be implemented within our general search
framework via a priority queue, a data structure that will
maintain the fringe in ascending order of f values
6
Best-first search
Idea: use an evaluation function f(n) for each node
Estimate of "desirability“ using heuristic and path cost
Expand most desirable unexpanded node
The information gives a clue about which node to be expanded
first
This will be done during queuing
The best node according to the evaluation function may not be
best
Implementation:
Order the nodes in fringe in decreasing order of desirability (increasing
order of cost evaluation function)
7
Straight Line distance to
Ethiopia Map with step costs in km Gondar
Aksum
100 Gondar 0
Mekele
200 Aksum 100
Gondar 80
180
Lalibela Mekele 150
110 250
150 Lalibela 110
Bahr dar
Dessie
Desseie 210
170 Bahrdar 90
Debre markos 330
Dire Dawa Debre Markos 170
230 Addis Ababa 321
Jima
330
400
Jima 300
Addis Ababa
430
100
370
Diredawa 350
Nazarez
Nazarez 340
Gambela 230 320 Nekemt
Gambela 410
Awasa 500
Awasa
Nekemt 420
8
Note that, hSLD cannot be computed from the problem
description itself. It takes a certain amount of experience
to know that it is correlated with actual road distances, and
therefore it is a useful heuristic
9
Greedy best-first search
Tries to expand the node that is closest to the goal, on the grounds that this is
likely to lead to a solution quickly
it evaluates nodes by using just the heuristic function: f ( n )= h(n) (heuristic)
= estimate of cost from n to goal
That means the agent prefers to choose the action which is assumed to be best
after every action
e.g., h (n) = straight-line distance from n to Gonder
SLD
Greedy best-first search expands the node that appears to be closest to goal (It
tries to minimizes the estimated cost to reach the goal). disregarding the
total path cost accumulated so far.
Greedy best-first search resembles depth-first search in the way it prefers to
follow a single path all the way to the goal, but will back up when it hits a dead
end
The chosen path may not be optimal, but the algorithm doesn’t backtrack to
correct this. Hence, a greedy algorithm is not optimal.
10
Greedy best-first search example
Show the flow to move from Awasa to Gondar using
the given road map graph
11
Open list
The open list (also: frontier) organizes the leaves of a
search tree.
set of nodes that are currently candidates for expansion
It must support two operations efficiently:
determine and remove the next node to expand
insert a new node that is a candidate node for expansion
Some implementations support modifying an open list
entry when a shorter path to the corresponding state is
found.
Methods of an open list
open.is empty() test if the open list is empty
open.pop() removes and returns the next node to expand
12
open.insert(n) inserts node n into the open list
Closed list
The closed list remembers expanded states to avoid
duplicated expansions of the same state.
set of already expanded nodes (and their states)
It must support two operations efficiently:
insert a node whose state is not yet in the closed list
test if a node with a given state is in the closed list; if yes,
return it
Methods of a closed list
closed.insert(n) insert node n into closed; if a node with this
state already exists in closed, replace it
closed.lookup(s) test if a node with state s exists in the closed
list; if yes, return it; otherwise, return none
13
Example Two: Greedy best-first search example
Given the following tree structure, Heuristic
show the content of the open list R G -------------- 100
and closed list generated by A G -------------- 60
Greedy best first search algorithm B G -------------- 80
C G -------------- 70
D G -------------- 65
R
E G -------------- 40
A B C
F G -------------- 45
H G ---------------10
G1 G2
I G ---------------- 20
D E F H
J G ---------------- 8
G1,G2,G3 G ------------ 0
I G3 J
14
Properties of greedy best-first search
Complete? Yes if repetition is controlled otherwise it can get
stuck in loops
Time? O(bm), but a good heuristic can give dramatic improvement
Space? O(bm), keeps all nodes in memory
Optimal? No
15
A* search
Idea: avoid expanding paths that are already expensive
Evaluation function f(n) = g(n) + h(n) where
g(n) = cost so far to reach n, gives the path cost from the start node to
node n
h(n) = estimated cost from n to goal
f(n) = estimated total cost of path through n to goal
It tries to minimizes the total path cost to reach into the goal at every
node N.
the algorithm combines best-first and uniform cost search
Path costs are updated when nodes are expanded (similarly as with
uniform cost search)
Example one
Indicate the flow of search to move from Awasa to Gondar using A*
16
17
Example Two
18
Condition for optimality: Admissible
A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n) , where h*(n) is the true cost to reach the goal state
from n.
An admissible heuristic never overestimates the cost to reach the
goal, i.e., it is optimistic
Admissible heuristics are by nature optimistic because they think
the cost of solving the problem is less than it actually is
Example: hSLD(n) (never overestimates the actual road distance)
because the shortest path between any two points is a straight
line, so the straight line cannot be an overestimate
Theorem: If h(n) is admissible, A* using TREE-SEARCH is optimal
19
Optimality of A* (proof)
Suppose some suboptimal goal G2 has been generated and is in the fringe.
Let n be an unexpanded node in the fringe such that n is on a shortest path to
an optimal goal G but not on the path to G2.
We want to prove that the algorithm chooses to expand n than going to the
suboptimal direction.
If G2 is suboptimal, it should satisfy
g(G2) ≥ f* where f* is the optimal path cost
Assume n is not chosen for expansion before G2
f(n) ≥ f(G2) Since h is admissible
h*(n) ≥ h(n) h*(n) + g(n) ≥ h(n) + g(n)
f* ≥ f(n)
Combining the two gives
f* ≥ f(G2)
Since G2 is a goal state we have h(G2) = 0
f(G2) = h(G2) + g(G2) = g(G2)
f* ≥ g(G2)
This shows a contradiction with the initial assumption
Therefore, A* will never select G2 for expansion
20
Find Admissible heuristics for the 8-puzzle?
h1(S) = ?
h2(S) = ?
21
Admissible heuristics
E.g., for the 8-puzzle:
h (n) = number of misplaced tiles
1
h (n) = total Manhattan distance (i.e., no. of squares from desired location of each tile)
2
h (S) = ? 8
1
h (S) = ? 3+1+2+2+2+3+3+2 = 18 (Tiles 1 to 8 in the start state give a Manhattan distance)
2
As we would hope, neither of these overestimates the true solution cost, which is
26
• Dominance
– If h2(n) ≥ h1(n) for all n (both admissible)
– then h2 dominates h1
– h2 is better for search
– it is always better to use a heuristic function with higher values, provided it
does not overestimate and that the computation time for the heuristic is not
22too large.
Domination property
23
Properties of A*
Complete? Yes (unless there are infinitely many nodes
with f ≤ f(G) )
Optimal? Yes (provided that the heuristic is admissible)
Time?
In the best case (if the heuristic is the same as the actual cost), it is
equivalent to the depth of the solution node (i.e. it is linear). O(d)
In the worst case, it is equivalent to the number of nodes which has
f-value ≤ f-value of the solution node O(bceiling(C*/ ε)) where C* is the
f value of the solution node
This shows, A* search is computationally efficient compared to
Greedy best first search strategy
24
Properties of A*
Space? Keeps all nodes in memory (exponential)
i.e. O(bm)
This is again a limitation in the same way as we saw while
discussing Greedy, Breadth and Depth first search
Hence, it is advisable to have modified version of such
algorithm in which the modification minimizes the space
complexity
There are two such modifications
1. Iterative deepening A* (IDA*) search
2. Simplified Memory Bound A* (SMA*) search
25
Game playing (Adversarial Search)
• Outlines
– How to make optimal decisions in two player game
– MinMax algorithm
– α-β pruning algorithm
• In Game theory there are always at least two agents that participate.
• There may be different groups that participate in game where each of
them go for win or maximize the objective
• In this topic, we focus on only two player game:
– Player1 wants to maximize his objective function at the end of the
game
– Player2 (opponent): wants to minimize player1 objective function
26
Game playing (Adversarial Search)
• Opponent always introduce uncertainty because one never
knows what action the opponent may choose
• This unpredictable nature of game playing makes it different
from search problem.
• In most cases, game playing has very large branching factor
which will have a direct impact on the implementation time and
space complexity
• Example: Tic-Tac-Toe
27
Game tree (2-player, deterministic, turns)
28
Game Components
Initial state (environment + whose turn to move)
Operators (defines legal move to the agent)
Terminal test which determines when the galme is over. States
where the game has ended are called terminal states.
Utility function (payoff function) which gives a numeric value for the
terminal states
Minimax Algorithm
Perfect play for deterministic games
Idea: choose move to position with highest Minimax value
= best achievable payoff against best play
E.g., 2-ply game:
The algorithm consists of five steps
1. Generate the whole tree
2. Apply the utility function to each terminal state to get its value
3. Determine the utility of upper state using the lower states
4. Continue upward until the root
5. Max should choose the best play
29
Minimax algorithm
31
α-β pruning
Alpha (α ) minimal score that player MAX is guaranteed to
attain.
Beta (β ) maximum score that player MAX can hope to obtain
against a sensible opponent.
32
α-β pruning algorithm description
Case one: pruning via calling MIN function
Consider M is a node for MAX and it has guaranteed α using all the
paths to the left of P1 and assume the utility of N i for i < K is greater
than α. However utility of Nk < α. This shows if MAX choose to apply
action P1, then MIN will choose P2 that minimizes MAX utility which
MAX don’t want at all. Therefore the moment this situation happen, no
need to investigate all the sub trees with roots N i where k < i <= m
MAX Node
M
P1
MIN Nodes
P2
MAX Nodes N1 Nk Nm
33
α-β pruning algorithm description
Case two: pruning via calling MAX function
Consider M is a node for MIN and it knows that MAX could obtain
using all the paths to the left of P1 and assume the utility of N i for i< K is
less than . However utility of Nk > . This shows if MIN choose to apply
action P1, then MAX will choose P2 that maximizes MAX utility which
MIN don’t want at all. Therefore the moment this situation happen, no
need to investigate all the sub trees with roots N i where k < i <= m
MIN Node
M
P1
MAX
Nodes
P2
MIN Nodes N1 Nk Nm
34
Example:
Show the utility of each of nodes and prune unnecessary nodes using α-β pruning
algorithm for the following state space tree
3 4
4
7 6 9 30 12 -10 0
25
35
The α-β algorithm
36
The α-β algorithm
37
b =∞
= -∞
b =∞ 3 4
4
= 3
b=3
7 6 9 25 30 12 -10 0
= ∞
3 4
4
7 6 9 25 30 12 -10 0
38
b =∞
= 3
b=3
b =∞
= ∞
= 3
b =∞
3 4 = 7
4
b=
b=3 ∞ 7 6 9 25 30 12 -10 0
= 3 b=
= ∞
7
= 3
3 4
4
7 6 9 25 30 12 -10 0
39
b =∞
= 3
b=3
= ∞ b =7
= 3
3 4
4
b =∞
7 6 9 25 30 12 -10 0
= 7
b=3 b =7
= ∞ b =7 = 3
= 3 V=9
3 4
4
7 6 9 25 30 12 -10 0
40
b =∞ b =∞
b=3 = 7 = 7
= ∞ b =7 V=4
= 3
3 4
4
7 6 9 25 30 12 -10 0
41
Properties of α-β
Pruning does not affect final result
Good move ordering improves effectiveness of pruning
With "perfect ordering," time complexity = O(bm/2)
doubles depth of search
Why is it called α-β?
α is the value of the best (i.e., highest-value) choice found so far
at any choice point along the path for max
If v is worse than α, max will avoid it
prune that branch
Define β similarly for min
42