Network Action Set
Finding the Block-Cut Tree of 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 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.
Consider again the undirected graph shown in Figure 1, which is represented by the links data table LinkSetIn. The statements that define the LinkSetIn data table are listed in Example 28.1. The following statements calculate the block-cut tree and output the results in the data tables BCTreeNodesOut and BCTreeLinksOut. To indicate the mapping to the original node labels, the bcTree_node variable is added to the NodeSetOut data table.
proc cas;
loadactionset "network";
action network.biconnectedComponents result=r status=s /
indexOffset = 1
links = {name = "LinkSetIn"}
outNodes = {name = "NodeSetOut", replace="true"}
outLinks = {name = "LinkSetOut", replace="true"}
outBCTreeNodes = {name = "BCTreeNodesOut", replace="true"}
outBCTreeLinks = {name = "BCTreeLinksOut", replace="true"};
run;
print r.ProblemSummary; run;
print r.SolutionSummary; run;
action table.fetch / table = "NodeSetOut" sortBy = "node"; run;
action table.fetch / table = "BCTreeNodesOut" sortBy = "node"; run;
action table.fetch / table = "BCTreeLinksOut" sortBy = {"from","to"}; run;
quit;
The problem summary output from this action is shown in Output 28.2.1.
Output 28.2.1: Problem Summary
| Problem Summary | |
|---|---|
| Number of Nodes | 9 |
| Number of Links | 11 |
| Graph Direction | Undirected |
The solution summary output from this action is shown in Output 28.2.2.
Output 28.2.2: Solution Summary
| Solution Summary | |
|---|---|
| Problem Type | Biconnected Components |
| Solution Status | OK |
| Number of Components | 4 |
| Number of Articulation Points | 3 |
| CPU Time | 0.00 |
| Real Time | 0.00 |
The BCTreeNodesOut output data table contains the nodes in the block-cut tree, as shown in Output 28.2.3.
Output 28.2.3: Block-Cut Tree Nodes Data Table
| Selected Rows from Table BCTREENODESOUT | ||
|---|---|---|
| _Index_ | node | artpoint |
| 1 | a_1 | A |
| 2 | a_2 | B |
| 3 | a_3 | G |
| 4 | b_1 | |
| 5 | b_2 | |
| 6 | b_3 | |
| 7 | b_4 | |
The BCTreeLinksOut output data table contains the links in the block-cut tree, as shown in Output 28.2.4.
Output 28.2.4: Block-Cut Tree Links Data Table
| Selected Rows from Table BCTREELINKSOUT | ||
|---|---|---|
| _Index_ | from | to |
| 1 | a_1 | b_1 |
| 2 | a_1 | b_2 |
| 3 | a_2 | b_1 |
| 4 | a_2 | b_3 |
| 5 | a_3 | b_2 |
| 6 | a_3 | b_4 |
The NodeSetOut output data table contains the articulation points of the input graph as well as the bcTree_node variable, which indicates the map from nodes in the original graph to nodes in the block-cut tree, as shown in Output 28.2.5.
Output 28.2.5: Articulation Points and Block-Cut Tree Node Mappings
| Selected Rows from Table NODESETOUT | |||
|---|---|---|---|
| _Index_ | node | artpoint | bcTree_node |
| 1 | A | 1 | a_1 |
| 2 | B | 1 | a_2 |
| 3 | C | 0 | b_3 |
| 4 | D | 0 | b_3 |
| 5 | E | 0 | b_1 |
| 6 | F | 0 | b_1 |
| 7 | G | 1 | a_3 |
| 8 | H | 0 | b_4 |
| 9 | I | 0 | b_4 |
The block-cut tree is shown graphically in Figure 2.
Figure 2: Block-Cut Tree of the Undirected Graph G
Finding the Block-Cut Tree of 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 the biconnected components and articulation points for G and output the results in the data tables LinkSetOut and NodeSetOut:
s:network_biconnectedComponents{
indexOffset = 1,
links = {name = "LinkSetIn"},
outNodes = {name = "NodeSetOut", replace=true},
outLinks = {name = "LinkSetOut", replace=true},
outBCTreeNodes = {name = "BCTreeNodesOut", replace=true},
outBCTreeLinks = {name = "BCTreeLinksOut", replace=true}}
Finding the Block-Cut Tree of 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 the biconnected components and articulation points for G and output the results in the data tables LinkSetOut and NodeSetOut:
s.network.biconnectedComponents(
indexOffset = 1,
links = {"name":"LinkSetIn"},
outNodes = {"name":"NodeSetOut", "replace":True},
outLinks = {"name":"LinkSetOut", "replace":True},
outBCTreeNodes = {"name":"BCTreeNodesOut", "replace":True},
outBCTreeLinks = {"name":"BCTreeLinksOut", "replace":True})
Finding the Block-Cut Tree of an Undirected Graph
This example is not available for the R programming language.