Uploaded by L ADITYA RAJ

AI MOD 2 FULL 4 IN 1 beta

advertisement
Solving Problems by Searching
Reflex agent is simple
base their actions on
 a direct mapping from states to actions
 but cannot work well in environments

Problem Solving by Searching
which this mapping would be too large to store
 and would take too long to learn

Hence, goal-based agent is used
Problem-solving agent
Problem-solving agent
A kind of goal-based agent
 It solves problem by



finding sequences of actions that lead to
desirable states (goals)
To solve a problem,

the first step is the goal formulation, based on
the current situation
Problem-solving agent
Intelligent agents are supposed to maximize
their performance measure or the agent can
adopt a goal and aim at satisfying it.
Goal formulation, based on the current
situation and the agent’s performance
measure, is the first step in problem solving.
Goal formulation
The goal is formulated

as a set of world states, in which the goal is
satisfied
Problem formulation
The process of deciding

Reaching from initial state  goal state

Actions are required
Actions are the operators
causing transitions between world states
 Actions should be abstract enough at a
certain degree, instead of very detailed
 E.g., turn left VS turn left 30 degree, etc.

E.g., driving Amman  Zarqa
in-between states and actions defined
 States: Some places in Amman & Zarqa
 Actions: Turn left, Turn right, go straight,
accelerate & brake, etc.

Search
Because there are many ways to achieve
the same goal
Those ways are together expressed as a tree
 Multiple options of unknown value at a point,


the agent can examine different possible
sequences of actions, and choose the best
This process of looking for the best sequence
of actions that reaches the goal is called
search
 The best sequence is then a list of actions,
called solution

what actions and states to consider for a
goal
Search algorithm
Defined as
taking a problem
 and returns a solution

Once a solution is found
the agent follows the solution
 and carries out the list of actions –
execution phase

Design of an agent

“Formulate, search, execute”
Well-defined problems and solutions
A problem is defined by 5 components:
Initial state
Actions
Transition model or
(Successor functions)
Goal Test.
Path Cost.
Well-defined problems and solutions
A problem can be defined formally by five components:
The initial state that the agent starts in.
A description of the possible actions available to the
agent.
A description of what each action does called transition
model.
 Together, the initial state, actions, and transition model
implicitly define the state space of the problem.
The goal test, which determines whether a given state is a
goal state.
A path cost function that assigns a numeric cost to
each path.
 The step cost of taking action a in state s to reach
state s’.
A solution to a problem is an action sequence that
leads from the initial state to a goal state.
Well-defined problems and solutions
Well-defined problems and solutions
The goal test

Applied to the current state to test

if the agent is in its goal
-Sometimes there is an explicit set of possible goal states.
-Sometimes the goal is described by the properties


instead of stating explicitly the set of states
Example: Chess


the agent wins if it can capture the KING of the opponent on
next move ( checkmate).
no matter what the opponent does
Well-defined problems and solutions
Together a problem is defined by





Initial state
Actions
Transition model
Goal test
Path cost function
The solution of a problem is then

a path from the initial state to a state satisfying the goal
test
Optimal solution

the solution with lowest path cost among all solutions
A path cost function,
assigns a numeric cost to each path
 = performance measure
 denoted by g
 to distinguish the best path from others

Usually the path cost is

the sum of the step costs of the individual
actions (in the action list)
Defining the problem as a State
Space Search
A Water Jug Problem
You are given two jugs, a 4-gallon one and a
3-gallon one. Neither has any measuring
markers on it. There is a pump that can be
used to fill the jugs with water. How can you
get exactly 2 gallons of water into the 4-gallon
jug?
Rules(Actions)
X represents the number of gallons of water in
the 4-gallon jug.
Y represents the number of gallons of water in
the 3-gallon jug.
X =0,1,2,3,4
Y=0,1,2,3
The start state is (0,0)
The goal state is (2,n)
9. (x,y) if(x+y≤4 and y>0) (x+y,0) Pour all the water from
3-g jug into the 4-g jug
10. (x,y) if(x+y ≤3 and x>0) (0,x+y) Pour all the water
from 4-g jug into the 3-g jug
11. (0,2) (2,0) Pour the 2-g from the 3-g jug into the 4-g
jug
12. (2,y) (0,y) Empty the 2-g in the 4-g jug
1. (x,y) if (x<4)
(4,y) Fill the 4-gallon jug
2. (x,y) if (y<3)
(x,3) Fill the 3-gallon jug
3. (x,y) if (x>0)
(x-d,y) Pour some water out of 4-g jug
4. (x,y) if (y>0)
(x,y-d) Pour some water out of 3-g jug
5. (x,y) if (x>0)
(0,y) Empty the 4-g jug
6. (x,y) if(y>0)
(x,0) Empty the 3-g jug
7. (x,y) if(x+y≥4 and y>0 (4,y-(4-x)) Pour water from the 3-g
jug into the 4-g jug until the 4-g jug is full
8. (x,y) if(x+y ≥3 and x>0 (x-(3-y),3) Pour water from the 4-g
jug into the 3-g jug until the 3-g jug is full
(4-g Jug ,3-g Jug)
(0,0)
(0,3)
(3,0)
(3,3)
(4,2)
(0,2)
(2,0)
Rules Applied
2
9
2
7 or 12
5 or 11
Formulating problems
Besides the five components for problem
formulation

anything else?
Abstraction



the process to take out the irrelevant information
The process of removing detail from a representation
Conclusion: Only the most important parts that are
contributing to searching are used.
Example: Romania
On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest
Formulate goal:

be in Bucharest

Formulate problem:


states: various cities
actions: drive between cities
Find solution:


sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest
Evaluation Criteria
formulation of a problem as search task
basic search strategies
important properties of search
strategies
selection of search strategies for
specific tasks
(The ordering of the nodes in FRINGE
defines the search strategy)
Example: Romania
Single-state problem formulation
A problem is defined by:
initial state e.g., "at Arad"
1. actions or successor function S(x) = set of action–state pairs


2.

the optimal solution has the lowest path cost
goal test, can be


3.
S(In(Arad)) =
{(Go(Sibiu),In(Sibiu)),(Go(Zerind),In(Zerind)),(Go(Timisoara),In(Ti
misoara))}
Initital state + successor function = state space
A solution is a sequence of actions leading from the
initial state to a goal state
explicit, e.g., x = "at Bucharest"
implicit, e.g., Checkmate(x)
path cost (assume additive)


e.g., sum of distances, number of actions executed, etc.
c(x,a,y) is the step cost, assumed to be ≥ 0
Problem-Solving Agents
A simple problem-solving agent. It first formulates a goal and a
problem, searches for a sequence of actions that would solve
the problem, and then executes the actions one at a time. When
this is complete, it formulates another goal and starts over.
Example problems
The problem-solving approach has been applied to a vast array
of task environments.
Some of the best known are listed here, distinguishing between
toy and real-world problems.
Toy problems
 those intended to illustrate or exercise various problemsolving methods
 E.g., puzzle, chess, etc.
Real-world problems
 tend to be more difficult and whose solutions people actually
care about
 E.g., Design, planning, etc.
Toy problems
State Space of the vacuum world
Example: vacuum world

The 8-queens
There are two ways to formulate the
problem
The 8-queens
Incremental formulation

Complete-state formulation
 Incremental formulation

All of them have the common followings:
Goal test: Place 8 queens on a chessboard,
not attacking each other.
 Path cost: zero

Number of states: 2X 22=8
Initial state: Any
Number of actions: 3
 left, right, suck
Goal: clean up all dirt
 Goal states: {7, 8}
Path Cost:
 Each step costs 1



States: n (0 to 8) queens on the board, one per column
in the n leftmost columns with no queen attacking any
other
Actions: Add queen in leftmost empty column such that
the queen is not attacking any other queen
2057 possible sequences to investigate; solutions are
easy to find
But with 100 queens the problem is much harder
The 8-queens
Complete-state formulation
States: Any arrangement of 0 to 8 queens on
the board
 Initial state: No queens
 Actions: Add queen to any empty square
 Goal test: 8 queens on board and none
attacked
 Path cost: N/A
 64.63.62…..57 ≈ 1.8 x 1014 possible
sequences to investigate

The 8-queens
Conclusion:

the right formulation makes a big difference
to the size of the search space
Searching for solutions
Searching for solutions
How do we find the solutions of previous
problems?
Search the state space
 State space can be represented by a
search tree
 Root of the tree is the initial state
 Children generated through successor
function
In general we may have a search graph
rather than tree (same state can be reached
through multiple paths)
Search tree
Example: Romania
Initial state

The root of the search tree is a search node
Expanding
applying successor function to the current state
 thereby generating a new set of states

leaf nodes
the states having no successors
Fringe : Set of search nodes that have not been
expanded yet.

Refer to next figure
Tree search example
(Expanding Arad)
Tree search example
(Expanding Arad)
Search tree
Search tree
The essence of searching
in case the first choice is not correct
 choosing one option and keep others for later
inspection

Hence we have the search strategy
which determines the choice of which state to
expand
 good choice  fewer work  faster

State space
has unique states {A, B}
 while a search tree may have cyclic paths:
A-B-A-B-A-B- …

A good search strategy should avoid
such paths
Important:

state space ≠ search tree
Search tree
A node is having five components:
STATE: which state it is in the state space
 PARENT-NODE: from which node it is generated
 ACTION: which action applied to its parent-node
to generate it
 PATH-COST: the cost, g(n), from initial state to
the node n itself
 DEPTH: number of steps along the path from the
initial state

State Space Vs. Search Tree
Measuring problem-solving performance
Measuring problem-solving performance
A search strategy is defined by picking the order of node expansion.
The evaluation of a search strategy
 Completeness:
 is the strategy guaranteed to find a solution when there is one?
 Optimality:
 does the strategy find the highest-quality solution when there
are several different solutions?
 Time complexity:
 how long does it take to find a solution?
 Space complexity:
 how much memory is needed to perform the search?
In AI, complexity (Time & Space) is expressed in
 b, branching factor, maximum number of successors of
any node
 d, the depth of the shallowest goal node.
(depth of the least-cost solution)
 m, the maximum length of any path in the state space
Time and Space is measured in
 number of nodes generated during the search
 maximum number of nodes stored in memory
Measuring problem-solving performance
For effectiveness of a search algorithm
we can just consider the total cost
 The total cost = path cost (g) of the solution
found + search cost


search cost = time necessary to find the solution
Tradeoff:
(long time, optimal solution with least g)
 vs. (shorter time, solution with slightly larger
path cost g)

Uninformed search strategies
Uninformed search (or Blind search)
no additional information about the states
 or the path cost from the current state to
the goal,
 search the state space blindly.

Informed search (or heuristic search)
a cleverer strategy that searches toward
the goal,
 based on the information from the current
state so far

Uninformed search strategies
Breadth-first search
Breadth-first search

Uniform cost search
Depth-first search
Depth-limited search
 Iterative deepening search

Bidirectional search
Breadth-first search
S
Breadth-first search
A
The root node is expanded first (FIFO)
All the nodes generated by the root
node are then expanded
And then their successors and so on
B
C
11
D
D
E
D F
14
G
19
A
E
B
F
C G
19 17
E
B
C
17
B
E
F
A C G
15 15 13
F
G 25
Breadth-First Strategy
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
New nodes are inserted at the end of FRINGE
1
1
2
4
FRINGE = (1)
3
5
6
7
2
4
FRINGE = (2, 3)
3
5
6
7
Breadth-First Strategy
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
New nodes are inserted at the end of FRINGE
1
1
2
4
FRINGE = (3, 4, 5)
3
5
6
7
2
4
FRINGE = (4, 5, 6, 7)
3
5
6
7
Breadth-first search (Analysis)
Properties of breadth-first search
Breadth-first search
 Completeness – find the solution eventually,
branching factor b is finite.
 Is Optimal, if the path cost is a non decreasing
function of the depth of the node.
The disadvantage
 if the branching factor of a node is large,
 for even small instances (e.g., chess)
 the space complexity and the time complexity
are enormous
Complete? Yes (if b is finite)
Time? b+b2+b3+… +bd + (bd+1-b) = O(bd+1)
Space? O(bd+1) (keeps every node in memory)
Optimal? Yes (if cost = 1 per step)
Space is the bigger problem (more than time)
Breadth-first search (Analysis)
Memory requirements are a bigger
problem than execution time.
Uniform cost search
Breadth-first finds the shallowest goal state
but not necessarily be the least-cost solution
 work only if all step costs are equal

Uniform cost search

Extension of breadth-first search


by always expanding the lowest-cost node
The lowest-cost node is measured by the path
cost g(n)
Uniform-cost search
Uniform cost search
the first found solution is guaranteed to be the cheapest
 least in depth
 But restrict to non-decreasing path cost
 Unsuitable for operators with negative cost
Expand least-cost unexpanded node
Implementation:
 fringe = queue ordered by path cost
Equivalent to breadth-first if step costs all equal
Depth-first search
Complete? Yes, if step cost ≥ ε
Time? # of nodes with g ≤ cost of optimal solution, O(bceiling(C*/ ε))
where C* is the cost of the optimal solution
Space? # of nodes with g ≤ cost of optimal solution, O(bceiling(C*/
ε))
Optimal? Yes – nodes expanded in increasing order of g(n)
Always expands one of the nodes at the
deepest level of the tree
Only when the search hits a dead end


let
C* be the cost of optimal solution.
ε is possitive constant (every action cost)
goes back and expands nodes at shallower levels
Dead end  leaf nodes but not the goal
Backtracking search



only one successor is generated on expansion
rather than all successors
fewer memory
Depth-first search
Expand deepest unexpanded node
Implementation:

fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:

fringe = LIFO queue, i.e., put successors at front

Depth-first search
Expand deepest unexpanded node
Implementation:

fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:

fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:

fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:

Depth-first search
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Expand deepest unexpanded node
Implementation:
Implementation:


fringe = LIFO queue, i.e., put successors at front


fringe = LIFO queue, i.e., put successors at front
Depth-first search
Depth-first search
Expand deepest unexpanded node
Expand deepest unexpanded node
Implementation:
Implementation:

fringe = LIFO queue, i.e., put successors at front


fringe = LIFO queue, i.e., put successors at front

Depth-first search
Depth-first search
Expand deepest unexpanded node
Expand deepest unexpanded node
Implementation:
Implementation:


fringe = LIFO queue, i.e., put successors at front


fringe = LIFO queue, i.e., put successors at front
Depth-first search
S
A
D
B
C
11
D
E
D F
14
G
19
A
E
B
F
C G
19 17
E
B
C
17
B
E
A
15
F
C G
15 13
F
G 25
Depth-first search (Analysis)
Not complete
because a path may be infinite or looping
 then the path will never fail and go back try
another option

Not optimal

it doesn't guarantee the best solution
It overcomes

the time and space complexities
Properties of depth-first search
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 dense, may be much faster
than breadth-first
Space? O(bm), i.e., linear space!
Optimal? No
Depth-limited search
Depth-Limited Strategy
Depth-first with depth cutoff k (maximal
depth below which nodes are not
expanded)
Three possible outcomes:
Solution
 Failure (no solution)
 Cutoff (no solution within cutoff)

It is depth-first search
with a predefined maximum depth
 However, it is usually not easy to define
the suitable maximum depth
 too small  no solution can be found
 too large  the same problems are
suffered from

Anyway the search is
complete
 but still not optimal

Depth-limited
search
S
depth = 3
A
3
D
6
B
C
11
D
E
D F
14
G
19
A
E
B
F
C G
19 17
E
B
C
17
B
E
F
A C G
15 15 13
F
G 25
Iterative deepening search
Iterative deepening search
No choosing of the best depth limit
It tries all possible depth limits:
first 0, then 1, 2, and so on
 combines the benefits of depth-first and
breadth-first search

Iterative deepening search
(Analysis)
optimal
complete
Time and space complexities

reasonable
suitable for the problem
having a large search space
 and the depth of the solution is not known

Properties of iterative deepening
search
Complete? Yes
Time? (d)b0 + (d-1)b1 + (d-2)b2 + … + bd
= O(bd)
Space? O(bd)
Optimal? Yes, if step cost = 1
Iterative lengthening search
IDS is using depth as limit
ILS is using path cost as limit
an iterative version for uniform cost search
has the advantages of uniform cost search



while avoiding its memory requirements
but ILS incurs substantial overhead

compared to uniform cost search
Bidirectional Strategy
Bidirectional search
Run two simultaneous searches
one forward from the initial state another
backward from the goal
 stop when the two searches meet

However, computing backward is difficult
A huge amount of goal states
 at the goal state, which actions are used to
compute it?
 can the actions be reversible to computer its
predecessors?

Bidirectional
search
S
A
2 fringe queues: FRINGE1 and FRINGE2
B
C
11
D
E
D F
14
Time and space complexity = O(bd/2) << O(bd)
D
G
19
A
E
B
F
C G
19 17
E
B
C
17
B
E
F
A C G
15 15 13
F
G 25
Forward
Backwards
Comparing search strategies
Avoiding repeated states
for all search strategies

There is possibility of expanding states

that have already been encountered and expanded
before, on some other path
may cause the path to be infinite  loop forever
 Algorithms that forget their history
Avoiding repeated states
Three ways to deal with this possibility

Do not return to the state it just came from




Do not create paths with cycles

are doomed to repeat it

Refuse generation of any successor same as its
parent state
Refuse generation of any successor same as its
ancestor states
Do not generate any generated state

Not only its ancestor states, but also all other
expanded states have to be checked against
Avoiding repeated states
We then define a data structure
closed list:
a set storing every expanded node so far
 If the current node matches a node on the
closed list, discard it.

Informed (Heuristic) Search Strategies
• An informed search strategy uses problem specific knowledge beyond
the definition of the problem itself and it can find solutions more efficiently
than can an uninformed strategy.
• Best-first search is an algorithm in which a node is selected for expansion
based on an evaluation
function, f(n).
• The evaluation function is construed as a cost estimate, so the node with
the lowest evaluation is expanded first.
• The implementation of best-first graph search is identical to that for
uniform-cost search except for
the use of evaluation function f
instead of lowest path cost g to order the
priority queue.
• The choice of evaluation function determines the search strategy.
• Most best-first algorithms include a heuristic function, h(n) as a
component of evaluation function.
Uniform-Cost Search: Review
Heuristic
• A heuristic function h(n) is the estimated cost of the cheapest path from
Function
the state at node n to a goal state.
• Heuristic functions are the most common form of additional knowledge
of the problem for
informed (heuristic) search algorithms.
• Heuristic functions are nonnegative, problem-specific functions, with one
constraint: if n is a goal node, then h(n)=0.
We have use
evaluation
function f(n)
instead of PATHCOST for Best-first
search.
• When we use a heuristic function to guide our search, we perform
informed (heuristic”) search.
• Some informed (heuristic) searches:
• Greedy best-first search
• A*
• Recursive best-first search (a memory-bounded heuristic search)
Heuristic Function
Example
line
• For route-finding problemsstraight
in Romania, we can
use thedistance
straight line
distance heuristic h .
heuristic
Heuristic Function Example
straight line distance heuristic
SLD
• If the goal is Bucharest, we need to know the straight-line distances
to Bucharest
• The values of hSLD cannot be computed from the problem description
itself.
• Since hSLD is correlated with actual road distances and it is a useful
heuristic.
hSLD(n) = straight-line distance from node n to Bucharest
Greedy best-first
• Greedy best-first search expands the node that is closest to the goal, on
search
the grounds that this is likely to lead to a solution
quickly.
Greedy search example
Node labels are hSLD values
Arad is the initial
state.
• Greedy search expands the node that appears to be closest to goal
• Greedy best-first search evaluates nodes by using just the heuristic
function.
• This means that it uses heuristic function h(n) as the evaluation function
f(n) ( that is f(n) = h(n) ).
• For Romania problem, the heuristic function
hSLD(n) = straight-line distance from n to Bucharest as evaluation function
Fronti
er
36
Arad
6
Explor
ed
Greedy search example
After expanding
Arad.
Frontier
Sibiu
253
Timisoa 329
ra
Zerind 374
Node labels are hSLD values
Expl
ored
Arad
Greedy search example
Frontier
Fagaras 17
6
Rimnicu 19
Vil
3
Timisoar 32
a
9
Zerind 37
4
Oradea 38
0
Greedy search example
After expanding
Fagaras.
Node labels are hSLD values
Comple
te?
Tim
e?
Space?
0
Explo
red
Arad
193
Sibiu
329
Fagar
as
Frontier
Buchare
st
Rimnicu
Vil
Timisoar
a
Zerind
Oradea
374
380
Node labels are hSLD values
After expanding
Sibiu.
Optimal?
Explor
ed
Arad
Sibiu
Properties of greedy
NO
It can get stuck in loops without
search
repeated-state checking Complete in finite space
with repeated-state checking
O(bm) where m is the maximum depth of the
search tree.
O(ba good
keeps
all nodes
memory
but
heuristic
caningive
dramatic
m)
improvement
NO nodes expanded in increasing order
of path cost
Optimal?
NO
Properties of greedy
the path via Sibiu and Fagaras to Bucharest is 32
kilometers longer than the path through
Rimnicu
search
Vilcea and Pitesti.
path found by greedy
search
A* Search
Minimizing
thethat
total
estimated
solution cost
Idea: Avoid expanding
paths
are already
expensive
Evaluation function f(n) = g(n) + h(n)
g(n) = cost so far to reach node n
h(n) = estimated cost to goal from node n
f(n) = estimated total cost of path through node n to goal
optimum path
• Since 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,
f(n) = estimated cost of the cheapest solution through n
• If heuristic function h(n) satisfies certain conditions, A∗ search is
both complete and optimal.
A* Search Example
Arad is the initial
state.
Node labels are f(n) = g(n) + hSLD(n)
A* Search Example
After expanding
Arad.
Frontier
Fronti
er
36
Arad
6
Explor
ed
Sibiu
393
Timisoa 447
ra
Zerind 449
Node labels are f(n) = g(n) + hSLD(n)
Expl
ored
Arad
A* Search Example
After expanding
Sibiu.
Frontier
Rimnicu
Vil
Fagaras
Timisoar
a
Zerind
Oradea
413
415
447
Node labels are f(n) = g(n) + hSLD(n)
Explo
red
Arad
Sibiu
449
671
A* Search Example
After expanding
Rimnicu Vilcea.
Fronti
er
Fagaras
Pitesti
Timisoa
ra
Zerind
Craiova
Oradea
415
417
447
Explor
ed
Arad
Sibiu
Rimnic
uVil
449
526
671
A* Search Example
After expanding
Fagaras.
Frontier
Pitesti
417
Timisoar 447
a
Zerind 449
Buchare 450
st
Craiova 526
Oradea 671
Node labels are f(n) = g(n) + hSLD(n)
Explor
ed
Arad
Sibiu
Rimnic
uVil
Fagaras
Node labels are f(n) = g(n) + hSLD(n)
A* Search Example
After expanding
Pitesti.
Fronti
Buchare
er
st
Timisoar
a
Zerind
450
418
447
Craiova
Oradea
526
671
449
Node labels are f(n) = g(n) + hSLD(n)
Explor
Arad
ed
Sibiu
Rimnic
uVil
Fagaras
Pitesti
A* Search Example
Node labels are f(n) = g(n) + hSLD(n)
Conditions for
Optimality:
Admissibility
and
• The first condition forConsistency
optimality is that heuristic function h(n) must be an
admissible heuristic.
• An admissible heuristic is one that never overestimates the cost to
reach the goal (optimistic).
• A heuristic h(n) is admissible if for every node n, h(n)≤ C(n) where
C(n) is the true cost to reach
the goal state from the state of node n.
Path found by A*: Arad, Sibiu, Rimnicu Vilcea,
Pitesti, Bucharest A* Path Cost: 140+80+97+101
= 418
Optimum Path Cost: 418 A* finds an optimum
path.
• Straight-line distance heuristic hSLD(n) is admissible because the shortest
path between any two points is a straight line. hSLD(n) never overestimates
actual distance.
• If h(n) is admissible, f(n) never overestimates the cost to reach the goal
because f(n)=g(n)+h(n) and g(n) is the actual cost to reach node n.
• A heuristic h(n) is consistent if, for every node n and every successor n′ of
n generated by any action a, the estimated cost of reaching the goal from n
is no greater than the step cost of getting to n′ plus the estimated cost of
reaching the goal from n′:
h(n) ≤ c(n, a, n′) + h(n′)
• h
(n) is consistent.
•
Optimality of A*
• If h(n) is consistent (h(n) ≤ c(n, a, n′) + h(n′)),
(proof)
then the values of f(n) along any path are non-decreasing.
• The proof follows directly from the definition of consistency.
• Suppose n′ is a successor of n; then g(n′)=g(n) + c(n, a, n′) for some action a,
and we have
f(n′) = g(n′) + h(n′) = g(n) + c(n, a, n′) + h(n′) ≥ g(n) + h(n) = f(n) .
• Whenever A∗ selects a node n for expansion, the optimal path to that
node has been found.
• If this is not the case, there would have to be another frontier node n′ on the
optimal path from the start node to n, because f is non-decreasing along any
path, n′ would have lower f-cost than n and would have been selected first.
• From these two preceding observations, it follows that the sequence of
nodes expanded by A∗ is in non-decreasing order of f(n).
• Hence, the first goal node selected for expansion must be an optimal
solution because f is the
true cost for goal nodes (h(Goal)=0) and all later goal nodes will be at
Optimality of A*
• A* expands nodes in order of increasing f value. Gradually adds fcontours of nodes. Contour i has all nodes with f = fi, where fi < fi+1
Comple
te?
Time?
Recursive best-first
search
Properties of A*
YES
unless there are infinitely many nodes
with f ≤f(Goal)
Exponential (depends on h(n))
Space?
O(bm) keeps all nodes in memory
Optimal?
YES
A* cannot expand fi+1
until fi is finished.
• A* expands all nodes with f(n) < C* where C* is
the optimal cost
• A* expands some nodes with f(n) = C*
Memory-bounded heuristic search
•
Recursive best-first search (RBFS) is a
simple recursive algorithm that attempts
to mimic the operation of standard bestfirst search, but using only linear space.
• Its structure is similar to that of a recursive
depth-first search, but rather than
continuing indefinitely down the current
path, it uses the f-limit variable to keep
track of the f-value of the best alternative
path available from any ancestor of the
current node.
• A* expands no nodes with f(n) > C*
Recursive best-first search
•
If the current node exceeds this limit, the
recursion unwinds back to the
alternative path.
• As the recursion unwinds, RBFS
replaces the f-value of each node along
the path with a backed-up value (the
best f-value of its children).
• In this way, RBFS remembers the fvalue of the best leaf in the forgotten
subtree and can therefore decide
whether it’s worth
Stages in an RBFS search
for the shortest route to
Bucharest.
Arad will be
Stages in an RBFS search
for the shortest route to
Bucharest.
Sibiu will be
expanded.
expanded
Stages in an RBFS search
for the shortest route to
Bucharest.
Rimnicu Vilcea will be
Stages in an RBFS search
for the shortest route to
Bucharest.
Unwind to
expanded
Sibiu.
Stages in an RBFS search
for the shortest route to
Bucharest.
After unwinding to Sibiu. Fagaras will
Stages in an RBFS search
for the shortest route to
Bucharest.
Unwind to Sibiu
be expanded
again.
Stages in an RBFS search
for the shortest route to
Bucharest.
After Unwinding to Sibiu again. Rimnicu Vilcea will
Stages in an RBFS search
for the shortest route to
Bucharest.
Pitesti will be
be re-expanded.
expanded.
Stages in an RBFS search
for the shortest route to
Bucharest.
After expanding Pitesti, the best successor is Bucharest. RBFS will be called with
Bucharest and Goal is reached.
Heuristic
• The 8-puzzle was one of the earliest heuristic search problems.
Functions
• The average solution cost for a randomly generated 8-puzzle
instance is about 22 steps.
• The branching factor is about 3.
• in the middle four moves
• in a corner  two moves
• along an edge  three moves
• A search algorithm may look at 170,000 states to solve a random 8puzzle instance, because
9!/2=181,400 distinct states are reachable.
• A search algorithm may look at 1013 s.tates to solve a random 15puzzle instance
 We need a good heuristic function.
 If we want to find the shortest solutions by using A∗,
we need a heuristic function that never overestimates the number of
Heuristic
• A typical instance of the 8-puzzle. The solution
Functions
is 26 steps long.
Two admissible heuristics for 8-puzzle.
h1(n) = number of misplaced tiles
Heuristic
Functions
• h1 is an admissible heuristic because any tile that is out of place must be
moved at least once.
h2(n) = total Manhattan distance (the sum of the distances of the tiles
from their goal positions)
• Because tiles cannot move along diagonals, the distance is the sum of the
horizontal and vertical distances.
• h2 is also admissible because all any move can do is move one tile one step
closer to the goal.
h1(start) = 8
h2(start) = 3+1+2+2+2+3+3+2 = 18
summation Manhattan
Distances of tiles 1 to 8
The effect of heuristic
• The quality of a heuristic can be measured by its effective branching
accuracy on performance
factor b∗.
• If the total number of nodes generated by A∗ for a particular problem is N
and the solution depth is d, then b∗ is the branching factor that a uniform
tree of depth d would have to have in order to contain N + 1 nodes.
The effect of heuristic
• To test the heuristic functions h1 and h2, 1200 random problems are
on2 toperformance
generated accuracy
with solution lengths from
24 (100 for each even number)
and solved with iterative deepening search and with A∗ tree search using
both h1 and h2.
• The results suggest that h2 is better than h1, and it is far better than using
iterative deepening search.
• If A∗ finds a solution at depth 5 using 52 nodes, then the effective
branching factor is 1.92.
• Experimental measurements of b∗ on a small set of problems can
provide a good guide to the
heuristic’s overall usefulness.
• A well-designed heuristic would have a value of b∗ close to 1.
Dominance
If h2(n) ≥ h1(n) for all n (both h1 and h2
are admissible) then h2 dominates h1 and
h2 is better than h1 for search.
• Domination translates directly into
efficiency.
• A∗ using h2 will never expand more
nodes than A∗ using h1.
• It is generally better to use a heuristic
function with higher values, provided it is
consistent.
•
Generating Admissible
Heuristics from Relaxed
• h1 (misplaced tiles) and h2 (Manhattan distance) are fairly good heuristics
for the 8-puzzle and that h2 is better.
Problems
• A problem with fewer restrictions on the actions is called a relaxed
problem.
• Admissible heuristics can be derived from the exact solution cost of a
relaxed version of the problem.
• If the rules of the 8-puzzle are relaxed so that a tile can move anywhere,
then h1(n) gives the shortest solution.
• If the rules are relaxed so that a tile can move to any adjacent square, then
h2(n) gives the shortest
solution.
• Key point: the optimal solution cost of a relaxed problem is no greater than
the optimal solution cost
of the real problem
Summary
• Heuristic functions estimate costs of shortest paths
• Good heuristics can dramatically reduce search cost
• Greedy best-first search expands lowest h
• incomplete and not always optimal
• A* search expands lowest g + h
• complete and optimal
• also optimally efficient
• Admissible heuristics can be derived from exact solution
of relaxed problems
Download