| Crates.io | networkflow |
| lib.rs | networkflow |
| version | 0.1.1 |
| created_at | 2025-11-14 09:46:34.971098+00 |
| updated_at | 2025-11-20 15:14:49.326294+00 |
| description | A collection of network flow algorithms. |
| homepage | |
| repository | https://github.com/pvunderink/networkflow |
| max_upload_size | |
| id | 1932522 |
| size | 24,794 |
A Rust library for network flow algorithms.
use networkflow::FlowGraph;
// Create a new flow graph with f64 as flow type and cost type
let mut graph: FlowGraph<f64, f64> = FlowGraph::new();
let node_a = graph.add_node();
let node_b = graph.add_node();
let node_c = graph.add_node();
let source_to_a = graph.add_edge(graph.source(), node_a, 10.0, 10.0); // Edge with high cost and high capacity
let source_to_b = graph.add_edge(graph.source(), node_b, 5.0, 1.0); // Edge with lower cost and lower capacity
graph.add_edge(node_a, node_c, f64::INFINITY, 1.0); // Infinite capacity edge with low cost
graph.add_edge(node_b, node_c, f64::INFINITY, 1.0); // Infinite capacity edge with low cost
let c_to_sink = graph.add_edge(node_c, graph.sink(), 10.0, 1.0); // Bottleneck edge to sink
// Maximize flow
graph.maximize_flow();
// Inspect flow along edges
assert_eq!(graph.get_flow(source_to_a), 5.0);
assert_eq!(graph.get_flow(source_to_b), 5.0);
assert_eq!(graph.get_flow(c_to_sink), 10.0);
This project is available under the MIT license.