0% found this document useful (0 votes)
61 views10 pages

Ai - Chapter 3

This document discusses problem solving by search. It defines key concepts like the initial state, successor function, state space, path cost and goal test used to formally define problems. Search involves systematically examining states to find a path from the start to goal state. The document provides examples of toy problems like vacuum world and real-world problems like route finding. It describes generating a search tree from the initial state and successor function and how search strategies determine which nodes to expand first in searching for a solution.

Uploaded by

sale msg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views10 pages

Ai - Chapter 3

This document discusses problem solving by search. It defines key concepts like the initial state, successor function, state space, path cost and goal test used to formally define problems. Search involves systematically examining states to find a path from the start to goal state. The document provides examples of toy problems like vacuum world and real-world problems like route finding. It describes generating a search tree from the initial state and successor function and how search strategies determine which nodes to expand first in searching for a solution.

Uploaded by

sale msg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CHAPTER 3

SOLVING PROBLEMS BY SEARCHING AND CONSTRAINT SATISFACTION PROBLEM


1. Avoiding Repeated States
2. Constraint Satisfaction Search
3. Games as Search Problems

3.1 Problem Solving by Search


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:


 Initial state
 Operator or successor function - for any state x returns s(x), the set of states reachable from x with
one action
 State space - all states reachable from initial by any sequence of actions
 Path - sequence through state space
 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
 Goal test - test to determine if at goal state

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.

3.2 Problem-solving agents


A Problem solving agent is a goal-based agent . It decide what to do by finding sequence of actions that lead
to desirable states. The agent can adopt a goal and aim at satisfying it.

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.

Well-defined problems and solutions

A problem can be formally defined by four components:


 The initial state that the agent starts in. The initial state for our agent of example problem is
described by In(Arad)
 A Successor Function returns the possible actions available to the agent. Given a state
x,SUCCESSOR-FN(x) returns a set of {action,successor} ordered pairs where each action is one of
the legal actions in state x, and each successor is a state that can be reached from x by applying the
action.
For example,from the state In(Arad),the successor function for the Romania problem would return
{ [Go(Sibiu),In(Sibiu)],[Go(Timisoara),In(Timisoara)],[Go(Zerind),In(Zerind)] }

 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

3.3 EXAMPLE PROBLEMS


The problem solving approach has been applied to a vast array of task environments. Some best known
problems are summarized below. They are distinguished as toy or real-world 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.

3.3.1 TOY PROBLEMS

Vacuum World Example

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

3.3.2 REAL-WORLD PROBLEMS

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.

AIRLINE TRAVEL PROBLEM


The airline travel problem is specifies as follows :
o States : Each is represented by a location(e.g.,an airport) and the current time.
o Initial state : This is specified by the problem.
o Successor function : This returns the states resulting from taking any scheduled flight(further
specified by seat class and location),leaving later than the current time plus the within-airport transit
time,from the current airport to another.
o Goal Test : Are we at the destination by some prespecified time?
o Path cost : This depends upon the monetary cost,waiting time,flight time,customs and immigration
procedures,seat quality,time of dat,type of air plane,frequent-flyer mileage awards, and so on.

3.4 SEARCHING FOR SOLUTIONS

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

Figure 5 An informal description of the general tree-search algorithm

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.

Figure 6 The general Tree search algorithm

MEASURING PROBLEM-SOLVING PERFORMANCE


The output of problem-solving algorithm is either failure or a solution.(Some algorithms might struck in
an infinite loop and never return an output.
The algorithm’s performance can be measured in four ways :
o Completeness : Is the algorithm guaranteed to find a solution when there is one?
o Optimality : Does the strategy find the optimal solution
o Time complexity : How long does it take to find a solution?
o Space complexity : How much memory is needed to perform the search?

3.4.1 UNINFORMED SEARCH STRATGES


Uninformed Search Strategies have no additional information about states beyond that provided in the
problem definition.

Strategies that know whether one non goal state is “more promising” than another are called Informed
search or heuristic search strategies.

There are five uninformed search strategies as given below.


o Breadth-first search
o Uniform-cost search
o Depth-first search
o Depth-limited search
o Iterative deepening search

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.

Breath-first-search is implemented by calling TREE-SEARCH with an empty fringe that is a first-in-first-


out(FIFO) queue,assuring that the nodes that are visited first will be expanded first.

In otherwards,calling TREE-SEARCH(problem,FIFO-QUEUE()) results in breadth-first-search.


The FIFO queue puts all newly generated successors at the end of the queue,which means that
Shallow nodes are expanded before deeper nodes.

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 can be implemented as a simple modification to the general tree-search algorithm or to


the recursive depth-first-search algorithm. It can be noted that the above algorithm can terminate with two
kinds of failure : the standard failure value indicates no solution; the cutoff value indicates no solution within
the depth limit.

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

Figure 9 Four iterations of iterative deepening search on a binary tree

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.

Figure 10 A schematic view of a bidirectional search that is about to succeed,when a


Branch from the Start node meets a Branch from the goal node.

3.5 AVOIDING REPEATED STATES


In searching,time is wasted by expanding states that have already been encountered and expanded before. For
some problems repeated states are unavoidable. The search trees for these problems are infinite. If we prune
some of the repeated states,we can cut the search tree down to finite size. Considering search tree upto a
fixed depth,eliminating repeated states yields an exponential reduction in search cost.

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

You might also like