Skip to contents

[Experimental]

Computes the transitive closure of a graph. The resulting graph will have an edge from vertex \(i\) to vertex \(j\) if \(j\) is reachable from \(i\) in the original graph.

The transitive closure of a graph is a new graph where there is an edge between any two vertices if there is a path between them in the original graph. For directed graphs, an edge from \(i\) to \(j\) is added if there is a directed path from \(i\) to \(j\). For undirected graphs, this is equivalent to connecting all vertices that are in the same connected component.

Usage

transitive_closure(graph)

Arguments

graph

The input graph. It can be directed or undirected.

Value

A new graph object representing the transitive closure. The returned graph will have the same directedness as the input.

Author

Fabio Zanini fabio.zanini@unsw.edu.au

transitive_closure().

Examples


# Directed graph
g <- make_graph(c(1, 2, 2, 3, 3, 4))
tc <- transitive_closure(g)
# The closure has edges 1->2, 1->3, 1->4, 2->3, 2->4, 3->4
print_all(tc)
#> IGRAPH 98db348 D--- 4 6 -- 
#> + edges from 98db348:
#> [1] 1->2 1->3 1->4 2->3 2->4 3->4

# Undirected graph - connects all vertices in same component
g2 <- make_graph(c(1, 2, 3, 4), directed = FALSE)
tc2 <- transitive_closure(g2)
# Full graph on vertices 1, 2 and full graph on vertices 3, 4
print_all(tc2)
#> IGRAPH 4fac569 U--- 4 2 -- 
#> + edges from 4fac569:
#> [1] 1--2 3--4