Network Optimization Action Set
Calculating a Minimum Cut for an Undirected Graph
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 1, Introduction (SAS Optimization: The OPTNETWORK Procedure). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
As an example, consider the weighted undirected graph in Figure 12.
Figure 12: An Undirected Graph

The links data set can be represented as follows:
data LinkSetIn;
input from to weight @@;
datalines;
1 2 2 1 5 3 2 3 3 2 5 2 2 6 2
3 4 4 3 7 2 4 7 2 4 8 2 5 6 3
6 7 1 7 8 3
;
The following DATA step loads the LinkSetIn data set into a CAS data table named mylib.LinkSetIn. These statements assume that the CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.LinkSetIn;
set LinkSetIn;
run;
The following statements calculate minimum cuts in the graph and output the results in the data tables MinCutCutSets and MinCutPartitions:
proc cas;
loadactionset "optNetwork";
action optNetwork.minCut result=r status=s /
links = {name = "LinkSetIn"}
indexOffset = 1
maxCuts = 3
outPartitions = {name = "Partitions", replace = true}
outCutSets = {name = "CutSets", replace = true};
run;
print r.ProblemSummary; run;
print r.SolutionSummary; run;
action table.fetch / table = "Partitions" sortBy = "cut"; run;
action table.fetch / table = "CutSets" sortBy = "cut"; run;
quit;
The problem summary output from this action is shown in Output 2.10.1.
Output 2.10.1: Problem Summary
| Problem Summary | |
|---|---|
| Number of Nodes | 8 |
| Number of Links | 12 |
| Graph Direction | Undirected |
The solution summary output from this action is shown in Output 2.10.2.
Output 2.10.2: Solution Summary
| Solution Summary | |
|---|---|
| Problem Type | Minimum Cut |
| Solution Status | Optimal |
| Objective Value | 4 |
| CPU Time | 0.00 |
| Real Time | 0.00 |
The output data table Partitions now contains the partition of the nodes for each cut, shown in Output 2.10.3.
Output 2.10.3: Minimum Cut Node Partition
| Selected Rows from Table PARTITIONS | |||
|---|---|---|---|
| _Index_ | cut | node | partition |
| 1 | 1 | 1 | 1 |
| 2 | 1 | 4 | 0 |
| 3 | 1 | 8 | 0 |
| 4 | 1 | 7 | 0 |
| 5 | 1 | 3 | 0 |
| 6 | 1 | 5 | 1 |
| 7 | 1 | 6 | 1 |
| 8 | 1 | 2 | 1 |
| 9 | 2 | 6 | 1 |
| 10 | 2 | 5 | 1 |
| 11 | 2 | 4 | 1 |
| 12 | 2 | 3 | 1 |
| 13 | 2 | 2 | 1 |
| 14 | 2 | 7 | 1 |
| 15 | 2 | 1 | 1 |
| 16 | 2 | 8 | 0 |
| 17 | 3 | 8 | 0 |
| 18 | 3 | 6 | 0 |
| 19 | 3 | 5 | 0 |
| 20 | 3 | 4 | 0 |
The output data table mycas.CutSets contains the links in the cut sets for each cut. This data table is shown in Output 2.10.4.
Output 2.10.4: Minimum Cut Sets
| Selected Rows from Table CUTSETS | ||||
|---|---|---|---|---|
| _Index_ | cut | from | to | weight |
| 1 | 1 | 6 | 7 | 1 |
| 2 | 1 | 2 | 3 | 3 |
| 3 | 2 | 4 | 8 | 2 |
| 4 | 2 | 7 | 8 | 3 |
| 5 | 3 | 1 | 5 | 3 |
| 6 | 3 | 1 | 2 | 2 |
Calculating a Minimum Cut for an Undirected Graph
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="LinkSetIn.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The following statements calculate minimum cuts in the graph and output the results in the data tables MinCutCutSets and MinCutPartitions:
s:optNetwork_minCut{
links = {name = "LinkSetIn"},
indexOffset = 1,
maxCuts = 3,
outPartitions = {name = "Partitions", replace=true},
outCutSets = {name = "CutSets", replace=true}}
Calculating a Minimum Cut for an Undirected Graph
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv and then use the following code to load the CSV file into CAS:
s.upload_file('LinkSetIn.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following statements calculate minimum cuts in the graph and output the results in the data tables MinCutCutSets and MinCutPartitions:
s.optNetwork.minCut(
links = {"name":"LinkSetIn"},
indexOffset = 1,
maxCuts = 3,
outPartitions = {"name":"Partitions", "replace":True},
outCutSets = {"name":"CutSets", "replace":True})
Calculating a Minimum Cut for an Undirected Graph
This example is not available for the R programming language.