Shortest paths with some
(i, j) < 0 when some link lengths on a network are negative the two shortest-path algorithms of section 6.2 must be modified. algorithm 6.1 must be modified drastically, while only a minor modification is necessary in algorithm 6.2. in this problem we shall explore various aspects of the shortest-path problem with some
(i, j) < 0.a.Let
(f, e) = -2, instead of 5, in the graph of Figure 6.3. How would the shortest-path tree of Figure 6.5 change?b.Suppose that the following approach has been suggested for finding shortest paths on the graph of Figure 6.3 with
(f, e) = -2: (i) Add 2 units to the length of all links of the graph so that all
(i, j)
0; (ii) use Algorithm 6.1 to find any shortest paths required and then subtract 2 units from every link on each shortest path to find the true length of each shortest path. What is wrong with such an approach?c.Suppose now that
(f, e) = -8 in Figure 6.3. What would now be the minimum distance between nodes a and j, d(a, j) ?
Hint: Be careful!
d.The phenomenon that you have observed in part (c) is referred to as a “negative cycle.” Whenever a negative cycle exists between two nodes of a graph, the shortest-path problem for this pair of nodes is meaningless. Note that this means that no undirected links on a graph should have negative
(i,j)–since this immediately implies a negative cycle. Shortest-path algorithms must be able to “detect” the presence of negative cycles if they are to work with some
(i, j) < o. the key to such detecting is the following statement: in a graph with n nodes, no meaningful shortest path (i.e., one that does not indude a negative cycle) can consist of more than n – 1 links. argue for the validity of this statement.e.Algorithm 6.2 can be used as stated for cases where some
(i, j) < o with only a minor modification to check for the existence of negative cycles upon termination. how would you use the final matrix d(n) at the conclusion of Algorithm 6.2 to check whether there are any negative cycles in a graph?
Hint: What should happen to one or more diagonal elements dn(i, i) of this matrix if there is a negative cycle in the graph ?
f.Repeat Example 2 of Section 6.2.2 for the case in which the length of the directed arc from node 5 to node 2 in Figure 6.6 is equal to -3.g.Can you suggest how shortest-path Algorithm 6.1 should be changed in order to be applicable to cases with some
(i, j) < 0?
Hints: No labels can become permanent (i.e., nodes cannot become closed) until all labels are permanent; the algorithm requires at most N – 1 passes but may terminate earlier if no labels change during a pass.
For a more extensive discussion of algorithms of this type, see, for instance, Chapter 8, Section 2.2, of Christofides [CHRI 75].
https://web.mit.edu/urban_or_book/www/book/chapter6/problems6/6.1.html
a. If (f, e) is changed to -2 instead of 5 in the graph of Figure 6.3, the shortest-path tree of Figure 6.5 would change as follows:
The shortest-path tree is initially empty, and all nodes except the source node are marked as unvisited. The source node is denoted as a predecessor of all other nodes with a link of length -1. The shortest paths are then updated iteratively.
1. Initially, the shortest-path tree is empty.
2. The first iteration would update the shortest path from the source node ‘a’ to node ‘f’ with a length of -2.
3. In the second iteration, the shortest path from ‘a’ to node ‘e’ is updated with a length of -1. This path becomes the shortest path from ‘a’ to ‘e’ in the new shortest-path tree.
4. In the third iteration, the shortest path from ‘a’ to node ‘c’ is updated with a length of -2.
5. In the fourth iteration, the shortest path from ‘a’ to node ‘b’ is updated with a length of -1.
6. In the fifth iteration, the shortest path from ‘a’ to node ‘d’ is updated with a length of -2.
7. Finally, in the sixth iteration, the shortest path from ‘a’ to node ‘g’ is updated with a length of -1.
The resulting shortest-path tree would have edges: (a, b), (a, c), (a, d), (a, e), (e, g), and (c, f).
b. The suggested approach of adding 2 units to all link lengths, finding the shortest paths using Algorithm 6.1, and then subtracting 2 units from each link on the shortest path is flawed. The problem with this approach is that it assumes adding a constant value to all link lengths will preserve the shortest paths. However, this assumption is incorrect.
By adding 2 units to all link lengths, the relative distances between nodes change. It might result in a different shortest path compared to the original graph with negative link lengths. Subtracting 2 units from each link on the computed shortest path would not yield the correct shortest path in the original graph.
c. If (f, e) is changed to -8 in Figure 6.3, the minimum distance between nodes ‘a’ and ‘j’ (d(a, j)) would be undefined or infinite. This is because there is a negative cycle in the graph, specifically the cycle (a, b, e, g, a), which has a total length of -8.
The presence of a negative cycle makes the shortest-path problem for a pair of nodes meaningless because it allows for infinitely decreasing path lengths by repeatedly traversing the cycle. Therefore, no meaningful shortest path exists between ‘a’ and ‘j’ in this case.
d. The statement “in a graph with n nodes, no meaningful shortest path (i.e., one that does not include a negative cycle) can consist of more than n – 1 links” is valid. This is because in any simple path (a path without cycles), the maximum number of nodes is n – 1. If a shortest path consists of more than n – 1 links, it implies the presence of at least one cycle. If that cycle has a negative total length, it can be traversed repeatedly to decrease the path length infinitely.
e. To check for the existence of negative cycles using the final matrix d(n) at the conclusion of Algorithm 6.2, we can inspect the diagonal elements dn(i, i) of the matrix. If there is a negative cycle in the graph, at least one
of the diagonal elements will be negative.
The diagonal elements represent the shortest distance from a node to itself. In the absence of negative cycles, all diagonal elements should be non-negative since the shortest distance from a node to itself is zero. However, if there is a negative cycle, the shortest distance from a node to itself can be negative due to the repeated traversal of the negative cycle.
Therefore, by examining the diagonal elements of matrix d(n), we can determine whether there are any negative cycles present in the graph.
f. Repeating Example 2 of Section 6.2.2 for the case where the length of the directed arc from node 5 to node 2 in Figure 6.6 is equal to -3, the resulting shortest path would be different.
The original graph:
“`
3
a —–> b
| |
1 -1
| |
v v
c —–> d
2
“`
The modified graph with a directed arc from node 5 to node 2 having a length of -3:
“`
3
a —–> b
| |
1 -1
| |
v v
c —–> d
^ ^
| |
5 —–> 2
“`
Using Algorithm 6.1, the shortest path from ‘a’ to ‘d’ would be: a -> b -> d with a total length of 1 – 1 = 0.
g. To make shortest-path Algorithm 6.1 applicable to cases with some (i, j) < 0, the following modifications can be made:
1. Initialize all labels (tentative distances) to infinity, except for the source node, which is set to zero.
2. Modify the condition for selecting the node with the minimum label. Instead of selecting the closest node, choose the node with the minimum non-infinity label.
3. When updating the labels, if the sum of the current node’s label and the link length is negative, set the label to zero instead of the negative value.
4. Continue the algorithm until all labels become permanent (i.e., all nodes are closed), or until no labels change during a pass.
These modifications ensure that negative link lengths are properly handled during the computation of shortest paths.