0% found this document useful (0 votes)
11 views22 pages

CS488-CH-4 Basics of Search

searching algo
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)
11 views22 pages

CS488-CH-4 Basics of Search

searching algo
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/ 22

HiLCoE

School of Computer Science and Technology

Course Title: Introduction to Artificial Intelligence (CS488)


Credit Hour: 4
Instructor: Fantahun B. (PhD) [email protected]
Office: 402
C_Hrs: Tues 10:30-12:10, Thurs 13:30-15:10
13:30-15:10 10:30-12:10
June 30, 2022
AA
4-BASICS OF SEARCH

Agenda
 What is Search? How to search?
 Performing state space search and examples
 Searching strategies and Evaluation mechanisms:
Completeness, optimality, Time and space complexity;

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 2


4-BASICS OF SEARCH

Objectives
 Define the search problem and explain how it works
 Performing state space search and examples
 Discuss searching strategies and evaluation mechanisms:
(completeness, optimality, time and space complexity)

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 3


4-BASICS OF SEARCH
What is Search?

 Having formulated some problems, we now need to solve


them.
 A solution is an action sequence, so search algorithms
work by considering various possible action sequences.
 The process of looking for a sequence of actions that
reaches the goal is called search.
 The possible action sequences starting at the initial state
form a search tree with the initial state at the root; the
branches are actions and the nodes correspond to states
in the state space of the problem.
Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 4
4-BASICS OF SEARCH
How to Search?
 Figure 4.2 shows the first few steps in growing the search tree
for finding a route from Arad to Bucharest.
 The root node of the tree corresponds to the initial state,
In(Arad).
 The first step is to test whether this is a goal state.
o (Clearly it is not, but it is important to check so that we can solve trick
problems like “starting in Arad, get to Arad.”)
 Then we need to consider taking various actions.
o We do this by expanding the current state; that is, applying each legal
action to the current state, thereby generating a new set of states.
o In this case, we add three branches from the parent node In(Arad)
leading to three new child nodes: In(Sibiu), In(Timisoara), and
In(Zerind).
 Now we must choose which of these three possibilities to
consider further.
Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 5
4-BASICS OF SEARCH
How to Search?
 This is the essence of search - following up one option now
and putting the others aside for later, in case the first choice
does not lead to a solution.
 Suppose we choose Sibiu first.
 We check to see whether it is a goal state (it is not) and then
expand it to get In(Arad), In(Fagaras), In(Oradea), and
In(RimnicuVilcea).
 We can then choose any of these four or go back and
choose Timisoara or Zerind.
 Each of these six nodes is a leaf node, that is, a node with no
children in the tree.
 The set of all leaf nodes available for expansion at any given
point is called the frontier.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 6


4-BASICS OF SEARCH
Search Example Romania

Figure 4.1 A simplified road map of part of Romania.


Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 7
4-BASICS OF SEARCH
Search Example Romania

Arad

Sibiu Timisoara Zerind

Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea

Figure 4.2 The first few Steps in growing the search tree for finding a route from Arad to Bucharest

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 8


4-BASICS OF SEARCH
Search Example Romania

Arad

Sibiu Timisoara Zerind

Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea

Figure 4.2 The first few Steps in growing the search tree for finding a route from Arad to Bucharest

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 9


4-BASICS OF SEARCH
Search Example Romania

Arad

Sibiu Timisoara Zerind

Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea

Figure 4.2 The first few Steps in growing the search tree for finding a route from Arad to Bucharest

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 10


4-BASICS OF SEARCH
How to Search?

 The process of expanding nodes on the frontier continues


until either a solution is found or there are no more states
to expand.
 The general TREE-SEARCH algorithm is shown informally in
Figure 4.3.
 Search algorithms all share this basic structure; they vary
primarily according to how they choose which state to
expand next (search strategy).

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 11


4-BASICS OF SEARCH
How to Search?

Figure 4.3 An informal description of the general tree-search algorithm.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 12


4-BASICS OF SEARCH
How to Search?
 The search tree shown in Figure 4.2 includes the path from Arad to
Sibiu and back to Arad again! We say that In(Arad) is a repeated
state in the search tree, generated in this case by a loopy path.
 Considering such loopy paths means that the complete search tree
for Romania is infinite because there is no limit to how often one
can traverse a loop.
 On the other hand, the state space (the map shown in Figure 4.1)
has only 20 states.
 Loops can cause certain algorithms to fail, making otherwise
solvable problems unsolvable.
 Fortunately, there is no need to consider loopy paths. Because
o path costs are additive,
o step costs are nonnegative,
o a loopy path to any given state is never better than the same path with the
loop removed.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 13


4-BASICS OF SEARCH
How to Search?

 Loopy paths are a special case of the more general concept


of redundant paths, which exist whenever there is more than
one way to get from one state to another.
 Consider the paths Arad–Sibiu (140 km long) and Arad–Zerind–
Oradea–Sibiu (297 km long).
 Obviously, the second path is redundant—it’s just a worse way
to get to the same state.
 If you are concerned about reaching the goal, there’s never
any reason to keep more than one path to any given state,
because any goal state that is reachable by extending one
path is also reachable by extending the other.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 14


4-BASICS OF SEARCH
How to Search?

 As the saying goes, algorithms that forget their history are


doomed to repeat it.
 The way to avoid exploring redundant paths is to remember
where one has been. To do this, we augment the TREE-
SEARCH algorithm with a data structure called the explored
set (also known as the closed list), which remembers every
expanded node.
 Newly generated nodes that match previously generated
nodes (ones in the explored set or the frontier) can be
discarded instead of being added to the frontier.
 The new algorithm, called GRAPH-SEARCH, is shown informally
in Figure 4.4. The specific algorithms in this chapter draw on
this general design.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 15


4-BASICS OF SEARCH
How to Search?

Figure 4.4 An informal description of the general graph-search algorithm. The parts of
GRAPH-SEARCH marked in bold italic are the additions needed to handle repeated states.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 16


4-BASICS OF SEARCH
How to Search?

Class work:
Based on the GRAPH-SEARCH algorithm, try to generate a
sequence of search trees for the Romania problem (Fig. 4.1)

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 17


4-BASICS OF SEARCH
How to Search?

Figure 4.5 A sequence of search trees generated by a graph search on the Romania problem of
Figure 4.1. At each stage, we have extended each path by one step. Notice that at the third
stage, the northernmost city (Oradea) has become a dead end: both of its successors are
already explored via other paths.
Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 18
4-BASICS OF SEARCH
Infrastructure for search algorithms

 Search algorithms require a data structure to keep track


of the search tree that is being constructed.
 For each node n of the tree, we have a structure that
contains four components:
o n.STATE: the state in the state space to which the node
corresponds;
o n.PARENT: the node in the search tree that generated this node;
o n.ACTION: the action that was applied to the parent to generate
the node;
o n.PATH-COST: the cost, traditionally denoted by g(n), of the path
from the initial state to the node, as indicated by the parent
pointers.

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 19


4-BASICS OF SEARCH
Search strategies and measuring problem-solving performance

 A strategy is defined by picking the order of node expansion


 Uninformed strategies use only the information available in the
problem definition
o Breadth-first search
o Uniform-cost search
o Depth first search
o Depth-limited search
o Iterative deepening search
 Informed search strategies use problem-specific knowledge
beyond the definition of the problem itself
o Best-first search
o A* search

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 20


4-BASICS OF SEARCH
Search strategies and measuring problem-solving performance

 Strategies are evaluated along the following dimensions:


o Completeness: Is the algorithm guaranteed to find a solution
when there is one?
o Optimality: Does the strategy find the optimal solution, as defined
on page 68?
o Time complexity: How long does it take to find a solution?
o Space complexity: How much memory is needed to perform the
search?

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 21


4-BASICS OF SEARCH
Search strategies and measuring problem-solving performance

 Time and space complexity are measured in terms of


o b-maximum branching factor of the search tree
o d-depth of the least-cost solution
o m-maximum depth of the state space (may be ꝏ)

Jun-22 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 22

You might also like