Skip to content

Commit abd07a0

Browse files
Copilotkrlmlr
andauthored
feat: add transitive_closure() function (#2413)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: krlmlr <[email protected]> Co-authored-by: Kirill Müller <[email protected]>
1 parent 385615a commit abd07a0

28 files changed

+217
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ export(topo_sort)
874874
export(topological.sort)
875875
export(traits)
876876
export(traits_callaway)
877+
export(transitive_closure)
877878
export(transitivity)
878879
export(tree)
879880
export(triad.census)

R/topology.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,3 +1373,47 @@ automorphism_group <- function(
13731373
details = details
13741374
)
13751375
}
1376+
1377+
#' Transitive closure of a graph
1378+
#'
1379+
#' @description
1380+
#' `r lifecycle::badge("experimental")`
1381+
#'
1382+
#' Computes the transitive closure of a graph.
1383+
#' The resulting graph will have an edge from vertex \eqn{i} to vertex \eqn{j}
1384+
#' if \eqn{j} is reachable from \eqn{i} in the original graph.
1385+
#'
1386+
#' The transitive closure of a graph is a new graph where there is an edge
1387+
#' between any two vertices if there is a path between them in the original
1388+
#' graph.
1389+
#' For directed graphs, an edge from \eqn{i} to \eqn{j} is added if there is
1390+
#' a directed path from \eqn{i} to \eqn{j}.
1391+
#' For undirected graphs, this is equivalent to connecting all vertices that
1392+
#' are in the same connected component.
1393+
#'
1394+
#' @param graph The input graph.
1395+
#' It can be directed or undirected.
1396+
#' @return A new graph object representing the transitive closure.
1397+
#' The returned graph will have the same directedness as the input.
1398+
#' @author Fabio Zanini \email{fabio.zanini@@unsw.edu.au}
1399+
#' @seealso [distances()], [are_adjacent()]
1400+
#' @keywords graphs
1401+
#' @examples
1402+
#'
1403+
#' # Directed graph
1404+
#' g <- make_graph(c(1, 2, 2, 3, 3, 4))
1405+
#' tc <- transitive_closure(g)
1406+
#' # The closure has edges 1->2, 1->3, 1->4, 2->3, 2->4, 3->4
1407+
#' print_all(tc)
1408+
#'
1409+
#' # Undirected graph - connects all vertices in same component
1410+
#' g2 <- make_graph(c(1, 2, 3, 4), directed = FALSE)
1411+
#' tc2 <- transitive_closure(g2)
1412+
#' # Full graph on vertices 1, 2 and full graph on vertices 3, 4
1413+
#' print_all(tc2)
1414+
#' @family functions for manipulating graph structure
1415+
#' @export
1416+
#' @cdocs igraph_transitive_closure
1417+
transitive_closure <- function(graph) {
1418+
transitive_closure_impl(graph = graph)
1419+
}

man/add_edges.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/add_vertices.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/complementer.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/compose.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/contract.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/delete_edges.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/delete_vertices.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/difference.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)