PAI (21AI54) Module 2 Notes
PAI (21AI54) Module 2 Notes
MODULE 2
Solving Problems by Searching
1. Problem Solving Agents
2. Example problems
3. Searching for Solutions
4. Uninformed Search Strategies
Introduction
➢ An important aspect of intelligence is goal-based problem solving.
➢ The solution of many problems can be described by finding a sequence of actions
that lead to a desirable goal.
➢ Each action changes the state and the aim is to find the sequence of actions and
states that lead from the initial (start) state to a final (goal) state.
➢ A well-defined problem can be described by:
1. Initial state
2. Operator or successor function - for any state x returns s(x), the set of states
reachable from x with one action.
3. State space - all states reachable from initial by any sequence of actions.
4. Path - sequence through state space.
5. Path cost - function that assigns a cost to a path. Cost of a path is the sum
of costs of individual actions along the path.
6. Goal test - test to determine if at goal state.
➢ Search is the systematic examination of states to find path from the start/root state
to the goal state.
Example Problems
➢ A toy problem is intended to illustrate various problem-solving methods. It can be
easily used by different researchers to compare the performance of algorithms.
➢ A real-world problem is one whose solutions people actually care about.
Toy Problems
1. Vacuum World:
➢ States: The state is determined by both the agent location and the dirt
locations. The agent is in one of two locations, each of which might or might
not contain dirt. Thus, there are 2 × 22 = 8 possible world states. A larger
environment with n locations has n · 2n states.
➢ Initial state: Any state can be designated as the initial state.
➢ Actions: In this simple environment, each state has just three actions: Left,
Right, and Suck. Larger environments might also include Up and Down.
2. The 8 – Puzzle:
➢ The 8-puzzle, an instance of which is shown in Figure 3.4, consists of a 3×3
board with eight numbered tiles and a blank space.
➢ A tile adjacent to the blank space can slide into the space.
➢ The objective is to reach a specified goal state, such as the one shown on
the right of the figure.
2. You have a program that outputs the message “illegal input record” when fed a certain
file of input records. You know that processing of each record is independent of the
other records. You want to discover what record is illegal.
States: Any combination/order of records.
Initial State: All input records.
Actions: Searching through records for the illegal record.
Transition Model: Dividing records up into parts and searching each part.
Goal Test: Finding the illegal record.
Path Cost: Amount of attempts.
4. You have three jugs, measuring 12 gallons, 8 gallons, and 3 gallons, and a water faucet.
You can fill the jugs up or empty them out from one to another or onto the ground. You
need to measure out exactly one gallon.
States: Any combination of filled/non-filled jugs.
Initial State: Jugs are empty.
Actions: Fill jugs up or transfer water between them.
Transition Model: Amount of water in each jug changes.
Goal Test: Is there exactly one gallon?
Path Cost: Number of actions.
States:
➢ Number of missionaries, cannibals and a boat on the banks of the river.
➢ Illegal states: Missionaries outnumbered by cannibals on either bank of the
river.
Initial State: All missionaries, cannibals and a boat on one side of the river.
➢ The set of all leaf nodes available for expansion at any given point is called the
frontier.
➢ The process of expanding nodes on the frontier continues until either a solution is
found or there are no more states to expand.
➢ Note that in the search tree shown in Figure 3.6: it includes the path from Arad to
Sibiu and back to Arad again!
➢ We say that In(Arad) is a repeated state in the search tree, generated in this case
by a loopy path.
➢ Considering such loopy paths means that the complete search tree for Romania is
infinite because there is no limit to how often one can traverse a loop.
➢ Notice how the PARENT pointers string the nodes together into a tree structure.
➢ These pointers also allow the solution path to be extracted when a goal node is
found.
➢ The frontier needs to be stored in such a way that the search algorithm can easily
choose the next node to expand according to its preferred strategy.
➢ The appropriate data structure for this is a queue.
➢ BFS is complete—if the shallowest goal node is at some finite depth d, breadth-first
search will eventually find it after generating all shallower nodes (provided the
branching factor b is finite).
➢ Note that as soon as a goal node is generated, we know it is the shallowest goal
node because all shallower nodes must have been generated already and failed the
goal test.
➢ Above table lists various values of the solution depth d, the time and memory
required for a breadth-first search with branching factor b = 10.
➢ The table assumes that 1 million nodes can be generated per second and that a node
requires 1000 bytes of storage.
➢ The successors of Sibiu are Rimnicu Vilcea and Fagaras, with costs 80 and 99,
respectively.
➢ The least-cost node, Rimnicu Vilcea, is expanded next, adding Pitesti with cost 80
+ 97 = 177.
➢ The least cost node is now Fagaras, so it is expanded, adding Bucharest with cost
99 + 211 = 310.
➢ Now a goal node has been generated, but uniform-cost search keeps going, choosing
Pitesti for expansion and adding a second path to Bucharest with cost 80+ 97+ 101
= 278.
➢ Now the algorithm checks to see if this new path is better than the old one; it is, so
the old one is discarded.
➢ Bucharest, now with g-cost 278, is selected for expansion and the solution is
returned.
➢ It is easy to see that uniform-cost search is optimal in general.
➢ First, we observe that whenever uniform-cost search selects a node n for expansion,
the optimal path to that node has been found.
➢ Then, because step costs are nonnegative, paths never get shorter as nodes are
added.
➢ Iterative deepening search may seem wasteful because states are generated multiple
times.
➢ It turns out this is not too costly.