optNetwork

maxFlow

Description

The maxFlow action calculates the maximum flow of a graph. The maximum flow problem is a classical network flow problem that involves finding a feasible flow from a single source node to a single sink node that is maximum. This action is useful for modeling problems in logistics, transportation, and communication.

proc cas; optNetwork.maxFlow links = {name='links_table'}, source = 'source_node', sink = 'sink_node', outLinks = {name='out_flow', replace=true}, outNodes = {name='out_cut', replace=true}; run;
Settings
ParameterDescription
deterministicWhen set to True, ensures that each invocation (with the same machine configuration and parameter settings) produces the same final result. Default is True.
directionSpecifies whether to consider the input graph as directed or undirected. Default is 'UNDIRECTED'.
graphSpecifies the in-memory graph to use.
linksSpecifies the input data table that contains the graph link information.
logLevelControls the amount of information that is displayed in the SAS log. Can be 'NONE', 'BASIC', 'MODERATE', or 'AGGRESSIVE'. Default is 'BASIC'.
outLinksSpecifies the output data table to contain the flow on each link and the cut information.
outNodesSpecifies the output data table to contain the cut information for each node.
sinkSpecifies the sink node for maximum network flow calculations.
sourceSpecifies the source node for maximum network flow calculations.
Data Preparation View data prep sheet
Creating the Input Data

This example illustrates calculating the maximum flow between a source node 'S' and a sink node 'T' in a directed graph. The capacity of each link is defined in the 'capacity' variable.

Copied!
1DATA mycas.LinkData;
2 INPUT from $ to $ capacity;
3 DATALINES;
4S A 5
5S B 8
6A C 4
7A D 2
8B D 3
9B E 4
10C T 3
11D T 6
12E T 5
13;
14RUN;

Examples

This example calculates the maximum flow from node 'S' to node 'T'. The total maximum flow value is stored in the macro variable `max_flow_val`.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 optNetwork.maxFlow
3 links = {name='LinkData'},
4 linksVar = {from='from', to='to', weight='capacity'},
5 SOURCE = 'S',
6 sink = 'T';
7RUN;
8QUIT;
9%put Maximum Flow = &_OROPTNET_MAXFLOW_;
Result :
The SAS log will display the maximum flow value, which should be 9 in this case.

This example calculates the maximum flow and outputs two tables: `FlowNetwork` and `MinCutNodes`. The `FlowNetwork` table shows the flow on each link, and `MinCutNodes` identifies the nodes in the source-side of the minimum cut.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 optNetwork.maxFlow
3 links = {name='LinkData'},
4 linksVar = {from='from', to='to', weight='capacity'},
5 SOURCE = 'S',
6 sink = 'T',
7 outLinks = {name='FlowNetwork', replace=true},
8 outNodes = {name='MinCutNodes', replace=true};
9RUN;
10PROC PRINT DATA=mycas.FlowNetwork;
11RUN;
12PROC PRINT DATA=mycas.MinCutNodes;
13RUN;
Result :
Two tables will be printed. The 'FlowNetwork' table details the flow for each link, not exceeding its capacity. The 'MinCutNodes' table lists the nodes belonging to the S-side of the min-cut, which defines the bottleneck. For this graph, the nodes S, A, and B will be in the min-cut set.

FAQ

What is the primary function of the maxFlow action in the Network Optimization action set?
What is the basic CASL syntax for the maxFlow action?
What are the main input tables required by the maxFlow action?
What does the 'direction' parameter specify in the maxFlow action?
What are the key results returned by the maxFlow action?