In this section we now propose two variants of Dijkstra’s algorithm. These are designed to find shortest paths in our edge-coloured graphs (that is, graphs featuring transfer penalties at their vertices), but without the need for first performing a graph expansion.
4.1. Extended Dijkstra Version 1
Our first adaptation, E
xtended-D
ijkstra-V1, is given in Algorithm 3. The rationale for this method can be explained by considering a cluster of dummy vertices in a Kirby–Potts expanded graph. As previously noted, vertices in each cluster of the expanded graph can be partitioned into two sets: in-vertices and out-vertices (see
Figure 3a,b). Moreover, observe that a shortest path from an in-vertex must always next pass through an out-vertex from the same cluster before moving to a different cluster. As proven in Theorem 1 below, it is therefore sufficient to simply add the length of the corresponding transfer (edge) to the path here, rather than consider the out-vertices as separate entities within the graph.
The idea in our approach is to therefore use a pair for each vertex and incoming colour , giving pairs in total. The source is also defined by such a pair , which is interpreted as meaning that the paths should start at , assuming initial entry to s on an edge of colour l. Similarly to the Dijkstra procedure of Algorithm 1, during execution this algorithm stores labels, predecessors and the distinguished status of each pair using the data structures L, P and D respectively. At termination, all pairs reachable from the source are marked as distinguished, and the label holds the length of the shortest path from the source to vertex u, assuming entry at u on an edge of colour i.
An example solution from this method is shown in
Figure 5. The main differences between this approach and D
ijkstra are (a) the use of vertex-colour pairs, and (b) at Lines 11 and 13 of E
xtended-D
ijkstra-V1, where transfer penalties
are added when comparing and recalculating label values. Note also that for
this algorithm becomes equivalent to D
ijkstra.
Algorithm 3 The extended Dijkstra algorithm, version 1. |
| Extended-Dijkstra-V1 |
(1) | for all |
(2) | for all |
(3) | Set ; false; and null |
(4) | Set and |
(5) | while |
(6) | Let be the element in Q with minimum value for x |
(7) | Remove from Q and set true |
(8) | for all such that false |
(9) | if then |
(10) | if then remove from Q |
(11) | Set ; ; and insert into Q |
The correctness of Extended-Dijkstra-V1 is due to the following theorem.
Theorem 1. If all edge weights and transfer penalties in a graph are nonnegative then, for all distinguished pairs , the label is the length of the shortest path from the source to .
Proof. Proof is by induction on the number of distinguished pairs. When there is just one distinguished pair, the theorem clearly holds since the length of the shortest path from to itself is .
For the step case, let be the next pair to be marked as distinguished by the algorithm (i.e., is minimal among all undistinguished pairs) and let be its predecessor. Hence the shortest --path has length . Now consider any other path P from to . We need to show that the length of P cannot be less than . Let and be pairs on P such that is distinguished and is not, meaning that P contains the edge . This implies that the length of P is greater than or equal to (due to the induction hypothesis). Similarly, this figure must be greater than or equal to because, as assumed, is minimal among all undistinguished pairs. □
We now consider the computational complexity of E
xtended-D
ijkstra-V1. As before, we assume the use of a binary heap for
Q and direct access data structures for
L,
D and
P. The initialisation of
L,
D, and
P in Lines 1 to 5 has a worst-case complexity of
. For the main part of the algorithm, note that each label in
L is considered and marked as distinguished exactly once and, in the worst case, we will have
such labels. Once a label
is marked as distinguished, all incident edges
are then considered in turn and are subject to a series of constant-time and log-time operations, as shown in Lines 12 to 15. This leads to an overall worst case complexity of
. Assuming graph connectivity, this simplifies to a growth rate for E
xtended-D
ijkstra-V1 of
As previously noted, the complexity of D
ijkstra using a binary heap is
. Using a Kirby–Potts expansion, in the worst case this leads to a graph
with
vertices and
edges, giving an overall complexity of
, or
Figure 6 compares
and
for a range of different parameter values. Note that
grows more quickly in all cases, demonstrating that E
xtended-D
ijkstra-V1 is less efficient with regards to increases in the number of edges
m. The main reason for this is that, with E
xtended-D
ijkstra-V1, each outgoing edge of a vertex
v is considered for each incoming colour of
v. This results in the term
seen in Equation (
3). In contrast, although a Kirby–Potts expansion results in a graph
with an increased number of edges and vertices, each edge in
is considered only once using D
ijkstra, which results in a slower growth rate. Note, however, that each chart in
Figure 6 features an intersect, suggesting that E
xtended-D
ijkstra-V1 is more efficient with very sparse graphs. (If Fibonacci heaps are used for
Q instead of binary heaps, the growth rates for
and
are
and
respectively. These feature the same noted properties as
and
except that growth is more gradual, and intersects occur at slightly higher values of
m.) For indicative purposes, the grey rectangles in the figure show the range of values for which planar digraphs exist (i.e., the right boundary of these rectangles occur at
, which is the maximum possible number of directed edges in a planar digraph). Planar graphs are considered further in
Section 5.
4.2. Extended Dijkstra Version 2
Our second adaptation operates by replicating the behaviour of Dijkstra’s algorithm on Kirby–Potts graphs. This results in a method with the more favourable growth rate of but that also avoids the need for graph expansion. To do this, approximately twice as much working memory as Extended-Dijkstra-V1 is required because, in addition to storing values for each vertex/in-colour pair, we also need to store values for each vertex/out-colour pair. The structures L, D and P are therefore replaced with the structures and , and , and and .
The complete procedure for Extended-Dijkstra-V2 is given in Algorithm 4. Note that each item in the priority queue Q is now a tuple comprising four values. The fourth value indicates whether the item refers to an “in-label” or and “out-label”, which correspond to in-vertices and out-vertices in a Kirby–Potts graph. The item means that we are considering the vertex u, incoming edges of colour i, and that . Similarly, means we are considering vertex u, outgoing edges of colour i, and that .
Algorithm 4 The extended Dijkstra algorithm, version 2. |
| Extended-Dijkstra-V2 |
(1) | for all |
(2) | for all |
(3) | Set ; false; and null |
(4) | for all |
(5) | Set ; false; and null |
(6) | Set and |
(7) | while |
(8) | Let be the element in Q with minimum value for x |
(9) | Remove from Q |
(10) | if then |
(11) | Set true |
(12) | for all such that false |
(13) | if then |
(14) | if then remove from Q |
(15) | Set ; ; and insert into Q |
(16) | else |
(17) | Set true |
(18) | for all such that and false |
(19) | if then |
(20) | if then remove from Q |
(21) | Set ; ; and insert into Q |
As shown in Algorithm 4, items are selected and removed from the priority queue Q on Lines 8 and 9. If the selected item refers to an in-label (), then only labels referring to the outgoing colours of vertex u need to be considered for update; hence, we only need to look at the transfer penalties for in which is not distinguished (Lines 12 to 15). Similarly, if refers to an out-label (), then we only need to consider updating the in-labels of any vertex v connected to u by an edge of colour i (Lines 18 to 21). This behaviour is identical to the way in which Dijkstra would operate with a Kirby–Potts expanded version of the graph.