Implementation and Efficiency of For The Shortest Route Problem

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Mathematieal Programming 7 (1974) 212-222.

North-Holland Publishing Company

IMPLEMENTATION AND EFFICIENCY OF MOORE-ALGORITHMS


FOR THE SHORTEST ROUTE PROBLEM

U. PAPE
Technische Universitd't Berlin, W. Berlin, Germany

Received 7 February 1972


Revised manuscript received 29 June 1974

in the last 15 years, a good deal of effort has been devoted to the study of the shortest
route problem. More than 200 publications are known but little has been reported concerning
relative efficiencies. For a long time the Dijkstra method was considered the most efficient one.
Programming work, using different data structures and implementation techniques for several
algorithms, has shown that a variant of Moore's method seems to be most efficient for different
types of graph structures.
The main objective of this paper is to show the strong relationship between an algorithm and
its implementation.

1. Problem

Consider a network with node set X, IXI = n, and directed arcs (i, j)
having distances di/. Let J = (Jl, ..., Jt } c X, and K = X \ J, where t. < n.
The problem is to determine the lengths mix of the shortest routes to
each k ~ K from t h a t ] =fg (g ~ { 1, ..., t}), which is nearest to k.
The case t = 1 is the well-known problem for determining the lengths
of the shortest routes from one node to all other nodes. The case of
several roots can be solved by adding to the network one node Jn+l con-
nected to all roots by arcs of length zero. The multiple root problem
may then be regarded as a single root problem; however, this trick is in-
efficient when parameters in the network are subsequently altered and
the new problem must be solved [3].

2. The algorithms of Moore and d'Esopo


The algorithm of Moore [2]
The algorithm is an iterative process with the following general
U. Pape, Moore-algorithms for the shortest route problem 213

step v:

Sv := Y ' ( S u - 1 ) ;

m]~~) := min {m](~~-1), m]}"-1) + dik" i E Sv_ I } , k E Sv;

S, := (k: k ~ S , , m ] ( [ ) ¢ m j ( k ~ - l ) } ;

Sv_ 1 denotes the set of current nodes, and S~ the set of successors o f
nodes in S~_ 1 .
The initial condition of this algorithm is:

SO := (]1' " " ' I t } '

m](kO) :=~ , k--/= ]g , g= l,..., t ;

mj! °) := 0 g=1 t.

The algorithm is applied for u = 1, 27 ... and terminates if S~ =¢.

The algorithm of d'Esopo [2]


The general step u is the following

S, := P(S~_ 1) ;

mJ(k') := min (mj(k~-1), m]} ~-1) + dik : i ~ Sv_ 1 ) , k • S ;

R v := Rv_ 1 U Sv_ 1 ;

S := (k: k ~ S , rnj~') ¢ m]~È-u } ;

i f S , nH4= 0 then (S v := S, u H; H := 0)
else
ifS~ n R , 4= 0 then (H : = H u (S, \ (S~ n R ~ ) ) ;
S~ := S~ n R~)
else
/fS~ = O A H ¢ O then(S, :=H;H:=0)

The initial condition is


214 U. Pape, Moore-algorithms for the shortest route problem

S0 := (Jl' "'" ]t } ;

mJ(kO) := oo , k4=jg, g= 1,...,t;

rnj!~g°) := 0 g = 1, ..., t ,

Ro :=0; H:=0.

The algorithm is applied for v = 1, 2, ... and terminates if S~ = 0.

3. Implementation with circular lists

One fundamental criterion of a graph theoretic algorithm is the kind


of list structure for treating the nodes. A simple but not recommended
method is the use of a list of variable length as a queue for storing the
indices of nodes to be visited during the traversal of the network. As
several nodes of the network appear more than once during the per-
formance it is not possible to estimate the length of this array; it m a y
be a great deal longer than n.
This is the reason for using a queue of circular structure and length n:

1 5c mt n
Ind I I ~ S / / ~ I [

The queue moves from left to right through the array. If mt becomes n,
the next element of the queue is stored in Ind 1 again. As the temporary
length of the sequence of nodes is never longer than n and all indices
are stored without gaps, no overlapping of beginning and end of the
sequence occurs.
The use of this list structure in graph algorithms has two main advan-
tages:
(1) Fixed length of the array induced by the number of nodes in the
network,
(2) small access time to the following nodes in the queue without
any search.
Moreover, one must know the following information about each node
k , k = 1, ...,n:
(i) The list contains node k, or
U. Pape, Moore-algorithms for the shortest route problem 215

(ii) the list does not but has contained node k, or


(iii) the list does not and has not contained node k.
These three data may be expressed by an additional array of length n :

l! 0 if the case (i) occurs for node k,


KList/c 0 if the case (ii) occurs for node k,
0 if the case (iii) occurs for node k.

The codes need the following basic operations on the arrays Ind and
KList:
(i) Addition of a node k at the t e m p o r a r y end (indicated by rot) of
the list,
(ii) Addition of a node k at the temporary beginning (indicated by sc)
of the list,
(iii) Progression from the temporary beginning to the next element
of the list.
Computer codes MOORE1 and D'ESOPO1 incorporate these opera-
tions (cf. [4]). For testing the algorithms ten networks were con-
structed. Five of them (series 70 000 in Table 1) are traffic networks
and represent parts of the road net of Braunschweig (W. Germany). In-
degree and out-degree are on an average 3. The networks are asym-
metric, but of course most streets are not one-way streets. The arc dis-
tances correspond to topographic distances. The other five networks
(series 71 000 in Table 1) are project networks, and hence are anti-
symmetric and acyclic with in-degree and out-degree of approximately
2.
The main difference between the computing time of the 70 000 and
71 000 examples is due to the different density of the networks and the
different degree of asymmetry. The times in Tables 1 - 3 (for t = 1) were
obtained on an ICL 1907 computer of the Technical University of
Braunschweig.
Avoiding the redundant array, KList leads to a considerable increase
in computing time (see Table 2).
The computer code based on the algorithm of d'Esopo produced
much better results (see Table 3). The average values of the series
70 000 in the third columns of Tables 1 and 3 are shown in Fig. 1.
216 U. Pape, Moore-algorithms for the shortest route problem

t cseq

.1 SERIES 70,000

MOORE I ~.
MOORE2 -~ ~ ~ / ~
D'ESOPO I ~ " - - _ J ~

..)

n
I
$0 100 150 250 5NO ~00

Fig. 1.

Table 1
(MOORE 1)

Number n Average time Shortest time Longest time


(sec) (sec) (sec)

70 050 50 0.046 0.043 0.063


70 100 100 0.120 0.091 0.195
70 150 150 0.212 0.138 0.339
70 250 250 0.419 0.258 0.768
70 350 350 0.645 0.355. 1.316
70 500 500 0.905 0.519 1.890

71 050 50 0.011 0.005 0.035


71 100 100 0.024 0.010 0.069
71 150 150 0.042 0.014 0.128
71 250 250 0.074 0.025 0.245
71 350 350 0.104 0.034 0.386
71 500 500 0.161 0.062 0.633

Table 2

Number n Average time Shortest time Longest time


(sec) (sec) (sec)

70 050 50 0.068 0.057 0.106


70 100 100 0.269 0.175 0.506
U. Pape, Moore-algorithms for the shortest route problem 217

Table 3
(D'ESOPO 2)

Number n Average time Shortest time Longest time


(see) (sec) (sec)

70 050 50 0.041 0.039 0.049


70 100 100 0.097 0.082 0.125
70 150 150 0.155 0.125 0.271
70 250 250 0.263 0.230 0.385
70 350 350 0.373 0.318 0.488
70 500 500 0.523 0.388 0.687

71 050 50 0.012 0.007 0.034


71 100 100 0.024 0.013 0.070
71 150 150 0.039 0.019 0.106
71 250 250 0.071 0.032 0.182
71 350 350 0.087 0.034 0.245
71 500 500 0.134 0.062 0.363

4. Implementation with linked lists

The use of a linked queue instead of a circular list leads to a higher


efficiency for both algorithms. The indices a 1 , a 2 . . . . . ant ( n t <<. n ) to be
discussed in a fixed sequence are stored in an array n] of length n in
such a way that the element n]a i contains the following index ai+ 1 . The
end of this sequence is marked by n]ant = oo. The following scheme as
an example contains three elements:

1 a~ ~ @ fa 5 n

nj II Iq II

This technique has three essential advantages:


(1) Fixed length of the array n], induced by the number of nodes in
the network,
(2) small access time to the following node in the queue without any
search,
(3) small effort to change the sequence of nodes under consideration.
In addition, one must know the following information about each node
k, k = 1, ..., n:
(i) The list contains node k, or
218 U. Pape, Moore-algorithms for the shortest route problem

(ii) the list does not but has contained node k, or


(iii) the list does not and has not contained node k.
Case (iii) may be expressed by zeros in nj: nj k = 0 if node k is not in nj.
Case (i) can be expressed b y storing a positive integer: the index of the
following node or a large number. The second case is expressed b y
negative integers nJk < O.
The two arrays Ind and KList of the above mentioned circular list
technique are combined into a single list with high efficiency.
The following operations are part of the discussed algorithm:
(i) Addition of a node k at the temporary end of the queue,
(ii) addition of a node k between two consecutive elements of the
queue,
(iii) progression from the temporary beginning to the next element
of the list.
The algorithms M O O R E 2 and D'ESOPO2 incorporate these opera-
tions. The results on the MOORE 2 code (for t = 1) are given in Table 4.

Table 4
(MOORE 2)

Number n Average time Shortest time Longest time


(sec) (see) (see)

70 050 50 0.040 0.037 0.054


70 100 100 0.104 0.079 0.168
70 150 150 0.184 0.120 0.292
70 250 250 0.376 0.236 0.708
70 350 350 0.594 0.325 1.214
70 500 500 0.837 0.427 1.763

71 050 50 0.009 0.005 0.029


71 100 100 0.019 0.009 0.066
71 150 150 0.033 0.013 0.106
71 250 250 0.073 0.027 0.233
71 350 350 0.092 0.029 0.346
71 500 500 0.129 0.041 0.543
U. Pape, Moore-algorithms for the shortest route problem 219

Table 5
(D'ESOPO 2)

Number n Average time Shortest time Longest time


(sec) (sec) (sec)

70050 50 0.038 0.036 0.045


70 100 100 0.091 0.075 0.118
70 150 150 0.146 0.116 0.259
70 250 250 0.247 0.214 0.366
70 350 350 0.352 0.297 0.463
70 500 500 0.491 0.413 0.651

71 050 50 0.009 0.005 0.029


71 100 100 0.018 0.009 0.060
71 150 150 0.030 0.013 0.090
71 250 250 0.053 0.021 0.155
71 350 350 0.075 0.029 0.222
71 500 500 0.103 0.040 0.309

The results of the code based on d'Esopo are the most impressive
ones for (t = 1) and are given in Table 5.
Both algorithms ( M O O R E 2 and D'ESOPO2), which seem to be the
most efficient methods for solving the shortest path problem, were run
for t > 1, too. For each t, 10 runs with randomly obtained roots were
made. The results of this testing are given in Tables 6 and 7.
The times in Tables 6 and 7 show a high dependence on the dimen-
sion of the networks and the number of roots. This is particularly true
for large n and small t. Additionally, the results indicate that the
M O O R E 2 code yields slight better results than the D'ESOPO 2 code for
large t. This is due to the fact that the randomly determined arrange-
ment of the roots does not permit the D'ESOPO 2 code to take advan-
tage of the root arrangement; consequently, the smaller number of com-
parisons involved in the M O O R E 2 code makes it superior.
220 U. Pape, Moore-algorithms for the shortest route problem

¢¢3

¢.q

© ©

,gz

z
U. Pape, Moore-algorithms for the shortest route problem 221

09 09

t-- :~

¢¢3

09 09
¢ZJ

¢} 09

¢4
0
r..©

e~

z
222 U. Pape, Moore-algorithms for the shortest route problem

References

[1] S.E. Dreyfus, "An appraisal of some shortest path algorithms", Operations Research 17
(1969) 395-412.
[2] E.F. Moore, "The shortest path through a maze", in: Proceedings of an international sym-
posium on the theory of switching, Part 1I, Apr. 2 - 5 , 1957 (Harvard University Press,
Cambridge, Ma., 1959).
[3] U. Pape, "Netzwerkver~inderungen und Korrektur kiirzester Wegl~ngen yon einer Wurzel-
menge zu allen anderen Knoten", Technical University of Berlin, Department of Cyber-:
netics, Tech. Rept. 73-17.
[4] U. Pape, "Implementierung und Wirtschaftlichkeit von Moore-Algorithmen zur Bestimmung
kfirzester Wegl~ngen in einem Netzwerk", Technical University of Berlin, Department of
Cybernetics, Tech. Rept. 73-06.
[5] M. Pollack and W. Wiebenson, "Solutions of the shortest route problem - a review",
Operations Research 8 (1960) 224-230.

You might also like