0% found this document useful (0 votes)
25 views103 pages

Ai Tu Cse 3

The document discusses control strategies in Artificial Intelligence, focusing on problem-solving through search methods in a search space. It highlights the importance of search algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS), detailing their structures, algorithms, benefits, and drawbacks, along with various applications in fields such as web crawling, social networks, and game development. The document emphasizes the need to choose appropriate search strategies based on factors like completeness, optimality, time complexity, and space complexity.

Uploaded by

siddiqtahaseem
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)
25 views103 pages

Ai Tu Cse 3

The document discusses control strategies in Artificial Intelligence, focusing on problem-solving through search methods in a search space. It highlights the importance of search algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS), detailing their structures, algorithms, benefits, and drawbacks, along with various applications in fields such as web crawling, social networks, and game development. The document emphasizes the need to choose appropriate search strategies based on factors like completeness, optimality, time complexity, and space complexity.

Uploaded by

siddiqtahaseem
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/ 103

Control Strategies

ARTIFICIAL INTELLIGENCE

By
Dr B Nandini,
Associate Professor, Dept of CSE,
Telangana University
• Problem solving is an important aspect of Artificial Intelligence.
• A problem can be considered to consist of a goal and a set of
actions that can be taken to lead to the goal.
• At any given time, we consider the state of the search space to
represent where we have reached as a result of the actions we
have applied so far.
• Search is a method that can be used by computers to examine a
problem space in order to find a goal.
• Often, we want to find the goal as quickly as possible or without
using too many resources.
• A problem space can be considered to be a search space
because in order to solve the problem, we will search the space
for a goal state.
• We will continue to use the term search space to describe this
concept. In this chapter, we will look at a number of methods for
examining a search space. These methods are called search
methods.
• The Importance of Search in AI
– It has already become clear that many of the tasks underlying AI can be
phrased in terms of a search for the solution to the problem at hand.
– Many goal based agents are essentially problem solving agents which must
decide what to do by searching for a sequence of actions that lead to their
solutions.
– For production systems, we have seen the need to search for a sequence of
rule applications that lead to the required fact or action.
– For neural network systems, we need to search for the set of connection
weights that will result in the required input to output mapping.
• Which search algorithm one should use will generally depend on the
problem domain? There are four important factors to consider:
– Completeness – Is a solution guaranteed to be found if at least one solution
exists?
– Optimality – Is the solution found guaranteed to be the best (or lowest cost)
solution if there exists more than one solution?
– Time Complexity – The upper bound on the time required to find a solution, as
a function of the complexity of the problem.
– Space Complexity – The upper bound on the storage space (memory) required
at any point during the search, as a function of the complexity of the problem.
• Routes through State Space:
• Our general aim is to search for a route, or sequence of transitions,
through the state space graph from our initial state to a goal state.
• Sometimes there will be more than one possible goal state. We
define a goal test to determine if a goal state has been achieved.
• The solution can be represented as a sequence of link labels (or
transitions) on the state space graph. Note that the labels depend
on the direction moved along the link.
• Sometimes there may be more than one path to a goal state, and
we may want to find the optimal (best possible) path. We can
define link costs and path costs for measuring the cost of going
along a particular path, e.g. the path cost may just equal the
number of links, or could be the sum of individual link costs.
• For most realistic problems, the state space graph will be too large
for us to hold all of it explicitly in memory at any one time.
Search Trees:
• It is helpful to think of the search process as
building up a search tree of routes through the
state space graph. The root of the search tree is
the search node corresponding to the initial state.
• The leaf nodes correspond either to states that
have not yet been expanded, or to states that
generated no further nodes when expanded.
• At each step, the search algorithm chooses a new
unexpanded leaf node to expand. The different
search strategies essentially correspond to the
different algorithms one can use to select which
is the next node to be expanded at each stage.
Breadth-First Search
(BFS):
• This method explores all the neighboring
nodes at a given level systematically
before moving on to the next level. It's
like checking every door on one floor of a
building before moving up to the next
floor. BFS is guaranteed to find a solution
if one exists, but it can be slow for
expansive search spaces.
Data Structures:
• Queue (Q): Used to store the nodes to be explored. It follows a First-In-First-Out (FIFO) principle.
• Visited: This can be an array or hash table to keep track of visited nodes and avoid revisiting them.
Algorithm:
• Initialization:
– Enqueue the starting node in the queue (Q).
– Mark the starting node as visited.

• Exploration Loop:
– While the queue is not empty:
• Dequeue a node (v) from the queue.
• Process the node (v) (e.g., print its value).
• For each unvisited neighbor (w) of node (v):

– Enqueue the neighbor (w) into the queue (Q).


– Mark the neighbor (w) as visited.

Explanation:
• We start by adding the starting node to the queue and marking it visited.
• The exploration loop continues as long as there are nodes to explore (queue is not empty).
• In each iteration, we remove the first node (v) from the queue and process it (e.g., print its value).
• We then check all the neighbors of the dequeued node (v). If a neighbor (w) is unvisited, we add it to the queue
and mark it visited.
• This process repeats until all reachable nodes from the starting node are explored.
Benefits of BFS:
• Guaranteed to find a path to the goal node (if it exists) because it explores all neighboring nodes systematically.
• Useful for finding the shortest path in unweighted graphs.
Drawbacks of BFS:
• Can be slow for expansive search spaces due to exploring all nodes level by level.
• Might not be optimal for finding the shortest path in weighted graphs
• Let's consider a scenario where
you're searching for your friend Alice
in a social network. You can model
the social network as a graph, where
people are nodes and friendships are
edges. BFS can help you find Alice
efficiently.
Here's how BFS would work to find Alice, starting your search from John:
• Initialization: Add John (the starting node) to the queue and mark him as visited.
• Exploration Loop:
– Iteration 1:
• Dequeue John from the queue (since he's the only one there).
• Process John (e.g., you already know John and he isn't Alice).
• Check John's neighbors: Sarah and David.
• Add Sarah and David to the queue (since they haven't been visited).
• Mark Sarah and David as visited.
– Iteration 2:
• Dequeue Sarah from the queue.
• Process Sarah (still not Alice).
• Check Sarah's neighbors: Emily and Mike.
• Add Emily and Mike to the queue (unvisited).
• Mark Emily and Mike as visited.
– Iteration 3:
• Dequeue David from the queue.
• Process David (still not Alice).
• Check David's neighbor: Charles.
• Add Charles to the queue (unvisited).
• Mark Charles as visited.
– Iteration 4:
• Dequeue Emily from the queue.
• Process Emily (still not Alice).
• Emily has no unvisited neighbors (both Sarah and Mike have been visited).
– Iteration 5: (Similar to iteration 4 for Mike)
– Iteration 6:
• Dequeue Charles from the queue.
• Process Charles (still not Alice).
• Check Charles' neighbors: Alice and Bob.
• Add Alice to the queue (unvisited - bingo!).
• Mark Alice as visited.
• Bob is not added since we're looking for Alice.
End of Exploration: We've found Alice! BFS systematically explored all John's friends (level 1), then friends of
friends (level 2), until it reached Alice on level 2. This demonstrates how BFS searches outward level by level.
Applications:
Breadth-First Search (BFS) has a variety of applications across computer science and beyond, due to its efficient
exploration of neighboring nodes. Here are some examples:
Web Crawling:
• Search engines like Google use BFS to crawl the web. Starting from a seed webpage, BFS follows all the links on that
page, then all the links on those linked pages, and so on. This systematic exploration helps search engines discover
new webpages and build their index.
Social Networks:
• Social media platforms can leverage BFS to find people within a certain distance (e.g., friends of friends) of a
particular user. By starting from the user and exploring their connections level by level, BFS can efficiently identify
people within the specified social network radius.
Routing and Navigation:
• BFS can be used in GPS navigation systems to find the shortest path between two locations on a map (if the map is
unweighted). It explores neighboring roads systematically, ensuring it finds the quickest route with the same
number of turns for each road.
Circuit Design:
• In circuit board design, BFS can be employed to check for electrical connectivity between components. Starting from
a specific point, BFS traverses the conductive paths to verify if there's a complete circuit connection.
Image Processing:
• BFS plays a role in image processing tasks like flood fill. Given a starting point and a new color, BFS can efficiently
fill a connected region in an image with the new color, ensuring it only changes pixels that are adjacent to the
starting point and have the original color.
Game Development:
• BFS can be used in pathfinding algorithms for game characters. By exploring neighboring tiles or spaces level by
level, BFS helps characters find the shortest path to reach a goal location within the game world.
Computer Networks:
• Peer-to-peer file-sharing networks like BitTorrent utilize BFS to discover neighboring devices on the network. Starting
from a seed node, BFS searches for peers who have the desired file, enabling efficient file sharing and distribution.
• These are just a few examples, and the applications of BFS continue to grow in various fields that involve exploring
interconnected structures and finding optimal solutions.
• Social Network Analysis: BFS goes beyond just finding friends of friends. It can be used to analyze
the spread of information or influence within a social network. By starting from a source node (e.g.,
someone who starts a rumor), BFS can efficiently track how the information propagates to other
users based on their connections, revealing patterns of influence and information dissemination.
• Load Balancing: In distributed computing systems, BFS can be used for load balancing. It helps
distribute tasks or workloads evenly across multiple servers or resources. By starting from a central
task queue and assigning tasks to available servers level by level (using BFS approach), the system
ensures no server gets overloaded while others remain idle.
• Minimum Spanning Tree Algorithms: Algorithms like Prim's Minimum Spanning Tree (MST) utilize
BFS principles. They find the minimum cost network connecting all nodes in a graph. BFS helps
explore neighboring nodes systematically, ensuring the chosen edges contribute to the minimum
overall cost for the spanning tree.
• Broadcast in Wireless Networks: In wireless networks, BFS can be used for efficient message
broadcasting. A node receiving a message can forward it to all its neighbors within its transmission
range. By using BFS, the message propagates outwards level by level, ensuring all reachable nodes
receive the broadcast efficiently.
• Video Game Level Design: Game developers can leverage BFS to create open-world game levels.
BFS helps procedurally generate accessible and interesting level layouts. It starts from a central point
and progressively expands outwards, placing obstacles, rooms, and points of interest while ensuring
all areas are reachable from the starting point.
• Image and Video Compression: Some image and video compression techniques employ BFS. By
analyzing pixel color or feature similarities, BFS can identify redundant regions within an image or
video. These redundant areas can then be compressed efficiently, reducing file size without
significant quality loss.
• Spam Filtering: Email spam filters can utilize BFS to analyze the origin and sender reputation of
emails. Starting from a suspicious email, BFS can explore the email's sender and recipient network to
identify connections to known spam sources. This helps flag suspicious emails more effectively.
• Protein-Protein Interaction Networks: In bioinformatics, BFS can be used to analyze protein-
protein interaction networks. By modeling proteins as nodes and interactions as edges, BFS can
identify groups of interacting proteins that might be involved in specific biological processes. This
aids in understanding cellular functions and protein signaling pathways.
Depth-First Search (DFS):
• DFS dives as deep as possible along
a single branch before backtracking
and exploring alternative branches.
Imagine going down a long corridor,
then backtracking to try other
corridors if you reach a dead end.
DFS can be faster than BFS for
certain problems, but it might miss
the optimal solution if the goal is
located on a shallower branch.
• Data Structures:
• Stack (S): Used to remember the path taken during exploration. It follows a Last-In-First-Out (LIFO) principle.
• Visited: Similar to BFS, this can be an array or hash table to keep track of visited nodes and avoid revisiting
them.
• Algorithm:
• Initialization:
– Push the starting node onto the stack (S).
– Mark the starting node as visited.
• Exploration Loop:
– While the stack is not empty:
• Pop a node (v) from the stack (S).
• Process the node (v) (e.g., print its value).
• For each unvisited neighbor (w) of node (v):
– Push the neighbor (w) onto the stack (S).
– Mark the neighbor (w) as visited.

• Explanation:
• We start by pushing the starting node onto the stack and marking it visited.
• The exploration loop follows a depth-first approach.
• In each iteration, we pop a node (v) from the stack (since it follows LIFO, it explores the deepest path first).
• We process the popped node (v).
• We then check all the unvisited neighbors of node (v). If a neighbor (w) is unvisited, we push it onto the stack
for further exploration and mark it visited.
• This process continues until all reachable paths from the starting node are explored. Since the stack prioritizes
the most recent path, DFS explores one branch as deep as possible before backtracking and trying other
branches.
• Benefits of DFS:
• Can be faster than BFS for certain problems, especially when the goal node is located on a deeper branch in
the search space.
• Useful for finding paths in graphs that might have cycles, as BFS would keep looping infinitely in cycles.
• Drawbacks of DFS:
• Not guaranteed to find the optimal solution (shortest path) compared to BFS.
• Might explore unnecessary paths before reaching the goal, especially for expansive search spaces.
• Here's how DFS would work to find Alice, starting your search from John:
• Initialization: Push John (the starting node) onto the stack and mark him as visited.
• Exploration Loop:
– Iteration 1:
• Pop John from the stack.
• Process John.
• Check John's neighbors: Sarah and David. Since DFS goes deep first, explore Sarah first.
• Push Sarah onto the stack and mark her visited.
– Iteration 2:
• Pop Sarah from the stack.
• Process Sarah.
• Check Sarah's neighbors: Emily and Mike. Push Emily first (DFS follows LIFO).
• Push Emily onto the stack and mark her visited.
– Iteration 3:
• Pop Emily from the stack.
• Process Emily.
• Emily has no unvisited neighbors (both Sarah and Mike have been visited). Since there are no more unvisited neighbors on this path, DFS backtracks.
– Backtracking: DFS pops Sarah again (revisit) since there are unexplored neighbors (David).
– Iteration 4:
• Pop Sarah from the stack (again). (We already processed her).
• Now explore David (John's other neighbor).
• Push David onto the stack and mark him visited.
– Iteration 5:
• Pop David from the stack.
• Process David.
• Check David's neighbor: Charles. Push Charles onto the stack.
– Iteration 6:
• Pop Charles from the stack.
• Process Charles.
• Check Charles' neighbors: Alice and Bob. Push Alice first (DFS prioritizes it).
– Iteration 7: (similar to iteration 3, DFS backtracks as Emily has no unvisited neighbors)
– Backtracking: Pop Charles again (revisit) to explore Bob (since Alice is not found yet).
– Iteration 8:
• Pop Charles from the stack (again). (We already processed him).
• Explore Bob (David's neighbor). Since Bob is not Alice, DFS backtracks again.
• End of Exploration (Backtracking): We haven't found Alice after exploring John-Sarah-Emily and John-David-Charles paths.
Backtracking all the way to John, DFS would realize there are no more unvisited neighbors to explore. While BFS would
systematically check all friends and friends of friends, DFS might miss the shortest path if the goal (Alice) is on a less explored
branch.
• In this case, DFS didn't find Alice as quickly as BFS, but it demonstrates how DFS explores a single path as deeply as possible
until it reaches the goal or a dead end, then backtracks to try other branches.
Applications:
• Depth-First Search (DFS) proves valuable in various computer science scenarios due to its efficient
exploration of paths within a graph structure. Here are some key applications of DFS:
• Maze Solving: DFS is a fundamental algorithm for solving maze problems. It starts at the entry
point and explores one path at a time until it reaches the exit. If it hits a dead end, it backtracks
and tries another path. This systematic exploration makes DFS well-suited for finding a solution in
mazes.
• File System Navigation: DFS is handy for navigating directory structures in file systems. It can
efficiently list all files and folders within a directory, starting from a root directory and traversing
all subdirectories one by one until it reaches the end of each branch.
• Topological Sorting: This technique sorts a directed acyclic graph (DAG) where there are no
cycles. DFS helps achieve this by following directed edges and ensuring all predecessors of a node
are visited before the node itself. This ordering is useful in various applications, like resolving
dependencies when compiling code or scheduling tasks without conflicts.
• Cycle Detection in Graphs: DFS can effectively detect cycles in graphs. As it explores a path, it
keeps track of visited nodes. If it encounters a node that has already been visited while following a
path, it signifies a cycle exists in the graph.
• Undirected Graph Connectivity: DFS can be used to determine if an undirected graph is
connected. By starting from a node and using DFS to explore all reachable nodes, we can identify if
all nodes in the graph are connected or if there are isolated components.
• Strongly Connected Components: An extension of DFS can be used to find strongly connected
components (SCCs) in a directed graph. SCCs are groups of nodes where there's a path between
any two nodes within the group. DFS helps identify these SCCs efficiently.
• Network Routing Protocols: Some routing protocols, like distance-vector routing, can leverage
DFS principles to discover neighboring routers and exchange routing information. By exploring
paths outward from a router, DFS helps establish connections and build routing tables.
• These are just a few examples, and DFS continues to be a versatile tool for various tasks involving
graph exploration, pathfinding, and dependency management in computer science and beyond.
• Game AI: In games with artificial intelligence (AI) controlled enemies, DFS can be used
to explore the game world and chase the player. The AI can start from its current location
and use DFS to explore reachable areas, prioritizing paths that might lead to the player's
location.
• Natural Language Processing (NLP): DFS can be used in some NLP tasks for text
parsing and understanding sentence structure. By following the grammatical
dependencies between words in a sentence, DFS can help identify the relationships
between clauses and phrases, aiding in tasks like sentiment analysis or machine
translation.
• Computer Vision: In image segmentation problems, DFS can be employed to group
connected pixels that belong to the same object in an image. Starting from a seed pixel,
DFS can traverse neighboring pixels with similar color or features, effectively segmenting
the foreground object from the background.
• Logic Puzzles and Constraint Satisfaction Problems (CSPs): DFS can be a valuable
tool for solving logic puzzles like Sudoku or solving CSPs. It can systematically explore
different configurations (assignments of values to variables) and backtrack when
encountering contradictions, eventually finding a solution that satisfies all constraints.
• Circuit Analysis: Some circuit analysis algorithms utilize DFS to identify loops or paths
within a circuit. This can be helpful in tasks like finding short circuits or analyzing signal
flow within the circuit.
• Model Checking: In software verification, DFS can be used for model checking, a
technique to ensure a system meets specific requirements. It can explore all possible
states of the system using DFS and verify if any state violates the desired properties.
• Bioinformatics: In analyzing biological sequences like DNA or proteins, DFS can be used
to identify patterns or motifs within the sequence. It can explore different paths through
the sequence and compare them to known patterns, aiding in gene identification or
protein structure analysis.
Complexity
Both Breadth-First Search (BFS) and Depth-First Search (DFS) have a time complexity of O(V + E), where V represents
the number of vertices (nodes) and E represents the number of edges (connections) in the graph.
Here's why:
• Iterating over the Graph: Both BFS and DFS traverse the entire graph in the worst case scenario. BFS explores all
nodes level by level, while DFS explores all branches until it reaches a dead end or the goal. This traversal ensures
they visit (and potentially process) all V vertices and their corresponding edges (E).
• Linear Relationship: The time complexity grows linearly with the increase in the number of vertices and edges.
This means the execution time roughly doubles if the graph size doubles.

Factors Affecting Complexity:


• Adjacency List vs. Adjacency Matrix: The data structure used to represent the graph can affect the constant
factor hidden in the O(V + E) notation. Adjacency lists are generally preferred for sparse graphs (less edges than
vertices) as they only store connected edges, leading to faster lookups. Adjacency matrices, on the other hand, store
all possible connections, which can be faster for dense graphs (more edges than vertices) but use more space.
Space Complexity:
• BFS: BFS has a space complexity of O(V) in the worst case. This is because BFS uses a queue to store the nodes to
be explored at each level. In the worst case, when the graph is a complete tree (all nodes have children), the queue
can hold all the nodes at a single level, leading to a maximum space complexity of O(V).
• DFS: DFS generally has a space complexity of O(h) in the worst case, where h represents the height of the graph
(the longest path from a root node to a leaf node). This is because DFS uses a stack to keep track of the path it's
exploring. The depth of the stack corresponds to the current depth in the exploration, and in the worst case (deeply
nested paths), the stack can grow up to the height of the graph. However, for graphs with bounded depth (limited
number of levels), the space complexity of DFS is also considered O(V).

In conclusion:
• Both BFS and DFS offer efficient algorithms for graph traversal with a time complexity of O(V + E). Their space
complexity can differ based on the data structure used and the graph's properties. BFS uses more space in the worst
case due to the queue, while DFS uses more space in the worst case for deep graphs due to the stack.
Heuristic searches:
Heuristic searches are a type of search algorithm used in artificial intelligence
(AI) to find optimal or satisfactory solutions to problems within a vast search
space. Unlike uninformed search algorithms like Breadth-First Search (BFS)
and Depth-First Search (DFS) that explore the search space exhaustively,
heuristic searches leverage additional knowledge to guide their exploration
towards promising areas.
Here's how heuristic searches work:
• Problem Representation: The problem is modeled as a search space,
where each state represents a possible configuration, and actions lead to
transitions between states. The goal state represents the desired solution.
• Heuristic Function: A heuristic function, often denoted by h(x), estimates
the cost or distance from a current state (x) to the goal state. This function is
crucial for guiding the search towards more promising paths. However, it's
important to note that the heuristic function doesn't guarantee finding the
optimal solution, only an estimate.
• Evaluation Function: An evaluation function, often denoted by f(x),
combines the cost of reaching the current state (g(x)) with the heuristic
estimate (h(x)). Common evaluation functions include:
– f(x) = g(x) + h(x) (This is often used for A* search)
• Search Algorithm: The chosen search algorithm leverages the evaluation
function to prioritize exploring states that seem closer to the goal based on
the heuristic estimate.
Benefits of Heuristic Search:
• Reduced Exploration Time: By focusing on promising areas based on the heuristic, heuristic
searches can significantly reduce exploration time compared to uninformed searches, especially
for large search spaces.
• Finding Good Solutions: Even if the heuristic isn't perfect, it can still guide the search towards
good solutions, making them valuable in scenarios where finding the absolute optimal solution
might not be critical.

Challenges of Heuristic Search:


• Heuristic Design: Designing an accurate and efficient heuristic function is crucial for the success
of a heuristic search. A poor heuristic can lead the search astray or provide little benefit over
uninformed searches.
• Optimality Guarantees: Unlike BFS or DFS, which can guarantee finding the optimal solution for
certain problems, heuristic searches don't always guarantee finding the best solution. The
accuracy of the heuristic function plays a significant role.
Applications of Heuristic Search:
• Game Playing: Heuristic search algorithms are widely used in game playing AI, where the search
space can be vast (all possible game states). The heuristic function might estimate the advantage
a particular move offers, guiding the AI towards winning strategies.
• Pathfinding: In robotics and navigation problems, heuristic searches can be used to find efficient
paths for robots or autonomous vehicles. The heuristic function might estimate the distance or
travel time to the destination.
• Scheduling and Planning: Heuristic searches can be applied in tasks like job scheduling or
resource allocation. The heuristic function might estimate the completion time or resource usage
for different scheduling options.
• Machine Learning: Heuristic search principles can be incorporated into machine learning
algorithms to guide the search for optimal model parameters during training.
In conclusion, heuristic searches offer a powerful approach for tackling complex problems in AI by
leveraging informed exploration strategies. While they might not always guarantee the optimal
solution, their ability to efficiently explore promising areas within a vast search space makes them
valuable for various applications.
Cont..
• Generate and Test
• Hill Climbing
• Best First Search
• Problem Reduction
• Constraint Satisfaction
• Means-ends analysis
Generate and Test:
• The generate-and-test algorithm is a fundamental approach in problem-solving
and AI.
Concept:
• Generate: It involves creating possible solutions, often systematically. In
simpler forms, it might involve random generation.
• Test: Each generated solution is then evaluated against a set of criteria to
determine if it solves the problem.

Think of it like this: Imagine you're trying to find the combination to a lock. You
might:
• Generate possible combinations (e.g., trying numbers one by one).
• Test each combination on the lock to see if it opens.

Properties:
• Guaranteed Solution (if systematic): If there exists a solution and you
systematically generate and test all possibilities, you're guaranteed to find it
eventually.
• Exhaustive Search: In its most basic form, it's essentially an exhaustive
search, checking every single option. This can be slow for problems with vast
solution spaces.
• Limited Search Space: It becomes more powerful when combined with
constraints or heuristics that limit the generation process to a more focused
search space, making it more efficient.
Here are some contexts where generate-and-test is used:
• Constraint Satisfaction Problems (CSPs): Here, the
algorithm finds assignments that satisfy all the constraints of
the problem. For example, fitting together a jigsaw puzzle can
be seen as a CSP.
• Finding all solutions: If you need to find all possible valid
solutions, not just the first one, generate-and-test can be
adapted to keep track of all working solutions.

Limitations:
• Scalability: For problems with massive solution spaces,
exhaustive generate-and-test becomes impractical.
• Random vs. Systematic: Random generation might miss good
solutions, while systematic generation can be slow.
• Overall, the generate-and-test algorithm is a versatile
tool. It's a good starting point for understanding
problem-solving techniques and can be a foundation for
more advanced algorithms that incorporate heuristics
and optimizations.
Example:
A jigsaw puzzle is a tiling puzzle that requires the assembly of
often irregularly shaped interlocking and mosaicked pieces,
each of which typically has a portion of a picture. When
assembled, the puzzle pieces produce a complete picture.
• Jigsaw puzzles come in a variety of shapes and sizes. They
can be enjoyed by people of all ages and can provide a
variety of benefits, including:
• Improved problem-solving skills
• Enhanced critical thinking
• Increased patience and concentration
• Reduced stress and anxiety
• Boosted cognitive function
• Jigsaw puzzles can be a fun and relaxing activity for
individuals or groups. They can also be used as a challenge
or to promote teamwork.
Plan - Generate and Test:
• DENDRAL is an early example of successful
AI Program based on Heuristic plan-
generate-and test.
• In planning process it used Constraint –
satisfaction techniques to create lists of
recommended and constraint substructures.
• Next these fairly limited set of structures are
going to be used in Generate – and – Test
procedure.
• Constrained in this way, Generate and Test
procedure has proved highly effective.
Dendral was a pioneering AI program developed in the 1960s at Stanford University
https://en.wikipedia.org/wiki/Dendral. It's considered a landmark achievement for being
one of the first successful expert systems.

Here's how Dendral revolutionized AI:


• Focus: Dendral's primary function was to assist organic chemists in determining the
molecular structure of unknown organic molecules.
• Approach: It did this by analyzing mass spectrometry data, a technique that provides
information about the molecule's components.
• Innovation: Dendral employed a rule-based system that mimicked the knowledge and
decision-making processes of human chemists. This involved:
– Heuristic Search: It used a heuristic search algorithm to explore possible molecular structures
efficiently.
– Knowledge Base: It incorporated a vast knowledge base of chemical rules and constraints to guide
the search towards likely structures.

Impact of Dendral:
• Problem-Solving: Dendral paved the way for other expert systems in various domains,
demonstrating the power of AI in replicating human expertise for problem-solving.
• Drug Discovery: It had a significant impact on the field of drug discovery by automating
tasks and speeding up the process of identifying new drug candidates.
• Foundation for Future AI: The techniques and knowledge gained from Dendral laid the
groundwork for advancements in knowledge representation, reasoning, and search
algorithms, all crucial aspects of modern AI.

Overall, Dendral stands as a testament to the early success of AI in scientific


domains. It set the stage for the development of more sophisticated expert
systems and continues to inspire advancements in AI for scientific discovery.
Hill Climbing
• There is no feedback system in Generate and Test,
this is weakness of the approach and often produces
somewhat inaccurate solutions.
• Hill Climbing is a variant of Generate and Test in
which feedback from the test procedure, it helps the
generator decide which direction to move in the
search space.
• In a pure Generate and Test procedure, the test
function responds with only a yes or no.
• By augmenting with heuristic function provides an
estimate of how close a given state is to a goal state.
• This is useful when a good heuristic function is
available for evaluating states but no other
information is available.
Types of Hill Climbing:
1. Simple Hill climbing
2. Steepest-Ascent Hill climbing
3. Stochastic hill climbing
Simple Hill climbing
Hill climbing is a fundamental optimization technique used in Artificial Intelligence (AI) for finding
optimal solutions. It belongs to a class of algorithms called local search algorithms.
Here's a breakdown of a simple hill climbing algorithm:
• Core Idea: Imagine yourself climbing a hill. You want to reach the highest peak (optimal solution).
Hill climbing mimics this process by iteratively moving towards solutions that improve a specific
criteria.
Components:
• Initial State: This is the starting point of your search. It can be randomly chosen or based on some
domain knowledge.
• Successor Function: This function generates neighboring states from the current state. These
neighbors represent small modifications to the current solution.
• Objective Function: This function evaluates the quality of a state. It assigns a score indicating how
good a particular solution is. The goal is to maximize (or minimize) this score based on the problem.
Algorithm Steps:
• Start: Begin with an initial state.
• Evaluate: Check if the initial state is the goal state (optimal solution). If yes, you've found the
answer and can stop.
• Loop: Here's the iterative part:
– Generate neighboring states using the successor function.
– Evaluate each neighbor using the objective function.
– Select the neighbor with the best score (highest value for maximization, lowest for minimization).
• Update: If the chosen neighbor is better than the current state, replace the current state with the
neighbor.
• Repeat: Go back to step 3 and continue looping until:
– A goal state is reached.
– No better neighbor exists (stuck in local optima).
Limitations:
• Local Optima: Hill climbing can get trapped in local
maxima/minima, which are not the global optimum
(highest/lowest peak). The starting position significantly
impacts the outcome.
• No guarantee of finding the global optimum.
Applications:
• Hill climbing is used in various AI problems where finding
an optimal solution is crucial. Here are some examples:
• Scheduling: Optimizing task scheduling to minimize
completion time.
• Routing: Finding the shortest route for a delivery truck.
• Game Playing: Choosing the best move in a game like
chess.
Despite its limitations, the simplicity and efficiency of hill
climbing make it a valuable tool in AI for finding good
solutions, especially when the search space is vast.
Example:
Let's illustrate a simple hill climbing example to find the maximum height of a hill
(maximization problem).
• Scenario: Imagine a landscape with several hills. We want to find the highest point.
• States: Each point on the landscape represents a state. The height of the point represents
the value of the state.
• Successor Function: We can define our successor function to move us to adjacent points
(up, down, left, right) on the landscape.
• Objective Function: The objective function simply returns the height of the current state.
Steps:
• Start: We randomly pick a starting point on the landscape (e.g., a valley).
• Evaluate: The initial state's height is not the maximum, so we continue.
• Loop:
– We explore neighboring points (up, down, left, right).
– We compare their heights to the current state.
– If a neighbor is higher, we move to that point (update current state).
• Repeat: We keep looping until:
– We reach a peak (no higher neighbors).
– We've explored all possibilities (unlikely for a real landscape).
Example:
• Suppose our starting point has a height of 3. We explore neighbors and find one with a height
of 5. We move there. We continue exploring neighbors from this new point (height 5). If all
neighbors are lower than 5, we've reached a local maximum (peak) and stop. The final height
(5) might not be the absolute highest point on the landscape (global maximum), but it's a
local optimum found by hill climbing.
• This is a simplified example, but it captures the essence of how hill climbing works. It
iteratively moves towards better solutions based on the objective function until it reaches a
local optimum.
example of hill climbing to find the
shortest path for a traveling salesperson:
Scenario: Imagine a salesperson has to visit N cities and return to the starting point. The goal is to find the
shortest route that visits all cities exactly once.
• States: A state represents a possible travel route visiting some or all cities. We can represent this as a
permutation of the city indices (e.g., [1, 3, 2] means visiting city 1, then 3, then 2).
• Successor Function: The successor function generates neighboring states by swapping the order of two
cities in the current route. For example, swapping city 2 and 3 in [1, 3, 2] would result in [1, 2, 3].
• Objective Function: The objective function calculates the total distance traveled in a specific route
(state). This involves summing the distances between consecutive cities in the permutation.
Steps:
• Start: We randomly generate an initial order for visiting the cities (initial route).
• Evaluate: The initial route might not be the shortest.
• Loop:
– Generate neighboring routes by swapping city positions.
– Calculate the total distance for each neighbor.
– Select the neighbor with the shortest distance (minimum value).
• Update: If the chosen neighbor has a shorter distance than the current route, replace the current route
with the neighbor.
• Repeat: Keep looping until:
– A route visiting all cities with the minimum distance is found.
– No neighbor with a shorter distance exists (local minimum).

Limitations:
• Similar to the previous example, here too, the algorithm can get stuck in local minima (a shorter route
might exist but not explored). The quality of the solution significantly depends on the initial random route.
• This example demonstrates how hill climbing can be applied in routing problems to find (hopefully) the
most efficient path despite the possibility of local optima.
steepest ascent hill climbing
Steepest ascent hill climbing is a variant of the simple hill climbing algorithm
used in Artificial Intelligence (AI) for optimization problems. Here's how it differs
from regular hill climbing:
Regular Hill Climbing:
• Evaluates only one neighboring state at a time from the current state.
• Selects the first neighbor that improves the objective function value.
Steepest Ascent Hill Climbing:
• Evaluates all neighboring states of the current state.
• Selects the neighbor with the highest value for a maximization problem (or
the lowest value for minimization) according to the objective function.
• In essence, steepest ascent takes a more comprehensive approach by
considering all possibilities in the immediate vicinity before making a move.
Advantages:
• Potentially faster convergence towards a local optimum compared to simple
hill climbing, especially in scenarios with many neighbors.
• Might be more likely to escape shallow local optima by taking a bigger jump in
the direction of steeper improvement.
Disadvantages:
• Can be computationally expensive, especially for problems with a large
number of neighbors.
• Still susceptible to getting trapped in local optima, just like regular hill
climbing.
Here's an analogy:
• Imagine you're lost in a foggy forest trying to find the highest
peak (maximum value).
• Regular hill climbing: You check the visibility in one direction
(neighbor) at a time and move towards the first uphill path you
find.
• Steepest ascent hill climbing: You climb a tree (if possible) to
get a better view of the surroundings (evaluate all neighbors).
Then, you descend towards the direction with the steepest incline
(highest value neighbor).

Choosing the Right Algorithm:


• The choice between regular and steepest ascent hill climbing
depends on the specific problem and the trade-off between speed
and potential for better solutions. For problems with a high
number of neighbors, the computational cost of steepest ascent
might outweigh its benefits. However, for problems with well-
defined landscapes (objective function), steepest ascent can be a
good choice.
stochastic hill climbing

Stochastic hill climbing, also known as randomized hill climbing, is


another variation of the basic hill climbing algorithm used in
optimization problems within Artificial Intelligence (AI). While both
regular and steepest ascent hill climbing methods rely on
deterministic improvement (always moving in the best direction),
stochastic hill climbing incorporates an element of randomness.
Here's how stochastic hill climbing works:
• Similar to basic hill climbing: It uses the same concepts of
states, successor function, and objective function.
• Introducing Randomness: Instead of always selecting the
neighbor with the best improvement, stochastic hill climbing
considers multiple neighbors and chooses one randomly from
those that show improvement (or sometimes even no change).
There are different ways to implement the "random selection" part:
• Random Selection with Threshold: Only neighbors with
improvement above a certain threshold participate in the random
selection process.
• Probability Based Selection: The probability of selecting a
neighbor can be tied to the improvement it offers. Higher
improvement gets a higher chance of selection.
Advantages:
• Escaping Local Optima: By introducing randomness,
stochastic hill climbing has a better chance of escaping local
optima. Even if a neighbor isn't the absolute best, there's a
possibility it leads out of a stagnant area and towards a better
region of the search space.
• Avoiding Cycling: In some scenarios, deterministic hill climbing
can fall into a loop where it keeps revisiting the same states.
Stochasticity helps to break out of such cycles.

Disadvantages:
• Slower Convergence: Compared to deterministic methods,
stochastic hill climbing might take longer to converge towards a
local optimum because it doesn't strictly follow the steepest
ascent path.
• Finding Suboptimal Solutions: The random element can also
lead the algorithm towards less than ideal solutions, especially if
the chosen "random improvement" neighbor doesn't lead to a
very promising area of the search space.
Applications:
• Stochastic hill climbing is a good choice for problems with:
• Rough landscapes: When the objective function has many ups
and downs, randomness can help explore different areas and
potentially find better solutions.
• Risk of getting stuck: If the problem is prone to local optima,
the random element can increase the chance of escaping them.

Here's an analogy:
• Imagine you're again lost in a foggy forest but this time with a
compass (objective function) to guide you uphill.
• Regular/Steepest Ascent Hill Climbing: You meticulously
follow the steepest uphill path indicated by the compass.
• Stochastic Hill Climbing: You trust the compass generally but
occasionally take slightly random detours (within a reasonable
range) hoping to stumble upon a better path out of the fog.
In conclusion, stochastic hill climbing offers a balance between
deterministic improvement and exploration, making it a valuable
tool for navigating complex search spaces in AI.
Example : Local Maxima and Global
Maxima
Let's revisit the scenario of finding the highest point on a hill
(maximization problem) to illustrate local and global maxima:
Imagine a landscape with two hills:
• Hill A: Tall and isolated, with a single peak (global maximum) at its
center.
• Hill B: Smaller with multiple bumps. It has a central peak (local
maximum) that's not the highest point on the entire landscape
(global maximum lies on Hill A).
Local Maximum:
• The peak on Hill B is a local maximum. Here's why:
• It's the highest point in its immediate vicinity.
• If you start climbing from any point on Hill B, you'll eventually
reach this central peak.
• However, this peak is not the highest point on the entire landscape
(both hills combined).
Global Maximum:
• The global maximum refers to the absolute highest point across
the entire landscape (both hills). In this case, it's the peak on Hill A.
• Key Points:
• A local maximum is only the highest point in its local area.
• The global maximum is the highest point overall.
• Finding Local vs. Global Maxima:
• Hill climbing algorithms like the ones we discussed earlier often find
local maxima. They might get stuck there if the surrounding area
doesn't offer a clear path towards a higher point.
• There are advanced optimization techniques that can improve the
chances of finding the global maximum, but they often come with
increased complexity.
• Visualizing Local and Global Maxima:
• Imagine a graph where the x-axis represents different locations on
the landscape and the y-axis represents the height at each location.
The peaks on the graph would correspond to the maxima.
• A local maximum would appear as a bump on the graph, higher than
its immediate surroundings but lower than some other points on the
graph (global maximum).
• The global maximum would be the highest point on the entire graph.
Diagrammatic
Representation:
• Plateau and ridge are terms used in AI, specifically in optimization algorithms like hill
climbing, to describe challenging terrains encountered during the search for an optimal
solution.
• Plateau:
• A plateau refers to a flat region in the search space where all neighboring states
(possible solutions) have the same value according to the objective function.
• Imagine yourself on a flat tableland while climbing a hill. No matter which direction you
move, the elevation remains constant.
• For a hill climbing algorithm, a plateau presents a dilemma. The objective function
doesn't provide any clear direction for improvement (either uphill or downhill) since
neighboring states have the same value.
• Ridge:
• A ridge is a more subtle challenge. It's a long, narrow area in the search space that's
generally higher than its surroundings but has a slight downward slope in all directions.
• Imagine yourself on the crest of a long, narrow mountain ridge. While you're at a higher
elevation compared to the valleys on either side, there's no clear peak to reach.
• For a hill climbing algorithm, a ridge can be misleading. Since all immediate neighbors
have a lower value, the algorithm might terminate here, mistaking it for a local
maximum (peak). The true optimum might lie further along the ridge.
• Challenges Posed by Plateaus and Ridges:
• Both plateaus and ridges can hinder the progress of a hill climbing algorithm in finding
the optimal solution.
• Plateaus cause the algorithm to stagnate as there's no clear direction for improvement.
• Ridges can lead to premature termination as the algorithm gets stuck at a seemingly
high point (but not the highest).
Techniques to overcome local maxima, plateau and ridge

Hill climbing algorithms are great for finding optimal solutions, but they can get stuck in less-
than-ideal situations like local maxima, plateaus, and ridges. Here are some techniques to
overcome these challenges:
Local Maxima:
• Simulated Annealing: This method introduces a random element, allowing the algorithm
to escape local maxima with a certain probability. It works by accepting worse solutions
(downhill moves) with a decreasing probability as the search progresses, mimicking the
cooling process of metal.
• Multiple Restarts: Run the algorithm multiple times with different starting points. This
increases the chance of finding the global optimum by exploring various regions of the
search space.
• Genetic Algorithms: These algorithms work with a population of solutions and mimic
biological evolution. They can explore diverse areas of the search space and potentially
escape local maxima through crossover and mutation operations.

Plateau:
• Random Restarts: Similar to local maxima, restarting the algorithm from a new random
point can help it escape the flat region and explore areas with more promising solutions.
• Larger Step Sizes: Instead of evaluating only immediate neighbors, the algorithm can
consider states further away. This might allow it to "jump" over the plateau and find a
better direction for improvement.
• Change of Objective Function: If applicable, consider using a secondary objective
function alongside the primary one. This can break ties in cases where multiple neighboring
states have the same value in the primary function.
Ridge:
• Random Restarts: Similar to plateaus and local maxima, random restarts can be helpful.
• Variable Step Sizes: Instead of a fixed step size for exploring neighbors, the algorithm
can dynamically adjust it. This allows for larger jumps along the ridge while still exploring
nearby areas for improvement.
• Multiple Evaluation Criteria: Similar to plateaus, using additional objective functions can
help the algorithm navigate a ridge. These secondary functions might provide a way to
differentiate between points along the ridge and guide the search towards a true peak.

Choosing the Right Technique:


• The best technique depends on the specific problem and the characteristics of the search
space. Here are some general considerations:
• Simulated annealing is a good choice for problems with rugged landscapes (many local
maxima) where escaping them is crucial.
• Multiple restarts are a simple and effective strategy for various scenarios, especially
when combined with other techniques.
• Genetic algorithms are powerful for complex problems where exploration and
exploitation of the search space are both important.
• Larger step sizes can be beneficial for plateaus but might be less effective for ridges
where a more nuanced approach is needed.

Overall:
• While these techniques can improve the performance of hill climbing algorithms, it's
important to remember that there's no guaranteed escape from local optima, plateaus, or
ridges. The choice of technique depends on the problem and the desired balance between
efficiency and finding the best possible solution.
Best-First Search
• In BFS and DFS, when we are at a node, we can
consider any of the adjacent as next node.
• So both BFS and DFS blindly explore paths
without considering any cost function.
• The idea of Best First Search is to use an
evaluation function to decide which adjacent is
most promising and then explore.
• Best First Search falls under the category of
Heuristic Search or Informed Search.
• We use a priority queue to store costs of nodes.
So the implementation is a variation of BFS, we
just need to change Queue to PriorityQueue.
OR Graphs
• We start from source "S" and search for goal "I"
using given costs and Best First search.
• pq initially contains S We remove s from and
process unvisited neighbors of S to pq.
• pq now contains {A, C, B} (C is put before B
because C has lesser cost)
• We remove A from pq and process unvisited
neighbors of A to pq. pq now contains {C, B, E, D}
• We remove C from pq and process unvisited
neighbors of C to pq. pq now contains {B, H, E, D}
• We remove B from pq and process unvisited
neighbors of B to pq. pq now contains {H, E, D, F,
G}
• We remove H from pq. Since our goal "I" is a
neighbor of H, we return.
Analysis :
• The worst case time complexity for Best
First Search is O(n * Log n) where n is
number of nodes. In worst case, we may
have to visit all nodes before we reach goal.
Note that priority queue is implemented
using Min(or Max) Heap, and insert and
remove operations take O(log n) time.
• Performance of the algorithm depends on
how well the cost or evaluation function is
designed.
Best-first search is a type of search algorithm used in artificial
intelligence (AI) for pathfinding and problem-solving. It belongs
to the category of informed search algorithms, meaning it
utilizes additional knowledge about the problem domain to
guide its exploration.
– Here's a breakdown of how it works:
• Core Idea:
– Unlike blind search algorithms (BFS & DFS) that explore all
possibilities equally, best-first search prioritizes exploring what
seems to be the most promising path based on a specific evaluation
function.
• Key Components:
– Search Space: The set of all possible states or configurations the
search can explore.
– Evaluation Function: A function that estimates how "good" a
particular state is relative to the goal. This function is crucial for
guiding the search towards the optimal solution.
– Priority Queue: A data structure that prioritizes elements based on
their evaluation function scores. The lower the score (indicating a
more promising state), the higher the priority for exploration.
• Steps:
– Start State: Begin with an initial state representing the starting point of the
search.
– Evaluation: Calculate the evaluation function score for the starting state.
– Expand State: Add the starting state to the priority queue.
• Loop: While not finished searching:
– Dequeue: Remove the state with the highest priority (supposedly closest to the
goal) from the queue.
– Goal Check: If the dequeued state is the goal state, terminate the search and
return the solution path.
– Generate Successors: Identify all possible next states reachable from the current
state.
– Evaluate Successors: Calculate the evaluation function score for each successor
state.
– Enqueue Successors: Add the successor states along with their scores to the
priority queue.
• No Solution Found: If the loop finishes without finding the goal state, it
might indicate either no solution exists or the evaluation function needs
refinement.

• Example (Maze Navigation):


– Imagine searching for the exit in a maze. Here, the search space is all possible
locations within the maze. The evaluation function could estimate the distance from
a particular location to the maze exit. The best-first search would prioritize
exploring paths that lead closer to the estimated exit, ultimately finding the
shortest path out.
• Types of Best-First Search:
• Greedy Best-First Search: This version only considers the evaluation
function score at the current state, making it susceptible to getting stuck
in local minima (non-optimal solutions that seem promising initially).
• A Search Algorithm:* A popular variant that combines the evaluation
function with the cost of reaching the current state, making it more likely
to find the optimal solution.
• Advantages:
• More efficient than blind search algorithms, especially for problems with
large search spaces.
• Can find good solutions quickly by focusing on promising paths.
• Disadvantages:
• Optimality depends on the quality of the evaluation function.
• Can still get stuck in local minima if the evaluation function is misleading.
• Applications:
• Pathfinding in video games and robotics.
• Game playing (e.g., chess)
• Constraint satisfaction problems
• Logistics and scheduling problems
A* Algorithm
The A* (pronounced "A-star") algorithm is a widely used and powerful
best-first search technique for pathfinding on graphs.
– Here's a breakdown of the key concepts involved in A*:
• Core Functionality:
• A* finds the shortest path between a starting node and a goal node in a
weighted graph. Each edge (connection between nodes) has an
associated weight representing the cost of traversing that path.
• Key Components:
• Weighted Graph: A representation of the problem space where nodes
represent locations and edges represent connections between them.
Weights on edges indicate the cost of moving between those nodes.
• Heuristic Function (h(n)): An informed guess that estimates the cost
of the cheapest path from a node (n) to the goal node. This function
plays a crucial role in guiding the search towards the most promising
paths.
• Cost Function (g(n)): Represents the actual cost incurred to reach a
particular node (n) from the starting node.
• Evaluation Function (f(n)): A combination of the cost function (g(n))
and the heuristic function (h(n)). It guides the search by prioritizing
nodes with a lower f(n) score. f(n) = g(n) + h(n).
• Steps:
• Open Set: Initialize an open set containing only the starting node with
an f(n) score calculated based on h(n) (estimated cost to goal from start).
• Closed Set: Initialize a closed set to store already explored nodes.
• Loop: While the open set is not empty and the goal node hasn't been
found:
– Select Best Node: Remove the node with the lowest f(n) score from the open
set. This is considered the most promising node to explore next.
– Goal Check: If the selected node is the goal node, reconstruct the path from the
start node to reach the goal using the recorded predecessor information and
terminate the search.
– Expand Node: Add the selected node to the closed set (to avoid revisiting).
– Generate Successors: Identify all neighboring nodes reachable from the
selected node.
– Evaluate Successors: For each neighbor:
• Calculate the cost function (g(n)) by adding the cost of reaching the current node
(g(current)) to the cost of the edge connecting them.
• Estimate the heuristic value (h(n)) for the neighbor using the heuristic function.
• Calculate the evaluation function (f(n)) for the neighbor (g(n) + h(n)).
– Update Open Set: If a neighbor is not in the closed set and either it's not in the
open set or the new g(n) for the neighbor is lower than the previous one in the
open set, add the neighbor to the open set (or update its f(n) score) along with its
predecessor information (the node it was reached from).
• Advantages:
• Optimality: A* is guaranteed to find the shortest path if a
consistent heuristic function is used (a heuristic that never
overestimates the actual cost to the goal).
• Efficiency: A* focuses its search on promising areas guided by
the heuristic, making it efficient for large search spaces.
• Disadvantages:
• Heuristic Dependence: The optimality and efficiency of A*
heavily rely on the quality of the chosen heuristic function. A
bad heuristic can lead to suboptimal solutions or excessive
exploration.
• Memory Usage: A* can store a significant number of nodes in
the open and closed sets, especially for complex graphs.
• Applications:
• Pathfinding in video games and robotics navigation.
• Route planning for GPS systems.
• Scheduling and resource allocation problems.
• Game playing and AI decision making.
A* algorithm for 8 Puzzle
Problem Reduction
• AND – OR Graphs:
AND-OR graphs are a special type of graph used in Artificial Intelligence (AI) for
representing problems that can be broken down into smaller subproblems. They help
visualize the different ways to achieve a goal by considering both mandatory and
optional steps.
• Here's a breakdown of how they work:
• Structure: An AND-OR graph is similar to a regular graph, but with two types of
edges:
– AND edges: Represented by a line connecting nodes. It indicates that all subproblems
connected by the AND edge must be solved for the parent node (representing a bigger goal) to
be successful.
– OR edges: Represented by a dotted line connecting nodes. It signifies that only one of the
subproblems connected by the OR edge needs to be solved for the parent node to be successful.
• Applications: AND-OR graphs are useful in various AI problems where there are
multiple ways to achieve a goal. Some examples include:
– Planning and scheduling: Reasoning about different actions or tasks that need to be
completed to achieve a desired outcome.
– Diagnosis: Modeling different faults or symptoms that could lead to a particular system failure.
– Game playing: Representing the possible moves and their outcomes in a game like chess.
• Algorithms: There are specialized search algorithms designed to work with AND-OR
graphs, such as the AO* algorithm. AO* is a best-first search that leverages heuristics
to efficiently explore the graph and find the optimal solution (the best course of action
to achieve the goal).
• AND-OR graphs are more complex than regular graphs due to the “AND" relationships.
Standard search algorithms like A* might not be suitable for them.
• AND-OR graphs can be used to model uncertainty or different initial conditions in a
problem.
Algorithm: Problem
Reduction
• Problem reduction is a powerful technique used in AI and computer science to
tackle complex problems by breaking them down into smaller, more
manageable subproblems. It's like taking a large, overwhelming task and
dividing it into a series of achievable steps.
• Here's a closer look at how it works:
• The Process:
• Break Down the Big Picture: You start by identifying the main problem you
want to solve. Then, you analyze it and see if it can be decomposed into
smaller, well-defined subproblems. Each subproblem should contribute to
solving the overall problem.
• Solve the Smaller Problems: Once you have your subproblems, you can
tackle them individually. Depending on the complexity, you might use
different approaches for each subproblem. In some cases, you might even
need to apply problem reduction again to further break down a subproblem.
• Combine Solutions: After solving the subproblems, you need to combine
their solutions to reach a solution for the original problem. This might involve
merging results, following a specific order of execution, or making sure all
subproblems are addressed.
• Benefits of Problem Reduction:
• Makes complex problems easier to understand and solve. By breaking
down a large problem, you can focus on smaller, more manageable pieces.
• Improves efficiency. Focusing on smaller problems can often lead to quicker
solutions compared to tackling a complex problem head-on.
• Allows for reusability. Solutions to subproblems can sometimes be reused
in other contexts, saving time and effort.
• Applications of Problem Reduction:
• Divide-and-conquer algorithms: These algorithms rely heavily on
problem reduction. A classic example is merge sort, which breaks
down a large list into smaller sub-lists, sorts them individually, and
then merges the sorted sub-lists back into a single sorted list.
• Game playing: AI in games often uses problem reduction to
evaluate possible moves and their outcomes, ultimately aiming to
achieve the best course of action.
• Robotics: Robots can use problem reduction to break down
complex tasks like navigating an environment into smaller, more
manageable steps like obstacle avoidance and path planning.
• Things to Consider:
• Not all problems can be effectively reduced. Sometimes, the
complexity of breaking down a problem might outweigh the benefits
of solving smaller subproblems.
• The effectiveness of reduction depends on how well the
subproblems are chosen. They should be independent (not rely
on each other heavily) and contribute directly to the overall solution.
Another difference to OR
Graphs:
Limitation of AND_OR Graph
AO* algorithm:
• AO* (pronounced "A-star-augmented") is an AI search
algorithm designed for dynamic environments. It builds
upon the A* algorithm, but with a key advantage: AO* can
adapt to changes in the environment without having to
completely restart the search.
• Here's a breakdown of AO* and its key features:
• Core functionalities:
• Best-first search: Similar to A*, AO* explores the search
space in an informed way, prioritizing nodes that are likely
to lead to the goal based on a heuristic function.
• AND-OR Graphs: AO* leverages AND-OR graphs to
represent the search space. These graphs capture not only
mandatory steps (AND edges) but also optional alternatives
(OR edges) to reach the goal.
• Adaptability: AO* shines in dynamic environments. When
the environment changes (e.g., a blocked passage), AO* can
revise costs and re-evaluate previously explored paths. It
avoids blindly continuing down a path that might no longer
be optimal due to the change.
• How AO works:*
• Initialization:
– Define the starting node and the goal node.
– Build the AND-OR graph representing the search space.
– Set up the heuristic function to estimate the cost of reaching the goal from any
node.
• Iterative exploration:
– AO* maintains an open list (nodes to be explored) and a closed list (already
explored nodes).
– It prioritizes nodes in the open list based on a combined evaluation:
• g-value: The actual cost of reaching the current node from the start.
• h-value: The estimated cost of reaching the goal from the current node (provided by the
heuristic function).
– AO* expands the most promising node (with the lowest combined f-value) from
the open list.
• Adapting to changes:
– If a change is detected in the environment, AO* focuses on revising costs of
affected nodes and re-evaluating their positions in the open list. Nodes whose
paths become invalid due to the change are removed from the open list.
• Reaching the goal:
– The search continues until a node representing the goal state is expanded.
The path to the goal can then be traced back through the parent nodes.
• Benefits of AO:*
• Efficient search in dynamic environments: AO* avoids
unnecessary re-exploration of the entire search space when the
environment changes.
• Leverages A for efficiency:* It incorporates the best-first search
approach of A*, making it efficient for finding optimal solutions.
• Handles complex search spaces: By using AND-OR graphs, AO*
can represent problems with multiple options and mandatory steps.
• Applications of AO:*
• Real-time planning and scheduling: In scenarios where
conditions can change (e.g., robot navigation, traffic routing), AO*
can adapt the plan in real-time.
• Game playing: AI players in games with dynamic environments can
benefit from AO* to make optimal moves considering potential
changes.
• Interactive systems: AO* can be used in systems that respond to
user input or external events, continuously adapting the search
based on new information.
• Understanding AO requires familiarity with AND-OR graphs.
Real-Life Applications of AO* algorithm:

• Vehicle Routing Problem:


• The vehicle routing problem is determining the shortest routes for a fleet of
vehicles to visit a set of customers and return to the depot, while minimizing
the total distance traveled and the total time taken. The AO* algorithm can be
used to find the optimal routes that satisfy both objectives.
• Portfolio Optimization:
• Portfolio optimization is choosing a set of investments that maximize returns
while minimizing risks. The AO* algorithm can be used to find the optimal
portfolio that satisfies both objectives, such as maximizing the expected
return and minimizing the standard deviation.
• In both examples, the AO* algorithm can be used to find the optimal solution
that balances multiple conflicting objectives, such as minimizing distance and
time in the vehicle routing problem, or maximizing returns and minimizing
risks in the portfolio optimization problem. The algorithm starts with an initial
solution and iteratively improves it by exploring alternative solutions and
keeping the best solution that satisfies both objectives.
Working of AO* algorithm:

• The evaluation function in AO* looks like


this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node
to the current node.
h(n) = estimated cost from the
current node to the goal state.
• Here in the example below the Node
which is given is the heuristic value
i.e h(n). Edge length is considered
as 1.
Step 1:
Step 2:
Step 3:
Constraint Satisfaction:
Constraint Satisfaction Problems (CSP) Examples:
Here are some classic examples of AI problems that can be effectively solved using constraint satisfaction
techniques:
• N-Queens Puzzle: You have an N x N chessboard and N queens. The goal is to place the queens on the
board such that no two queens can attack each other (diagonally, horizontally, or vertically). Variables
are queen positions, domains are squares on the board, and constraints ensure no queens threaten each
other.
• Sudoku: A partially filled Sudoku puzzle. The objective is to fill the remaining squares such that each
row, column, and 3x3 subgrid contains the numbers 1 to 9 exactly once. Variables are empty cells,
domains are numbers 1 to 9, and constraints ensure no number repeats in a row, column, or subgrid.
• Course Scheduling: A university needs to assign professors and classrooms to various courses while
considering professor availability, classroom capacity, and student enrollment conflicts. Variables are
course assignments, domains are available time slots and classrooms, and constraints ensure professors
aren't double-booked, classrooms aren't overloaded, and students don't have conflicting schedules.
AI problems without Constraint Satisfaction:
Some AI problems might not be ideal candidates for constraint satisfaction due to the nature of the solution
or the complexity of the constraints. Here are some examples:
• Game Playing (Chess): While some aspects of chess opening strategy might involve CSP (e.g., piece
placement), overall chess playing relies on evaluating positions, planning future moves, and adapting to
the opponent's strategies. This requires more complex decision-making beyond simple constraint
satisfaction.
• Machine Translation: Translating text from one language to another involves understanding the
meaning of the source sentence, generating different possible translations, and selecting the most
natural and grammatically correct option. Constraint satisfaction struggles with the open-ended nature of
language and the need for nuanced understanding.
• Image Recognition: Identifying objects in an image requires analyzing visual features, recognizing
patterns, and reasoning about the context. Constraint satisfaction wouldn't be suitable for capturing the
complex relationships between pixels and the real-world objects they represent.
cryptarithmetic problem

A cryptarithmetic problem is a type of constraint satisfaction problem (CSP)


where you use logic and reasoning to assign digits to letters in a mathematical
equation. The goal is to find a unique assignment that makes the equation true.
– Here's how a cryptarithmetic problem works as a CSP:
• Variables: The letters in the equation (e.g., S E N D + M O R E = M O N E Y).
• Domains: Each letter can be assigned a digit from 0 to 9 (although leading
zeros are usually not allowed).
• Constraints:
– Each letter must be assigned a unique digit (e.g., S cannot be both 1 and 7).
– The arithmetic operation (addition, subtraction, multiplication, etc.) must hold true
when using the assigned digits (e.g., the sum of SEND + MORE must equal MONEY).
• Solving a cryptarithmetic problem involves trying different combinations of
digit assignments to the letters while ensuring all the constraints are satisfied.
• Here are some strategies for solving cryptarithmetic problems:
• Start from the rightmost column: Since carrying over digits affects the
next column, it's easier to solve the rightmost column first and work your way
left.
• Use the properties of addition/subtraction: Consider the possible
sums/differences of digits in each column based on the carry-over information.
• Uniqueness of digits: No digit can be assigned to two different letters. Use
this to eliminate possibilities.
Algorithm:
• Additional Constraints:
• M=1, since two –digit numbers plus a carry con’t total
more than 19.
• S=8 or 9, since S+M(1)+C3>9 (to generate the carry)
and M=1, S+1+C3>9, so S+C3>8 and C3 is at most 1.
• O=0, since S+M+C3(<=1) must be at least 10 to
generate a carry and it can be a most 11. But M is
already 1, so O must be 0.
• N=E or E+1, depending on the value of C2. but N can’t
have the same value as E. So N=E+1 and C2 is 1.
• In order C2 to be 1, the sum of N+R+C1 must be
greater than 9, so N+R must be greater than 8.
• N+R can’t be greater than 18, even with a carry in, so
E can’t be 9.
From here no more constraints can be generated.
• To make progress from here, we must guess.
• Suppose E is assigned the value 2. (it occures 3
times i.e interact highly with other letters)
• Next cycle:
• N=3, since N=E+1.
• R=8 or 9, since R+N(3)+C1(1 or 0)=2 or 12. But
since N is already 3, the sum of these
nonnegative numbers can’t be less than 3. Thus
R+3+(0 or 1)=12 and R=8 or 9.
• 2+D=Y or 2+D=10+Y, from the sum in the
rightmost column.
Again, assume no further constraints can be
generated, a guess is required. Suppose C1 is
chosen to guess a value for. If we try the value 1.
Means-Ends Analysis:
Means-ends analysis (MEA) is a problem-solving technique used in various fields, including artificial
intelligence (AI). It's a step-by-step approach to break down a problem into smaller, more manageable
goals and then identify actions to achieve those goals.
• Here's how it works:
• Define the End Goal: Clearly identify the desired outcome you want to achieve. This is your final
state.
• Identify the Current State: Describe the situation you're starting from. This is your initial state.
• Analyze the Differences: Compare the current state to the end goal and identify the key differences
that need to be addressed. These differences essentially become subgoals.
• Generate Actions: For each subgoal, brainstorm actions or steps you can take to reduce the gap
between the current state and the desired state.
• Evaluate and Refine: Assess the feasibility and effectiveness of the proposed actions. Refine your
approach as needed and potentially identify additional subgoals or adjust existing ones.
• Repeat: Continue iterating through steps 3-5 until you've identified a sequence of actions that bridge
the gap between the current state and the end goal.
• MEA helps you decompose a complex problem into smaller, more achievable steps. It also encourages
you to consider potential roadblocks and actively plan for overcoming them.
• Here are some benefits of using means-ends analysis:
• Structured Problem-Solving: Provides a clear framework for breaking down problems and
identifying solutions.
• Goal-Oriented Approach: Keeps the focus on the desired outcome and guides decision-making.
• Flexibility: Adaptable to various types of problems and can be applied in different contexts.
• Creativity Enhancement: Encourages exploration of different actions and potential solutions.
• Here are some limitations to consider:
• Complexity of Large Problems: Decomposing very complex problems can become cumbersome.
• Limited Scope: Focuses on the specific problem at hand and might not consider broader implications.
• Trial and Error: Finding the optimal solution often involves some trial and error.
• Most of the search strategies either reason forward of
backward however, often a mixture of the two
directions is appropriate.
• Such mixed strategy would make it possible to solve
the major parts of problem first and solve the smaller
problems the arise when combining them together.
• Such a technique is called "Means - Ends Analysis".
• The means -ends analysis process centers around
finding the difference between current state and goal
state.
• The problem space of means - ends analysis has an
initial state and one or more goal state, a set of
operators with a set of preconditions their application
and difference functions that computes the difference
between two state a(i) and s(j).
• A problem is solved using means - ends
analysis by
1. Computing the current state s1 to a goal
state s2 and computing their difference D12.
2. Satisfy the preconditions for some
recommended operator op is selected, then
to reduce the difference D12.
3. The operator OP is applied if possible. If not
the current state is solved a goal is created
and means- ends analysis is applied
recursively to reduce the sub goal.
4. If the sub goal is solved state is restored and
work resumed on the original problem.
• The first AI program to use means - ends analysis was
the GPS General problem solver.
• Means- Ends analysis is useful for many human
planning activities.
• Consider the example of planning for an office worker.
• Suppose we have a different table of three rules:
1. If in out current state we are hungry , and in our goal state
we are not hungry , then either the "visit hotel" or "visit
Canteen " operator is recommended.
2. If our current state we do not have money , and if in your
goal state we have money, then the "Visit our bank"
operator or the "Visit secretary" operator is recommended.
3. If our current state we do not know where something is ,
need in our goal state we do know, then either the "visit
office enquiry" , "visit secretary" or "visit co worker "
operator is recommended.
Example: Simple House hold robot domain

• The available operators are shown in


table 3.15 along with their preconditions
and results.
• Table 3.16 shows the difference table
that describes when each of the
operators is appropriate.
Solving Problem:
• Problem given to robot : Moving a desk with two things on
it from one room to another.
• The objects on the must also be moved.
• The
• Main difference between start state and goal state is
location of the desk.
• To reduce this difference, either PUSH or CARRY could be
chosen.
• If CARRY is chosen first, its preconditions must be met.
• This results in two more differences that must be reduced:
the location of the desk and the size of the desk.
• The location of the robot can be handled by applying WALK,
but there are no operators that can change the size of an
object (since we did’t include SAW-APART ). So this path
leads to dead end.

You might also like