How successive shortest paths price a min-cost flow

Short answer: Successive shortest paths compute a minimum-cost maximum flow, or a flow of a demanded value. Each augmentation is a cheapest path in the residual graph under edge costs, with backward edges carrying the negated cost. Potentials from those distances reprice the edges so the next search sees nonnegative reduced costs and can use Dijkstra. The flow stays minimum-cost among all flows of its current value. With nonnegative original costs and no potentials, the first search is already a Dijkstra.


What the problem actually asks

Maximum flow ignores cost. Among all flows of a given value, the minimum-cost one sends the next unit of flow along a cheapest residual path. Sending it along any other residual path would leave a negative-cost cycle or a cheaper augmentation unused. That is the successive-shortest-path theorem.

A cheapest path with negative residual costs, the backward edges, is a Bellman-Ford computation. After one search, vertex potentials h(v) equal to the cheapest-path distance make every reduced cost c(u,v) + h(u) − h(v) nonnegative. The next search is then Dijkstra on reduced costs, and the true path cost is recovered by the same endpoint correction Johnson uses.


What the algorithm guarantees

If a feasible flow of the demanded value exists, the algorithm returns one of minimum cost, provided a negative cycle is absent from the original graph or is handled as an infeasibility of the cheapest-path problem. Each augmentation increases the flow value by the bottleneck. For unit demands, or for integer capacities augmented by the bottleneck, the number of augmentations is bounded by the demanded value, so the algorithm is pseudo-polynomial in that value and polynomial only when the value is small or a scaling version is used. Extra memory is the residual graph, the potentials, and one Dijkstra heap.

Cost scaling and capacity scaling replace the pseudo-polynomial bound with a polynomial one. They are refinements of this idea, not the basic procedure. A negative reduced cost after a potential update means the potential was not the true distance.


The working steps

  1. Start from the zero flow and zero potentials. Backward residual cost of an edge is the negation of its forward cost.
  2. While the flow value is below the demand and the sink is reachable, compute a cheapest residual path from the source. Use Dijkstra on reduced costs c(u,v) + h(u) − h(v).
  3. Augment by the minimum of the residual bottleneck and the remaining demand. Update residual capacities. Backward edges appear with negated cost.
  4. Replace each potential by the sum of itself and the distance Dijkstra just computed. Reduced costs stay nonnegative for the next round.
  5. If the sink is unreachable before the demand is met, no feasible flow of that value exists.

The basic version is pseudo-polynomial in the flow value. It is the right algorithm for moderate demands and the wrong complexity quote for a huge capacity. Maximum flow with no costs is Dinic or push-relabel. Assignment is the special case this algorithm also solves, with unit supplies.


Approaches that look simpler and fail

Approach Why it fails when a negative backward edge is handed to Dijkstra
Run Dijkstra on raw residual costs after the first augmentation A backward edge has negative cost. Dijkstra can settle a vertex before the cheap cancellation is considered.
Forget to update potentials after a search The reduced costs of the next round can go negative even if the previous round was nonnegative. The distance update is what restores them.
Augment along a shortest hop path instead of a cheapest path That maximizes nothing about cost. It is Edmonds-Karp, and the cost can be arbitrarily worse than optimal.
Quote a polynomial bound in the bits of the capacity The number of augmentations tracks the flow value. Polynomial time needs scaling or a different min-cost algorithm.

Uncosted maximum flow belongs to Dinic or push-relabel. A dense assignment problem can use the Hungarian algorithm and avoid an explicit residual graph. Successive shortest paths are the min-cost method that makes the potential correction visible.


A working example

This Python fragment augments the cheapest residual path under reduced costs and adds the distances into the potentials. One edge has cost -1. Shipping two units costs 3.

import heapq
graph = [[] for _ in range(4)]

def add_edge(u, v, cap, cost):
    graph[u].append([v, cap, cost, len(graph[v])])
    graph[v].append([u, 0, -cost, len(graph[u]) - 1])

add_edge(0, 1, 2, 1)
add_edge(0, 2, 2, 4)
add_edge(1, 2, 1, -1)
add_edge(1, 3, 2, 1)
add_edge(2, 3, 2, 1)
potential = [0] * 4
flow = cost = 0
demand = 2
while flow < demand:
    dist = [10 ** 9] * 4
    dist[0] = 0
    prev = [None] * 4
    heap = [(0, 0)]
    while heap:
        d, u = heapq.heappop(heap)
        if d != dist[u]:
            continue
        for i, (v, cap, edge_cost, _) in enumerate(graph[u]):
            reduced = edge_cost + potential[u] - potential[v]
            if cap and d + reduced < dist[v]:
                dist[v] = d + reduced
                prev[v] = (u, i)
                heapq.heappush(heap, (dist[v], v))
    if dist[3] >= 10 ** 9:
        break
    for i in range(4):
        if dist[i] < 10 ** 9:
            potential[i] += dist[i]
    add = demand - flow
    v = 3
    while v != 0:
        u, i = prev[v]
        add = min(add, graph[u][i][1])
        v = u
    v = 3
    while v != 0:
        u, i = prev[v]
        edge = graph[u][i]
        edge[1] -= add
        graph[v][edge[3]][1] += add
        cost += add * edge[2]
        v = u
    flow += add
assert flow == 2 and cost == 3
print(cost)

Where it is used

Successive shortest paths solve a minimum-cost flow: transportation problems and priced assignment, where each augmenting path is cheapest under the current potentials. A maximum flow ignores cost. The Hungarian algorithm is the bipartite assignment special case.


When you can drop this algorithm

Drop basic successive shortest paths when the demanded value is huge and no scaling is implemented. Use a polynomial min-cost flow algorithm. Keep this procedure when costs matter, the demand is moderate, and every Dijkstra runs on reduced costs that the potentials keep nonnegative.


Why this stays published

We publish this so a search for successive shortest paths returns the negated backward cost and the potential that lets the next search run Dijkstra. Successive shortest paths build a min-cost flow by augmenting a cheapest residual path and updating potentials so the next path is a Dijkstra search.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *