Minimum-Cost Flows and Klein's Negative-Cycle Optimality Theorem #
Formalizes minimum-cost integral network flows over arbitrary vertex balances, Klein's negative-cycle optimality theorem and complementary slackness characterization ([Kle67], pp. 205–220, locator not re-verified against primary PDF; [Sch03], Chapter 12, locator not re-verified against primary PDF), and executable cycle-canceling algorithms.
Model and source mapping #
- Capacitated cost networks (
CostNetwork V W): finite vertex typeV, nonnegative integral arc capacitiescap : V → V → ℕ, per-unit arc costscost : V → V → Win a linearly ordered additive commutative groupW(e.g.,ℤ,ℚ, orℝ), and net vertex supply balancesbalance : V → ℤ(balance = 0for circulations,±valats, tfor fixed-values–tflows). Antiparallel arcs(u, v)and(v, u)with distinct costs (cost u v ≠ -cost v u) and self-loops(v, v)are supported directly. - Feasible flows (
CostNetwork.Flow): integral flows0 ≤ f u v ≤ M.cap u vsatisfying exact balance∑ w, f v w - ∑ u, f u v = M.balance vat every vertexv. - Residual steps (
ResArc V): because antiparallel arcs may carry independent costs, residual steps distinguish forward increments(u, v, true)(f u v < cap u v, residual cost+cost u v) from backward cancellations(u, v, false)(0 < f v u, residual cost-cost v u). - Complementary slackness (
CompSlackness): node potentialsπ : V → Wsatisfyingf u v < cap u v → 0 ≤ cost u v + π u - π vand0 < f u v → cost u v + π u - π v ≤ 0. - Source comparison: [Kle67], pp. 205–220 gives the negative-cycle optimality theorem and primal cycle-canceling algorithm; [Sch03], Chapter 12 develops the complementary slackness and cycle-canceling characterizations over arbitrary vertex supply balances.
Main definitions #
Cslib.Algorithms.Lean.MaxFlow.CostNetwork,CostNetwork.Flow,CostNetwork.Flow.totalCost,CostNetwork.Flow.IsMinCost: minimum-cost flow networks, feasible flows, total cost, and optimality.Cslib.Algorithms.Lean.MaxFlow.ResArc,CostNetwork.resCost,CostNetwork.walkCost,CostNetwork.Flow.resCap,CostNetwork.Flow.IsResWalk,CostNetwork.Flow.IsResCycle,CostNetwork.Flow.cycleBottleneck,CostNetwork.Flow.cancelCycle,CostNetwork.CompSlackness: residual network, cycle cancellation, and potentials.Cslib.Algorithms.Lean.MaxFlow.CostNetwork.findNegCycleOrPotential,CostNetwork.CycleCancelOutput,CostNetwork.cycleCancelLoop,CostNetwork.cycleCancelInt: Bellman–Ford relaxation DP negative-cycle / potential finder and executable cycle-canceling solver.Cslib.Algorithms.Lean.MaxFlow.CostNetwork.ofNetwork,Network.Flow.flowCost,Network.Flow.IsMinCostOfValue,Cslib.Algorithms.Lean.MaxFlow.MinCostMaxFlowOutput,Cslib.Algorithms.Lean.MaxFlow.minCostMaxFlow: bridge tos–tflows and executable minimum-cost maximum-flow solver overFin n.
Main results #
Cslib.Algorithms.Lean.MaxFlow.CostNetwork.isMinCost_iff_not_exists_negCycle: Klein's negative-cycle criterion ([Kle67], locator not re-verified against primary PDF): a feasible flow has minimum cost iff its residual network contains no negative simple cycle.Cslib.Algorithms.Lean.MaxFlow.CostNetwork.isMinCost_iff_exists_compSlackness: complementary slackness theorem ([Sch03], Chapter 12, locator not re-verified against primary PDF): a feasible flow has minimum cost iff it admits complementary-slackness potentials.Cslib.Algorithms.Lean.MaxFlow.CostNetwork.cycleCancelInt_correct,CostNetwork.exists_isMinCost_of_feasible: correctness and pseudo-polynomial termination of integral cycle canceling (≤ 2 * absCostBoundcancellations), and existence of optimal flows for arbitrary linearly ordered group costsW.Cslib.Algorithms.Lean.MaxFlow.Network.Flow.isMinCostOfValue_iff_not_exists_negCycle,Network.Flow.isMinCostOfValue_iff_exists_compSlackness,Cslib.Algorithms.Lean.MaxFlow.minCostMaxFlow_correct: exact specializations to fixed-values–tflows and minimum-cost maximum flows.
Cost model and scope #
CostNetwork.cycleCancelIntcancels an arbitrary Bellman–Ford negative residual cycle per iteration and proves a pseudo-polynomial cancellation bound (≤ 2 * absCostBound M vs) rather than minimum-mean cycle canceling or Word-RAM machine time.
References #
Cost networks, feasible flows, and residual arcs #
A directed step in the residual network: isFwd = true increases flow on (src, dst)
and isFwd = false decreases flow on (dst, src).
- src : V
Tail vertex of the residual step.
- dst : V
Head vertex of the residual step.
- isFwd : Bool
truefor a forward step(src, dst);falsefor canceling reverse arc(dst, src).
A feasible integral flow on M: bounded by M.cap and matching M.balance at every
vertex.
- toFun : V → V → ℕ
Integral flow assigned to each directed arc
(u, v). Capacity bound on every directed arc.
Exact vertex net-outflow conservation against
M.balance.
Instances For
Zero circulation on a network whose vertex balances all vanish.
Residual cost of a step a : ResArc V: cost u v forward, -cost v u backward.
Total cost of an arc list in the residual network.
Total cost ∑ u, ∑ v, f u v • M.cost u v of a feasible flow f.
f is a minimum-cost feasible flow on M.
Residual capacity of step a : ResArc V with respect to f.
Walk predicate in f's residual network.
Instances For
arcs is a nonempty simple directed cycle in f's residual network (distinct start
vertices, allowing self-loops [⟨v, v, b⟩] and 2-cycles [⟨u, v, b₁⟩, ⟨v, u, b₂⟩]).
Instances For
Minimum residual capacity along a list of residual arcs (0 when empty).
Complementary slackness optimality condition for f and potentials π : V → W.
Residual walks, bottleneck, and cycle cancellation #
Raw arc-flow update adding δ on forward arcs of arcs and subtracting δ on backward arcs
of arcs.
Cancel δ units of flow around a residual cycle arcs (δ ≤ f.resCap a for all a ∈ arcs).
Canceling δ units along a residual cycle arcs changes totalCost by δ • M.walkCost arcs.
Complementary slackness optimality #
Flow conservation identity against vertex potentials:
∑ u, ∑ v, f u v • (π u - π v) = ∑ u, M.balance u • π u.
Complementary slackness implies minimum cost ([Kle67], [Sch03], Chapter 12,
locator not re-verified against primary PDF): any feasible flow admitting potentials π with
CompSlackness M f π minimizes totalCost among all feasible flows of M.
Simple cycle extraction from walks #
Extract a simple directed cycle (pre, cyc, post) from an arc walk ending at v, scanning
right-to-left, or none when arcs.map src ++ [v] has no duplicate vertices.
Structural-fuel helper for peelNegCycle.
Peel simple cycles from arcs (ending at v) until returning the first negative-cost simple
cycle.
Bellman–Ford relaxation DP for negative cycles and potentials #
All positive-residual-capacity arcs of f whose endpoints lie in vs.
Synchronous one-round Bellman–Ford relaxation storing (bestWeight, arcTrail) per vertex.
k-round synchronous Bellman–Ford relaxation from (0, []) at every vertex.
Run Bellman–Ford relaxation DP for vs.length - 1 steps from (0, []) and return either a
negative simple residual cycle (Sum.inl cyc) or complementary-slackness potentials
(Sum.inr π).
Klein's negative-cycle optimality theorem #
Klein's negative-cycle optimality theorem ([Kle67], pp. 205–220, locator not re-verified against primary PDF; [Sch03], Chapter 12, locator not re-verified against primary PDF): a feasible flow has minimum cost if and only if its residual network contains no negative-cost simple cycle.
Complementary slackness optimality theorem ([Sch03], Chapter 12, locator not re-verified against primary PDF): a feasible flow has minimum cost if and only if it admits complementary-slackness node potentials.
Cycle canceling algorithm and existence of minimum-cost flows #
Result of executable negative-cycle canceling on M : CostNetwork V W.
Iteratively find and cancel negative residual cycles up to fuel steps, returning an
optimal flow and complementary-slackness potentials once none remain.
Any feasible flow network with linearly ordered additive group costs admits a minimum-cost feasible flow and complementary-slackness potentials.
Explicit upper bound on |f.totalCost| over a vertex enumeration vs for integer-cost
networks.
Executable integral negative-cycle canceling ([Kle67], pp. 205–220, locator not
re-verified against primary PDF): repeatedly extracts and cancels a negative simple residual cycle
starting from f₀. Terminates in at most 2 * absCostBound M vs cancellations.
Correctness of executable cycle canceling ([Kle67], pp. 205–220, locator not
re-verified against primary PDF): on any finite vertex list vs covering V, cycleCancelInt
returns a minimum-cost feasible flow certified by complementary-slackness potentials after at most
2 * absCostBound M vs cancellations.
Fixed-value s-t flows and minimum-cost maximum flow #
Embed an s-t Network V with fixed net flow value val into a CostNetwork V W
with arc costs cost.
Total cost ∑ u, ∑ v, f u v • cost u v of an s-t flow f : N.Flow.
Fixed-value minimum-cost s-t flow optimality: f minimizes flowCost cost among all
feasible flows on N with the same value as f.
View an s-t flow g : N.Flow with g.value = val as a feasible flow in
CostNetwork.ofNetwork N cost val.
View an s-t flow f : N.Flow as a feasible flow of value f.value in
CostNetwork.ofNetwork N cost f.value.
View a feasible flow f in CostNetwork.ofNetwork N cost val back as an s-t flow on N.
Klein's negative-cycle optimality theorem for s-t flows ([Kle67], pp. 205–220,
locator not re-verified against primary PDF): an s-t flow f has minimum cost among all flows
of value f.value if and only if its residual network contains no negative-cost simple cycle.
Complementary slackness optimality theorem for s-t flows ([Sch03],
Chapter 12, locator not re-verified against primary PDF): an s-t flow f has minimum cost
among all flows of value f.value if and only if it admits complementary-slackness potentials.
Output of minCostMaxFlow: an integral maximum s-t flow of minimum cost, node
potentials certifying fixed-value minimum cost, and the number of negative-cycle cancellations.
Compute a minimum-cost maximum s-t flow on N : Network (Fin n) by finding an initial
maximum flow via dinitzDense (or Network.Flow.zero N when N.s = N.t) and canceling negative
residual cycles via CostNetwork.cycleCancelInt.
Correctness of minCostMaxFlow ([Kle67], pp. 205–220; [Sch03], Chapter 12,
locators not re-verified against primary PDF): returns a maximum s-t flow that minimizes
flowCost cost among all flows of its value (hence among all maximum flows), together with
complementary-slackness potentials certifying optimality.