AIT307 AI Unit2 3
AIT307 AI Unit2 3
PROBLEM-SOLVING AGENTS
INFORMED (HEURISTIC)
SEARCH -
Informed (Heuristic) Search Strategies
Heuristics estimate the cost of reaching the goal state from a given node, helping
to prioritize the search towards promising paths.
Key Components
Best-First Search is an informed search algorithm that explores the search space
by selecting the node that appears to be closest to the goal state 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.
Key Components
● Heuristic function: Estimates the distance from the current node to the goal.
● Priority queue: Stores nodes based on their estimated distances.
This means it prioritizes the node that appears to be closest to the goal based on the
heuristic estimate, without considering the actual cost to reach that node.
Initialization:
● A priority queue is used to store nodes and their estimated distances to the
goal.
● The starting node is added to the priority queue with its estimated distance.
Exploration:
● The node with the lowest estimated distance (based on the heuristic) is
removed from the priority queue.
● If this node is the goal node, the algorithm terminates and returns the path.
● For each neighbor of the extracted node:
○ Calculate the estimated distance to the goal for the neighbor.
○ Add the neighbor to the priority queue with its estimated distance.
Key Characteristics
Consider the problem of getting from Iasi to Fagaras. The heuristic suggests
that Neamt be expanded first because it is closest to Fagaras, but
it is a dead end.
The worst-case time and space complexity for the tree version is O(b^m)
where m is the maximum depth of the search space.
A* Search
A* Search
A Search* is an informed search algorithm that combines the efficiency of Best-First
Search with the optimality guarantees of Uniform Cost Search (UCS).
It is widely used in pathfinding and other search problems.
Key Components
● Heuristic function (h(n)): Estimates the cost from the current node to the goal.
● Path cost (g(n)): The actual cost to reach the current node from the start.
● Evaluation function (f(n)): The sum of g(n) and h(n) (f(n) = g(n) + h(n)).
How A* Search Works
Initialization:
● A priority queue is used to store nodes and their evaluation function values.
● The starting node is added to the priority queue with an evaluation function value of
0.
Exploration:
● The node with the lowest evaluation function value is removed from the priority
queue.
● If this node is the goal node, the algorithm terminates and returns the path.
● For each neighbor of the extracted node:
○ Calculate the tentative path cost to the neighbor.
○ Calculate the evaluation function value for the neighbor.
○ If the neighbor is not in the priority queue or the tentative path cost is less than
the previous known path cost, update the neighbor's path cost and evaluation
function value, and add it to the priority queue.
Other details
Mathematically, if:
h(n) is the estimated cost from node n to the goal.
h*(n) is the actual cost from node n to the goal.
Then, for an admissible heuristic:
h(n) <= h*(n)
Examples
Admissible heuristics are by nature optimistic because they think the cost of
solving the problem is less than it actually is
A heuristic function is consistent if for every node n and its successor n',
the estimated cost of reaching the goal from n is less than or equal to the
step cost from n to n' plus the estimated cost of reaching the goal from n'.
Mathematically:
● h(n) <= c(n, n') + h(n')
Where:
● h(n) is the estimated cost from node n to the goal.
● c(n, n') is the cost of moving from node n to its successor n'.
● h(n') is the estimated cost from node n' to the goal.
Optimality of A*
the tree-search version of A∗ is optimal if h(n) is admissible, while the
graph-search version is optimal if h(n) is consistent.
A∗ expands no nodes with f(n) > C∗—for example, Timisoara is not expanded in
even though it is a child of the root
the subtree below Timisoara is pruned; because hSLD is admissible, the
algorithm can safely ignore this subtree while still guaranteeing optimality
Pruning eliminates possibilities from consideration without having to examine
them
A∗ is optimally efficient for any given consistent heuristic.
That is, no other optimal algorithm is guaranteed to expand fewer nodes
than A∗
This is because any algorithm that does not expand all nodes with f(n) <
C∗ runs the risk of missing the optimal solution.
Overestimation and
Underestimation in A* Algorithm
Under estimation in A* Algorithm
In the context of A* search, underestimation refers to a heuristic function
that estimates a lower cost to reach the goal than the actual cost. While this
might seem counterintuitive, it's crucial to understand its implication
Overestimation in A* Algorithm
Overestimation in A* search occurs when the heuristic function provides an
estimate of the cost to reach the goal that is greater than the actual cost. In
other words, the heuristic function is inadmissible.
Underestimation in A* Algorithm
Here cost of each arch is 1
Each node has f=g+h
Here initially B has lowest f cost(4) so it will be expanded
next
It has only one successor E its fcost=3+2=5 which is
same as path cost of C
If we resolve this in favour of current path we follow and
choose E.
E’s successor F has cost 6 and now this path is less
attractive and we will go back to C whose cost is 5
Here by underestimating h cost we wasted some effort
Overestimation in A* Algorithm
Again we expand B first then E then F then reach Goal
G with a solution path of length 4
Suppose there is a direct path from D to solution giving
path length of 2
We will never find it
By overestimating h’(D) we make D look so bad
If h’ overestimate h then we cannot guarantee to find
the cheapest path solution unless we expand entire
graph
h’ never over-estimates h then A* is admissible
HEURISTIC FUNCTIONS
Heuristics
A heuristic function is a function that estimates the cost of reaching the goal
from a particular state in a search algorithm. In other words, it's an educated
guess about the cost of reaching the goal from a given state.
It's essentially a rule of thumb or an educated guess that helps guide the
search process towards promising paths.
Heuristic functions are primarily used in informed search algorithms like:
1. Best-First Search
2. *A Search
The heuristic function is denoted as h(n), where n is a particular state.
In this algorithm, nodes are expanded based solely on their heuristic value. It always
expands the node that appears to be closest to the goal.
It combines the cost of getting from the start state to the current state
with the heuristic estimate of the cost to reach the goal from the
current state.
The evaluation function f(n) = g(n) + h(n)
g(n) = the actual cost from the initial state to the current state.
h(n) = the heuristic function estimate
Example: The 8-Puzzle
This function estimates the minimum number of moves required to reach the goal
state by counting the tiles that are not in their correct positions.
Admissible Heuristics
h1 = the number of misplaced tiles.
For Figure 3.28, all of the eight tiles are out of position, so the start
state would have h1 = 8. h1 is an admissible heuristic because it is
clear that any tile that is out of place must be moved at least once.
• h2 = the sum of the distances of the tiles from their goal positions.
Because tiles cannot move along diagonals, the distance we will
count is the sum of the horizontal and vertical distances. This is
sometimes called the city block distance or Manhattan distance.
h2 is also admissible because all any move can do is move one tile
one step closer to the goal. Tiles 1 to 8 in the start state give a
Manhattan distance of
h2 = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18 .
neither of these overestimates the true solution cost, which is 26.
Heuristic Performance
The estimated cost from a current state to the goal is never more than
the cost of getting from the current state to a neighbouring state, plus
the estimated cost from that neighbouring state to the goal.
If h(n) is the estimated cost from state n to the goal, c(n,a,n′) is the actual
cost of getting from n to its neighbour n′ using some action a, and h(n′)
is the estimated cost from n′ to the goal, then the consistency condition
can be written as:
h(n)≤c(n,a,n′)+h(n′)
Applications