Professional Documents
Culture Documents
Problem Solving by Searching
Problem Solving by Searching
searching
Outline
Problem-solving agents
Problem types
Problem formulation
Example problems
Basic search algorithms
Introduction
To build a system to solve a particular
problem, we need to do 04 things:
1. Define the problem precisely. Specify
Initial/final solutions
2. Analyze the problem. A few very important
features can have an immense impact on
the appropriateness of various possible
techniques for solving the problem
3. Isolate & represent the task knowledge
that is necessary to solve the problem
4. Choose the best problem-solving
technique (s) & apply it (them) to the
Production Systems
Since search forms the core of many intelligent processes, it is
useful to structure AI programs in a way that facilitates describing
& performing the search process.
Production systems provide such structures.
A production system consist of:
- A set of rules, each consisting of a left side (a pattern) that
determines the applicability of the rule & a right side that
describes the operation to be performed if the rule is applied
- One ore more knowledge/databases that contain whatever
information is appropriate for the particular task. Some parts of the
database may be permanent, while other parts of it may pertain
only to the solution of the current problem. The information in
these databases may be structured in any appropriate way.
- A control strategy that specifies the order in which the rules will be
compared to the database & a way of resolving the conflicts that
arise when several rules match at once
- A rule applier
Search
In general, an agent with several
immediate options of unknown value can
decide what to do by just examining
different possible sequences of actions that
lead to states of known value, and then
choosing the best sequence.
This process of looking for such a sequence
is called search.
A search algorithm takes a problem as
input & returns a solution in the form of an
action sequence.
Once a solution is found, the actions it
recommends can be carried out:
Problem-solving agents
Restricted form of general agent:
Formulate goal:
be in Bucharest
Formulate problem:
states: various cities
actions: drive between cities
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest
Example: Romania
Problem types
Deterministic, fully observable single-state
problem
Agent knows exactly which state it will be in; solution is a
sequence
Non-observable sensorless problem (conformant
problem)
Agent may have no idea where it is; solution is a sequence
Nondeterministic and/or partially observable
contingency problem
percepts provide new information about current state
solution is a contingent plan or a policy
often interleave search, execution
Unknown state space exploration problem
(“online”)
Example: vacuum world
Single-state, start in #5. Solution??
[Right; Suck]
Conformant, start in {1; 2; 3; 4; 5; 6; 7;
8}
e.g., Right goes to {2; 4; 6; 8}. Solution??
[Right; Suck; Left; Suck]
Contingency, start in #5
Murphy's Law: Suck can dirty a clean
carpet
Local sensing: dirt, location only.
Solution??
3 4
5 6
8
7
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Breadth-first
search
Expand shallowest Step 1
unexpanded node
Implementation:
fringe is a FIFO queue,
i.e., new successors go at
end
30
How to do depth-first
searching
Put the root node on a stack;
while (stack is not empty) {
remove a node from the stack;
if (node is a goal node) return success;
put all children of node onto the stack;
}
return failure;
At each step, the stack contains some nodes
from each of a number of levels
The size of stack that is required depends on the
branching factor b
While searching level n, the stack contains
approximately b*n nodes
When this method succeeds, it doesn’t give
the path 31
Properties of depth-first
search
Complete? No: fails in infinite-depth
spaces, spaces with loops
Modify to avoid repeated states along path
complete in finite spaces
Time? O(bm): terrible if m is much larger
than d
but if solutions are dense, may be much
faster than breadth-first
Space? O(bm), i.e., linear space!
Optimal? No
Pros of DFS
DFS requires less memory since only the nodes on
the current path are stored
This contrast with BFS, where all of the tree that
has so far been generated must be stored
By chance, DFS may find a solution without
examine much of the search space at all
Contrast with BFS, in which all parts of the tree
must be examined to level n before any nodes on
level n+1 can be examined.
This is particularly significant if many acceptable
solutions exist,
DFS can stop when one of them is found
Comparative analysis (b = 3,d = 2)
FIFO
LIFO
Max-list-length = 1 + Max-list-length =
Depth-limited searching
Depth-first searches may be performed with a
depth limit:
boolean limitedDFS(Node node, int limit, int depth) {
if (depth > limit) return failure;
if (node is a goal node) return success;
for each child of node {
if (limitedDFS(child, limit, depth + 1))
return success;
}
return failure;
}
Since this method is basically DFS, if it succeeds
then the path to a goal node is in the stack
35
Iterative deepening search