Ai Unit 2
Ai Unit 2
II-YEAR-AI&DS -2021 R
SUB CODE: AL3391
SUB NAME: Artificial Intelligence
UNIT II
PROBLEM SOLVING
Heuristic search strategies – heuristic functions. Local search and optimization
problems – local search in continuous space – search with non-deterministic
actions – search in partially observable environments – online search agents and
unknown environments
1
UNIT II
What is Heuristics?
● A heuristic is a technique that is used to solve a problem faster than the classic methods. These
techniques are used to find the approximate solution of a problem when classical methods
do
not.
●
Heuristics are said to be the problem-solving techniques that result in practical and quick
solutions.
Why do we need heuristics?
● Heuristics are used in situations in which there is the requirement of a short-term solution.
● On facing complex situations with limited resources and time, Heuristics can help the companies to make
quick decisions by shortcuts and approximated calculations.
● Most of the heuristic methods involve mental shortcuts to make decisions on past experiences.
● The heuristic method might not always provide us the finest solution, but it is assured that it helps us find
a good solution in a reasonable time.
2
Direct Heuristic Search techniques in AI
It includes Blind Search, Uninformed Search, and Blind control strategy. These search techniques
are not always possible as they require much memory and time. These techniques search the
complete space for a solution and use the arbitrary ordering of operations.
The examples of Direct Heuristic search techniques include Breadth-First Search (BFS) and Depth
First Search (DFS).
It includes Informed Search, Heuristic Search, and Heuristic control strategy. These techniques
are helpful when they are applied properly to the right types of tasks. They usually require domain-
specific information.
The examples of Weak Heuristic search techniques include Best First Search (BFS) and A*.
Before describing certain heuristic techniques, let's see some of the techniques listed below:
o Bidirectional Search
o A* search
o Simulated Annealing
o Hill Climbing
o Best First search
o Beam search
It is a technique for optimizing the mathematical problems. Hill Climbing is widely used when a
good heuristic is available.
It terminates when it reaches a peak value where no neighbor has a higher value. Traveling-
salesman Problem is one of the widely discussed examples of the Hill climbing algorithm, in which
we need to minimize the distance traveled by the salesman.
It is also called greedy local search as it only looks to its good immediate neighbor state and
not beyond that. The steps of a simple hill-climbing algorithm are listed below:
3
Step 1: Evaluate the initial state. If it is the goal state, then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Else if it is better than the current state, then assign a new state as a current state.
Else if not better than the current state, then return to step2.
Step 5: Exit.
This algorithm always chooses the path which appears best at that moment. It is the combination
of depth-first search and breadth-first search algorithms. It lets us to take the benefit of both
algorithms. It uses the heuristic function and search. With the help of the best-first search, at each
step, we can choose the most promising node.
Step 3: Remove the node n from the OPEN list, which has the lowest value of h(n), and places it
in the CLOSED list.
Step 5: Check each successor of node n, and find whether any node is a goal node or not. If any
successor node is the goal node, then return success and stop the search, else continue to next step.
Step 6: For each successor node, the algorithm checks for evaluation function f(n) and then check
if the node has been in either OPEN or CLOSED list. If the node has not been in both lists, then
add it to the OPEN list.
4
A* Search Algorithm
A* search is the most commonly known form of best-first search. It uses the heuristic function
h(n) and cost to reach the node n from the start state g(n). It has combined features of UCS and
greedy best-first search, by which it solve the problem efficiently.
It finds the shortest path through the search space using the heuristic function. This search
algorithm expands fewer search tree and gives optimal results faster.
Algorithm of A* search:
Step 2: Check if the OPEN list is empty or not. If the list is empty, then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of the evaluation function
(g+h). If node n is the goal node, then return success and stop, otherwise.
Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each
successor n', check whether n' is already in the OPEN or CLOSED list. If not, then compute the
evaluation function for n' and place it into the Open list.
Step 5: Else, if node n' is already in OPEN and CLOSED, then it should be attached to the back
pointer which reflects the lowest g(n') value.
Some of the real-life examples of heuristics that people use as a way to solve a problem:
o Common sense: It is a heuristic that is used to solve a problem based on the observation
of an individual.
o Rule of thumb: In heuristics, we also use a term rule of thumb. This heuristic allows an
individual to make an approximation without doing an exhaustive search.
o Working backward: It lets an individual solve a problem by assuming that the problem
is already being solved by them and working backward in their minds to see how much a
solution has been reached.
5
o Availability heuristic: It allows a person to judge a situation based on the examples of
similar situations that come to mind.
Types of heuristics
There are various types of heuristics, including the availability heuristic, affect heuristic and
representative heuristic.
Each heuristic type plays a role in decision-making. Let's discuss about the Availability
heuristic, affect heuristic, and Representative heuristic.
i.Availability heuristic
Availability heuristic is said to be the judgment that people make regarding the likelihood of
an event based on information that quickly comes into mind.
On making decisions, people typically rely on the past knowledge or experience of an event.
It allows a person to judge a situation based on the examples of similar situations that come to
mind.
ii.Representative heuristic
It occurs when we evaluate an event's probability on the basis of its similarity with another event.
If a company packages its products that remind you of a high quality and well-known product,
then consumers will relate that product as having the same quality as the branded product.
So, instead of evaluating the product based on its quality, customers correlate the products quality
based on the similarity in packaging.
iii.Affect heuristic
It is based on the negative and positive feelings that are linked with a certain stimulus. It includes
quick feelings that are based on past beliefs.
Its theory is one's emotional response to a stimulus that can affect the decisions taken by an
individual.
When people take a little time to evaluate a situation carefully, they might base their decisions
based on their emotional response.
6
Example: The affect heuristic can be understood by the example of advertisements.
Advertisements can influence the emotions of consumers, so it affects the purchasing decision of
a consumer. The most common examples of advertisements are the ads of fast food. When fast-
food companies run the advertisement, they hope to obtain a positive emotional response that
pushes you to positively view their products.
If someone carefully analyzes the benefits and risks of consuming fast food, they might decide that
fast food is unhealthy.
But people rarely take time to evaluate everything they see and generally make decisions based on
their automatic emotional response.
So, Fast food companies present advertisements that rely on such type of Affect heuristic for
generating a positive emotional response which results in sales.
Limitation of heuristics
o Although heuristics speed up our decision-making process and also help us to solve
problems, they can also introduce errors just because something has worked accurately in
the past, so it does not mean that it will work again.
o It will hard to find alternative solutions or ideas if we always rely on the existing solutions
or heuristics.
⮚ Consider the following 8-puzzle problem where we have a start state and a goal state.
Our task is to slide the tiles of the current/start state and place it in an order followed in the goal
state.
There can be four moves either left, right, up, or down. There can be several ways to convert
the current/start state to the goal state, but, we can use a heuristic function h(n) to solve the
problem more efficiently.
7
A heuristic function for the 8-puzzle problem is defined below:
So, there is total of three tiles out of position i.e., 6,5 and 4. Do not count the empty tile present
in the goal state).
i.e. h(n)=3. Now, we require to minimize the value of h(n) =0.
We can construct a state-space tree to minimize the h(n) value to 0, as shown below:
● It is seen from the above state space tree that the goal state is minimized from h(n)=3 to
h(n)=0.
● However, we can create and use several heuristic functions as per the reqirement. It is
also clear from the above example that a heuristic function h(n) can be defined as the
8
information required to solve a given problem more efficiently.
● The information can be related to the nature of the state, cost of transforming from
one state to another, goal node characterstics, etc., which is expressed as a heuristic
function.
⮚ Which leads to a solution state required to reach the goal node. But beyond these “classical
search algorithms," we have some “local search algorithms” where the path cost does not
matters, and only focus on solution-state needed to reach the goal node.
⮚ A local search algorithm completes its task by traversing on a single current node rather than multiple
paths and following the neighbors of that node generally.
Although local search algorithms are not systematic, still they have the following two
advantages:
● Local search algorithms use a very little or constant amount of memory as they operate
only on a single path.
● Most often, they find a reasonable solution in large or infinite state spaces where
the classical or systematic algorithms do not work.
Working of a Local search algorithm
Consider the below state-space landscape having both:
The local search algorithm explores the above landscape by finding the following two points:
● Global Minimum: If the elevation corresponds to the cost, then the task is to find
the lowest valley, which is known as Global Minimum.
9
● Global Maxima: If the elevation corresponds to an objective function, then it finds
the highest peak which is called as Global Maxima. It is the highest point in the
valley.
● Hill-climbing Search
● Simulated Annealing
● Local Beam Search
● Global Maximum: It is the highest point on the hill, which is the goal state.
● Local Maximum: It is the peak higher than all other peaks but lower than the
global maximum.
● Flat local maximum: It is the flat area over the hill where it has no uphill or downhill.
It is a saturated point of the hill.
● Shoulder: It is also a flat area where the summit is possible.
● Current state: It is the current position of the person.
10
Types of Hill climbing search algorithm
There are following types of hill-climbing search:
● Local Maxima: It is that peak of the mountain which is highest than all its neighboring
states but lower than the global maxima. It is not the goal peak because there is another peak higher than it.
● Plateau: It is a flat surface area where no uphill exists. It becomes difficult for the
climber to decide that in which direction he should move to reach the goal point.
Sometimes, the person gets lost in the flat area.
12
● Ridges: It is a challenging problem where the person finds two or more local maxima of
the same height commonly. It becomes difficult for the person to navigate the right point
and stuck to that point itself.
Simulated Annealing
Simulated annealing is similar to the hill climbing algorithm. It works on the current situation. It
picks a random move instead of picking the best move.
⮚ If the move leads to the improvement of the current situation, it is always accepted as a step
towards the solution state, else it accepts the move having a probability less than 1.
⮚ This search technique was first used in 1980 to solve VLSI layout problems.
⮚ It is also applied for factory scheduling and other large optimization tasks.
Local Beam Search
o Local beam search is quite different from random-restart search.
o It keeps track of k states instead of just one.
o It selects k randomly generated states, and expand them at each step.
o If any state is a goal state, the search stops with success.
o Else it selects the best k successors from the complete list and repeats the same process.
o In random-restart search where each search process runs independently, but in local beam
search, the necessary information is shared between the parallel search processes.
Disadvantages of Local Beam search
● This search can suffer from a lack of diversity among the k states.
● It is an expensive version of hill climbing search.
13
2.4.Local search in continuous space:
14
15
16
2.5.Search with non-deterministic actions:
17
18
2.6. Search in partial observable environments:
19
20
21
2.7.Online Search Agents and Unknown Environments:
22
23
24
TWO MARKS
1. What is the power of heuristic search? (or) Why does one go for heuristics
search?
Heuristic search uses problem specific knowledge while searching in state
space. This helps to improve average search performance. They use evaluation
functions which denote relative desirability (goodness) of a expanding node set. This
makes the search more efficient and faster. One should go for heuristic search because
it has power to solve large, hard problems in affordable times.
25
the search procedure turns out to be wasted here. It is like a dead end.
7. What is CSP?
CSP are problems whose state and goal test conform to a standard structure
and very simple representation. CSPs are defined using set of variables and a set of
constraints on those variables. The variables have some allowed values from specified
domain. For example – Graph coloring problem.
26
16.Differentiate deterministic and non deterministic environment. (pg.no.17)
PART B
1. Elaborate the need for local search algorithm and discuiss any one algorithm in detail.
(A.U(A/M-2023)
2. Discuiss on online search agent that uses depth first exploration. .(A.U(A/M-2023)
5. What is the heuristic Search technique in AI?.How does heuristic search work? Explain its
advantages and disadvantages. .(A.U(N/D-2023).
27