Overview
The Max Flow algorithm computes the maximum amount of flow that can be routed through a directed, weighted graph from one or more source nodes to one or more sink (target) nodes. Edge weights represent capacities — the upper bound on how much flow an edge can carry. Max Flow is commonly applied in scenarios such as:- Network throughput optimization (bandwidth, pipelines, logistics)
- Traffic routing and congestion analysis
- Supply chain and distribution planning
- Bipartite matching and scheduling problems
Algorithm Details
The procedure implements a capacity-scaling max-flow algorithm over the subgraph induced by the specified node labels and relationship types. It builds a residual graph from the selected edges (using the configured capacity property), then repeatedly finds augmenting paths from the source super-node to the sink super-node and pushes flow along them until no augmenting path exists. Multiple source or sink nodes are supported by introducing a virtual super-source connected to every source node, and a virtual super-sink connected from every sink node, each with infinite capacity. The algorithm returns the set of nodes and edges that carry positive flow, together with the per-edge flow values and the total maximum flow.Performance
The algorithm operates with a time complexity of O(V · E²), where:- |V| represents the total number of nodes in the subgraph
- |E| represents the total number of edges in the subgraph
Syntax
Parameters
The procedure accepts a required configurationMap with the following parameters:
Return Values
The procedure yields a single record with the following fields:Examples
Consider this pipeline network:- A → C directly, with capacity 5
- A → B → C, with a bottleneck of 8 (min of 10 and 8)
Create the Graph
Example: Compute the maximum flow between two nodes
Expected Results
Example: Inspect per-edge flow on the solution
Expected Results
Example: Restrict the subgraph by node label
When the graph contains multiple node labels, usenodeLabels to limit the algorithm to a specific subset of nodes:
Example: Multiple sources and multiple sinks
sourceNodes and targetNodes each accept arrays, allowing multi-commodity-style problems to be modelled with virtual super-nodes:
Frequently Asked Questions
What is the max flow algorithm used for?
What is the max flow algorithm used for?
Max Flow computes the greatest amount of flow that can be pushed from source nodes to sink nodes through a capacity-constrained network. It is commonly used for network throughput and bandwidth planning, traffic routing and congestion analysis, supply chain and distribution planning, and bipartite matching or scheduling problems.
How do I run max flow in FalkorDB?
How do I run max flow in FalkorDB?
Match your source and target nodes, then call
algo.maxFlow with a configuration map: CALL algo.maxFlow(...) YIELD nodes, edges, edgeFlows, maxFlow. Unlike most FalkorDB algorithms, the configuration map is required — sourceNodes, targetNodes, and relationshipTypes must all be supplied.Can algo.maxFlow handle multiple sources and sinks?
Can algo.maxFlow handle multiple sources and sinks?
Yes. Both
sourceNodes and targetNodes accept arrays. FalkorDB adds a virtual super-source connected to every source and a virtual super-sink fed by every sink, each with infinite capacity, so multi-source and multi-sink problems work without changing your graph.Which edge property is used as the capacity?
Which edge property is used as the capacity?
The property named by
capacityProperty, which defaults to 'capacity'. If your edges store capacity under a different name — such as cap or bandwidth — set capacityProperty to that name.What do the nodes and edges fields returned by algo.maxFlow contain?
What do the nodes and edges fields returned by algo.maxFlow contain?
They contain only the entities that carry positive flow in the solution, not the whole subgraph.
edgeFlows holds the numeric flow for each edge in edges, in the same order, so you can zip them together with UNWIND range(0, size(edges) - 1).How do I limit max flow to part of my graph?
How do I limit max flow to part of my graph?
Use
relationshipTypes to choose which edges form the flow network, and nodeLabels to restrict which nodes participate. Only the induced subgraph is considered, which also keeps the computation faster.How does max flow perform on large graphs?
How does max flow perform on large graphs?
The algorithm is O(V · E²) in the worst case, where
V and E are the nodes and edges of the selected subgraph. Sparse graphs typically run much faster in practice. Narrowing the subgraph with nodeLabels and relationshipTypes is the most effective way to speed it up.