Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
166 views

Artificial Intelligence Unit 1 Notes

This document provides an introduction to artificial intelligence, including definitions, goals, techniques, and applications. Some key points: - AI is concerned with designing intelligent behavior in machines and is an interdisciplinary field at the intersection of computer science, mathematics, psychology, and more. - It aims to build machines that can think and act intelligently through techniques like problem solving, learning, reasoning, and perception. - Core goals include developing intelligent systems through understanding how human intelligence works from both a science and engineering perspective. - Representing knowledge, learning, and manipulating symbols are important AI techniques to enable problem solving. - Applications span many domains like robotics, natural language processing, planning, expert systems

Uploaded by

Sa Inamdar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views

Artificial Intelligence Unit 1 Notes

This document provides an introduction to artificial intelligence, including definitions, goals, techniques, and applications. Some key points: - AI is concerned with designing intelligent behavior in machines and is an interdisciplinary field at the intersection of computer science, mathematics, psychology, and more. - It aims to build machines that can think and act intelligently through techniques like problem solving, learning, reasoning, and perception. - Core goals include developing intelligent systems through understanding how human intelligence works from both a science and engineering perspective. - Representing knowledge, learning, and manipulating symbols are important AI techniques to enable problem solving. - Applications span many domains like robotics, natural language processing, planning, expert systems

Uploaded by

Sa Inamdar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Artificial Intelligence

Unit 1 chapter 1 Introduction to AI


Introduction:
Artificial Intelligence is concerned with the design of intelligence in an artificial device. The term was coined
by John McCarthy in 1956.
Intelligence is the ability to acquire, understand and apply the knowledge to achieve goals in the world.
AI is the study of the mental faculties through the use of computational models
AI is the study of intellectual/mental processes as computational processes.
AI program will demonstrate a high level of intelligence to a degree that equals or exceeds the intelligence
required of a human in performing some tasks.
AI is unique, sharing borders with Mathematics, Computer Science, Philosophy, Psychology, Biology, Cognitive
Science and many others.
Although there is no clear definition of AI or even Intelligence, it can be described as an attempt to build
machines that like humans can think and act, able to learn and use knowledge to solve problems on their own.
What is Artificial Intelligence?
It is a branch of Computer Science that pursues creating the computers or machines as intelligent as human beings.
It is the science and engineering of making intelligent machines, especially intelligent computer programs.
It is related to the similar task of using computers to understand human intelligence, but AI does not have to confine
itself to methods that are biologically observable.

Definition: Artificial Intelligence is composed of two words Artificial and Intelligence, where Artificial defines
"man-made," and intelligence defines "thinking power", hence AI means "a man-made thinking power."
• Systems that think like humans
• Systems that act like humans
• Systems that think rationally
• Systems that act rationally
Definition: Artificial Intelligence is the study of how to make computers do things, which, at the moment, people
do better.

According to the father of Artificial Intelligence, John McCarthy, it is “The science and engineering of making
intelligent machines, especially intelligent computer programs”.
Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a software think intelligently,
in the similar manner the intelligent humans think.
AI is accomplished by studying how human brain thinks and how humans learn, decide, and work while trying to
solve a problem, and then using the outcomes of this study as a basis of developing intelligent software and systems.
It has gained prominence recently due, in part, to big data, or the increase in speed, size and variety of data
businesses are now collecting. AI can perform tasks such as identifying patterns in the data more efficiently than
humans, enabling businesses to gain more insight out of their data.
From a business perspective AI is a set of very powerful tools, and methodologies for using those tools to solve
business problems.
From a programming perspective, AI includes the study of symbolic programming, problem solving, and search.
AI Vocabulary
Intelligence relates to tasks involving higher mental processes, e.g. creativity, solving problems, pattern
recognition, classification, learning, induction, deduction, building analogies, optimization, language processing,
knowledge and many more. Intelligence is the computational part of the ability to achieve goals.
Intelligent behaviour is depicted by perceiving one’s environment, acting in complex environments, learning and
understanding from experience, reasoning to solve problems and discover hidden knowledge, applying knowledge
successfully in new situations, thinking abstractly, using analogies, communicating with others and more.

goals of AI
Science based goals of AI pertain to developing concepts, mechanisms and understanding biological intelligent
behaviour. The emphasis is on understanding intelligent behaviour.
Engineering based goals of AI relate to developing concepts, theory and practice of building intelligent machines.
The emphasis is on system building.
AI Techniques depict how we represent, manipulate and reason with knowledge in order to solve problems.
Knowledge is a collection of ‘facts’. To manipulate these facts by a program, a suitable representation is required.
A good representation facilitates problem solving.
SIBA ,VIJAYAPURA Page 1
Artificial Intelligence
Learning means that programs learn from what facts or behaviour can represent. Learning denotes changes in the
systems that are adaptive in other words, it enables the system to do the same task(s) more efficiently next time.
Applications of AI refers to problem solving, search and control strategies, speech recognition, natural language
understanding, computer vision, expert systems, etc.
1.1 The Problems of AI:
Intelligence does not imply perfect understanding; every intelligent being has limited perception, memory and
computation.
Many points on the spectrum of intelligence versus cost are viable, from insects to humans.
AI seeks to understand the computations required from intelligent behaviour and to produce computer systems that
exhibit intelligence.
Aspects of intelligence studied by AI include perception, communicational using human languages, reasoning,
planning, learning and memory.
The following questions are to be considered before we can step forward:
1. What are the underlying assumptions about intelligence?
2. What kinds of techniques will be useful for solving AI problems?
3. At what level human intelligence can be modelled?
4. When will it be realized when an intelligent program has been built?

Applications of AI(some of task or domain of Artificial Intelligence)


AI has applications in all fields of human study, such as finance and economics, environmental engineering,
chemistry, computer science, and so on. Some of the applications of AI are listed below:
Perception
■ Machine vision
■ Speech understanding
■ Touch (tactile or haptic) sensation
Robotics
Natural Language Processing
■ Natural Language Understanding
■ Speech Understanding
■ Language Generation
■ Machine Translation
Planning
Expert Systems
Machine Learning
Theorem Proving
Symbolic Mathematics
Game Playing

1.2 The Underlying Assumption


At the heart of research in artificial intelligence lies what Newell and Simon (1976) call the physical symbol system
Hypothesis. They define a physical symbol system as follows:

A physical symbol system consists of a set of entities, called symbols, which are physical patterns that can occur
as components of another type of entity called an expression (or symbol structure). Thus, a symbol structure is
composed of a number of instances (or tokens) of symbols related in some physical way (such as one token being
next to another). At any instant of time the system will contain a collection of these symbol structures. Besides
these structures, the system also contains a collection of processes that operate on expressions to produce other
expressions: processes of creation, modification, reproduction and destruction. A physical symbol system is a
machine that produces through time an evolving collection of symbol structures. Such a system exists in a world
of objects wider than just these symbolic expressions themselves.

They then state the hypothesis as


The Physical Symbol System Hypothesis. A physical symbol system has the necessary and sufficient means for
general intelligent action

SIBA ,VIJAYAPURA Page 2


Artificial Intelligence
This hypothesis is only a hypothesis. There appears to be no way to prove or disprove it on logical grounds. So it
must be subjected to empirical validation. We may find that it is false. We may find that the bulk of the evidence
says that it is true. But the only way to determine its truth is by experimentation.
Computers provide the perfect medium for this experimentation since they can be programmed to simulate any
physical symbol system we like. This ability of computers to serve as arbitrary symbol manipulators was noticed
very early in the history of computing. Lady Lovelace made the following observation about Babbage's proposed
Analytical Engine in 1842.

The operating mechanism can even be thrown into action independently of any object to operate upon (although
of course no result could then be developed). Again, it might act upon other things besides numbers, were objects
found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and
which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine.
Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical
composition were susceptible of such expression and adaptations, the engine might compose elaborate and
scientific pieces of music of any degree of complexity or extent. [Lovelace, 1961]

As it has become increasingly easy to build computing machines, so it has become increasingly possible to conduct
empirical investigations of the physical symbol system hypothesis. In each such investigation, a particular task that
might be regarded as requiring intelligence is selected. A program to perform the task is proposed and then tested.
Although we have not been completely successful at creating programs that perform all the selected.

1.3 AI Technique:
Artificial Intelligence research during the last three decades has concluded that Intelligence requires knowledge.
To compensate overwhelming quality, knowledge possesses less desirable properties.
A. It is huge.
B. It is difficult to characterize correctly/accurately.
C. It is constantly varying/changing.
D. It differs from data by being organized in a way that corresponds to its application.
E. It is complicated.

An AI technique is a method that exploits knowledge that is represented so that:


The knowledge captures generalizations that share properties, are grouped together, rather than being allowed
separate representation.
It can be understood by people who must provide it—even though for many programs bulk of the data comes
automatically from readings. In many AI domains, how the people understand the same people must supply the
knowledge to a program.
It can be easily modified to correct errors and reflect changes in real conditions.
It can be widely used even if it is incomplete or inaccurate.
It can be used to help overcome its own sheer bulk by helping to narrow the range of possibilities that must be
usually considered.
In order to characterize an AI technique let us consider initially OXO or tic-tac-toe and use a series of different
approaches to play the game.
• The programs increase in complexity.
• their use of generalizations.
• the clarity of their knowledge
• and the extensibility of their approach. In this way they move towards being representations of AI techniques.

1.3.1 Tic Tac Toe


Game playing strategies
Two players
human
computer.

SIBA ,VIJAYAPURA Page 3


Artificial Intelligence

The objective is to write a computer program in such a way that computer wins most of the time.
Three approaches are presented to play this game which increase in
Complexity
Use of generalization
Clarity of their knowledge
Extensibility of their approach
These approaches will move towards being representations of what we will call AI techniques.
Tic Tac Toe Board- (or Noughts and crosses, Xs and Os)
It is two players, X and O, game who take turns marking the spaces in a 3×3 grid.
The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal row wins the game.

Approach 1
Data Structure
Consider a Board having nine elements vector.
Each element will contain
● 0 for blank
● 1 indicating X player move
● 2 indicating O player move
Computer may play as X or O player.
First player who so ever is always plays X.
Move Table MT
MT is a vector of 39 elements, each element of which is a nine-element vector representing board position.
Total of 39 (19683) elements in MT

Algorithm
To make a move, do the following:
i. View the vector (board) as a ternary number and convert it to its corresponding decimal number.
ii. Use the computed number as an index into the MT and access the vector stored there.
iii. The selected vector in step 2 represents the way the board will look after the move. Set board equal to that
vector.
Comments
▪ Very efficient in terms of time but has several disadvantages.
Lot of space to store the move table.
Lot of work to specify all the entries in move table.
Highly error prone as the data is voluminous.
Poor extensibility: If we want to extend 3D tic-tac-toe = 327 board position to be stored which results
overwhelming present computer memories.
Not intelligent at all.

SIBA ,VIJAYAPURA Page 4


Artificial Intelligence
Approach 2
Data Structure
Board: A nine-element vector representing the board: B[1..9]
Following conventions are used
2 - indicates blank
3 - indicates X
5 - indicates 0
Turn: An integer which moves of the game to be played
1 - First move
9 - Last move
Procedures Used
Make_2
▪ Make_2 first tries to play in the center of board is blank that is Board [5] =2 and returns 5 (square
number)
▪ If not possible, then it tries the various suitable non corner square and returns square number (2 ,4 , 6, 8).
Go(n) makes a move in square ‘n’ which is blank represented by 2. Set board[n]=3 if turn is odd or 5 if turn is
even. It also increments turn by one.

PossWin(p)
PossWin (P)
▪ Returns 0, if player P cannot win in its next move,
▪ otherwise the number of square that constitutes a winning move for P.
Rule
If PossWin (P) = 0 {P can not win} then find whether opponent can win. If so, then block it.
Strategy used by PosWin
PosWin checks one at a time, for each rows /columns and diagonals as follows.
If 3 * 3 * 2 = 18 then player X can win
else if 5 * 5 * 2 = 50 then player O can win
These procedures are used in the algorithm are showed below.

Algorithm:
1. Turn = 1: (X moves)
Go(1) //make a move at the left-top cell
2. Turn = 2: (O moves)
IF board[5] is blank THEN
Go(5)
ELSE
Go(1)
3. Turn = 3: (X moves)
IF board[9] is blank THEN
Go(9)
ELSE
Go(3).
4. Turn = 4: (O moves)
IF Posswin (X) is not 0 THEN
Go (Posswin (X))
//Prevent the opponent to win
ELSE Go (Make2)
5. Turn = 5: (X moves)
IF Posswin(X) is not 0 THEN
Go(Posswin(X)) //Win for X.
ELSE IF Posswin(O) is not 0 THEN
Go(Posswin(O)) //Prevent the opponent to win
ELSE IF board[7] is blank THEN
Go(7)
ELSE Go(3)
SIBA ,VIJAYAPURA Page 5
Artificial Intelligence
6. Turn = 6: (O moves)
IF Posswin(O) is not 0 THEN
Go(Posswin(O)) //Win for O.
ELSE IF Posswin(X) is not 0 THEN
Go(Posswin(X)) //Prevent the opponent to win
ELSE Go(Make2)
7. Turn=7: (X moves)
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
8. Turn =8:( O moves)
IF Posswin(O) is not 0 THEN
Go(Posswin(O))
ELSE IF Posswin(X) is not 0 THEN
Go(Posswin(X))
ELSE go anywhere that is blank
9. Same as the turn 7

Comments
▪ Not as efficient as first one in terms of time.
▪ Several conditions are checked before each move.
▪ It is memory efficient.
▪ Easier to understand & complete strategy has been determined in advance
▪ Still can not generalize to 3-D.

Approach 3
Same as approach 2 except for one change in the representation of the board.
Board is considered to be a magic square of size 3 X 3 with 9 blocks numbered by numbers indicated by magic
square.
This representation makes process of checking for a possible win more simple.
Board Layout – Magic Square
Board Layout as magic square. Each row, column and diagonals add to 15.

Strategy for possible win for one player


Maintain the list of each player’s blocks in which he has played.
Consider each pair of blocks that player owns.
Compute difference D between 15 and the sum of the two blocks.
If D < 0 or D > 9 then
these two blocks are not collinear and so can be ignored
otherwise if the block representing difference is blank (i.e., not in either list) then a move in that block will
produce a win.
Working Example of algorithm
Assume that the following lists are maintained up to 3rd move.
Consider the magic block shown in slide 18.
First Player X (Human)
8 3
Second Player O (Computer)
5
SIBA ,VIJAYAPURA Page 6
Artificial Intelligence
Strategy is same as in approach 2
First check if computer can win.
If not then check if opponent can win.
If so, then block it and proceed further.
Steps involved in the play are:
First chance, H plays in block numbered as 8
Next C plays in block numbered as 5
H plays in block numbered 3
Now there is a turn of computer
Strategy by computer: Since H has played two turns and C has played
only one turn, C checks if H can win or not.
Compute sum of blocks played by H
S = 8 + 3 = 11
Compute D = 15 – 11 = 4
Block 4 is a winning block for H.
So block this block and play in block numbered 4.
The list of C gets updated with block number 4 as follows:
H 8 3 C 5 4

Comments
This program will require more time than two others as
it has to search a tree representing all possible move sequences
before making each move.
This approach is extensible to handle
3-dimensional tic-tac-toe.
games more complicated than tic-tac-toe.

Example-2: Question Answering


Let us consider Question Answering systems that accept input in English and provide answers also in English.
This problem is harder than the previous one as it is more difficult to specify the problem properly.
Another area of difficulty concerns deciding whether the answer obtained is correct, or not, and further what is
meant by ‘correct’. For example, consider the following situation:
2.1 Text
Rani went shopping for a new Coat. She found a red one she really liked.
When she got home, she found that it went perfectly with her favourite dress.
2.2 Question
1. What did Rani go shopping for?
2. What did Rani find that she liked?
3. Did Rani buy anything?

Method 1-Solution of Example-2


i) Data Structures
• A set of templates that match common questions and produce patterns used to match against inputs.
• Templates and patterns are used so that a template that matches a given question is associated with the
corresponding pattern to find the answer in the input text.
• For example, the template who did x y generates x y z if a match occurs and z is the answer to the question. The
given text and the question are both stored as strings.
ii) Algorithm
Answering a question requires the following four steps to be followed:
Compare the template against the questions and store all successful matches to produce a set of text patterns.
Pass these text patterns through a substitution process to change the person or voice and produce an expanded
set of text patterns.
Apply each of these patterns to the text; collect all the answers and then print the answers.

iii) Example

SIBA ,VIJAYAPURA Page 7


Artificial Intelligence
In question 1 we use the template WHAT DID X Y which generates Rani go shopping for z and after substitution
we get
Rani goes shopping for z and
Rani went shopping for z
giving z [equivalence] a new coat
In question 2 we need a very large number of templates and also a scheme to allow the insertion of ‘find’ before
‘that she liked’; the insertion of ‘really’ in the text; and the substitution of ‘she’ for ‘Rani’ gives the answer ‘a red
one’.
Question 3 cannot be answered.
iv) Comments
This is a very primitive approach basically not matching the criteria we set for intelligence and worse than that,
used in the game. Surprisingly this type of technique was actually used in ELIZA which will be considered later in
the course.

Method 2- Solution of Example-2


i) Data Structures
A structure called English consists of a dictionary, grammar and some semantics about the vocabulary we are
likely to come across.
This data structure provides the knowledge
• to convert English text into a storable internal form and
• also to convert the response back into English.
The structured representation of the text is a processed form and defines the context of the input text by making
explicit all references such as pronouns.
There are three types of such knowledge representation systems:
• production rules of the form ‘if x then y’,
• slot and filler systems and
• statements in mathematical logic.

The system used here will be the slot and filler system.
Take, for example sentence: ‘She found a red one she really liked’.
Event 2 Thing 1 Event2
instance : finding instance : coat instance : liking
tense : past colour : red tense : past
agent : Rani modifier : much
object : Thing1 object : Thing1
Figure 1.2 A structure Representation of a sentences
The question is stored in two forms: as input and in the above form.
ii) Algorithm
Convert the question to a structured form using English know how, then use a marker to indicate the substring
(like ‘who’ or ‘what’) of the structure, that should be returned as an answer.
If a slot and filler system is used a special marker can be placed in more than one slot.
The answer appears by matching this structured form against the structured text.
The structured form is matched against the text and the requested segments of the question are returned.

iii) Examples
Both questions 1 and 2 generate answers via a new coat and a red coat respectively.
Question 3 cannot be answered, because there is no direct response.
iv) Comments
• This approach is more meaningful than the previous one and so is more effective.
• The extra power given must be paid for by additional search time in the knowledge bases.
• A warning must be given here: that is – to generate unambiguous English knowledge base is a complex task
• and must be left until later in the course.
• The problems of handling pronouns are difficult.
For example:
Rani walked up to the salesperson: she asked where the toy department was.

SIBA ,VIJAYAPURA Page 8


Artificial Intelligence
Rani walked up to the salesperson: she asked her if she needed any help.
Whereas in the original text the linkage of ‘she’ to ‘Rani’ is easy, linkage of ‘she’ in each of the above sentences to
Rani and to the salesperson requires additional knowledge about the context via the people in a shop.

Method 3- Solution of Example-2


i) Data Structures
• World model contains knowledge about objects, actions and situations that are described in the input text.
• This structure is used to create integrated text from input text.
• The diagram shows how the system’s knowledge of shopping might be represented and stored.
• This information is known as a script and in this case it is a shopping script.
ii) Algorithm
• Convert the Input text( question) to a structured form using both the knowledge contained in Method 2 and the
World model, generating even more possible structures, since even more knowledge is being used.
• Sometimes filters are introduced to prune the possible answers.
• To answer a question, the scheme followed is: Convert the question to a structured form as before but use the
world model to resolve any ambiguities that may occur.
• The structured form is matched against the text and the requested segments of the question are returned.

iii) Example
• Both questions 1 and 2 generate answers, as in the previous program.
• Question 3 can now be answered.
• The shopping script is instantiated and from the last sentence the path through step 14 is the one used to form
the representation. ‘M’ is bound to the red coat-got home.
• ‘Rani buys a red coat’ comes from step 10 and the integrated text generates that she bought a red coat.
iv) Comments
• This program is more powerful than both the previous programs because it has more knowledge.
• Thus, like the last game program it is exploiting AI techniques.
• However, we are not yet in a position to handle any English question.
• The major omission is that of a general reasoning mechanism known as inference to be used when the
required answer is not explicitly given in the input text.
• But this approach can handle, with some modifications, questions of the following form with the answer—
Saturday morning Rani went shopping. Her brother tried to call her but she did not answer.
Question: Why couldn’t Rani’s brother reach her?
Answer: Because she was not in.
This answer is derived because we have supplied an additional fact that a person cannot be in two places at once.
This patch is not sufficiently general so as to work in all cases and does not provide the type of solution we are
really looking for.

SIBA ,VIJAYAPURA Page 9


Artificial Intelligence
1.4 LEVEL OF THE AI MODEL
‘What is our goal in trying to produce programs that do the intelligent things that people do?’
Are we trying to produce programs that do the tasks the same way that people do?
OR
Are we trying to produce programs that simply do the tasks the easiest way that is possible?
• Programs in the first class attempt to solve problems that a computer can easily solve and do not usually use AI
techniques.
• AI techniques usually include a search, as no direct method is available, the use of knowledge about the objects
involved in the problem area and abstraction on which allows an element of pruning to occur, and to enable a
solution to be found in real time; otherwise, the data could explode in size.
• Examples of these trivial problems in the first class,
• which are now of interest only to psychologists are EPAM (Elementary Perceiver and Memorizer) which
memorized garbage syllables.
The second class of problems attempts to solve problems that are non-trivial for a computer and use AI techniques.
We wish to model human performance on these:
1. To test psychological theories of human performance. Ex. PARRY [Colby, 1975] – a program to simulate the
conversational behaviour of a paranoid person.
2. To enable computers to understand human reasoning – for example, programs that answer questions based upon
newspaper articles indicating human behaviour.
3. To enable people to understand computer reasoning. Some people are reluctant to accept computer results unless
they understand the mechanisms involved in arriving at the results.
4. To exploit the knowledge gained by people who are best at gathering information. This persuaded the earlier
workers to simulate human behaviour in the SB part of AISB simulated behaviour. Examples of this type of approach
led to GPS (General Problem Solver).

Chapter 2 PROBLEMS, PROBLEM SPACES AND SEARCH


A problem is defined by its elements and their relations. To provide a formal description of a problem,
To solve the problem of building a system we should take the following steps:
1. Define the problem accurately including detailed specifications and what constitutes a suitable solution.
2. Scrutinize the problem carefully, for some features may have a central affect on the chosen method of solution.
3. Isolate and represent the task knowledge needed to solve the problem.
4. Choose the best solving techniques for the problem to solve a solution.
Problem solving is a process of generating solutions from observed data.
a ‘problem’ is characterized by
• a set of goals,
• a set of objects, and
• a set of operations.
These could be ill-defined and may evolve during problem solving.
• A ‘problem space’ is an abstract space.
A problem space encompasses all valid states that can be generated by the application of any combination of
operators on any combination of objects.
The problem space may contain one or more solutions. A solution is a combination of operations and objects
that achieve the goals.
A problem space is represented by a directed graph, where nodes represent search state and paths represent the
operators applied to change the state.
• A ‘search’ refers to the search for a solution in a problem space.
Search proceeds with different types of ‘search control strategies’.
The depth-first search and breadth-first search are the two common search strategies.

A problem is defined by its ‘elements’ and their ‘relations’. To provide a formal description of a problem, we
need to do the following:
a. Define a state space that contains all the possible configurations of the relevant objects, including some
impossible ones.

SIBA ,VIJAYAPURA Page 10


Artificial Intelligence
b. Specify one or more states that describe possible situations, from which the problem-solving process may start.
These states are called initial states.
c. Specify one or more states that would be acceptable solution to the problem. These states are called goal states.
Specify a set of rules that describe the actions (operators) available.

The problem can then be solved by using the rules, in combination with an appropriate control strategy, to move
through the problem space until a path from an initial state to a goal state is found. This process is known as
‘search’. Thus:
Search is fundamental to the problem-solving process.
Search is a general mechanism that can be used when a more direct method is not known.
Search provides the framework into which more direct methods for solving subparts of a problem can be
embedded. A very large number of AI problems are formulated as search problems.

2.1 DEFINING PROBLEM AS A STATE SPACE SEARCH


• To solve the problem of playing a game, we require the rules of the game and targets for winning as well as
representing positions in the game.
• The opening position can be defined as the initial state and a winning position as a goal state.
• Moves from initial state to other states leading to the goal state follow legally.
• The rules are far too abundant in most games— especially in chess, where they exceed the number of particles
in the universe.
• Thus, the rules cannot be supplied accurately and computer programs cannot handle easily.
• The storage also presents another problem but searching can be achieved by hashing.
• The number of rules that are used must be minimized and the set can be created by expressing each rule in a
form as possible.
• The representation of games leads to a state space representation and it is common for well-organized games
with some structure.
• This representation allows for the formal definition of a problem that needs the movement from a set of initial
positions to one of a set of target positions.
• It means that the solution involves using known techniques and a systematic search. This is quite a common
method in Artificial Intelligence.
2.1.1 State Space Search
A state space represents a problem in terms of states and operators that change states.
A state space consists of:
A representation of the states the system can be in.
For example, in a board game, the board represents the current state of the game.
A set of operators that can change one state into another state.
In a board game, the operators are the legal moves from any given state. Often the operators are represented as
programs that change a state representation to represent the new state.
An initial state.
A set of final states; some of these may be desirable, others undesirable. This set is often represented implicitly
by a program that detects terminal states.
Game: Chess Playing
Each position can be described by an 8-by-8array.
•Initial position is the game opening position.
•Goal position is any position in which the opponent does not have a legal move and his or her king is under
attack.
•Legal moves can be described by a set of rules
Left sides are matched against the current state.
Right sides describe the new resulting state
State space is a set of legal positions.
•Starting at the initial state
•Using the set of rules to move from one state to another.
•Attempting to end up in a goal state.

SIBA ,VIJAYAPURA Page 11


Artificial Intelligence
we have to write a very large number of rules since there has a separate rule for each of the roughly 10120 possible
board positions.
Using so many rules pose two serious practical difficulties
• No person could ever supply a complete set of such rules. It would take too long and could certainly not be done
without mistakes.
• No program could easily handle all those rules. Although a hashing scheme could be used to find the relevant
rules for each moves fairly and quickly, just storing that may rules poses serious difficulties.

2.1.2 The Water Jug Problem


In this problem, we use two jugs called four and three;
four holds a maximum of four gallons of water and
three a maximum of three gallons of water.
How can we get two gallons of water in the four jug?
The state space is a set of prearranged pairs giving the number of gallons of water in the pair of jugs at any time,
i.e., (four, three) where four = 0, 1, 2, 3 or 4 and three = 0, 1, 2 or 3.
The start state is (0, 0) and the goal state is (2, n) where n may be any but it is limited to three holding from 0 to 3
gallons of water or empty.
Three and four shows the name and numerical number shows the amount of water in jugs for solving the water jug
problem.
The major production rules for solving this problem are shown below:

SIBA ,VIJAYAPURA Page 12


Artificial Intelligence

Figure : One Solution to the water Jug Problem

Summary: In order to provide a formal description of a problem, it is necessary to do the following things:
✓ Define a state space that contains all the possible configurations of the relevant objects.
✓ Specify one or more states within that space that describe possible situations from which the problem-
solving process may start. These states are called initial states.
✓ Specify one or more states that would be acceptable as solutions to the problem called goal states.
✓ Specify a set of rules that describe the actions. Order of application of the rules is called control strategy.
Control strategy should cause motion towards a solution.

• The problem solved by using the production rules in combination with an appropriate control strategy, moving
through the problem space until a path from an initial state to a goal state is found.
• In this problem-solving process, search is the fundamental concept.
• For simple problems it is easier to achieve this goal by hand but there will be cases where this is far too
difficult.

2.2 PRODUCTION SYSTEMS


Production systems provide appropriate structures for performing and describing search processes.
A production system has four basic components as enumerated below.
• A set of rules each consisting of a left side that determines the applicability of the rule and a right side that
describes the operation to be performed if the rule is applied.
• A database of current facts established during the process of inference.
• A control strategy that specifies the order in which the rules will be compared with facts in the database and
also specifies how to resolve conflicts in selection of several rules or selection of more facts.
• A rule applier.

2.2.1 Control Strategies


Control Strategy decides which rule to apply next during the process of searching for a solution to a problem.
Requirements for a good Control Strategy
It should cause motion
In water jug problem, if we apply a simple control strategy of starting each time from the top of rule list and
choose the first applicable one, then we will never move towards solution.
It should explore the solution space in a systematic manner.
✓ If we choose another control strategy, say, choose a rule randomly from the applicable rules then
definitely it causes motion and eventually will lead to a solution.
✓ But one may arrive to same state several times.
✓ This is because control strategy is not systematic.

Breadth First Search BFS Algorithm


Consider the state space of a problem that takes the form of a tree. Now, if we search the goal along each breadth
of the tree, starting from the root and continuing up to the largest depth, we call it breadth first search.
• Algorithm:
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 do
a. Remove the first element from NODE-LIST and call it E. If NODE-LIST was empty, 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 return this state

SIBA ,VIJAYAPURA Page 13


Artificial Intelligence
iii. Otherwise, add the new state to the end of NODE-LIST
BFS: Water Jug Problem
• Construct a tree with the initial state of the problem as its root.
• Generate all the offspring of the root by applying each of the applicable rules to the initial state.
• For each leaf node, generate all its successors by applying all the rules that are appropriate.
• Repeat this process till we find a solution, if it exists.
Advantages
1. Guaranteed to find an optimal solution (in
terms of shortest number of steps to reach
the goal).
2. Can always find a goal node if one exists
(complete).
Disadvantages
1. High storage requirement: exponential with
tree depth

Depth First Search – DFS


Algorithm
We may sometimes search the goal along the largest depth of the tree, and move up only when further traversal
along the depth is not possible.
We then attempt to find alternative offspring of the parent of the node (state) last visited.
If we visit the nodes of a tree using the above principles to search the goal, the traversal made is called depth first
traversal and consequently the search strategy is called depth first search.
• Here, the search systematically proceeds to some depth d, before another path is considered.
• If the maximum depth of search tree is reached and if the solution has not been found, then the search
backtracks to the previous level and explores any remaining alternatives at this level, and so on.

• Algorithm:
1. If the initial state is a goal state, quit and return success.
2. Otherwise, do the following until success or failure is signaled:
• Generate a successor, E, of initial state. If there are no more successors, signal failure.
• Call Depth-First Search, with E as the initial state
• If success is returned, signal success. Otherwise continue in this loop.
✓ Here we pursue a single branch of the tree until it yields a solution or some pre- specified depth has reached.
✓ If solution is not found then go back to immediate previous node and explore other branches in DF fashion.
✓ Let us see the tree formation for water jug problem using DFS.
Advantages
1. Low storage requirement: linear with tree
depth.
2. Easily programmed: function call stack does
most of the work of maintaining state of the
search.
Disadvantages
1. May find a sub-optimal solution (one that is
deeper or more costly than the best solution).
2. Incomplete: without a depth bound, may not
find a solution even if one exists.

SIBA ,VIJAYAPURA Page 14


Artificial Intelligence
Travelling Salesman Problem
Consider 5 cities.
A salesman is supposed to visit each of 5 cities.
All cities are pair wise connected by roads.
There is one start city.
The problem is to find the shortest route for the
salesman who has to
✓ visit each city only once and
✓ returns to back to start city.
A simple motion causing and systematic control structure could, in principle solve this problem.
Explore the search tree of all possible paths and return the shortest path.
This will require 4! paths to be examined.
If number of cities grow, say 25 cities, then the time required to wait a salesman to get the information about the
shortest path is of 0(24!) which is not a practical situation.
This phenomenon is called combinatorial explosion.
We can improve the above strategy as follows:
Begin generating complete paths, keeping track of the shortest path found so far.
Give up exploring any path as soon as its partial length becomes greater than the shortest path found so far.
This algorithm is efficient than the first one, still requires exponential time
some number raised to N (number of cities).

2.3 Problem Characteristics


Heuristics are criteria for deciding which among several alternatives be the most effective in order to achieve some
goal.
it is necessary to analyse the problem along several key dimensions:
✓ Is the problem decomposable into a set of (nearly) independent smaller or easier subproblems?
✓ Can solution steps be ignored or at least undone if they prove unwise?
✓ Is the problem's universe predictable?
✓ Is a good solution to the problem obvious without comparison to all other possible solutions?
✓ Is the desired solution a 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 that is simply given the problem return the solution, or will the solution of the problem
require interaction between the computer and a person?
2.3.1 Is the Problem Decomposable?
Suppose to solve the expression is:
✓ This problem can be solved by breaking it into
smaller problems, each of which we can solve by
✓ using a small collection of specific rules.
✓ Using this technique of problem decomposition,
we can solve very large problems very easily.
This can be considered as an intelligent
behaviour.

2.3.2 Can Solution Steps be Ignored?


Suppose we are trying to prove a mathematical theorem:
✓ first we proceed considering that proving a lemma will be useful.
✓ Later we realize that it is not at all useful. We start with another one to prove the theorem. Here we
simply ignore the first method.
✓ Consider the 8-puzzle problem to solve: we make a wrong move and realize that mistake. But

SIBA ,VIJAYAPURA Page 15


Artificial Intelligence
✓ here, the control strategy must keep track of all the moves, so that we can backtrack to the initial state
and start with some new move.
✓ Consider the problem of playing chess. Here, once we make a move we never recover from that step.
These problems are illustrated in the three important classes of problems mentioned below:
1. Ignorable, in which solution steps can be ignored. Eg: Theorem Proving
2. Recoverable, in which solution steps can be undone. Eg: 8-Puzzle
3. Irrecoverable, in which solution steps cannot be undone. Eg: Chess
Example: Eight puzzle (8-Puzzle)
✓ The 8-puzzle is a 3 × 3 array containing eight square pieces, numbered 1 through 8, and one empty space.
✓ A piece can be moved horizontally or vertically into the empty space, in effect exchanging the positions of
the piece and the empty space.
✓ There are four possible moves, UP (move the blank space up), DOWN, LEFT and RIGHT.
✓ The aim of the game is to make a sequence of moves that will convert the board from the start state into the
goal state:
1 3 4
8 6 2
7 5
Initial State

This example can be solved by the operator sequence UP, RIGHT, UP, LEFT, DOWN.

2.3.3 Is the Problem Universe Predictable?


✓ Consider the 8-Puzzle problem. 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 what the resulting state
will be. We can backtrack to earlier moves if they prove unwise.
✓ Suppose we want to play Bridge. We need to plan before the first play, but we cannot play with certainty. So,
the outcome of this game is very uncertain. In case of 8-Puzzle, the outcome is very certain.
✓ To solve uncertain outcome problems, we follow the process of plan revision as the plan is carried out and
the necessary feedback is provided.
✓ The disadvantage is that the planning in this case is often very expensive.

2.3.4 Is Good Solution Absolute or Relative?


Consider the problem of answering questions based on a database of simple facts such as the following:
1. Marcus was a man.
2. Marcus was a worker in a company.
3. Marcus was born in 1905.
4. All men are mortal.
5. All workers in a factory died when there was an accident in 1952.
6. No mortal lives longer than 100 years.
Suppose we ask a question: ‘Is Marcus alive?’
By representing these facts in a formal language, such as predicate logic, and then using formal inference
methods we can derive an answer to this question easily.
There are two ways to answer the question shown below:
Method I:
1. Marcus was a man.
2. Marcus was born in 1905.
3. All men are mortal.
4. Now it is 2023, so Marcus’s age is 118 years.
5. No mortal lives longer than 100 years.
Method II:
1. Marcus is a worker in the company.
2. All workers in the company died in 1952.
Answer: So, Marcus is not alive. It is the answer from the above methods.
We are interested to answer the question; it does not matter which path we follow. If we follow

SIBA ,VIJAYAPURA Page 16


Artificial Intelligence
one path successfully to the correct answer, then there is no reason to go back and check another path to lead
the solution.
2.3.5 Is the solution a state or a path?
Consider the problem of finding a consistent interpretation for the sentence
The bank president ate a dish of pasta salad with the fork.

There are several components of this sentence, each of which, in isolation, may have more than one interpretation.
But the components must form a coherent whole, and so they constrain each other's interpretations. Some of the
sources of ambiguity in this sentence are the following:

• The word "bank" may refer either to a financial institution or to a side of a river. But only one of these
may have a president.
• The word "dish" is the object of the verb "eat." It is possible that a dish was eaten. But it is more likely that
the pasta salad in the dish was eaten.
• Pasta salad is a salad containing pasta. But there are other ways meanings can be formed from pairs of
nouns. For example, dog food does not normally contain dogs.
• The phrase "with the fork" could modify several parts of the sentence. In this case, it modifies the verb
"eat." But, if the phrase had been "with vegetables," then the modification structure would be different.
And if the phrase had been "with her friends," the structure would be different still.

2.3.6 What is the role of knowledge?


✓ The size of the knowledge base available for solving the problem does matter in arriving at a good
solution.
✓ Take for example the game of playing chess, just the rules for determining legal moves and some simple
control mechanism is sufficient to arrive at a solution.
✓ Additional knowledge about good strategy and tactics could help to constrain the search and speed up the
execution of the program

2.3.7 Does the task require interaction with a person?


The problems can again be categorized under two heads.
Solitary
• Computer will be given a problem description and will produce an answer
• No intermediate communication and with the demand for an explanation of the reasoning process.
Example: Simple theorem proving
Conversational,
• There will be intermediate communication between a person and the computer
• Provides additional assistance to the computer or additional information to the user, or both.
Example: Medical diagnosis

2.4 Production System Characteristics


Production systems provide us with good ways of describing the operations that can be performed in a search
for a solution to a problem.
At this time, two questions may arise:
1. Can production systems be described by a set of characteristics? And how can they be easily implemented?
2. What relationships are there between the problem types and the types of production systems well suited for
solving the problems?
To answer these questions, first consider the following definitions of classes of production systems:
1. A monotonic production system is a production system in which the application of a rule never prevents the
later application of another rule that could also have been applied at the time the first rule was selected.
2. A non-monotonic production system is one in which this is not true.
3. A partially communicative production system is a production system with the property that if the
application of a particular sequence of rules transforms state P into state Q, then any combination of those rules
that is allowable also transforms state P into state Q.

SIBA ,VIJAYAPURA Page 17


Artificial Intelligence
4. A commutative production system is a production system that is both monotonic and partially
commutative.

Chapter 3 Heuristic search techniques


Introduction
A Heuristic technique helps in solving problems, even though there is no guarantee that it will never lead in the
wrong direction.
There are heuristics of every general applicability as well as domain specific.
The strategies are general purpose heuristics.
In order to use them in a specific domain they are coupler with some domain specific heuristics.
There are two major ways in which domain - specific, heuristic information can be incorporated into rule-based
search procedure.
A heuristic function is a function that maps from problem state description to measures desirability,
usually represented as number weights. The value of a heuristic function at a given node in the search process
gives a good estimate of that node being on the desired path to solution.

The algorithms that use heuristic functions are called heuristic algorithms.
Heuristic algorithms are not really intelligent; they appear to be intelligent because they achieve better
performance.
Heuristic algorithms are more efficient because they take advantage of feedback from the data to direct the
search path.

A good heuristic will make an informed search :


for example, the Traveling Salesman Problem (TSP), where the goal is to find is a good solution instead of
finding the best solution.
In such problems, the search proceeds using current information about the problem to predict which path is
closer to the goal and follow it, although it does not always guarantee to find the best possible solution. Such
techniques help in finding a solution within reasonable time and space (memory).

Some prominent intelligent search algorithms are stated below:


1. Generate and Test Search
2. Best-first Search
3. Greedy Search
4. A* Search
5. Constraint Search
6. Means-ends analysis

There are some more algorithms. They are either improvements or combinations of these.
• Hierarchical Representation of Search Algorithms: A Hierarchical representation of most search algorithms is
illustrated below. The representation begins with two types of search:
• Uninformed Search: Also called blind, exhaustive or brute-force search, it uses no information about the
problem to guide the search and therefore may not be very efficient.
Uninformed search algorithms or Brute-force algorithms, search through the search space all possible
candidates for the solution checking whether each candidate satisfies the problem’s statement.

• Informed Search: Also called heuristic or intelligent search, this uses information about the problem to guide
the search—usually guesses the distance to a goal state and is therefore efficient, but the search may not be
always possible.

SIBA ,VIJAYAPURA Page 18


Artificial Intelligence
Informed search algorithms use heuristic functions that are specific to the problem, apply them to guide the
search through the search space to try to reduce the amount of time spent in searching.

Figure: Different Search Algorithm


A heuristic is a method that improves the efficiency of the search process.
These are like tour guides.
There are good to the level that they may neglect the points in general interesting directions; they are bad to
the level that they may neglect points of interest to particular individuals.
Some heuristics help in the search process without sacrificing any claims to entirety that the process might
previously had.
Others may occasionally cause an excellent path to be overlooked. By sacrificing entirely it increases
efficiency.
Heuristics may not find the best solution every time but guarantee that they find a good solution in a
reasonable time.
These are particularly useful in solving tough and complex problems, solutions of which would require infinite
time, i.e. far longer than a lifetime for the problems which are not solved in any other way.

Heuristic search
To find a solution in proper time rather than a complete solution in unlimited time we use heuristics. ‘A
heuristic function is a function that maps from problem state descriptions to measures of desirability, usually
represented as numbers’.
Heuristic search methods use knowledge about the problem domain and choose promising operators first. These
heuristic search methods use heuristic functions to evaluate the next state towards the goal state.
For finding a solution, by using the heuristic technique, one should carry out the following steps:
1. Add domain—specific information to select what is the best path to continue searching along.
2. Define a heuristic function h(n) that estimates the ‘goodness’ of a node n.
Specifically, h(n) = estimated cost(or distance) of minimal cost path from n to a goal state.
3. The term, heuristic means ‘serving to aid discovery’ and is an estimate, based on domain specific
information that is computable from the current state description of how close we are to a goal.

Finding a route from one city to another city is an example of a search problem in which different search orders
and the use of heuristic knowledge are easily understood.
1. State: The current city in which the traveller is located.
2. Operators: Roads linking the current city to other cities.
3. Cost Metric: The cost of taking a given road between cities.
4. Heuristic information: The search could be guided by the direction of the goal city from the current city, or
we could use airline distance as an estimate of the distance to the goal.

Heuristic search techniques


For complex problems, the traditional algorithms, presented above, are unable to find the solution within some
practical time and space limits.
SIBA ,VIJAYAPURA Page 19
Artificial Intelligence
Consequently, many special techniques are developed, using heuristic functions.
• Blind search is not always possible, because it requires too much time or Space (memory).
Heuristics are rules of thumb; they do not guarantee a solution to a problem.
• Heuristic Search is a weak technique but can be effective if applied correctly; it requires domain specific
information.
Properties of a Heuristic Search Algorithm
Heuristic search algorithms have the following properties:
Admissible Condition: If an algorithm produces an optimal result, it is considered admissible.
Completeness: If an algorithm ends with a solution, it is considered complete.
Dominance Property: If A1 and A2 are two heuristic algorithms and have h1 and h2 heuristic functions,
respectively, then A1 Will dominate A2 if h1 is superior to h2 for all possible values of node n.
Optimality Property: If an algorithm is thorough, allowable, and dominates the other algorithms, that'll be
the optimal one and will unquestionably produce an optimal result.

Characteristics of heuristic search


• Heuristics are knowledge about domain, which help search and reasoning in its domain.
• Heuristic search incorporates domain knowledge to improve efficiency over blind search.
• Heuristic is a function that, when applied to a state, returns value as estimated merit of state, with respect to
goal.
• Heuristics might (for reasons) underestimate or overestimate the merit of a state with respect to goal.
• Heuristics that underestimate are desirable and called admissible.
• Heuristic evaluation function estimates likelihood of given state leading to goal state.
• Heuristic search function estimates cost from current state to goal, presuming function is efficient.

Heuristic search compared with other search


The Heuristic search is compared with Brute force or Blind search techniques below:
Comparison of Algorithms
Brute force / Blind search Heuristic search

Can only search what it has knowledge about already Estimates ‘distance’ to goal state through
explored nodes
No knowledge about how far a node node from goal state Guides search process toward goal
Prefers states (nodes) that lead close to and not
away from goal state

3.1 Generate And Test


Generate-And-Test Algorithm
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: Generate-And-Test
1.Generate a possible solution.
2.Test to see if this is the expected solution.
3.If the solution has been found quit else go to
step 1.
Potential solutions that need to be generated
vary depending on the kinds of problems. For
some problems the possible solutions may be
particular points in the problem space and for
some problems, paths from the start state.

SIBA ,VIJAYAPURA Page 20


Artificial Intelligence
Figure: Generate And Test
✓ Generate-and-test, like depth-first search, requires that complete solutions be generated for testing.
✓ In its most systematic form, it is only an exhaustive search of the problem space.
✓ Solutions can also be generated randomly but solution is not guaranteed. This approach is what is
✓ known as British Museum algorithm: finding an object in the British Museum by wandering
randomly.

Systematic Generate-And-Test
✓ While generating complete solutions and generating random solutions are the two extremes there exists
another approach that lies in between.
✓ The approach is that the search process proceeds systematically but some paths that unlikely to lead the
solution are not considered.
✓ This evaluation is performed by a heuristic function.
✓ Depth-first search tree with backtracking can be used to implement systematic generate-and-test
procedure.
✓ As per this procedure, if some intermediate states are likely to appear often in the tree, it would be better
to modify that procedure to traverse a graph rather than a tree.

Generate-And-Test And Planning


✓ Exhaustive generate-and-test is very useful for simple problems.
✓ But for complex problems even heuristic generate-and-test is not very effective technique.
✓ But this may be made effective by combining with other techniques in such a way that the space in
which to search is restricted.
An AI program DENDRAL, for example, uses plan-Generate-and-test technique.
✓ First, the planning process uses constraint-satisfaction techniques and creates lists of recommended
and contraindicated substructures.
✓ Then the generate-and-test procedure uses the lists generated and required to explore only a limited set
of structures.
✓ Constrained in this way, generate-and-test proved highly effective.
✓ A major weakness of planning is that it often produces inaccurate solutions as there is no feedback from
the world.
✓ But if it is used to produce only pieces of solutions then lack of detailed accuracy becomes unimportant.

3.2 Hill Climbing


Hill Climbing is heuristic search used for mathematical optimization problems in the field of Artificial Intelligence
Given a large set of inputs and a good heuristic function, it tries to find a sufficiently good solution to the problem.

This solution may not be the global optimal maximum.


In the above definition, mathematical optimization problems implies that hill climbing solves the problems
where we need to maximize or minimize a given real function by choosing values from the given inputs.
Example-Travelling salesman problem where we need to minimize the distance travelled by salesman.
‘Heuristic search’ means that this search algorithm may not find the optimal solution to the problem. However,
it will give a good solution in reasonable time.
A heuristic function is a function that will rank all the possible alternatives at any branching step in search
algorithm based on the available information. It helps the algorithm to select the best route out of possible routes.

Features of Hill Climbing


1. Variant of generate and test algorithm: It is a variant of generate and test algorithm. The generate and test
algorithm is as follows:
1. Generate a possible solution.
2. Test to see if this is the expected solution.
3. If the solution has been found quit else go to step 1.
Hence we call Hill climbing as a variant of generate and test algorithm as it takes the feedback from test
procedure. Then this feedback is utilized by the generator in deciding the next move in search space.
2. Uses the Greedy approach : At any point in state space, the search moves in that direction only which
optimizes the cost of function with the hope of finding the optimal solution at the end.
SIBA ,VIJAYAPURA Page 21
Artificial Intelligence

Types of Hill Climbing


1. Simple Hill climbing : It examines the neighboring nodes one by one and selects the first neighboring node
which optimizes the current cost as next node.
3.2.1 Algorithm for Simple Hill climbing :
Step 1 : Evaluate the initial state. If it is a goal state then stop and return success. Otherwise, make initial state as
current state.
Step 2 : Loop until the solution state is found or there are no new operators present which can be applied to current
state.
a) Select a state that has not been yet applied to the current state and apply it to produce a new state.
b) Perform these to evaluate new state
i. If the current state is a goal state, then stop and return success.
ii. If it is better than the current state, then make it current state and proceed further.
iii. If it is not better than the current state, then continue in the loop until a solution is found.
Step 3 : Exit.

3.2.2. Steepest-Ascent Hill climbing : It first examines all the neighbouring nodes and then selects the node
closest to the solution state as next node.
Step 1 : Evaluate the initial state. If it is goal state then exit else make the current state as initial state
Step 2 : Repeat these steps until a solution is found or current state does not change
i. Let ‘target’ be a state such that any successor of the current state will be better than it;
ii. for each operator that applies to the current state
a. apply the new operator and create a new state
b. evaluate the new state
c. if this state is goal state then quit else compare with ‘target’
d. if this state is better than ‘target’, set this state as ‘target’
e. if target is better than current state set current state to Target
Step 3 : Exit

3.3.3. Stochastic hill climbing : It does not examine all the neighbouring nodes before deciding which node to
select .It just selects a neighbouring node at random, and decides (based on the amount of improvement in that
neighbour) whether to move to that neighbour or to examine another.
State Space diagram for Hill Climbing

State space diagram is a graphical representation of the set of states our search algorithm can
reach vs the value of our objective function(the function which we wish to maximize).
X-axis : denotes the state space ie states or configuration our algorithm may reach.
Y-axis : denotes the values of objective function corresponding to to a particular state.
The best solution will be that state space where objective function has maximum value(global maximum).
Different regions in the State Space Diagram
1. Local maximum : It is a state which is better than its neighbouring state however there exists a state which is
better than it(global maximum). This state is better because here value of objective function is higher than its
neighbours
2. Global maximum : It is the best possible state in the state space diagram. This because at this state, objective
function has highest value.
3. Plateua/flat local maximum : It is a flat region of state space where neighbouring states have the same value.

SIBA ,VIJAYAPURA Page 22


Artificial Intelligence
4. Ridge : It is region which is higher than its neighbours but itself has a slope. It is a special kind of local
maximum.
5. Current state : The region of state space diagram where we are currently present during the search.
6. Shoulder : It is a plateau that has an uphill edge.
Problems in different regions in Hill climbing
Hill climbing cannot reach the optimal/best state(global maximum) if it enters any of the following regions :
1. Local maximum : At a local maximum all neighboring states have a values which is worse than than the
current state. Since hill climbing uses greedy approach, it will not move to the worse state and terminate itself. The
process will end even though a better solution may exist.
To overcome local maximum problem : Utilize backtracking technique. Maintain a list of visited states. If the
search reaches an undesirable state, it can backtrack to the previous configuration and explore a new path.
2. Plateau : On plateau all neighbors have same value . Hence, it is not possible to select the
best direction.
To overcome plateaus : Make a big jump. Randomly select a state far away from current state. Chances are that we
will land at a non-plateau region
3. Ridge : Any point on a ridge can look like peak because movement in all possible directions is downward.
Hence the algorithm stops when it reaches this state.
To overcome Ridge : In this kind of obstacle, use two or more rules before testing. It implies moving in several
directions at once.

3.3 Best First Search (Informed Search)


A combination of depth first and breadth first searches.
✓ Depth first is good because a solution can be found without computing all nodes
✓ breadth first is good because it does not get trapped in dead ends.
✓ One way of combining the two is to follow a single path a time, best first search allows us to switch between
paths thus gaining the benefit of both approaches.
✓ At each step the most promising node is chosen, this is done by applying appropriate heuristic function to
each of them.
✓ In best first search, one move is selected but the other are kept around so that they can be revisited later if
the selected path becomes less promising
✓ If one of the nodes chosen generates nodes that are less promising it is possible to choose another at the
same level and in effect the search changes from depth to breadth.
✓ It is sometimes important to search a graph instead of tree so that duplicate path will not be pursed.
✓ Each node in a graph have
o Point in the problem space
o Description of the problem space state it represent
o A list of nodes that were generated from it
o A parent link that point back to the best node from which it come
To implement such a graph search procedure we will need to use two list of nodes.

OPEN -nodes that has been generated and have heuristic function applied to them but which have been not
examined yet.
It is a priority queue of nodes that have been evaluated by the heuristic function but which have not yet been
expanded into successors. The most promising nodes are at the front.
CLOSED are nodes that have already been examined and we need to keep this node in memory if we want to
search a graph rather than a tree. Since whenever new node is generated, we need to check whether it has been
generated before.
Algorithm: Best first search (OR graph)
1. Start with OPEN holding the initial state
2. Until a goal is found or there are no nodes left on open do.
Pick the best node on OPEN
Generate its successors
For each successor Do
• If it has not been generated before, evaluate it, add it to OPEN and record its parent
• If it has been generated before change the parent if this new path is better and, in that case, update the cost
of getting to any successor nodes.
SIBA ,VIJAYAPURA Page 23
Artificial Intelligence

Observations
In hill climbing, sorting is done on the successors nodes whereas in the best first search sorting is done on
the entire list.
It is not guaranteed to find an optimal solution, but normally it finds some solution faster than any other
methods.
The performance varies directly with the accuracy of the heuristic evaluation function.
Termination Condition: Instead of terminating when a path is found, terminate when the shortest incomplete
path is longer than the shortest complete path.

Heuristics function: Heuristic is a function which is used in Informed Search, and it finds the most promising path. It takes
the current state of the agent as its input and produces the estimation of how close agent is from the goal. The heuristic method,
however, might not always give the best solution, but it guaranteed to find a good solution in reasonable time. Heuristic function
estimates how close a state is to the goal. It is represented by h(n), and it calculates the cost of an optimal path between the
pair of states. The value of the heuristic function is always positive.
h(n) <= h*(n)
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should be less than or equal to the
estimated cost.

BFS EXAMPLE( OR graph)

In this search example, we are using two lists which are OPEN and CLOSED Lists. Following are the iteration for
traversing the above example.
Expand the nodes of S and put in the CLOSED list
Initialization: Open [A, B], Closed [S]
Iteration 1: Open [A], Closed [S, B]
Iteration 2: Open [A,E,F], Closed [S, B]
: Open [ A,E], Closed [S, B, F]

Iteration 3: Open [A,E, I, G], Closed [S, B, F]


: Open [A,E, I], Closed [S, B, F, G]
Hence the final solution path will be: S--> B-->F--> G

Time Complexity: The worst case time complexity of Greedy best first search is O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is O(bm). Where, m is the maximum
depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite.
Optimal: Greedy best first search algorithm is not optimal.

3.3.2 A* search
A* (“Aystar”) (Hart, 1972) method is a combination of branch & bound and best search, combined with the
dynamic programming principle.

SIBA ,VIJAYAPURA Page 24


Artificial Intelligence
• The heuristic function (or Evaluation function) for a node N is defined as f(N) = g(N) + h(N)

• The function g is a measure of the cost of getting from the Start node (initial state) to the current node.
• It is sum of costs of applying the rules that were applied along the best path to the current node.
• The function h is an estimate of additional cost of getting from the current node to the Goal node (final state).
• Here knowledge about the problem domain is exploited.
• A* algorithm is called OR graph / tree search algorithm.

Algorithm (A*)
Step1: Initialization OPEN list with initial node; CLOSED= ∅; g = 0, f = h, Found = false;
Place the starting node in the OPEN list.
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 evaluation function (g+h), if node
n is 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 evaluation function for n' and
place into 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.
Step 6: Return to Step 2.

Behavior of A* Algorithm
Underestimation
If we can guarantee that h never over estimates actual value from current to goal, then A* algorithm is guaranteed
to find an optimal path to a goal, if one exists
Example – Underestimation – f=g+h Here h is underestimated

Initialization: {(S, 5)}


Iteration1: S--> A : f(A)=g(A)+h(A)=1+3=4
S-->G: f(G)=g(G)+h(G)= 10+0=10
{(S--> A, 4), (S-->G, 10)}

Iteration2: S--> A-->C : f(C)=g(A)+g(C)+h(C)=1+1+2=4


S--> A-->B : f(B)=g(A)+g(B)+h(B)=1+2+4=7
S-->G: f(G)=g(G)+h(G)= 10+0=10
{(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}

SIBA ,VIJAYAPURA Page 25


Artificial Intelligence
Iteration3: S--> A-->C--->G : f(C)=g(A)+g(C)+g(G)+h(G)=1+1+4+0=6
S--> A-->C--->D : f(C)=g(A)+g(C)+g(D)+h(D)=1+1+3+6=11
S--> A-->B : f(B)=g(A)+g(B)+h(B)=1+2+4=7
S-->G : f(G)=g(G)+h(G)= 10+0=10

{(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with cost 6.

Admissibility of A*:
A search algorithm is admissible, if  for any graph, it always terminates in an optimal path from initial state to
goal state, if path exists.
If heuristic function h is underestimate of actual value from current state to goal state, then the it is called
admissible function.
Alternatively we can say that A* always terminates with the optimal path in case h(x) is an admissible heuristic
function.

Advantages:
A* search algorithm is the best algorithm than other search algorithms.
A* search algorithm is optimal and complete.
This algorithm can solve very complex problems.
Disadvantages:
It does not always produce the shortest path as it mostly based on heuristics and approximation.
A* search algorithm has some complexity issues.
The main drawback of A* is memory requirement as it keeps all generated nodes in the memory, so it is not
practical for various large-scale problems.

3.4 Problem Reduction


Algorithm: Problem Reduction
Thus we can see that to search an AND-OR graph, the following three things must be done.
1. Initialize the graph to the starting node
2. Loop until the starting node is labelled SOLVED or until its cost goes above FUYTILITY.
a. traverse the graph starting at the initial node and following the current best path, and accumulate the set of
nodes that are on the path and have not yet been expanded.
b. Pick one of these unexpanded nodes and expand it. Add its successors to the graph and computer f ' (cost
of the remaining distance) for each of them.
c. Change the f' estimate of the newly expanded node to reflect the new information produced by its
successors. Propagate this change backward through the graph. Decide which of the current best path.

The propagation of revised cost estimation backward is in the tree is not Tabu Search necessary in A*
algorithm. This is because in AO* algorithm expanded nodes are re-examined so that the current best path
can be selected.

3.4.1 And-OR graph


Best-first search is what the And-OR algorithm does.
The And-OR method divides any given
difficult problem into a smaller group of problems that
are then resolved using the AND-OR graph concept.
AND OR graphs are specialized graphs that are used in
problems that can be divided into smaller problems.
• The AND side of the graph represents a set of tasks that
must be completed to achieve the main goal,
• while the OR side of the graph represents different
methods for accomplishing the same main goal.

SIBA ,VIJAYAPURA Page 26


Artificial Intelligence
• In the above figure, the buying of a car may be broken down into smaller problems or tasks that can
be accomplished to achieve the main goal in the above figure, which is an example of a simple AND-
OR graph.
• The other task is to either steal a car that will help us accomplish the main goal or use your own money
to purchase a car that will accomplish the main goal.
• The AND symbol is used to indicate the AND part of the graphs, which refers to the need that all
subproblems containing the AND to be resolved before the preceding node or issue may be finished.
• The start state and the target state are already known in the knowledge-based search strategy known as
the AO* algorithm, and the best path is identified by heuristics.
• The informed search technique considerably reduces the algorithm’s time complexity. The AO*
algorithm is far more effective in searching AND-OR trees than the A* algorithm.

ALGORITHM:The A0*

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 of CURRENT to S.

Working of AO* algorithm:


The evaluation function in AO* looks like this:
f(n) = g(n) + h(n) here,
f(n) = Actual cost + Estimated cost f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.

Example 1
• A is the only node, it is at the end of the current best path.
• It is expanded, 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.

Node B 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.

SIBA ,VIJAYAPURA Page 27


Artificial Intelligence
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(since that is the best we think
we can do, which we can achieve by going through G).
This requires updating the cost of the AND arc B-C to 12(6+4+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.

Example 2

Start from node A,


f(A⇢B) = g(B) + h(B)= 1 + 5 =6
here g(n)=1 is taken by default for path cost
f(A⇢C+D) = g(c) + h(c) + g(d) + h(d)
=1+2+1+4 =8
…here we have added C & D because they are in AND
So, by calculation A⇢B path is chosen which is the
minimum path, i.e f(A⇢B)

SIBA ,VIJAYAPURA Page 28


Artificial Intelligence
According to the answer of step 1, explore node B
Here the value of E & F are calculated as follows,
f(B⇢E) = g(e) + h(e)
f(B⇢E) = 1 + 7 = 8
f(B⇢f) = g(f) + h(f)
f(B⇢f) = 1 + 9 = 10
So, by above calculation B⇢E path is chosen which is
minimum path, i.e f(B⇢E)
because B's heuristic value is different from its actual
value The heuristic is
updated and the minimum cost path is selected. The
minimum value in our situation is 8.
Therefore, the heuristic for A must be updated due to the
change in B's heuristic.
So we need to calculate it again.
f(A⇢B) = g(B) + updated h(B) = 1 + 8 = 9
We have Updated all values in the above tree.

By comparing f(A⇢B) & f(A⇢C+D)


f(A⇢C+D) is shown to be smaller. i.e 8 < 9
Now explore f(A⇢C+D)
So, the current node is C

f(C⇢G) = g(g) + h(g)


f(C⇢G) = 1 + 3
=4

f(C⇢H+I) = g(h) + h(h) + g(i) + h(i)


f(C⇢H+I) = 1 + 0 + 1 + 0 ……here we have
added H & I because they are in AND
=2

f(C⇢H+I) is selected as the path with the lowest cost and


the heuristic is also left unchanged
because it matches the actual cost. Paths H & I are solved
because the heuristic for those paths is 0,
but Path A⇢D needs to be calculated because it has an
AND.

f(D⇢J) = g(j) + h(j)


f(D⇢J) = 1 + 0 = 1
the heuristic of node D needs to be updated to 1.

f(A⇢C+D) = g(c) + h(c) + g(d) + h(d)


=1+2+1+1=5

as we can see that path f(A⇢C+D) is get solved and this


tree has become a solved tree now.
In simple words, the main flow of this algorithm is that we
have to find firstly level 1st heuristic value and then level
2nd and after that update the values with going upward
means towards the root node.
In the above tree diagram, we have updated all the values

SIBA ,VIJAYAPURA Page 29


Artificial Intelligence
3.5 Constraint Satisfaction
Many AI problems can be viewed as problems of constrained satisfaction in which the goal is to solve some
problem state that satisfies a given set of constraints.
Example of such a problem are

• Crypt-Arithmetic puzzles.
• Many design tasks can also be viewed as constrained satisfaction problems.
• N-Queen: Given the condition that no two queens on the same row/column/diagonal attack each other.
• Map colouring: Given a map, colour three regions in blue, red and black, such that no two
neighbouring regions have the same colour.
• Such problems do not require a new search method.

Algorithm:

1. Propagate available constraints. To do this first set OPEN to set of all objects that must have values assigned

to them in a complete solution. Then do until an inconsistency is detected or until OPEN is empty:

a. Select an object OB from OPEN. Strengthen as much as possible the set of constraints that apply to OB.

b. If this set is different from the set that was assigned the last time OB was examined or if this is the first

time OB has been examined, then add to OPEN all objects that share any constraints with OB.

c. Remove OB from OPEN.

2. If the union of the constraints discovered above defines a solution, then quit and report the solution.

3. If the union of the constraints discovered above defines a contradiction, then return the failure.

4. If neither of the above occurs, then it is necessary to make a guess at something in order to proceed. To

do this loop until a solution is found or all possible solutions have been eliminated:

a.Select an object whose value is not yet determined and select a way of strengthening the constraints

on that object.

b. Recursively invoke constraint satisfaction with the current set of constraints augmented by

strengthening constraint just selected.

2.6.1.Crypt-Arithmetic puzzle

Problem Statement:

Solve the following puzzle by assigning numeral (0-9) in such a way that each letter is assigned unique
digit which satisfy the following addition.

Constraints : No two letters have the same value. (The constraints of arithmetic).

Initial Problem State S = ? ; E = ? ;N = ? ; D = ? ; M = ?


;O = ? ; R = ? ;Y = ?

Carries : C4 = ? ; C3 = ? ; C2 = ? ; C1 = ?
CONSTRAINTS:-

1. no two digits can be assigned to same letter. only single digit number can be assigned to a letter.
2. Assumption can be made at various levels such that they do not contradict each other.
SIBA ,VIJAYAPURA Page 30
Artificial Intelligence
3. The problem can be decomposed into secured constraints. A constraint satisfaction approach may be used.
4. Any of search techniques may be used.
5. Backtracking may be performed as applicable us applied search techniques.
6. Rule of arithmetic may be followed.

Goal State: the digits to the letters must be assigned in such a manner so that the sum is satisfied

Constraint Equation

We can easily see that M has to be non zero digit, so the value of C4 =1

1. M = C4 => M = 1

2. O = S + M + C3 -> C4

For C4 =1, S + M + C3 > 9 =>

S + 1 + C3 > 9 => S+C3 > 8.

If C3 = 0, then S = 9 else if C3 = 1,

then S = 8 or 9.

We see that for S = 9

C3 = 0 or 1

It can be easily seen that C3 = 1 is not possible as O = S + M + C3

=> O = 11 => O has to be assigned digit 1 but 1 is already assigned to M, so not possible.

Therefore, only choice for C3 = 0, and thus O = 10. This implies that O is assigned 0 (zero) digit.
Therefore, O = 0 M = 1, O = 0
Since C3 = 0; N = E + O + C2 produces no carry.

• As O = 0, N = E + C2 .
• Since N  E, therefore, C2 = 1.

From Y = D + E , we get 10 + Y= D + 2 . For no value of D, we can get Y.

Try similarly for E = 3, 4. We fail in each case.


If E = 5, then N = 6

Since C2 = 1, from E = N + R + C1 , we get 15 = N + R + C1 ,

If C1 = 0 then R = 9, which is not possible as we are on the path

with S = 9.

SIBA ,VIJAYAPURA Page 31


Artificial Intelligence
If C1 = 1 then R = 8, then
From Y = D + E , we get 10 + Y= D + 5 i.e., 5 + Y = D.
If Y = 2 then D = 7. These values are possible.
Hence we get the final solution as given below and on
backtracking, we may find more solutions.

Solving a Cryptarithmetic Problem

3.6 Means End Analysis


• Strategies which can reason either in forward or backward
• but a mixture of the two directions is appropriate for solving a complex and large problem.
• Such a mixed strategy, make it possible that
✓ first to solve the major part of a problem and
✓ then go back and solve the small problems arise during combining the big parts of the problem.
Such a technique is called Means-Ends Analysis.
o Means-Ends Analysis is problem-solving techniques used in Artificial intelligence for limiting search in
AI programs.
o It is a mixture of Backward and forward search technique.
o The MEA technique was first introduced in 1961 by Allen Newell, and Herbert A. Simon in their problem-
solving computer program, which was named as General Problem Solver (GPS).
o The MEA analysis process cantered on the evaluation of the difference between the current state and goal
state.
How means-ends analysis Works:
The means-ends analysis process can be applied recursively for a problem. It is a strategy to control search in
problem-solving. Following are the main Steps which describes the working of MEA technique for solving a
problem.
i. First, evaluate the difference between Initial State and final State.
ii. Select the various operators which can be applied for each difference.
iii. Apply the operator at each difference, which reduces the difference between the current state and goal
state.
Operator Subgoaling

SIBA ,VIJAYAPURA Page 32


Artificial Intelligence
In the MEA process, we detect the differences between the current state and goal state. Once these differences
occur, then we can apply an operator to reduce the differences. But sometimes it is possible that an operator
cannot be applied to the current state. So we create the subproblem of the current state, in which operator can
be applied, such type of backward chaining in which operators are selected, and then sub goals are set up to
establish the preconditions of the operator is called Operator Subgoaling.

Algorithm for Means-Ends Analysis:


Let's we take Current state as CURRENT and Goal State as GOAL, then following are the steps for the MEA
algorithm.
Step 1: Compare CURRENT to GOAL, if there are no differences between both then return Success and Exit.
Step 2: Else, select the most significant difference and reduce it by doing the following steps until the success
or failure occurs.
Select a new operator O which is applicable for the current difference, and if there is no such operator, then
signal failure.
Attempt to apply operator O to CURRENT. Make a description of two states.
i) O-Start, a state in which O?s preconditions are satisfied.
ii) O-Result, the state that would result if O were applied In O-start.
iii)If(First-Part <------ MEA (CURRENT, O-START)
And
(LAST-Part <----- MEA (O-Result, GOAL),
are successful, then signal Success and return the result of combining
FIRST-PART, O, and LAST-PART.

SIBA ,VIJAYAPURA Page 33


Artificial Intelligence

SIBA ,VIJAYAPURA Page 34

You might also like