Chapter 4
Shortest Paths: Label-Setting
Algorithms
1
4.1 Introduction
Directed network G = (N, A) with an arc length (cost) cij associated with each
arc (i, j)A. C = max{ cij: (i, j)A}
Given source node s, find shortest path from s to every other node iN\{s}.
(finding s-t shortest path gives shortest paths to every other iN\{s}as
byproducts.)
May interpret as sending one unit of flow from s to each of the nodes iN\{s}
in an uncapacitated network.
Minimize
subject to
(i, j)A cijxij
{j: (i, j)A} xij - {j: (j, i)A} xji = n-1,
= -1,
xij 0 for all (i, j)A
Network Theory and Applications 2010
for i = s
for all iN\{s}
2
Assumption 4.1: Arc lengths are integers
Some algorithms use this assumption in complexity analysis
Assumption 4.2: G contains a directed path from s to every other node.
May add arc (s, i) with large cost for every node i not connected to s by a directed
path.
Assumption 4.3: G does not contain a negative cycle. (negative arc length may
be allowed, but no negative cycle)
LP formulation unbounded if there exists a negative cycle in G.
Combinatorial algorithms try to find shortest length directed walks, hence
unbounded if there exists a negative cycle in G.
Assumption 4.4: The network is directed.
If arc lengths nonnegative, use two arcs with opposite direction
If negative length arc exists, above transformation creates negative cycle. (need
other transformation to handle this (matching).
Network Theory and Applications 2010
3
Various Types of Shortest Path Problems:
Finding shortest path from one node to all other nodes when arc lengths are
nonnegative
Finding shortest path from one node to all other nodes with arbitrary arc lengths.
Finding shortest paths from every node to every other node (all pairs shortest path
problem)
Various generalizations (e.g., k-shortest path problem)
Analog solution of the shortest path problem.
See the 3 observations in text.
Label-Setting and Label-Correcting Algorithms
Network Theory and Applications 2010
4
4.2 Applications
Application 4.3 Knapsack problem
maximize i=1p uixi
subject to i=1p wixi W
xi {0, 1} for all i.
Can be modeled as a longest path problem on an acyclic network.
Compare the dynamic programming algorithm and the algorithm on the
network.
Ex in text)
j
1
2
3
4
uj
40
15
20
10
wj
4
2
3
1
Network Theory and Applications 2010
5
Longest path problem → shortest path problem: take negative of arc lengths
If negative cycle exists, cannot be solved easily. But, the graph is acyclic.
Recall that for dynamic programming, d(i, j) is maximum utility (longest path
length in the transformed graph) using items 1 through i and weight restriction
j.
Exists algorithm for shortest path problem in acyclic networks: O(m)
Does it imply that knapsack problem can be solved in polynomial time? No
Transformed network has O(pW) arcs, hence running time is still O(pW),
which is pseudopolynomial time.
Network Theory and Applications 2010
6
Application 4.4 Tramp Steamer Problem (minimum cost-to-time ratio cycle
problem)
A voyage of tramp steamer from port i to port j earns pij units of profit and
requires ij units of time.
Find tour W that achieves the largest possible mean daily profit
(W) = ( (i, j)W pij) / ((i, j)W ij)
We assume ij 0 for (i, j)A, and (i, j)W ij > 0 for every directed cycle W.
For given 0, consider if there exists W such that
( (i, j)W pij) / ((i, j)W ij) > 0 ,
→
(i, j)W (0ij - pij) < 0
Identify a negative cycle in G with arc cost (0ij - pij). Then, use binary
search.
Network Theory and Applications 2010
7
Application 4.5 System of Difference Constraints:
Consider LP with constraints: having one +1 and one -1 in each constraint
m difference constraints in n variables x = {x(1), x(2), … , x(n)}:
x(jk) – x(ik) b(k)
for each k = 1, … , m.
Want to determine whether it has a feasible solution, and if so, identify a
feasible solution.
Use constraint graph:
Use arc (ik, jk) of length b(k) for the constraint x(jk) – x(ik) b(k)
Network Theory and Applications 2010
8
x(3) – x(4) 5
x(4) – x(1) -10
x(1) – x(3) 8
x(2) – x(1) -11
x(3) – x(2) 2.
Ex)
4
5
0
3
4
5
3
0
8
-10
2
s
1
0
2
-11
Network Theory and Applications 2010
0
8
-10
1
2
2
-11
9
Constraints are identical to the optimality conditions for the shortest path
problem in G (later in Chapter 5). Conditions satisfied if and only if there
does not exist a negative cycle.
Interpret x(i) as the shortest distance from an additional node s to i. Connect
node s to node i with arc cost 0 so that the existence of a path from s to i is
guaranteed for all i.
Note that for negative cycle 1-2-3 in G, we can add the lhs and rhs of the
corresponding constraints respectively and get 0 < -1, which is inconsistent.
Value of a shortest path from s to i gives a feasible solution x(i) for all i. If
negative cycle exists, label correcting algorithm can detect it, and it indicates
inconsistent set of constraints.
Network Theory and Applications 2010
10
Application 4.6 Telephone Operator Scheduling
Telephone company need to schedule operators around the clock.
Let b(i), i = 0, 1, 2, … , 23 denote the minimum number of operators needed
for the i-th hour of the day. (b(0): number needed for 0-1 a.m.)
Each operator works 8 consecutive hours and a shift can begin at any hour.
Want cyclic schedule that repeats daily.(using minimum number of operators )
minimize i=023 yi
subject to
yi-7 + yi-6 + … + yi b(i)
y17+i + … + y23 + y0 + … + yi b(i)
yi 0
for all i = 8 to 23,
for all i = 0 to 7,
for all i =0 to 23.
Note that the rows have 1’s consecutively (in wraparound fashion)
Network Theory and Applications 2010
11
Let x(i) = k=0i yk, i = 0, … , 23
and x(23) = p
yi-7 + yi-6 + … + yi b(i)
for all i = 8 to 23,
y17+i + … + y23 + y0 + … + yi b(i)
for all i = 0 to 7,
yi 0
for all i =0 to 23.
Rewrite the constraints as
x(i) – x(i-8) b(i)
for all i = 8 to 23,
x(23) – x(16+i) + x(i)
= p – x(16+i) + x(i) b(i) for all i = 0 to 7,
x(i) – x(i-1) 0
System of difference constraints. Use binary search.
Network Theory and Applications 2010
12
4.3 Tree of Shortest Paths
Shortest paths from s to all other nodes constitutes a directed out-tree (Shortest
path tree)
Property 4.1 Let s = i1 – i2 - … - ih = k be a shortest path from s to k.
Then subpath s = i1 – i2 - … - iq is a shortest s-iq path for q = 2, 3,…, h-1
P1
s
P3
p
k
P2
P1-P3 is shortest s-k path. If P2 is shorter s-p path, P2-P3 is s-k walk with
shorter length. Can obtain s-k path after eliminating cycles (if no negative
cycle)
Network Theory and Applications 2010
13
Let d() denote the shortest path distances.
P is a shortest s-k path. d(j) = d(i) + cij for every arc (i, j)P.
Converse?
Suppose d(j) = d(i) + cij for every arc in an s-k path P.
Let s = i1 – i2 - … - ih = k be the node sequence in P. Then
d(k) = d(ih) = (d(ih) – d(ih-1)) + (d(ih-1) – d(ih-2)) + … + (d(i2) – d(i1))
= ci(h-1),i(h) + ci(h-2),i(h-1) + … + ci2,i1 = (i, j)P cij
Hence P is a shortest s-k path.
Property 4.2 Let the vector d represent the shortest path distances. Then
s-t path P is a shortest path. d(j) = d(i) + cij for every arc (i, j)P.
Use breadth-first search to identify shortest path tree satisfying d(j) = d(i) + cij.
Network Theory and Applications 2010
14
4.4 Shortest Path Problems in Acyclic Networks
For acyclic network topological ordering with i < j for (i, j)A.
Then for node k, all incoming arcs must come from nodes 1, 2, … , k-1.
By property 4.1, d(k) = minimumi<k {d(i) + cik}.
Algorithm
Initially, d(s) = 0, d(i) = M for large M
scan nodes in topological order
for all arcs (i, j) in adjacency list A(i), if d(j) > d(i) + cij, set d(j) = d(i) + cij.
at termination, d(i)’s are shortest distances (use pointers to identify the paths)
Network Theory and Applications 2010
15
Proof of correctness)
Use induction. Suppose scanned nodes 1, 2, … , k and the distance labels are
optimal. For node k+1, suppose s = i1 – i2 – ih – (k+1) is shortest path to k+1.
By property 4.1, the path i1 – i2 – ih is a shortest s - ih path.
By topological ordering, (ih, k+1)A implies ih {1, 2, … , k}.
By inductive hypothesis, the label of ih is equal to the length of i1 – i2 – ih .
Hence, when examining node ih, algorithm scans arc (ih, k+1) and set the label
of node k+1 as the length of the path i1 – i2 – ih – (k+1).
So, when the algorithm examines node k+1, its distance label is optimal.
Thm 4.3. The reaching algorithm solves the shortest path problem on acyclic
networks in O(m) time.
If the network contains cycles, we need more elaborate schemes.
Network Theory and Applications 2010
16
© Copyright 2026 Paperzz