Flow - Family of functions¶
pgr_maxFlow - Only the Max flow calculation using Push and Relabel algorithm.
pgr_boykovKolmogorov - Boykov and Kolmogorov with details of flow on edges.
pgr_edmondsKarp - Edmonds and Karp algorithm with details of flow on edges.
pgr_pushRelabel - Push and relabel algorithm with details of flow on edges.
Applications
pgr_edgeDisjointPaths - Calculates edge disjoint paths between two groups of vertices.
pgr_maxCardinalityMatch - Calculates a maximum cardinality matching in a graph.
Experimental
Warning
Possible server crash
These functions might create a server crash
Warning
Experimental functions
They are not officially of the current release.
They likely will not be officially be part of the next release:
The functions might not make use of ANY-INTEGER and ANY-NUMERICAL
Name might change.
Signature might change.
Functionality might change.
pgTap tests might be missing.
Might need c/c++ coding.
May lack documentation.
Documentation if any might need to be rewritten.
Documentation examples might need to be automatically generated.
Might need a lot of feedback from the comunity.
Might depend on a proposed function of pgRouting
Might depend on a deprecated function of pgRouting
pgr_maxFlowMinCost - Experimental - Details of flow and cost on edges.
pgr_maxFlowMinCost_Cost - Experimental - Only the Min Cost calculation.
Flow Functions General Information¶
The main characteristics are:
The graph is directed.
Process is done only on edges with positive capacities.
When the maximum flow is 0 then there is no flow and EMPTY SET is returned.
There is no flow when a source is the same as a target.
Any duplicated value in the source(s) or target(s) are ignored.
Calculates the flow/residual capacity for each edge. In the output
Edges with zero flow are omitted.
Creates a super source and edges to all the source(s), and a super target and the edges from all the targets(s).
The maximum flow through the graph is guaranteed to be the value returned by pgr_maxFlow when executed with the same parameters and can be calculated:
By aggregation of the outgoing flow from the sources
By aggregation of the incoming flow to the targets
pgr_maxFlow is the maximum Flow and that maximum is guaranteed to be the same on the functions pgr_pushRelabel, pgr_edmondsKarp, pgr_boykovKolmogorov, but the actual flow through each edge may vary.
Inner Queries¶
Edges SQL¶
Capacity edges
Column |
Type |
Default |
Description |
---|---|---|---|
|
ANY-INTEGER |
Identifier of the edge. |
|
|
ANY-INTEGER |
Identifier of the first end point vertex of the edge. |
|
|
ANY-INTEGER |
Identifier of the second end point vertex of the edge. |
|
|
ANY-INTEGER |
Weight of the edge ( |
|
|
ANY-INTEGER |
-1 |
Weight of the edge (
|
Where:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Capacity-Cost edges
Column |
Type |
Default |
Description |
---|---|---|---|
|
ANY-INTEGER |
Identifier of the edge. |
|
|
ANY-INTEGER |
Identifier of the first end point vertex of the edge. |
|
|
ANY-INTEGER |
Identifier of the second end point vertex of the edge. |
|
|
ANY-INTEGER |
Capacity of the edge (
|
|
|
ANY-INTEGER |
-1 |
Capacity of the edge (
|
|
ANY-NUMERICAL |
Weight of the edge ( |
|
|
ANY-NUMERICAL |
\(-1\) |
Weight of the edge ( |
Where:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Cost edges
Column |
Type |
Default |
Description |
---|---|---|---|
|
ANY-INTEGER |
Identifier of the edge. |
|
|
ANY-INTEGER |
Identifier of the first end point vertex of the edge. |
|
|
ANY-INTEGER |
Identifier of the second end point vertex of the edge. |
|
|
ANY-NUMERICAL |
Weight of the edge ( |
|
|
ANY-NUMERICAL |
-1 |
Weight of the edge (
|
Where:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Combinations SQL¶
Parameter |
Type |
Description |
---|---|---|
|
ANY-INTEGER |
Identifier of the departure vertex. |
|
ANY-INTEGER |
Identifier of the arrival vertex. |
Where:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
Result Columns¶
Used in
Column |
Type |
Description |
---|---|---|
seq |
|
Sequential value starting from 1. |
edge |
|
Identifier of the edge in the original query (edges_sql). |
start_vid |
|
Identifier of the first end point vertex of the edge. |
end_vid |
|
Identifier of the second end point vertex of the edge. |
flow |
|
Flow through the edge in the direction
( |
residual_capacity |
|
Residual capacity of the edge in the direction
( |
For pgr_maxFlowMinCost - Experimental
Column |
Type |
Description |
---|---|---|
seq |
|
Sequential value starting from 1. |
edge |
|
Identifier of the edge in the original query (edges_sql). |
source |
|
Identifier of the first end point vertex of the edge. |
target |
|
Identifier of the second end point vertex of the edge. |
flow |
|
Flow through the edge in the direction (source, target). |
residual_capacity |
|
Residual capacity of the edge in the direction (source, target). |
cost |
|
The cost of sending this flow through the edge in the direction (source, target). |
agg_cost |
|
The aggregate cost. |
Adcanced Documentation¶
A flow network is a directed graph where each edge has a capacity and a flow. The flow through an edge must not exceed the capacity of the edge. Additionally, the incoming and outgoing flow of a node must be equal except for source which only has outgoing flow, and the destination(sink) which only has incoming flow.
Maximum flow algorithms calculate the maximum flow through the graph and the flow of each edge.
The maximum flow through the graph is guaranteed to be the same with all implementations, but the actual flow through each edge may vary.
Given the following query:
pgr_maxFlow \((edges\_sql, source\_vertex, sink\_vertex)\)
where \(edges\_sql = \{(id_i, source_i, target_i, capacity_i, reverse\_capacity_i)\}\)
Graph definition
The weighted directed graph, \(G(V,E)\), is defined as:
the set of vertices \(V\)
\(source\_vertex \cup sink\_vertex \bigcup source_i \bigcup target_i\)
the set of edges \(E\)
\(E = \begin{cases} \text{ } \{(source_i, target_i, capacity_i) \text{ when } capacity > 0 \} & \quad \text{ if } reverse\_capacity = \varnothing \\ \text{ } & \quad \text{ } \\ \{(source_i, target_i, capacity_i) \text{ when } capacity > 0 \} & \text{ } \\ \cup \{(target_i, source_i, reverse\_capacity_i) \text{ when } reverse\_capacity_i > 0)\} & \quad \text{ if } reverse\_capacity \neq \varnothing \\ \end{cases}\)
Maximum flow problem
Given:
\(G(V,E)\)
\(source\_vertex \in V\) the source vertex
\(sink\_vertex \in V\) the sink vertex
Then:
\(pgr\_maxFlow(edges\_sql, source, sink) = \boldsymbol{\Phi}\)
\(\boldsymbol{\Phi} = {(id_i, edge\_id_i, source_i, target_i, flow_i, residual\_capacity_i)}\)
Where:
\(\boldsymbol{\Phi}\) is a subset of the original edges with their residual capacity and flow. The maximum flow through the graph can be obtained by aggregating on the source or sink and summing the flow from/to it. In particular:
\(id_i = i\)
\(edge\_id = id_i\) in edges_sql
\(residual\_capacity_i = capacity_i - flow_i\)
See Also¶
Indices and tables