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

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 Nodes8
Number of Links12
Graph DirectionUndirected


The solution summary output from this action is shown in Output 2.10.2.

Output 2.10.2: Solution Summary

Solution Summary
Problem TypeMinimum Cut
Solution StatusOptimal
Objective Value4
CPU Time0.00
Real Time0.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_cutnodepartition
1111
2140
3180
4170
5130
6151
7161
8121
9261
10251
11241
12231
13221
14271
15211
16280
17380
18360
19350
20340


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_cutfromtoweight
11671
21233
32482
42783
53153
63122


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.

Last updated: March 06, 2026