UNIT 1 Notes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

KARPAGAM ACADEMY OF HIGHER EDUCATION

DEPARTMENT OF COMPUTER APPLICATIONS


COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Introduction to AI-Problem formulation, problem Definition-Production systems, Control


strategies, Search strategies. Problem solving methods- Problem Graphs, Matching. Heuristic
functions – Hill Climbing – Depth first and Breath first search, A* Algorithm, Simulated
Annealing, Constraints satisfaction.
INTRODUCTION TO ARTIFICIAL INTELLIGEMCE :
In the simplest terms, AI which stands for artificial intelligence refers to systems or machines
that mimic human intelligence to perform tasks and can iteratively improve themselves
based on the information they collect. AI manifests in a number of forms.
Artificial intelligence is the simulation of human intelligence processes by machines, especially
computer systems. Specific applications of AI include expert systems, natural language
processing, speech recognition and machine vision.

AI programming focuses on three cognitive skills: learning, reasoning and self-correction.

Learning processes. This aspect of AI programming focuses on acquiring data and creating
rules for how to turn the data into actionable information.

Reasoning processes. This aspect of AI programming focuses on choosing the right algorithm to
reach a desired outcome.

Self-correction processes. This aspect of AI programming is designed to continually fine-tune


algorithms and ensure they provide the most accurate results possible.

Why is artificial intelligence important?

AI is important because it can give enterprises insights into their operations that they may not
have been aware of previously and because, in some cases, AI can perform tasks better than
humans.

Advantages

 Good at detail-oriented jobs;


 Reduced time for data-heavy tasks;
 Delivers consistent results; and
 AI-powered virtual agents are always available.

4 types of artificial intelligence

Type 1: Reactive machines. These AI systems have no memory and are task specific.
Type 2: Limited memory. These AI systems have memory, so they can use past experiences to
inform future decisions.
Type 3: Theory of mind. Theory of mind is a psychology term. When applied to AI, it means
that the system would have the social intelligence to understand emotions.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Type 4: Self-awareness. In this category, AI systems have a sense of self, which gives them
consciousness.

History of Artificial Intelligence

Artificial Intelligence is not a new word and not a new technology for researchers. This
technology is much older than you would imagine. Even there are the myths of Mechanical men
in Ancient Greek and Egyptian Myths. Following are some milestones in the history of AI which
defines the journey from the AI generation to till date development.

How does AI work?

To begin with, an AI system accepts data input in the form of speech, text, image, etc. The
system then processes data by applying various rules and algorithms, interpreting, predicting,
and acting on the input data. Upon processing, the system provides an outcome, i.e., success or
failure, on data input. The result is then assessed through analysis, discovery, and feedback.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Lastly, the system uses its assessments to adjust input data, rules and algorithms, and target
outcomes. This loop continues until the desired result is achieved.

How AI Works

Key components of AI

Intelligence has a broader context that reflects a deeper capability to comprehend the
surroundings. However, for it to qualify as AI, all its components need to work in conjunction
with each other. Let’s understand the key components of AI.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Key Components of AI

1. Machine learning: Machine learning is an AI application that automatically learns and


improves from previous sets of experiences without the requirement for explicit
programming.
2. Deep learning: Deep learning is a subset of ML that learns by processing data with the
help of artificial neural networks.
3. Neural network: Neural networks are computer systems that are loosely modeled on
neural connections in the human brain and enable deep learning.
4. Cognitive computing: Cognitive computing aims to recreate the human thought process
in a computer model. It seeks to imitate and improve the interaction between humans and
machines by understanding human language and the meaning of images.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

5. Natural language processing (NLP): NLP is a tool that allows computers to comprehend,
recognize, interpret, and produce human language and speech.
6. Computer vision: Computer vision employs deep learning and pattern identification to
interpret image content (graphs, tables, PDF pictures, and videos).

Types of AI

Artificial Intelligence can be broadly divided into two categories: AI based on capability and AI
based on functionality. Let’s understand each type in detail.

Types of AI

PROBLEM CHARACTERISTICS
In order to solve a problem, it need to be analyzed on the following lines:
1. Is the program decomposable into a set of independent smaller or easier sub-problems?
2. Can the solution steps be ignored or undone if they prove fruit less?

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

3. Is the problem’s universe predictable?


4. Is the good solution absolute or relative?
5. Is the desired solution a state of the problem’s world or a path to a state?
6. What is the role of knowledge about the problem’s domain?
7. Will the computer return the solution having fed the problem automatically or will the
solution be obtained only after the interaction between the computer and the problem solver?

PROBLEM SOLVING IN ARTIFICIAL INTELLIGENCE

The reflex agent of AI directly maps states into action. Whenever these agents fail to operate in
an environment where the state of mapping is too large and not easily performed by the agent,
then the stated problem dissolves and sent to a problem-solving domain which breaks the large
stored problem into the smaller storage area and resolves one by one. The final integrated action
will be the desired outcomes.

On the basis of the problem and their working domain, different types of problem-solving agent
defined and use at an atomic level without any internal state visible with a problem-solving
algorithm. The problem-solving agent performs precisely by defining problems and several
solutions. So we can say that problem solving is a part of artificial intelligence that encompasses
a number of techniques such as a tree, B-tree, heuristic algorithms to solve a problem.

We can also say that a problem-solving agent is a result-driven agent and always focuses on
satisfying the goals.

Steps problem-solving in AI: The problem of AI is directly associated with the nature of
humans and their activities. So we need a number of finite steps to solve a problem which makes
human easy works.

These are the following steps which require to solve a problem :

 Goal Formulation: This one is the first and simple step in problem-solving. It organizes
finite steps to formulate a target/goals which require some action to achieve the goal.
Today the formulation of the goal is based on AI agents.
 Problem formulation: It is one of the core steps of problem-solving which decides what
action should be taken to achieve the formulated goal. In AI this core part is dependent
upon software agent which consisted of the following components to formulate the
associated problem.

Components to formulate the associated problem:

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 Initial State: This state requires an initial state for the problem which starts the AI agent
towards a specified goal. In this state new methods also initialize problem domain solving
by a specific class.
 Action: This stage of problem formulation works with function with a specific class
taken from the initial state and all possible actions done in this stage.
 Transition: This stage of problem formulation integrates the actual action done by the
previous action stage and collects the final stage to forward it to their next stage.
 Goal test: This stage determines that the specified goal achieved by the integrated
transition model or not, whenever the goal achieves stop the action and forward into the
next stage to determines the cost to achieve the goal.
 Path costing: This component of problem-solving numerical assigned what will be the
cost to achieve the goal. It requires all hardware software and human working cost.

Problem solving in AI

PRODUCTION SYSTEMS:
A production system is an artificial intelligence program that consists of some rules and the
procedures or processes for following them. This set of rules can be termed as 'production'.
They enhance action selection and automated planning.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Definition:
Knowledge representation formalism consists of collections of condition-action
rules(Production Rules or Operators), a database which is modified in accordance with
the rules, and a Production System Interpreter which controls the operation of the rules
i.e the 'control mechanism' of a Production System, determining the order in which
Production Rules are fired.

A system that uses this form of knowledge representation is called a production system.
A production system consists of following components.
(a)A set of production rules, which are of the form A→B. Each rule consists of left hand side
constituent that represent the current problem state and a right hand side that represent an output
state. A rule is applicable if its left hand side matches with the current problem state.
(b) A database, which contains all the appropriate information for the particular task. Some part
of the database may be permanent while some part of this may pertain only to the solution of the
current problem.
(c) A control strategy, which specifies order in which the rules will be compared to the
database of rules and a way of resolving the conflicts that arise when several rules match
simultaneously.
(d) A rule applier, which checks the capability of rule by matching the content state with the left
hand
Four classes of production systems:

1. A monotonic production system: It is a production system in which the application of a


rule never prevents the later application of another rule that could also have been applied at
the time first rule was selected.
2. A non-monotonic production system: A non-monotonic production system is one in
which this is not true.
3. Partially commutative production system: A partially commutative production syste
m is a production system with the property that if the application of a particular sequence
of rules transforms state x into state y then any permutation of those rules that is allowable
(i.e. each rules preconditions are satisfied when it is applied) also
transforms state x into state y.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Partially commutative, monotonic production systems are useful for solving ignorable
problems.
4. A commutative production system: A commutative production system is a productio
n system that is both monotonic and partially commutative.

Advantages of production systems:

1. Production systems provide an excellent tool for structuring AI programs.


2. Production Systems are highly modular because the individual rules can be added, removed or
modified independently.
3. The production rules are expressed in a natural form, so the statements contained in the
knowledge base should be the recording of an expert thinking out loud.

Disadvantages of Production Systems:

1. One important disadvantage is the fact that it may be very difficult analyse the flow of control
within a production system because the individual rules don’t call each other.
2. Production systems describe the operations that can be performed in a search for a solution to
the problem.

CONTROL STRATEGIES:

Control Strategy in Artificial Intelligence scenario is a technique or strategy, tells us about


which rule has to be applied next while searching for the solution of a problem within
problem space. It helps us to decide which rule has to apply next without getting stuck at any
point.

Control strategy should be Systematic

Though the strategy applied should create the motion but if do not follow some systematic
strategy than we are likely to reach the same state number of times before reaching the solution
which increases the number of steps. Taking care of only first strategy we may go through
particular useless sequences of operators several times. Control Strategy should be systematic
implies a need for global motion (over the course of several steps) as well as for local motion
(over the course of single step).

Examples:

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Breadth-First Search: It searches along the breadth and follows first-in-first-out queue data
structure approach. It will start to scan node A first and then B-C-D-E-F.

Depth-First Search: It searches along the depth and follows the stack approach. The sequence
for scanning nodes will be A-B-D-E-C-F, it scans all the sub-nodes of parent nodes and then
moves to another node.

Widely used Control Strategies are Breadth-First Search, Depth-First Search, Generate and Test,
Hill-Climbing, Best-first search, Problem Reduction and many more.

Problem solving in control strategies is searching for a goal state.


Control strategies help us to decide which rule to apply next.
Good control strategy should
(i) Cause motion
(ii) Systematic
Cause motion Example:
(i) In a game playing program the pieces move on the board.
(ii) In the water jug problem water is used to fill jugs.
Systematic example:
It would not be sensible to fill a jug and empty it repeatedly
In a game it would not be advisable to move a piece round and round the
board in a cyclic way.

SEARCH STRATEGIES :

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

(i) Breadth-First Search. ...


(ii) Depth-First Search. ...
(iii) Bidirectional Search. ...
(iv) Uniform Cost Search. ...
(v) Iterative Deepening Depth-First Search. ...
(vi) Comparison of Various Algorithms Complexities. ...
(vii) Heuristic Evaluation Functions. ...
(viii) Pure Heuristic Search.

Search Terminology
 Problem Space − It is the environment in which the search takes place. (A set of states
and set of operators to change those states)
 Problem Instance − It is Initial state + Goal state.
 Problem Space Graph − It represents problem state. States are shown by nodes and
operators are shown by edges.
 Depth of a problem − Length of a shortest path or shortest sequence of operators from
Initial State to goal state.
 Space Complexity − The maximum number of nodes that are stored in memory.
 Time Complexity − The maximum number of nodes that are created.
 Admissibility − A property of an algorithm to always find an optimal solution.
 Branching Factor − The average number of child nodes in the problem space graph.
 Depth − Length of the shortest path from initial state to goal state.

Brute-Force Search Strategies


They are most simple, as they do not need any domain-specific knowledge. They work fine with
small number of possible states.

Requirements −

 State description
 A set of valid operators
 Initial state
 Goal state description

Breadth-First Search

It starts from the root node, explores the neighboring nodes first and moves towards the next
level neighbors. It generates one tree at a time until the solution is found. It can be implemented
using FIFO queue data structure. This method provides shortest path to the solution.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

If branching factor (average number of child nodes for a given node) = b and depth = d, then
number of nodes at level d = bd.

The total no of nodes created in worst case is b + b2 + b3 + … + bd.

Disadvantage − Since each level of nodes is saved for creating next one, it consumes a lot of
memory space. Space requirement to store nodes is exponential.

Its complexity depends on the number of nodes. It can check duplicate nodes.

Depth-First Search

It is implemented in recursion with LIFO stack data structure. It creates the same set of nodes as
Breadth-First method, only in the different order.

As the nodes on the single path are stored in each iteration from root to leaf node, the space
requirement to store nodes is linear. With branching factor b and depth as m, the storage space is
bm.

Disadvantage − This algorithm may not terminate and go on infinitely on one path. The solution
to this issue is to choose a cut-off depth. If the ideal cut-off is d, and if chosen cut-off is lesser
than d, then this algorithm may fail. If chosen cut-off is more than d, then execution time
increases.

Its complexity depends on the number of paths. It cannot check duplicate nodes.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Bidirectional Search

It searches forward from initial state and backward from goal state till both meet to identify a
common state.

The path from initial state is concatenated with the inverse path from the goal state. Each search
is done only up to half of the total path.

Uniform Cost Search

Sorting is done in increasing cost of the path to a node. It always expands the least cost node. It
is identical to Breadth First search if each transition has the same cost.

It explores paths in the increasing order of cost.

Disadvantage − There can be multiple long paths with the cost ≤ C*. Uniform Cost search must
explore them all.

Iterative Deepening Depth-First Search

It performs depth-first search to level 1, starts over, executes a complete depth-first search to
level 2, and continues in such way till the solution is found.

It never creates a node until all lower nodes are generated. It only saves a stack of nodes. The
algorithm ends when it finds a solution at depth d. The number of nodes created at depth d is bd
and at depth d-1 is bd-1.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Comparison of Various Algorithms Complexities

Let us see the performance of algorithms based on various criteria −

Interactive
Criterion Breadth First Depth First Bidirectional Uniform Cost
Deepening
Time bd bm bd/2 bd bd
Space bd bm bd/2 bd bd
Optimality Yes No Yes Yes Yes
Completeness Yes No Yes Yes Yes

Informed (Heuristic) Search Strategies


To solve large problems with large number of possible states, problem-specific knowledge needs
to be added to increase the efficiency of search algorithms.

Heuristic Evaluation Functions

They calculate the cost of optimal path between two states. A heuristic function for sliding-tiles
games is computed by counting number of moves that each tile makes from its goal state and
adding these number of moves for all tiles.

Pure Heuristic Search

It expands nodes in the order of their heuristic values. It creates two lists, a closed list for the
already expanded nodes and an open list for the created but unexpanded nodes.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

In each iteration, a node with a minimum heuristic value is expanded, all its child nodes are
created and placed in the closed list. Then, the heuristic function is applied to the child nodes and
they are placed in the open list according to their heuristic value. The shorter paths are saved and
the longer ones are disposed.

A * Search

It is best-known form of Best First search. It avoids expanding paths that are already expensive,
but expands most promising paths first.

f(n) = g(n) + h(n), where

 g(n) the cost (so far) to reach the node


 h(n) estimated cost to get from the node to the goal
 f(n) estimated total cost of path through n to goal. It is implemented using priority queue
by increasing f(n).

Greedy Best First Search

It expands the node that is estimated to be closest to goal. It expands nodes based on f(n) = h(n).
It is implemented using priority queue.

Disadvantage − It can get stuck in loops. It is not optimal.

Local Search Algorithms


They start from a prospective solution and then move to a neighboring solution. They can return
a valid solution even if it is interrupted at any time before they end.

Hill-Climbing Search

It is an iterative algorithm that starts with an arbitrary solution to a problem and attempts to find
a better solution by changing a single element of the solution incrementally. If the change
produces a better solution, an incremental change is taken as a new solution. This process is
repeated until there are no further improvements.

function Hill-Climbing (problem), returns a state that is a local maximum.

inputs: problem, a problem


local variables: current, a node
neighbor, a node
current <-Make_Node(Initial-State[problem])
loop
do neighbor <- a highest_valued successor of current

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

if Value[neighbor] ≤ Value[current] then


return State[current]
current <- neighbor

end

Disadvantage − This algorithm is neither complete, nor optimal.

Local Beam Search

In this algorithm, it holds k number of states at any given time. At the start, these states are
generated randomly. The successors of these k states are computed with the help of objective
function. If any of these successors is the maximum value of the objective function, then the
algorithm stops.

Otherwise the (initial k states and k number of successors of the states = 2k) states are placed in a
pool. The pool is then sorted numerically. The highest k states are selected as new initial states.
This process continues until a maximum value is reached.

function BeamSearch( problem, k), returns a solution state.

start with k randomly generated states


loop
generate all successors of all k states
if any of the states = solution, then return the state
else select the k best successors
end

Simulated Annealing

Annealing is the process of heating and cooling a metal to change its internal structure for
modifying its physical properties. When the metal cools, its new structure is seized, and the
metal retains its newly obtained properties. In simulated annealing process, the temperature is
kept variable.

We initially set the temperature high and then allow it to ‘cool' slowly as the algorithm proceeds.
When the temperature is high, the algorithm is allowed to accept worse solutions with high
frequency.

Start

 Initialize k = 0; L = integer number of variables;


 From i → j, search the performance difference Δ.
 If Δ <= 0 then accept else if exp(-Δ/T(k)) > random(0,1) then accept;
 Repeat steps 1 and 2 for L(k) steps.
 k = k + 1;

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Repeat steps 1 through 4 till the criteria is met.

End

Travelling Salesman Problem

In this algorithm, the objective is to find a low-cost tour that starts from a city, visits all cities en-
route exactly once and ends at the same starting city.

Start
Find out all (n -1)! Possible solutions, where n is the total number of cities.
Determine the minimum cost by finding out the cost of each of these (n -1)! solutions.
Finally, keep the one with the minimum cost.
end

PROBLEM SOLVING METHODS IN ARTIFICIAL


INTELLIGENCE
Problem-solving in Artificial Intelligence usually refers to researching a solution to a problem
by performing logical algorithms, utilizing polynomial and differential equations, and
executing them using modeling paradigms. There can be various solutions to a single problem,
which are achieved by different heuristics.

Examples of Problems in Artificial Intelligence

Developers worldwide are using artificial intelligence to automate systems for efficient
utilization of time and resources. Some of the most common problems encountered in day-to-day

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

life are games and puzzles. These can be solved efficiently by using artificial intelligence
algorithms. Ranging from mathematical puzzles including crypto-arithmetic and magic squares,
logical puzzles including Boolean formulas and N-Queens to popular games like Sudoku and
Chess, these problem-solving techniques are used to form a solution for all these. Therefore,
some of the most prevalent problems that artificial intelligence has resolved are the following:

 Chess
 N-Queen problem
 Tower of Hanoi Problem
 Travelling Salesman Problem
 Water-Jug Problem

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

PROBLEM GRAPHS, MATCHING :


Matching algorithms are algorithms used to solve graph matching problems in graph theory. A
matching problem arises when a set of edges must be drawn that do not share any vertices.

Graph matching problems are very common in daily activities. From online matchmaking and
dating sites, to medical residency placement programs, matching algorithms are used in areas
spanning scheduling, planning, pairing of vertices, and network flows. More specifically,
matching strategies are very useful in flow network algorithms such as the Ford-Fulkerson
algorithm and the Edmonds-Karp algorithm.

Graph matching algorithms often use specific properties in order to identify sub-optimal areas in
a matching, where improvements can be made to reach a desired goal. Two famous properties
are called augmenting paths and alternating paths, which are used to quickly determine
whether a graph contains a maximum, or minimum, matching, or the matching can be further
improved.

Graph 1Graph 1 shows all the edges, in blue, that connect the bipartite graph. The goal of a
matching algorithm, in this and all bipartite graph cases, is to maximize the number of
connections between vertices in subset AA, above, to the vertices in subset BB, below.

Graph 1Graph 1. Unmatched bipartite graph

Most algorithms begin by randomly creating a matching within a graph, and further refining the
matching in order to attain the desired objective.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Random initial matching , MM, of


Graph 1 represented by the red edges

Graph 1Graph 1, with the matching, MM, is said to have an alternating path if there is a path
whose edges are in the matching, MM, and not in the matching, in an alternating fashion. An
alternating path usually starts with an unmatched vertex and terminates once it cannot append
another edge to the tail of the path while maintaining the alternating sequence.

An alternating path in Graph 1 is


represented by red edges, in MM, joined with green edges, not in MM.

An augmenting path, then, builds up on the definition of an alternating path to describe a path
whose endpoints, the vertices at the start and the end of the path, are free, or unmatched, vertices;
vertices not included in the matching. Finding augmenting paths in a graph signals the lack of a
maximum matching.

The matching, MM, for Graph 1Graph 1, does not start and end on free vertices, so it does not
have an augmenting path. This implies that the matching MM is a maximum matching.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

BREADTH FIRST SEARCH (BFS)


The Breadth-First Search Algorithm? Breadth-First Search algorithm is a graph traversing
technique, where you select a random initial node (source or root node) and start traversing the
graph layer-wise in such a way that all the nodes and their respective children nodes are visited
and explored.

 Breadth first search is a general technique of traversing a graph. Breadth first search may
use more memory but will always find the shortest path first.
 In this type of search the state space is represented inform of a tree. The solution is
obtained by traversing through the tree.
 The nodes of the tree represent the start value or starting state, various intermediate states
and the final state.
 In this search a queue data structure is used and it is level by level traversal.
 Breadth first search expands nodes in order of their distance from the root. It is a path
finding algorithm that is capable of always finding the solution if one exists.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 The solution which is found is always the optional solution. This task is completed in a
very memory intensive manner. Each node in the search tree is expanded in a breadth
wise at each level.
Concept:
Step 1: Traverse the root node
Step 2: Traverse all neighbours of root node.
Step 3: Traverse all neighbours of neighbours of the root node.
Step 4: This process will continue until we are getting the goal node.
Algorithm:
Step 1: Place the root node inside the queue.
Step 2: If the queue is empty then stops and return failure.
Step 3: If the FRONT node of the queue is a goal node then stop and return success.
Step 4: Remove the FRONT node from the queue. Process it and find all its neighbours that are
in readystate then place them inside the queue in any order.
Step 5: Go to Step 3.
Step 6: Exit.

Implementation:
Let us implement the above algorithm of BFS by taking the following suitable example.

Figure
Consider the graph in which let us take A as the starting node and F as the goal node (*)
Step 1:
Place the root node inside the queue i.e. A
A
Step 2:
Now the queue is not empty and also the FRONT node i.e. A is not our goal node. So move to
step 3.
A
Step 3:
So remove the FRONT node from the queue i.e. A and find the neighbour of A i.e. B and C
B C A
Step 4:
Now B is the FRONT node of the queue .So process B and finds the neighbours of B i.e. D.
C D B
Step 5:
Now find out the neighbours of C i.e. E

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

D E C
Step 6:
Next find out the neighbours of D as D is the FRONT node of the queue
E F D
Step 7:
Now E is the front node of the queue. So the neighbour of E is F which is our goal node.
F E
Step 8:
Finally F is our goal node which is the FRONT of the queue. So exit.
F
Advantages:
 In this procedure at any way it will find the goal.
 It does not follow a single unfruitful path for a long time.
 It finds the minimal solution in case of multiple paths.
Disadvantages:
 BFS consumes large memory space.
 Its time complexity is more.
 It has long pathways, when all paths to a destination are on approximately the same
search depth.

DEPTH FIRST SEARCH (DFS)

The depth-first search or DFS algorithm traverses or explores data structures, such as
trees and graphs. The algorithm starts at the root node (in the case of a graph, you can use any
random node as the root node) and examines each branch as far as possible before backtracking

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 DFS is also an important type of uniform search.


 DFS visits all the vertices in the graph.
 This type ofalgorithm always chooses to go deeper into the graph.
 After DFS visited all the reachable vertices from aparticular sources vertices it chooses
one of the remaining undiscovered vertices and continues the search.
 DFS reminds the space limitation of breath first search by always generating next a child
of the deepestunexpanded node.
 The data structure stack or last in first out (LIFO) is used for DFS.

Concept:
Step 1: Traverse the root node.
Step 2: Traverse any neighbour of the root node.
Step 3: Traverse any neighbour of neighbour of the root node.
Step 4: This process will continue until we are getting the goal node.

Algorithm:
Step 1: PUSH the starting node into the stack.
Step 2: If the stack is empty then stop and return failure.
Step 3: If the top node of the stack is the goal node, then stop and return success.
Step 4: Else POP the top node from the stack and process it. Find all its neighbours that are in
ready stateand PUSH them into the stack in any order.
Step 5: Go to step 3.
Step 6: Exit.

Implementation:
Let us take an example for implementing the above DFS algorithm.

Figure
Examples of DFS
Consider A as the root node and L as the goal node in the graph figure
Step 1: PUSH the starting node into the stack i.e.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Step 2: Now the stack is not empty and A is not our goal node. Hence move to next step.
A

Step 3: POP the top node from the stack i.e. A and find the neighbours of A i.e. B and C.
B C A

Step 4: Now C is top node of the stack. Find its neighbours i.e. F and G.
B F G C

Step 5: Now G is the top node of the stack. Find its neighbour i.e. M
B F M G

Step 6: Now M is the top node and find its neighbour, but there is no neighbours of M in the
graph so
POP it from the stack.
B F M

Step 7: Now F is the top node and its neighbours are K and L. so PUSH them on to the stack.
B K L F

Step 8: Now L is the top node of the stack, which is our goal node.
B K L

Also you can traverse the graph starting from the root A and then insert in the order C and B into
the
stack.

Advantages:
 DFSconsumes very less memory space.
 It will reach at the goal node in a less time period than BFS if it traverses in a right path.
 It may find a solution without examining much of search because we may get the desired
solutionin the very first go.
Disadvantages:
 It is possible that may states keep reoccurring.
 There is no guarantee of finding the goal node.
 Sometimes the states may also enter into infinite loops.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

DIFFERENCE BETWEEN BFS AND DFS :


BFS
 It uses the data structure queue.
 BFS is complete because it finds the solution if one exists.
 BFS takes more space i.e. equivalent to o (bd) where b is the maximum breath exist in a
search
tree and d is the maximum depth exit in a search tree.
 In case of several goals, it finds the best one.
DFS
 It uses the data structure stack.
 It is not complete because it may take infinite loop to reach at the goal node.
 The space complexity is O (d).
 In case of several goals, it will terminate the solution in any order.

HILL CLIMBING :

Hill Climbing Algorithm in Artificial


Intelligence
 Hill climbing algorithm is a local search algorithm which continuously moves in the
direction of increasing elevation/value to find the peak of the mountain or best solution to
the problem. It terminates when it reaches a peak value where no neighbor has a higher
value.
 Hill climbing algorithm is a technique which is used for optimizing the mathematical
problems. One of the widely discussed examples of Hill climbing algorithm is Traveling-
salesman Problem in which we need to minimize the distance traveled by the salesman.
 It is also called greedy local search as it only looks to its good immediate neighbor state
and not beyond that.
 A node of hill climbing algorithm has two components which are state and value.
 Hill Climbing is mostly used when a good heuristic is available.
 In this algorithm, we don't need to maintain and handle the search tree or graph as it only
keeps a single current state.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Features of Hill Climbing:


Following are some main features of Hill Climbing Algorithm:

 Generate and Test variant: Hill Climbing is the variant of Generate and Test method.
The Generate and Test method produce feedback which helps to decide which direction
to move in the search space.
 Greedy approach: Hill-climbing algorithm search moves in the direction which
optimizes the cost.
 No backtracking: It does not backtrack the search space, as it does not remember the
previous states.

State-space Diagram for Hill Climbing:


The state-space landscape is a graphical representation of the hill-climbing algorithm which is
showing a graph between various states of algorithm and Objective function/Cost.

On Y-axis we have taken the function which can be an objective function or cost function, and
state-space on the x-axis. If the function on Y-axis is cost then, the goal of search is to find the
global minimum and local minimum. If the function of Y-axis is Objective function, then the
goal of the search is to find the global maximum and local maximum.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 Hill climbing is often used when a good heuristic function is available for evaluating
states but when no other useful knowledge is available.
 Searching for a goal state = Climbing to the top of a hill
• Generate-and-test + direction to move.
• Heuristic function to estimate how close a given state is to a goal state.
Example:
Suppose you are in an unfamiliar city without a map and you want to get downtown which
consists of tall buildings.
You simply aim for the tall buildings.
Getting downtown is an example of such a problem. For these problems, hill climbing can
terminate whenever a goal state is reached. Only relative solutions exist.
Algorithm:
1. Evaluate the initial state.
2. Loop until a solution is found or there are no new operators left to be applied:
a) Select and apply a new operator
b) Evaluate the new state:
i. goal-> quit
ii. better than current state-> new current state
iii. not better than the current state->Continue the loop
Steepest-Ascent Hill Climbing
 A useful variation on simple hill climbing considers all the moves from the current state
and selects the best one as the next state. This method is called steepest-ascenthill climbing
or gradient search.
 Considers all the moves from the current state.
 Selects the best one as the next state.
Algorithm: Steepest-Ascent Hill Climbing
1. Evaluate the initial state.
2. Loop until a solution is found or a complete iteration produces no change to current state:
a. SUCC = a state such that any possible successor of the
current state will be better than SUCC (the worst state).
b. For each operator that applies to the current state, evaluatethe new state:
i. goal-> quit
ii. better than SUCC-> set SUCC to this state
c. SUCC is better than the current state-> set the currentstate to SUCC.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Hill Climbing & Steepest Hill climbing: Disadvantages


Local maximum
A state that is better than all of its neighbours, but not better than some
other states far away.

Plateau
It is a flat area of the search space in which all neighbouring states have the
same value.

Ridge
It is a special kind of local maximum. It is an area of the search space that is
higher than surrounding areas and that itself has slope.

Ways Out:
 Backtrack to some earlier node and try going in a different direction.
 Make a big jump to try to get in a new section.
 Moving in several directions at once.

HEURISITIC SEARCH TECHNIQUES


 Heuristic is a technique which makes our search algorithm more efficient.
 Heuristic is a problem specific knowledge that decreases expected search efforts.
 It is a technique which sometimes works but not always.
 Generally heuristic improve efficiency over blind search.
 Generally a term heuristicis used for any advice that is effective but is not guaranteed to
work in every case. For example in case of travelling sales man (TSP) problem we are using
a heuristic to calculate the nearest neighbour.
 This technique is useful in solving though problems which could not be solved in any other
way.
 Solutions take an infinite time to compute.

State space search


“It is complete set of states including start and goal states, where the answer of the
problem is to be searched”.
Problem
“It is the question which is to be solved. For solving the problem it needs to be precisely defined.
The definition means, defining the start state, goal state, other valid states and transitions”. A
state space representation allows for the formal definition of a problem which makes the

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

movement from initial state to the goal state quite easily. So we can say that various problems
like planning, learning, theorem proving etc. are all essentially search problems only.

State space search is a process used in the field of computer science, including artificial
intelligence (AI), in which successive configurations or states of an instance are considered, with
the goal of finding a goal state with a desired property.

Example1:

The eight tile puzzle problem formulation. The eight tile puzzle consist of a 3 by 3 (3*3) square
frame board which holds 8 movable tiles numbered 1 to 8. One square is empty, allowing the
adjacent tiles to be shifted. The objective of the puzzle is to find a sequence of tile movements
that leads from a starting configuration to a goal configuration.

The states of 8 tile puzzle are the different permutations of the tiles within frame.

Lets do a standard formulation of this problem now.

States: It specifies the location of each of the 8 tiles and the blank in one of the nice squares.
Initial state: Any state can be designated as the initial state.
Goal: Many goal configurations are possible one such is shown in the figure
Legal moves (or state): They generate legal states that result from trying the four actions-

 Blank moves left


 Blank moves right
 Blank moves up
 Blank moves down

Path cost: Each step costs 1, so the path cost is the number of steps in the path.
The tree diagram showing the search space is shown in figure.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

( HEURISITIC SEARCH TECHNIQUES )

A*SEARCHALGORITHM?

A* Search Algorithm is a simple and efficient search algorithm that can be used to find the
optimal path between two nodes in a graph. It will be used for the shortest path finding. It is
an extension of Dijkstra's shortest path algorithm (Dijkstra's Algorithm).

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

A* Search algorithm is one of the best and popular technique used in path-finding and graph
traversals.
Why A* Search Algorithm ?
Informally speaking, A* Search algorithms, unlike other traversal techniques, it has “brains”.
What it means is that it is really a smart algorithm which separates it from the other conventional
algorithms. This fact is cleared in detail in below sections.
And it is also worth mentioning that many games and web-based maps use this algorithm to find
the shortest path very efficiently (approximation).

(A* Algorithm)

Algorithm
We create two lists – Open List and Closed List (just like Dijkstra Algorithm)
// A* Search Algorithm
1. Initialize the open list
2. Initialize the closed list
put the starting node on the open

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

list (you can leave its f at zero)

3. while the open list is not empty


a) find the node with the least f on
the open list, call it "q"

b) pop q off the open list

c) generate q's 8 successors and set their


parents to q

d) for each successor


i) if successor is the goal, stop search
successor.g = q.g + distance between
successor and q
successor.h = distance from goal to
successor (This can be done using many
ways, we will discuss three heuristics-
Manhattan, Diagonal and Euclidean
Heuristics)

successor.f = successor.g + successor.h

ii) if a node with the same position as


successor is in the OPEN list which has a
lower f than successor, skip this successor

iii) if a node with the same position as


successor is in the CLOSED list which has
a lower f than successor, skip this successor
otherwise, add the node to the open list
end (for loop)

e) push q on the closed list


end (while loop)

CONSTRAINT SATISFACTION PROBLEM :


In artificial intelligence and operations research, constraint satisfaction is the process of finding
a solution to a set of constraints that impose conditions that the variables must satisfy.[1] A
solution is therefore a set of values for the variables that satisfies all constraints—that is, a point
in the feasible region.
The techniques used in constraint satisfaction depend on the kind of constraints being
considered. Often used are constraints on a finite domain, to the point that constraint satisfaction

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

problems are typically identified with problems based on constraints on a finite domain. Such
problems are usually solved via search, in particular a form of backtracking or local
search. Constraint propagation are other methods used on such problems; most of them are
incomplete in general, that is, they may solve the problem or prove it unsatisfiable, but not
always. Constraint propagation methods are also used in conjunction with search to make a given
problem simpler to solve. Other considered kinds of constraints are on real or rational numbers;
solving problems on these constraints is done via variable elimination or the simplex algorithm.
Constraint satisfaction problems on finite domains are typically solved using a form of search.
The most used techniques are variants of backtracking, constraint propagation, and local search.
These techniques are used on problems with nonlinear constraints.
Variable elimination and the simplex algorithm are used for
solving linear and polynomial equations and inequalities, and problems containing variables with
infinite domain. These are typically solved as optimization problems in which the optimized
function is the number of violated constraints.

Constraint Satisfaction Problems in Artificial Intelligence

We have seen so many techniques like Local search, Adversarial search to solve different
problems. The objective of every problem-solving technique is one, i.e., to find a solution to
reach the goal. Although, in adversarial search and local search, there were no constraints on the
agents while solving the problems and reaching to its solutions.

In this section, we will discuss another type of problem-solving technique known as Constraint
satisfaction technique. By the name, it is understood that constraint satisfaction means solving a
problem under certain constraints or rules.

Constraint satisfaction is a technique where a problem is solved when its values satisfy certain
constraints or rules of the problem. Such type of technique leads to a deeper understanding of
the problem structure as well as its complexity.

Constraint satisfaction depends on three components, namely:

 X: It is a set of variables.
 D: It is a set of domains where the variables reside. There is a specific domain for each
variable.
 C: It is a set of constraints which are followed by the set of variables.

In constraint satisfaction, domains are the spaces where the variables reside, following the
problem specific constraints. These are the three main elements of a constraint satisfaction
technique. The constraint value consists of a pair of {scope, rel}. The scope is a tuple of

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

variables which participate in the constraint and rel is a relation which includes a list of values
which the variables can take to satisfy the constraints of the problem.

Solving Constraint Satisfaction Problems

The requirements to solve a constraint satisfaction problem (CSP) is:

 A state-space
 The notion of the solution.

A state in state-space is defined by assigning values to some or all variables such as

{X1=v1, X2=v2, and so on…}.

An assignment of values to a variable can be done in three ways:

 Consistent or Legal Assignment: An assignment which does not violate any constraint
or rule is called Consistent or legal assignment.
 Complete Assignment: An assignment where every variable is assigned with a value,
and the solution to the CSP remains consistent. Such assignment is known as Complete
assignment.
 Partial Assignment: An assignment which assigns values to some of the variables only.
Such type of assignments are called Partial assignments.

Types of Domains in CSP

There are following two types of domains which are used by the variables :

 Discrete Domain: It is an infinite domain which can have one state for multiple
variables. For example, a start state can be allocated infinite times for each variable.
 Finite Domain: It is a finite domain which can have continuous states describing one
domain for one specific variable. It is also called a continuous domain.

Constraint Types in CSP

With respect to the variables, basically there are following types of constraints:

 Unary Constraints: It is the simplest type of constraints that restricts the value of a
single variable.
 Binary Constraints: It is the constraint type which relates two variables. A value x2 will
contain a value which lies between x1 and x3.
 Global Constraints: It is the constraint type which involves an arbitrary number of
variables.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Some special types of solution algorithms are used to solve the following types of
constraints:

 Linear Constraints: These type of constraints are commonly used in linear


programming where each variable containing an integer value exists in linear form only.
 Non-linear Constraints: These type of constraints are used in non-linear programming
where each variable (an integer value) exists in a non-linear form.

Note: A special constraint which works in real-world is known as Preference constraint.

Constraint Propagation

In local state-spaces, the choice is only one, i.e., to search for a solution. But in CSP, we have
two choices either:

 We can search for a solution or


 We can perform a special type of inference called constraint propagation.

Constraint propagation is a special type of inference which helps in reducing the legal number
of values for the variables. The idea behind constraint propagation is local consistency.

In local consistency, variables are treated as nodes, and each binary constraint is treated as an
arc in the given problem. There are following local consistencies which are discussed below:

 Node Consistency: A single variable is said to be node consistent if all the values in the
variable’s domain satisfy the unary constraints on the variables.
 Arc Consistency: A variable is arc consistent if every value in its domain satisfies the
binary constraints of the variables.
 Path Consistency: When the evaluation of a set of two variable with respect to a third
variable can be extended over another variable, satisfying all the binary constraints. It is
similar to arc consistency.
 k-consistency: This type of consistency is used to define the notion of stronger forms of
propagation. Here, we examine the k-consistency of the variables.

CSP Problems

Constraint satisfaction includes those problems which contains some constraints while solving
the problem. CSP includes the following problems:

 Graph Coloring: The problem where the constraint is that no adjacent sides can have the
same color.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 Sudoku Playing: The gameplay where the constraint is that no number from 0-9 can be
repeated in the same row or column.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 n-queen problem: In n-queen problem, the constraint is that no queen should be placed
either diagonally, in the same row or column.

Note: The n-queen problem is already discussed in Problem-solving in AI section.

 Crossword: In crossword problem, the constraint is that there should be the correct
formation of the words, and it should be meaningful.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

 Latin square Problem: In this game, the task is to search the pattern which is occurring
several times in the game. They may be shuffled but will contain the same digits.

 Cryptarithmetic Problem: This problem has one most important constraint that is, we
cannot assign a different digit to the same character. All digits should contain a unique
alphabet.

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications


KARPAGAM ACADEMY OF HIGHER EDUCATION
DEPARTMENT OF COMPUTER APPLICATIONS
COURSE NAME : ARTIFICIAL INTELLIGENCE COURSE CODE :20CAU601
BATCH : BCA 2020 -2023 UNIT : I

Prepared by H.RAMPRASANTH, Assistant Professor, Department of Computer Applications

You might also like