Module 2 (3)
Module 2 (3)
• The process of looking for a sequence of actions that reaches the goal
is called search.
• A search algorithm takes a problem as input and returns a solution in
the form of an action sequence.
• Once a solution is found, the actions it recommends can be carried
out. This is called the execution phase.
• Thus, we have a simple “formulate, search, execute” design for the
agent
• In order for an agent to solve a problem it should pass by 2 phases of
formulation:
• Goal formulation, based on the current situation and the agent’s performance
measure, is the first step in problem solving.
3.1 PROBLEM-SOLVING AGENTS
3.1.1 Well-defined problems and solutions
• A problem can be defined formally by five components:
• The initial state that the agent starts in. For example, the initial state
for our agent in Romania might be described as In(Arad).
• A description of the possible actions available to the agent. Given a
particular state s, returns the set of actions that can be executed in s.
• A description of what each action does; the formal name for this is the
transition model, specified by a function RESULT(s, a) that returns the
state that results from SUCCESSOR doing action a in state s.
• RESULT(In(Arad),Go(Zerind)) = In(Zerind) .
• The goal test, which determines whether a given state is a goal state.
• A path cost function that assigns a numeric cost to each path.
Agent Assumptions
• Environment is observable
• Environment is discrete
• Environment is known
• Environment is deterministic
• The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as test
problems for new search algorithms in AI.
Standard formulation
• States: A state description specifies the location of each of the eight Ides and the blank
in one of the nine squares.
• Initial state: Any state can be designated as the initial state. Note that any given goal can
be reached.
• Actions: The simplest formulation defines the actions as movements of the blank space
Left, Right,Up, or Down. Different subsets of these are possible depending on where the
blank is.
• Transition model: Given a state and action, this returns the resulting state; for example,
if we apply Left to start state in Figure 3.4, the resulting state has the 5 and the blank
switched.
• Goal test: This checks whether the state matches the goal configuration shown in Figure
3.4. (Other goal configurations are possible.)
• Path cost: Each step costs 1, so the path cost is the number of steps in the path.
8-queens problem
• The goal of the 8-queens problem is to place eight queens on a chessboard such that no queen attacks any
other.
• it remains a useful test problem for search algorithms.
• There are two main kinds of formulation.
1. An incremental formulation involves operators that augment the state
description, starting with an empty state; for the 8-queens problem, this means that
each action adds a queen to the state.
2. A complete-state formulation starts with all 8 queens on the board and moves
them amend. In either case, the path cost is of no interest because only the final state
counts.
• Explores all the nodes at given depth before proceeding to the next level
• Uses Queue to implement
• Blind technique
• Brute force method
• Complete
• Time complexity
• The root node is expanded first
• then all the successors of the root node are expanded next, then their
successors, and so on.
• Achieved by FIFO – FRONTIER
• Then the total number of nodes generated is
• the memory requirements are a bigger problem for breadth-first search than is the execution time.
• If your problem has a solution at depth 16, then (given our assumptions) it will take about 350 years for
breadth-first search (or indeed any uninformed search) to find it.
Advantages of BFS
• Simplest strategy
• BFS is complete – If there is a solution, BFS is guaranteed to find it.
• If there are multiple solutions, then a minimal solution will be found.
Disadvantages of BFS
• The BFS cannot be effectively used unless the search space is quite
small.
Solve BFS
Uniform Cost Search
• An uninformed search algorithm in AI
• UCS uses the lowest cumulative cost to find a path from the source
node to the goal node.
• Nodes are expanded, starting from the root, according to the
minimum cumulative cost.
• The UCS is implemented using a Priority Queue.
• Insert the root node into the priority queue.
• Remove an element with the highest priority
• If removed node is the goal node, print total cost and stop the
algorithm
• Else, enqueue all the children of the current node to the priority
queue, with their cumulative cost from the root as priority.
Depth First Search
• DFS always expands the deepest node in the current frontier of the
search tree
• Stack (LIFO)
• Deepest Node
• Incomplete – no solution or infinite loop
• If the initial state is a goal state, quit and return success.
• Call DFS with E as the initial state, if success is returned, signal
success. Otherwise continue in this loop
• NODE LIST : A
• NODE LIST : B C
• The solution path A-B-C-D-G is returned and the algorithm
terminates.
Advantages of DFS
• DFS requires less memory since only the nodes on the current path
are stored.
• The DFS may find a solution without examining much of the search
space at all.
Disadvantages of DFS
• May find a sub-optimal solution
• Incomplete: without a depth bound, one may not fina a solution even
if one exists
• A variant of depth-first search called backtracking search uses
still 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.
• the idea of generating a successor by modifying the current state
description directly rather than copying it first.
• Robotic assembly – critical to success.
Depth Limited Search
• Time Complexity:
• Complete and Incomplete – so we choose BFS
3.4.6 Bidirectional search
3.4.7 Comparing uninformed search strategies