pgr_maxFlow - pgRouting Manual (3.2)
pgr_maxFlow
   
    
     pgr_maxFlow
    
   
   - Calculates the maximum flow in a directed graph from the source(s) to the targets(s) using the Push Relabel algorithm.
  
   
   Availability
- 
    
Version 3.2.0
- 
      
New proposed function:
- 
        
pgr_maxFlow(Combinations)
 
 - 
        
 
 - 
      
 - 
    
Version 3.0.0
- 
      
Official function
 
 - 
      
 - 
    
Version 2.4.0
- 
      
New Proposed function
 
 - 
      
 
Description
The main characteristics are:
- 
     
The graph is directed .
 - 
     
Calculates the maximum flow from the source(s) to the target(s) .
- 
       
When the maximum flow is 0 then there is no flow and 0 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.
 - 
     
Uses the pgr_pushRelabel algorithm.
 
- 
     
Running time: \(O( V ^ 3)\)
 
Signatures
Summary
pgr_maxFlow(Edges SQL, source,  target)
pgr_maxFlow(Edges SQL, sources,  target)
pgr_maxFlow(Edges SQL, source,  targets)
pgr_maxFlow(Edges SQL, sources,  targets)
pgr_maxFlow(Edges SQL, Combinations SQL) -- Proposed on v3.2
RETURNS BIGINT
    One to One
pgr_maxFlow(Edges SQL, source,  target)
RETURNS BIGINT
     - Example :
 - 
      
From vertex \(6\) to vertex \(11\)
 
SELECT * FROM pgr_maxFlow(
    'SELECT id,
            source,
            target,
            capacity,
            reverse_capacity
    FROM edge_table'
    , 6, 11
);
 pgr_maxflow
-------------
         230
(1 row)
     One to Many
pgr_maxFlow(Edges SQL, source,  targets)
RETURNS BIGINT
     - Example :
 - 
      
From vertex \(6\) to vertices \(\{11, 1, 13\}\)
 
SELECT * FROM pgr_maxFlow(
    'SELECT id,
            source,
            target,
            capacity,
            reverse_capacity
    FROM edge_table'
    , 6, ARRAY[11, 1, 13]
);
 pgr_maxflow
-------------
         340
(1 row)
     Many to One
pgr_maxFlow(Edges SQL, sources,  target)
RETURNS BIGINT
     - Example :
 - 
      
From vertices \(\{6, 8, 12\}\) to vertex \(11\)
 
SELECT * FROM pgr_maxFlow(
    'SELECT id,
            source,
            target,
            capacity,
            reverse_capacity
    FROM edge_table'
    , ARRAY[6, 8, 12], 11
);
 pgr_maxflow
-------------
         230
(1 row)
     Many to Many
pgr_maxFlow(Edges SQL, sources,  targets)
RETURNS BIGINT
     - Example :
 - 
      
From vertices \(\{6, 8, 12\}\) to vertices \(\{1, 3, 11\}\)
 
SELECT * FROM pgr_maxFlow(
    'SELECT id,
            source,
            target,
            capacity,
            reverse_capacity
    FROM edge_table'
    , ARRAY[6, 8, 12], ARRAY[1, 3, 11]
);
 pgr_maxflow
-------------
         360
(1 row)
     Combinations
pgr_maxFlow(Edges SQL, Combinations SQL)
RETURNS BIGINT
     - Example :
 - 
      
Using a combinations table, equivalent to calculating result from vertices \(\{6, 8, 12\}\) to vertices \(\{1, 3, 11\}\) .
 
SELECT * FROM pgr_maxFlow(
    'SELECT id,
            source,
            target,
            capacity,
            reverse_capacity
    FROM edge_table',
    'SELECT * FROM ( VALUES (6, 1), (8, 3), (12, 11), (8, 1) ) AS t(source, target)'
);
 pgr_maxflow
-------------
         360
(1 row)
     Parameters
| 
        Column  | 
      
        Type  | 
      
        Default  | 
      
        Description  | 
     
|---|---|---|---|
| 
        Edges SQL  | 
      
        
          | 
      
        Edges query as described in Inner Queries .  | 
     |
| 
        Combinations SQL  | 
      
        
          | 
      
        Combinations query as described in Inner Queries .  | 
     |
| 
        source  | 
      
        
          | 
      
        Identifier of the starting vertex of the flow.  | 
     |
| 
        sources  | 
      
        
          | 
      
        Array of identifiers of the starting vertices of the flow.  | 
     |
| 
        target  | 
      
        
          | 
      
        Identifier of the ending vertex of the flow.  | 
     |
| 
        targets  | 
      
        
          | 
      
        Array of identifiers of the ending vertices of the flow.  | 
     
Inner queries
- Edges SQL :
 - 
     
an SQL query of a directed graph of capacities, which should return a set of rows with the following columns:
 
| 
        Column  | 
      
        Type  | 
      
        Default  | 
      
        Description  | 
     
|---|---|---|---|
| 
        id  | 
      
        
          | 
      
        Identifier of the edge.  | 
     |
| 
        source  | 
      
        
          | 
      
        Identifier of the first end point vertex of the edge.  | 
     |
| 
        target  | 
      
        
          | 
      
        Identifier of the second end point vertex of the edge.  | 
     |
| 
        capacity  | 
      
        
          | 
      
        Weight of the edge (source, target) 
  | 
     |
| 
        reverse_capacity  | 
      
        
          | 
      
        -1  | 
      
        Weight of the edge (target, source) , 
  | 
     
Where:
- ANY-INTEGER :
 - 
     
SMALLINT, INTEGER, BIGINT
 
- Combinations SQL :
 - 
     
an SQL query which should return a set of rows with the following columns:
 
| 
        Column  | 
      
        Type  | 
      
        Default  | 
      
        Description  | 
     
|---|---|---|---|
| 
        source  | 
      
        
          | 
      
        Identifier of the first end point vertex of the edge.  | 
     |
| 
        target  | 
      
        
          | 
      
        Identifier of the second end point vertex of the edge.  | 
     
Where:
- ANY-INTEGER :
 - 
     
SMALLINT, INTEGER, BIGINT
 
The function aggregates the sources and the targets, removes the duplicates, and then it calculates the result from the resultant source vertices to the target vertices.
Return Columns
| 
        Type  | 
      
        Description  | 
     
|---|---|
| 
        
          | 
      
        Maximum flow possible from the source(s) to the target(s)  | 
     
See Also
- 
     
https://www.boost.org/libs/graph/doc/push_relabel_max_flow.html
 - 
     
https://en.wikipedia.org/wiki/Push%E2%80%93relabel_maximum_flow_algorithm
 
Indices and tables