Network Flow - max flow
Problem: send as much flow as possible from a source node to a sink node through arcs with limited capacities.
Show code
import { initNetworkFlow, SimpleMaxFlow, setWorkerBridgeEnabled } from 'or-tools-wasm/network-flow';
setWorkerBridgeEnabled(true);
await initNetworkFlow();
const maxFlow = new SimpleMaxFlow();
maxFlow.add_arcs_with_capacity(startNodes, endNodes, capacities);
const status = await maxFlow.solve(sourceNode, sinkNode);
- Flow starts at the green source node and must reach the red sink node.
- Each directed arc has a capacity: the maximum flow it can carry.
- The solver chooses arc flows that maximize total source-to-sink throughput.
- After solving, thicker blue arcs carry more flow and labels show flow/capacity.
- The min cut identifies the bottleneck separating source-side and sink-side nodes.
Run the solver to view the max-flow solution.
Status: