Lec15 (Is)
Lec15 (Is)
Intelligent Systems
Lecture 15
Search Methods for Route-finding Problems
Lecturer
Dr. Faris S. Alghareb
PhD in Computer Engineering @ UCF
email: [email protected]
Copyright © 2020 Faris S. Alghareb. All rights reserved.
Route-finding Problem (1/2)
v Route-finding algorithms are used in a variety of applications, such as routing video
streams in computer networks, military operations planning, airline travel-planning systems,
and other application that involve much more complex specifications
v The possible action sequences starting at the initial state from 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.
v Expanding the current state is done by applying each legal action to the current state,
thereby generating a new set of states
v In this case, we add some branches from the parent node, leading to generate some new
child nodes.
v Then we need to choose which of the possibilities (new children) to consider further
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 1
Route-finding Problem (2/2)
v When reaching a leaf node, i.e., a node with no children below its level, the next step is to
go back (back track) to choose.
v The process of expanding or exploring nodes on the tree continues until either a
solution is found or there are no more states (nodes) to expand or visit.
v Search algorithms all share this basic structure; however, they vary primarily according to
how they choose which state to expand next–the so-called search strategy.
v Nodes are the data structures from which the search tree is constructed
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 2
Route-finding Problem
v The figure below shows a sequence of search trees generated by a graph search
◆ At each stage, each path is extended by one step.
v All they can do is generating successors and distinguish a goal state from a non-goal state.
v All search strategies are distinguished by the order in which nodes are expanded.
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 5
Breadth-first Search (BFS) Algorithm
v As show in the figure below, BFS algorithm visit all nodes at a level before moving to visit
and explore the nodes at the lower level.
v At each stage, the node to be expanded next is indicated by a marker.
v Theses need to be stored in such a way that the search algorithm can easily choose the
next node to expand according to its preferred strategy.
v The appropriate data structure for this is a queue
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 6
Procedure of Breadth-first Search Algorithm
v Pseudo algorithm of breadth-first search
Queue (FIFO)
Closed Open
......
list list
Begin
1- Place the starting node in a queue;
2- Repeat
delete the visited node in the queue to get a new front node;
if (the new front element of the queue = goal)
return success and stop;
Else
begin
insert the children of the explored node; /* we put them on
the right side in the open list to be visited next */
if (no any nodes remained to visit)
Exit; /* until the queue become empty */
End;
End;
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 7
Breadth-first Search Algorithm ⎼ Example #1
✏ Apply the breadth-first search algorithm on the following graph, where the start state is node (A) and
the desired goal state is node (G), show the successive values of open and closed, and the traversed
path.
ANS: For the next iteration, node (A) replace by its Children [BCD] in the open list, then move it the closed list.
1
Iteration
X Goal Open Closed A
#
0 Ø ⎼ G [A] []
1 Ø A G [BCD] [A]
2 Ø B G [CDEF] [BA] 2 B 3 C 4
D
3 Ø C G [DEFG] [CBA]
4 Ø D G [EFG] [DCBA]
E F G
5 Ø E G [FGHI] [EDCBA] 5 6 7
6 Ø F G [GHIJ] [FEDCBA]
7 Ø G G The goal is achieved I
H J
◆ Open list: contains the successors of a node that is being
visited. Ø Traversed path = ABCDEF à G
◆ Closed list: contains the nodes that have been already Ø Thus, the required data structure here is
explored (visited) a Queue
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 8
Breadth-first Search Algorithm ⎼ Example #2
✏ Apply the breadth-first search algorithm on the following graph, where the start state is node (A) and
the desired goal state is node (O), show the successive values of open and closed, and the traversed
path.
ANS: For the next iteration, node (A) replace by its Children [BCD] in the open list, then move it the closed list.
Iteration 1
X Goal Open Closed
# A
0 Ø ⎼ O [A] []
1 Ø A O [BCD] [A]
2
B 3
C 4 D
2 Ø B O [CDE] [BA]
3 Ø C O [DEGH] [CBA]
4 Ø D O [EGH] [DCBA] E 6
G H
5 7
5 Ø E O [GHKN] [EDCBA]
6 Ø G O [HKNR] [GEDCBA]
7 Ø H O [KNROP] [HGEDCBA] K 9
N 10
R 11 O P
8 12
8 Ø K O [NROP] [KHGEDCBA]
9 Ø N O [ROP] [NKHGEDCBA] J U
10 Ø R O [OP] [RNKHGEDCBA]
Ø Traversed path = ABCDEGHKNR à O
11 Ø O O The goal is achieved Ø Thus, the required data structure here is a Queue
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 9
Depth-first Search (DFS) Algorithm
v Depth first search algorithm generates nodes and compares them to the desired goal
along the largest depth of the tree.
v It moves up (back track) to the parent of the last visited node (child), only when no further
nodes can be generated below the visited last node (a leaf has been reached).
v After moving up to the parent, the algorithm starts generating new nodes (new unvisited
children).
v This concept is repeated recursively to visit each node in the tree until the desired goal
achieved.
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 10
Depth-first Search (DFS) Algorithm
v Applying the depth-first search algorithm on the following graph
1
A
insertion deletion
2
B C D TOS
3
E F G
6
forward
4 H I J track Stack
5 7
back
track
v Insertion and deletion are done at one end (same end); therefore, the new nodes (children)
of a vertex will be added on the left in the open list.
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 11
Procedure of Depth-first Search Algorithm
v Pseudo algorithm of depth-first search
Begin
1- Push the starting node at the stack, pointed to by the top
of stack (TOS);
2- while the stack is not empty do
Begin
pop stack to get TOS element;
if (TOS element = goal)
return success and stop;
Else
push the children of the TOS element (node) in any order
in the stack;
End while;
End;
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 12
Depth-first Search Algorithm ⎼ Example #1
✏ Apply the depth-first search algorithm on the following graph, where the start state is node (A) and the
desired goal state is node (G), show the successive values of open and closed, and the traversed
path.
ANS: 1
A
Iteration
X Goal Open Closed 2
#
0 Ø ⎼ G [A] [] B 8 C D
10
1 Ø A G [BCD] [A]
2 Ø B G [EFCD] [BA] 3
E F G
3 Ø E G [HIFCD] [EBA] 6
9
4 Ø H G [IFCD] [HEBA]
forward back
5 Ø I G [FCD] [IHEBA]
4 H I J track track
6 Ø F G [JCD] [FIHEBA] 7
5
7 Ø J G [CD] [JFIHEBA]
8 Ø C G [GD] [CJFIHEBA] Traversed path = ABEHIFJC à G
9 Ø G G The goal is achieved Ø Thus, the required data structure here is a Stack
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 13
Depth-first Search Algorithm ⎼ Example #2
✏ For the graph tree show on the right, apply the depth-first search algorithm, where the start state is
node (A) and the desired goal state is node (G), show the successive values of open and closed, and
the traversed path.
ANS: 1
A
Iteration Open Closed
X Goal
# (not yet) (visited)
2
0 Ø ⎼ G [A] []
B 6
F C 9
D
1 Ø A G [BFCD] [A]
2 Ø B G [EFCD] [BA]
3 7
3 Ø E G [HIFCD] [EBA]
E J G
4 Ø H G [IFCD] [HEBA] 8
5 Ø I G [FCD] [IHEBA]
6 Ø F G [JGCD] [FIHEBA] I forward back
4 H track
track
7 Ø J G [GCD] [JFIHEBA] 5
8 Ø G G The goal is achieved
Traversed path = ABEHIFJ à G
Ø Thus, the required data structure here is a stack
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 14
Differences between Depth and Breadth Search algorithms
# Stack Queue
1 Last-In-First-Out (LIFO) First-In-First-Out (FIFO)
Items can be added or removed only at
One end is always used to insert data (enqueue)
2 and from one end. Stack instructions are
and the other is used to remove data (dequeue).
push & pop
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 16
Searching Techniques of Graph Tree ⎼ Classwork #1
✏ In terms of search cost and solution cost, which algorithm the breadth or the depth search
will perform better to search a tree that has so many branches? Elaborate on the answer.
✏ Apply both searching algorithms that have been learned in this lecture on the graph tree
illustrated on the next slide, where the start state is node (A) and the desired goal state is
node (O), show the successive values of open and closed, and the traversed path. Then
compare between the obtained results.
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 17
Searching Techniques of Graph Tree ⎼ Classwork #1
Tree 1:
A
B C D
E F G
K H M N P
L I J
O U
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 18
End of Lecture 15