Upload
d-r-shier
View
216
Download
3
Embed Size (px)
Citation preview
On Algorithms for Finding the k Shortest Paths in a Network D. R. Shier National Bureau of Standards Washington, D.C.
ABSTRACT
This paper presents, wi thin a uni f ied framework, several neu aZgorithms fo r computing k shortest paths i n a network. These algorithms u t i l i z e s t ra teg ies which have proved t o be e f f i c i e n t i n solving shortest path probZems. computational study was conducted t o assess the e f f e c t s of the d i f f e ren t "arc processing" orders which are characteris t ic of each aZgorithm. Testing uas performed using generated classes of moderately large g r i d , compZete and random networks. Two particular aZgor i th s emerge as the most promising among those eua Zuated.
I n addition, a
1. INTRODUCTION
The need f o r ca l cu la t ing s h o r t e s t pa ths f requent ly a r i s e s i n the modeling of c e r t a i n phys ica l systems, such as those re- presented by t r anspor t a t ion , communication and d i s t r i b u t i o n networks. I n these s i t u a t i o n s , it i s o f t e n valuable t o be able t o f i n d the k s h o r t e s t paths . For example, knowledge of near ly optimal pa ths ( i n con t r a s t t o s h o r t e s t pa ths a lone) can be use- f u l i n t r anspor t a t ion planning a n a l y s i s , e spec ia l ly i n t h e assignment of t r a f f i c flows t o road networks [141. Other appl i - ca t ions using k s h o r t e s t pa ths a r i s e i n rout ing messages through a communication network o r shipping goods through a d i s t r i b u - t i o n network, when some of the l i n k s are temporarily obs t ruc ted o r unavailable. Moreover, ca l cu la t ion of k s h o r t e s t pa ths pro- vides a means of imposing add i t iona l cons t r a in t s on good solu- t i o n paths i n a network; as a p a r t i c u l a r app l i ca t ion , it i s poss ib le to so lve in t ege r l i n e a r programming problems by f ind- i ng the k s h o r t e s t pa ths i n c e r t a i n group-derived networks [4,181.
Networks, Vol. 9 (1979) 195-214 0028/3045/79/0009-Ol95$01 .OO 0 1 9 7 9 John Wiley & Sons, InC.
196 SHIER
Two versions of t h e k s h o r t e s t path problem have been in- ves t iga ted over the p a s t twenty years . s h o r t e s t path i s allowed t o contain repeated nodes; algorithms f o r t h i s type of problem have been descr ibed by seve ra l auth- o r s , most recent ly by Yen [201 and Lawle r [81. A second ver- s ion of the problem allows the k s h o r t e s t pa ths t o contain re- peated nodes, and it is t h i s s i t u a t i o n which represents t h e focus of the present paper.
The survey a r t i c l e s by Pollack [131 and Dreyfus 131 re- v i e w severa l so lu t ion methods f o r t h i s l a t t e r problem, proposed p r i o r t o 1969. Since t h a t t i m e a number of o the r algorithms f o r this same problem have appeared [4,10,15,171, some of which are based on an underlying a lgebra ic s t r u c t u r e discussed i n [ l l l . A s demonstrated i n [171, t h e a lgeb ra i c s t r u c t u r e appro- p r i a t e f o r the k s h o r t e s t path problem bears a marked s imi la r - i t y t o t h a t re levant f o r t he ordinary s h o r t e s t path problem. Accordingly, it is poss ib le t o modify seve ra l e x i s t i n g shor t - es t path algorithms i n order t o produce so lu t ion techniques f o r t he k s h o r t e s t pa th problem [10,171. Unfortunately, only a l imi ted amount of computational experience has been pub- l i shed concerning t h e e f f i c i ency of var ious so lu t ion methods f o r t he k s h o r t e s t pa th problem 116,171.
This paper develops a new c l a s s of so lu t ion methods f o r t he k s h o r t e s t path problem, one of which has been previously discussed and s tudied [16,171. These methods u t i l i z e strat- eg ie s which have proved t o be e f f i c i e n t i n solving s h o r t e s t pa th problems. In c o n t r a s t t o the approaches discussed i n [3] and 1131, t h e approach adopted here performs intermediate ca l - cu la t ions using path lengths and so does no t requi re an addi- t i o n a l bookkeeping e f f o r t t o keep t r ack of t he paths . More- over , t h e present approach has t h e p o t e n t i a l f o r making f u l l use of previously generated information [171.
For s h o r t e s t path algori thms, seemingly minor changes i n the implementation s t r a t e g y can e f f e c t a dramatic change i n computational e f f o r t [6 ,12] . That t h i s i s a l s o the case f o r k s h o r t e s t path algorithms i s i l l u s t r a t e d by the r e s u l t s of computational experiments reported i n t h i s paper. These ex- periments were conducted using t h e algorithms descr ibed i n Section 2 on moderately l a rge networks wi th th ree d i f f e r e n t network s t r u c t u r e s ( g r i d , complete and random). While a worst- case ana lys i s [171 ind ica t e s t h a t these algorithms are of roughly equal computational complexity (approximately
O(n k log n) ope ra t ions ) , t he r e s u l t s of Sect ion 3 show t h a t
these algorithms a r e not equal ly e f f i c i e n t i n p r a c t i c e .
I n one vers ion , no k
2 2 2
K SHORTEST PATH ALGORITHMS 197
The c l a s s of so lu t ion methods s tud ied here can be s t a t e d wi th in a un i f i ed framework and implemented using a common set of (modular) subroutines. For t h i s reason, t he Dreyfus al- gorithm [3,9], which works with pa ths d i r e c t l y and does no t f i t nea t ly i n t o t h i s un i f i ed scheme, has n o t been evaluated.
2. ALGORITHMS FOR THE k SHORTEST PATH PROBLEM
L e t G be a f i n i t e d i r ec t ed network i n which t h e arc ( i , j ) from node i t o node j is assigned t h e length a Node i of a r c
( i , j ) i s s a i d t o be ad jacent - t o node j , w h i l e node j i s s a i d t o be ad jacent from node i. A pa th f r o m node i t o node j i n t h e network i s an ordered sequence of a r c s [ (i,il) , (il,i2),
. . . , t i , j ) l ; a c i r c u i t is simply a path whose i n i t i a l node i
and terminal node j a r e the same. The length of a pa th i s de- f ined t o be the a r i thmet ic sum of the a r c lengths a long t h a t path.
pa ths between t w o spec i f i ed nodes of a network that have the smallest, t h e second smallest,... and t h e k-th smallest lengths . Any such pa th i s c a l l e d one of t h e k s h o r t e s t pa ths between t h e spec i f i ed o r i g i n and des t ina t ion nodes. A s def ined here , t he k s h o r t e s t pa ths a r e allowed t o conta in embedded c i r c u i t s . In order f o r t h e k s h o r t e s t path problem t o be phys ica l ly meaning- f u l , it i s required t h a t a l l c i r c u i t s i n t h e network have non- negat ive length. Furthermore, it w i l l be assumed t h a t t he net- work conta ins no loops or a r c s of the form (i,i) ; this is a s implifying and not e s s e n t i a l assumption f o r t h e procedures t h a t follow.
k s h o r t e s t pa ths from a given node i t o a given node j , but w i l l i n f a c t produce t h e k s h o r t e s t pa ths f r o m node i t o nodes j of a network. I n add i t ion , t hese s o l u t i o n methods f i r s t determine the k s h o r t e s t ( d i s t i n c t ) pa th lengths from t h e o r i g i n node i t o a l l nodes j , and then use such pa th length information t o recons t ruc t t he pa ths themselves. A desc r ip t ion of t h i s path- t racing procedure is given i n [161, where it i s a l s o assumed f o r s impl i c i ty t h a t a l l c i r c u i t s have s t r i c t l y p o s i t i v e length . Since seve ra l pa ths can achieve the same pa th length , it i s c e r t a i n l y poss ib l e t h a t more than k pa ths w i l l be generated from the k d i s t i n c t s h o r t e s t pa th lengths . Because it is r e l a t i v e l y s t ra ight forward t o recover the k s h o r t e s t pa ths from their pa th l eng ths , a t t e n t i o n w i l l focus i n t h i s paper on a l t e r n a t i v e methods f o r c a l c u l a t i n g the k d i s t i n c t s h o r t e s t pa th lengths from a given o r i g i n (usua l ly assumed t o be node 1 of the network).
i j '
-
m
The problem t o be considered here is t h a t of determining
The so lu t ion methods discussed here w i l l n o t only f i n d t h e
198 SHIER
One algorithm f o r computing t h i s information has been c a l l e d the Double-Sweep method and has been s tudied from both theo re t i ca l [171 and computational 1161 viewpoints. The Double-Sweep method proceeds by means of a l t e r n a t i n g forward and backward passes through the a r c s of t he network, and i s a genera l iza t ion o f t h e s h o r t e s t pa th algorithm of Yen 1191. The e s s e n t i a l d i f fe rence is t h a t one now dea ls with k-vectors of pa th lengths associated with each node, i n s t ead of t h e s i n g l e node l a b e l appropriate f o r Yen's s h o r t e s t pa th algorithm. The idea of using k-vectors ins tead of s ing le labels is c e r t a i n l y not r e s t r i c t e d t o the use of Yen's algorithm (see [11,171), and so it i s appropriate t o consider how one might s i m i l a r l y modify o the r e x i s t i n g s h o r t e s t pa th algorithms. The remainder of the present sec t ion w i l l show how t h i s can be done f o r a number of s h o r t e s t pa th algorithms t h a t appear t o be mst pro- mising. The bas i c d i s t i n c t i o n between t h e various k s h o r t e s t pa th algorithms t h a t r e s u l t l ies i n t h e sequence i n which the arcs of t he network are processed.
I t w i l l be convenient t o consider two broad ca tegor ies of k s h o r t e s t pa th algorithms, similar t o t h e c l a s s i f i c a t i o n d is - cussed i n [6] f o r s h o r t e s t path methods. Algorithms of t h e f i r s t type a r e ca l l ed labe l -cor rec t inp methods because they s t a r t with an i n i t i a l guess (upper bound) f o r t h e k s h o r t e s t pa th lengths and successively improve t h e t e n t a t i v e k s h o r t e s t pa th lengths u n t i l they correspond t o the a c t u a l k s h o r t e s t pa th lengths. Algorithms of t h e second type a r e c a l l e d label- s e t t i n g methods because they successively increase t h e number of components of t h e cu r ren t k-vectors assoc ia ted with nodes of the network which are ac tua l ly co r rec t ( i .e. , those which are i n f a c t equal t o t h e t r u e k s h o r t e s t pa th l eng ths ) . should be emphasized t h a t t he methods of t h i s l a t t e r c l a s s re- qu i r e t h a t t he a r c lengths a a l l be nonnegative, while t he
label-correcting methods remain v a l i d i f some a are negative.
W e w i l l now b r i e f l y discuss c e r t a i n k s h o r t e s t pa th a l - gorithms of these two types. A more d e t a i l e d discussion of the ordinary s h o r t e s t path methods on which these algorithms are based can be found i n [ 6 ] .
It
i j
ij
2 . 1 LABEL-COWCTING ALGORITHMS
Suppose f o r ease of exposit ion t h a t the k s h o r t e s t pa th lengths from node 1 t o a l l nodes j of an n-node network are re- quired. Then a t y p i c a l l abe l -cor rec t ing algorithm w i l l proceed according t o the following th ree s t eps :
K SHORTEST PATH ALGORITHMS 199
LC1. S t a r t with an i n i t i a l (upper bound) approximation t o t h e required k s h o r t e s t pa th lengths from node 1 t o each node j . That i s , assign a k-vector x ( j ) = (xjl ,xj2, . . . ,xjk) t o every
node j , where the entr ies of x ( j ) are l i s t e d i n increas ing order. While the re are seve ra l i n i t i a l approximations t h a t could be used t o begin t h e process, it is convenient t o use as an i n i t i a l guess
X U ) = (-0, m I . . . , -1
x ( j ) = (m, Q) ,..., a)) f o r j # 1.
LC2. Se l ec t a new a r c and then process t h e arc. By process- ing an arc ( i , j ) , w e mean t h a t t h e cu r ren t k-vector f o r node j w i l l be improved i f poss ib le by means of a pa th t o node j which extends f i r s t t o node i and which then uses t h e a r c ( i , j ) . More p rec i se ly , i f any of t he q u a n t i t i e s (xim + a .:m=l,...,k}
i J provides a smaller pa th length than any one of t he t e n t a t i v e k s h o r t e s t pa th lengths i n x ( j ) , then t h e cu r ren t k-vector x ( j ) i s updated by inc lus ion of t h i s smaller pa th length. It is t o be understood t h a t all such poss ib l e updatings of x ( j ) using x ( i ) are performed when processing arc ( i , j ) .
LC3. Check the termination c r i t e r i o n . I f s a t i s f i e d s top , otherwise r e tu rn t o Step LC2.
W e w i l l now discuss four algorithms of t h e label-correct- i n g var ie ty . I t i s again noted t h a t such algorithms remain v a l i d even when t h e r e a r e some a < 0 , as long as t h e network i j under consideration has no c i r c u i t s of negative length. When t h e algorithms terminate, no k-vector can be improved and the cur ren t k-vectors represent t h e des i red k s h o r t e s t pa th lengths t o the corresponding nodes.
2 .2 BASIC LABEL-CORRECTING (BLC) ALGORITHM
This method processes t h e arcs of the network i n a fixed order: namely, i n increas ing o rde r by t h e i n i t i a l node of each a rc . Thus, a r c s emanating from node 1 are processed before those emanating from node 2 , and so f o r t h . I f a t some s tage a node contains t h e label (m,m,...,m), then no a r c s emanating from that node are processed since no improvements can r e s u l t by using such a l abe l . It is usefu l t o group the a r c s by t h e i r i n i t i a l node. Accordingly, w e s h a l l examine nodes i n the fixed order 1 , 2 , . . . ,n and s h a l l sk ip the examination of a node i f i t s label i s (m,m, ...,a 1 . Here t h e examination of a node simply
200 S H I E R
e n t a i l s t he processing of a l l arcs emanating from t h a t node. F ina l ly , t he algorithm w i l l terminate when a f te r examining a l l nodes 1 ,2 , . . . ,n it is found t h a t none of the components of t h e cu r ren t k-vectors have changed from t h e i r previous l eve l s . An o u t l i n e of t h e method i s given below.
B L C ~ . S e t X U ) = ( o p , ... , m ) , X(J) = (m,m,...,m) f o r J f 1. S e t NODE = 1.
BLC2. I f x(N0DE) = (m,~,...~m) then go t o BLC3. Otherwise, begin examination of NODE: For a l l J ad jacent from NODE, process the a r c (NODE, J) .
BLC3: I f NODE < N then NODE -+ NODE + 1 and go t o BLC2. Otherwise, tes t i f any k-vector x ( J ) has been changed i n Step BLC2 s ince the l a s t t e s t .
I f t he re has been a change, set NODE = 1 and go t o BLC2. Otherwise , s top .
The steps ind ica t ed above only give a general statement of the bas i c labe l -cor rec t ing method, and f u r t h e r d e t a i l s a r e c l e a r l y necessary before an a c t u a l implementation can be speci- f i ed . For example, t h e p rec i se way i n which a r c s are t o be processed and the procedure f o r e f f i c i e n t l y updating the cu r ren t k-vectors have not been spe l l ed o u t i n t h e above. Generally, such d e t a i l s follow the procedures and guide l ines which have been discussed i n r e l a t i o n t o the Double-Sweep method 1161 and t h e i n t e r e s t e d reader i s d i r ec t ed to t h a t source. Accordingly, t h e various algori thmic descr ip t ions i n t h i s paper w i l l usua l ly be phrased i n r a t h e r broad terms, and t h i s w i l l more c l e a r l y h igh l igh t t h e e s s e n t i a l d i f f e rences among t h e algorithms.
A s an example of the BLC algori thm, consider t he 5-node network given i n Figure 1, where the k=3 s h o r t e s t pa th lengths from node 1 a r e required. The r e s u l t s of applying t h e algorithm t o t h i s network a r e given i n Table 1. Termination i s achieved a f t e r t h ree passes through the a r c l i s t , each pass e n t a i l i n g the examination of nodes l , . . . , n I and the f i n a l row of Table 1 ind ica t e s t he required k=3 s h o r t e s t pa th lengths . For b r e v i t y , only non in f in i t e path lengths have been recorded i n T a b l e 1.
2 . 3 ALTERATION FLAG (AF) ALGORITHM
This method i s a simple modification o f the BLC algorithm: namely, t h e examination of a node is skipped i f t h e k-vector assoc ia ted with t h a t node has n o t changed s ince the previous
K SHORTEST PATH ALGORITHMS 201
NODE EXAMINED
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Fig. 1. Example f o r BLC Algorithm
THE K = 3 TENTATIVE PATH LENGTHS TO NODE
1 2 3 4 5 ( 0 )
( 0 ) (3) (10) (8) - ( 0 ) (3) (10) ( 5 , 8) (15) ( 0 ) (3) (10) (5, 8, 12) (15, 16)
( 0 , 9, 12) (3) ( 7 , 10, 14) ( 5 , 8, 12) (9, 12, 15) ( 0 , 9, 12) (3) (7, 10, 14) (5, 8, 12) (9, 12, 15) ( 0 , 9, 12) (3, 12, 15) ( 7 , 10, 14) ( 5 , 8 , 12) (9, 12, 15) ( 0 , 9, 12) (3, 12, 15) (7, 10, 14) (5, 8, 12) (9, 12, 15) ( 0 , 9, 12) (3, 12, 15) (7, 10, 14) ( 5 , 8, 9) (9, 12, 13) ( 0 , 9, 12) (3, 12, 15) ( 7 , 10, 11) ( 5 , 8 , 9) (9, 12, 13) ( 0 , 9, 12) (3, 12. 15) (7, 10, 11) (5, 8, 9) (9, 12, 13) ( 0 , 9 , 12) (3, 12, 15) (7, 10, 11) ( 5 , 8, 9) (9, 12, 13) ( 0 , 9, 12) (3, 12, 15) ( 7 , 10, 11) ( 5 , 8, 9) (9, 12, 13) ( 0 , 9, 12) (3, 12, 15) ( 7 , 10, 11) ( 5 , 8, 9) (9, 12, 13) ( 0 , 9, 12) (3, 12, 15) ( 7 , 10, 11) ( 5 , 8, 9) (9, 12, 13) ( 0 . 9. 12) (3, 12, 15) (7. 10. 11) (5. 8, 9) (9, 12. 13)
- - - -
T a b l e 1
Computations for t h e BLC A l g o r i t h m
examination of t he node. N o t e t h a t t h e BLC algori thm tests i f t h e cu r ren t node l a b e l is ( m , ~ , ...,m 1; s ince elements of t he k-vector a r e l i s t e d i n increas ing o rde r , it s u f f i c e s then t o check i f t h e f i r s t component of the node label is equal t o m.
By con t ra s t , the AF algorithm as soc ia t e s a " f lag" T ( j ) wi th every node j of the network: T ( j ) = 0 i n d i c a t e s t h a t no change has been made t o any component of the label for node j s ince the last examination of node j, while T ( j ) = 1 ind ica t e s t h a t s o m e change has occurred. ithm follows the steps of t he BLC algorithm.
In a l l o the r r e spec t s , t he A F a lgor-
202 SHIER
AF1. Set x (1 ) = ( O , m , . . . I m ) , T ( 1 ) = 1 and x ( J ) = ( m t m t - . . I m ) I
T(J) = o f o r J # 1. S e t NODE = 1.
A F 2 . I f T(N0DE) = 0 then go t o AF3. Otherwise, begin examina- t i o n of NODE: For a l l J ad jacent f r o m NODE, process the a r c (NODE, J) . I f any change occurs to the l a b e l on node J , s e t T ( J ) = 1. S e t T(N0DE) = 0.
A F 3 . If NODE < N then NODE -t NODE + 1 and go t o AF2. Other- w i s e , t e s t i f any k-vector x(J ) has been changed i n Step AF2 s ince t h e l a s t test .
If the re has been a change, set NODE = 1 and go t o AF2. Otherwise , s top .
2 . 4 DOUBLE-SWEEP ( D S ) ALGORITHM
This method represents another v a r i a n t of the BLC a lgor i - thm. Instead of examining t h e nodes i n the same o rde r 1 , 2 , . * . , n during every i t e r a t i o n , t h e Double-Sweep method em- ploys a sequence of a l t e r n a t i n g forward and backward i t e r a t i o n s . During the forward i t e r a t i o n the nodes a r e examined i n the order 1 ,2 , . . . ,n , while during the backward i t e r a t i o n the nodes a r e examined i n the order nr . . . ,2 ,1 . Moreover, when examining a node j during t h e forward i t e r a t i o n , only arcs ( i , j ) with i C j a re processed. S imi la r ly , only arcs (i, j ) with i > j a r e processed during t h e backward i t e r a t i o n . These a l t e r n a t - ing forward and backward i t e r a t i o n s are continued u n t i l no i m - provement i n the cur ren t k-vectors i s poss ib le . More p rec i se ly , termination occurs when the node labels a t t h e end of itera- t i o n t i o n
D S 1 .
DS2 .
DS3.
DS4.
DS5.
t + 1 coincide with the node labels a t t h e end of itera- t , t - > 0. An o u t l i n e of this procedure i s given below.
S e t x ( 1 ) = (O,m,...,m), x(J ) = (m,mI. . . Im) f o r J # 1.
Let NODE = 2 , . . . , N . For a l l I < NODE which are adjacent t o NODE, process the arc ( 1 , N O D E ) .
Test i f any node labels x(J) have changed during Step D S 2 . If a l l a r e unchanged, s top .
L e t NODE = N - l , . . . , l . For a l l I > NODE which are adja- cent t o NODE, process t h e a r c (1,NODE).
T e s t i f any node labels x ( J ) have changed during Step DS4. If a l l a r e unchanged, s top ; otherwise, go t o DS2.
K SHORTEST PATH ALGORITHMS 203
2.5 SEQUENCE LIST (SL) ALGORITHM
This method i s a th i rd var iant of the BLC algorithm. Un- l i k e the BLC algorithm, nodes are no longer examined i n a fixed order. Rather, a l i s t of nodes i s generated and a t each stage the next node on the l i s t i s examined. Once a node i s examined, a l l arcs emanating from the node are processed, whereupon the given node is removed from the sequence list. Nodes j are entered on the sequence l ist (on a FIFO bas is ) whenever the processing of a rc ( i , j ) r e su l t s i n a change i n some component of x ( j ) and node j i s not already on the l is t . Nodes are taken i n sequence from the l i s t and termination oc- curs when the l ist is empty. The basic s teps of the SL algo- rithm proceed as follows.
sL1. S e t x ( l ) = (0,- ,..., -1, X(J) = (-,- ,..., m) f o r J # 1. Put node 1 on the sequence list.
SL2. Remove the "top" node I from the list. Examine node I: For a l l J adjacent from I , process arc (1,J). I f any change occurs t o the labe l on node J and i f node J is not already on the l i s t , then add J t o the "bottom" of the l is t .
SL3. If there i s another node s t i l l on top of the l i s t , go t o Step SL2. Otherwise, stop.
Certain d e t a i l s have been omitted from the above descrip- t ion , and a f e w remarks should be made about the spec i f ic im- plementation of SL t h a t w i l l be investigated i n Section 3. F i r s t , t o detect whether i n SL2 node J is already on the l i s t , one can use a f l ag T ( J ) j u s t a s i n Algorithm AF. Second, it is useful t o consider the sequence l i s t as a " ro ta t ing l is t" of length N. That is , two pointers are used t o ind ica te the cur- ren t top and bottom posit ions on the list. These pointers a r e successively moved down the l i s t u n t i l the las t posi t ion N is encountered, a f t e r which the pointer jumps t o posi t ion 1 of the l i s t , thus creat ing a c i r cu la r e f f ec t . Final ly , it should be noted t h a t i n contrast t o the other label-correcting algorithms discussed here, the actual execution of the SL algorithm w i l l be sensi t ive t o the order i n which the arcs emanating from node I ( in Step SL2) are processed.
2.6 LABEL - SETTING ALGORITHMS
Label-setting algorithms are appropriate for finding k
204 SHIER
s h o r t e s t path lengths i n networks with nonnegative arc lengths. Such algorithms represent s u i t a b l e genera l iza t ions of t he labe l - s e t t i n g s h o r t e s t path algorithm of Di jks t r a [2]. For the labe l - cor rec t ing algorithms previously given i n this sec t ion , t he co r rec t k s h o r t e s t pa th lengths are found simultaneously; t h a t is t o say, it is not poss ib le to recognize t h a t a c e r t a i n com- ponent of t h e k-vector f o r a c e r t a i n node has the c o r r e c t value u n t i l t he e n t i r e procedure has terminated. In t h i s sense, it i s not noticeably e a s i e r t o f ind the k s h o r t e s t pa th lengths between t w o given nodes than t o f i n d the k s h o r t e s t path lengths from one given node t o a l l o thers . By con t r a s t , t he label- s e t t i n g algorithms proceed sequent ia l ly and i d e n t i f y a t each s t e p a new co r rec t component of some k-vector i n t h e f i n a l so lu t ion . Such a component value is s a i d t o be permanent, i n con t r a s t t o a temporary component which has not y e t been guar- anteed t o be a t t he optimal l e v e l . Thus, i n f ind ing k short- est pa th lengths from a given o r i g i n node, the co r rec t k shor t - est path lengths t o some given des t ina t ion node w i l l be found when a l l components of t he des t ina t ion ' s k-vector are declared permanent. This s i t u a t i o n may occur considerably sooner than when a l l k sho r t e s t pa th lengths from t h e o r i g i n t o a l l nodes are determined (i .e. , when a l l k-vector components are perm- anent ) .
In what follows, it w i l l be supposed t h a t node 1 i s the given o r i g i n node and t h a t t he k s h o r t e s t pa th lengths t o a l l nodes of an n-node network a r e ' t o be found. The bas i c s t e p s used by l abe l - se t t i ng algorithms are ou t l ined below. noted t h a t a l i s t i s maintained a t each s t age t o ind ica t e which nodes s t i l l have temporary components i n t h e i r k-vector l abe l . I n i t i a l l y , a l l components are considered t o be t e m - porary, and one by one c e r t a i n of these labels a r e declared permanent u n t i l no temporary labels remain. I n the descrip- t i o n t h a t follows, A ( 1 , J ) is used to denote the nonnegative a r c length a:;.
I t i s
LS1.
LS2.
LS3.
A J
Set x(1) = ( 0 , ~ ,..., w ) , x ( J ) = ( m , m ,..., -1 f o r J # 1. Put a l l nodes on t h e l ist (a l l components are made tem- porary) and s e t I = 1.
Find t h e smallest temporary component TEMP f o r node I. For each node J adjacent from I, i n s e r t i f poss ib l e the value TEMP + A ( 1 , J ) i n t o the k-vector f o r node J.
Make permanent t he component TEMP f o r node I. Remove node I from the l i s t i f t he re are no more temporary com- ponents f o r t h a t node.
K SHORTEST PATH ALGORITHMS 205
LS4: I f t he l i s t i s empty, s top . Otherwise, l o c a t e a node I whose smallest temporary component i s minimum over a l l nodes i n t h e l ist , and go t o Step LS2.
There are several poss ib l e ways t o implement the above l a b e l - s e t t i n g algorithm. Gi l s inn and Witzgal l [ 6 ] i n d i c a t e seve ra l a l t e r n a t i v e approaches i n the context of s h o r t e s t path algori thms, and t h e i r computational r e s u l t s show t h a t a p a r t i c u l a r v a r i a n t [1,71 performs extremely w e l l . Motivated by this v a r i a n t ' s success i n s h o r t e s t pa th problems, w e w i l l de- s c r i b e a modification appropr ia te f o r k shortest pa th problems.
F i r s t , s ince the components of each vector are assumed t o be kept i n s t r i c t l y increas ing o r d e r , t he permanent components for any node w i l l always precede the temporary components. Moreover, the smallest temporary component w i l l always be t h e f irst temporary component appearing i n t h e k-vector, and so an appropriate po in t e r can be set f o r each node t o i n d i c a t e t h i s f i r s t temporary component pos i t i on . Second, it i s only nec- essary t o keep a l i s t of those nodes whose f irst temporary component is f i n i t e (< m 1. If one f u r t h e r makes t h e assump- t i o n t h a t a l l a r c lengths a r e nonnegative i n t e g e r s , then it is only necessary t o keep a l i s t whose length is equal t o the maximum a r c length p lus one [ 6 ] . I n o rde r t o avoid t h e nec- e s s i t y of s o r t i n g i n S tep LS4 (a r e l a t i v e l y time-consuming chore ) , t he algorithm pu t s a node i n a list p o s i t i o n which is indica ted by t h e value of t he f i rs t temporary component f o r t h e node, modulo the maximum arc length p lus one. Thus a "ro- t a t i n g l ist" of t he type encountered i n Algorithm SL i s em- ployed. I n case the re a r e seve ra l nodes w i t h t he same tempor- a r y component value, po in t e r s a r e used t o "chain" the nodes having equal component values.
With t h i s p a r t i c u l a r implementation i n mind, t h e above s t e p s of t h e labe l -cor rec t ing method are c a r r i e d o u t , adding and de le t ing nodes a s necessary from the l i s t . In Step LS1, only node 1 is i n i t i a l l y p u t on the l ist . I n Step LS2, node I should f i r s t be de le ted from the l i s t and node J should be re- pos i t ioned on the l i s t i f i t s f irst temporary component is changed by the i n s e r t i o n . Af t e r the component TEMP is made permanent i n Step LS3, a new f i r s t temporary component ( i f one exists) i s loca ted for node I and node I w i l l be re-entered on the l i s t i f t h i s new temporary component i s f i n i t e . F ina l ly , t h e search f o r a node with minimum first temporary component is accomplished by simply moving through t h e l i s t u n t i l t he next node is encountered, s ince nodes automatical ly appear on the l i s t i n o rde r by (nondecreasing) temporary component value.
206 SHIER
Another va r i an t of t h e bas i c type of l abe l - se t t i ng algo- rithm described a t t h e beginning of t h i s s ec t ion has been d is - cussed by Rubin 1151. Unlike t h e implementation given here , Rubin's method i s o r i en ted more towards t h e manipulation of t he paths themselves and not simply the d i s t i n c t pa th lengths , as considered here. Whenever t h e r e are several pa ths having the same length , such paths have t o be considered separa te ly i n Rubin's scheme and s to red separa te ly i n lists. t h a t Rubin's method e x p l i c i t l y requi res s o r t i n g a l i s t of n e lements during Step LS4, while t he preserit method avoids ex- p l i c i t s o r t i n g by using t h e s p e c i a l l i s t defined by temporary component values. I n addi t ion , Rubin's method requi res approx- imately (3k+l) n s torage loca t ions f o r working a r r ays , while the " ro t a t ing l is t" method described here requi res only (k+4) n loca t ions p lus s torage f o r an a r r ay whose s i z e i s the maximum a r c length p lus one.
It is noted
3 . COMPUTATIONAL RESULTS
A l l f i v e of t h e algorithms described i n Section 2 (BLC, A F , D S , SL and LS) were coded i n FORTRAN V and run on a UNIVAC 1108 computer. (FORTRAN V i s UNIVAC's augmented version of standard FORTRAN I V . ) A l l programming w a s done by one person and as f a r as was poss ib le the same subroutines w e r e used t o perform common operations: e.g., "processing an arc" i n t he label-correcting methods. Coding w a s done so t h a t the k shor t - es t ( d i s t i n c t ) path lengths from an a r b i t r a r y o r i g i n could be determined.
I n order t o tes t the r e l a t i v e e f f i c i e n c i e s of these f i v e algorithms, t h ree d i f f e r e n t types of network s t ructure w e r e investigated.
s ists of n=pq nodes, assumed t o be numbered consecutively from lef t t o r i g h t and top t o bottom. node immediately above , below, t o t h e l e f t o r t o t h e r igh t .
nodes, any d i s t i n c t p a i r of which are joined by an a rc . a r e n(n-1) arcs i n a l l .
(1) Rectangular Grid Networks: a p x q g r i d network con-
A r c s j o i n a given node t o any
( 2 ) Complete Networks: a complete network cons i s t s of n There
(3) Random Networks: a random (connected) network con- sists of n nodes with a spec i f i ed number m of arcs. A spanning tree rooted a t the o r i g i n node is f i r s t c rea ted by randomly joining a node i n t h e cu r ren t (non-spanning) tree t o a node not i n the tree. Then a l l remaining arcs are generated by jo in ing two d i s t i n c t nodes chosen randomly from the n , u n t i l a t o t a l
K SHORTEST PATH ALGORITHMS 207
of m arcs have been generated. have mul t ip le a r c s between two spec i f i ed nodes i n t h e r e s u l t - i ng network. i n t e g e r s , uniformly generated over the range 1 t o 100.
T a b l e s 2-5 p re sen t t imings t i n CPU seconds) for a series of computational experiments designed t o s tudy the re la t ive e f f i c i e n c i e s of t h e f ive algorithms as cu r ren t ly implemented. The timings given represent e lapsed computation t i m e (exclu- s i v e of input and output opera t ions) requi red t o c a l c u l a t e t he k=5 s h o r t e s t pa th lengths f r o m node 1 t o a l l other nodes. A range of s m a l l t o medium-sized networks having g r i d (square/ rec tangular ) , complete and random s t r u c t u r e s w e r e considered. Resul ts given i n these and subsequent tables a r e based on t i m - ings for a s i n g l e network of t h e s i z e and type spec i f i ed .
T a b l e s 2 and 3 i n d i c a t e t h a t Algorithms AF, LS and SL perform the best f o r square g r i d networks and t h a t Algorithm LS c l e a r l y dominates a l l o the r s as the g r i d s become more and more elongated. It i s of i n t e r e s t t o note t h a t DS and espec- i a l l y BLC a r e never r e a l l y competit ive here with the o t h e r al- gorithms. However, t h e extremely s i m p l e modif icat ion of using an a l t e r a t i o n f l a g i n t h e bas i c labe l -cor rec t ing method pro- duces a competit ive k s h o r t e s t pa th algori thm AF, a t l e a s t i n t h e case of square g r i d networks. For complete networks (with up t o 70 nodes and 4830 a r c s ) , t he DS a lgori thm is c l e a r l y the b e s t , as ind ica t ed by T a b l e 4. The r e s u l t s of T a b l e 5 are based on var ious random networks having m = 3000 a r c s , and are arranged i n o rde r of decreasing dens i ty , measured as the aver- age number of arcs p e r node. b e s t f o r networks having high d e n s i t i e s (10 or more arcs/node), while Algorithm LS is b e s t f o r networks having low d e n s i t i e s (fewer than 10 arcs/node).
throughout t h e r e s u l t s given i n Tables 2-5, This i s , q u i t e simply , t h a t Algorithm DS r equ i r e s t he least computation t i m e f o r high-density networks ( i . e . , complete and high-density ran- dom) while Algorithm LS requi res the least computation time f o r low-density networks (i.e., g r i d and low-density random). Thus, t he f i e l d of f i v e algorithms has narrowed down t o t w o r a t h e r promising ones. m o s t important f a c t o r i n determining which of t h e two algori thms is appropr ia te f o r a given s i t u a t i o n . Since t r anspor t a t ion and communication networks a r e genera l ly spa r se , Algorithm LS would appear wel l -sui ted f o r app l i ca t ion i n these circumstances.
a s e r i e s of add i t iona l experiments w e r e performed i n which the
Note t h a t it i s poss ib l e t o
I n a l l networks arc lengths w e r e chosen t o be
I t is seen tha t Algorithm DS i s
One genera l , and f a i r l y accura te , conclusion p e r s i s t s
The dens i ty of t h e network seems t o be t h e
I n order t o study f u r t h e r the behavior of these algori thms,
208 SHIER
parameter k w a s allowed t o vary from 4 t o 20. Elapsed compu- t a t i o n times were determined f o r f ind ing k s h o r t e s t pa th lengths from node 1 i n a number of d i f f e r e n t networks, again having i n t e g r a l a r c lengths uniformly generated from 1 t o 100. The networks chosen f o r study w e r e a 16 X 16 square g r i d , a 64 x 4 elongated g r i d , a 30-node complete, a 50-node/lOOO-arc random and a 200-node/1000-arc random network. I n a l l cases, the previous conclusions based on k=5 about t h e b e s t algorithms f o r such s i t u a t i o n s remained t r u e over the range of values of k s tud ied (k=4,8,12,16,20). Spec i f i c t imings are given for t h e b e s t algorithm i n Table 6; i n every ins tance , t h e b e s t algorithm turned ou t t o be e i t h e r LS o r D S , when t h e e n t i r e range of k values w a s considered.
w i t h k is obtained by f i t t i n g the da ta of T a b l e 6 t o a model of the form
A f a i r l y good idea of how t h e computation t i m e T varies
B T = A k .
T a b l e 2
Timings ( i n secs . ) for Algorithms on P X P
Grid Networks, k = 5
K SHORTEST PATH ALGORITHMS 209
P x Q
24 x 24
32 x 1 8
64 x 9
144 x 4
BLC AF DS SL LS
2.902 1.324 2.838 1.297 1.210
3.185 1 .194 1.746 1.147 1.111
5.426 3.148 3.188 2.909 1.277
6.575 3.371 3.897 3.265 1.127
T a b l e 3
T i m i n g s ( i n s e c s . ) for A l g o r i t h m s on P x Q G r i d Networks, k = 5
n
10
20
30
40
50
60
70
BLC AF
.054 .048
.155 .135
.420 .326
.706 .406
1.119 .730
1.849 1.076
2.598 1.458
T a b l e 4
Timings ( i n secs.) f o r A l g o r i t h m s on n-node C o m p l e t e N e t w o r k s , k = 5
210 SHIER
BEST ALGORITHM NETWORK
LS 16 x 16 GRID
64 x 4 GRID
RANDOM (n - 200, m = 1000)
DS RANDOM (n - 50, m = 1000)
30-NODE COMPLETE
400 7.5
500
600
7 50
1000
4
.375
.359
.360
.164
.099
- BLC
- 1.388
1.879
2.325
2.821
2.654
4.000
4.130
3.447 -
AF
.987
1.225
1.517
1.755
1.748
2.183
2.654
2.327
DS
.515
.800
1.094
1.309
1.488
2.026
2.243
2.298 -
SL
1.002
1.112
1.645
1.558
1.661
1.931
2.416
2.029
- LS
.936
1.072
1.161
1.225
1.315
1.372
1.728
1.658
+ The density d is defined as t h e r a t io of arcs to nodes.
Table 5
Timings ( i n secs.) for Algorithms on Random Networks with m = 3000, k = 5
I - 8
.869
,822
.820
-
.291
.226 -
Value of k
1.405 2.117
1.395 2.092
.372
Table 6
Timings ( i n secs.) fo r Best Algorithms On Selected Networks, Varying k
20 3.138
2.950
2.902
1.120
.876
K SHORTEST PATH ALGORITHMS 211
This seems an appropriate func t iona l form, inasmuch as T=O when k=O. The unknown parameters t o be est imated, A and B, should both be p o s i t i v e and t h e i r a c t u a l values were est imated by per- forming a simple l i n e a r regress ion on t h e transformed equation
log T = a + B(log k ) .
T h e es t imated values f o r a,B toge ther with the est imated stand-
and the R2 c o e f f i c i e n t of determination B a rd devia t ions s
are presented i n T a b l e 7. I n the worst case, 97.5% of t h e var- i a t i o n w a s explained by t h e regress ion , i nd ica t ing t h a t an ex- c e l l e n t f i t t o t h e model w a s found. The small values ind ica t ed by s a and s
the unknown a and 8 are q u i t e narrow.
a l s o show t h a t t he 95% confidence i n t e r v a l s f o r B
I SUMMARY REGRESSION STATISTICS I
T a b l e 7
Summary S t a t i s t i c s for Regression Model Using Se lec ted Networks
The est imated values f3 a r e of most i n t e r e s t t o us here i n observing t h e behavior of the algorithms as a func t ion of k. The r e s u l t s of Table 7 show t h a t for the 30-node complete net-
work, Algorithm DS requi res O(k ) opera t ions , while f o r t h e
high-density random network, Algorithm DS i s O(k 1. On the
o the r hand, Algorithm LS i s O(k1.29) f o r the low-density random
network, 0 (k ) f o r t h e square g r i d network and 0 (k 1 f o r the elongated g r i d network.
emphasize t h a t t w o algorithms of t h e f ive considered here em- erged as the most e f f i c i e n t f o r so lv ing k s h o r t e s t pa th pro- blems i n g r i d , complete and random networks: t h e Double-Sweep and the Label-Sett ing algorithms. t h e Double-Sweep method f a red t h e b e s t i i n complete networks
1.34
1.18
1 .32 1.31
To summarize t h e computational r e s u l t s o f t h i s s ec t ion , w e
For high-density networks,
212 SHIER
(a worst case i n many r e spec t s f o r pa th algori thms) t h i s method
requi res 0 (k’.’) operat ions , while i n high-density random net-
works it requi res O(k ) operat ions. For low-density networks, the Label-Setting algorithm performed t h e b e s t , r equ i r ing
0 ( k l . 3, operat ions i n g r i d and low-density random networks. I n the cases s tud ied here , t h e r e appeared t o be an e x c e l l e n t
f i t of computation t i m e t o t he model T = Ak . These f indings have been based on t h e study of networks
wi th i n t e g r a l a r c lengths uniformly generated over t h e range 1 t o 100. While a previous computational study [161 has found t h a t t he choice of arc length range can a f f e c t absolu te com- puta t ion t i m e s , there i s no reason t o be l i eve t h a t r e l a t i v e algorithm performance w i l l be e spec ia l ly s e n s i t i v e t o t h e range chosen.
O f course, these computational gu ide l ines may have t o be weighed aga ins t t he d i f f e r i n g s torage requirements of the a l - gorithms. Accordingly, Table 8 provides a summary of these s torage requirements (number of computer words), expressed i n terms of N = number of nodes, A = number of a r c s , K = value of k , and L = maximum ( i n t e g r a l ) a r c length. I t i s i n t e r e s t i n g t o note t h a t t he cons tan t terms i n each of these expressions a r e f o r all p r a c t i c a l purposes equal . Thus, t h e d i f f e r i n g s torage requirements are r e f l e c t e d i n t h e d i f f e r i n g number of node-length a r rays used by the var ious codes. A s T a b l e 8 in- d i c a t e s , BLC has the smal les t s torage requirements, followed by A F and D S , by SL, and f i n a l l y by LS (with t h e l a r g e s t stor- age requirements).
1.2
B
ALGORITHM STORAGE (words) * BLC N + 2 A + NK + K + 6912
A F 2 N + 2.4 + NK + K + 6986
DS 2 N + 2A + NK + K + 1065
SL 3N + 2A + NK + K + 7006
LS 5N + 2A + NK + L + 7098
*Expressed i n terms of N=nUmber of nodes, A=nUmber o f a r c s , K=value of k, and L=maximum arc length.
Table 8
Storage Requirements f o r the Five Algorithms
K SHORTEST PATH ALGORITHMS 213
ACKNOWLEDGEMENTS
The author g r a t e f u l l y acknowledges t h e cons t ruc t ive and useful. suggestions of t h e re ferees .
4.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
REFERENCES
D i a l , R.B., "Algorithm 360: Shor tes t Path Fores t with Topological Ordering", Corn. ACM, V o l . 12, 1969, 632-633.
Di jks t r a , E.W., "A Note on Two Problems i n Connexion with Graphs", Nm. Math., Vol. 1, 1959, 269-271.
Dreyfus, S.E., "An Appraisal of Some Shortest-Path Algor- ithms",Operations Research, Vol. 17, 1969, 395-412.
Fox, B.L., "Calculating k t h Shor tes t Paths", INFOR., Vol. 11, 1973, 66-70.
Fox. B.L., "More on k t h Shor tes t Paths", C o r n . ACM., Vol. 18, 1975, 279.
G i l s i n n , J. and C. Witzgall , "A Performance Comparison of Labeling Algorithms fo r Calcu la t ing Shor t e s t Path Trees", Technical N o t e 772, National Bureau of Standards, Washington, D.C., 1973.
Hitchner, L.E., "A Comparative Inves t iga t ion of t h e Com- pu ta t iona l Efficiency of Shor tes t Path Algorithms", Report ORC 68-25, Operations Research Center , University of C a l i f o r n i a , Berkeley, 1968.
Lawler, E.L., "A Procedure f o r Computing the K B e s t Solu- t i o n s t o Discrete Optimization Problems and i ts Applica- t i o n t o Shor tes t Path Problems", Management Science, V o l . 18, 1972, 401-405.
Lawler, E.L., COmbinatOrYiaZ Optimization, Holt, Reinhart and Winston, New York, 1976.
Minieka, E . , "On Computing S e t s of Shor t e s t Paths i n a Graph", Corn. ACM, Vol. 17, 1974, 351-353.
Minieka, E. and D. Sh ier , "A Note on an Algebra f o r t he k B e s t Routes i n a Network", J . Inst. Math. AppZ. , V o l . 11, 1973, 145-149.
214
12 .
13.
14.
15.
16.
17.
18.
19.
20.
SHIER
Pape, U . , "ImpLementation and Efficiency of Moore-Algor- ithms f o r t h e Shor tes t Route Problem", MathematieaZ Pro- graming, vol. 7 , 1974, 212-222.
Pollack, M . , "Solutions of t h e k th B e s t Route Through a Network - A Review", J . Math. AnaZ. AppZ., Vol. 3, 1961, 547-559.
P o t t s , R.B. and R.M. O l i v e r , F ~ a i t s in !Transportation Net- works, Academic Press , N.Y. , 1972.
Rubin, F. , "An Algorithm f o r Finding the k Shor t e s t P a t h s i n a Graph", Working Paper, IBM Systems Development Divi- s ion , Poughkeepsie, N.Y., 1975.
Shier , D.R. , "Computational Experience with an Algorithm f o r Finding the k Shor tes t Paths i n a Network", s. Res. NatZ. Bur. Stand., vol. 78B, 1974, 139-165.
Shier , D.R. , " I t e r a t i v e Nethods f o r Determining t h e k Shor tes t Paths i n a Network", Networks, Vol. 6 , 1976, 205-229.
White, W.W., "On a Group Theoretic Approach t o Linear In teger Programming" , Report ORC 66-27, Operations Re- search Center, University of Ca l i fo rn ia , Berkeley, 1966.
Yen, J . Y . , "Some Algorithms f o r Finding the Shor t e s t Routes Through t h e General. Networks", L.A. Zadeh, L.W. Neustadt and A.V. Balakrishnan (Eds.) , Computing Methods i n Optimization ProbZems - 2, Academic Press, N.Y. 1969, 377-388.
Yen, J . Y . , "Finding the K Shor t e s t Loopless Paths i n a Network", Management Science, Vol. 17, 1971, 712-716.
Received Deeember 1977; Revised May 1978