Lecture - 7 - 10
Lecture - 7 - 10
• Problems can range from simple to complex, and AI aims to develop algorithms and techniques that
allow computers or intelligent agents to solve these problems effectively.
• Problems can be diverse and come from various domains, such as puzzle-solving, optimization,
planning, decision-making, and more.
• Examples of problems include finding the shortest path between two locations on a map, solving a
Sudoku puzzle, scheduling tasks to minimize costs, playing a game, or diagnosing a medical condition.
Problem Solving
• Problem solving is a process of generating solutions from observed data.
• To solve the problem of building a system you should take the following steps:
1. Define the problem accurately including detailed specifications and what constitutes a suitable
solution.
2. Scrutinize the problem carefully, for some features may have a central affect on the chosen method
of solution.
3. Segregate and represent the background knowledge needed in the solution of the problem.
4. Choose the best solving techniques for the problem to solve a solution.
The 8-puzzle
search space
consists of 8!
states (40320)
Example: n queens
• State space: configurations from 0 to n queens on the board with only one queen per row and column
• Initial state: configuration without queens on the board
• Goal state: configuration with n queens such that no queen attacks any other
• Operators or actions: place a queen on the board
• Condition: the new queen is not attacked by any other already placed
• Transformation: place a new queen in a particular square of the board
• Solution: one solution (cost is not considered)
• Homework:
• Missionaries and Cannibals Problem
• Monkey & Bananas Problem
Example: 5 queens
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Characteristics of a Problem
1. Well-Defined Goal: A problem should have a clear and well-defined goal or objective that the AI system
aims to achieve. The goal provides a target for the solution-seeking process.
2. Initial State: The problem typically starts from a specific initial state or condition. This initial state
represents the starting point from which the AI system begins its search or reasoning process.
3. Set of Actions: Problems involve a set of possible actions that can be taken by the AI system to move
from one state to another. These actions represent the decisions or steps that the system can make to
progress toward the goal.
4. Transition Model: The transition model specifies how the state changes when an action is taken. It
defines the relationship between different states and the actions that lead from one state to another.
5. Constraints: Many problems come with constraints or limitations that the solution must adhere to.
These constraints may include resource limitations, logical rules, or domain-specific requirements.
6. Multiple Solutions: Some problems may have multiple valid solutions, and the AI system needs to
identify and evaluate different options.
Characteristics of a Problem
7. Optimality Criteria: Problems often have criteria for determining the optimality of a solution. These
criteria can be related to minimizing or maximizing certain factors, such as cost, time, distance, or utility.
8. Search Space: The set of all possible states and actions that can be explored to reach a solution is known as
the search space. The size and structure of the search space influence the complexity of the problem-
solving process.
9. Complexity: The complexity of a problem can be measured in terms of factors like the size of the search
space, the number of possible actions, and the difficulty of finding a solution. Complex problems may
require advanced AI techniques to solve effectively.
10. Uncertainty: Some problems involve uncertainty or incomplete information. The AI system may need to
make decisions under uncertainty and consider probabilistic outcomes.
11. Heuristics and Domain Knowledge: Heuristics are problem-solving strategies or rules of thumb that guide
the AI system's decision-making process. Domain knowledge refers to specific information about the
problem domain that can aid in finding solutions.
Characteristics of a Problem
12. Interactions and Dependencies: Problems may involve interactions and dependencies between
different components or variables. Understanding these interactions is crucial for accurate decision-
making.
13. Dynamic Nature: Certain problems involve dynamic environments where conditions change over
time. The AI system needs to adapt to these changes to maintain effectiveness.
14. Scalability: Scalability refers to the ability of the problem-solving approach to handle larger or more
complex instances of the problem.
• The characteristics of a problem guide the selection of appropriate AI techniques and algorithms for
solving it. Analyzing these characteristics helps AI researchers and practitioners determine the most
effective strategies to tackle the challenges posed by the problem.
Problem Solving Techniques in AI
• Search Algorithms:
• Breadth-First Search (BFS): Explores neighboring states before deeper levels of the search tree.
• Depth-First Search (DFS): Explores as far as possible along a branch before backtracking.
• A* Search: Combines the advantages of BFS and heuristic-driven search to find optimal paths.
• Iterative Deepening Search: Gradually increases the depth limit of DFS to balance efficiency and optimality.
• Greedy Best-First Search: Selects the most promising state based on a heuristic function.
• Heuristic Methods:
• Heuristic functions provide estimates of how close a state is to the goal. They guide search algorithms by
evaluating potential states.
• Hill Climbing: Moves toward the best neighboring state based on a heuristic function.
• Simulated Annealing: Allows occasional uphill moves to escape local optima by gradually reducing the
acceptance of worse solutions.
• Genetic Algorithms: Utilizes principles of natural selection to evolve a population of solutions over generations.
Problem Solving Techniques in AI
• Constraint Satisfaction Problems (CSPs):
• CSPs involve finding solutions that satisfy a set of constraints.
• Backtracking: Systematically explores possible solutions, backtracking when constraints are violated.
• Constraint Propagation: Infers constraints from the relationships between variables.
• Adversarial Search and Game Playing:
• Minimax Algorithm: Used in two-player games to find optimal strategies by considering the opponent's moves.
• Alpha-Beta Pruning: Optimizes the minimax algorithm by eliminating branches that are guaranteed to lead to
worse outcomes.
• Planning Algorithms:
• Generate sequences of actions to achieve a goal within a given set of constraints.
• STRIPS (Stanford Research Institute Problem Solver): Formalizes planning problems as a series of states and
actions.
• Partial Order Planning: Considers the order of events while allowing flexibility in non-interfering actions.
Problem Solving Techniques in AI
• Reinforcement Learning:
• Agents learn to take actions to maximize cumulative rewards in an environment.
• Q-Learning: Learns an action-value function that guides decision-making based on expected future rewards.
• Deep Q Networks (DQN): Combines Q-learning with deep neural networks for more complex problems.
• Expert Systems:
• Utilize human expertise and knowledge to solve complex problems in specific domains.
• Rule-Based Systems: Represent knowledge as a set of IF-THEN rules to make inferences.
• Optimization Algorithms:
• Solve optimization problems by finding the best possible solution within a given set of constraints.
• Genetic Algorithms: Evolve solutions by mimicking the process of natural selection.
• Simulated Annealing: Gradually explores the solution space while avoiding getting trapped in local optima.
• Case-Based Reasoning:
• Solves new problems by adapting solutions from similar past problems stored in a case library.
Problem Solving Techniques in AI
• Fuzzy Logic:
• Handles uncertainty and imprecision by allowing degrees of truth between true and false.
• Neural Networks and Deep Learning:
• Neural networks are used for pattern recognition, function approximation, and decision-making.
• These problem-solving techniques are often tailored to specific problem domains and scenarios.
• AI practitioners choose and adapt these techniques based on the nature of the problem, available data,
computational resources, and desired outcomes.
• The evolution of AI continues to bring new techniques and approaches, enabling more efficient and
effective problem-solving across various domains.
Some More Terms
• Solution : a sequence of actions that leads from the initial state to a goal state.
• Optimal Solution : a solution that has the lowest path cost among all solutions.
• Goal Test : way to determine whether a given state is a goal state.
• Path Cost : numerical cost associated with a given path.
• Node : a data structure that keeps track of
• a state
• a parent (node that generated this node)
• an action (action applied to parent to get node)
• a path cost (from initial state to node)
Search Strategy
• Many (all?) AI problems can be formulated as search problems!
• A search strategy is defined by picking the order of node expansion.
• Strategies are evaluated along the following dimensions:
• completeness: does it always find a solution if one exists?
• time complexity: number of nodes generated
• space complexity: maximum number of nodes in memory
• optimality: does it always find a least-cost solution?
• systematicity: does it visit each state at most once?
• Time and space complexity are measured in terms of
• b:maximum branching factor of the search tree
• d: depth of the least-cost solution
• m: maximum depth of the state space (may be ∞)
Search Strategies - Types
• Uninformed Search : strategies use only the information (action) available in the problem definition. It
does not use problem specific knowledge.
Examples:
• Breadth-first search; Depth-first search; Depth-limited search; Iterative deepening search; Beam Search
• Informed Search : search strategy that uses problem-specific knowledge to find solutions more
efficiently. Also known as Heuristic Search.
Examples:
• Generate and Test search; Hill Climbing; Best-first search; Greedy best-first search; A* search; Depth
first branch & bound search; Simulated Annealing
Approach of Search
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
E D
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
What could go
wrong?
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
A C
D
C D
E
F
Find a path from A to E. A
B
Frontier
D C D
• A B A B…
stack
last-in first-out data type
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
B E
F
Find a path from A to E. A
B
Frontier
C D
C D
Explored Set
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A D
B E
F
Find a path from A to E. A
B
Frontier
C F
C D
Explored Set
A D
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A D F
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A D F C
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A D F C
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A D F C
B E
F
This is known as :
• Time Complexity? : O(bm) In worst case, It is equal to the search tree size.
• Space Complexity? : O(bm) In worst case, Maximum Length of the tree (m)
and no. of children for each node (b)
Let’s use another simple data structure for adding or
removing a node :
queue
first-in first-out data type
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
B E
F
Find a path from A to E. A
B
Frontier
C D
C D
Explored Set
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A C
B E
F
Find a path from A to E. A
B
Frontier
D E
C D
Explored Set
A C
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A C D
B E
F
Find a path from A to E. A
B
Frontier
E F
C D
Explored Set
A C D
B E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A C D
B E
F
This is known as :
• Time Complexity? : O(bd) In any case, It is equal to the solution length only.
• Space Complexity? : O(bd) In any case, we must maintain the full frontier. Length
till the solution (d) and no. of children for each node (b)
• Optimal? : Yes If step cost is equal for all or ONE (1).
• Let’s See both strategies in visual representation.
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Aspect Depth First Search (DFS) Breadth First Search (BFS)
Traversal Explores as deeply as possible along each branch before Explores all neighbors before moving to the next
Order backtracking. level.
Used in topological sorting, finding connected Suitable for shortest path finding, analyzing social
Applications
components, cycle detection, maze problems. networks, puzzle solving.
The Problem
• All these uninformed methods / strategies are slow (Because all are blind).
• Solution ???