MaxFlow Module
Maximum flow and minimum cut algorithms for network flow problems.
Provides the Edmonds-Karp algorithm for computing maximum flow in a flow network, and the max-flow min-cut theorem for extracting minimum cuts.
When to Use
- Network flow optimization problems
- Finding bottlenecks in transportation networks
- Bipartite matching (via max flow)
- Image segmentation (via min cut)
- Project selection problems
Key Concepts
Flow Network
A directed graph where each edge has a capacity and each edge receives a flow. The amount of flow on an edge cannot exceed its capacity.
Maximum Flow
The maximum amount of flow that can be sent from a source node to a sink node without violating capacity constraints.
Minimum Cut
A partition of nodes into two sets (S, T) where source ∈ S and sink ∈ T, minimizing the sum of capacities of edges from S to T.
Complexity
- Time: O(V × E²) for Edmonds-Karp
- Space: O(V + E) for residual graph
Max-Flow Min-Cut Theorem
The maximum flow value equals the capacity of the minimum cut. This fundamental result connects optimization on flows to graph partitioning.
Types
| Type | Description |
|
Result of a max flow computation. Contains both the maximum flow value and information needed to extract the minimum cut. |
|
|
Represents a minimum cut in the network. A cut partitions the nodes into two sets: those reachable from the source in the residual graph (source side) and the rest (sink side). |
Functions and values
| Function or value |
Description
|
||
Full Usage:
edmondsKarp zero add subtract compare minVal source sink graph
Parameters:
'e
add : 'e -> 'e -> 'e
subtract : 'e -> 'e -> 'e
compare : 'e -> 'e -> int
minVal : 'e -> 'e -> 'e
source : NodeId
sink : NodeId
graph : Graph<'n, 'e>
Returns: MaxFlowResult<'e>
|
Finds the maximum flow using the Edmonds-Karp algorithm. Edmonds-Karp is a specific implementation of the Ford-Fulkerson method that uses BFS to find the shortest augmenting path.
Type Parameters
Parameters
Algorithm
Complexity
Example
Applications
val graph: obj
val result: obj
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
val min: e1: 'T -> e2: 'T -> 'T (requires comparison)
|
||
Full Usage:
edmondsKarpInt source sink graph
Parameters: Returns: MaxFlowResult<int>
|
Finds maximum flow with integer capacities.
Parameters
Example
val result: obj
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
|
||
Full Usage:
minCut zero compare result
Parameters:
'e
compare : 'e -> 'e -> int
result : MaxFlowResult<'e>
Returns: MinCut
|
Extracts the minimum cut from a max flow result. Uses the max-flow min-cut theorem, identifying nodes reachable from source in the final residual graph.
Parameters
Algorithm
Example
PropertyThe sum of capacities of edges from SourceSide to SinkSide equals the maximum flow value (max-flow min-cut theorem). val flowResult: obj
val cut: obj
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
|