0% found this document useful (0 votes)
9 views89 pages

Module 1 (AI)

The document discusses the fundamentals of artificial intelligence (AI), including its classification into formal, mundane, and expert tasks, and the physical symbol system hypothesis. It explores AI techniques through examples like Tic-Tac-Toe, detailing various programs with increasing complexity and strategic approaches for gameplay. Additionally, it covers problem-solving in AI through state space search, production systems, and control strategies, using the water jug problem as a case study.

Uploaded by

Vishwesh J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views89 pages

Module 1 (AI)

The document discusses the fundamentals of artificial intelligence (AI), including its classification into formal, mundane, and expert tasks, and the physical symbol system hypothesis. It explores AI techniques through examples like Tic-Tac-Toe, detailing various programs with increasing complexity and strategic approaches for gameplay. Additionally, it covers problem-solving in AI through state space search, production systems, and control strategies, using the water jug problem as a case study.

Uploaded by

Vishwesh J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

Module 1

What is artificial intelligence?, Problems, Problem Spaces and


search, Heuristic search technique

Vishwesh Jayashkear, GSSSIETW, Mysuru


Task Classification of AI
• The domain of AI is classified into Formal tasks,
Mundane tasks, and Expert tasks.

Vishwesh Jayashkear, GSSSIETW, Mysuru


The Underlying Assumption
What is the underlying assumption?
• The heart of AI lies in the physical symbol system hypothesis (Newells &
simon). The physical symbol system is defined as: It consists of a set of entities
called symbols which are the physical patterns which can occur as components
of another type of entity called an Expression (or symbol structure).
• A symbol structure is composed of a number of instances (or token) of symbols
related in some physical way.
• At any instant of time the system will contain a collection of those symbol
structures, system also contains a collection of processes which operate an
expressions to produce other expressions, processes of creation, modification,
reproduction and destruction.

Vishwesh Jayashkear, GSSSIETW, Mysuru


What is an AI Technique
Intelligence requires knowledge but the knowledge possess some less desirable
properties such as
• It is voluminous
• It is hard to characterize accurately.
• It is constantly changing.
• It differs from data which is organised in some way corresponding to the way
in which it will be used.

Vishwesh Jayashkear, GSSSIETW, Mysuru


What is an AI Technique
Thus we can define that an AI technique is a method which uses knowledge
which should be represented in such a way that:
• The knowledge captures generalizations: Each individual situation need not be
represented separately and the situations that share important properties are
grouped together.
• Knowledge can be understood by people who must provide.
• It can be modified easily to correct errors and to reflect the changes in the
world and in our world view.
• It can be used in many situations even if it is not totally accurate or complete.
• By narrowing down the range of possibilities the sheer bulk of data can be
reduced, for being considered.
The AI techniques must be designed keeping in view the constraints imposed by
AI problems. Vishwesh Jayashkear, GSSSIETW, Mysuru
What is an AI Technique: Tic-Tac-Toe
Here we see serious of three programs to play the game. The programs here
increases in:
• Their complexity
• Their use of generalizations
• The clarity of their knowledge
• The extensibility of their approach

Vishwesh Jayashkear, GSSSIETW, Mysuru


What is an AI Technique: Tic-Tac-Toe
Program 1
Data Structures
Board A 9-elements vector representing the board:
Elements of vector 0: Empty, 1: Filled with X and 2: Filled with O
Movetable A large vector of 19,683 elements (39 ), each element is a nine-element vector. The contents of this
vector are chosen specifically to allow the algorithm to work.
The Algorithm
To make a move, do the following:
1. View the vector as a ternary (base three) number. Convert to decimal number.
2. Use the computed number as an index into Move-Table and access the vector stored there.
3. Set the new board to that vector
Comments
1. A lot od space to store the Move-Table.
2. A lot of work to specify all the entries in the Move-Table.
3. Difficult to extend. Vishwesh Jayashkear, GSSSIETW, Mysuru
Vishwesh Jayashkear, GSSSIETW, Mysuru
What is an AI Technique: Tic-Tac-Toe
Program 2
Data Structures
Board A 9-elements vector representing the board, as same as program 1. But instead of 0, 1, 2. We store 2,
3 and 5.
Elements of vector 2: Empty, 3: Filled with X and 5: Filled with O
Turn An integer indicating which move of the game is about to be played; 1 indicating the first move and
9 the last.

Vishwesh Jayashkear, GSSSIETW, Mysuru


What is an AI Technique: Tic-Tac-Toe
Program 2
The Algorithm
The main algorithm uses 3 subprocedures:

Make 2 Return 5 if the center square of the board is blank, that is, if Board[5]=2. Otherwise, will return
any blank noncorner square (2, 4, 6 or 8)
Posswin(P) Return 0 if the player P can’t win on his next move; otherwise, it returns the number of square
that says winning move.
This function will enable the program both to win and to block the opponent’s win.
Posswin operates by checking, one at a time, each of the row, column, and diagonals. Because
the way values are numbered, it can to see if it is possible to win by multiplying the values of its
squares together.
If the product is 18(3 x 3 x 2), the X can win, if product is 50(5 x 5 x 2), then O can win.
If we find a winning row, we determine which element is blank, and return the number of the
square.
Go(n) Makes a move in square n. This procedure sets Board[n] to 3 if Turn is odd, or 5 if Turn is even.
It also increments Turn by one.Vishwesh Jayashkear, GSSSIETW, Mysuru
What is an AI Technique: Tic-Tac-Toe
Program 2
The Algorithm
The algorithm has built in strategy for each move it may have to make. It makes the odd numbered moves if it is
playing X, the even numbered moves if it is playing O. The strategy for each turn is as follows:
Turn 1 Go(1)(under left corner).
Turn 2 If Board[5] is blank, Go(5),else Go(1).
Turn 3 If Board[5] is blank, Go(9),else Go(3).
Turn 4 If Posswin(X) is not 0, then Go(Posswin(X))[i.e.,block opponent’s win], else Go(Make2).
Turn 5 If Posswin(X) is not 0, then Go(Posswin(X))[i.e.,win] else if Posswin(O) is not 0, then Go(Posswin(O)) [i.e.,win], else
if Board[7] is blank, then Go(7), else Go(3). [Here the program is trying to make fork.]
Turn 6 If Posswin(O) is not 0, then Go(Posswin(O)), else if Posswin(X) is not 0,then Go(Posswin(X)),else Go(Make2).
Turn 7 If Posswin(X) is not 0, then Go(Posswin(X)), else if Posswin(O) is not 0,then Go(Posswin(O)),else go anywhere that
is blank.
Turn 8 If Posswin(O) is not O, then Go(Posswin(O)), else if Posswin(X) is not 0,then Go(Posswin(X)),else go anywhere that
is blank.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Turn 9 Same as Turn 7.
What is an AI Technique: Tic-Tac-Toe
Program 2
Comments
1. Not efficient in time, as it has to check several conditions before making each move.
2. Easier to understand the program’s strategy.
3. Hard to generalize.
4. Checking for a possible win is quicker.
5. Human finds the row-scan approach is easier, while computer finds the number-counting approach is more
efficient.

Vishwesh Jayashkear, GSSSIETW, Mysuru


What is an AI Technique: Tic-Tac-Toe
Program 3
Data Structures
BoardPosition A structure containing a nine-element vector representing the board, a list of board positions that could
result from the next move, and a number representing an estimate of how likely the board position is to
lead to an ultimate win for the player to move.
The Algorithm
To decide which of a set of board positions is best, do the following for each of them:
1. If it is a win, give it the highest rating.
2. Otherwise, consider all the moves the opponent could make next. Assume the opponent will make the move
that is worst for us. Assign the rating of that move to the current node.
3. The best nodes is then the one with the highest rating.
Comments
1. Require much more time to consider all possible moves.
2. Could be extended to handle more complicated games.
Vishwesh Jayashkear, GSSSIETW, Mysuru
What is an AI Technique: Tic-Tac-Toe
Program 3

Vishwesh Jayashkear, GSSSIETW, Mysuru


Defining the Problem as a State Space Search
1. Define the state space which contains all the possible configuration of the relevant
objects.
2. Specify one or more states within that space which describe possible situation from which
the problem solving process manages. These states are called the Initial states.
3. Specifies one or more states which would be acceptable as solutions to the problem.
These states are called the goal states.
4. Specify a set of rules which describe the action (operators) available. And for doing this
following issues may have to be considered.
a) What unstated assumptions are present in the informal problem description?
b) How generate the rule should be?
c) How much of the work required to solve the problem should be precomputed and
represented in the rules.
• The problems can be solved using the rules in combination with an appropriate
control strategy to more through the problem space until a path from initial state
to final state is found.
• The process of search is fundamental to the problem solving process.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Defining the Problem as a State Space Search- A Water Jug Problem
Statement: You are given a 4-gallon jug and a 3-gallon jug and a pump
which has unlimited water which can be used to fill the jug. Further
water present in the jug can be poured on the ground. None of the jugs
have measuring marks. How can you get exactly 2 gallons of water in
the 4-gallon jug…..????????
State Representation, Initial State & Goal State:
The state of the problem is represented as (x,y) where
x: Amount of water in 4-gallon jug.
y: Amount of water in 3-gallon jug.
Note: 0 ≤ x ≤ 4, 0 ≤ y ≤ 3
Initial state is (0,0)
End state/Goal state: (2,y) where 0 ≤ y ≤ 3

Vishwesh Jayashkear, GSSSIETW, Mysuru


Defining the Problem as a State Space Search- A Water Jug Problem
The production rules for the water jug problems:

Vishwesh Jayashkear, GSSSIETW, Mysuru


Defining the Problem as a State Space Search- A Water Jug Problem
Solution:

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production Systems
Production system is a mechanism that describes and performs the search process.
A production system consists of four basic components:
1. A set of rules of the form 𝐶𝑖 → 𝐴𝑖 where 𝐶𝑖 is the condition part and 𝐴𝑖 is the
action part. The condition determines when a given rule is applied, and the action
determines what happens when it is applied.
i.e., A set of rules each consistency of a left side(a pattern) which determines the
applicability of rule and a right side which describes the operation to be performed
if the rule is applied.
2. One or more knowledge/databases that contain whatever information is appropriate
for the particular task. Some parts of the database may be permanent while other
parts of it may pertain only to the solution of the current problem. The info within
the databases may be structured in any appropriate way.
3. A control strategy which specifies the order in which the rules will be compared to
the database and a way of resolving the conflicts which arise when several rules
that match at once.
4. A rule applier. Vishwesh Jayashkear, GSSSIETW, Mysuru
Production Systems Control Strategies
By considering control strategies we can decide which rule to apply next during
the process of searching for a solution to problem.
The two requirements of a good control strategy are:
1. It should cause motion: Consider water jug problem, if we implement
control strategy of starting each time at the top of the list of rules, it will
never leads to solution. So we need to consider control strategy that leads to
solution.
2. It should be systematic: Consider water jug problem, on each cycle, choose
at random from among the applicable rules. This is better than the first. It
causes motion. It will lead to the solution eventually. But we may arrive at
the same state several times during the process. Because control strategy is
not systematic. Let’s see a systematic strategy for the water jug problem.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production Systems Control Strategies Systematic Control Strategy for
the Water Jug Problem using:
Breadth First Search (Blind / Uninformed Search)
Systematic Control Strategy for the Water Jug Problem is as follows:
1. Construct a tree with initial state as its root .
2. Generate all the offspring off the root by applying each of the applicable rules to the
initial state.
Figure shows how tree looks at this point.
Now for each leaf node generate all the successors nodes
by applying all the rules that are appropriate.
Continue this process until some rule produces a
goal state.
This process is called the Breadth First Search.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production Systems Control Strategies Systematic Control Strategy for
the Water Jug Problem using:
Algorithm for Breadth First Search (Blind / Uninformed Search)
1. Create a variable called NODE_LIST and set it to
initial state.
2. Until a goal state is found or NODE_LIST is
empty:
a) Remove the first element from NODE_LIST
and call it E. If NODE_LIST was empty, then
quit.
b) For each way that each rule can match the state
described in E do:
I. Apply the rule to generate a new state.
II. If the new state is a goal state, quit and returned this
state.
III. Otherwise, add the new state to the end of node out.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Production Systems Control Strategies Systematic Control Strategy for
the Water Jug Problem using:
Algorithm for Depth First Search (Blind / Uninformed Search)
1. If the initial state is a goal state, quit and return “success”.
2. Otherwise, do the following until SUCCESS or FAILURE is
signalled:
a) Generate a successor, E of the initial state, If there are no
more successors signal failure.
b) Call Depth-First Search with E as initial state.
c) If success is returned signal success. Otherwise continue
in this loop.
Advantages of Depth-First Search:
• Depth-first search requires less memory since only the nodes on the current path are stored. But in breadth-first
search all of the tree that has been generated so far must be stored.
• By chance DFS may find a solution without examining much of the search space at all. But in BFS, all the parts
of the tree must be examined to level ‘n’ before any node on level ‘n+1’ can be examined. This is particularly
important if many acceptable solutions exist.
Vishwesh Jayashkear, GSSSIETW, Mysuru
• Depth-first search can stop when one of the acceptable solution is found.
Production Systems Control Strategies Systematic Control Strategy for
the Water Jug Problem using:
Advantages of Breadth-First Search:
• BFS will not get trapped exploring the blind alley. But the DFS may get trapped in a blind
alley by following a single unfruitful path for a very long time, perhaps forever before the
path actually terminates in a state that has no successors.
• If there is a solution to the problem the BFS is guaranteed to find it, further if there are
multiple solutions then a minimal solution will be found, because longer paths are never
explored until all shorter ones have already been examined. But in DFS a long path maybe
explored to find a solution when a shorter path exists in some other.
• The control strategy for water jug will cause motion and it is systematic. It will always lead
to a solution as the problem is very simple.
• But this is not always the case. In order to solve some complex problems, we must also
demand a control structure that is efficient.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production Systems Control Strategies Systematic Control Strategy for
the Water Jug Problem using:
Advantages of Breadth-First Search:
Consider The Travelling Salesman Problem: “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.”
• A simple motion causing & systematic control structure could solve the problem if number
of cities (n) is small, but the system breaks down as the number of cities grows.
• If there are N cities, the number of different paths among them are (N - 1)!
• Assume there are N=11 cities then 10! = 3628800, which is a very large number. But what if
the number of cities = 25.
• This type of problem lead to a phenomenon called combinational explosion.
• To counter this new control strategy is required; this technique is called the branch and
bound technique.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Production Systems Heuristic Search
• Heuristic search is a technique which improves the efficiency of a search process, possibly by sacrificing
claims of completeness.
Ex: Heuristics is like a tour guide who is good to the extent of that he can point all the generally interesting
directions but he is bad to the extent that he may miss points of interest to particular individuals.
• On the average, they improve the quality of the paths that are explored.
• There are general-purpose heuristic that are useful in a wide variety of problem domains.
• In addition, it is possible to construct special-purpose heuristic, which are domain specific.
• One example of a good general-purpose heuristic that is useful for a verity of combinatorial problems is the
nearest neighbor heuristic, which works by selecting the locally superior alternative at each step. Applying it
to the traveling salesman problem, we produce the following procedure:
1. Arbitrarily select a starting city.
2. To select the next city, look at all cities not yet visited, and select the one closest to the current city. Go to it next.
3. Repeat step 2 until all cities have been visited.
• This procedure executes in time proportional to 𝑁 2 , a significant improvement over N!.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production Systems Heuristic Search
Heuristic Function:
• It is a function which maps from problem state descriptions to measure of desirability usually represented as
numbers.
Note: A well designed heuristic function can play an important part in efficiently guiding the search process towards a
solution.
• A high value of heuristic function indicates a relatively good position, while at other times a low value indicates an
advantageous situation.
Some Simple Heuristic Functions
Traveling salesman The sum of the distance so far
Tic-Tac-Toe 1 for each row in which we could win and in which we
already have one piece plus 2 for each such row in which
we have two pieces

Purpose of Heuristic Function:


• A heuristic function guides the search process in the most profitable direction; by suggesting which
path to follow first when more than one path is available.
• In general there is a trade-off between the cost of evaluating a heuristic function & the saving in
search time which the function provides.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Problem Characteristics
The criteria for choosing most appropriate method for solving a particular problem
we have to consider the following:-
• Is the problem decomposable into a set of (nearly) independent smaller or easier
sub-problems.
• Can the solution steps be ignored or at least undone, if they prove unwise?
• Is the problems universe predictable?
• Is a good solution to the problem obvious without compression to all other
possible solutions?
• Is the desired solution state of the world or a path to a state.
• Is a large amount of knowledge absolutely required to solve the problem or is
knowledge important only to constrain the search?
• Can a computer which is simply given the problem return the solution or will the
• solution of the problem require interaction between the computer & a person.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Problem Characteristics  Is the problem Decomposable?
• Consider the problem
∫(𝒙𝟐 + 𝟑𝒙 + 𝒔𝒊𝒏𝟐 𝒙 ∗ 𝒄𝒐𝒔𝟐 𝒙)dx
• This problem can be solved by breaking it down
into three smaller problems each of which can
then be solved by using a small collection of
rules generating the problem tree by the process
of problem decomposition using a simple
recursive integration which works as follows:
o At each step, it checks whether the problem
it is working on, is immediately solvable, if
so then the solution is returned directly & if
the problem into smaller problems.
o If the problem is decomposable then such
problems are decomposed into smaller parts
and calls itself recursively on them.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Problem Characteristics  Is the problem Decomposable?
Now consider the Blocks World Problem
Assume that the following operators are available :
1. CLEAR(x) [Block x has nothing on it] ON (x, Table) [pickup x
& put it on the table]
2. CLEAR(x) and CLEAR(y) ON(x, y) [put x on y]
You can pick up a single block at a time.

Applying the technique of problem decomposition to this Blocks


world example:

ON(B,C) and ON(A,B)

ON(B,C) ON(A,B)
Put B on C
ON(B,C) CLEAR(A) ON(A,B)
Move A to table Put A on B
CLEAR(A) ON(A,B)
Vishwesh Jayashkear, GSSSIETW, Mysuru
Problem Characteristics  Can the solution step be Ignored or Undone?
• In mathematical theorem proving the solution steps can be ignore. In bridge or chess the solution steps are not
ignorable. Also they are not recoverable. But in 8 puzzle problem the solution steps are recoverable.
• Classes of problems
o Ignorable ( Eg: Theorem Proving ) in which solution steps can be ignored
o Recoverable(Eg: 8 Puzzle ) in which solution steps can be undone
o Irrecoverable(Eg: Chess) in which solution steps cannot be undone.
• Consider the 8-puzzle: The 8-puzzle is a square tray in which 8 tiles are placed. Remaining 9th square is
uncovered. Each tile has a number on it. A tile which is adjacent to the blank space can be slid into that space.
• The game consists of starting position & a specified goal position. The goal is to transform the starting position
into the goal position by sliding the tiles around.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Problem Characteristics  Is the Universe Predictable?

• Predictable :In 8 puzzle every time we make a move we know exactly


what will happen , this means that it is possible to plan an entire
sequence of moves and be confident that we know what the resulting
state will be . (The Universe Out come is Certain)
• Un Predictable : In Playing Bridge , We Cannot know exactly where
all the cards are or what the other players will do on their turn.
(Uncertain outcome)

Vishwesh Jayashkear, GSSSIETW, Mysuru


Problem Characteristics  Is a good solution Absolute or Relative?
Whether problem is Independent or Dependent
Consider the problem of Answering Question based on a database of simple facts,
such has the following:
1.Marcus was a man.
2.Marcus was a Pompeian.
3.Marcus was born in 40A.D.
4.All men are mortal.
5.All Pompeian's died when the volcano erupted in 79A.D.
6.No mortal lives longer than 150 years.
7.It is now 1991A.D.
Suppose we ask a question “Is Marcus alive?”

Vishwesh Jayashkear, GSSSIETW, Mysuru


Problem Characteristics  Is a good solution Absolute or Relative?
1.Marcus was a man. Justification
2.Marcus was a Pompeian. 1 Marcus was a man Axiom 1
3.Marcus was born in 40A.D.
4 All men are mortal. Axiom 4
4.All men are mortal.
5.All Pompeian's died when the 8 Marcus is a mortal 1, 4
volcano erupted in 79A.D. 3 Marcus was born in 40 A.D. Axiom 3
6.No mortal lives longer than 150 7 It is now 1991 A.D. Axiom 7
years.
7.It is now 1991A.D. 9 Marcus age is 1951 years 3, 7
Suppose we ask a question “Is 6 No mortal lives longer than 150 years Axiom 6
Marcus alive?” 10 Marcus is dead 8, 6, 9
OR
Two Ways of Deciding That 7 It is now 1991 A.D. Axiom 7
Marcus Is Dead  5 All Pompeians died in 79 A.D Axiom 5
Any path of reasoning will give the
11 All Pompeians are dead now. 7, 5
absolute answer to the problem, there is
no reason to go back and see if the other 2 Marcus was Pompeian. Axiom 2
path might lead to the absolute solution. Vishwesh Jayashkear, GSSSIETW, Mysuru
12 Marcus is dead 11, 2
Problem Characteristics  Is a good solution Absolute or Relative?
Consider now Travelling Salesman Problem. Our goal is to find the shortest path so that the
sales man visits each city exactly once. Suppose the cities we need to visit and the distances
between them are known: Let the salesman start from Bostom. He could follow the one path
Boston New Miami Dallas San covering the total distance of 8850 Km. But is this the solution?
York Francisco We are not sure unless other alternate paths are covered. A second
Boston 250 1450 1700 3000 or third path can also be known, a second one is shown on the
New York 250 1200 1500 2900 right hand side of the earlier traversal tree giving certainly first
path as the answer, which is of course relative
Miami 1450 1200 1600 3300

Dallas 1700 1500 1600 1700

San Francisco 3000 2900 3300 1700

Vishwesh Jayashkear, GSSSIETW, Mysuru


Problem Characteristics  Is the solution a State or a Path?
For State: In the Natural Language Processing example, because of the
interaction between various components some search may be required to find a
complete interpretation, otherwise we are concerned only about the solution.
Consider the problem of finding a consistent interpretation for the sentence “The
bank president ate a dish of pasta salad with the fork“.

For Path: Contrast to this with The Water Jug Problem, what we really must
report is not the final state but the path that we found to that state. Thus a
statement of solution to this problem must be a sequence of operation that
produces the final state. This problem solution is Path to the state.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Problem Characteristics  What is the Role of Knowledge?
• Is a large amount of knowledge absolutely required to solve the problem or is
knowledge important only to constrain the search.
• In 8 puzzle or Chess game we get a solution with the help of knowledge base.
(Rules for determining the legal moves).
• But when we consider the problem of scanning daily newspaper to decide which
political party will win in upcoming election, it would have to know such things
as
–The name of the candidate of each party
–Major issues/achievement to support party
–Major issues to oppose the party
–And so on –
• These two problems, 8 puzzle and newspaper story understanding, illustrate the
difference between:
• Problems for which a lot of knowledge is important just to search for a solution &
• Problems for which a lot of knowledge is required even to be able to recognize a solution.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Problem Characteristics  Does the Task Require Interaction with a Person?
• Increasingly we are building programs that requires intermediate interaction with
people, both to provide additional input to the program and to provide additional
reassurance to the user.
• Interaction requirement distinguish between two types of problems:
1. Solitary, in which the computer will be given a problem description and will produce
an answer, with no intermediate communication and with no demand for an explanation
of the reasoning process. Simple theorem proving falls under this category . Given the
basic rules and laws, the theorem could be proved, if one exists.
Ex:- Theorem Proving (give basic rules & laws to computer)
2. Conversational, in which there will be intermediate communication between a person
and the computer, either to provide additional assistance to the computer or to provide
additional informed information to the user, or both. Problems such as medical diagnosis
fall under this category, where people will be unwilling to accept the verdict of the
program, if they can not follow its reasoning.
Ex:- Problems such as Medical Diagnosis.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Problem Characteristics  Problem Classification
• There is a variety of problem‐solving methods, but there is no one
single way of solving all problems.
• Not all new problems should be considered as totally new. Solutions of
similar problems can be exploited.
• Broad classes to which the problems falls is associated with a generic
control strategy that is appropriate for solving the problems.
–Classification: Medical diagnosis tasks, Diagnosis of fault in mechanical
devices.
–Propose and Refine: Design and Planning Problems

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production System Characteristics
• A Production System (or Production Rule System) is a computer program
typically used to provide some form of artificial intelligence, which consists
primarily of a set of rules about behaviour.
• These rules, termed productions, are a basic representation found useful in
automated planning, expert systems and action selection.
• A production system provides the mechanism necessary to execute productions
in order to achieve some goal for the system.
• In simple terms, it is said to contain a number of rules which are defined by their
Left Hand Side (LHS) and Right Hand Side (RHS).
• The LHS contains the necessary conditions to be met if the rule is to be applied,
while the RHS denotes the outcome of each applicability of the rule.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Production System Characteristics
Four classes of production systems:-
1. Monotonic Production System: A system in which the application of a rule never prevents the
later application of another rule that could have also been applied at the time the first rule was
selected.
2. Non-Monotonic Production System: Here the application of rule prevents later application of
the another rule which may not have been applied at the time the first rule was selected i.e., it is
a system in which the above rule is not true i.e., the monotonic production system rule not true.
3. Partially Commutative Production System: A production system in which the application of a
particular sequence of rules transforms state X into state Y.
4. Not Partially Commutative Production System: Is a program which satisfies both monotonic
and partially commutative production System.
Monotonic Non-Monotonic
Partially Commutative Theorem proving Robot navigation
Not Partially Commutative Chemical synthesis Bridge
Vishwesh Jayashkear, GSSSIETW, Mysuru
Production System Characteristics
Advantages of Production Systems
1. Production systems provide an excellent tool for structuring AI programs.
2. Production Systems are highly modular because the individual rules can be added, removed
or modified independently.
3. The production rules are expressed in a natural form.
4. Helpful in real time environment and applications.

Disadvantages of Production Systems


1. Very difficult to analyze the flow of control within a production system because the
individual rules don’t call each other.
2. Several Production Systems exist for various types of problems. The efficiency varies from
problem to problem.

Vishwesh Jayashkear, GSSSIETW, Mysuru


• Search is a central topic in Artificial Intelligence. The basic search
algorithms/techniques can be classified as follows:
•Uninformed (Blind) Search:
Breadth-first search and
Depth-first search.

•Informed (Heuristic) Search:


Generate and Test
Hill Climbing
Best First Search
Problem Reduction
Constraint Satisfaction and
Means ends Analysis .
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Generate and Test
Definition: Generate-and-test search algorithm is a very simple algorithm that guarantees to find
a solution if done systematically and there exists a solution.

Algorithm:
1. Generate a possible solution. For some problems, this means generating a particular point in
the problem space. For others it means generating a path from a start state.
2. Test to see if this is actually a solution by comparing the chosen point or the endpoint of the
chosen path to the set of acceptable goal states.
3. If a solution has been found, quit, Otherwise return to step 1.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Generate and Test
• It is a depth first search procedure since complete solutions must be generated
before they can be tested.
• It’s a most systematic form, it is simply an exhaustive search of the problem
space.
• Operate by generating solutions randomly.
• The random form is also known as the British Museum method a reference to a
method for finding an object in the British Museum by wandering randomly.
• Another successful example is AI program DENDRAL, which helps the organic
chemists to find the unknown organic compounds by analysing there mass spectra
and using the knowledge of chemistry.
• Another simple example for generate and test is Travelling Salesman Problem
where traveller 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.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Generate and Test
• Consider the path for Travelling Salesman Problem:
TSP - generation of possible solutions is done in
lexicographical order of cities:
1. A -B -C -D
2. A -B -D -C
3. A -C -B -D
4. A -C -D -B
...

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing
• 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.
• The test function is augmented with a heuristic function that provides an estimate
of how close a given state is to the goal state.
• Computation of heuristic function can be done with negligible amount of
computation.
• Hill climbing is often used when a good heuristic function is available for
evaluating states but when no other useful knowledge is available.
• Following are the different types of Hill Climbing algorithm.
1.Simple Hill Climbing
2.Steepest Ascent Hill Climbing
3.Simulated Healing

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Simple Hill Climbing
• Use heuristic to move only to states that are better than the current state.
• Always move to better state when possible.
• The process ends when all operators have been applied and none of the resulting
states are better than the current state.
• The simplest way to implement hill climbing is as follows.
Algorithm: Simple Hill Climbing (Local Search)
1. Evaluate the initial state. If it is also a goal state, then return it and quit.
Otherwise, continue with the initial state as the current state.
2. Loop until a solution is found or until there are no new operators left to be
applied in the current state:
a) Select an operator that has not yet been applied to the current state and
apply it to produce a new state.
b) Evaluate the new state.
i. If it is a goal state, then return it and quit.
ii. If it is not a goal state but it is better than the current state, then make it
the current state.
iii. If it is not better than the current
Vishwesh state,
Jayashkear, GSSSIETW, then continue in the loop.
Mysuru
Informed (Heuristic) Search  Hill Climbing  Steepest Ascent Hill
Climbing
• This method considers all the moves from the current state and selects the best
one as the next state.
• This method steepest-ascent hill climbing is also called as gradient search.
• Instead of moving to the first state that is better, move to the best possible state
that is one move away.
• The order of operators does not matter.
• Not just climbing to a better state, climbing up the steepest slope.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Steepest Ascent Hill
Climbing
Algorithm: Steepest-Ascent Hill Climbing
1. Evaluate the initial state. If it is also a goal state, then return it and quit.
Otherwise, continue with the initial state as the current state.
2. Loop until a solution is found or until a complete iteration produces no
change to current state:
a) Let SUCCESSOR (S) be a state such that any possible successor of the
current state (CS) will be better than S.
b) For each operator that applies to the current state do:
i. Apply the operator and generate a new state (NS).
ii. Evaluate the new state. If it is a goal state, then return it and quit. If not,
compare it to S. If it is better, then set S to this state. If it is not better,
leave S alone.
iii. If the S is better than CS, then set CS to S.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Hill Climbing  Steepest Ascent Hill
Climbing
Problems with Hill Climbing (Both Simple & Steepest Ascent Hill Climbing)
• Both basic and steepest-ascent hill climbing may fail to find a solution. Either algorithm may
terminate not by finding a goal state but by getting to a state from which no better states can be
generated. This will happen if the program has reached either a local maximum, a plateau, or a
ridge.
1. A local maximum is a state that is better than all its neighbor's but is not better than some other states farther
away. At a local maximum, all moves appear to make things worse. Local maxima are particularly frustrating
because they often occur almost within sight of a solution. In this case, they called foothills.
2. A plateau is a flat area of the search space in which a whole set of neighbouring states have the same value. On
a plateau, it is not possible to determine the best direction in which to move by making local comparisons.
3. A ridge is a special kind of local maximum, where there are steep slopes and the search direction is not towards
the top but towards the side.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Steepest Ascent Hill
Climbing
Solutions to Problems local maximum, plateau and ridge
• Backtrack to some earlier node and try going in a different direction. This is
mainly important if at that node there was another direction that looked as
promising or almost promising as the one that was chosen earlier. Its good way
of dealing with local maximum.
• Make a big jump in some direction to try to get to a new section of the search
space. Its good way of dealing with plateau.
• Apply two or more rules before doing the test. This corresponds to moving in
several directions at once. Its good way of dealing with ridge.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Steepest Ascent Hill
Climbing
There are some ways of dealing with these problems, although these methods are by no means
guaranteed:
• Consider the Blocks World Problem.
Local: Add one point for every block that is resting on the thing it is
supposed to resting on. Subtract one point for every block that is sitting on
the wrong thing.
Using this function, the goal state has a score of 8. The initial state has a
score of 4 (since it gets one point added for blocks C,D,E,F,G and H and
one point subtracted for blocks A and B).
There is only one move from the initial state, namely to move block A to
the table. That produces a state with a score of 6. The hill-climbing
procedure will accept that move. From the new state, there are three
possible moves, leading to the three states. These states have the score: (a)
4, (b) 4, and (c) 4. Hill climbing will halt because all these states have
lower scores than the current state. The process has reached a local
maximum that is not the global maximum.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Simulated Annealing
• Simulated Annealing is a variation of hill climbing in which, at the beginning of the process,
some downhill moves may be made.
• The idea is to do enough exploration of the whole space in the early stage.
• This should lower the chances of getting caught at a local maximum, a plateau, or a ridge.
• We use the term objective function in place of the term heuristic function.
• And we attempt to minimize rather than maximize the value of the objective function. Thus
we actually describe a process of valley descending rather than hill climbing.

Three differences for Simulated Annealing from the Simple Hill-Climbing procedure:
• The annealing schedule must be maintained.
• Moves to worse states may be accepted.
• It is a good idea to maintain, in addition to the current state, the best state found so far. Then,
if the final state is worse than that earlier state, the earlier state is still available.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Simulated Annealing

• The algorithm is basically hill-climbing except instead of picking the best move,
it picks a random move. If the selected move improves the solution, then it is
always accepted. Otherwise, the algorithm makes the move anyway with some
probability less than 1.
• The probability is given by the function:𝒑 = 𝒆−∆𝑬/𝒌𝑻

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Hill Climbing  Simulated Annealing

Algorithm: Simulated Annealing


1. Evaluate the initial state. If it is a goal state , then return it and quit. Otherwise set initial
state as the current state.
2. Initialize BEST-SO-FAR to the current state.
3. Initialize T according to the annealing schedule.
4. Loop until a solution is found or there are no new operators left to be applied:
a. Select and applies a new operator which has not yet applied.
b. Evaluate the new state:
• If the new state is goal state , then return it and quit.
• If it is not a goal state and better than the current state then make it as the current
state. Also set BEST–So-FAR to this new state.
• If it is not better than the current state, then Compute ∆E= Val(current state) -
Val(new state) make it the current state with probability 𝒑 = 𝒆−∆𝑬/𝒌𝑻
c. Revise T as necessary according to the annealing schedule.
5. Return BEST –So-FAR as the answer.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Hill Climbing  Simulated Annealing
• To implement this revised algorithm, it is necessary to select an annealing
schedule, which has three components.
1. The first is the initial value to be used for temperature.
2. The second is the criteria that will be used to decide when the temperature of the
system should be reduced.
3. The third is the amount by which the temperature will be reduced each time it is
changed.
• Simulated annealing is often used to solve problems in which the number of
moves from a given state is very large, such as the set of possible orders of
cities in the Traveling Salesman problem and in VLSI routing.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Best First Search
• Till now we have discussed two systematic control strategies: BFS & DFS.
• A new method Best First Search, is a way of combining the advantages of both
BFS & DFS into a single method.
• Best first search has three kinds:
1. OR Graph.
2. The A* Algorithm.
3. Agendas.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Best First Search OR Graph
• DFS is good because it allows a solution to be found, does not require to expand all the
branches. BFS is good because it allows a solution to be found without getting trapped on
the dead-end paths.
• One way to combining the two is to follow a single path at a time, but switches the path
whenever some other path looks more promising than the current one.
• At each step of the best-first search process, we select the most promising of the nodes we
have generated so far.
 This is done by applying an appropriate heuristic function to each of them.
 We then expand the chosen node by using the rules to generate its successors.
o If one of them is a solution, we can quit.
o If not, all those new nodes are added to the set of nodes generated so far.
o Again the most promising node is selected and the process continues.
• To implement the graph search procedure ,we will need to use two list of nodes.
 OPEN- nodes that have been generated but have not been visited yet. It’s a priority queue in
which the elements with the highest propriety are those with the most promising value of the
heuristic function.
 Closed - nodes that have been already
Vishweshvisited
Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search OR Graph
Step 1: Shows beginning of best-first search OPEN = {A}
procedure. Initially, there is only one node, so it will CLOSE = { }
be expanded.
Step 2: Expanding one need, results in three nodes. OPEN = {A, D}
Heuristic function here estimates the cost of getting CLOSE = { B, C}
a solution from a given node. Since D is the most
promising, it is expanded next.
Step 3: Expanding D produces two successors say OPEN = {A, D, E}
node E and F. But heuristic function say the path or
going through node B looks more promising, so OPEN = {A, B}
node B is expanded next. CLOSE = {C }
Step 4: Expanding B produces two successors say OPEN = {A, D, E}
node G and H. But again heuristic function say G CLOSE = {B, C, G H }
and H are less promising compare to node E, so
node E is expanded next.
Step 5: Expanding E produces two successors say OPEN = {A, D, E, I}
node I and J. Heuristic function says J is more CLOSE = {B, C, G, H, F, I }
promising and it is expanded next.
This continues till the solution is found.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search OR Graph
• We call the previous graph as an OR Graph, since each of its branches represents alternative problem solving
path.
Algorithm: Best-First Search / OR Graph
1. Start with OPEN containing just the initial state.
2. Until a goal is found or there are no nodes left on OPEN do:
a) Pick the best node on OPEN.
b) Generate its successors.
c) For each successor do:
i. If it has not been generated before, evaluate it, add it to OPEN, and
record its parent.
ii. If it has been generated before, change the parent if this new path is
better than the previous one. In that case, update the cost of getting to
this node and to any successors that this node may already, have.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search The A* Algorithm
• Best First Search is a simplification of A* Algorithm.
• Algorithm uses f’, g, h’, OPEN & CLOSE:
f’: Heuristic function that estimates the merits of each node we generate. This
is sum of two components, g and h’. The f’ represents an estimate of the cost
of getting from the initial state to a goal state along with the path that
generated the current node.
g : The function g is a measure of the cost of getting from initial state to the
current node.
h’ : The function h’ is an estimate of the additional cost of getting from the
current node to a goal state.
OPEN.
CLOSED.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Best First Search The A* Algorithm
Algorithm: A*
1. Start with OPEN containing only initial node. Set that node’s g value to 0, its h’ value to whatever it
is, and its f’ value to h’+0 or h’. Set CLOSED to empty list.
2. Until a goal node is found, repeat the following procedure: If there are no nodes on OPEN, report
failure. Otherwise pick the node on OPEN with the lowest f’ value. Call it BESTNODE. Remove it
from OPEN. Place it in CLOSED. See if the BESTNODE is a goal state. If so exit and report a
solution. Otherwise, generate the successors of BESTNODE but do not set the BESTNODE to point
to them yet. For each of the SUCCESSOR, do the following:
a. Set SUCCESSOR to point back to BESTNODE. These backwards links will make it possible to
recover the path once a solution is found.
b. Compute g(SUCCESSOR) = g(BESTNODE) + the cost of getting from BESTNODE to
SUCCESSOR
c. See if SUCCESSOR is the same as any node on OPEN. If so call the node OLD.
d. If SUCCESSOR was not on OPEN, see if it is on CLOSED. If so, call the node on CLOSED
OLD and add OLD to the list of BESTNODE’s successors.
e. If SUCCESSOR was not already on either OPEN or CLOSED, then put it on OPEN and add it to
the list of BESTNODE’s successors. Compute f’(SUCCESSOR) = g(SUCCESSOR) +
h’(SUCCESSOR) Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search The A* Algorithm
Observations about A*
• Role of g function: This lets us choose which node to expand next on the basis of
not only of how good the node itself looks, but also on the basis of how good the
path to the node was. By incorporating g into f’, we will not always choose as
our next node to expand the node that appears to be closest to the goal. This is
useful if we care about the path we find.
• h’, the distance of a node to the goal. If h’ is a perfect estimator of h, then A*
will converge immediately to the goal with no search. If the value of h’ is always
0, the search will be controlled by g. if the value of g is also 0, the search strategy
will be random. If the value of g is always 1, the search will be breath first.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Best First Search The A* Algorithm
Example of A*:
Lets find the shortest path between A and J:
The number written with blue is the distance between the nodes
and written with red is the heuristic value.
A* uses f’(n) = g(n) + h’(n) to find the shortest path

Lets start with A


A have 2 nodes B and F
Lets calculate F(B) and F(F)
F(B) = 6 + 8 = 14
F(F) = 3 + 6 =9
F(F) < F(B), so we will choose F as our new start node.
A
So, path isVishwesh F
Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search The A* Algorithm
Example of A*:
Now F is our new start node
F have 2 nodes G and H
Lets calculate F(G) and F(H)
F(G) = 4 + 5 = 9 (3+1 = 4)
F(H) = 10 + 3 = 13 (3 + 7 = 10)
F(G) < F(H), so we will choose G as our new start node.
So, path is A  F  G

Now G is our new start node


G has only 1 node I
Lets calculate F(I)
F(I) = 7 + 1 = 9 (3+1 + 3 = 7)
Now we will choose I as our new start node.
So, path is A  F  G  I
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search The A* Algorithm
Example of A*:
Now I is our new start node
I have 3 nodes E, H and J
Lets calculate F(E), F(H), and F(J)
F(E) = 12 + 3 = 15 (3+1 + 3 + 5 = 12)
F(H) = 9 + 3 = 12 (3+1 + 3 + 2 = 10)
F(J) = 10 + 0 = 10 (3+1 + 3 + 3 = 10)
F(J) is smallest, so we will choose J as our new start node.
But we stop here as J was our target node.
So, path is A  F  G  I  J

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Best First Search The A* Algorithm
Advantages
• It is complete and optimal.
• It is the best one from other techniques.
• It is used to solve very complex problems.
• It is optimally efficient, i.e. there is no other optimal algorithm guaranteed to
expand fewer nodes than A*.
Disadvantages
• This algorithm is complete if the branching factor is finite and every action has
fixed cost.
• The speed execution of A* search is highly dependant on the accuracy of the
heuristic algorithm that is used to compute h (n).
• It has complexity problems.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search Agendas
• An Agenda is a list of tasks a system could perform.
• Associated with each task there are usually two things:
 A list of reasons why the task is being proposed (justification)
 Rating representing the overall weight of evidence suggesting that the task would
be useful.
Algorithm: Agendas driven search
1. Do until a goal state is reached or the agenda is empty:
a. Choose the most promising task from the agenda.
b. Execute the task by devoting to it the number of resources determined by its importance. The
important resources to consider are time and space. Executing the task will probably generate
additional tasks (successor nodes). For each of them do the followings:
i. See if it is already on the agenda. If so, then see if this same reason for doing it is already on
its list of justifications. If so, ignore this current evidence. If this justification was not
already present, add it to the list. If the task was not on the agenda, insert it.
ii. Compute the new task’s rating, combining the evidence from all its justifications. Not all
justifications need have equal weight. It is often useful to associate with each justification a
measure of how strong the reason it is. These measures are then combined at this step to
produce an overall rating for the task.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Best First Search Agendas
Example: Chatbot
Person: I don’t want to read any
more about china. Give me
something else.
Computer: OK. What else are you
interested in?
Person: How about Italy? I think
I’d find Italy interesting.
Computer: What things about Italy
are you interested in reading about?
Person: I think I’d like to start with
its history.
Computer: why don’t you want to
read any more about China?
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Problem Reduction
• In problem reduction, a complex problem is broken down or decomposed into a
set of primitive sub problem; solutions for these primitive sub-problems are
easily obtained. The solutions for all the sub-problems collectively give the
solution for the complex problem.
• The Problem Reduction technique can be represented using:
o AND-OR Graphs
o The AO* Algorithm

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Problem Reduction AND-OR Graphs
• The AND-OR GRAPH (or tree) is useful for representing the solution of problems that can
solved by decomposing them into a set of smaller problems, all of which must then be solved.
• This decomposition, or reduction, generates arcs that we call AND arcs.
• One AND arc may point to any number of successor nodes, all of which must be solved in
order for the arc to point to a solution.
• Just as in an OR graph, several arcs may emerge from a single node, indicating a variety of
ways in which the original problem might be solved.
• This is why the structure is called not simply an AND-graph but rather an AND-OR graph
(which also happens to be an AND-OR tree). Below figure shows a simple AND-OR graph, in
which AND arcs are indicating with a line connecting all the components.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Problem Reduction AND-OR Graphs
• The AND-OR GRAPH (or tree) is useful for representing the solution of problems that can
solved by decomposing them into a set of smaller problems, all of which must then be solved.
• This decomposition, or reduction, generates arcs that we call AND arcs.
• One AND arc may point to any number of successor nodes, all of which must be solved in
order for the arc to point to a solution.
• Just as in an OR graph, several arcs may emerge from a single node, indicating a variety of
ways in which the original problem might be solved.
• This is why the structure is called not simply an AND-graph but rather an AND-OR graph
(which also happens to be an AND-OR tree). Below figure shows a simple AND-OR graph, in
which AND arcs are indicating with a line connecting all the components.
• An algorithm to find a solution in an AND - OR graph must handle AND area
appropriately. This can be understand from the give figure.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Problem Reduction AND-OR Graphs
• An algorithm to find a solution in an AND - OR graph must handle AND area
appropriately. This can be understand from the give figure.
To see our best-first search is not adequate for searching AND-OR graphs:
• In figure (a) the top node A has been expanded producing two arcs, one leading to B and one leading
to C & D . The numbers at each node represent the value of f' at that node (cost of getting to the goal
state from current state). For simplicity, it is assumed that every operation(i.e. applying a rule) has
(a)
unit cost, i.e., each are with single successor will have a cost of 1 and each of its components. With
the available information till now , it appears that C is the most promising node to expand since its f'
= 3 , the lowest but going through B would be better since to use C we must also use D, and the cost
would be 9 (C+D+2). Through B it would be 6 (5+1).
• Thus the choice of the next node to expand depends not only on f' value but also
on whether that node is part of the current best path form the initial mode.
• Figure (b) makes this clearer. In figure the node G appears to be the most promising
node, with the least f' value. But G is not on the current beat path, since to use G we
must use G-H with a cost of 9 and again this demands that arcs I-J to be used (with a
cost of 27). The path from A, through B, to E and F is better with a total cost of 18
(17+1=18). So we should not expand G next; rather we should examine either E or
F.
(b)

In order to describe an algorithm for searching an AND-OR graph, we need to exploit a value that we call FUTILITY.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Problem Reduction AND-OR Graphs
In order to describe an algorithm for searching an AND-OR graph, we need to exploit a value that we call
FUTILITY.
• If the estimated cost of a solution becomes grater than the value of FUTILITY which is a threshold, then we
abandon the search, even if it could ever be found.

Algorithm: Problem Reduction / AND-OR Graph


1. Initialize the graph to the starting node.
2. Loop until the starting node is labeled SOLVED or until its cost goes above FUTILITY:
a. Traverse the graph, starting at the initial node and following the current best path, and accumulate the set of
nodes that are on that path and have not yet been expanded or labeled as solved.
b. Pick one of these nodes and expand it. If there are no successors, assign FUTILITY as the value of this
node. Otherwise, add its successors to the graph and for each of them compute f’. If f’ of any node is 0,
mark that node as SOLVED.
c. Change the f’ estimate of the newly expanded node to reflect the new information provided by its
successors. Propagate this change backward through the graph. Decide which of the current best path. This
propagation of revised cost estimates back up the tree was not necessary in the BFS algorithm because only
unexpanded nodes were examined. But now expanded nodes must be re-examined so that the best current
path can be selected.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Problem Reduction AND-OR Graphs
Example for AND-OR Graph:
Step 1: A is the only node, it is at the end of the current best path. It has to
expanded.
Step 2: Expanding A, yielding nodes B, C, D. The arc to D is labeled as the most
promising one emerging from A, since it costs 6 compared to B and C, Which costs
9.

Step 3: Node D is chosen for expansion. This process produces one new arc, the
AND arc to E and F, with a combined cost estimate of 10. So we update the f’
value of D to 10. Going back one more level, we see that this makes the AND arc
B-C better than the arc to D, so it is labeled as the current best path.

Step 4: We traverse the arc from A and discover the unexpanded nodes B and C. If
we going to find a solution along this path, we will have to expand both B and C
eventually, so let’s choose to explore B first. This generates two new arcs, the ones
to G and to H. Propagating their f’ values backward, we update f’ of B to 6. This
requires updating the cost of the AND arc B-C to 12 (B+C+2). After doing that, the
arc to D is again the better path from A, so we record that as the current best path
and either node E or node F will chosen for expansion at step 4.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Problem Reduction The AO* Algorithm
Algorithm: The 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’
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
Vishwesh of CURRENT
Jayashkear, GSSSIETW, Mysuru to S.
Informed (Heuristic) Search  Problem Reduction The AO* Algorithm
Example: The AO* Algorithm

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Constraint Satisfaction
• A CS Problem (CSP) is a problem composed of a finite set of
variables, each of which is associated with a finite domain, and a set
of constraints.
• CPS is a search procedure that operates in a space of constraint state.
Constraints in the initial state are originally given in the given
problem. Any state is a goal state that has been constrained ‘enough’
where ‘enough’ means that each letter has been assigned a unique
numeric value.
• The solution process in CSP contains cycles wherein the following
things are done on each cycle:
oPropagate the constraints using rules that correspond to the arithmetic
properties
oGuess a value for some letter whose value is not yet determined.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Constraint Satisfaction
Algorithm: Constraint Satisfaction
1. Propagate available constraints
a. All objects should be opened and must be assigned values in a complete
solution.
b. Repeat the succeeding steps until inconsistency or all objects assigned valid
values.
i. Select an object and strengthen this object as much as possible by a set
of constraints that is applied to the object.
ii. If the set of constraints is not matched from the previous set, then open
all objects that share any of these constraints.
iii. Remove selected objects.
2. Return Solution, if the union of constraints exposed above defines a solution.
3. Otherwise return failure, if the union of constraints discovered above defines
a contradiction.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Constraint Satisfaction
Example: Cryptarithmetic Problems
The problem is to plot integers from 0 to 9 for the alphabet specified in
the crypt arithmetic problems with following constraints:
1. No two alphabets should have the same integer value.
2. Having allotted the different values for different alphabets we have to
perform the arithmetic operations specified in the problem.
3. Numbers must not begin with zero i.e., 0123 (wrong), 123 (correct).
4. After replacing letters by their digits, the resulting arithmetic
operations must be correct.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Constraint Satisfaction
Example: Cryptarithmetic Problems
Consider the following Cryptarithmetic problem as an example:
SEND+MORE=MONEY

1. From Column 5, M=1, since it is only carry-over possible from sum of 2 single digit number in column 4.
2. Now in column 4, we know the value of M = 1 and so S+1=O. This S+1=O should generate the carry to the
next column to make M=1. If S=9, then 9+1=10. This means that S=9 and O=0.
3. In column 3, we have E+0=N  E=N, which is not possible because E and N cannot be the same value. To
be E and N different values, we should get the carry. This leads to E+1=N.
4. Since column 3 has a carry from column 2. In column 2, E value has to generate the carry and its value
cannot be 10 since value 0 is already assigned to O. So, E value should be greater then 10. we can write E
has E + 10. Over all we can write the equation has N + R (+1) = E +10. Here (+1) means, we may or may
not consider this value.
5. Now, if we solve the equations E + 1 = N and N + R (+1) = E +10. We will get R (+1) = 9. R value cannot
be 9 since 9 is assigned to S. Means column 2 has to receive a carry from column 1. So, considering the carry
R becomes 8. Means, R= 8 and this columnVishwesh
has aJayashkear,
carry. GSSSIETW, Mysuru
Informed (Heuristic) Search  Constraint Satisfaction
Example: Cryptarithmetic Problems

1. From Column 5, M=1, since it is only carry-over possible from sum of 2 single digit number in column 4.
2. Now in column 4, we know the value of M = 1 and so S+1=O. This S+1=O should generate the carry to the
next column to make M=1. If S=9, then 9+1=10. This means that S=9 and O=0.
3. In column 3, we have E+0=N  E=N, which is not possible because E and N cannot be the same value. To
be E and N different values, we should get the carry. This leads to E+1=N.
4. Since column 3 has a carry from column 2. In column 2, E value has to generate the carry and its value
cannot be 10 since value 0 is already assigned to O. So, E value should be greater then 10. we can write E
has E + 10. Over all we can write the equation has N + R (+1) = E +10. Here (+1) means, we may or may
not consider this value.
5. Now, if we solve the equations E + 1 = N and N + R (+1) = E +10. We will get R (+1) = 9. R value cannot
be 9 since 9 is assigned to S. Means column 2 has to receive a carry from column 1. So, considering the carry
R becomes 8. Means, R= 8 and this column has a carry.
6. Now, still we don’t know the value for N and E. Let’s see column 1 equation which is D + E = Y . We know
column 1 has to generate the carry, means Y has to send carry and Y value cannot be 10 or 11 since 0
assigned to O and 1 assigned to M. This say Y should be more than 11. So, different combination of D + E
can be 7 + 5 or 7 + 6. So, if we take D = 7 and E = 5, Y becomes Y = 2.
7. And hence N becomes, N = 6. Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Constraint Satisfaction
Example: Cryptarithmetic Problems

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Means-Ends Analysis
• Most of the search strategies either reason forward or backward however, often a mixture of the two directions is
appropriate. Such mixed strategy would make it possible to solve the major parts of problem first and solve the
smaller problems the arise when combining them together. Such a technique is called "Means - Ends Analysis".
• The means-ends analysis process centers around finding the difference between current state (initial state) and
goal state.
• We will use the operator to reduce the difference between initial and goal state.
• Operators are selected and sub-goals are setup.
• Example 1:

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Means-Ends Analysis
Summary:
• Until the goal is reached or no more procedures are available,
1. Describe the current state, the goal state, and Calculate the difference
between the two.
2. Use the difference, to select a promising procedure.
• Use the promising procedure and update the current state.
• If the goal is reached, announce success; otherwise, announce failure.

Key idea is to reduce difference between the current state and the goal
state.

Vishwesh Jayashkear, GSSSIETW, Mysuru


Informed (Heuristic) Search  Means-Ends Analysis
Example 2 Task: A robot has to move a desk with two things on it from one room
to another room.
The available operators, along with
preconditions and results

Table shows the difference table Push Carry Walk Pickup Putdown Place

that describes when each of the Move object * *

operators is appropriate  Move robot *


Clear object *
Get object on *
object
Get arm empty * *
Be holding
Vishwesh Jayashkear, object
GSSSIETW, Mysuru *
Informed (Heuristic) Search  Means-Ends Analysis
• The main difference between the start state and the goal state would be the location of the
desk.
• To reduce this difference either CARRY or PUSH could be chosen.
• If CARRY is chosen first, its preconditions must be met. This leads to two more differences
that must be reduced: location of the robot and size of the desk.
• The location of the robot can be handled by applying WALK.
• But no operators that can change the size of an object.
• This leads to dead end.
• If PUSH is chosen, problem solver progress at this point:
• From the figure we can that we are not reached the goal state, there is differences between A
and B and between C and D that must be reduced.
• The progress of the problem 
• But still there is a difference between C and E that
can be reduced by using WALK to get the robot
back to the objects, followed by PICKUP and
CARRY.
Vishwesh Jayashkear, GSSSIETW, Mysuru
Informed (Heuristic) Search  Means-Ends Analysis
Algorithm: Means-Ends Analysis (CURRENT, GOAL)
1. Compare CURRENT with GOAL. If there are no differences between them then return.
2. Otherwise, select the most important difference and reduce it doing the following until
success or failure is signaled:
a. Select an as yet untried operator O that is applicable to the current difference. If there are no such
operators, then signal failure.
b. Attempt to apply O to CURRENT. Generate descriptions of two states: O-START, a state
in which O's preconditions are satisfied and O-RESULT, the state that would result if O
were applied in O-START.
c. If
(FIRST-PART  MEA(CURRENT, O-START))
and
(LAST-PART  MEA(O-RESULT, GOAL))
are successful, then signal success and return the result of concatenating
FIRST-PART,O, and LAST-PART.
Vishwesh Jayashkear, GSSSIETW, Mysuru

You might also like