Module 2
Module 2
Module 2
Problem Solving
3.1 Problem Solving Agents
The reflex agents are known as the simplest agents because they directly map states into
actions. Unfortunately, these agents fail to operate in an environment where the mapping is
too large to store and learn.
Goal-based agent, on the other hand, considers future actions and the desired outcomes.
Here, we will discuss one type of goal-based agent known as a problem-solving agent,
which uses atomic representation with no internal states visible to the problem-solving
algorithms.
Goal Formulation: It is the first and simplest step in problem-solving. It organizes the
steps/sequence required to formulate one goal out of multiple goals as well as actions to
achieve that goal. Goal formulation is based on the current situation and the agent’s
performance measure (discussed below)
Problem Formulation: It is the most important step of problem-solving which decides what
actions should be taken to achieve the formulated goal.
The problem solving agent selects a cost function, which reflects its performance measure.
Remember, an optimal solution has the lowest path cost among all the solutions.
Page 1
Module2
Search: It identifies all the best possible sequence of actions to reach the goal state from the
current state. It takes a problem as an input and returns solution as its output.
Solution: It finds the best algorithm out of various algorithms, which may be proven as the
best optimal solution.
Execution: It executes the best optimal solution from the searching algorithms to reach the
goal state from the current state.
1. Toy Problem: It is a concise and exact description of the problem which is used by the
researchers to compare the performance of algorithms.
2. Real-world Problem: It is real-world based problems which require solutions. Unlike a toy
problem, it does not depend on descriptions, but we can have a general formulation of the
problem
Agent Design
Environment Assumptions
Static, formulating and solving the problem is done without paying attention to any
changes that might be occurring in the environment.
• Initial state is known and the environment is observable.
• Discrete, enumerate alternative courses of actions.
• Deterministic, solutions to problems are single sequences of actions, so they cannot handle
any unexpected events, and solutions are executed without paying attention to the percepts.
Page 2
Module2
Page 3
Module2
2 . 8- Puzzle Problem
Page 4
Module2
3. 8-queens problem
states: each is represented by a location (e.g. An airport) and the current time.
• Initial state: specified by the problem.
• Successor function: returns the states resulting from taking any scheduled flight, leaving later than
the current time plus the within airport transit time, from the current airport to another.
• goal test: are we at the destination by some pre-specified time.
• Path cost: monetary cost, waiting time, flight time, customs and immigration procedures, seat
quality, time of day, type of airplane, frequent-flyer mileage awards, etc.
• Route finding algorithms are used in a variety of applications, such as routing in computer
networks, military operations planning, airline travel planning systems.
There are many ways to represent nodes, but we will assume that a node is data structure with five
components:
1. State: the state in the state space to which the node corresponds.
2. Parent-node: the node in the search tree that generated this node.
Page 5
Module2
3. Action: the action that was applied to the parent to generate the node.
4.Path-cost: the cost, traditionally denoted by g(n), of the path from the initial state to the node, as
indicated by the parent pointers.
5. Depth: the number of steps along the path from the initial state.
Page 6
Module2
State VS Node
Fringe: The collection of nodes that have been generated but not yet been expanded
• Each element of a fringe is a leaf node, a node with no successors.
Search strategy: A function that selects the next node to be expanded from fringe
• We assume that the collection of nodes is implemented as a queue.
Types of Search
1. Uninformed (Blind) Search
2. Informed ( Heuristic)Search
Uninformed search (blind search) strategies use only the information available in the problem
definition.
1. Breadth-first search.
The root node is expanded first, then all the successors of the root node, and their successors and so
on.
In general, all the nodes are expanded at a given depth in the search tree before any nodes at the
next level are expanded. Expand shallowest unexpanded node.
• Implementation:
fringe is a FIFO queue,
the nodes that are visited first will be expanded first
Page 8
Module2
All newly generated successors will be put at the end of the queue
Shallow nodes are expanded before deeper nodes
Example
Page 9
Module2
Exponential-complexity search problems cannot be solved by uniformed methods for any but the
smallest instances.
Advantages:
BFS will provide a solution if any solution exists.
If there are more than one solutions for a given problem, then BFS will provide the minimal
solution which requires the least number of steps.
Disadvantages:
It requires lots of memory since each level of the tree must be saved into memory to expand
the next level.
BFS needs lots of time if the solution is far away from the root node.
2. Uniform-cost search
Uniform cost search can be used if the cost of travelling from one node to another is available.
Breadth first Search finds the shallowest goal but it’s not always sure to find the optimal solution.
Uniform cost search always expands the lowest cost node on the fringe (the collection of nodes t hat
are waiting to be expanded. The first solution is guaranteed to be the cheapest one because a
cheaper one is expanded earlier and so would have been found first.
O(bceil(C*/ ε))
3. Space
O(bceil(C*/ ε))
4.Optimal
Yes, Nodes are expanded in increasing order
Advantages:
Uniform cost search is optimal because at every state the path with the least cost is chosen.
Disadvantages:
Page 10
Module2
It does not care about the number of steps involve in searching and only concerned about
path cost. Due to which this algorithm may be stuck in an infinite loop.
3. Depth-First Search
It always expands the deepest node in the fringe. After reaching the deepest level, it backs up the
next deepest node that still has unexplored successors. It can be implemented by TREE-SEARCH
with a last-in-first-out (LIFO) queue.
Example:
Page 11
Module2
Properties:
1.Complete
No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated spaces along path
Yes: in finite spaces
2. Time
O(bm)
Not great if m is much larger than d
But if the solutions are dense, this may be faster than breadth-first search
3. Space
O(bm)…linear space
Optimal
No
Advantages:
DFS requires very less memory as it only needs to store a stack of the nodes on the path from root
node to the current node.
It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right path).
Disadvantages:
There is the possibility that many states keep re-occurring, and there is no guarantee of
finding the solution.
DFS algorithm goes for deep down searching and sometime it may go to the infinite loop.
4. Depth-Limited Search
A depth-limited search algorithm is similar to depth-first search with a predetermined limit. Depth-
limited search can solve the drawback of the infinite path in the Depth-first search. In this
algorithm, the node at the depth limit will treat as it has no successor nodes further.
Page 12
Module2
1.Standard failure value: It indicates that problem does not have any solution.
2.Cutoff failure value: It defines no solution for the problem within a given depth limit.
Example
The problem of unbounded tree can be alleviated supplying DFS with a depth limit l.
Properties:
Unfortunately, it introduces an additional source of incompleteness if l < d.
It is nonoptimal if l > d .
1 .Time complexity: O(b l )
Page 13
Module2
Advantages:
Depth-limited search is Memory efficient.
Disadvantages:
Depth-limited search also has a disadvantage of incompleteness.
It may not be optimal if the problem has more than one solution.
Algorithm:
Example
Page 14
Module2
Properties:
1.Complete: Yes
2.Time: O(bd )
3.Space: O(bd)
4.Optimal: Yes if step cost = 1
Can be modified to explore uniform cost tree
Advantages: It combines the benefits of BFS and DFS search algorithm in terms of fast search and
memory efficiency.
Disadvantages: The main drawback of IDDFS is that it repeats all the work of the previous phase.
6. Bidirectional search
Bidirectional search algorithm runs two simultaneous searches, one form initial state called
as forward-search and other from goal node called as backward-search, to find the goal
node.
Bidirectional search replaces one single search graph with two small subgraphs in which one
starts the search from an initial vertex and other starts from goal vertex. The search stops
when these two graphs intersect each other.
Properties:
Whether the algorithm is complete/optimal depends on the search strategies in both searches.
Page 15
Module2
1. Time complexity: O(b d/2 ) (Assume BFS is used) Checking node for membership in the other
search tree can be done in constant time.
2.Space complexity: O(b d/2 ) (Assume BFS is used)
At least one of the search tree must be kept in memory for membership checking.
3. Optimal: Bidirectional search is Optimal.
Advantages:
Bidirectional search is fast.
Page 16