Ai - Chapter 3
Ai - Chapter 3
What is Search?
Search is the systematic examination of states to find path from the start/root state to the goal state.
The set of possible states, together with operators defining their connectivity constitute the search space.
The output of a search algorithm is a solution, that is, a path from the initial state to a state that satisfies the
goal test.
To illustrate the agent’s behavior ,let us take an example where our agent is in the city of Arad,which is in
Romania. The agent has to adopt a goal of getting to Bucharest.
Goal formulation,based on the current situation and the agent’s performance measure,is the first step in
problem solving. The agent’s task is to find out which sequence of actions will get to a goal state.
Problem formulation is the process of deciding what actions and states to consider given a goal.
Search
An agent with several immediate options of unknown value can decide what to do by examining different
possible sequences of actions that leads to the states of known value,and then choosing the best sequence.
The process of looking for sequences actions from the current state to reach the goal state is called search.
The search algorithm takes a problem as input and returns a solution in the form of action sequence.
Once a solution is found,the execution phase consists of carrying out the recommended action..
Figure 2 shows a simple “formulate,search,execute” design for the agent. Once solution has been
executed,the agent will formulate a new goal.
function SIMPLE-PROBLEM-SOLVING-AGENT( percept) returns an action
inputs : percept, a percept
static: seq, an action sequence, initially empty
state, some description of the current world state
goal, a goal, initially null
problem, a problem formulation
state UPDATE-STATE(state, percept)
if seq is empty then do
goal FORMULATE-GOAL(state)
problem FORMULATE-PROBLEM(state, goal)
seq SEARCH( problem)
action FIRST(seq);
seq REST(seq)
return action
Figure 1 A Simple problem solving agent. It first formulates a goal and a problem,searches for
a sequence of actions that would solve a problem,and executes the actions one at a time.
An agent carries out its plan with eye closed. This is called an open loop system because ignoring the
percepts breaks the loop between the agent and the environment.
State Space : The set of all states reachable from the initial state. The state space forms a graph
in which the nodes are states and the arcs between nodes are actions.
A path in the state space is a sequence of states connected by a sequence of actions.
Thr goal test determines whether the given state is a goal state.
A path cost function assigns numeric cost to each action. For the Romania problem the cost of
path might be its length in kilometers.
The step cost of taking action a to go from state x to state y is denoted by c(x,a,y). The step cost
for Romania are shown in figure 1.18. It is assumed that the step costs are non negative.
A solution to the problem is a path from the initial state to a goal state.
An optimal solution has the lowest path cost among all solutions.
Figure 2 A simplified Road Map of part of Romania
o States: The agent is in one of two locations.,each of which might or might not contain dirt. Thus
there are 2 x 22 = 8 possible world states.
o Initial state: Any state can be designated as initial state.
o Successor function : This generates the legal states that results from trying the three actions (left,
right, suck). The complete state space is shown in figure 2.3
o Goal Test : This tests whether all the squares are clean.
o Path test : Each step costs one ,so that the the path cost is the number of steps in the path.
Vacuum World State Space
Figure 3 The state space for the vacuum world. Arcs denote actions: L = Left,R = Right,S = Suck
ROUTE-FINDING PROBLEM
Route-finding problem is defined in terms of specified locations and transitions along links between them.
Route-finding algorithms are used in a variety of applications,such as routing in computer networks,military
operations planning,and air line travel planning systems.
SEARCH TREE
Having formulated some problems,we now need to solve them. This is done by a search through the state
space. A search tree is generated by the initial state and the successor function that together define the
state space. In general,we may have a search graph rather than a search tree,when the same state can be
reached from multiple paths.
Figure 2 shows some of the expansions in the search tree for finding a route from Arad to Bucharest.
Figure 4 Partial search trees for finding a route from Arad to Bucharest. Nodes that have been
expanded are shaded.; nodes that have been generated but not yet expanded are outlined in
bold;nodes that have not yet been generated are shown in faint dashed line
The root of the search tree is a search node corresponding to the initial state,In(Arad). The first step is to
test whether this is a goal state. The current state is expanded by applying the successor function to the
current state,thereby generating a new set of states. In this case,we get three new states:
In(Sibiu),In(Timisoara),and In(Zerind). Now we must choose which of these three possibilities to consider
further. This is the essense of search- following up one option now and putting the others aside for latter,in
case the first choice does not lead to a solution.
Search strategy . The general tree-search algorithm is described informally in Figure 1.24
.
Tree Search
The choice of which state to expand is determined by the search strategy. There are an infinite number
paths in this state space ,so the search tree has an infinite number of nodes.
A node is a data structure with five components :
o STATE : a state in the state space to which the node corresponds;
o PARENT-NODE : the node in the search tree that generated this node;
o ACTION : the action that was applied to the parent to generate the node;
o PATH-COST :the cost,denoted by g(n),of the path from initial state to the node,as indicated by
the parent pointers; and
o DEPTH : the number of steps along the path from the initial state.
It is important to remember the distinction between nodes and states. A node is a book keeping data
structure used to represent the search tree. A state corresponds to configuration of the world.
Fringe - Fringe is a collection of nodes that have been generated but not yet been expanded. Each element
of the fringe is a leaf node, that is a node with no successors in the tree. The fringe of each tree consists of
those nodes with bold outlines. The collection of these nodes is implemented as a queue.
The general tree search algorithm is shown in Figure.
Strategies that know whether one non goal state is “more promising” than another are called Informed
search or heuristic search strategies.
1. Breadth-first search
Breadth-first search is a simple strategy in which the root node is expanded first,then all successors of the
root node are expanded next,then 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.
Figure 7 Breadth-first search on a simple binary tree. At each stage , the node to be expanded next
is indicated by a marker.
2. Uniform-Cost Search
Instead of expanding the shallowest node, uniform-cost search expands the node n with the lowest path
cost. uniform-cost search does not care about the number of steps a path has, but only about their total cost.
3. Depth-First-Search
Depth-first-search always expands the deepest node in the current fringe of the search tree. The progress of
the search is illustrated in figure. The search proceeds immediately to the deepest level of the search
tree,where the nodes have no successors. As those nodes are expanded, they are dropped from the fringe,so
then the search “backs up” to the next shallowest node that still has unexplored successors.
Figure 8 Depth-first-search on a binary tree. Nodes that have been expanded and have no
descendants in the fringe can be removed from the memory;these are shown in black. Nodes at
depth 3 are assumed to have no successors and M is the only goal node.
This strategy can be implemented by TREE-SEARCH with a last-in-first-out (LIFO) queue,also known as a
stack.
4 Depth-Limited-Search
The problem of unbounded trees can be alleviated by supplying depth-first-search with a pre-determined
depth limit l.That is,nodes at depth l are treated as if they have no successors. This approach is called depth-
limited-search. The depth limit soves the infinite path problem.
Depth-limited search = depth-first search with depth limit l,returns cut off if any path is cut off by depth
limit.
5. Iterative Deepening Depth-First Search
Iterative deepening search (or iterative-deepening-depth-first-search) is a general strategy often used in
combination with depth-first-search,that finds the better depth limit. It does this by gradually increasing the
limit – first 0,then 1,then 2, and so on – until a goal is found. This will occur when the depth limit reaches
d,the depth of the shallowest goal node. Iterative deepening combines the benefits of depth-first and breadth-
first-search
In general,iterative deepening is the prefered uninformed search method when there is a large search space
and the depth of solution is not known.
6. Bidirectional Search
The idea behind bidirectional search is to run two simultaneous searches – one forward from he initial state
and the other backward from the goal, stopping when the two searches meet in the middle.
The motivation is that bd/2 + bd/2 much less than ,or in the figure ,the area of the two small circles is less than
the area of one big circle centered on the start and reaching to the goal.
Repeated states ,can cause a solvable problem to become unsolvable if the algorithm does not detect them.
Repeated states can be the source of great inefficiency: identical sub trees will be explored many times.
Figure 11