Beruflich Dokumente
Kultur Dokumente
feqvm,marta,zeluisg@mat.uc.pt
Departamento de Matem atica
Universidade de Coimbra
PORTUGAL
June 1998
In this paper we are concerned with the unconstrained ranking shortest paths
problem. For this
problem, the algorithms are divided in two sets: those which are based on the
Optimality Principle
and those which determine a set which contains the set of the K shortest
paths.
The objective of the first part of this paper is to review the problem and to
show how it can be
considered a generalization of the classical shortest path problem. In fact,
althought this generalization
seems to be obvious (K = 1 for the shortest path problem), it has not been
explored for K > 1. In
the second part of the paper the problem is studied under a different
perspective { the set of the K
shortest paths forms a tree in the sense of Theory of Graphs, being new
algorithms proposed which
compute a tree containing at least all the K shortest paths.
The reader is assumed to be familiarized with the problem. Notation is the
one used in previous
papers, 1, 2, 3, 15, 16, 18]. Despite, some definitions and notation are
introduced in the next section.
::: v
n
::: a
m
a
v
::: a
v
=ti, where:
r
1. a
k
0
2. a
k
0
k
0
= (v
v
), for any k = 1 ::: r ;1
k+1
Let c(a
k
X
) (or c
2 IR) be a real number associated with arc a
= (i j) and let c(p) =
c
ij
k
ij
(i j)2p
(or
c(p) =
X
c
ij
), for any path p that can be defined between a pair of nodes of (N A), denote
the value
of path p { or p path distance (or p path cost).
Let P
ij
denote the set of paths that can be defined from i to j in (N A) (P will be used
for P
st
).
In what follows it is assumed that P
si
= and P
it
and P
st
and there is also no loss of generality when it is assumed that both the initial
and terminal nodes are not repeated in a path.
A path from s to t in (N A) is a loopless path, if all its nodes are different. A
cycle is a path
from some node to itself, where all the nodes are different except the first
which is also the last one.
A cycle C in (N A) is said to be a negative cycle if and only if
X
c
ij
c
ij
::: p
K
g P, such that:
1. c(p
k
) c(p
k+1
3. p
k
.
Let p
ij
2P
ij
and p
j`
2P
j`
is also
the initial node of p
j`
, the concatenation of p
ij
and p
j`
, denoted by p
ij
p
j`
from j to `.
Let C be a given cycle in (N A). For any k 1, C
k
C ::: C
|
. Under these
assumptions, p C
and p
be two paths in (N A) such that p =p
p
it
si
it
k
k
0
C
p
, for any k 0. (For convenience, p C
is also
si
it
= and P
= . There is a finite shortest
it
c
ij
,
such that p =p
si
= and P
= , there is a path p
2P
and a path p
2P
it
si
si
it
it
p
is a path from s to t. Moreover, since i is a node from path p and from cycle
C,
it
(p(k)). So,
c(p
1
= lim
k!1
) = c( lim
fp(k)g)
k!1
= lim
fc(p(k))g
k!1
= lim
k!1
fc(p C
)g
= lim
k!1
fc(p) +c(C
)g
= lim
k!1
fc(p)g+ lim
fc(C
)g
k!1
= c(p) + lim
fk c(C)g
k!1
That is, p
1
= and P
it
pC
k
, it is assumed that c(C)> 0 for any cycle C in (N A), that is, there are no
absorvent cycles
in (N A).
}
k times
=,P
it
= for any
i 2 N. The k
th
=p
p
p
and p
is a subpath of p
which is the j
shortest path from ` to h and
s`
ht
k
i
j>k. Since j>k we conclude that there are, at least, k different paths p
`h
c(p
j
j
j
i
i
)< c(p
), for any 1 i k<j. Butc(p
) =c(p
) +c(p
) +c(p
) andc(p
) < c(p
), for any
k
s`
ht
`h
`h
`h
`h
`h
j
), for any
i k<j. That is, p
k
)< c(p
s`
ht
k
th
is not the k
A class of ranking shortest paths algorithms is supported by theorem 3.
Dreyfus, 10], was the first
one to propose an algorithm in this class. This algorithm determines not only
the K shortest paths
between a given pair of nodes but also the K shortest paths from all nodes to
t.
Yet in this class of algorithms we can consider the generalization of the
labeling algorithms for the
shortest path problem. Shier was the first one to propose algorithms in this
subclass 19, 20, 21].
Labeling algorithms will be presented in the next subsection.
::: p
K
as soon
as a path from s to t is determined, in label correcting algorithms this is
known only at the ending of
the algorithm.
Labeling algorithms have in common the use of one or more labels assigned
to each node. While
in the shortest path problem there is a single label assigned to each node i, in
the K shortest paths
problem we may have a single label or several labels assigned to each node.
In the former case the
label of node i is formed by three K{tuple:
i
k
i
th
, is the
distance of a path from s to node i, the k
,
i
and
i
. While
, the k
th
, is the node
before i in that path and its position in
i
. To achieve this a flag associated with each node i can be used in this
case, the flag of i would be a K{tuple whose k
th
component of
i
th
is not formed by j
and
i
, respectively
th
component of
i
k
i
and
k
i
i
K
:::
g ; f+1 ::: +1g, for all node i 2 N
i
1
s
1
;0
is unused
s
X ; fsg
while X =
do begin
i ; node of X
X ;X ; fig
do begin
k
i
is used
if (
k
i
1
j
K
+c
< maxf
:::
g)
ij
j
then begin
` ; order of maxf
1
j
K
j
1
j
K
:::
g in f
:::
g
j
`
j
k
i
`
j
`
;
+c
;i
;k
ij
j
`
j
is unused
if j 62X then X ;X fj g
end
end
end
Find the K shortest paths
, which represents
a really large amount of computational effort.
Computationally it is really difficult to deal with the three K{tuple labels
used in the general form
is enlarged in order that each node is assigned with a single label. Note that
the enlarged set of nodes
::: a
m
g
anda
k
0
j
0
0
0
= (i j) < a
= (i
. Furthermore, in order to increase
`
;1
with primes within the circle. Closed to each circle we find a number which
represents the distance of
this path the is represented by the arrows.
Dashed circles represent labels that had been computed and later removed.
We must notice the
0
a single label and the form where each node is assigned with K labels, are
coincident when K = 1.
Moreover, in this case, algorithm 3 is also the Bellman{Ford{Moore form of
the label correcting
algorithm for the single shortest path problem.
Other forms of the label correcting algorithm could be designed, either with a
K{tuple label
assigned to each node or manipulating X in different ways. However, it
appears that its either
practical or theoretical efficiency is not improved.
It must be also pointed out that the set P
K
count
i
.
/
count
i
; 0, for all i 2 N
elm ;1
-1
h(elm) ;s h
(s) ; felmg
elm
;0
X ; felmg
while (X = )
do begin
k ; some element of X
X ;X ; fkg
i ;h(k)
do begin
if (count
j
=K)
then begin
-1
` ; element of h
(j) for which
`
-1
(j)g
if (
k
= maxf
x
jx 2h
+c
ij
<
`
then begin
`
;
+c
ij `
;k
end
end
else begin / (count
j
< K) /
elm ;elm+ 1
elm
;
+c
ij elm
;k
count
j
;count
j
+1
-1
-1
h(elm) ;j h
(j) ;h
(j) felmg
X ;X felmg
end
end
end
Find the K shortest paths
......................................................................................
........................ 3
......................................................................................
........................ .................................................
5s
..............
......................................................................................
......................................... ............................................
................................................................................... ..
............
....................................................................................
1
0
3 ..............
..............
......................................................................................
........................
......................................................................................
........................
1
4
2
1 ....................................................................................
.................................................................................... .
.............
..............
......................................................................................
......................................... ............................................
................................................................................... ..
............
.................................................................................... 1
2
1
..............
.............. .......................................................................
....................................... 4
................................................. ..............
count
i
.
/
count
i
; 0, for all i 2 N
elm ;1
-1
h(elm) ;s h
(s) ; felmg
elm
;0
X ; felmg
while X =
do begin
k ; first element of X
X ;X ; fkg
i ;h(k)
=K)
then begin
-1
` ; element of h
(j) for which
`
-1
(j)g
if (
k
= maxf
x
jx 2h
+c
ij
<
`
then begin
if ` 2X then X ;X ; f`g
`
;
+c
ij `
;k
end
end
else begin / (count
j
< K) /
elm ;elm+ 1
elm
;
+c
ij elm
;k
count
j
;count
j
+1
-1
-1
h(elm) ;j h
(j) ;h
(j) felmg
X ;X felmg and elm is the last element of X
end
end
end
Find the K shortest paths
......................................................................................
........................................ 5
0
......................................................................................
........................................ 5
......................................................................................
........................................ 5
X = f5g
(1 { Initialization)
0
......................................................................................
........................................ 2
0 ..............................................................
.................................... ..............
03
......................................................................................
............
......................................................................................
........................................ 3 ..............
0 ....................................................................................
..........................................
2
X = f2
......................................................................................
............
1
......................................................................................
............ ..............
..............
3
0 ....................................................................................
..............
......................................................................................
........................................ 3 ..............
01
0
0
3
g
(2 - Labels from 5)
......................................................................................
........................................ 1
0
7
......................................................................................
............
......................................................................................
........................................ 4 ..............
0
4
0
0
0
X = f3
1
4
g
0
(3 { Labels from 2
)
......................................................................................
........................................ 5
0
......................................................................................
........................................ 5
......................................................................................
........................................ 2
0 ....................................................
........................................................... ..............
......................................................................................
................................. .............. .....................................
............................................................. ..............
3
0 ....................................................................................
..........................................
......................................................................................
........................................ 2
......................................................................................
............................................ ..............
......................................................................................
..........................................................
1
3 0 0 ......
.............. .......................................................................
....................................................... 3
......
......
......
......
......
......
...... .....................................................
......................................................................... 1
...........
1
0 ....................................................................................
..............
..............
......................................................................................
............ ..............
......................................................................................
............ ..............
......
......
............
X = f1
......
......
......
......
......
......
......
......
...........
......................................................................................
............
07
4
......................................................................................
........................................ 4
0 ....................................................................................
..........................................
2
00 ....
....
....
....
2
......................................................................................
........................................
4
..................
......
......
..............
......................................................................................
............ ..............
......
......
1 ....................................................................................
.......... ..............
.................. ......
......
......
3
00 ... 0 ......
...... 0 7
......
......
4
......
4
............
......................................................................................
........................................
2
00 2
......................................................................................
........................................
4
00 3
......................................................................................
........................................ 5
......
......
......
......
0
0
00
00
4
2
4
g
0
(4 { Labels from 3
)
7
0 ....................................................................................
..........................................
1 ....................................................................................
..........
..............
00 ...................................................................................
...............
..............
......................................................................................
............ ..............
X = f4
5
......................................................................................
........................................
1
000 6
......................................................................................
........................................
4
000 3
00
0
00
000
000
5
1
1
4
g
00
(7 { Labels from 2
)
......................................................................................
........................................................................ 5
0
......................................................................................
........................................................................ 2
......................................................................................
......................................................................................
....................... ..............
......................................................................................
......................................................................................
...... ..............
......
......
......
......
......
......
......
......
......
......
............
3
......................................................................................
........................................................................ 3
1
......
......
......
............
0
0
......................................................................................
........................................................... ..............
......
......
......
......
......
......
......
......
......
...... ......
......
......
......
......
......
......
......
......
......
....
....
....
......
....
............
......
............ ......
......................................................................................
................................. ..............
......
......
......
1
............ ......
......
...... ......
......
......
......
7
......
......
4
......
......
4
......
............
......................................................................................
........................................................................
2
2
......................................................................................
........................................................................
4
3
0
0
00
00
......
......
......
..................
......
......
......
......
......
...... ......
......
......
......
......
......
......
......
......
....
....
............ ......
....
...... ...... ......
....
......
......
......
......
......
......
......
......
......
....
......
.... ............ ......
......................................................................................
................................. ..............
......................................................................................
............................ ..............
...... ......
......
5
......
......
......
......
......
......
......
......
......
...... ......
............ ...... ......
......
1
............ ......
......
...... ......
......
......
......
7
......
...... ......
......
1
......
..................
5
......
......
......
6
......
......
......
..................
......................................................................................
........................................................................
4
3
......................................................................................
........................................................................
1
4
0
00
000
000
0000
......
......
......
..................
......
......
......
......
......
......
......
......
......
......
......
......
......
......
......
....
....
......
....
...... ...... ......
....
............ ...... ......
......
3
......
......
......
......
......
......
......
......
......
...... ......
......................................................................................
........................................................................
......................................................................................
............................ .............. ..........................................
........................................................................ .............
.
......................................................................................
............................ .............. ............ ......
......
...... ......
......
......
......
8
......
...... ......
......
5
......
..................
5
4
......................................................................................
........................................................................
5
......
......
......
..................
4
00
00
00000
000
......
......
......
......
....
....
...... ............ ............ ...... ......
...... ...... ...... ......
...... ...... ...... ......
...... ......
66
000 000 ......
...... ...... ......
33
......
..................
......................................................................................
........................................................................
5 ...... ......
4
0000
......................................................................................
........................................................................
3 ....................................................................................
..............................
0000
..............
5
X=