3.
1 PROBLEM SOLVING AGENTS
When the correct action to take is not immediately obvious, an
agent may need to plan ahead: to consider a sequence of
actions that form a path to a goal state. Such an agent is called
a problem-solving agent, and the computational process
it undertakes is called search.
SEARCH PROBLEMS AND SOLUTIONS
Problem Formulation
1. Initial State: The initial state is A
2. Actions: From A the applicable actions are
{ Go (B,D,E) }
3. Successor Function: Result = ( In (A) , Go(B))= In(B)
4. Goal State: The agents goal state is { In(M) }
5. Path Cost : Distance between two nodes is the path
cost.
FORMULATION PROBLEMS
The process of removing detail from a representation is
called abstraction. A good problem formulation has the
right level of detail.
The choice of a good abstraction thus involves removing
as much detail as possible while retaining validity and
ensuring that the abstract actions are easy to carry out.
3.2 EXAMPLE PROBLEMS
A grid world problem is a two-dimensional rectangular array of square
cells in which agents can move from cell to cell. Typically, the agent can
move to any obstacle-free adjacent cell — horizontally or vertically and in
some problems diagonally. Cells can contain objects, which the agent can
pick up, push, or otherwise act upon; a wall or other obstacle in a cell
prevents an agent from moving into that cell.
FORMULATING THE VACUUM WORLD PROBLEM
States : The State is determined by both the agent location and dirt locations. The agent is in
one of the two locations, each of which might or might not contain dirt.
- possible states = 2 * 2 ^2 = 8 ( n * 2 ^ n )
1. Initial State: Any state may be designated as initial state
2. Actions : Three Actions Left , Right , Suck / Clean
3. Transition Model : The Actions have expected effects , except that moving left in leftmost
square , moving right in rightmost square and cleaning in a cleaned room has no effect.
4. Goal Test : Check whether all the squares are clean
5. Path Cost : Each Steps costs 1 , so the path cost is number of steps in the path.
8 PUZZLE
8-Puzzle Online
3x3 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.
8 PUZZLE
8-Puzzle Online
3x3 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.
States: Location of each of the eight tiles and the blank in
one of the nine squares.
Initial State: Any State
Actions: Movement of the blank space Up, Down , Left or
Right.
Transition Model: Given a state and action , it results in
the resulting state.
Goal Test: Checks whether the state matches the goal
configuration
Path Cost: Each Steps Costs 1. Path Cost is the number of
steps in the path.
REAL WORLD PROBLEMS
Route Finding Problems are common in Real world.
Consider the airline travel problem that must be solved by a travelling
plan website:
States : Each State includes a location ( e.g. : an airport ) and the current time
Initial State : Specified by user's query
Actions : Take any flight from current location , in any seat class , leaving after
current time, leaving enough time for within airport transfer if needed.
Transition Model : The state resulting from taking a flight will have flights
destination as the current location and flights arrival time as the current time.
Goal Test : Are we at the final destination specified by the user ?
Path Cost : Depends on the monetary cost , waiting time , flight time , customs
and immigration procedures , seat quality , time of the day , type of airplane ,
frequent flyer mileage awards etc.
REAL WORLD PROBLEMS.
Touring Problems are slightly different from route finding problems
Ex: An Agent wants to visit every species of animals at the St. Louis Zoo at
least once , starting and ending at the snake house near the south entrance
The State Space is different – each state must include not just the current
location but also the set of cities or places the agent has visited.
Agents initial state would be In ( Snake-House ) , Visited ( { Snake House } )
A typical intermediate state would be
In ( Giraffe House ) , Visited({Snake House , Primate House , Giraffe House })
The Goal test is also different
Check whether the agent is in Snake – House and whether all the animal
houses are visited or not.
3.3 SEARCH ALGORITHMS
Concept of State Space : = { “All Possible Configurations”}
WHAT EXACTLY IS ‘SEARCHING FOR SOLUTION’ ?
A Solution is an action sequence
Search algorithms work by considering various action sequences.
The Possible action sequences , starting at the initial state form a search tree with
- the initial state at the root
- the branches are the actions and
- the nodes correspond to states in the state space of the problem.
Each of the six node is a leaf node
A node with no children in the tree
The set of all leaf nodes available for expansion at any
given point is called the frontier
Tree consist of those nodes with bold outlines
DATA STRUCTURES TO KEEP TRACK OF THE SEARCH TREE
Search algorithms require a data structure to keep track of the search tree that is being
constructed.
MEASURING PROBLEM-SOLVING PERFORMANCE
We can evaluate an algorithm’s performance in four ways:
• Completeness: Is the algorithm guaranteed to find a
solution when there is one, and to Completeness correctly
report failure when there is not ?
• Cost optimality: Does it find a solution with the lowest
path cost of all solutions ?
• Time complexity: How long does it take to find a solution
? This can be measured in seconds, or more abstractly by
the number of states and actions considered.
• Space complexity: How much memory is needed to
perform the search ?
3.4 UNINFORMED SEARCH
STRATEGIES
An uninformed search algorithm is given no clue
about how close a state is to the goal(s).
For example, consider our agent in Arad with the
goal of reaching Bucharest.
An uninformed agent with no knowledge of
Romanian geography has no clue whether going to
Zerind or Sibiu is a better first step.
Whereas informed agent who knows the location of
each city likely to find the shortest path.
3.4.1 BREADTH-FIRST SEARCH
When all actions have the same cost, an appropriate strategy is breadth-
first search, in which the root node is expanded first, then all the successors
of the root node are expanded next, then their successors, and so on.
BFS uses a queue data structure to keep track of the vertices that need to
be explored next. BFS is useful in finding the shortest path between two
vertices in an unweighted graph and can also be used to detect cycles in a
graph.
3.4.1 BREADTH-FIRST SEARCH
3.4.1 BREADTH-FIRST SEARCH
3.4.1 BREADTH-FIRST SEARCH
APPLICATIONS OF BFS
1.
Bittorrent application uses peer to peer connection
2. Crawlers in Search Engines use BFS to build an index.
3. In social networking websites, BFS can find people within a given distance ‘k’ from
a person by traversing ‘k’ levels.
4. GPS Navigation systems use BFS to find all neighboring locations.
5. Broadcasting in networks uses BFS to reach all nodes.
6. BFS can be used to find if there is a path between two vertices.
3.4.1 BREADTH-FIRST SEARCH
Advantages of BFS:
1. Used to find the shortest path between states.
2. Always finds optimal solutions.
3. There is nothing like useless path in BFS, since it searches level by
level.
4. Finds the closest goal state in less time.
Disadvantages of BFS:
1. All the connected vertices must be stored in memory. So consumes
more memory
3.4.3 DEPTH-FIRST SEARCH AND THE PROBLEM OF MEMORY
Depth-first search always expands the deepest node in the
frontier first.
Search proceeds immediately to the deepest level of the
search tree, where the nodes have no successors.
The search then “backs up” to the next deepest node that still
has unexpanded successors.
Depth-first search is not cost-optimal , it returns the first
solution it finds, even if it is not cheapest.
It uses last in- first-out strategy and hence it is implemented
using a stack.
APPLICATION OF DEPTH FIRST
SEARCH
Cycle detection: DFS can be used to detect cycles in
a graph. If a node is visited again during a DFS
traversal, it indicates that there is a cycle in the
graph.
Solving puzzles: DFS can be used to solve puzzles
such as mazes, where the goal is to find a path from
the start to the end.
Backtracking: DFS can be used for backtracking in
algorithms like the N-Queens problem or Sudoku.
ADVANTAGES OF DEPTH FIRST SEARCH
Depth-First Search uses a memory allocation proportional to the search graph's size.
Depth-First Search is not guaranteed to find the solution and there is no guarantee to find a
minimal solution, if more than one solution.
A variant of depth-first search called backtracking search uses even less memory.
In backtracking, only one successor is generated at a time rather than all successors each
partially expanded node remembers which successor to generate next.
we must be able to undo each action when we backtrack. Backtracking is critical to the success
of many problems with large state descriptions, such as robotic assembly