# 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 connected 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 inefficient 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

t . u H.. H := 0) /fS~ = O A H ¢ O The initial condition is . t.1 ) . mj! °) := 0 k--/= ]g . m]} ~-1) + dik : i ~ Sv_ 1 ) . i f S .. \ (S~ n R ~ ) ) . The algorithm of d'Esopo [2] The general step u is the following S. 4= 0 else then (H : = H u (S.. S := (k: k ~ S . and terminates if S~ =¢. := P(S~_ 1) .. :=H. Moore-algorithms for the shortest route problem 213 step v: Sv := Y ' ( S u . m ] ( [ ) ¢ m j ( k ~ . k • S . := (k: k ~ S .H:=0) then (S v := S. m]}"-1) + dik" i E Sv_ I } . The algorithm is applied for u = 1. m]~~) := min {m](~ ~-1).. mJ(k') := min (mj(k~-1). and S~ the set of successors o f nodes in S~_ 1 .. Pape. 27 . S. nH4= 0 else ifS~ n R . S~ := S~ n R~) then(S. rnj~') ¢ m]~È-u } . k E Sv. g=1 g= l. The initial condition of this algorithm is: SO := (]1' " " ' I t } ' m](kO) :=~ .l ) } . Sv_ 1 denotes the set of current nodes. .U. R v := Rv_ 1 U Sv_ 1 .

... As several nodes of the network appear more than once during the performance it is not possible to estimate the length of this array. Moreover.. This is the reason for using a queue of circular structure and length n: 1 Ind I I 5c ~ S / / ~ mt n I [ The queue moves from left to right through the array.. k = 1. As the temporary length of the sequence of nodes is never longer than n and all indices are stored without gaps.t.. . it m a y be a great deal longer than n. 2. mJ(kO) := oo . rnj! °) := 0 ~g Ro :=0. H:=0. Implementation with circular lists One fundamental criterion of a graph theoretic algorithm is the kind of list structure for treating the nodes.n: (i) The list contains node k. and terminates if S~ = 0. Pape. The use of this list structure in graph algorithms has two main advantages: (1) Fixed length of the array induced by the number of nodes in the network. no overlapping of beginning and end of the sequence occurs. If mt becomes n.. The algorithm is applied for v = 1. . 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. the next element of the queue is stored in Ind 1 again.. 3. k4=jg.. g= 1.. . Moore-algorithms for the shortest route problem S0 := (Jl' "'" ]t } .214 U. (2) small access time to the following nodes in the queue without any search... g = 1. one must know the following information about each node k . or . t .

. The arc distances correspond to topographic distances. Pape. Moore-algorithms for the shortest route problem 215 (ii) the list does not but has contained node k. The times in Tables 1 . 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. (ii) Addition of a node k at the temporary beginning (indicated by sc) of the list. The average values of the series 70 000 in the third columns of Tables 1 and 3 are shown in Fig. The networks are asymmetric. and hence are antisymmetric and acyclic with in-degree and out-degree of approximately 2. if the case (ii) occurs for node k. 1. or (iii) the list does not and has not contained node k.U. if the case (iii) occurs for node k. [4]). Germany). but of course most streets are not one-way streets. Five of them (series 70 000 in Table 1) are traffic networks and represent parts of the road net of Braunschweig (W. The other five networks (series 71 000 in Table 1) are project networks. For testing the algorithms ten networks were constructed. KList leads to a considerable increase in computing time (see Table 2). KList/c 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. Computer codes MOORE1 and D'ESOPO1 incorporate these operations (cf. Avoiding the redundant array. (iii) Progression from the temporary beginning to the next element of the list. The computer code based on the algorithm of d'Esopo produced much better results (see Table 3). Indegree and out-degree are on an average 3.3 (for t = 1) were obtained on an ICL 1907 computer of the Technical University of Braunschweig. These three data may be expressed by an additional array of length n : l! 0 0 0 if the case (i) occurs for node k.

1 SERIES 70.074 0.506 .258 0.138 0.633 70 050 70 100 70 150 70 250 70 350 70 500 71 050 71 100 71 150 71 250 71 350 71 500 50 100 150 250 350 500 50 100 150 250 350 500 Table 2 Number n Average time Shortest time Longest time (sec) 70 050 70 100 50 100 0.890 0.645 0. Pape.128 0.355.035 0.216 U.063 0.025 0. -~ ~ ~ ~ " .043 0.034 0.042 0.212 0.069 0. 0.120 0..014 0.161 Shortest time (sec) 0. Moore-algorithms for the shortest route problem t cseq .339 0.519 0.386 0.046 0. Table 1 (MOORE 1) Number n Average time (sec) 0.091 0.316 1._ MOORE I MOORE2 D'ESOPO I / J ~ ~ .057 0.068 0.010 0.000 ~.011 0.419 0.905 0.024 0.104 0.245 0.) \$0 100 150 250 5NO I ~00 n Fig..005 0.195 0.106 0. 1.269 (sec) 0.768 1.062 Longest time (sec) 0.175 (sec) 0.

one must know the following information about each node k. . . k = 1.049 0.062 Longest time (sec) 0. 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 .134 Shortest time (sec) 0.071 0.024 0.034 0.007 0. or .230 0.182 0.488 0.U.019 0. n: (i) The list contains node k. In addition.013 0. . (2) small access time to the following node in the queue without any search.039 0. Moore-algorithms for the shortest route problem Table 3 (D'ESOPO 2) Number n Average time (see) 0.263 0.041 0.388 0.385 0.087 0.687 0.125 0..155 0. . ant ( n t <<. induced by the number of nodes in the network.082 0.318 0. The indices a 1 .034 0. The end of this sequence is marked by n]ant = oo. .373 0. 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].523 0.125 0. (3) small effort to change the sequence of nodes under consideration..097 0.. Implementation with linked lists The use of a linked queue instead of a circular list leads to a higher efficiency for both algorithms.245 0.271 0.106 0. Pape. a 2 .039 0.363 217 70 050 70 100 70 150 70 250 70 350 70 500 71 050 71 100 71 150 71 250 71 350 71 500 50 100 150 250 350 500 50 100 150 250 350 500 4.070 0.032 0.012 0.

(ii) addition of a node k between two consecutive elements of the queue.236 0. The results on the MOORE 2 code (for t = 1) are given in Table 4.092 0. (iii) progression from the temporary beginning to the next element of the list.027 0. The following operations are part of the discussed algorithm: (i) Addition of a node k at the temporary end of the queue. Case (i) can be expressed b y storing a positive integer: the index of the following node or a large number.427 0.218 U.346 0. The second case is expressed b y negative integers nJk < O.594 0.033 0.129 (see) 0.106 0.029 0.009 0.079 0.041 (see) 0.054 0. Case (iii) may be expressed by zeros in nj: nj k = 0 if node k is not in nj.066 0.233 0.543 .376 0.040 0.168 0.037 0.005 0.009 0.325 0.184 0.073 0. Pape.029 0.013 0. Moore-algorithms for the shortest route problem (ii) the list does not but has contained node k.292 0. Table 4 (MOORE 2) Number n Average time Shortest time Longest time (sec) 70 050 70 100 70 150 70 250 70 350 70 500 71 050 71 100 71 150 71 250 71 350 71 500 50 100 150 250 350 500 50 100 150 250 350 500 0. The algorithms M O O R E 2 and D'ESOPO2 incorporate these operations.120 0.019 0.763 0.708 1. The two arrays Ind and KList of the above mentioned circular list technique are combined into a single list with high efficiency.214 1.104 0. or (iii) the list does not and has not contained node k.837 0.

Pape. too. The results of this testing are given in Tables 6 and 7.090 0.103 Shortest time (sec) 0.352 0.075 0. were run for t > 1. For each t.030 0.018 0.075 0.029 0.013 0. This is particularly true for large n and small t.038 0.366 0.259 0.491 0.214 0.118 0. consequently.091 0.005 0.146 0.222 0. Moore-algorithms for the shortest route problem Table 5 (D'ESOPO 2) Number n Average time (sec) 0.309 70050 70 100 70 150 70 250 70 350 70 500 71 050 71 100 71 150 71 250 71 350 71 500 50 100 150 250 350 500 50 100 150 250 350 500 The results of the code based on d'Esopo are the most impressive ones for (t = 1) and are given in Table 5.463 0.021 0. The times in Tables 6 and 7 show a high dependence on the dimension of the networks and the number of roots.247 0. which seem to be the most efficient methods for solving the shortest path problem. the smaller number of comparisons involved in the M O O R E 2 code makes it superior. Both algorithms ( M O O R E 2 and D'ESOPO2).036 0. Additionally. .155 0.116 0.040 219 Longest time (sec) 0. 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.009 0.297 0. This is due to the fact that the randomly determined arrangement of the roots does not permit the D'ESOPO 2 code to take advantage of the root arrangement.413 0.060 0.029 0.651 0.053 0.009 0. 10 runs with randomly obtained roots were made.U.045 0.

Pape.220 U.gz © z .q z © © z . Moore-algorithms for the shortest route problem z ¢¢3 ¢.

U.. Pape. Moore-algorithms for the shortest route problem 221 09 09 t-- :~ z ¢¢3 z Z 09 09 ¢ZJ Z ¢} 09 ¢4 0 r.© e~ z .

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