0% found this document useful (0 votes)
4 views

UNIT-1

The document provides an overview of Artificial Intelligence (AI) and its applications, including healthcare, finance, transportation, retail, manufacturing, and entertainment. It discusses problem-solving agents, search algorithms, and techniques for effective problem-solving in AI, such as uninformed and informed search strategies, optimization techniques, and machine learning. Additionally, it highlights challenges in AI problem-solving, including complexity, data quality, interpretability, and ethical concerns.

Uploaded by

znovelgame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

UNIT-1

The document provides an overview of Artificial Intelligence (AI) and its applications, including healthcare, finance, transportation, retail, manufacturing, and entertainment. It discusses problem-solving agents, search algorithms, and techniques for effective problem-solving in AI, such as uninformed and informed search strategies, optimization techniques, and machine learning. Additionally, it highlights challenges in AI problem-solving, including complexity, data quality, interpretability, and ethical concerns.

Uploaded by

znovelgame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

DEPARTMENT OF CSE

CS3491 ARTIFICIAL INTELLIGENCE


AND MACHINE LEARNING

NOTES

Prepared By- Suresh C AP/CSE/ACT


UNIT I PROBLEM SOLVING
Introduction to AI - AI Applications - Problem solving agents – search algorithms
– uninformed search strategies – Heuristic search strategies – Local search and
optimization problems – adversarial search – constraint satisfaction problems
(CSP)

Introduction to AI

Artificial Intelligence (AI) refers to the simulation of human intelligence in


machines that are designed to think, learn, reason, and make decisions. These
machines use algorithms and data to mimic cognitive functions such as problem-
solving, understanding natural language, and recognizing patterns.

AI can be broadly categorized into:


1. Narrow AI(weak AI): Designed for specific tasks, such as virtual
assistants or image recognition systems.
2. General AI(Strong AI): A hypothetical form of AI capable of performing
any intellectual task a human can do.
3. Superintelligent AI: An advanced AI surpassing human intelligence,
which remains theoretical

APPLICATIONS OF AI
1. Healthcare
• Diagnostics: AI algorithms analyze medical images (e.g., X-rays, MRIs)
to identify diseases like cancer or fractures.
• Personalized Medicine: AI tailors treatments based on individual genetic
profiles.
• Robotic Surgery: Robots assist surgeons with precision.
• Drug Discovery: AI accelerates the identification of new drugs

Prepared By- Suresh C AP/CSE/ACT


2.Finance
• Fraud Detection: AI identifies unusual patterns in transactions to prevent
fraud.
• Algorithmic Trading: AI executes trades based on market data.
• Customer Service: Chatbots handle banking queries

Prepared By- Suresh C AP/CSE/ACT


3.Transportation
• Autonomous Vehicles: Self-driving cars like those developed by Tesla.
• Traffic Management: AI optimizes traffic flow and reduces congestion.
• Navigation Systems: Apps like Google Maps use AI to provide real-time
directions.

Prepared By- Suresh C AP/CSE/ACT


4.Retail and E-commerce
• Recommendation Systems: Platforms like Amazon suggest products
based on user preferences.
• Inventory Management: AI forecasts demand and prevents stockouts.
• Chatbots: Customer service bots assist shoppers.

Prepared By- Suresh C AP/CSE/ACT


5.Manufacturing
• Predictive Maintenance: AI predicts machinery failures to minimize
downtime.
• Quality Control: AI inspects products for defects.
• Automation: Robots powered by AI handle assembly line

Prepared By- Suresh C AP/CSE/ACT


6.Entertainment
• Content Recommendations: Netflix, Spotify, and YouTube suggest
personalized content.
• Game Development: AI creates adaptive and realistic in-game
environments

Prepared By- Suresh C AP/CSE/ACT


Problem solving agents

• A problem-solving agent in AI is a type of intelligent system designed to


find solutions to specific problems. These agents analyze a problem,
figure out possible solutions, and choose the best one based on the rules
and goals set for them.
STEPS FOLLOWED BY PROBLEM SOLVING AGENTS
• Define the Problem
The agent identifies the problem, the initial state, the goal state, and the
rules to move between states.
• Formulate the Search Space
The agent explores all possible actions and states to reach the goal.

Prepared By- Suresh C AP/CSE/ACT


• Search for Solutions
It applies a specific search strategy (e.g., breadth-first, depth-first) to find
the best path or action sequence.
• Execute the Solution
The agent applies the selected solution to solve the problem.

Components of Problem Formulation in AI


Effective problem-solving in AI is dependent on several critical components:
• Initial State: This represents the starting point for the AI agent,
establishing the context in which the problem is addressed. The initial
state may also involve initializing methods for problem-solving.

Prepared By- Suresh C AP/CSE/ACT


• Action: This stage involves selecting functions associated with the initial
state and identifying all possible actions. Each action influences the
progression toward the desired goal.
• Transition: This component integrates the actions from the previous
stage, leading to the next state in the problem-solving process. Transition
modeling helps visualize how actions affect outcomes.
• Goal Test: This stage verifies whether the specified goal has been
achieved through the integrated transition model. If the goal is met, the
action ceases, and the focus shifts to evaluating the cost of achieving that
goal.
• Path Costing: This component assigns a numerical value representing
the cost of achieving the goal. It considers all associated hardware,
software, and human resource expenses, helping to optimize the problem-
solving strategy.
Techniques for Problem Solving in AI
Several techniques are prevalent in AI for effective problem-solving:
1. Search Algorithms
Search algorithms are foundational in AI, used to explore possible solutions in a
structured manner. Common types include:
• Uninformed Search: Such as breadth-first and depth-first search, which
do not use problem-specific information.
• Informed Search: Algorithms like A* that use heuristics to find solutions
more efficiently.
2. Constraint Satisfaction Problems (CSP)
CSPs involve finding solutions that satisfy specific constraints. AI uses
techniques like backtracking, constraint propagation, and local search to solve
these problems effectively.

Prepared By- Suresh C AP/CSE/ACT


3. Optimization Techniques
AI often tackles optimization problems, where the goal is to find the best
solution from a set of feasible solutions. Techniques such as linear
programming, dynamic programming, and evolutionary algorithms are
commonly employed.
4. Machine Learning
Machine learning techniques allow AI systems to learn from data and improve
their problem-solving abilities over time. Supervised, unsupervised, and
reinforcement learning paradigms offer various approaches to adapt and
enhance performance.
5. Natural Language Processing (NLP)
NLP enables AI to understand and process human language, making it
invaluable for solving problems related to text analysis, sentiment analysis, and
language translation. Techniques like tokenization, sentiment analysis, and
named entity recognition play crucial roles in this domain.
Challenges in Problem Solving with AI
Despite its advancements, AI problem-solving faces several challenges:
• Complexity: Some problems are inherently complex and require
significant computational resources and time to solve.
• Data Quality: AI systems are only as good as the data they are trained
on. Poor quality data can lead to inaccurate solutions.
• Interpretability: Many AI models, especially deep learning, act as black
boxes, making it challenging to understand their decision-making
processes.
• Ethics and Bias: AI systems can inadvertently reinforce biases present in
the training data, leading to unfair or unethical outcomes.

Prepared By- Suresh C AP/CSE/ACT


Search algorithms

Search algorithms are foundational in AI, used to explore possible solutions in a


structured manner. Common types include:
• Uninformed Search: Uninformed search algorithms are a class of search
algorithms that do not have any additional information about the problem
other than what is given in the problem definition. They are also known
as blind search algorithms.
Breadth-first Search:
• Breadth-first search is the most common search strategy for traversing a
tree or graph. This algorithm searches breadthwise in a tree or graph, so it
is called breadth-first search.
• BFS algorithm starts searching from the root node of the tree and expands
all successor node at the current level before moving to nodes of next
level.
• The breadth-first search algorithm is an example of a general-graph
search algorithm.
• Breadth-first search implemented using FIFO queue data structure.
Algorithm:
BFS(graph, start):
Create an empty set 'visited'
Create a queue and enqueue 'start' node

While queue is not empty:


node ← Dequeue the front element of the queue
If node is not in 'visited':
Print node

Prepared By- Suresh C AP/CSE/ACT


Add node to 'visited'
Enqueue all unvisited neighbors of node

End BFS

Advantages:
• BFS will provide a solution if any solution exists.
• If there are more than one solutions for a given problem, then BFS will
provide the minimal solution which requires the least number of steps.
• It also helps in finding the shortest path in goal state, since it needs all
nodes at the same hierarchical level before making a move to nodes at
lower levels.
• It is also very easy to comprehend with the help of this we can assign the
higher rank among path types.
Example:

Prepared By- Suresh C AP/CSE/ACT


Depth-first Search
• Depth-first search is a recursive algorithm for traversing a tree or graph
data structure.
• It is called the depth-first search because it starts from the root node and
follows each path to its greatest depth node before moving to the next
path.
• DFS uses a stack data structure for its implementation.
• The process of the DFS algorithm is similar to the BFS algorithm.

Prepared By- Suresh C AP/CSE/ACT


Algorithm:
DFS(graph, start, visited):
If 'visited' is not initialized:
Initialize 'visited' as an empty set

If 'start' is not in 'visited':


Print start
Add start to 'visited'

For each neighbor in graph[start]:


DFS(graph, neighbor, visited)

End DFS
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).
• With the help of this we can stores the route which is being tracked in
memory to save time as it only needs to keep one at a particular time.

Prepared By- Suresh C AP/CSE/ACT


Example:

3.Depth-Limited Search (DLS)


• DLS is a variant of DFS where the search is limited to a specified depth.
If the solution is not found within the depth limit, the algorithm stops and
backtracks.
• Avoids going too deep in infinite search spaces.
• Requires a depth limit to be set in advance.
Algorithm:
DLS(graph, node, goal, depth_limit):
If node is the goal:
Return "Goal Found"

Prepared By- Suresh C AP/CSE/ACT


If depth_limit ≤ 0:
Return "Cutoff"

Mark node as visited

For each neighbor in graph[node]:


result ← DLS(graph, neighbor, goal, depth_limit - 1)
If result is "Goal Found":
Return result

Return "Failure"

End DLS

Prepared By- Suresh C AP/CSE/ACT


Example:

4.Uniform-cost Search Algorithm


• Uniform Cost Search is a pathfinding algorithm that expands the least
cost node first, ensuring that the path to the goal node has the minimum
cost.
• Unlike other search algorithms like Breadth-First Search (BFS), UCS
takes into account the cost of each path, making it suitable for weighted
graphs where each edge has a different cost.

Prepared By- Suresh C AP/CSE/ACT


Algorithm:

UCS(graph, start, goal):


Create a priority queue (min-heap) 'pq' and enqueue (start, cost=0)
Create an empty dictionary 'visited' to store the lowest cost to each node

While 'pq' is not empty:


(current_node, cost) ← Dequeue the node with the lowest cost

If current_node is the goal:


Return "Goal Found with cost = " + cost

If current_node is not in 'visited' OR cost is less than visited[current_node]:


visited[current_node] ← cost

For each (neighbor, edge_cost) in graph[current_node]:


new_cost ← cost + edge_cost
Enqueue (neighbor, new_cost) into 'pq'

Return "Failure" (if goal is not reached)

End UCS

Prepared By- Suresh C AP/CSE/ACT


Example:

5. Iterative deepening depth-first Search


• A search algorithm known as IDS combines the benefits of DFS with
Breadth First Search (BFS).
• The graph is explored using DFS, but the depth limit steadily increased
until the target is located.
• In other words, IDS continually runs DFS, raising the depth limit each
time, until the desired result is obtained

Prepared By- Suresh C AP/CSE/ACT


Example:

Informed search or Heuristic search strategies


Uninformed search algorithms are a class of search algorithms that have any
additional information about the problem other than what is given in the
problem definition. It is also known as Heuristic search.
• A heuristic is a technique that is used to solve a problem faster than the
classic methods. These techniques are used to find the approximate
solution of a problem when classical methods do not. Heuristics are said
to be the problem-solving techniques that result in practical and quick
solutions.
• Heuristics are strategies that are derived from past experience with
similar problems. Heuristics use practical methods and shortcuts used to
produce the solutions that may or may not be optimal, but those solutions
are sufficient in a given limited timeframe.

Prepared By- Suresh C AP/CSE/ACT


Greedy Best First Search
Greedy Best-First Search is an AI search algorithm that attempts to find the
most promising path from a given starting point to a goal. It prioritizes paths
that appear to be the most promising, regardless of whether or not they are
actually the shortest path. The algorithm works by evaluating the cost of each
possible path and then expanding the path with the lowest cost. This process is
repeated until the goal is reached.
Steps:
Initialization:
o Begin with the first node that you have chosen, which is also the only
node we have.
o Please enter the first node into the priority queue by the amount of its
estimated heuristic function h(n).
Expand the most promising node:
o The marked node with the lowest value - this node must be removed
o The next available processor takes an h(n) from the priority queue.
o If this node is the goal, then print the path at this node, and the search is
done.
Generate successors:
o Produce all possible successors (the cellular neighbours) of the current
node.
Evaluate and add successors:
o Determine a heuristic value h for each of the successors.
o The successors are added to the priority queue according to their h values.

Prepared By- Suresh C AP/CSE/ACT


Repeat:
o Perform steps 2 to 4 as many times as could be possible until either a goal
node is discovered or until the priority queue is exhausted and no nodes
can be retrieved from it.
Example1:

Prepared By- Suresh C AP/CSE/ACT


Example2:

Prepared By- Suresh C AP/CSE/ACT


A* Algorithm:
Depending on the required path and situation, A* Search is slightly better than
the Greedy Best First Search. It uses two functions: A*-algorithm to use g(n) as
the actual cost from the start node to the current node n, and h(n) as the
estimated cost from n to the goal. Thus, the total cost function f(n)=g(n)+h(n) is
used to select which node to expand next, simultaneously providing optimal and
efficient search.
Steps:
Initialization:
o The strategy being employed here is to begin with the first node.
o The first node, the source node, has its g value initially set to 0, meaning
that 0 costs were incurred to get to it.
o At the required end node, find f=g+h and add the initial node to the
priority queue.
Expand the lowest-cost node:
o Select the node with the least cost in the number of steps f(n) and delete it
from the priority queue.
o If this node is the goal, initiate to construct and return the path to this
node and then break the loop.
Generate successors:
o Produce all possible successors of the given node.
Evaluate costs for successors (For each successor):
o Get the tentative g value as g(current) + cost(current, successor).
o This last part is done by mathematically summarizing the values
of g and h of the successor node as f = g(successor) + h(successor).
o If the successor is not in the priority queue and the new g value is less
than the recorded g value, then extend the priority queue with the
new f value and record this path.

Prepared By- Suresh C AP/CSE/ACT


Repeat:
o If the priority queue is not empty, go back to steps 2 to 4 to identify the
goal node.

Example1:

Prepared By- Suresh C AP/CSE/ACT


Example2:

The numbers written on edges represent the distance between the nodes.
The numbers written on nodes represent the heuristic value.
Find the most cost-effective path to reach from start state A to final state J using
A* Algorithm.

Solution-

Step-01:
• We start with node A.
• Node B and Node F can be reached from node A.

A* Algorithm calculates f(B) and f(F).


• f(B) = 6 + 8 = 14
• f(F) = 3 + 6 = 9
Since f(F) < f(B), so it decides to go to node F.

Prepared By- Suresh C AP/CSE/ACT


Path- A → F
Step-02:
Node G and Node H can be reached from node F.

A* Algorithm calculates f(G) and f(H).


• f(G) = (3+1) + 5 = 9
• f(H) = (3+7) + 3 = 13

Since f(G) < f(H), so it decides to go to node G.

Path- A → F → G

Step-03:
Node I can be reached from node G.
A* Algorithm calculates f(I).
f(I) = (3+1+3) + 1 = 8
It decides to go to node I.

Path- A → F → G → I

Step-04:
Node E, Node H and Node J can be reached from node I.
A* Algorithm calculates f(E), f(H) and f(J).
• f(E) = (3+1+3+5) + 3 = 15

Prepared By- Suresh C AP/CSE/ACT


• f(H) = (3+1+3+2) + 3 = 12
• f(J) = (3+1+3+3) + 0 = 10
Since f(J) is least, so it decides to go to node J.
Path- A → F → G → I → J
This is the required shortest path from node A to node J.

Algorithm:

Local search and optimization problems


Local search is a family of optimization algorithms used to find a good solution
to a problem by iteratively making small changes to a current solution. Unlike
global search algorithms that explore the entire search space, local search
focuses on improving a solution within a limited neighborhood. It’s particularly

Prepared By- Suresh C AP/CSE/ACT


useful for large, complex problems where finding the absolute best solution
(global optimum) is impractical.
Key Characteristics:
1. Neighborhood: The set of solutions close to the current solution.
2. Iterative Improvement: Moves to a better solution in the neighborhood at
each step.
3. Local Optimum: Stops when no better solution is found in the
neighborhood.
Real-Time Example: The Traveling Salesman Problem (TSP)
Suppose a delivery person needs to visit 10 cities and return to the starting
point, aiming to find the shortest possible route.
1. Initial Solution: Start with a random route, say: A → B → C → D → E → F
→ G → H → I → J → A.
2. Neighborhood: Define the neighborhood as swapping two cities in the route.
For example, swap cities C and D to get: A → B → D → C → E → F → G →
H → I → J → A.
3. Evaluate: Calculate the total distance of the new route. If it’s shorter, keep
this route; otherwise, discard it.
4. Repeat: Continue swapping pairs of cities until no further improvements can
be made.
The final route might not be the absolute shortest (global optimum), but it will
be a reasonably good solution (local optimum).
Advantages of Local Search:
• Efficient for large problems where exhaustive search is impossible.
• Simple to implement and requires less memory.
Disadvantages:
• Can get stuck in a local optimum (a good but not the best solution).
• The quality of the solution depends on the initial starting point.

Prepared By- Suresh C AP/CSE/ACT


Hill Climbing Algorithm:
Hill Climbing is a local search optimization algorithm used to find the best
possible solution to a problem by iteratively making small improvements. It’s like
climbing a hill: you take small steps upward until you reach the highest point
(optimal solution) in your immediate area. However, it can get stuck at a local
maximum (a point that’s higher than its neighbors but not the highest overall)
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.

Key Characteristics:
1. Greedy Approach: Always chooses the immediate best option.
2. Local Optimum: Can get stuck at a point that’s better than its neighbors
but not the best overall.
3. No Backtracking: Once a move is made, it doesn’t revisit previous states.

Prepared By- Suresh C AP/CSE/ACT


Steps of Hill Climbing:
1. Start with an initial solution.
2. Evaluate the solution (e.g., calculate its score or fitness).
3. Generate neighboring solutions by making small changes.
4. Move to the best neighboring solution (the one with the highest score).
5. Repeat until no better solution is found in the neighborhood
Advantages of Hill Climbing:
Simple and easy to implement.
Requires less memory and computational resources.
Works well for problems with a large search spaces.
Disadvantages of Hill Climbing:
Local Optima: Can get stuck at a solution that’s not the best overall.
Plateaus: May get stuck if all neighboring solutions have the same score.
Ridges: May struggle to navigate if the best solutions are along a narrow
path.
Variants of Hill Climbing:
1. Steepest-Ascent Hill Climbing: Evaluates all neighbors and chooses the
best one.
2. Stochastic Hill Climbing: Randomly selects a neighbor with a better
score.
3. Random-Restart Hill Climbing: Restarts the algorithm multiple times
from different initial states to avoid local optima.

Prepared By- Suresh C AP/CSE/ACT


Steps to Solve the 8 Queens Problem Using Hill Climbing:
The 8 Queens Problem is a classic puzzle where the goal is to place 8 queens on
a chessboard such that no two queens threaten each other. This means no two
queens can share the same row, column, or diagonal. The Hill Climbing algorithm
can be used to solve this problem by iteratively improving the placement of
queens.
1. Representation:
Represent the chessboard as an array of size 8, where each index represents a
column, and the value at that index represents the row where the queen is
placed.
Example: [3, 7, 2, 8, 5, 1, 4, 6] means:
Queen in column 1 is at row 3.
Queen in column 2 is at row 7.
Queen in column 3 is at row 2.
And so on.
2. Objective:
Minimize the number of conflicts (pairs of queens threatening each other).
3. Initial State:
Start with a random arrangement of 8 queens (one in each column).
4. Evaluation Function:
Calculate the number of conflicts (pairs of queens threatening each other).
The goal is to reduce this number to 0.
5. Neighborhood Generation:
Generate neighboring states by moving one queen to a different row in its
column.
For example, if the current state is [3, 7, 2, 8, 5, 1, 4, 6], a neighbor could be
[3, 7, 2, 8, 5, 1, 4, 7] (moving the queen in column 8 from row 6 to row 7).

Prepared By- Suresh C AP/CSE/ACT


6. Hill Climbing Process:
Evaluate the current state (count conflicts).
Generate all possible neighbors.
Move to the neighbor with the fewest conflicts.
Repeat until no better neighbor is found (local optimum).
Example:
Initial State:
Random arrangement: [3, 7, 2, 8, 5, 1, 4, 6]
Conflicts: 5 (calculated by counting pairs of queens threatening each other).

Generate Neighbors:
Move the queen in column 1 to rows 1, 2, 4, 5, 6, 7, 8.
Move the queen in column 2 to rows 1, 2, 3, 4, 5, 6, 8.
Repeat for all columns.
Evaluate Neighbors:
Suppose moving the queen in column 1 to row 2 results in [2, 7, 2, 8, 5, 1, 4, 6]
with 3 conflicts.
This is better than the current state (5 conflicts), so move to this state.
Repeat:
Continue generating and evaluating neighbors until no better state is found.

Prepared By- Suresh C AP/CSE/ACT


Challenges:
1. Local Optima:
Hill Climbing can get stuck in a state where no better neighbor exists, but
conflicts are still present.
Example: A state with 1 conflict where no single move can reduce the
conflicts to 0.
2. Plateaus:
If all neighbors have the same number of conflicts, the algorithm cannot make
progress.
Adversarial Search
Adversarial search is a type of search algorithm used in competitive environments
where two or more agents (players) have opposing goals. It is commonly used in
game-playing scenarios, such as chess, tic-tac-toe, or poker, where one player's
gain is another player's loss. The goal is to make optimal decisions by anticipating
the opponent's moves and planning accordingly.
Key Components:
1. Players: Two or more agents with opposing goals (e.g., one tries to maximize
the score, the other tries to minimize it).
2. Game Tree: A tree-like structure that represents all possible moves and
counter-moves.

Prepared By- Suresh C AP/CSE/ACT


3. Strategy: Choosing the best move by evaluating the possible outcomes of
each action
Real-Time Example: Tic-Tac-Toe
Let’s say you’re playing tic-tac-toe as X, and your opponent is O. The game
board is empty at the start.
1. Your Move: You place an X in the center. This is the best starting move
because it gives you the most opportunities to win.
2. Opponent’s Move: Your opponent places an O in a corner.
3. Your Next Move: You think ahead: "If I place an X in another corner, my
opponent might block me, but if I place it here, I can create two winning
opportunities."
4. Outcome: You choose the move that maximizes your chances of winning
while minimizing your opponent’s chances.
This back-and-forth process of evaluating moves and counter-moves is
adversarial search.

Prepared By- Suresh C AP/CSE/ACT


Algorithms Used in Adversarial Search:
1. Minimax Algorithm:
- Assumes both players play optimally.
- Maximizes your score while minimizing the opponent’s score.
- Explores the game tree to evaluate all possible moves and counter-moves.
2. Alpha-Beta Pruning:
- An optimization of the minimax algorithm.
- Reduces the number of nodes evaluated by "pruning" branches that don’t
need to be explored.
Real-Time Example: Chess
In chess, adversarial search is used to evaluate millions of possible moves and
counter-moves. For example:
1. Your Move: You consider moving your knight to attack the opponent’s queen.
2. Opponent’s Response: You anticipate that the opponent might move their
queen to safety or counterattack.
3. Your Strategy: You choose the move that puts you in the best position,
considering all possible responses.

Prepared By- Suresh C AP/CSE/ACT


Constraint satisfaction problems (CSP)
Constraint Satisfaction Problem (CSP) is a type of problem in Artificial
Intelligence (AI) where the solution must meet a number of constraints.
The goal is to find a solution that satisfies a set of constraints.
Example: Map Coloring Problem
• Variables (X): Regions on a map (eg. X1,X2,x3)
• Domains (D): Each region can be colored Red, Green, or Blue.
• Constraints (C): No two adjacent regions can have the same color.
Backtracking Algorithm (Basic CSP Solver)
• Assign a value to a variable.
• Check if it satisfies constraints.
• If not, backtrack and try a different value.
• Continue until all variables are assigned.
Example: Solving Sudoku with backtracking.
Constraint Propagation
• Uses forward checking to eliminate invalid choices early.
• Arc Consistency (AC-3 Algorithm) ensures that every variable has at
least one possible valid value.
Heuristics to Improve Efficiency
• Minimum Remaining Values (MRV): Choose the variable with the
fewest possible values first.
• Degree Heuristic: Choose the variable involved in the most constraints
first.
• Least Constraining Value (LCV): Assign the value that rules out the
fewest future options.

Prepared By- Suresh C AP/CSE/ACT


Applications of CSP
1. Sudoku Solver
2. Timetable Scheduling
3. Cryptarithmetic Problems (e.g., SEND + MORE = MONEY)
4. Map Coloring
5. Job Scheduling
6. Robot Path Planning
Cryptarithmetic Problem
A Crypt-arithmetic puzzle, also known as a cryptogram, is a type of
mathematical puzzle in which we assign digits to alphabetical letters or
symbols. The end goal is to find the unique digit assignment to each letter so
that the given mathematical operation holds true.
The rules for a Crypt-arithmetic puzzle
• We can use digits from 0 to 9 only to represent a unique alphabetical
letter in the puzzle.
• The same digit cannot be assigned to different letters in the whole
equation.
• The resulting equation formed by replacing letters with digits should be
mathematically correct.
Example1:
Solve the following Crypt arithmetic problem using constraints satisfaction
search procedure.
CROSS
+ROADS
------------
DANGER
----------------

Prepared By- Suresh C AP/CSE/ACT


Steps to Solve Using Constraint Satisfaction Search Procedure

1. Define Variables

The variables are the unique letters:


C, R, O, S, A, D, N, G, E

2. Define the Domain

Each letter has a domain of digits {0,1,2,...,9}

3. Apply Constraints

Uniqueness: No two letters can represent the same digit.

Prepared By- Suresh C AP/CSE/ACT


Solution:

Prepared By- Suresh C AP/CSE/ACT


Example2:

Prepared By- Suresh C AP/CSE/ACT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy