NetworkSimplex Module
Network Simplex algorithm for minimum cost flow problems.
⚠️ EXPERIMENTAL - This implementation is incomplete. The pivot logic
is not fully implemented, causing the algorithm to return Infeasible
for most feasible problems. Use with caution or consider alternative
minimum cost flow algorithms.
Solves the minimum cost flow problem: find the cheapest way to send flow through a network satisfying supply/demand constraints at nodes.
When to Use
- Transportation problems (minimize shipping cost)
- Assignment problems (optimal worker-task assignment)
- Circulation problems with costs
- Problems requiring flow conservation with minimum cost
Problem Definition
Given: - Directed graph with edge capacities and costs per unit flow - Node supplies (positive) or demands (negative) - Total supply = total demand (balanced)
Find: - Flow on each edge satisfying capacity constraints - Flow conservation at each node - Minimum total cost
Key Concepts
Supply/Demand
- Supply node (source): net outflow > 0 (positive demand value)
- Demand node (sink): net inflow > 0 (negative demand value)
- Transshipment node: flow in = flow out (zero demand)
Spanning Tree Structure
The network simplex maintains a spanning tree of "basic" edges and iteratively pivots to improve the solution.
Complexity
- Time: Strongly polynomial variants exist, typically very fast in practice
- Space: O(V + E)
Comparison with Other Algorithms
Problem Type |
Algorithm |
Notes |
|---|---|---|
Max flow (no costs) |
Edmonds-Karp |
Simpler, polynomial |
Min cost flow |
Network Simplex |
Fast in practice |
Min cost flow |
Successive Shortest Paths |
Easier to implement |
Assignment |
Hungarian |
Specialized, O(V³) |
Error Handling
UnbalancedDemands: Total supply ≠ total demandInfeasible: Cannot satisfy all demands with given capacities
Types
| Type | Description |
|
Represents a flow on a single edge. |
|
|
Result of a minimum cost flow computation. |
|
|
Errors that can occur during minimum cost flow computation. |
Functions and values
| Function or value |
Description
|
||
Full Usage:
minCostFlow graph getDemand getCap getCost
Parameters:
Graph<'n, 'e>
getDemand : 'n -> int
getCap : 'e -> int
getCost : 'e -> int
Returns: Result<MinCostFlowResult, NetworkSimplexError>
|
Solves the minimum cost flow problem using the Network Simplex algorithm. ⚠️ WARNING: This implementation is incomplete and experimental.
The pivot loop logic is not fully implemented, which may cause false
Type Parameters
Parameters
Algorithm
Example
Use Cases
val graph: obj
val result: obj
val id: x: 'T -> 'T
val fst: tuple: ('T1 * 'T2) -> 'T1
val snd: tuple: ('T1 * 'T2) -> 'T2
|