Send flow from supply nodes to demand nodes through capacitated arcs at least total cost (transshipment allowed): the minimum cost and a flow achieving it.
\min \sum c_{ij} x_{ij}\ \text{s.t.}\ \sum_j x_{vj} - \sum_i x_{iv} = b_v,\ 0 \le x_{ij} \le u_{ij}
Inputs
capacity arc capacities, n x n (row = from node, column = to node, 0 = no arc) matrixcost unit cost of each arc, n x n matrixsupply net supply of each node (positive = supply, negative = demand), summing to 0 vector
Returns
min_cost minimum total costflows optimal flow matrix (only when unique; otherwise flows_example)flow_unique yes when the optimal flow is uniquedual dual values: node potentials then arc-capacity prices
Applies when
- supplies sum to 0
- a feasible flow exists
- at most 60 arcs
Example
m.ask("Find the minimum cost flow with capacity [[0, 10, 5], [0, 0, 10], [0, 0, 0]], cost [[0, 1, 4], [0, 0, 2], [0, 0, 0]] and supply [8, 0, -8].")
→ min_cost = 24, flows = [[0.0, 8.0, 0.0], [0.0, 0.0, 8.0], [0.0, 0.0, 0.0]], flow_unique = yes, dual = [3.0, 2.0, 0.0, 0.0, 0.0, 0.0]