0% found this document useful (0 votes)
10 views44 pages

Module - 1

Uploaded by

inzamamgmd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
10 views44 pages

Module - 1

Uploaded by

inzamamgmd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 44

Principles of Artificial Intelligence/18AI55 Module – 1

Syllabus
Module – 1

Introduction to AI: history, Intelligent systems, foundation and sub area of AI, applications, current trend and
development of AI. Problem solving: state space search and control strategies.

Module – 2
Problem reduction and Game playing: Problem reduction, game playing, Bounded look-ahead strategy, alpha-
beta pruning, Two player perfect information games.

Module – 3
Logic concepts and logic Programming: propositional calculus, Propositional logic, natural deduction system,
semantic tableau system, resolution refutation, predicate logic, Logic programming.

Module – 4

Advanced problem solving paradigm: Planning: types of planning system, block world problem, logic based
planning, Linear planning using a goal stack, Means-ends analysis, Non-linear planning strategies, learning plans.

Module – 5
Knowledge Representation, Expert system
Approaches to knowledge representation, knowledge representation using semantic network, extended
semantic networks for KR, Knowledge representation using Frames.
Expert system: introduction phases, architecture ES verses Traditional system.

Course Learning Objectives: This course will enable students to:


1. Gain a historical perspective of AI and its foundations.
2. Become familiar with basic principles of AI toward problem solving.
3. Get to know approaches of inference, perception, knowledge representation, and learning.
Course outcomes: The students should be able to:
1. Apply the knowledge of Artificial Intelligence to write simple algorithm for agents.
2. Apply the AI knowledge to solve problem on search algorithm.
3. Develop knowledge base sentences using propositional logic and first order logic.
4. Apply first order logic to solve knowledge engineering process.
Textbooks:
1. Saroj Kaushik, Artificial Intelligence, Cengage learning, 2014.

Reference Books:
1. Elaine Rich, Kevin Knight, Artificial Intelligence, Tata McGraw Hill.
2. Nils J. Nilsson, Principles of Artificial Intelligence, Elsevier, 1980.
3. StaurtRussel, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson Education, 3rd Edition,
2009.
4. George F Lugar, Artificial Intelligence Structure and strategies for complex, Pearson Education, 5 th
Edition, 2011.

Web Resource Link:

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 1


Principles of Artificial Intelligence/18AI55 Module – 1

Module – 1
Introduction to AI: history, Intelligent systems, foundation and sub area of AI, applications, current trend and
development of AI. Problem solving: state space search and control strategies.

Introduction to AI
The foundation of Artificial Intelligence (AI) was laid with the development of Boolean theory and principles
by a mathematician named Boole and others researchers.

AI has been of interest to the researchers as they have always aimed to make machines more intelligent than
humans and tried to simulate intelligent behaviour.

AI has grown substantially starting from simple programs to intelligent programs such as programs for playing
games, expert systems, intelligent robots, agents, etc.

AI researchers generally use one of the two basic approaches, namely bottom-up and top-down, for creating
intelligent machines.

In bottom-up approach, the belief is to achieve artificial intelligence by building electronic replicas of the human
brain which is a complex network of neurons.

In the top-down approach, the attempt is to mimic the behaviour of brain with computer programs. Al currently
comprises of a huge variety of subfields ranging from general-purpose areas such as perception, logical
reasoning, to specific tasks such as game playing, theorem proving, diagnosing diseases, etc.

Al application problems can be found in all disciplines from software engineering to film theory. Al programs
tend to be large, and it would have not been possible to work unless there is great advancement in speed and
memory of computers.

Brief History
John McCarthy organized a conference on machine intelligence in 1956 and since then the field was known as
Artificial Intelligence.

In 1957, the first version of a new program named as General Problem Solver (GPS) was developed and tested.
This program was also developed by Newell and Simon.

McCarthy announced his new development called LISt Processing language (LISP) in 1958. LISP was adopted as
the language of choice by most Al developers.

Marvin Minsky of MIT demonstrated that computer programs could solve spatial and logic problems when
confined to a specific domain. Another program, named STUDENT, was developed during late 1960 which could
solve algebra story problems.

Fuzzy set and logic was developed by L. Zadeh in 1960 that had the unique ability to make decisions under
uncertain conditions. Also neural networks were considered as possible ways of achieving Artificial Intelligence.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 2


Principles of Artificial Intelligence/18AI55 Module – 1

During the same time, the system named SHRDLU was developed by Terry Winograd at the MIT, AI Laboratory,
as a part of the micro worlds project, which consisted of research and programming in small worlds.

SHRDLU was a program that carried out a simple dialogue (via teletype) with a user in English, about a small
world of objects (the BLOCK world) and this program was written in MACLISP.

Frame theory was one of the new methods developed by Minsky during 1970 in the development of Al for
storing structured knowledge to be used by Al programs.

Another development during the same time was the PROLOG language that was initially proposed by R Kowalski
of Imperial College, London. Advent of the expert system appeared in 1970, when Expert systems were designed
and developed to predict the probability of a solution under set conditions.

New theories about machine vision was proposed by David Marr, where it was possible to distinguish an image
based on basic information such as shapes, colour, edge, texture, and the shading of an image.
Neural networks were used to simulate brain functioning. Neural network provided a model for massive parallel
computation.

More recently, work in Al has started from agent point of view. Agents are viewed to be entities that receive
precepts constantly from dynamic environment and perform actions.

Intelligent Systems
AI is a combination of computer science, physiology, and philosophy. Al is a broad topic, consisting of different
fields, from machine vision to expert systems. John McCarthy was one of the founders of Al field who stated
that Al is the science and engineering of making intelligent machines, especially intelligent computer programs.

Different people think of Al differently and there is no unique definition. Various authors have defined Al
differently as given below.

• Al is the study of mental faculties through the use computational models (Charniak and
McDermott, 1985).

• The art of creating machines that perform functions which require intelligence when performed
by people (Kurzweil, 1990).
• AI is a field of study that seeks to explain and emulate intelligent behaviour in terms of computational
processes (Schalkoff, 1990).

• Al is the study of how to make computers do things at which, at the moment, people are better (Rich and
Knight, 1991).

• Al is the study of the computations that make it possible to perceive, reason, and act (Winston, 1992).
• Al is the branch of computer science that is concerned with the automation of intelligent behaviour
(Luger and Stubblefield, 1993).

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 3


Principles of Artificial Intelligence/18AI55 Module – 1

In brief, we can define Al as the study of making computers do things intelligently.


• Al programs must have capability and characteristics of intelligence such as learning, reasoning,
inferencing, perceiving and comprehending information.
• Understanding of Al: It requires an understanding of related terms such as intelligence, knowledge,
reasoning, cognition, learning, and a number of other computer-related terms.
• Generally it is thought to be an advanced software engineering, sophisticated software techniques for
hard problems that cannot be solved in any easy way.
• Al programs like human are: usually not perfect, and even make mistakes.
AI programs also can be treated as non-numeric (common sense) ways of solving problems and need not be
perfect but can give reasonably good solutions. There are two views of Al goals.
• The first view is that Al is about duplicating what the (human) brain DOES (Cognitive Science)
• The second view is that Al is about duplicating what the (human) brain SHOULD do, that is, doing things
logically or rationally.
In order to classify systems as intelligent, it is necessary to define intelligence. The earliest best method to gauge
the intelligence of a system was the Turing test that was proposed by Alan Turing in 1950.
It was designed to provide a satisfactory operational definition of intelligence.
Alan Turing defined intelligent behaviour as the ability to achieve human-level performance in all cognitive
tasks, sufficient to fool an interrogator.
He said that a system is called intelligent if it has an ability to pass the Turing test which is informally defined as
follows:
A system is said to have passed Turing test if a human questioner is unable to determine from repeated
questions of any kind, whether he or she is talking to another person or to a machine/ system.
The very first so-called intelligent system named ELIZA passed the Turing test which was written by Joseph
Weizenbaum during the period from 1964 to 1966.

ELIZA
Eliza was a program that conversed with user in English. The program was able to converse about any subject,
because it stored subject information in data banks.
Another feature of Eliza was its ability to pick up speech patterns from user's questions and provide responses
using those patterns.
In this mode, ELIZA mostly rephrased the user's statements as questions and posed those to the user. The
following passage contains dialogue between Eliza and a teenage girl. The system initiates the conversation
marked as > and user's responses are marked as *

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 4


Principles of Artificial Intelligence/18AI55 Module – 1

Passage of Eliza Conversation


> Hello, I am Eliza.
* Can you help me?
> Don’t you believe that I can help you?
* Yes.
> I See.
* I feel depressed.
> How long have you been feeling depressed?
* Since last month.
> That is quite interesting.
* what is interesting in this?
> Have you asked anyone else?
* No
> Are you saying no just to be negative?
* No I did not ask anyone.
> Why no?
* I do not believe other people.
> Say, do you have any psychological problems?
* I do not know?
> Tell me more.
Since then lot many versions of Eliza have been developed and are available on the Internet.
The basic philosophy and characteristics in all these programs are the same. The main characteristics of Eliza
are briefly mentioned here:
Simulation of Intelligence: Eliza programs are not intelligent at all in real sense. They do not understand the
meaning of utterance. Instead these programs simulate intelligent behaviour quite effectively by recognizing
key words and phrases. By using a table lookup, one of a few ways of responding question is chosen.
Quality of Response: It is limited by the sophistication of the ways in which they can process the input text at a
syntactic level.
Coherence: The earlier version of the system imposed no structure on the conversation.
Semantics: Such systems have no semantic representation of the content of either the user's input or the reply.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 5


Principles of Artificial Intelligence/18AI55 Module – 1

Categorization of Intelligent Systems


In order to design intelligent systems, it is important to categorize these systems. There are four possible
categories of such systems (Luger and Stubblefield, 1993), (Russell and Norvig, 2003).
• System that thinks like humans
• System that acts like humans
• System that thinks rationally
• System that acts rationally
System that thinks like human requires cognitive modelling approaches. Most of the time, it is a black box where
we are not clear about our thought process. One has to know the functioning of the brain and its mechanism
for processing information. It is an area of cognitive science.
System that acts like human requires that the overall behaviour of the system should be human like which could
be achieved by observation. Turing test is an example.
System which thinks rationally relies on logic rather than human to measure correctness. For thinking rationally
or logically, logical formulae and theories are used for synthesizing outcomes.
System that acts rationally is the final category of intelligent system where by rational behaviour we mean doing
the right thing. Even if the method is illogical, the observed behaviour must be rational.
To summarize, we can define intelligence to be that property of mind which encompasses many related mental
abilities. Some of the capabilities are given as follows:
• Reason and draw meaningful conclusions
• Plan sequences of actions to complete a goal
• Solve problems
• Think abstractly
• Comprehend ideas and help computers to communicate in Natural Languages (NL)
• Store knowledge provided before or during interrogation
• Learn new ideas from environment and new circumstances.
• Offer advice based on rules and situations
• Learn new concepts and tasks that require high levels of intelligence

Components of AI Program
AI techniques must be independent of the problem domain as far as possible. Any Al program should have
knowledge base, and navigational capability which contains control strategy and inference mechanism.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 6


Principles of Artificial Intelligence/18AI55 Module – 1

Knowledge base: Al programs should be learning in nature and update its knowledge accordingly. Knowledge
base generally consists of facts and rules and has the following characteristics:
• It is voluminous in nature and requires proper structuring.
• It may be incomplete and imprecise.
• It may be dynamic and keep on changing.
• Control strategy: It determines which rule to be applied. To know this rule, some heuristics or thumb
rules based on problem domain may be used.
• Inference mechanism: It requires search through knowledge base and derives new knowledge using the
existing knowledge with the help of inference rules.
Commonly used AI techniques and theories are rule-based, fuzzy logic, neural networks, decision theory,
statistics, probability theory, genetic algorithms, etc. Since Al is interdisciplinary in nature, foundations of Al are
in various fields such as:
• Mathematics
• Neuroscience
• Control theory
• Linguistics
Mathematics: AI systems use formal logical methods and Boolean logic (Boole, 1847), analysis of limits to what
can be computed, probability theory, uncertainty that forms the basis for most modern approaches to AI, fuzzy
logic, etc.
Neuroscience: This science of medicine helps in studying the functioning of brains. In early studies, injured and
abnormal people were used to understand what parts of brain work.
Control theory: Machines can modify their behaviour in response to the environment (sense/ action loop).
Steam engine governor, thermostat and water-flow regulator are few examples of control theory.
Linguistics: Speech demonstrates so much of human intelligence. Analysis of human language reveals thought
taking place in ways not understood in other settings.

Sub-areas of AI
As we have already mentioned earlier that Al is an interdisciplinary area having numerous diverse subfields.
Each one of these field is an area of research in Al itself. Some of these are listed below:
• Knowledge representation models
• Theorem proving mechanisms
• Game playing methodologies
• Common sense reasoning dealing with uncertainty and decision making
• Learning models, inference techniques, pattern recognition, search and matching, etc.
• Logic (fuzzy, temporal, modal)
• Planning and scheduling

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 7


Principles of Artificial Intelligence/18AI55 Module – 1

• Natural language understanding, speech recognition and understanding spoken utterances


Computer vision.
• Models for intelligent tutoring systems
• Robotics
• Data mining
• Expert problem solving
• Neural networks, Al tools, etc.
• Web agents

Applications
Al finds applications in almost all areas of real-life applications. Broadly speaking, business, engineering,
medicine, education and manufacturing are the main areas.

• Business: financial strategies, give advice


• Engineering: check design, offer suggestions to create new product, expert systems for all
• engineering applications
• Manufacturing: assembly, inspection, and maintenance
• Medicine: monitoring, diagnosing, and prescribing
• Education : in teaching
• Fraud detection
• Object identification
• Space shuttle scheduling
• Information retrieval

Development of AI Languages
Al languages have traditionally been those which stress on knowledge representation schemes. pattern
matching, flexible search, and programs as data. The typical examples of such languages are LISP, Pop-2, ML,
and Prolog.
LISP is a functional language based on lambda calculus and Prolog is a logic language based on first-order
predicate logic. Both languages are declarative languages where one is concerned about 'what to compute', and
not 'how to compute'.
Pop-2 (later extended to Pop11) is a stack-based language providing greater flexibility and has some similarity
to LISP. Pop 11 is embedded in an Al Programming Environment called Poplog.
The KLONE family of languages support modelling at the knowledge level. Environments such as KEE, ART and
CLIPS provide a variety of knowledge representation schemes which helps the AI programmer to integrate
object-oriented representations with ones based on logic.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 8


Principles of Artificial Intelligence/18AI55 Module – 1

Current Trends in AI
Conventional computing (sometimes called hard computing) is based on the concept of precise modelling and
analysing to yield accurate results. Hard computing techniques work well for simple problems, but is bound by
the NP-Complete set which include problems, often occurring in biology, medicine, humanities, management
sciences, and similar fields.

Al community has started looking towards soft computing methodologies which are complementary rather than
competitive. Furthermore, soft computing may be viewed as a foundation component for the emerging field of
conceptual intelligence.

Generally speaking, soft computing techniques resemble biological processes more closely than traditional
techniques, which are largely based on formal logical systems. In effect, the role model for soft computing is
the human mind.

The successful applications of soft computing suggest that the impact of soft computing will be felt increasingly
in the coming years. Soft computing is likely to play an especially important role in science and engineering, but
eventually its influence may extend much farther. Components of soft computing include Neural networks,
Fuzzy systems, Evolutionary algorithms, Swarm intelligence, etc.

Current trends in AI are basically towards the development of technologies which have origin and analogy with
biological or behavioural phenomena related to human or animals such as evolution any computation.

These technologies are helping a widely recognized goal of Al for creation of artificial scenarios that can emulate
humans in their ability. Neural networks have been developed based on functioning of the human brain.

Swarm intelligence (SI) is a type of artificial intelligence based on the collective behaviour of decentralized, self-
organized systems. Social insects like ants, bees, wasps, and termites perform their simple tasks independent
of other members of the colony.

Swarm intelligence is a specialization in the field of self-organizing systems (adaptation). Swarm intelligence
was inspired by the social behaviour of birds flocking and fish schooling.

The agents follow very simple rules, and although there is no centralized control structure dictating how
individual agents should behave, local, and to a certain degree random, interactions between such agents' lead
to the emergence of “intelligent” global behaviour, unknown to the individual agents.

Expert system continues to remain an attractive field for its practical utility in all walk of real life. Emergence of
Agent technology as a subfield of AI is a significant paradigm shift for software development and breakthrough
as a new revolution.

Multi agent systems are designed using several independent and interacting agents to solve the problems of
distributed nature.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 9


Principles of Artificial Intelligence/18AI55 Module – 1

Problem Solving: State-Space Search and Control Strategies


Introduction
Problem solving is a method of deriving solution steps beginning from initial description of the problem to the
desired solution. It has been conventionally one of the focus areas of Artificial Intelligence (AI) and can be
characterized as a systematic search using a range of possible steps to achieve some predefined solution.

In AI, the problems are frequently modelled as a state space problem where the state space is a set of all possible
states from start to goal states. The set of states form a graph in which two states are linked if there is an
operation which can be executed to transform one state to other.

There is difference between the state space search used in AI and the conventional computer science search
methods.

The typical state-space graph for solving problem is too large to be generated and stored in memory. The two
types of problem-solving methods that are generally followed include general purpose and special-purpose
methods.

The most general approach for solving a problem is to generate the solution and test it. For generating new
state in the search space, an action/operator/rule is applied and tested whether the state is the goal state or
not.

The order of application of the rules to the current state is called control strategy. Since Al programs involve
clean separation of computational components of operations, control, and data, it is useful to structure Al
programs in such a way that it helps describe search process efficiently that forms the core of many intelligent
processes.

General Problem Solving


Production System: It is one of the formalisms that helps Al programs to do search process more conveniently
in state-space problems. This system comprises of start (initial) state(s) and goal (final) state(s) of the problem
along with one or more databases consisting of suitable and necessary information for the particular task.

PS consists of number of production rules in which each production rule has left side that determines the
applicability of the rule and a right side that describes the action to be performed if the rule is applied.

Left side of the rule is current state, whereas the right side describes the new state that is obtained from
applying the rule. These production rules operate on the databases that change as these rules are applied.

Let us consider an example of water jug problem and formulate production rules to solve this problem.

Water Jug Problem:

Problem statement: We have two jugs, a 5-gallon (5-g) and the other 3-gallon (3-g) with no measuring marker
on them. There is endless supply of water through tap. Our task is to get 4 gallon of water in the 5-g jug.
Solution: State space for this problem can be described as the set of ordered pairs of integers (X, Y) such that X
represents the number of gallons of water in 5-g jug and Y for 3-g jug.

1. Start state is (0,0)


2. 2. Goal state is (4, N) for any value of NS3.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 10


Principles of Artificial Intelligence/18AI55 Module – 1

The possible operations that can be used in this problem are listed as follows:
• Fill 5-g jug from the tap and empty the 5-g jug by throwing water down the drain
• Fill 3-g jug from the tap and empty the 3-g jug by throwing water down the drain
• Pour some or 3-g water from 5-g jug into the 3-g jug to make it full
• Pour some or full 3-g jug water into the 5-g jug
These operations can formally be defined as production rules as given in Table 2.1.

Table 2.1: Production Rules for Water Jug Problem

Rule
Left of rule Right of rule Description
No

1 (X, Y | X < 5) (5, Y) Fill 5-g jug

2 (X, Y | Y > 0) (0, Y) Empty 5-g jug

3 (X, Y | Y < 3) (X, 3) Fill 3-g jug

4 (X, Y|Y > 0) (X, 0) Empty 3-g jug

5 (X, Y | X + Y ≤ 5 ^ Y > 0) (X + Y, 0) Empty 3-g into 5-g jug

6 (X, Y | X + Y ≤ 3 ^ X > 0) (0, X + Y) Empty 5-g into 3-g jug

(5, Y – (5 – X)) until


7 (X, Y | X + Y ≥ 5 ^ Y > 0) Pour water from 3-g jug into 5-g jug
5-g jug is full

Pour water from 5-g jug into 3-g jug


8 (X, Y | X + Y ≥ 3 ^ X > 0) (X – (3 – Y), 3)
until 3-g jug is full

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 11


Principles of Artificial Intelligence/18AI55 Module – 1

Table2.2: Solution Path 1

Rule Applied 5-g jug 3-g jug Step No

Start state 0 0

1 5 0 1

8 2 3 2

4 2 0 3

6 0 2 4

1 5 2 5

8 4 3 6

Goal state 4 -

Table2.3: Solution Path 2

Rule Applied 5-g jug 3-g jug Step No

Start state 0 0

3 0 3 1

5 3 0 2

3 3 3 3

7 5 1 4

2 0 1 5

5 1 0 6

3 1 3 7

5 4 0 8

Goal state 4 -

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 12


Principles of Artificial Intelligence/18AI55 Module – 1

Let us consider another problem of ‘Missionaries and Cannibals’ and see how we can we solve this using
production system.

Missionaries and Cannibals Problem:


Problem statement: Three missionaries and three cannibals want to cross a river. There is a boat on their side
of the river that can be used by either one or two persons. How should they use this boat to cross the river in
such a way that cannibals never outnumber missionaries on either side of the river? If the cannibals ever
outnumber the missionaries (on either bank) then the missionaries will be eaten. How can they all cross over
without anyone being eaten?
Solution: State space for this problem can be described as the set of ordered pairs of left and right banks of the
river as (L, R) where each bank is represented as a list [nM, mC, B). Here n is the number of missionaries M, m
is the number of cannibals C, and B represents the boat.
Let us consider another problem of ‘Missionaries and Cannibals’ and see how we can we solve this using
production system.
1. Start state: ([3M, 3C, 1B], [OM, OC, OB]), 1B means that beat is present and OB means it is absent.
2. Any state: {{n, M, mc, _), n2M, mC, _]), with constraints/conditions at any state as nj (#0) Zm; n2 (+0) 2
m2; n, + n2 = 3, m + m2 = 3; boat can be either side.
3. Goal state: ([OM, OC, OB], [3M, 3C, 1B])
It should be noted that by no means, this representation is unique. In fact, one may have number of
representations for the same problem. Table 2.4 consists of production rules based on the chosen
representation. States on the left or right sides of river should be valid states satisfying the constraints given in
(2) above.

Table 2.4: Production Rules for Water Jug Problem

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 13


Principles of Artificial Intelligence/18AI55 Module – 1

Table 2.5: Solution Path

State-Space Search: State space is another method of problem representation that facilitates easy search. Using
this method, one can also find a path from start state to goal state while solving a problem. A state space
basically consists of four components:
1. A set S containing start states of the problem
2. A set G containing goal states of the problem
3. Set of nodes (states) in the graph/tree. Each node represents the state in problem-solving process 4. Set
of arcs connecting nodes. Each arc corresponds to operator that is a step in a problem-solving process.
A solution path is a path through the graph from a node in S to a node in G. The main objective of search
algorithm is to determine a solution path in the graph.
Commonly used approach is to apply appropriate operator to transfer one state of problem to another. It is
similar to production system search method where we use production rules instead of operators.
Let us consider again the problem of ‘Missionaries and Cannibals'.
The possible operators that are applied in this problem are {2M0C, 1M1C, 0M2C, 1M0C, 0M1C}. Here M is
missionary and C is cannibal. Digit before these characters indicates number of missionaries and cannibals
possible at any point in time. These operators can be used in both the situations, i.e., if boat is on the left bank
then, we write ‘Operator ' and if the boat is on the right bank of the river, then we write “Operator ”.

For the sake of simplicity, let us represent state (L : R), where L = n1M m1C1B and R = n2M m2 C0B. Here B
represents boat with 1 or 0 indicating the presence or absence of the boat.
1. Start state: (3M3C1B : 0M0C0B) or simply (331:000)
2. Goal state: (0M0C0B : 3M3C1B) or simply (000:331)

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 14


Principles of Artificial Intelligence/18AI55 Module – 1

Furthermore, we will filter out invalid states, illegal operators not applicable to some states, and some states
that are not required at all. For example,
• An invalid state like (1M2C1B:2M1C0B) is not a possible state, as it leads to one missionary
and two cannibals on the left bank.
• In case of a valid state like (2M2C1B:1MIC0B), the operator 0M1C or 0M2C would be
illegal. Hence, the operators when applied should satisfy some conditions that should not lead
to invalid state.
Applying the same operator both ways would be a waste of time, since we have returned to a previous states.
This is called looping situation. Looping may occur after few steps even. Such operations are to be avoided.
To illustrate the progress of search, we are required to develop a tree of nodes, with each node in the tree
representing a state. The root node of the tree may be used to represent the start state. The arcs of the tree
indicate the application of one of the operators. The nodes for which no operators are applied, are called leaf
nodes, which have no arcs leading from them.
To simplify, we have not generated entire search space and avoided illegal and looping states. Depth-first or
breadth-first strategy or some intelligent heuristic searches (explained later) is used to generate the search
space.
The search space generated using valid operators are shown in the Fig. The sequence of operators applied to
solve this problem is given in Table.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 15


Principles of Artificial Intelligence/18AI55 Module – 1

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 16


Principles of Artificial Intelligence/18AI55 Module – 1

Let us consider another problem called Eight-puzzle Problem and see how we can model this using state space
search method (Nilsson N. J., 1980).

The Eight-Puzzle Problem


Problem Statement: The eight-puzzle problem has a 3 x 3 grid with 8 randomly numbered (1 to 8) tiles arranged
on it with one empty cell. At any point, the adjacent tile can move to the empty cell, creating a new empty cell.
Solving this problem involves arranging tiles such that we get the goal state from the start state. Fig shows start
and goal states.

A state for this problem should keep track of the position of all tiles on the game board, with 0 representing the
blank (empty cell) position on the board. The start and goal states may be represented as follows with each list
representing corresponding row:
1. Start state: { [3,7,6), (5,1,2], [4,0,8] ]
2. The goal state could be represented as: [ (5,3,6] [7,0,2], [4,1,8] ]
3. The operators can be thought of moving {Up, Down, Left, Right}, the direction in which blank
space effectively moves.
To simplify, a search tree up to level 2 is drawn as shown in Fig. to illustrate the use of operators to generate
next state.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 17


Principles of Artificial Intelligence/18AI55 Module – 1

Control Strategies
Control strategy is one of the most important components of problem solving that describes the order of
application of the rules to the current state.
Control strategy should be such that it causes motion towards a solution. For example, in water jug problem, if
we apply a simple control strategy of starting each time from the top of rule list and select the first applicable
one, then we will never move towards solution. The second requirement of control strategy is that it should
explore the solution space in a systematic manner.
Depth-first and breadth-first are systematic control strategies but these are blind searches.
In depth-first strategy, we follow a single branch of the tree until it yields a solution or some pre-specified depth
has reached and then go back to immediate previous node and explore other branches using depth-first
strategy.
In breadth-first search, a search space tree is generated level wise until we find a solution or some specified
depth is reached.
The main work in the area of search strategies is to find the correct search strategy for a given problem. There
a two directions in which such a search could proceed.
• Data-driven search, called forward chaining, from the start state
• Goal-driven search, called backward chaining, from the goal state
Forward Chaining: The process of forward chaining begins with known facts and works towards a conclusion.
For example in eight-puzzle problem, we start from the start state and work forward to the conclusion, i.e., the
goal state.
• In this case, we begin building a tree of move sequences with the root of the tree as start state. The
states of next level of the tree are generated by finding all rules whose left sides match with root and
use their right side to create the new state. This process is continued until a configuration that matches
the goal state is generated. Language OPS5 uses forward reasoning rules. Rules are expressed in the
form of if-then rules.
Backward Chaining: It is a goal-directed strategy that begins with the goal state and continues working
backward, generating more sub-goals that must also be satisfied to satisfy main goal until we reach to start
state.
• Prolog (Programming in Logic) language uses this strategy. We can use both data-driven and goal-
directed strategies for problem solving.

• Therefore, the general observations are that move from the smaller set of states to the larger set of
states and proceed in the direction with the lower branching factor (the average number of nodes that
can be reached directly from single node).

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 18


Principles of Artificial Intelligence/18AI55 Module – 1

Characteristics of Problem
Before starting modelling the search and trying to find solution for the problem, one must analyze it along
several key characteristics (Rich and Knight, 2003) initially. Some of these are mentioned below.
Type of Problem: There are three types of problems in real life, viz., Ignorable, Recoverable, and Irrecoverable.
Ignorable: These are the problems where we can ignore the solution steps.
Recoverable: These are the problems where solution steps can be undone. For example, in water jug problem,
if we have filled up the jug, we can empty it also. Any state can be reached again by undoing the steps. These
problems are generally puzzles played by a single player. Such problems can be solved by backtracking, so
control strategy can be implemented using a push-down stack.
Irrecoverable: The problems where solution steps cannot be undone. For example, any two-player game such
as chess, playing cards, snake and ladder, etc. are examples of this category. Such problems can be solved by
planning process.
Decomposability of a problem: Divide the problem into a set of independent smaller sub-problems, solve them
and combine the solutions to get the final solution.
Role of knowledge: Knowledge plays an important role in solving any problem. Knowledge could be in the form
of rules and facts which help generating search space for finding the solution.
Consistency of Knowledge Base used in solving problem: Make sure that knowledge base used to solve problem
is consistent. Inconsistent knowledge base will lead to wrong solutions.
Requirement of solution: We should analyze the problem whether solution required is absolute or relative. We
call solution to be absolute if we have to find exact solution, whereas it is relative if we have reasonably good
and approximate solution.

Exhaustive Searches
Let us discuss some of systematic uninformed exhaustive searches, viz., breadth-first, depth-first depth-first
iterative deepening, and bidirectional searches, and present their algorithms.

Breadth-First Search
The breadth-first search (BFS) expands all the states one step away from the start state, and then expands all
states two steps from start state, then three steps, etc., until a goal state is reached. All successor states are
examined at the same depth before going deeper. The BFS always gives an optimal path or solution.
This search is implemented using two lists called OPEN and CLOSED. The OPEN list contains those states that
are to be expanded and CLOSED list keeps track of states already expanded. Here OPEN list is maintained as a
queue and CLOSED list as a stack.

Algorithm:

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 19


Principles of Artificial Intelligence/18AI55 Module – 1

Let us see the search tree generation from start state of the water jug problem using BFS algorithm. At each
state, we apply first applicable rule. If it generates previously generated state then cross it and try another rule
in the sequence to avoid the looping. If new state is generated then expand this state in breadth-first fashion.
The rules given in Table 2.1 for water jug problem are applied and enclosed in {}.
Figure 2.4 shows the trace of search tree using BFS.
Solution path: (0,0)  (5,0)  (2,3)  (2,0)  (0,2)  (5,2)  (4,3)

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 20


Principles of Artificial Intelligence/18AI55 Module – 1

Let us discuss some of systematic uninformed exhaustive searches, viz., breadth-first, depth-first depth-first
iterative deepening, and bidirectional searches, and present their algorithms.

Depth-First Search
In the depth-first search (DFS), we go as far down as possible into the search tree/graph before backing up and
trying alternatives. It works by always generating a descendent of the most recently expanded node until some
depth cut off is reached and then backtracks to next most recently expanded node and generates one of its
descendants.
We can implement DFS by using two lists called OPEN and CLOSED. The OPEN list contains those states that are
to be expanded, and CLOSED list keeps track of states already expanded Here OPEN and CLOSED lists are
maintained as stacks.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 21


Principles of Artificial Intelligence/18AI55 Module – 1

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 22


Principles of Artificial Intelligence/18AI55 Module – 1

The path is obtained from the list stored in CLOSED. The solution Path is
(0,0)  (5,0)  (5,3)  (0,3)  (3,0)  (3,3)  (5,1)  (0, 1)  (1,0)  (1,3)  (4,0)

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 23


Principles of Artificial Intelligence/18AI55 Module – 1

Comparisons: Since these are unguided, blind, and exhaustive searches, we cannot say much about them but
can make some observations.
• BFS is effective when the search tree has a low branching factor.
• BFS can work even in trees that are infinitely deep.
• BFS requires a lot of memory as number of nodes in level of the tree increases exponentially.
• BFS is superior when the GOAL exists in the upper right portion of a search tree.
• BFS gives optimal solution.
• DFS is effective when there are few sub trees in the search tree that have only one connection
point to the rest of the states.
• DFS is best when the GOAL exists in the lower left portion of the search tree.
• DFS can be dangerous when the path closer to the START and farther from the GOAL has been
chosen.
• DFS is memory efficient as the path from start to current node is stored. Each node should
contain state and its parent.
• DFS may not give optimal solution.

Depth-First Iterative Deepening


Depth-first iterative deepening (DFID) takes advantages of both BFS and DFS searches on trees.
The algorithm for DFID is given as follows:

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 24


Principles of Artificial Intelligence/18AI55 Module – 1

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 25


Principles of Artificial Intelligence/18AI55 Module – 1

Bidirectional Search
Directional search is a graph search algorithm that runs two simultaneous searches. One search moves forward
from the start state and other moves backward from the goal and stops when the two meet in the middle. It is
useful for those problems which have a single start state and single goal state.
The DFID can be applied to bidirectional search for k = 1, 2, .... The kth iteration consists of generating all states
in the forward direction from start state up to depth k using BFS. and from goal state using DFS one to depth k
and other to depth k +1 not storing states but simply matching against the stored states generated from forward
direction.
Here the backward search to depth k + 1 is necessary to find odd-length solutions. If match is found, then path
can be traced from start to the matched state and from matched to the goal state. It should be noted that each
node has link to its successors as well as to its parent. These links will help generating complete path from start
to goal states.
The reason for this approach is that each of the two searches has time complexity 0(5d2), and O(bd 12 + 502) is
much less than the running time of one search from the beginning to the goal, which would be 0(59).
This search can be made in already existing graph/tree or search graph/ tree can be generated as a part of
search. Let us illustrate the working of this method using existing graph. Consider the following graph as shown
in Fig. 2.7. Find a route/path from node labelled 1 to node labelled 16.
The trace of finding path from node 1 to 16 using bidirectional search is given in Fig. 2.8. We can clearly see that
the path obtained is: 1, 2, 6, 11, 14, 16

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 26


Principles of Artificial Intelligence/18AI55 Module – 1

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 27


Principles of Artificial Intelligence/18AI55 Module – 1

Analysis of Search methods


Effectiveness of any search strategy in problem solving is measured in terms of:
• Completeness: Completeness means that an algorithm guarantees a solution if it exists.
• Time Complexity: Time required by an algorithm to find a solution.
• Space Complexity: Space required by an algorithm to find a solution.
• Optimality: The algorithm is optimal if it finds the highest quality solution when there are several
different solutions for the problem.
We will compare searches discussed above on these parameters. Let us assume 'b' to be the branching factor
and 'd' to be the depth of the tree in the worst case.
DFS: If the depth cut off is 'd', then the space requirement is of O(d). The time complexity of DFS to depth 'd' is
of O(b) in the worst case. The DFS requires some cut-off depth. If branches are not cut off and duplicates are
not checked for, the algorithm may not even terminate. We can not say on optimality of solution.
BFS: In BFS, all the nodes up to depth d' must be generated in the worst case. At level i there will be b'nodes
generated. So, total number of nodes generated in the worst case is
1 + b + b2 + b3 + ... + bd-1 = O(bo)
Space complexity in the worst case is also O(b4). The solution obtained using BFS is optimal but il may take
higher computational time. It will terminate and find solution if it exists.
DFID: Space requirement of DFID is of O(d), as search tree is generated using DFS method. The time requirement
for DFID will be based on number of nodes generated during search. The total nodes in tree are calculated as
follows:
• Nodes at depth d are generated once during the final iteration of the search,
• Nodes at depth d-1 are generated twice,
• Nodes at depth d-2 are generated thrice, and so on.
Thus, the total number of nodes generated in DFID to depth d is
N = bd + 2bd-1 + 3bd-2 + .... db
= bd[1 + 2b-1 + 3b-2 + .... db1- d]
= bd [1 + 2x +3x2 + 4x3 + ... + dxd-1) { if x = b-1}
N converges to (bd) * (1 - x)-2 for |x| < 1. Since (1 – x)-2 is a constant and independent of 'd', we can say that N
ꝏ O(bd) if b > 1. So time complexity is of O(bd).
Since DFID also moves level wise, it finds the optimal solution.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 28


Principles of Artificial Intelligence/18AI55 Module – 1

The following table summarizes the results

To illustrate the need of intelligent searches, let us consider a problem of travelling salesman.
Travelling Salesman Problem Statement: In travelling salesman problem (TSP), one is required to find the
shortest route of visiting all the cities once and returning back to starting point. Assume that there are 'n' cities
and the distance between each pair of the cities is given.
The problem seems to be simple, but deceptive. The TSP is one of the most intensely studied problems in
computational mathematics and yet no effective solution method is known for the general case.
In this problem, a simple motion causing and systematic control strategy could, in principle, be applied to solve
it. All possible paths of the search tree are explored and the shortest path is returned. This will require (n - 1)!
(i.e., factorial of n - 1) paths to be examined for 'n' cities. If number of cities grows, then the time required to
wait a salesman to get the information about the shortest path is not a practical situation. This phenomenon is
called combinatorial explosion.
Above-mentioned strategy could be improved little bit using the following techniques.
• Start generating complete paths, keeping track of the shortest path found so far.
• Stop exploring any path as soon as its partial length becomes greater than the shortest path length found
so far.
Let us consider an example of five cities and see how we can find solution to this problem using above-
mentioned technique. Assume that C1 is the start city.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 29


Principles of Artificial Intelligence/18AI55 Module – 1

Heuristic Search Techniques


Heuristic technique is a criterion for determining which among several alternatives will be the most effective to
achieve some goal. This technique improves the efficiency of a search process possibly by sacrificing claims of
systematic and completeness.
Using good heuristics, we can hope to get good solution to hard problems (such as travelling salesman problem)
in less than exponential time.
There are two types of heuristics, namely,
• General-purpose heuristics that are useful in various problem domains.
• Special purpose heuristics that are domain specific.
General-Purpose Heuristics: A general-purpose heuristics for combinatorial problem is nearest neighbor
algorithms that work by selecting the locally superior alternative.
• For such algorithms, it is often possible to prove an upper bound on the error. It provides reassurance
that we are not paying too high a price in accuracy for speed.
• For real-world problems, it is often useful to introduce heuristics on the basis of relatively unstructured
knowledge.
• In AI approaches, behaviour of algorithms is analyzed by running them on computer as contrast to
analyzing algorithm mathematically.
There are at least many reasons for such ad hoc approaches in AI.
• It is a fun to see a program do something intelligent than to prove it.
• Since Al problem domains are usually complex, it is generally not possible to produce analytical
proof that a procedure will work.
• It is not even possible to describe the range of problems well enough to make statistical analysis
of program behaviour meaningful.
One of the most important analysis of the search process is to find number of nodes in a complete search tree
of depth 'd' and branching factor 'f, that is, f* d.
This simple analysis motivates to look for improvements on the exhaustive searches and to find an upper bound
on the search time which can be compared with exhaustive search procedures. The searches which use some
domain knowledge are called Informed Search Strategies.
Branch and Bound Search (Uniform Cost Search): In branch and bound search method, cost function (denoted
by g(x)) is designed that assigns cumulative expense to the path from start node to the current node X by
applying the sequence of operators.
While generating a search space, a least cost path obtained so far is expanded at each iteration till we reach to
goal state. Since branch and bound search expands the least-cost partial path, it is sometimes also called a
uniform cost search.
The following algorithm is simple to give you an idea about how it works Furthermore, it can be modified by
putting parent links along with the node in the CLOSED list

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 30


Principles of Artificial Intelligence/18AI55 Module – 1

We notice that algorithm generally requires generate solution and test it for its goodness. Solution can be
generated using any method and testing might be based on some heuristics. Skeleton of algorithm for ‘generate
and test’ strategy is as follows:

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 31


Principles of Artificial Intelligence/18AI55 Module – 1

Hill Climbing
Quality Measurement turns Depth-First search into Hill climbing (variant of generate and test strategy). It is an
optimization technique that belongs to the family of local searches.
Hill climbing can be used to solve problems that have many solutions but where some solutions are better than
others.
Hill climbing proceeds in depth-first order, but the choices are ordered according to some heuristic value (i.e.,
measure of remaining cost from current to goal state).

Problems with Hill Climbing


The search process may reach to a position that is a solution but from there no move improves the situation.
This will happen if we have read local maximum, a plateau, or a ridge.
Local maximum: It is a state that is better than all its neighbours but not better than some other states which
are far away. From this state all moves looks to be worse. In such situation, backtrack to some earlier state and
try going in different direction to find a solution.
Plateau: It is a flat area of the search space where all neighbouring states has the same value. It is not possible
to determine the best direction. In such situation make a big jump to some direction and try to get to new
section of the search space.
Ridge: It is an area of search space that is higher than surrounding areas but that cannot be traversed by single
moves in any one direction. It is a special kind of local maxima. Here apply two or more rules before doing the
test, i.e. moving in several directions at once.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 32


Principles of Artificial Intelligence/18AI55 Module – 1

Beam Search
Beam search is a heuristic search algorithm in which W number of best nodes at each level is always expanded.
It progresses level by level and moves downward only from the best W nodes at each level.
Beam search uses breadth-first search to build its search tree. At each level of the tree, it generates all
successors of the states at the current level, sorts them in order of increasing heuristic values.
However, it only considers a W number of states at each level. Other nodes are ignored. Best nodes are decided
on the heuristic cost associated with the node. Here W is called width of beam search.

The search tree generated using Beam search algorithm, assume W = 2 and B = 3 is given below. Here, black
nodes are selected based on their heuristic values for further expansion.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 33


Principles of Artificial Intelligence/18AI55 Module – 1

Best-First Search
Best-first search is based on expanding the best partial path from current node to goal node. Here forward
motion is from the best open node so far in the partially developed tree.
The cost of partial paths is calculated using some heuristic. If the state has been generated earlier and new path
is better than the previous one, then change the parent and update the cost.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 34


Principles of Artificial Intelligence/18AI55 Module – 1

A* Algorithm
A* Algorithm ("Aystar'; proposed by Hart in 1972) is a combination of branch and bound' and 'best search'
methods combined with the dynamic programming principle.
It uses a heuristic or evaluation function usually denoted by f(x) to determine the order in which the search
visits nodes in the tree.
The heuristic function for a node N is defined as follows: f(N) = g(N) + h(N)
The function g is a measure of the cost of getting from the start node to the current node N, i.e., it is sum of
costs of 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 N to the goal node. Generally, A* algorithm is called OR graph
/ tree search algorithm.
A* algorithm incrementally searches all the routes starting from the start node until it finds the shortest path
to a goal. Starting with a given node, the algorithm expands the node with the lowest f(x) value. It maintains a
set of partial solutions. Unexpanded leaf nodes of expanded nodes are stored in a queue with corresponding f
values. This queue can be maintained as a priority queue.

Let us consider an example of eight puzzle again and solve it by using A* algorithm. The simple evaluation
function f(x) is defined as follows:
f(X) = g(X) + h(X), where
h(X) = the number of tiles not in their goal position in a given state X
g(x) = depth of node X in the search tree
Given

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 35


Principles of Artificial Intelligence/18AI55 Module – 1

The search tree using A* algorithm for eight-puzzle problem is given in Fig. 2.10. It should be noted that the
quality of solution will depend on heuristic function.
A better estimate of h function might be as follows. The function g may remain same.
h(X) = the sum of the distances of the tiles (1 to 8) from their goal position in a given state X.
Here start state has h(start_state) = 3 + 2 +1+0+1+2+ 2 + 1 = 12
For the sake of brevity, search tree has been omitted

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 36


Principles of Artificial Intelligence/18AI55 Module – 1

Optimal Solution by A* Algorithm


A* algorithm finds optimal solution if heuristic function is carefully designed and is underestimated. We will
support the argument using the following example (Rich and Knight, 2003).
Underestimation
If we can guarantee that h never overestimates actual value from current to goal, then A* algorithm ensures to
find an optimal path to a goal, if one exists. Let us illustrate this by the following example shown in Fig. 2.11.
Formal proof is omitted as it is not relevant here. Here we assume that h value for each node X is
underestimated, i.e., heuristic value is less than actual value to node X to goal node.
In Fig. 2.11, start node A is expanded to B, C, and D with f values as 4 5 6, respectively.

Overestimation
Let us consider another situation. Here we are overestimating heuristic value of each node in the graph/tree.
We expand B to E, E to F, and F to G for a solution path of length 4. But assume that there is a direct path from
D to a solution giving a path of length 2 as h value of D is also overestimated.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 37


Principles of Artificial Intelligence/18AI55 Module – 1

Admissibility of A*
A search algorithm is admissible, if for any graph, it always terminates in an optimal path from start state to
goal state, if path exists. We have seen earlier that if heuristic function 'h' underestimates the actual value from
current state to goal state, then it bounds to give an optimal solution and hence is called admissible function.
So, we can say that A* always terminates with the optimal path in case h is an admissible heuristic function.
Monotonic Function
A heuristic function h is monotone if
1. states Xi and Xj such that Xj is successor of Xi
h(Xi) - h(Xj) <= cost (Xi, Xj) i.e., actual cost of going from Xi to Xj
2. h (Goal) = 0
In this case, heuristic is locally admissible, i.e., consistently finds the minimal path to each state they encounter
in the search. The monotone property, in other words, is that search space which is every where locally
consistent with heuristic function employed.
With monotonic heuristic, if a state is rediscovered, it is not necessary to check whether the new path is shorter.
Each monotonic heuristic function is admissible.

 A cost function fis monotone if f(N) Sf(succ(N))"


 For any admissible cost function f, we can construct a monotonic admissible function.

Iterative-Deepening A*
Iterative-Deepening A* (IDA*) is a combination of the depth-first iterative deepening and A* algorithm. Here
the successive iterations are corresponding to increasing values of the total cost of a path rather than increasing
depth of the search. Algorithm works as follows:
• For each iteration, perform a DFS pruning off a branch when its total cost (g + h) exceeds a
given threshold
• The initial threshold starts at the estimate cost of the start state and increases for each iteration
of the algorithm.
• The threshold used for the next iteration is the minimum cost of all values exceeded the current
threshold.
• These steps are repeated till we find a goal state
Let us consider an example to illustrate the working of IDA* algorithm as shown in Fig. 2.13. initially, the
threshold value is the estimated cost of the start node.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 38


Principles of Artificial Intelligence/18AI55 Module – 1

Constraint Satisfaction
Many Al problems can be viewed as problems of constraint satisfaction in which the goal is to solve some
problem state that satisfies a given set of constraints instead of finding optimal path to the solution. Such
problems are called Constraint Satisfaction (CS) Problems.
A cryptography problem: A number puzzle in which a group of arithmetical operations has some or all of its
digits replaced by letters and the original digits must be found. In such a puzzle, each letter represents a unique
digit.
Let us consider the following problem in which we have to replace each letter by a distinct digit (0-9) so that
the resulting sum is correct.

B A S E
+ B A L L
_______________
G A M E S
_______________

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 39


Principles of Artificial Intelligence/18AI55 Module – 1

The n-Queen problem: The condition is that on the same row, or column, or diagonal no two queens attack
each other.
A map colouring problem: Given a map, colour regions of map using three colours, blue, red, and black such
that no two neighbouring countries have the same colour.
In general, we can define a Constraint Satisfaction Problem as follows:

 a set of variables (x1, x2, .., xn), with each xi ϵ Di with possible values and
 a set of constraints, i.e. relations, that are assumed to hold between the values of the variables.

The problem is to find, for each i, 1 ≤ i ≤ n, a value of xi ϵ Di, so that all constraints are satisfied. A CS problem is
usually represented as an undirected graph, called Constraint Graph in which the nodes are the variables and
the edges are the binary constraints.
We can easily see that a CSP can be given an incremental formulation as a standard search problem.
• Start state: the empty assignment, i.e. all variables, are unassigned.
• Goal state: all the variables are assigned values which satisfy constraints.
• Operator: assigns value to any unassigned variable, provided that it does not conflict with previously
assigned variables.
Every Solution must be a complete assignment and therefore appears at depth n if there are n variables.
Furthermore, the search tree extends only to depth n and hence depth-first search algorithms are popular for
CSPs.
The following algorithm is applied for the CSP. This procedure can be implemented as a DF search.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 40


Principles of Artificial Intelligence/18AI55 Module – 1

Let us solve the following crypt-arithmetic puzzle.


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:

B A S E
+ B A L L
_______________
G A M E S
_______________
• Constraints: No two letters have the same value (the constraints of arithmetic).
• Initial Problem State
G = ?; A = ?; M = ?; E = ?; S = ?; B = ?; L = ?
• Apply constraint inference rules to generate the relevant new constraints.
• Apply the letter assignment rules to perform all assignments required by the current set of constraints.
Then choose another rules to generate an additional assignment, which will, in turn, generate new
constrains at the next cycle.
• At each cycle, there may be several choices of rules to apply.
• A useful heuristics can help to select the best rule to apply first
For example, if a letter that has only two possible values and another with six possible values, then there is a
better chance of guessing right on the first than on the second.

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 41


Principles of Artificial Intelligence/18AI55 Module – 1

We can easily see that G has to be non-zero digit, so the value of carry C4 should be 1 and hence G=1. The
tentative steps required to solve above crypt-arithmetic are given below:

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 42


Principles of Artificial Intelligence/18AI55 Module – 1

Example: Let us solve another crypt-arithmetic puzzle.

The search tree using DF search approach for solving the crypt-arithmetic puzzle is given in Fig. 2.15. We get
two possible solutions as {F=1, T=7, O=4, R=8, W=3, U=6} and {F=1, T=7, O=5, W=6, U=3}. On backtracking we
may get more solutions. All possible solutions are given as follows:

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 43


Principles of Artificial Intelligence/18AI55 Module – 1

Prof. Manzoor Ahmed, Dept. of AI&ML, SKIT 44

You might also like