AI Lecture Three Search
AI Lecture Three Search
AI Lecture Three Search
Graph theory is our best tool for reasoning about the structure of
objects and relations; indeed, this is precisely the need that led to its
creation in the early eighteenth century. The Swiss mathematician
Leonhard Euler invented graph theory to solve the “bridges of
Königsberg problem.” The city of Königsberg occupied both banks and
two islands of a river. The islands and the riverbanks were connected by
seven bridges, as indicated in Figure 3.1.
1
إعداد م.د .اسعد نوري هاشم محاضرات في الذكاء االصطناعي
2
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
DEFINITION
A is the set of arcs (or links) between nodes. These correspond to the
steps in a
problem-solving process.
In order to apply a move, we must make sure that it does not move the
blank off the board. Therefore, all four moves are not applicable at all
times; for example, when the blank is in one of the corners only two
moves are possible. The legal moves are:
3
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
A state space may be searched in two directions: from the given data
of a problem instance toward a goal or from a goal back to the data. In
data-driven search, sometimes called forward chaining, the problem
solver begins with the given facts of the problem and a set of legal moves
or rules for changing state. Search proceeds by applying rules to facts to
produce new facts, which are in turn used by the rules to generate more
new facts. This process continues until (we hope!) it generates a path that
satisfies the goal condition.
4
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
2. There are a large number of rules that match the facts of the problem
and thus produce an increasing number of conclusions or goals. Early
selection of a goal can eliminate most of these branches, making goal-
driven search more effective in pruning the space (Figure 3.12). In a
theorem prover, for example, the total number of rules used to produce a
5
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
given theorem is usually much smaller than the number of rules that may
be applied to the entire set of axioms.
3. Problem data are not given but must be acquired by the problem solver.
In this case, goal-driven search can help guide data acquisition. In a
medical diagnosis program, for example, a wide range of diagnostic tests
can be applied. Doctors order only those that are necessary to confirm or
deny a particular hypothesis.
6
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
Goal-driven search thus uses knowledge of the desired goal to guide the
search through relevant rules and eliminate branches of the space. Data-
driven search is appropriate for problems in which:
1. All or most of the data are given in the initial problem statement.
Interpretation problems often fit this mold by presenting a collection of
data and asking the system to provide a high-level interpretation.
2. There are a large number of potential goals, but there are only a few
ways to use the facts and given information of a particular problem
instance. The DENDRAL program, an expert system that finds the
molecular structure of organic compounds based on their formula, mass
spectrographic data, and knowledge of chemistry, is an example of this.
For any organic compound, there are an enormous number of possible
structures. However, the mass spectrographic data on a compound allow
DENDRAL to eliminate all but a few of these.
7
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
8
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
9
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
Figure 3.16 illustrates the graph of Figure 3.15 after six iterations of
breadth first_search. The states on open and closed are highlighted. States
not shaded have not been discovered by the algorithm. Note that open
records the states on the “frontier” of the search at any stage and that
closed records states already visited. Because breadth-first search
considers every node at each level of the graph before going deeper into
the space, all states are first reached along the shortest path from the start
state. Breadth-first search is therefore guaranteed to find the shortest path
from the start state to the goal. Furthermore, because all states are first
found along the shortest path, any states encountered a second time are
found along a path of equal or greater length.
be saved along with a record of its parent state, e.g., as a (state, parent)
pair. If this is done in the search of Figure 3.15, the contents of open and
closed at the fourth iteration would be:
States on open and closed are highlighted. The path (A, B, F) that led
from A to F could easily be constructed from this information. When a
goal is found, the algorithm can construct the solution path by tracing
back along parents from the goal to the start state. Note that state A has a
parent of nil, indicating that it is a start state; this stops reconstruction of
the path.
Because breadth-first search finds each state along the shortest path
and retains the first version of each state, this is the shortest path from a
start to a goal. Figure 3.17 shows the states removed from open and
examined in a breadth-first search of the graph of the 8-puzzle. As before,
arcs correspond to moves of the blank up, to the right, down, and to the
left. The number next to each state indicates the order in which it was
removed from open. States left on open when the algorithm halted are
not shown. Next, we create a depth-first search algorithm, a simplification
11
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
12
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
13
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
14
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
which they were considered, i.e., removed from open. States left on open
when the goal is found are not shown. A depth bound of 5 was
imposed on this search to keep it from getting lost deep in the space.
15
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
16
اسعد نوري هاشم.د.إعداد م محاضرات في الذكاء االصطناعي
not waste time searching a large number of “shallow” states in the graph.
On the other hand, depth-first search can get “lost” deep in a graph,
missing shorter paths to a goal or even becoming stuck in an infinitely
long path that does not lead to a goal.
Depth-first search is much more efficient for search spaces with many
branches because it does not have to keep all the nodes at a given level on
the open list. The space usage of depth-first search is a linear function of
the length of the path. At each level, open retains only the children of a
single state. If a graph has an average of B children per state, this requires
a total space usage of B × n states to go n levels deep into the space.
The best answer to the “depth-first versus breadth-first” issue is to
examine the problem space and consult experts in the area. In chess, for
example, breadth-first search simply is not possible. In simpler games,
breadth-first search not only may be possible but, because it gives the
shortest path, may be the only way to avoid losing.
17