Unit I
Unit I
PROBLEM SOLVING
Page 1
TECHNICAL TERMS
Page 2
8. Local Maxima Local means relating to
A local maximum is a peak
place and maxima means
maximum. that is higher than each of its
neighboring states but lower
than the global maximum.
Page 3
UNIT I PROBLEM SOLVING
1.1.2 Types of AI
1.2 Applications of AI
Page 4
1.5.5 Iterative Deepening Depth First Search
Page 5
1.1 Introduction to Artificial Intelligence
● "Artificial Intelligence is a branch of computer science that deals with
developing intelligent machines which can behave like human, think like
human, and has ability to take decisions by their own."
● Artificial Intelligence is a combination of two words Artificial and Intelligence,
which refers to man-made intelligence. Therefore, when machines are equipped
with man-made intelligence to perform intelligent tasks similar to humans, it is
known as Artificial Intelligence. It is all about developing intelligent machines
that can simulate the human brain and work & behave like human beings.
Page 6
1.1.2 TYPES OF ARTIFICIAL INTELLIGENCE
Artificial Intelligence can be divided in various types, there are mainly two types
of main categorization which are based on capabilities and based on functionally of
AI. Following is flow diagram which explain the types of AI.
Page 7
❖ General AI is a type of intelligence which could perform any
intellectual task with efficiency like a human.
❖ The idea behind the general AI to make such a system which could
be smarter and think like a human by its own.
❖ Currently, there is no such system exist which could come under
general AI and can perform any task as perfect as a human.
❖ The worldwide researchers are now focused on developing machines
with General AI.
❖ As systems with general AI are still under research, and it will take lots
of efforts and time to develop such systems.
3. Super AI:
1. Reactive Machines
❖ Purely reactive machines are the most basic types of Artificial Intelligence.
❖ Such AI systems do not store memories or past experiences for future
Page 8
❖ These machines only focus on current scenarios and react on it as
per possible best action.
❖ IBM's Deep Blue system is an example of reactive machines.
❖ Google's AlphaGo is also an example of reactive machines.
2. Limited Memory
❖ Limited memory machines can store past experiences or some data for a
short period of time.
❖ These machines can use stored data for a limited time period only.
❖ Self-driving cars are one of the best examples of Limited Memory
systems. These cars can store recent speed of nearby cars, the distance of
other cars, speed limit, and other information to navigate the road.
3. Theory of Mind
❖ Theory of Mind AI should understand the human emotions,
people, beliefs, and be able to interact socially like humans.
❖ This type of AI machines is still not developed, but researchers are
making lots of efforts and improvement for developing such AI machines.
4. Self-Awareness
❖ Self-awareness AI is the future of Artificial Intelligence. These machines
will be super intelligent, and will have their own consciousness,
sentiments, and self-awareness.
❖ These machines will be smarter than human mind.
❖ Self-Awareness AI does not exist in reality still and it is a hypothetical
concept.
A.I Approaches
The definitions of AI according to some text books are categorized into
four approaches and are summarized in the table below:
❖ Systems that think like human
❖ Systems that act like human
❖ Systems that think rationally
❖ Systems that act rationally
Page 9
Thinking Humanly Thinking Rationally
―The exciting new effort to ―The study of mental
faculties through the use of
make computers think …
machines computational modelsǁ.
with minds, in the full and literal (Chamiak and McDermott, 1985)
senseǁ. (Haugeland, 1985)
―(The automation of) activities ―The study of the computations
that we associate with human that make it possible to perceive,
thinking, activities such as reason, and actǁ.
decision-making, problem solving, (―Winston, 1992)
learning …ǁ
Once there is sufficient precise theory of the mind, it becomes possible to express
the theory as a computer program
Cognitive Study of Human Mind:
It is a highly interdisciplinary field which combines ideas and methods from
psychology, computer science, philosophy, linguistics and neuroscience.
The goal of cognitive science is to characterize the nature of human knowledge
Page 10
Paavai InstitutionsDepartment of CSE
and how that knowledge is used, processed and acquired
Page 11
Paavai Institutions Department of CSE
said to involve inference.
The rational-agent approach to AI has two advantages over the other approaches.
First, it is more general than the ―laws of thoughtǁ approach because correct
inference is just one of several possible mechanisms for achieving rationality.
Second, it is suitable for scientific development.
1.2 APPLICATIONS OF AI
1. Game Playing:
AI is widely used in Gaming. Different strategic games such as Chess, where the
machine needs to think logically, and video games to provide real-time experiences
use Artificial Intelligence.
2. Robotics:
Artificial Intelligence is commonly used in the field of Robotics to develop
intelligent robots. AI implemented robots use real-time updates to sense any obstacle
in their path and can change the path instantly. AI robots can be used for carrying
goods in hospitals and industries and can also be used for other different purposes.
3. Healthcare:
In the healthcare sector, AI has diverse uses. In this field, AI can be used to detect
diseases and cancer cells. It also helps in finding new drugs with the use of historical
data and medical intelligence.
4. Computer Vision:
Computer vision enables the computer system to understand and derive
meaningful information from digital images, video, and other visual input with the
help of AI.
5. Agriculture:
AI is now widely used in Agriculture; for example, with the help of AI, we can
easily identify defects and nutrient absences in the soil. To identify these defects, AI
robots can be utilized. AI bots can also be used in crop harvesting at a higher speed
than human workers.
6. E-commerce:
AI is one of the widely used and demanding technologies in the E-commerce
Page 12
Paavai Institutions Department of CSE
industry. With AI, e-commerce businesses are gaining more profit and grow in
business by recommending products as per the user requirement.
7. Social Media
Different social media websites such as Facebook, Instagram, Twitter, etc., use AI
to make the user experiences much better by providing different features. For
example, Twitter uses AI to recommend tweets as per the user interest and search
history.
Page 13
Paavai Institutions Department of CSE
open-loop system: ignoring the percepts breaks the loop between agent
and environment. If there is a chance that the model is incorrect, or the
environment is nondeterministic, then the agent would be safer using a
closed-loop approach that monitors the percepts.
1.3.1 COMPONENTS TO FORMULATE THE ASSOCIATED PROBLEM
❖ 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 determine 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.
Page 14
Paavai Institutions Department of CSE
1.4.1 SEARCH ALGORITHM TERMINOLOGIES
Following are the four essential properties of search algorithms to compare the
efficiency of these algorithms:
Completeness: A search algorithm is said to be complete if it guarantees to return
a solution if at least any solution exists for any random input.
Optimality: If a solution found for an algorithm is guaranteed to be the best
solution (lowest path cost) among all other solutions, then such a solution for is said
to be an optimal solution.
Time Complexity: Time complexity is a measure of time for an algorithm to
complete its task.
Space Complexity: It is the maximum storage space required at any point during
the search, as the complexity of the problem.
Based on the search problems we can classify the search algorithms into
Page 15
Paavai Institutions Department of CSE
uninformed (Blind search) search and informed search (Heuristic search) algorithms.
Page 16
Paavai Institutions Department of CSE
another way.
❖ It requires lots of memory since each level of the tree must be saved
into memory to expand the next level.
❖ BFS needs lots of time if the solution is far away from the root node.
Example:
In the below tree structure, we have shown the traversing of the tree using BFS
algorithm from the root node S to goal node K. BFS search algorithm traverse in
layers, so it will follow the path which is shown by the dotted arrow, and the
traversed path will be:
1. S → A→ B → C → D → G → H → E → F → I → K
Page 18
Paavai Institutions Department of CSE
of the node.
Advantage:
❖ DFS requires very less memory as it only needs to store a stack of the
nodes on the path from root node to the current node.
❖ It takes less time to reach to the goal node than BFS algorithm (if it
traverses in the right path).
Disadvantage:
❖ There is the possibility that many states keep re-occurring, and there is no
guarantee of finding the solution.
❖ DFS algorithm goes for deep down searching and sometime it may go to
the infinite loop.
Example:
In the below search tree, we have shown the flow of depth-first search, and it will
follow the order as:
Root node -> Left node -> right node
It will start searching from root node S, and traverse A, then B, then D and E,
after traversing E, it will backtrack the tree as E has no other successor and still goal
node is not found. After backtracking it will traverse node C and then G, and here it
will terminate as it found goal node.
Page 19
Paavai Institutions Department of CSE
Where, m = maximum depth of any node and this can be much larger than d
(Shallowest solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root
node, hence space complexity of DFS is equivalent to the size of the fringe set,
which is O(bm).
Optimal: DFS search algorithm is non-optimal, as it may generate a large
number of steps or high cost to reach to the goal node.
Page 20
Paavai Institutions Department of CSE
Advantages:
Disadvantages:
❖ Depth-limited search also has a disadvantage of incompleteness.
❖ It may not be optimal if the problem has more than one solution.
Example:
❖ The primary goal of the uniform-cost search is to find a path to the goal node
which has the lowest cumulative cost.
❖ Uniform-cost search expands nodes according to their path costs form the
Page 21
Paavai Institutions Department of CSE
root node. It can be used to solve any graph/tree where the optimal cost is in
demand.
❖ Uniform cost search is equivalent to BFS algorithm if the path cost of all
edges is the same.
Advantages:
❖ Uniform cost search is optimal because at every state the path with the least
cost is chosen.
Disadvantages:
❖ It does not care about the number of steps involve in searching and only
concerned about path cost. Due to which this algorithm may be stuck in an
infinite loop.
Example:
Completeness:
Uniform-cost search is complete, such as if there is a solution, UCS will find it.
Time Complexity:
Let C* is Cost of the optimal solution, and ε is each step to get closer to the goal
node. Then the number of steps is = C*/ ε + 1. Here we have taken +1, as we start
from state 0 and end to C*/ ε.
Hence, the worst-case time complexity of Uniform-cost search is O(b1 + [C*/ ε])/.
Page 22
Paavai Institutions Department of CSE
Space Complexity:
The same logic is for space complexity so, the worst-case space complexity of
Uniform-cost search is O(b1 + [C*/ ε]).
Optimal:
Uniform-cost search is always optimal as it only selects a path with the lowest
path cost.
Advantages:
❖ It combines the benefits of BFS and DFS search algorithm in terms of
fast search and memory efficiency.
Disadvantages:
❖ The main drawback of IDDFS is that it repeats all the work of the
previous phase.
Example:
Following tree structure is showing the iterative deepening depth-first search.
IDDFS algorithm performs various iterations until it does not find the goal node. The
iteration performed by the algorithm is given as:
Page 23
Paavai Institutions Department of CSE
1st Iteration → A
2nd Iteration → A, B, C
3rd Iteration → A, B, D, E, C, F, G
4th Iteration → A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal node.
Completeness:
This algorithm is complete is if the branching factor is finite.
Time Complexity:
Let's suppose b is the branching factor and depth is d then the worst-case time
complexity is O(bd).
Space Complexity:
The space complexity of IDDFS will be O(bd).
Optimal:
IDDFS algorithm is optimal if path cost is a non- decreasing function of the depth
of the node.
Page 24
Paavai Institutions Department of CSE
Page 25
Paavai Institutions Department of CSE
Page 26
Paavai Institutions Department of CSE
involve simply available information that is not particular to the problem but is most
appropriate. They can include representative, affect, and availability heuristics.
Fig. 1.10.
Before describing certain heuristic techniques, let's see some of the techniques listed
below:
❖ Bidirectional Search
Page 27
Paavai Institutions Department of CSE
A* search
❖ Simulated Annealing
❖ Hill Climbing
❖ Best First search
❖ Beam search
First, let's talk about the Hill climbing in Artificial intelligence.
Page 28
Paavai Institutions Department of CSE
Best first search algorithm:
A* Search Algorithm
A* search is the most commonly known form of best-first search. It uses the
heuristic function h(n) and cost to reach the node n from the start state g(n). It has
combined features of UCS and greedy best-first search, by which it solve the
problem efficiently.
It finds the shortest path through the search space using the heuristic
function. This search algorithm expands fewer search tree and gives optimal
results faster.
Algorithm of A* search:
Step 1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not. If the list is empty, then return
failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of the
evaluation function (g + h). If node n is the goal node, then return
success and stop, otherwise.
Step 4: Expand node n and generate all of its successors, and put n into the
closed list. For each successor n ′, check whether n ′ is already in the
OPEN or CLOSED list. If not, then compute the evaluation function
for n ′ and place it into the Open list.
Some of the real-life examples of heuristics that people use as a way to solve a
problem:
❖ Common sense: It is a heuristic that is used to solve a problem based on
the observation of an individual.
❖ Rule of thumb: In heuristics, we also use a term rule of thumb. This
heuristic allows an individual to make an approximation without doing an
exhaustive search.
❖ Working backward: It lets an individual solve a problem by assuming
that the problem is already being solved by them and working backward in
their minds to see how much a solution has been reached.
❖ Availability heuristic: It allows a person to judge a situation based on the
examples of similar situations that come to mind.
❖ Familiarity heuristic: It allows a person to approach a problem on the
fact that an individual is familiar with the same situation, so one should
act similarly as he/she acted in the same situation before.
❖ Educated guess: It allows a person to reach a conclusion without doing
an exhaustive search. Using it, a person considers what they have
observed in the past and applies that history to the situation where there is not
any definite answer has decided yet.
Types of heuristics
There are various types of heuristics, including the availability heuristic, affect
heuristic and representative heuristic. Each heuristic type plays a role in decision-
making. Let's discuss about the Availability heuristic, affect heuristic, and
Representative heuristic.
Page 30
Paavai Institutions Department of CSE
Availability heuristic
Availability heuristic is said to be the judgment that people make regarding the
likelihood of an event based on information that quickly comes into mind. On
making decisions, people typically rely on the past knowledge or experience of an
event. It allows a person to judge a situation based on the examples of similar
situations that come to mind.
Representative heuristic
It occurs when we evaluate an event's probability on the basis of its similarity
with another event.
Example: We can understand the representative heuristic by the example of
product packaging, as consumers tend to associate the products quality with the
external packaging of a product. If a company packages its products that remind you
of a high quality and well-known product, then consumers will relate that product as
having the same quality as the branded product.
So, instead of evaluating the product based on its quality, customers correlate the
products quality based on the similarity in packaging.
Affect heuristic
It is based on the negative and positive feelings that are linked with a certain
stimulus. It includes quick feelings that are based on past beliefs. Its theory is one's
emotional response to a stimulus that can affect the decisions taken by an individual.
When people take a little time to evaluate a situation carefully, they might base
their decisions based on their emotional response.
Example: The affect heuristic can be understood by the example of
advertisements. Advertisements can influence the emotions of consumers, so it
affects the purchasing decision of a consumer. The most common examples of
advertisements are the ads of fast food. When fast-food companies run the
advertisement, they hope to obtain a positive emotional response that pushes you to
positively view their products.
If someone carefully analyzes the benefits and risks of consuming fast food, they
might decide that fast food is unhealthy. But people rarely take time to evaluate
everything they see and generally make decisions based on their automatic emotional
response. So, Fast food companies present advertisements that rely on such type of
Affect heuristic for generating a positive emotional response which results in sales.
Page 31
Paavai Institutions Department of CSE
Each point (state) in the landscape has an ―elevation, defined by the value of the
objective function. If elevation corresponds to an objective function, then the aim is
to find the highest peak - a global maximum - this is known as hill climbing. If
elevation corresponds to cost, then the aim is to find the lowest valley - a global
minimum - this is known as gradient descent.
Hill-climbing Search
The hill-climbing search algorithm, which is the most basic local search
technique. At each step the current node is replaced by the best neighbor. The hill-
climbing search algorithm keeps track of one current state and on each iteration
moves to the neighboring state with highest value - that is, it heads in the direction
Page 32
Paavai Institutions Department of CSE
that provides the steepest ascent. It terminates when it reaches a ―peakǁ
where no neighbor has a higher value. Hill climbing does not look ahead beyond the
immediate neighbors of the current state.
current ← problem.INITIAL
while true do
current ← neighbor
Hill climbing is sometimes called greedy local search because it grabs a good
neighbor state without thinking ahead about where to go next.
Unfortunately, hill climbing can get stuck for any of the following reasons:
Local Maxima: A local maximum is a peak that is higher than each of its
neighboring states but lower than the global maximum.
Ridges: A ridge is a special form of the local maximum. It has an area which is
higher than its surrounding areas, but itself has a slope, and cannot be reached in a
single move. Ridges result in a sequence of local maxima that is very difficult for
greedy algorithms to navigate.
Plateaus: A plateau is a flat area of the state-space landscape. It can be a flat local
maximum, from which no uphill exit exists, or a shoulder, from which progress is
possible.
Many variants of hill climbing have been invented. Stochastic hill climbing
chooses at random from among the uphill moves; the probability of selection can
vary with the steepness of the uphill move. This usually converges more slowly than
steepest ascent, but in some state landscapes, it finds better solutions.
First-choice hill climbing implements stochastic hill climbing by generating
successors randomly until one is generated that is better than the current state. This
is
Page 33
Paavai Institutions Department of CSE
a good strategy when a state has many (e.g., thousands) of successors.
Another variant is random-restart hill climbing, which adopts the quote ―If at
first you don‘t succeed, try, try again.ǁ It conducts a series of hill-climbing searches
from randomly generated initial states, until a goal is found. It is complete with
probability 1, because it will eventually generate a goal state as the initial state. If
each hill- climbing search has a probability of success, then the expected number of
restarts required is 1 / p. The expected number of steps is the cost of one successful
iteration plus (1 – p) / p times the cost of failure. For 8-queens, random-restart hill
climbing is very effective indeed. Even for three million queens, the approach can
find solutions in seconds
The success of hill climbing depends very much on the shape of the state-space
landscape: if there are few local maxima and plateaus, random-restart hill climbing
will find a good solution very quickly.
Example:
To illustrate hill climbing, Consider the 8-queens problem. The complete-state
formulation is used here, which means that every state has all the components of a
solution, but they might not all be in the right place. In this case every state has 8
queens on the board, one per column. The initial state is chosen at random, and the
successors of a state are all possible states generated by moving a single queen to
another square in the same column (so each state has 8 × 7 = 56 successors). The
heuristic cost function is the number of pairs of queens that are attacking each other;
this will be zero only for solutions. (It counts as an attack if two pieces are in the
same line, even if there is an intervening piece between them.)
Page 34
Paavai Institutions Department of CSE
Figure (a) : The 8-queens problem: place 8 queens on a chess board so that no queen
attacks another. (A queen attacks any piece in the same row, column, or diagonal.)
The figure (b) shows the h values of all its successors.
Solution:
Define the heuristic function
h(x) = +1 for all the blocks in the structure if the block is correctly positioned or
h(x) = – 1 for all uncorrectly placed blocks in the structure.
Page 35
Paavai Institutions Department of CSE
❖ The environment with more than one agent is termed as multi-agent
environment, in which each agent is an opponent of other agent and
playing against each other. Each agent needs to consider the action of
other agent and effect of that action on their performance.
❖ So, Searches in which two or more players with conflicting goals are
trying to explore the same search space for the solution, are called
adversarial searches, often known as Games.
❖ Games are modeled as a Search problem and heuristic evaluation function,
and these are the two main factors which help to model and solve games
in AI.
Types of Games in AI:
Page 36
Paavai Institutions Department of CSE
Zero-Sum Game
Page 37
Paavai Institutions Department of CSE
Game tree:
A game tree is a tree where nodes of the tree are the game states and Edges of the
tree are the moves by players. Game tree involves initial state, actions function, and
result Function.
Example: Tic-Tac-Toe game tree:
The following figure is showing part of the game-tree for tic-tac-toe game.
Following are some key points of the game:
❖ There are two players MAX and MIN.
❖ Players have an alternate turn and start with MAX.
❖ MAX maximizes the result of the game tree
❖ MIN minimizes the result.
Example Explanation:
❖ From the initial state, MAX has 9 possible moves as he starts first. MAX
place x and MIN place o, and both player plays alternatively until we
reach a leaf node where one player has three in a row or all squares are
filled.
❖ Both players will compute each node, minimax, the minimax value which
is the best achievable utility against an optimal adversary.
❖ Suppose both the players are well aware of the tic-tac-toe and playing the
best play. Each player is doing his best to prevent another one from
winning. MIN is acting against Max in the game.
❖ So in the game tree, we have a layer of Max, a layer of MIN, and each
layer is called as Ply. Max place x, then MIN puts o to prevent Max from
winning, and this game continues until the terminal node.
Page 38
Paavai Institutions Department of CSE
❖ In this either MIN wins, MAX wins, or it's a draw. This game-tree is the
whole search space of possibilities that MIN and MAX are playing tic-tac-
toe and taking turns alternately.
Hence adversarial Search for the minimax procedure works as follows:
❖ It aims to find the optimal strategy for MAX to win the game.
❖ It follows the approach of Depth-first search.
❖ In the game tree, optimal leaf node could appear at any depth of the tree.
❖ Propagate the minimax values up to the tree until the terminal
node discovered.
In a given game tree, the optimal strategy can be determined from the minimax
value of each node, which can be written as MINIMAX(n). MAX prefer to move to
a state of maximum value and MIN prefer to move to a state of minimum value then:
For a state S MINIMAX(s)
⎪
⎧UTILITY(s) If TERMINAL-TEST(s)
Page 39
Paavai Institutions Department of CSE
Xi
❖ For example, a Boolean variable would have the domain {true, false}.
Different variables can have different domains of different sizes. Each
constraint consists of a pair C j (scope,rel) , where scope is a tuple of variables
that participate in the constraint and rel is a relation that defines the values that
those variables can take on.
❖ For example, if X1 and X2 both have the domain, {1, 2, 3}then the constraint
Page 40
Paavai Institutions Department of CSE
The domain of every variable is the set Di = {red, green, blue} The constraints
require neighboring regions to have distinct colors.
C = {SA ≠ WA,SA ≠ NT,SA ≠ Q,SA ≠ NSW,SA ≠ V,WA ≠ NT,NT ≠ Q,Q ≠
NSW, NSW ≠ V }.
There are many possible solutions to this problem, such as
{WA = red,NT = green,Q = red,NSW = green,V = red,SA = blue,T = red }.
It can be helpful to visualize a CSP as a constraint graph. The nodes of the graph
correspond to variables of the problem, and an edge connects any two variables that
participate in a constraint.
Example problem: Job-shop scheduling
Factories have the problem of scheduling a day‘s worth of jobs, subject to various
constraints. In practice, many of these problems are solved with CSP techniques.
Consider the problem of scheduling the assembly of a car. The whole job is
composed of tasks. Constraints can assert that one task must occur before another -
for example, a wheel must be installed before the hubcap is put on. Constraints can
also specify that a task takes a certain amount of time to complete.
Consider a small part of the car assembly, consisting of 15 tasks: install axles
(front and back), affix all four wheels (right and left, front and back), tighten nuts for
each wheel, affix hubcaps, and inspect the final assembly. The tasks can be
represented with 15 variables:
X = {AxleF, AxleB, WheelRF ,WheelLF ,WheelRB, WheelLB,NutsRF NutsLF
,NutsRB,NutsLB,CapRF ,CapLF ,CapRB,CapLB,Inspect}.
Next precedence constraints are represented between individual tasks. Whenever
a task T1 must occur before task T2, and task takes duration d to complete, an
arithmetic constraint of the form can be added
T1 + d 1 ≤ T2
In this example, the axles have to be in place before the wheels are put on, and it
takes 10 minutes to install an axle, hence the constraints can be written as
AxleF + 10 ≤ WheelRF ; AxleF + 10 ≤ WheelLF ; AxleB + 10 ≤ WheelRB; AxleB + 10 ≤
WheelLB.
Page 41
Paavai Institutions Department of CSE
Constraints:
❖ Assign a decimal digit to each of the letters in such a way that the
answer is correct
❖ Assign decimal digit to letters
❖ Cannot assign different digits to same letters
❖ No two letters have the same digit
❖ Unique digit assigned to each letter
Rules:
❖ From Column 5, M = 1, since it is only carry-over possible from sum of
2 single digit number in column 4.
5 4 3 2 1
S E N D
+ 1 O R E
c3 c2 c1
1 O N E Y
Page 42
Paavai Institutions Department of CSE
9 5 6 7
Page 43
Paavai Institutions Department of CSE
+ 1 0 8 5
1 0 6 5 2
The key idea is local consistency. If each variable is treated as a node in a graph
and each binary constraint as an arc, then the process of enforcing local consistency
in each part of the graph causes inconsistent values to be eliminated throughout the
graph.
There are different types of local consistency, which are as follows.
Node consistency
A single variable (corresponding to a node in the CSP network) is node-consistent
if all the values in the variable‘s domain satisfy the variable‘s unary constraints. For
example, in the variant of the Australia map-coloring problem where South
Australians dislike green, the variable SA starts with domain {red , green, blue}, and
this can be made node consistent by eliminating green, leaving SA with the reduced
domain {red , blue}. Thus a network is node-consistent if every variable in the
network is node-consistent. It is always possible to eliminate all the unary constraints
in a CSP by running node consistency.
Page 44
Paavai Institutions Department of CSE
Arc consistency
Xi revised ← false
for each x in Di do
if no value y in Dj allows (x, y) to satisfy the constraint between Xi and
Xj then
Page 46
Paavai Institutions Department of AI&DS
Path Consistency
Path consistency tightens the binary constraints by using implicit constraints that
are inferred by looking at triples of variables.
A two-variable set {Xi , Xj } is path-consistent with respect to a third variable Xm
if, for every assignment {Xi = a, Xj = b} consistent with the constraints on {Xi , Xj },
there is an assignment to Xm that satisfies the constraints on {Xi , Xm} and {Xm, Xj }.
This is called path consistency because one can think of it as looking at a path from
Xi to Xj with Xm in the middle.
Let‘s consider the path consistency fares in coloring the Australia map with two
colors. Consider the set {WA, SA} which is path consistent with respect to NT. By
enumerating the consistent assignments to the set. there are only two assignments:
{WA = red , SA = blue}and {WA = blue, SA = red}.In both of these assignments
NT can be neither red nor blue (because it would conflict with either WA or SA).
Because there is no valid choice for NT, both assignments can be eliminated there is
no valid assignments for {WA, SA}. Therefore, there can be no solution to this
problem.
K -consistency
Stronger forms of propagation can be defined with the notion of k -consistency. A
CSP is k- consistent if, for any set of k-1 variables and for any consistent assignment
to those variables, a consistent value can always be assigned to any kth variable
A CSP is strongly k -consistent if it is k-consistent and is also (k – 1) -consistent,
(k – 2) - consistent, all the way down to 1-consistent.
Page 47
Paavai Institutions Department of AI&DS
Global constraints
A global constraint is one involving an arbitrary number of variables (but not
necessarily all variables). Global constraints occur frequently in real problems and
can be handled by special- purpose algorithms. For example, the All diff constraint
says that all the variables involved must have distinct values (as in the
cryptarithmetic problem and Sudoku puzzles).
One simple form of inconsistency detection for Alldiff constraints works as
follows: if m variables are involved in the constraint, and if they n have possible
distinct values altogether, and m>n , then the constraint cannot be satisfied.
This leads to the following simple algorithm:
❖ First, remove any variable in the constraint that has a singleton domain,
and delete that variable‘s value from the domains of the remaining
variables.
❖ Repeat as long as there are singleton variables.
❖ If at any point an empty domain is produced or there are more variables
than domain values left, then an inconsistency has been detected.
Sudoku
Page 48
Paavai Institutions Department of AI&DS
Fig. 1.11.
A Sudoku puzzle can be considered a CSP with 81 variables, one for each square.
The variable names A1 through A9 is used for the top row (left to right), down to I1
through I9 for the bottom row. The empty squares have the domain{1, 2, 3, 4, 5, 6,
7, 8, 9} and the pre-filled squares have a domain consisting of a single value. In
addition, there are 27 different Alldiff constraints, one for each unit (row, column,
and box of 9 squares):
Alldi
ff(A1,A2,A3,A4,A5,A6,A7,A8,A9)
Alldi
ff(B1,B2,B3,B4,B5,B6,B7,B8,B9)
Alldi
ff(A1,B1,C1,D1,E1,F1,G1,H1,I1)
Alldi
ff(A2,B2,C2,D2,E2,F2,G2,H2,I2)
Alldi
ff(A1,A2,A3,B1,B2,B3,C1,C2,C3)
Alldi
ff(A4,A5,A6,B4,B5,B6,C4,C5,C6)
Page 50
Paavai Institutions Department of AI&DS
assignment var←SELECT-UNASSIGNED-
VARIABLE(csp)
result ←BACKTRACK(assignment,
Fig. 1.12.
Page 51
Paavai Institutions Department of AI&DS
Page 52
Paavai Institutions Department of AI&DS
Page 53
Paavai Institutions Department of AI&DS
to detect diseases and cancer cells. It also helps in finding new drugs with
the use of historical data and medical intelligence.
Page 54
Paavai Institutions Department of AI&DS
e. Actions: It gives the description of all the available actions to the agent.
h. Solution: It is an action sequence which leads from the start node to the goal
node.
i. Optimal Solution: If a solution has the lowest cost among all solutions.
Page 55
Paavai Institutions Department of AI&DS
Page 56
Paavai Institutions Department of AI&DS
follows each path to its greatest depth node before moving to the next
path.
g. DFS uses a stack data structure for its implementation.
h. The process of the DFS algorithm is similar to the BFS algorithm.
Page 57
Paavai Institutions Department of AI&DS
Page 56
Paavai Institutions Department of AI&DS
PART B& C
******************
Page 57
Paavai Institutions Department of AI&DS
Page 58