{"id":262,"date":"2026-11-13T12:36:16","date_gmt":"2026-11-13T04:36:16","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-successive-shortest-paths-price-a-min-cost-flow\/"},"modified":"2026-11-13T21:53:57","modified_gmt":"2026-11-13T13:53:57","slug":"how-successive-shortest-paths-price-a-min-cost-flow","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-successive-shortest-paths-price-a-min-cost-flow\/","title":{"rendered":"How successive shortest paths price a min-cost flow"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Successive shortest paths<\/strong> compute a <strong>minimum-cost maximum flow<\/strong>, 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. <strong>Potentials<\/strong> from those distances reprice the edges so the next search sees nonnegative reduced costs and can use <strong>Dijkstra<\/strong>. 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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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) \u2212 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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Start from the zero flow and zero potentials. Backward residual cost of an edge is the negation of its forward cost.<\/li>\n<li>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) \u2212 h(v).<\/li>\n<li>Augment by the minimum of the residual bottleneck and the remaining demand. Update residual capacities. Backward edges appear with negated cost.<\/li>\n<li>Replace each potential by the sum of itself and the distance Dijkstra just computed. Reduced costs stay nonnegative for the next round.<\/li>\n<li>If the sink is unreachable before the demand is met, no feasible flow of that value exists.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when a negative backward edge is handed to Dijkstra<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Run Dijkstra on raw residual costs after the first augmentation<\/td>\n<td>A backward edge has negative cost. Dijkstra can settle a vertex before the cheap cancellation is considered.<\/td>\n<\/tr>\n<tr>\n<td>Forget to update potentials after a search<\/td>\n<td>The reduced costs of the next round can go negative even if the previous round was nonnegative. The distance update is what restores them.<\/td>\n<\/tr>\n<tr>\n<td>Augment along a shortest hop path instead of a cheapest path<\/td>\n<td>That maximizes nothing about cost. It is Edmonds-Karp, and the cost can be arbitrarily worse than optimal.<\/td>\n<\/tr>\n<tr>\n<td>Quote a polynomial bound in the bits of the capacity<\/td>\n<td>The number of augmentations tracks the flow value. Polynomial time needs scaling or a different min-cost algorithm.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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 <code>3<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import heapq\ngraph = [[] for _ in range(4)]\n\ndef add_edge(u, v, cap, cost):\n    graph[u].append([v, cap, cost, len(graph[v])])\n    graph[v].append([u, 0, -cost, len(graph[u]) - 1])\n\nadd_edge(0, 1, 2, 1)\nadd_edge(0, 2, 2, 4)\nadd_edge(1, 2, 1, -1)\nadd_edge(1, 3, 2, 1)\nadd_edge(2, 3, 2, 1)\npotential = [0] * 4\nflow = cost = 0\ndemand = 2\nwhile flow &lt; demand:\n    dist = [10 ** 9] * 4\n    dist[0] = 0\n    prev = [None] * 4\n    heap = [(0, 0)]\n    while heap:\n        d, u = heapq.heappop(heap)\n        if d != dist[u]:\n            continue\n        for i, (v, cap, edge_cost, _) in enumerate(graph[u]):\n            reduced = edge_cost + potential[u] - potential[v]\n            if cap and d + reduced &lt; dist[v]:\n                dist[v] = d + reduced\n                prev[v] = (u, i)\n                heapq.heappush(heap, (dist[v], v))\n    if dist[3] &gt;= 10 ** 9:\n        break\n    for i in range(4):\n        if dist[i] &lt; 10 ** 9:\n            potential[i] += dist[i]\n    add = demand - flow\n    v = 3\n    while v != 0:\n        u, i = prev[v]\n        add = min(add, graph[u][i][1])\n        v = u\n    v = 3\n    while v != 0:\n        u, i = prev[v]\n        edge = graph[u][i]\n        edge[1] -= add\n        graph[v][edge[3]][1] += add\n        cost += add * edge[2]\n        v = u\n    flow += add\nassert flow == 2 and cost == 3\nprint(cost)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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. <strong>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.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-graphs"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":661,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/262\/revisions\/661"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}