calculating a path algorithm

Upload: redgoriya

Post on 14-Apr-2018

236 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Calculating a Path Algorithm

    1/13

    C a l c u l a t i n g a P a t h A l g o r i t h mR o l a n d C . B a c k h o u s e a n d A . J .M . v a n G a s t e r e n

    D e p a r t m e n t o f M a t h e m a t i c s a n d C o m p u t i n g S c ie n ce ,E i n d h o v e n U n i v e r s i ty o f T e c h n o lo g y ,P . O . B o x 51 3 , 5 6 00 M B E i n d h o v e n ,T h e N e t h e r l a n d s .

    A b s t r a c t . A c a l c u l a t io n a l d e r i v a ti o n i s g iv e n o f a n a b s t r a c t p a t h a l g o r i t h m ,o n e i n s ta n c e o f t h e a l g o r i t h m b e i n g D i j k s t r a ' s s h o r t e s t - p a t h a l g o r i t h m , a n -o t h e r b e i n g b r e a d t h - f i r s t / d e p t h - f i r s t s e a r c h o f a d i re c t e d g r a p h . T h e b a s i s f o rt h e d e r i v a t i o n i s t h e a l g e b r a o f r e g u l a r l a n g u a g e s .

    1 P r o b l e m S t a t e m e n tG i v e n i s a ( n o n - e m p t y ) s e t N a n d a I N I x I N I m a t r i x A , t h e r o w s a n d c o l u m n so f w h i c h a r e in d e x e d b y e l e m e n t s o f N . I t is a s s u m e d t h a t t h e m a t r i x e l e m e n t s a r ed r a w n f r o m a r e g u l a r a l g e b r a 1 ( S , + , . , * , 0 , 1 ) h a v i n g t h e t w o a d d i t i o n a l p r o p e r t i e st h a t

    ( 1 ) t h e o r d e r i n g < i n d u c e d ~ b y + i s a t o t a l o r d e r i n go n t h e e l e m e n t s o f S , a n d( 2 ) 1 i s t h e l a r g e s t e l e m e n t i n t h e o r d e r i n g .I n a d d i t i o n t o N a n d A , o n e i s g i v e n a 1 x I N I m a t r i x b . H e r e a f t e r 1 m a t r i c e s

    w i ll b e c a l l e d " v e c t o r s " , 1 x 1 m a t r i c e s w i l l b e c a l l e d " e l e m e n t s " a n d I N [ x I N Im a t r i c e s w i l l b e c a l l ed " m a t r i c e s " .

    T h e p r o b l e m i s t o d er iv e a n a l g o r i t h m t o c o m p u t e t h e v e c t o r b 9 A * w h e r e b yt h e p r i m i t i v e t e r m s i n t h e a l g o r i t h m d o n o t i n v o lv e t h e " . " o p e r a t o r .

    2 I n t e r p r e t a t i o n sT h e r e l e v a n c e a n d i n t e r e s t o f t h e s t a t e d p r o b l e m i s t h a t i t is a n a b s t r a c t i o n f r o ms e v e r al p a t h p r o b l e m s o n la b e ll e d , d i r e c te d g r a p h s . L e t G = ( N , E ) b e a d i re c t e dg r a p h w i t h n o d e s e t N a n d l a b e ll e d - e d g e s e t E , t h e la b e l s b e i n g d r a w n f r o m s o m er e g u l a r a l g e b r a ( S , + , . , * , 0 , 1 ) . T h e n ( a s w e d e e m k n o w n , s e e f o r i n s t a n c e [3] a n d[7 ],) t h e r e i s a c o r r e s p o n d e n c e b e t w e e n e d g e s e t s E a n d I N I x I N I m a t r i c e s Aw h e r e b y t h e ( i, j ) t h e l e m e n t o f A e q u a l s t h e l a b e l o f t h e e d g e f r o m n o d e i t o n o d ej i n t h e g r a p h , i f p r e s e n t , a n d 0 o t h e r w i s e . ( F o r g r a p h s w i t h m u l t i p l e e d g e s , t h ec o r r e s p o n d e n c e w i ll b e a d j u s t e d l a te r ; n o t e t h a t a b s e n t e d g e s a n d e d g e s w i t h l a b e l0 a r e n o t d i s t i n g u i s h e d . )1 S o m e t i m e s k n o w n a s t h e a l g e b r a o f r e g u l a r l a n g u a g e s . S e e [2] f o r t h e a x i o m a t i s a t i o n o fr e g u l a r a l g e b r a a s s u m e d h e r e .

    x ~_y ---- x + y = y

  • 7/29/2019 Calculating a Path Algorithm

    2/13

    33S i n c e S f o r m s a r e g u l a r a l g e b r a ( S , + , . ,* , 0 , 1 ) , m a t r i x m u l t i p l i c a t i o n c a n b e

    d e f i n e d in t h e u s u a l w a y w i t h t h e u s u a l p r o p e r t i e s . I n fa c t o n e c a n p r o v e t h a t t h es e t o f s q u a r e m a t r i c e s o f a fi x ed s iz e w i t h e n t r i e s d r a w n f r o m S i t se l f f o r m s a r e g u l a ra l g e b r a , w i t h t h e u s u a l d e f i n i ti o n s o f t h e z e r o a n d i d e n t i t y m a t r i c e s , m a t r i x a d d i t i o na n d m a t r i x m u l t i p li c a ti o n . T h e d e r iv a t io n t o b e p r e s e n t e d m a k e s e x t e n s i v e u s e o ft h i s f ac t . ( Fo r de t a i l s s ee [ 3 ] . )

    I f t h e l a b e l o f a p a t h is d e fi n e d t o b e t h e p r o d u c t o f i ts c o n s t i t u e n t e d g e l a b e ls( t a k e n i n t h e o r d e r d e f in e d b y t h e p a t h ) , t h e ( i, j ) t h e n t r y o f A k is th e s u m o f t h el a b e l s o f t h e p a t h s o f l e n g t h k f r o m n o d e i t o n o d e j . N o t e t h a t t h is s t il l h o l d s t r u ei f w e r ed e f in e t h e ( i , j ) t h e n t r y o f A t o b e t h e s u m o f th e l a b e ls o f al l e d g e s f r o m it o j , t h u s a d m i t t i n g m u l t ip l e e d g e s . M o r e o v e r , i f b is a v e c t o r t h a t d i ff e rs f r o m t h ez e r o v e c t o r o n l y i n it s i t h e n t r y , f o r s o m e n o d e i , t h e n t h e j t h e n t r y o f b 9 A . is thes u m o f a ll la b e ls o f p a t h s b e g i n n i n g a t n o d e i a n d e n d i n g a t n o d e j .T h r e e i n t e r p r e t a t i o n s o f a re g u l a r a l g e b r a s a t i s f y in g ( 1 ) a n d ( 2 ) a re g i v e n in t h et a b l e b e l o w . ( N o t e t h a t p r o p e r t y ( 2 ) i m p l i e s t h a t x * = 1 f o r a ll x E S . F o r t h i sr e a s o n t h e i n t e r p r e t a t i o n o f * h a s b e e n o m i t t e d . )

    T a b l e 1 . R e g u l a r a l g e b r a sShor tes t pa ths uonneSgat ive

    realsReach ab i l i ty [ boo l eansBot t l enecks [ rea l s

    + . 0 1

    V A false t rueT ~ - o o oo N is s a t is f i e d b yv i r t u e o f t h e f a c t t h a t Y . > N f o r a ll I N I I N I m a t r i c e s Y . ( T h e l a t t e r p r o p e r t yf o l l o w s s i n c e , b y d e f i n i t i o n , Y 9 = N + Y 9 - Y . )

    5 A S k e l e t o n A l g o r i t h mT h e a l g o r i t h m w e d e v e lo p is b a s e d o n a n i t e ra t i v e p r o c e s s i n w h i c h a t e a c h i te r -a t i o n t h e o r e m 1 9 is u s e d t o " e l i m i n a t e " o n e n o d e f r o m t h e c a l c u l a t i o n . A t s o m ei n t e r m e d i a t e s t a g e s o m e se t o f n o d e s h a s b e e n e l im i n a t e d a n d s o m e s e t M o f n o d e sr e m a i n s t o b e c o n s id e r e d . T h e s e h e u r i s ti c s a r e c a p t u r e d f o r m a l l y b y p o s t u l a t i n g a sl o o p i n v a r i a n t( 20 ) b . A , = z . M . Y , + wa n d a s p o s t c o n d i t i o n(2 1 ) b - A * = ww h e r e x a n d w a r e v e c t o r s a n d Y i s a m a t r i x . ( I n th e c o u r s e o f o u r c a l c u l a t i o n s w es h a l l b e o b li g e d t o s t r e n g t h e n t h is i n v a r i a n t . )

    U s i n g e l e m e n t a r y p r o p e r t i e s o f r e g u la r a l g e b r a t o g e t h e r w i t h t h e p r o p e r t y ( 1 5 )o f t h e s e l e c t o r m a t r i x N i t is e a s y t o s e e t h a t t h e i n v a r i a n t is e s t a b l i s h e d b y t h ea s s i g n m e n t( 2 2 ) z , Y , M , w : = b , A , N , O

    F o r t h e g u a r d o f t h e l o o p t h e r e i s a n a b u n d a n c e o f c h o i ce . W e sh a l l t h e r e f o r e" h e d g e o u r b e t s " f o r t h e m o m e n t b y ch o o s i n g th e w e a k e s t p o s si b le g u a r d , n a m e l y t h en e g a t i o n o f t h e p o s t c o n d i t i o n ( 2 1 ). N o t e , h o w e v e r , t h a t t h e p 0 s t c o n d i t i o n i s i m p l i e db y ( a l t h o u g h n o t e q u i v a l e n t t o ) th e c o n j u n c t i o n o f M = r a n d t h e l o o p i n v a r i a n t .S i n c e N i s a f in i te s e t , p r o g r e s s to w a r d s M = r ( a n d t h u s t o w a r d s t e r m i n a t i o n )is g u a r a n t e e d i f a t e a c h i t e ra t i o n o n e n o d e is r e m o v e d f r o m M . T h e k e y th e o r e md i s c u s s e d i n t h e l a s t s e c ti o n p r o v i d e s a m e c h a n i s m f o r c h o o s i n g s u c h a n o d e . T h i s ist h e m a i n r e a s o n w h y i n v a r i a n t ( 2 0 ) is p r e f e r a b le t o a n o th e r w i s e e q u a l l y r e a s o n a b l ei n v a r i a n t l i k e

    b.A , = x . Y , + wT h u s , t h e m a i n d e s i g n d e c i s i o n f o r t h e l o o p b o d y i s t o c h o o s e k, k E M, i n s u c h

    a w a y t h a t( 2 3 ) x . M . Y * . k = x . ka n d t o t r y t o " t r a n s f e r " x . k f r o m x . M . Y * t o w . T h e k e y t h e o r e m , i n d e e d , e n a b l e st h i s c h o i c e si n c e, b y m u l t i p l y i n g b o t h s id e s o f i ts c o n s e q u e n t b y k 0 a n d s i m p l i f y in g

    ~ ,k 9 k , t o k , w e o b t a i n t h e l e m m a : f o r a ll v e c to r s u a n d m a t r i c e s Z ,( 2 4 ) Z >_ N ~ u . M . Z . k = u . k

  • 7/29/2019 Calculating a Path Algorithm

    7/13

    38T h i s l e a d s t o t h e f o l lo w i n g s k e l e to n a l g o r i t h m . ( F o r g r e a t e r c l a r i t y t h e d i f fe r e n t

    c o m p o n e n t s o f t h e s i m u l t a n e o u s a s s i g n m e n t t o M , w , x a n d Y h a v e b e e n s e p a r a t e db y "[l" s y m b o l s . )

    x , Y , M , w : - - b , A , N , O; { I n v a ri a n t: b . A . = x . M . Y . + w

    V a r i a n t : I M I}d o b , A * # w - - - *c h o o s e k E M s . t . V ( j : j E M : x . , j < x . , k )

    ; M : = M - { k}II w : = ~ '11 x , Y : = z ' , r '

    o d{ b . A , = w }F o r c o n v e n i e n c e w e l e t P d e n o t e M - { k } ; i .e .

    ( 2 5 ) _ M = P + kT h e n , b y a s t a n d a r d u s e o f t h e a s s ig n m e n t a x i o m , w e o b t a in a r e q u i r e m e n t o n t h et h r e e u n k n o w n s , n a m e l y :( 2 6 ) ~ . M . Y , + ~ = ~ ' . _ P . ( Y ' ) , + ~ '

    B e f o r e e m b a r k i n g o n t h e c a l c u l a t i o n d e a l i n g w i t h ( 2 6) it m a y b e h e l p f u l t o s u m -m a r i s e t h e p r o p e r t i e s o f r e g u l a r a l g e b r a t h a t a r e u s e fu l f o r d e a l i n g w i t h e x p r e s s i o n sZ . . F o r al l m a t r i c e s Z t h e d e f i n in g e q u a t i o n f o r Z . is(2 7) Z * = N + Z * . Za n d , h e n c e ,(28) Z * > NF i n a ll y , t w o g e n e r a l p r o p e r t i e s o f a r e g u l a r a l g e b r a a r e t h e r u le w e c al l " t h e l e a p f r o gr u l e " : f o r a l l X a n d Y ,(2 9 ) V . ( W . Y ) * = ( V - W ) * . Va n d t h e r u l e . w e c a l l " s t a r d e c o m p o s i t i o n " :(30) (v + w) 9 = ( v 9 .w) , 9 ,

    6 T h e A s s i g n m e n t t o w

    W e b e g i n o u r c a l c u l a t io n b y c o n s i d e r i n g t h e t r a n s f e r o f x 9k f r o m x 9 M . Y , t o w .T h a t is t o s a y , i n s p ir e d b y ( 2 3 ) a n d ( 2 5 ), w e p r o p o s e c h o o s i n g w ~ = x . k + w a n ds e e k a s u i t a b l e t e r m Z s u c h t h a t( 3 1 ) x .M .Y , = Z + x . kW e h a v e l

  • 7/29/2019 Calculating a Path Algorithm

    8/13

    x - Z{

    39

    x . M= {

    x . M= {

    x . M= {

    x . M= {

    x . M

    9 y ,M = M . M

    a s s u m e Y = Y . Mi n p r e p a r a t i o n f o r t h e u s e o f t h e l e a p f r o g r u l e }

    9 M . ( Y - M ) *l e a p f r o g r u l e )9 ( M . Y ) , 9 gM _ __ : P _ _ + k }9 ( M . Y ) , . ( P + _ k )d i s t r i b u t i v i t y }9 ( Z - Y ) * - P + z . Z - ( _ _ M . y ) , . kc h o i c e o f k , (2 8 ) a n d ( 2 4 ) }9 ( M . Y ) * - P + x - _ k

    I n t h i s c a l c u l a t i o n t h e f i r s t s t e p i s t h e m o s t c r u c i a l . T h e g o a l is t o r e a p a s m u c ha d v a n t a g e a s p o s s i b l e f r o m t h e k e y p r o p e r t y ( 24 ). K n o w i n g t h a t " k " c a n a l w a y sb e in t r o d u c e d i n t o o u r c a l c u l a t i o n s b y t h e i d e n t i t y M = P + _k, t h e s t r a t e g y is t or e t a i n " x 9 M " w h i l s t s i m u l t a n e o u s l y i n t r o d u c i n g a s e c o n d o c c u r r e n c e o f "M_M" o nt h e r i g h t o f t h e e x p r e s s io n b e i n g m a n i p u l a t e d . ( Q u o t a t i o n m a r k s a r e u s e d in t h isd i s c u ss i o n b e c a u s e t h e c o n s i d e r a t io n s a r e e n t i r e l y s y n t a c t i c . ) T o d o t h i s a n e x t r ap r o p e r t y o f th e m a t r i x Y is r e q u i r e d - - a s i n d i c a t e d b y t h e b u l l e t in t h e f i rs t h in t .I n o r d e r t o a c c o m m o d a t e t h i s e x t r a r e q u i r e m e n t w e s t r e n g t h e n t h e i n v a r i a n t to :( 3 2 ) b . A , = x . M . ( Y . M _ M _ ) , + ww h e r e b y Y h a s b e en r e p l a c e d b y Y . M . I n c o r p o r a t i n g t h e a s s ig n m e n t t o w a n d t h en e w i n v a r i a n t w e a r r i v e a t t h e f o l l o w i n g r e f i n e m e n t o f o u r i n i t i a l s k e l e t o n a l g o r i t h m 9

    x , Y , M , w : = b , A , N , O; { I n v a r i a n t : b . A * = x . M . ( Y . M ) , + w

    V a r i a n t : [ M [ }d o b . A * ~ w ->c h o o s e k E M s . t . V ( j : j E M : x 9 j < x 9 k )

    ; M : = P w h e r e P = . M - { k }[ I w : = z . _ k + wJl z , Y : = z ' , Y '

    o d{ b . A * = w }

    S t r e n g t h e n i n g t h e i n v a r i a n t d e m a n d s t h a t w e c h e ck t h a t t h e i n i t i a l is a t i o n is s t il lc o r r e c t - - w h i c h i t i s o n a c c o u n t o f ( 15 ) - - a n d r e v is e t h e r e q u i r e m e n t o n x ' a n dY q A p p l y i n g t h e a s s i g n m e n t a x i o m o n c e a g a i n , m a i n t e n a n c e o f t h e i n v a r i a n t isg u a r a n t e e d b y t h e i d e n t i t y(3 3) x - M - ( Y . M _ _ ) * + w = z ' . P . ( Y ' . P ) , + z . k + w

    9H o w e v e r , b y t h e c a l c u l a t i o n a b o V e ,

  • 7/29/2019 Calculating a Path Algorithm

    9/13

    40. M _ _ . ( Y . M _ _ ) , + ~

    x 9 M 9 ( M . Y ) , 9 P + x . _ k + w

    H e n c e , i t s u f f i c e s t o c h o o s e x ' a n d Y ' s o t h a t(3 4) x . M . ( M . Y ) , . P = x ' . P . ( Y ' , P ) ,

    7 U s i n g S t a r D e c o m p o s i t i o nO n e h a l f o f o u r c a l c u l a t io n i s n o w c o m p l e t e . I n t h e r e m a i n i n g h a l f w e d ea l w i t ht h e a s s i g n m e n t s t o z a n d Y . O u r f i r s t t a c t i c i s t o g e t i n t o a p o s i t i o n t o i n v o k e t h es t a r - d e c o m p o s i t i o n r u le . C o n s i d e r i n g t h e l e f t s id e o f ( 34 ) b u t o m i t t i n g t h e f i na l t e r mi n t h e p r o d u c t , w e h a v e :

    x . M . ( M , V ) ,{ M___ = _.P + k_, d is tr ib u ti v i t y }

    9 M _.M _ . ( P _ . V + k . v ) ,

    T h e d e s i re d p o s i t i o n h a s b e e n r e a c h e d . W e n o w a i m t o u s e t h e c h o ic e o f k - -m o r e p r e c is e l y , ( 2 4) - - w i t h Z i n s t a n t i a t e d t o a s l a r g e a v a l u e a s p o s s i b l e . T h i si n v o l v e s e x p o s i n g "k" o u t w i t h t h e "*" o p e r a t o r . F o r b r e v i t y a n d c l a r i t y i n t r o d u c et h e t e m p o r a r y a b b r e v i a t i o n s V fo r P . Y a n d W f o r k _.Y . T h e n w e p r o c e e d a s f o ll ow s .

    9 M ___. ( _P . Y + k . Z ) ,{ d e f i n i t io n s o f V a n d W }

    x 9 M . ( V + W ) ,{ c o n s i d e r t h e t e r m (V+W)*. R e c a l l i n g t h a t W = _k 9 Y ,

    w e t r y to d e r i v e a n e q u a l e x p r e s s i o n i n w h i c h W i se x p o s e d a s f a r t o t h e r i g h t a s p o s s i b l e .(Y + W)*= { s t a r d e c o m p o s i t i o n }

    (V* 9 W), 9 V*= { ( 2 7 ) }

    ( N+( V, . W) , . V , , W) V ,= { s t a r d e c o m p o s i t i o n }

    (N + (V + W) , . W) V,}x M (N _ + ( V + W ) , 9 W ) V ,

    { d i s t r i b u t i v i t y , d e f i n it i o n o f W }( x 9 M 9 g + x 9 _M_M 9 ( V + W ) * 9 _k 9 Y ) V *{ ( 1 5 ), a n d ( 24 ) u s i n g ( Y + W ) . >_ { ( 2 8 ) ) N }( ~ . M _ . + ~ 9 k_ . V ) V ,

    { d e f i n i t i o n o f V }( z . M + z 9 k . V ) ( P . Y ) ,

  • 7/29/2019 Calculating a Path Algorithm

    10/13

    41M u l t ip l y i n g b o t h s id e s o f t h e o b t a i n e d e q u a l i t y by t h e o m i t t e d t e r m P a n d

    c o n t i n u i n g w e g e t :x . _ _ _ M= {( x . M _ _

    = {( x 9 M

    = {

    9 ( M . V ) , 9 _ Pa b o v e c a l c u l a t io n }+ ~ . k . r ) 9 ( P . r ) , . _Pl e a p f r o g r u l e }

    + z . ~ _ . Y ) p 9 ( r . P ) ,d i s t r i b u t i v i t y ; a n d P C M ,

    t h u s x - M 9 P = { (12 ) } x 9 P}

    ( z + x . _ k . Y ) P . ( Y ._ _P ),

    O u r c a l c u l a t io n i s n o w c o m p l e t e . C o m p a r i n g t h e l a s t li n e o f t h e a b o v e c a l c u l a t i o nw i t h t h e s t a t e d r e q u i r e m e n t s o n x ' a n d Y ' (s e e e q u a t i o n ( 3 4 ) ) , o n e s e e s t h a t Y = Y 'a n d x ' .___P = ( x + x k - Y ) - _ P s u f f i c e. H e n c e p o s s i b l e c h o i c e s f o r x ' a r e

    x + x " k ' Ya n d , s i n c e P 9 P = P ,

    (~ +x . L . Y ) . sW e c h o o s e t h e l a t t e r fo r r e a s o n s d i s c u s s e d in t h e n e x t s e c t i o n , t h e m a i n r e a s o n b e i n gt h a t t h i s c h o ic e , b y c o n s t r u c t i o n , y i e l d s

    a s a n a d d i t i o n a l i n v a r i a n t . ( I t h o l d s in i t i a ll y l i .e . f o r M = N . ) T h u s , a p a r t f r o ms i m p l i f ic a t i o n o f th e t e r m i n a t i o n c o n d i t io n , t h e c o m p l e t e a l g o r i t h m is a s fo l lo w s :

    x ,Y ,M,w := b ,A ,N ,O; { I n v a r i a n t : b . A * = x . M . ( Y . M ) * + w

    V a r i a n t : I M [ }d o b. A* r w ,

    c h o o s e k E M s . t . V ( j : j E M : x . . j < x . , k ); M := P

    II w : = x . _ k + wII x : = ( ~ + z . _ k . Y ) P

    w h e r e P : M - { k }o d

    { b. A* = w}

    8 E l e m e n t w i s e I m p l e m e n t a t i o nI n t h i s f in a l s e c t i o n w e m a k e o n e l a s t s i g n i f ic a n t m o d i f i c a t i o n t o t h e i n v a r i a n t , w ei n d i c a t e h o w t o re e x p r e s s t h e v e c t o r a s s i g n m e n t s i n t e r m s o f e l e m e n t w i s e o p e r a t i o n sa n d w e a t l o n g l a s t m a k e a d e c i s io n o n t h e t e r m i n a t i o n c o n d i t io n . S o m e r e m a r k s o n

  • 7/29/2019 Calculating a Path Algorithm

    11/13

    42

    t h e r e la t io n s h i p b e t w e e n t h e a l g o r i t h m p r e s e n t e d h e r e a n d c o n v e n t i o n a l d e s c r ip t io n so f D i j k s t r a ' s s h o r t e s t - p a t h a l g o r i t h m a n d o f t r a v e rs a l a l g o r i t h m s a r e a ls o in c l u d e d .

    A s im p l e , b u t n e v e r t h e l e s s s i g n i fi c a n t, o b s e r v a t i o n is t h a t , w i t h L d e f i n ed b y( 3 5) L = N - Mt h e a s s i g n m e n t s t o w e s t a b l i s h a n d s u b s e q u e n t l y m a i n t a i n i n v a r i a n t t h e p r o p e r t y :( 3 6 ) t o = t o . L( T h e s e t L w o u l d c o n v e n t i o n a l l y b e c a l le d t h e " b l a c k " n o d e s ; s e e , f o r e x a m p l e , D i jk -s t r a a n d F e i je n ' s a c c o u n t [6 ] o f D i j k s t ra ' s s h o r t e s t - p a t h a l g o r i th m . ) E x p l o i t a t io n o ft h is p r o p e r t y w a s a n t i c i p a t e d w h e n w e e x p r e ss e d o u r p r e f e r re d c h o i ce o f a s s i g n m e n tt o z . F o r , a s s t a t e d i n t h e p r e v i o u s s e c ti o n , t h e a s s i g n m e n t s t o z e s t a b l i s h a n dm a i n t a i n i n v a r i a n t t h e p r o p e r t y(37) x = x 9 MN o w , s u p p o s e w e in t r o d u c e t h e v e c t o r u w h e r e , b y d e f in i t io n ,( 3 8 ) u = z + toT h e n , s in c e L N M = r w e h a v e b y ( 1 3 ) a n d ( 1 4 )(39) x = u 9 Ma n d(40 ) to = u 9 LI n o t h e r w o r d s , t h e r e i s a (1 - 1 ) c o r r e s p o n d e n c e b e t w e e n t h e v e c t o r u a n d t h e p a i r o fv e c t o r s ( x , to ). W e a r e t h u s f r e e t o re p l a c e t h i s p a i r i n t h e a l g o r i t h m b y u . T h i s w ed o a s f o l l o w s .

    I n t h e i n v a r i a n t w e u s e ( 3 7 ) , (3 9 ) a n d ( 4 0 ) t o r e m o v e o c c u r r e n c e s o f x a n d to ; w eo b t a i n :( 41 ) b .A . = u .M. (Y . M)* + u .LI n th e s t a t e m e n t ' c h o o s e k . . .' , i n t h e b o d y o f t h e l o o p , w e r e p la c e o c c u r r e n c e s o f zb y u ; t h i s i s a l l o w e d s i n c e b y ( 3 9 ) a n d ( 1 1 ) w e h a v e , f o r j E M ,

    z 9 , j = u . , jF o r th e a s s i g n m e n t s t o u w e s im p l y a d d t h e r i g h t s id e s o f t h e a s s i g n m e n t s t o 9 a n dw ( c f . ( 3 8 ) ) a n d a g a i n u s e ( 3 9 ) a n d ( 4 0 ) t o r e m o v e a ll t r a c e s o f t h e s e v a r ia b l e s . W eh a v e

    (z +x. k_. Y) P + x .k + w= { d i s t r i b u t i v i t y }x . P + x . _ k . Y . P + x . _ k + w

    = { c o m m u t a t i v i t y o f + }x .P_+ ~ , k_+ w+~ . k_ . Y .P_

    = { d i s t r i b u t i v i t y , M = P + _ k }

  • 7/29/2019 Calculating a Path Algorithm

    12/13

    x . M + w + x . _ k . Y . P= { ( 37 ) , ( 38 ) an d ( 39 ) }

    u + u . M . k . Y . P _= { k E M , ( l l ) }

    u + u . / c . Y . P

    43

    T h u s , i n th e b o d y o f t h e l o o p t h e a s s i g n m e n t t o u is( 42 ) u : = u + u . k . Y . P

    W h a t t h is e n t a il s a t e l e m e n t le v el ca n b e a s c e r ta i n e d b y p o s t m u l t i p l y i n g b y ~f o r e a c h n o d e j . F o r j E P , w e c a lc u l a t e a s f o ll o w s :

    ( u + u . k - Y - P ) o j= { d i s t r i b u t i v i t y }

    u 9 o j + u 9 /r 9 Y 9 P 9 o j= { d e f i n i t io n o f k , ( 5 ) ; a s s u m p t i o n j E P a n d ( 1 1 ) }

    ( u . . j ) + ( u . ~ ( k . . Y . ~

    P a r e n t h e s e s h a v e b e e n i n c l u d e d i n t h e l a s t li n e in o r d e r t o i n d i c a t e w h i c h s u b e x p r e s -s io n s ar e e l e m e n t s. F o r j ~ P t h e s e c o n d s u m m a n d - - i n t h e p e n u l t i m a t e f o r m u l a o ft h e c a l c u l a t i o n - - r e d u c e s t o z e r o , s in c e P 9 o j = 0 . I .e .( 4 3) ( u + u . / C - Y . _P ) . j = u 9 0 j

    T h e f i n a l d e c i si o n w e h a v e t o m a k e i s o n t h e t e r m i n a t i o n c o n d i t i o n . F o r o u r o w no b j e c t i v e s h e re w e m a k e d o w i t h t h e s im p l e s t p o s s i b le t e r m i n a t i o n c o n d i t io n , n a m e l yM = r t h u s o b t a i n i n g t h e f o l lo w i n g a l g o r i t h m :

    u , Y , M := b , A , N; { I n v a r i a n t : b . A * - - u . M . ( Y . M ) * + u . N - M

    V a r i a n t : I M I }d o M # r ----*c h o o s e k E M s . t . V ( j : j E M : u . , j _< u . , k )

    ; M := PI] p a r l o r j E P d o

    u . , j : = u . , j + ( u . , k ) . ( k , . Y . , j ).here P = M - { k }

    o d{ b . A * = u }

    N o t e th a t , s i n c e k ~ P , t h e p a r a ll e l f o r s t a t e m e n t c a n b e r e p l a c e d b y a s e q u e n t i a lf o r s t a t e m e n t .A s f o r o t h e r t e r m i n a t i o n c o n d i t i o n s , w e r e m a r k e d e a r l ie r t h a t t h e s e t L c o r re -s p o n d s t o t h e s o - c a ll e d " b l a c k " n o d e s in D i j k s t r a a n d F e i j e n ' s d e s c r i p t i o n o f D i j k -s t r a ' s s h o r t e s t - p a t h a l g o r it h m . T h e y a l so d i s ti n g u is h " w h i t e " a n d " g r e y" n o d e s .T h e " g r e y " n o d e s a r e j u s t n o d e s j E M f o r w h i c h u . , j r 0 , a n d t h e " w h i t e "n o d e s a r e t h e r e m a i n i n g n o d e s i n M ; i n s o m e c i r c u m s t a n c e s ( e. g . i f t h e g r a p h i s

  • 7/29/2019 Calculating a Path Algorithm

    13/13

    44n o t c o n n e c t e d ) a d v a n t a g e c a n b e m a d e f r o m t h e s p e c ia l m u l t i p l ic a t iv e a n d a d d i -t iv e p r o p e r t i e s o f t h e z e r o e l e m e n t o f t h e a l g e b r a . I n t h i s c a s e , a s u i ta b l e c h o i c e f o rt h e t e r m i n a t i o n c o n d i t io n w o u l d b e u 9M = 0 : t he n u 9 N - M = u a n d , h e n c e ,b . A , = 0 - ( Y . M ) * + u = 0 + u = u . ( I n c o n v e n t i o n a l t e r m i n o l o g y ,t h is t e r m i n a t i o n c o n d i t i o n r e a d s " t h e se t o f g r e y n o d e s is e m p t y " ; c o n v e n t i o n a l l y ,t h i s is , i n d e e d , t h e c h o i c e m a d e . )

    A t e r m i n a t i o n c o n d i t i o n u 9 M = 0 re q u i r e s t h e a l g o r i t h m t o k e e p t r a c k o f t h en o d e s j E M f o r w h i c h u 9 , j ~ 0 . W e w o n ' t g o in t o t h e p r e c is e d e t a i ls o f s u c ha n a d d i t i o n t o t h e a l g o r i th m , b u t w e f in i sh b y n o t i n g t h a t , i n t h e i n t e r p r e t a t i o np e r t a i n i n g t o t e a c h a b i l i t y p r o b l e m s ( se e t h e t a b l e i n s e c ti o n 2 ), k e e p i n g t r a c k o f t h e" g r e y " n o d e s i n a q u e u e l e ad s t o a b r e a d t h - f i r s t t r a v e r s a l a l g o r i t h m ; u s i n g a s t a c ki n s t e a d o f a q u e u e l e a d s t o d e p t h - f i rs t t r a v e r s a l .

    9 C o m m e n t a r y a n d C r e d i t sT h e g o a l o f t h is r e p o r t h a s b e e n t o s h o w h o w a c l as s o f s t a n d a r d p a t h a l g o r i th m sc a n b e d e r i v e d b y a l g e b r a ic c a l c u l a t io n . T h i s is, o f c o u r s e , n o t t h e f i r st a n d n o r ( w eh o p e ) w i ll it b e t h e l a s t s u c h d e r i v a t i o n . T h e a l g e b r a ic b a s i s f o r th e c a l c u l a t i o n g i v e nh e r e w a s l a id i n [ 2], a n d s o m e o f i ts d e t a i l s w e r e i n f l u e n c e d b y C a r r 6 ' s d e r i v a t i o n[3] o f t h e s a m e a l g o r i t h m . A g r e a t m a n y o t h e r a u t h o r s h a v e d e s c r i b e d a n d a p p l i e dr e la t e d a l g e b r a ic s y s t e m s t o a v a r ie t y o f p r o g r a m m i n g p r o b l e m s ; T a r j a n ' s p a p e r[7] i n c l u d e s m a n y r e fe r e n ce s . T h e m a i n d i s t i n g u i s h i n g f e a t u r e o f t h e d e v e l o p m e n tp r e s e n t e d h e r e , h o w e v e r , is i ts r el ia n c e o n c a l c u l a t i o n s w i t h m a t r i c e s r a t h e r t h a nw i t h m a t r i x e l e m e n t s , r e s u l t i n g ( i n o u r v i e w ) i n a p l e a s i n g l y c o m p a c t p r e s e n t a t i o n .

    R e f e r e n c e s1 . R .C . Backhouse . Ca l cu l a t i ng t he F l oy d / W ar sha l l pa t h a l go r i thm . E i ndhov en U n i ve r s i t yo f Techno l ogy , D epa r t m en t o f Co m p ut i ng Sc ience, 1992 .2 . R .C . Backhou se and B .A . Ca r t 6 . Regu l a r a l geb ra app l ied t o pa t h - f i nd i ng p r ob lem s .Journal of the Institute of Mathematics and its Applications, 15:161-186, 1975.3 . B.A. Car r6 . Graphs and Networks. Oxford Univers i ty Press , 1979.4 . P . Ch i sho l m . Ca l cu l a t i on by com put e r . I n Third International Workshop Software En-gineering and its Applications, pages 713-728, Toulouse , France , December 3-7 1990.E C 2 .5 . E .W . D i j kst r a . A no t e on tw o p r ob lem s i n connex i on w i t h g r aphs . Numerische Mathe-

    matik, 1:269-271, 1959.6 . E.W. Di jks t ra and W.H.J . Fe i jen . Een Methode van Programmeren. A cadem i c Se r v i ce ,Den Haa g, 1984. Also ava i lable as A Method of Programming, A ddi son- W es l ey , Read i ng ,Mass., 1988.7 . R .E . Ta r j an . A un i fi ed appr oa ch t o pa t h p r ob l em s . Journal of the Association forComputing Machinery, 28 : 577- 593 , 1981 .

    A c k n o w l e d g e m e n t sP r e p a r a t i o n o f t h is r e p o r t w a s e x p e d i t e d b y t h e u s e o f t h e p r o o f e d i t o r d e v e l o p e db y P a u l C h i s h o l m [ 4 ] .