Lecture 7&8_Ins
Lecture 7&8_Ins
Chapter_3
Solving Problems By
Searching
3
3
Heuristics
4
Heuristics
Extra information used by the searching algorithm beside problem definition.
Heuristic is an estimated cost to goal node
Recall, heuristic is not actual cost it is just an expectation (optimistic)
With knowledge, one can search the state space as if he was given “hints”
when exploring a maze.
Heuristic information in search = Hints
Leads to dramatic speed up in efficiency.
5
Informed Search
It relies on additional knowledge about the problem or domain
frequently expressed through heuristics .
It is used to distinguish more promising paths towards a goal may be
mislead, depending on the quality of the heuristic
In general, it performs much better than uninformed search.
A search strategy which searches the most promising branches of the
state-space first can:
Find a solution more quickly,
Find solutions even when there is limited time available,
Often find a better solution, since more profitable parts of the state-
space can be examined, while ignoring the unprofitable parts.
A search strategy which is better than another at identifying the most
promising branches of a search-space is said to be more informed.
6
Note
Start State
Goal State
Thus
9
Heuristics, The 8-puzzle: example
Function h(N) that estimate the cost of the cheapest path from node N to
goal node.
1
0
10
Heuristics, The 8-puzzle: example
Function h(N) that estimate the cost of the cheapest path from node N to
goal node.
Best-first search.
Greedy best-first search.
A* search.
IDA* Search
1
2
Greedy best-first
search
Best first search - Greedy search
1
4
Greedy search - example
1
5
15
Greedy search - example
1
6
16
Greedy search - example
1
7
17
Greedy search - - example
Goal is found!
1
8
18
Greedy search - example
Complete? No
2
0
20
Greedy search Evaluation
Optimal? No
2
1
Informed search algorithms
Best-first search.
Greedy best-first search.
A* search.
IDA* Search
2
2
A* search
A* search
2
2 4
4
A*search, example
Open queue:
Arad
Find Bucharest starting at Arad
f(Arad) = g(??,Arad)+h(Arad)=0+366=366
2
5
25
A*search - example
Open queue:
Sibiu, Timisoara, Zerind
Expand Arrad and determine f(n) for each node
f(Sibiu)=g(Arad,Sibiu)+h(Sibiu)=140+253=393
f(Timisoara)=g(Arad,Timisoara)+h(Timisoara)=118+329=447
f(Zerind)=g(Arad,Zerind)+h(Zerind)=75+374=449
Open queue:
Rimricu Vicea, Fagaras, Timisoara, Zerind, Arad, Oradea
Expand Sibiu and determine f(n) for each node
f(Arad)=g(Sibiu,Arad)+h(Arad)=280+366=646
f(Fagaras)=g(Sibiu,Fagaras)+h(Fagaras)=239+179=415
f(Oradea)=g(Sibiu,Oradea)+h(Oradea)=291+380=671
f(Rimnicu Vilcea)=g(Sibiu,Rimnicu Vilcea)+ h(Rimnicu
Vilcea) =220+192=413
Best choice is Rimnicu Vilcea; As it is at the top of the
open queue 2
7
27
A*search, example
Open queue:
Fagaras, Pitesti, Timisoara, Zerind, Craiova, Sibiu, Arad,
Oradea
Expand Sibiu and determine f(n) for each node
f(Arad)=g(Sibiu,Arad)+h(Arad)=280+366=646
f(Fagaras)=g(Sibiu,Fagaras)+h(Fagaras)=239+179=415
f(Oradea)=g(Sibiu,Oradea)+h(Oradea)=291+380=671
f(Pitesti)=417 , f(Sibiu)=553 , f(Craiova)=526 ,
Open queue:
Pitesti, Timisoara, Zerind, Bucharest, Craiova,Sibiu,
Sibiu,Arad, Oradea
Expand Fagaras and determine f(n) for each node
f(Sibiu)=g(Fagaras, Sibiu)+h(Sibiu)=338+253=591
f(Bucharest)=g(Fagaras,Bucharest)+h(Bucharest)=
450+0=450
Best choice is Pitesti !!! 2
9
Open queue:
Bucharest, Timisoara, Zerind, Bucharest, Craiova, Rimricu
Vicea, Sibiu, Sibiu, Craiova, Arad, Oradea
Expand Pitesti and determine f(n) for each node
f(Bucharest)=g(Pitesti,Bucharest)+h(Bucharest)=418+0
=418
Best choice is Bucharest !!! , as it is at the top of the open
queue… 3
0
Goal is found!
A*search, example
Open queue:
Bucharest, Timisoara, Zerind, Bucharest, Craiova, Rimricu
Vicea, Sibiu, Sibiu, Craiova, Arad, Oradea
Now we “expand” the node for Bucharest.
We’re done! (And we know the path that we’ve found is optimal.)
Time? Exponential
Number of nodes expanded is still exponential in the length of the solution.
3
2
Heuristics Properties - Admissible
Heuristic function should be admissible in order to find optimum solutions
A heuristic h(n) is admissible if for every node n, h(n) ≤ h*(n), where h*(n) is
the true (actual) cost to reach the goal state from n
Heuristic is said to be admissible:-
If it is no more than the actual cost to reach the goal.
If it never overestimates the cost of reaching the goal.
An admissible heuristic is also known as an optimistic heuristic if :
n is a node,
h is a heuristic,
h(n) is cost indicated by h to reach a goal from n
h * (n) is the actual cost to reach a goal from n,
h is admissible if h(n) ≤ h*(n).
3
4
8-Puzzle
f(N) = h(N) = number of misplaced tiles
3 3 4
5 3
4
2
4 2 1
3 3
0
4
5 4
3
5
8-Puzzle
f(N) = g(N) + h(N)
with h(N) = number of misplaced tiles
3+3
1+5 2+3
3+4
5+2
0+4 3+2 4+1
1+3 2+3
5+0
3+4
1+5 2+4
3
6
8-Puzzle
f(N) = h(N) = distances of tiles to goal
6 5
2
5 2 1
4 3
0
4
6 5
3
7
Informed search algorithms
Best-first search.
Greedy best-first search.
A* search.
IDA* Search
3
8
IDA* Search
Problem with A* search
You have to record all the nodes
In case you have to back up from a dead-end
A* searches often run out of memory, not time
Iterative deepening:
Repeat depth-first search within increasing depth limit
IDA*:
Repeat depth-first search within increasing f-limit
3
9
IDA* Search steps
f(n) is the estimate of total path cost for start to goal.
Use the same iterative deepening trick as IDS.
But iterate over f(n) rather than depth
Impose a limit on f
Define contours: f < 100, f < 200, f < 300 etc.
Use DFS to search within the f limit
Iteratively relax the limit
Greatly reduces memory usage.
• Find all nodes
Where f(n) < 100
Ignore f(n) >= 100
• Find all nodes
Where f(n) < 200
Ignore f(n) >= 200
• And so on… 4
0
Iterative Deepening A*:IDA*
f1
f2
f3
4
1
IDA* - Example
4
4 6
5 6
4
2
IDA* - Example
4
4 6
5 6
7 5
6 7
4
44
4
limitations of IDA*
Thus, if there are many short cycles in the graph and there is no
memory problem - choose A*.
4
5
4
6