Heuristic Search Algorithm
Heuristic Search Algorithm
Algorithm
Heuristic Search
• To find a solution in proper time rather than a complete solution in unlimited time
we use heuristics.
• ‘A heuristic function is a function that maps from problem state descriptions to
measures of desirability, usually represented as numbers’. Heuristic search methods
use knowledge about the problem domain and choose promising operators first.
• These heuristic search methods use heuristic functions to evaluate the next state
towards the goal state.
• To find a solution, by using the heuristic technique, one should carry out the
following steps:
1. Add domain—specific information to select what is the best path to continue searching along.
2. Define a heuristic function h(n) that estimates the ‘goodness’ of a node n. Specifically, h(n) = estimated
cost(or distance) of minimal cost path from n to a goal state.
3. The term, heuristic means ‘serving to aid discovery’ and is an estimate, based on domain-specific
information that is computable from the current state description of how close we are to a goal.
Cont’d
• Finding a route from one city to another city is an example of
a search problem in which different search orders and the use
of heuristic knowledge are easily understood.
1. State: The current city in which the traveler is located.
2. Operators: Roads linking the current city to other cities.
3. Cost Metric: The cost of taking a given road between cities.
4. Heuristic information: The search could be guided by the direction of the goal
city from the current city, or we could use airline distance as an estimate of the
distance to the goal.
Heuristic search techniques
• For complex problems, the traditional algorithms, presented above,
are unable to find the solution within some practical time and space
limits. Consequently, many special techniques are developed, using
heuristic functions.
• Blind search is not always possible, because it requires too much time or
Space (memory).
• Heuristics are rules of thumb; they do not guarantee a solution to a
problem.
• • Heuristic Search is a weak technique but can be effective if applied
correctly; it requires domain-specific information.
Characteristics of heuristic search
• Heuristics are knowledge about a domain, which helps search and reasoning in its
domain.
• Heuristic search incorporates domain knowledge to improve efficiency over blind
search.
• Heuristic is a function that, when applied to a state, returns the value as estimated
merit of state, concerning goal.
• Heuristics might (for reasons) underestimate or overestimate the merit of a state concerning
the goal.
• Heuristics that underestimate are desirable and called admissible.
• Heuristic evaluation function estimates the likelihood of a given state leading to the
goal state.
• Heuristic search function estimates cost from current state to goal, presuming
function is efficient.
Manhattan distance with a maze
example
Consider a maze represented as a grid
where each cell can be either a wall
(representing an obstacle) or a passage.
We have a start cell (S) and a goal cell
(G) in the maze.
Cont’d
• In this maze:
• S represents the start cell.
• G represents the goal cell.
• X represents walls or obstacles that cannot be traversed.
• To calculate the Manhattan distance between the start cell (S) and the
goal cell (G), we count the number of horizontal and vertical steps
required to reach from S to G, without considering any diagonal
movements.
Cont’d
• Let's assume the coordinates of S are (1, 1) and the coordinates of G are (5,
5). Using the Manhattan distance formula:
• h(n)=∣5−1∣+∣5−1∣=8
• So, the Manhattan distance between S and G in this maze is 8.
• In pathfinding algorithms like A*, the Manhattan distance can be used as a
heuristic to guide the search towards the goal by prioritizing nodes that are
closer to the goal. It's efficient to calculate, especially in grid-based
environments, and provides a good estimate of the actual distance.
However, it may overestimate the distance in some cases, especially when
there are obstacles that force the path to take detours.
Greedy BFS
• Greedy Breadth-First Search (GBFS) is a variant of the Breadth-First Search
(BFS) algorithm that prioritizes nodes based on a heuristic function without
considering the actual cost from the start node. It explores the search space
by systematically expanding nodes in a breadth-first manner, but it does so
greedily, favoring nodes that appear to be closer to the goal according to the
heuristic. However, unlike A* search, GBFS doesn't guarantee optimality.
• Here's how Greedy Breadth-First Search works:
• Step 1: Initialization:
1. Start with the initial state or node.
2. Initialize an empty queue to store nodes to be visited.
3. Add the initial state to the queue.
Cont’d
Step 2. Search:
1. While the queue is not empty:
1. Dequeue a node from the queue.
2. If the dequeued node is the goal state, terminate the search and return success.
3. Otherwise, expand the dequeued node by generating its successor states.
4. Sort the successor states based on the heuristic function, prioritizing states that appear
closer to the goal.
5. Enqueue the successor states onto the queue.
Cont’d
Step 3. Termination:
1. If the goal state is found during the search, return success.
2. If the queue becomes empty without finding the goal state, return failure.
• GBFS explores the search space by prioritizing nodes that are estimated to be
closer to the goal state according to the heuristic function. It expands nodes in a
breadth-first manner, ensuring that nodes are explored level by level. However, it
may get stuck in local optima and fail to find the optimal solution, as it doesn't
consider the actual cost from the start node.
• Here's a simple example to illustrate Greedy Breadth-First Search:
• Consider a grid representing a search space where we are trying to find the shortest path
from the start node S to the goal node G.
• Each cell in the grid represents a state, and we can move either up, down, left, or right from
one cell to another.
• In this grid:
• S represents the start node.
• G represents the goal node.
• X represents obstacles that cannot be
traversed.
• Using GBFS with a heuristic function
like the Manhattan distance, the
algorithm would prioritize expanding
nodes that are closer to the goal node
G. However, it may not guarantee the
shortest path since it doesn't consider
the actual cost from the start node.