4.heuristic (Informed) SearchTechniques
4.heuristic (Informed) SearchTechniques
2
1. Generate-and-Test
Algorithm:
3
Generate-and-Test
4
Generate-and-test Example
Travelling Sales Man(TSP)
A salesman has a list of cities, each of which he must visit
exactly once. There are direct roads between each pair of cities
on the list. Find the route the salesman should follow for the
shortest possible round trip that both starts and finishes at any
one of the cities.
Traveler needs to visit n cities.
Know the distance between
each pair of cities.
Want to know the shortest
route that visits all the cities
once.
5
Generate-and-test Example
Travelling Sales Man(TSP)
• TSP - generation of possible solutions is done in lexicographical order of
cities:
Length of
Search for Path
Path
1 ABCD 18 A B C D
2 ABDC 13
3 ACBD 11
4 ACDB 13 B C D
5 ADBC 11
Continued
C D B D C B
D C D B B C
Finally, select the path whose length
6
is less.
It is a depth first search procedure since complete
solutions must be generated before they can be tested.
7
2. Hill Climbing
It is a variant of generate-and test in which feedback from the test procedure
is used to help the generator decide which direction to move in search
space. (Generate and test + direction to move)
Hill climbing is often used when a good heuristic function is available for
evaluating states but when no other useful knowledge is available.
It is also called greedy local search as it only looks to its good immediate
neighbor state and not beyond that.
8
9
10
11
12
13
14
15
16
17
18
Features of Hill Climbing
19
State-space Diagram for Hill Climbing
21
2. Plateau: A plateau is the flat area of the search space in which all
the neighbor states of the current state contains the same value,
because of this algorithm does not find any best direction to move. A
hill-climbing search might be lost in the plateau area.
To avoid this,
we randomly
make a big
jump.
To avoid this, we
may use two or more
rules before testing
22
Types of Hill Climbing Algorithm
2.Steepest-Ascent hill-
climbing
23
1.Simple hill Climbing
Simple hill climbing is the simplest way to implement a hill
climbing algorithm.
selects the first one which optimizes current cost and set
it as a current state.
It only checks it's one successor state, and if it finds better than
Step 5: Exit.
25
Simple Hill Climbing-
Example
• TSP - define state space as the set of all possible
tours.
26
TSP Hill Climb State Space
ABCD Initial State
ABCD
BACD
BACD ACBD
ACBD ABDC
ABDC DBCA
DBCA
CABD
CABD ABCD
ABCD ACDB
ACDB DCBA
DCBA
27
2. Steepest-Ascent hill climbing
28
Algorithm for Steepest-Ascent hill climbing
Step 1: Evaluate the initial state, if it is goal state then return success and
stop, else make current state as initial state.
Step 2: Loop until a solution is found or the current state does not
change.
A. Let SUCC be a state such that any successor of the current
state will be better than it.
B. For each operator that applies to the current state:
i. Apply the new operator and generate a new state.
ii. Evaluate the new state.
iii. If it is goal state, then return it and quit, else compare it to
the SUCC.
iv. If it is better than SUCC, then set new state as SUCC.
v. If the SUCC is better than the current state, then set
current state to SUCC. 29
30
3. Stochastic hill climbing
31
3. Stochastic hill climbing - Algorithm
37
In this search example, we are using two lists which
are OPEN and CLOSED Lists. Following are the iteration for
traversing the above example.
38
Expand the nodes of S and put in the CLOSED list
39
Time Complexity: The worst case time complexity of Greedy
best first search is O(bm).
40
Advantages:
Best first search can switch between BFS and DFS
by gaining the advantages of both the algorithms.
This algorithm is more efficient than BFS and DFS
algorithms.
Disadvantages:
It can behave as an unguided depth-first search in
the worst case scenario.
It can get stuck in a loop as DFS.
This algorithm is not optimal.
41
3. Best First Search Algorithm (Greedy search)
3. 2 A* Algorithm
At each point in the search space, only those node is expanded which have the
lowest value of f(n), and the algorithm terminates when the goal node is found.
43
Algorithm of A* search:
47
Complete: A* algorithm is complete as long as:
Branching factor is finite.
Cost at every action is fixed.
Optimal: A* search algorithm is optimal if it follows below two
conditions:
Admissible: the first condition requires for optimality is
that h(n) should be an admissible heuristic for A* tree
search. An admissible heuristic is optimistic in nature.
Consistency: Second required condition is consistency
for only A* graph-search.
If the heuristic function is admissible, then A* tree search
will always find the least cost path.
49