Main Content

transclosure

传递闭包

Description

example

H= transclosure(G)returns thetransitive closureof graphGas a new graph,H. The nodes inHare the same as those inG, butHhas additional edges. If there is a path from nodeito nodejinG, then there is an edge between nodeiand nodejinH. For multigraphs with multiple edges between the same two nodes, the output graph replaces these with a single edge.

Examples

collapse all

Create and plot a directed graph.

G = digraph([1 2 3 4 4 4 5 5 5 6 7 8],[2 3 5 1 3 6 6 7 8 9 9 9]); plot(G)

Figure contains an axes object. The axes object contains an object of type graphplot.

Find the transitive closure of graphGand plot the resulting graph.Hcontains the same nodes asG, but has additional edges.

H = transclosure(G); plot(H)

Figure contains an axes object. The axes object contains an object of type graphplot.

The transitive closure information inHcan be used to answer reachability questions about the original graph,G.

Determine the nodes inGthat can be reached from node 1. These nodes are the successors of node 1 in the transitive closure graph,H.

N = successors(H,1)
N =7×12 3 5 6 7 8 9

Create and plot a directed graph.

s = [1 1 2 2 3 4 4 5]; t = [2 4 3 4 5 5 6 6]; G = digraph(s,t); plot(G,'Layout','subspace')

Figure contains an axes object. The axes object contains an object of type graphplot.

Calculate the adjacency matrix of the transitive closure ofG. The result is areachabilitymatrix, which has nonzero values to indicate which nodes are reachable from each node.

D = transclosure(G); R = full(adjacency(D))
R =6×60 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0

For example, to answer the question "Which nodes are reachable from node 3?", you can look at the third row in the matrix. That row indicates only nodes 5 and 6 are reachable from node 3:

find(R(3,:))
ans =1×25 6

Input Arguments

collapse all

Input graph, specified as adigraphobject. Usedigraphto create a directed graph object.

Example:G = digraph([1 2],[2 3])

Output Arguments

collapse all

传递闭包ofG,返回as adigraphobject. The tableG.Nodesis copied toH, but any properties inG.Edgesare dropped.

Usesuccessors(H,n)to determine the nodes inGthat are reachable from noden.

More About

collapse all

Transitive Closure

The transitive closure of a graph describes the paths between the nodes. If there is a path from nodeito nodejin a graph, then an edge exists between nodeiand nodejin the transitive closure of that graph. Thus, for a given node in the graph, the transitive closure turns any reachable node into a direct successor (descendant) of that node.

Version History

在R2015B中引入