2. HILL CLIMBING
• It is also known as discrete optimization algorithm.
• It uses a simple heuristic function viz., the amount of distance the
node is from the goal.
• Algorithm:-
Step1 : Put the initial node on a list START
Step 2 : If (START is empty) or (START=GOAL) terminate search
Step 3 : Remove the first node from START. Call this node a
Step 4 : If (a==GOAL) terminate search with success.
Step 5 : Else if node a has successor, generate all of them. Find out
how far they are from the goal node. Sort them by the remaining
distance from the goal and add them to the beginning of START
Step 6 : Goto Step 2.
4. Problems of Hill-Climbing Technique
1. Local maximum : A state that is better than
all its neighbors but not so when compared
to states to states that are farther away.
2. Plateau : A flat area of the search space, in
which all neighbors have the same value.
3. Ridge : This is an area in the path which must
be traversed very carefully because
movement in any direction might maintain
one at the same level or result in fast decent.
5. SOLUTION
• Backtracking for local maximum. Backtracking
helps in doing what has been done so far and
permits to try a totally different path to attain
the global peak.
• A big jump is the solution to escape from the
plateau.
• Trying different paths at the same time is the
solution for ridges.
6. Best-First Search
• This search procedure is an evaluation-function variant of breadth-
first search.
• Algorithm:-
Step1 : Put the initial node on a list START
Step 2 : If (START is empty) or (START=GOAL) terminate search
Step 3 : Remove the first node from START. Call this node a
Step 4 : If (a==GOAL) terminate search with success.
Step 5 : Else if node a has successor, generate all of them. Find out
how far they are from the goal node. Sort them by the remaining
distance from the goal.
Step 6 : Name this list as START 1
Step 7 : Replace START with START 1
Step 8 : Goto Step 2.
7. A Sample tree for best-first search
7
5
6
3
9
8
1
2
6
1
4
5
2
0
1
A
D
E
F
G
B
H
C
J
I L
M
K
Start
node
Goal
node
8. Search Process of Best-First Search
Step Node being
expanded
Children Available nodes Node Chosen
1 S (A:3), (B:6), (C:5) (A:3), (B:6), (C:5) (A:3)
2 A (D:9),(E:8) (B:6),(C:5),(D:9),(E:8) (C:5)
3 C (H:7) (B:6),(D:9),(E:8),(H:7) (B:6)
4 B (F:12), (G:14) (D:9), (E:8), (H:7), (F:12),
(G:14)
(H:7)
5 H (I:5), (J:6) (D:9), (E:8), (F:12), (G:14),
(I:5), (J:6)
(I:5)
6 I (K:1), (L:0), (M:2) (D:9), (E:8), (F:12), (G:14),
(J:6), (K:1), (L:0), (M:2)
Search stops as
the goal is
reached
9. A* Algorithm
• In this algorithm, we use the evaluation function
and cost function.
• Evaluation function estimates how far a particular
node is from goal.
• Cost functions indicates how much resources like
time, energy, money etc., have been spent in
reaching a particular node from the start.
• The sum of the evaluation function value and the
cost along the path leading to that state is called
fitness number.
10. A Sample tree with fitness number
used for A* Search
7
5
6
3
9
8
1
2
6
1
4
5
2
0
1
A
D
E
F
G
B
H
C
J
I L
M
K
Start
node
Goal
node
3
2
2
6
2
2
1
3
4
7
3
5
2
11. A* Algorithm
Step1 : Put the initial node on a list START
Step 2 : If (START is empty) or (START=GOAL) terminate search
Step 3 : Remove the first node from START. Call this node a
Step 4 : If (a==GOAL) terminate search with success.
Step 5 : Else if node a has successor, generate all of them.
Estimate the fitness number of the successor by totaling
the evaluation-function value and the cost-function value.
Sort the list by fitness number.
Step 6 : Name the new list as START 1
Step 7 : Replace START with START 1
Step 8 : Goto Step 2.
12. AND/OR graphs
• Some problems are best represented as
achieving subgoals, some of which achieved
simultaneously and independently (AND)
• Up to now, only dealt with OR options
Possess TV set
Steal TV Earn Money Buy TV
13. AND/OR Search (AO*)
• We must examine several nodes
simultaneously when choosing the next
move
A
B C D
38
E F G H I J
17 9 27
(5) (10) (3) (4) (15) (10)
A
B C D
(3)
(4)
(5)
(9)
14. AND/OR Best-First-Search
• Traverse the graph (from the initial node)
following the best current path.
• Pick one of the unexpanded nodes on that
path and expand it. Add its successors to the
graph and compute f for each of them
• Change the expanded node’s f value to reflect
its successors. Propagate the change up the
graph.
• Reconsider the current best solution and
repeat until a solution is found
19. AO* algorithm
1. Let G be a graph with only starting node INIT.
2. Repeat the followings until INIT is labeled SOLVED or
h(INIT) > FUTILITY
a) Select an unexpanded node from the most promising path
from INIT (call it NODE)
b) Generate successors of NODE. If there are none, set h(NODE)
= FUTILITY (i.e., NODE is unsolvable); otherwise for each
SUCCESSOR that is not an ancestor of NODE do the following:
i. Add SUCCESSSOR to G.
ii. If SUCCESSOR is a terminal node, label it SOLVED and set
h(SUCCESSOR) = 0.
iii. If SUCCESSPR is not a terminal node, compute its h
20. AO* algorithm (Cont.)
c) Propagate the newly discovered information up the graph
by doing the following: let S be set of SOLVED nodes or
nodes whose h values have been changed and need to
have values propagated back to their parents. Initialize S to
Node. Until S is empty repeat the followings:
i. Remove a node from S and call it CURRENT.
ii. Compute the cost of each of the arcs emerging from CURRENT.
Assign minimum cost of its successors as its h.
iii. Mark the best path out of CURRENT by marking the arc that had
the minimum cost in step ii
iv. Mark CURRENT as SOLVED if all of the nodes connected to it
through new labeled arc have been labeled SOLVED
v. If CURRENT has been labeled SOLVED or its cost was just changed,
propagate its new cost back up through the graph. So add all of the
ancestors of CURRENT to S.