Network Action Set

Enumerating the Paths of a Directed 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 2, Shared Concepts (SAS Viya: Machine Learning Procedures). 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.

This section provides an example of using the path enumeration algorithm on the directed graph G shown in Figure 11 to find all paths between one source-sink pair by using the SOURCE= and SINK= options.

Figure 11: A Directed Graph G

A Directed Graph


The directed graph G can be represented by the following links data set, LinkSetIn:

data LinkSetIn;
   input from $ to $ weight @@;
   datalines;
A B 1 A E 1 B C 1 C A 6 C D 1
D E 3 D F 1 E B 1 E C 4 F E 1
E A 1
;

The following DATA step loads the LinkSetIn data set into a CAS data table named mycas.LinkSetIn. These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

data mycas.LinkSetIn;
   set LinkSetIn;
run;

The following statements find all paths between node D and node A whose path link weight is less than or equal to 10. They output the results in the data tables PathLinks and PathNodes.

proc cas;
   loadactionset "network";
   action network.path result=r status=s /
      indexOffset   = 1
      direction     = "directed"
      links         = {name = "LinkSetIn"}
      source        = "D"
      sink          = "A"
      maxLinkWeight = 10
      outPathsLinks = {name = "PathLinks", replace=true}
      outPathsNodes = {name = "PathNodes", replace=true};
   run;
   print r.ProblemSummary; run;
   print r.SolutionSummary; run;
   action table.fetch / table = "PathLinks" to=1000
                        sortBy = {"source","sink","path","order"}; run;
   action table.fetch / table = "PathNodes" to=1000
                        sortBy = {"source","sink","path","order"}; run;
quit;

The problem summary output from this action is shown in Output 28.11.1.

Output 28.11.1: Problem Summary

Problem Summary
Number of Nodes6
Number of Links11
Graph DirectionDirected


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

Output 28.11.2: Solution Summary

Solution Summary
Problem TypePath
Solution StatusOK
Number of Paths3
CPU Time0.01
Real Time0.01


The output data table PathLinks contains the links of the three paths from D to A whose path link weight is less than or equal to 10, as shown in Output 28.11.3.

Output 28.11.3: Links for All (Short) Paths in a Directed Graph

Selected Rows from Table PATHLINKS
_Index_sourcesinkpathorderfromtoweight
1DA11DE3
2DA12EA1
3DA21DF1
4DA22FE1
5DA23EA1
6DA31DF1
7DA32FE1
8DA33EB1
9DA34BC1
10DA35CA6


The output data table PathNodes contains the nodes of the three paths, as shown in Output 28.11.4.

Output 28.11.4: Nodes for All (Short) Paths in a Directed Graph

Selected Rows from Table PATHNODES
_Index_sourcesinkpathordernode
1DA11D
2DA12E
3DA13A
4DA21D
5DA22F
6DA23E
7DA24A
8DA31D
9DA32F
10DA33E
11DA34B
12DA35C
13DA36A


The three (short) paths are shown graphically in Output 28.11.5.

Output 28.11.5: Paths

upper D right-arrow upper E right-arrow upper A upper D right-arrow upper F right-arrow upper E right-arrow upper A upper D right-arrow upper F right-arrow upper E right-arrow upper B right-arrow upper C right-arrow upper A
path1_1 path1_2 path1_3


Enumerating the Paths of a Directed 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 find all paths between node D and node A whose path link weight is less than or equal to 10. They output the results in the data tables PathLinks and PathNodes.

s:network_path{
   indexOffset   = 1,
   direction     = "directed",
   links         = {name = "LinkSetIn"},
   source        = "D",
   sink          = "A",
   maxLinkWeight = 10,
   outPathsLinks = {name = "PathLinks", replace=true},
   outPathsNodes = {name = "PathNodes", replace=true}}

Enumerating the Paths of a Directed 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 find all paths between node D and node A whose path link weight is less than or equal to 10. They output the results in the data tables PathLinks and PathNodes.

s.network.path(
    indexOffset   = 1,
    direction     = "directed",
    links         = {"name": "LinkSetIn"},
    source        = "D",
    sink          = "A",
    maxLinkWeight = 10,
    outPathsLinks = {"name": "PathLinks", "replace": True},
    outPathsNodes = {"name": "PathNodes", "replace": True})

Enumerating the Paths of a Directed Graph

This example is not available for the R programming language.

Last updated: August 04, 2026