The OPTGRAPH Procedure

Transitive Closure

The transitive closure of a graph G is a graph upper G Superscript upper T Baseline equals left-parenthesis upper N comma upper A Superscript upper T Baseline right-parenthesis such that for all i comma j element-of upper N there is a link left-parenthesis i comma j right-parenthesis element-of upper A Superscript upper T if and only if there exists a path from i to j in G.

The transitive closure of a graph can help to efficiently answer questions about reachability. Suppose you want to answer the question of whether you can get from node i to node j in the original graph G. Given the transitive closure upper G Superscript upper T of G, you can simply check for the existence of link left-parenthesis i comma j right-parenthesis to answer the question. Transitive closure has many applications, including speeding up the processing of structured query languages, which are often used in databases.

In PROC OPTGRAPH, you can invoke the transitive closure algorithm by using the TRANSITIVE_CLOSURE statement. The options for this statement are described in the section TRANSITIVE_CLOSURE Statement.

The results of the transitive closure algorithm are written to the output data set that is specified in the OUT= option in the TRANSITIVE_CLOSURE statement. The links that define the transitive closure are listed in the output data set with variable names from and to.

The transitive closure algorithm reports status information in a macro variable called _OPTGRAPH_TRANSCL_. For more information about this macro variable, see the section Macro Variable _OPTGRAPH_TRANSCL_.

The algorithm that the PROC OPTGRAPH uses to compute transitive closure is a sparse version of the Floyd-Warshall algorithm (Cormen, Leiserson, and Rivest 1990). This algorithm runs in time upper O left-parenthesis StartAbsoluteValue upper N EndAbsoluteValue cubed right-parenthesis and therefore might not scale to very large graphs.

Transitive Closure of a Simple Directed Graph

This example illustrates the use of the transitive closure algorithm on the simple directed graph G, which is shown in Figure 122.

Figure 122: A Simple Directed Graph G

A Simple Directed Graph


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

data LinkSetIn;
   input from $ to $ @@;
   datalines;
B C  B D  C B  D A  D C
;

The following statements calculate the transitive closure and output the results in the data set TransClosure:

proc optgraph
   graph_direction = directed
   data_links      = LinkSetIn;
   transitive_closure
      out          = TransClosure;
run;

The data set TransClosure contains the transitive closure of G and is shown in Figure 123.

Figure 123: Transitive Closure of a Simple Directed Graph

fromto
BC
CB
BD
DC
DA
BB
DB
CC
CD
DD
BA
CA


The transitive closure of G is shown graphically in Figure 124.

Figure 124: Transitive Closure of G

Transitive Closure of


For a more detailed example, see Transitive Closure for Identification of Circular Dependencies in a Bug Tracking System.

Last updated: August 06, 2020