Module - 1
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.
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.
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.
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).
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 *
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.
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
Applications
Al finds applications in almost all areas of real-life applications. Broadly speaking, business, engineering,
medicine, education and manufacturing are the main areas.
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.
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.
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.
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.
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.
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.
Rule
Left of rule Right of rule Description
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 -
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 -
Let us consider another problem of ‘Missionaries and Cannibals’ and see how we can we solve this using
production system.
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)
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.
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).
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.
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).
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:
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)
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.
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)
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.
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
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.
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:
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).
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.
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.
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
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
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.
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.
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.
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
_______________
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.
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.
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:
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: