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

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 Nodes | 6 |
| Number of Links | 11 |
| Graph Direction | Directed |
The solution summary output from this action is shown in Output 28.11.2.
Output 28.11.2: Solution Summary
| Solution Summary | |
|---|---|
| Problem Type | Path |
| Solution Status | OK |
| Number of Paths | 3 |
| CPU Time | 0.01 |
| Real Time | 0.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_ | source | sink | path | order | from | to | weight |
| 1 | D | A | 1 | 1 | D | E | 3 |
| 2 | D | A | 1 | 2 | E | A | 1 |
| 3 | D | A | 2 | 1 | D | F | 1 |
| 4 | D | A | 2 | 2 | F | E | 1 |
| 5 | D | A | 2 | 3 | E | A | 1 |
| 6 | D | A | 3 | 1 | D | F | 1 |
| 7 | D | A | 3 | 2 | F | E | 1 |
| 8 | D | A | 3 | 3 | E | B | 1 |
| 9 | D | A | 3 | 4 | B | C | 1 |
| 10 | D | A | 3 | 5 | C | A | 6 |
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_ | source | sink | path | order | node |
| 1 | D | A | 1 | 1 | D |
| 2 | D | A | 1 | 2 | E |
| 3 | D | A | 1 | 3 | A |
| 4 | D | A | 2 | 1 | D |
| 5 | D | A | 2 | 2 | F |
| 6 | D | A | 2 | 3 | E |
| 7 | D | A | 2 | 4 | A |
| 8 | D | A | 3 | 1 | D |
| 9 | D | A | 3 | 2 | F |
| 10 | D | A | 3 | 3 | E |
| 11 | D | A | 3 | 4 | B |
| 12 | D | A | 3 | 5 | C |
| 13 | D | A | 3 | 6 | A |
The three (short) paths are shown graphically in Output 28.11.5.
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.


