Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ cran
/src/*.d
/src/symbols.rds
/covr
*.dd
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export(alpha.centrality)
export(alpha_centrality)
export(any_loop)
export(any_multiple)
export(any_mutual)
export(are.connected)
export(are_adjacent)
export(arpack)
Expand Down Expand Up @@ -529,6 +530,7 @@ export(induced_subgraph)
export(infomap.community)
export(interconnected.islands.game)
export(intersection)
export(invalidate_cache)
export(is.bipartite)
export(is.chordal)
export(is.connected)
Expand Down Expand Up @@ -648,6 +650,7 @@ export(local_scan)
export(make_)
export(make_bipartite_graph)
export(make_chordal_ring)
export(make_circulant)
export(make_clusters)
export(make_de_bruijn_graph)
export(make_directed_graph)
Expand All @@ -657,15 +660,22 @@ export(make_from_prufer)
export(make_full_bipartite_graph)
export(make_full_citation_graph)
export(make_full_graph)
export(make_full_multipartite)
export(make_generalized_petersen)
export(make_graph)
export(make_kautz_graph)
export(make_lattice)
export(make_line_graph)
export(make_neighborhood_graph)
export(make_regular_tree)
export(make_ring)
export(make_star)
export(make_symmetric_tree)
export(make_tree)
export(make_triangular_lattice)
export(make_turan)
export(make_undirected_graph)
export(make_wheel)
export(match_vertices)
export(max_bipartite_match)
export(max_cardinality)
Expand Down
180 changes: 180 additions & 0 deletions R/make.R
Original file line number Diff line number Diff line change
Expand Up @@ -2806,3 +2806,183 @@ realize_bipartite_degseq <- function(
V(g)$type <- c(rep(TRUE, length(degrees1)), rep(FALSE, length(degrees2)))
g
}

#' Create a wheel graph
#'
#' A wheel graph is a graph formed by connecting a single universal vertex to
#' all vertices of a cycle.
#'
#' @param n The number of vertices in the graph.
#' @param mode Specifies the mode of the wheel graph:
#' * `"out"`: A directed graph where edges point from the center to the rim and around the rim.
#' * `"in"`: A directed graph where edges point from the rim to the center and around the rim.
#' * `"undirected"`: An undirected graph.
#' * `"mutual"`: A directed graph with mutual edges.
#' @param center The index of the center vertex, defaults to 0.
#' @return An igraph graph.
#' @family deterministic constructors
#' @export
#' @examples
#' make_wheel(10)
#' make_wheel(10, mode = "in")
#' @cdocs igraph_wheel
make_wheel <- function(
n,
mode = c("out", "in", "undirected", "mutual"),
center = 0
) {
wheel_impl(n = n, mode = mode, center = center)
}

#' Create a circulant graph
#'
#' A circulant graph is a graph where vertices are arranged in a circle and
#' each vertex is connected to vertices at certain distances (shifts) from it.
#'
#' @param n The number of vertices in the graph.
#' @param shifts A numeric vector specifying the shifts. Each vertex i will be
#' connected to vertex (i + shift) mod n for each shift in the vector.
#' @param directed Whether to create a directed graph.
#' @return An igraph graph.
#' @family deterministic constructors
#' @export
#' @examples
#' make_circulant(10, c(1, 3))
#' make_circulant(10, c(1, 2, 3), directed = TRUE)
#' @cdocs igraph_circulant
make_circulant <- function(n, shifts, directed = FALSE) {
circulant_impl(n = n, shifts = shifts, directed = directed)
}

#' Create a Turán graph
#'
#' A Turán graph is a complete multipartite graph formed by partitioning a set
#' of n vertices into r subsets, with edges between vertices in different
#' subsets but not within the same subset.
#'
#' @param n The number of vertices in the graph.
#' @param r The number of partitions.
#' @return An igraph graph with a `type` vertex attribute indicating partition membership.
#' @family deterministic constructors
#' @export
#' @examples
#' make_turan(10, 3)
#' make_turan(13, 4)
#' @cdocs igraph_turan
make_turan <- function(n, r) {
result <- turan_impl(n = n, r = r)
graph <- result$graph
V(graph)$type <- result$types
graph
}

#' Create a generalized Petersen graph
#'
#' The generalized Petersen graph is a cubic graph formed by connecting
#' vertices of a regular polygon to a star polygon.
#'
#' @param n The number of vertices in the outer and inner polygons.
#' @param k The step size for the star polygon.
#' @return An igraph graph.
#' @family deterministic constructors
#' @export
#' @examples
#' make_generalized_petersen(5, 2)
#' make_generalized_petersen(8, 3)
#' @cdocs igraph_generalized_petersen
make_generalized_petersen <- function(n, k) {
generalized_petersen_impl(n = n, k = k)
}

#' Create a full multipartite graph
#'
#' A full multipartite graph consists of several partitions with edges between
#' vertices in different partitions but no edges within a partition.
#'
#' @param n A numeric vector specifying the size of each partition.
#' @param directed Whether to create a directed graph.
#' @param mode For directed graphs, specifies how edges are oriented:
#' * `"all"` or `"total"`: Edges in both directions.
#' * `"out"`: Edges from lower-indexed to higher-indexed partitions.
#' * `"in"`: Edges from higher-indexed to lower-indexed partitions.
#' @return An igraph graph with a `type` vertex attribute indicating partition membership.
#' @family deterministic constructors
#' @export
#' @examples
#' make_full_multipartite(c(3, 4, 2))
#' make_full_multipartite(c(2, 3, 4), directed = TRUE, mode = "out")
#' @cdocs igraph_full_multipartite
make_full_multipartite <- function(
n,
directed = FALSE,
mode = c("all", "out", "in", "total")
) {
result <- full_multipartite_impl(n = n, directed = directed, mode = mode)
graph <- result$graph
V(graph)$type <- result$types
graph
}

#' Create a regular tree graph
#'
#' A regular tree is a tree where all internal vertices have the same degree.
#'
#' @param h The height of the tree (number of levels).
#' @param k The degree of internal vertices (branching factor), defaults to 3.
#' @param type Whether to create an undirected tree or a directed tree with
#' edges pointing outward (`"out"`) or inward (`"in"`).
#' @return An igraph graph.
#' @family deterministic constructors
#' @export
#' @examples
#' make_regular_tree(3, 2)
#' make_regular_tree(4, 3, type = "out")
#' @cdocs igraph_regular_tree
make_regular_tree <- function(h, k = 3, type = c("undirected", "out", "in")) {
regular_tree_impl(h = h, k = k, type = type)
}

#' Create a symmetric tree graph
#'
#' A symmetric tree where each level has a specified branching factor.
#'
#' @param branches A numeric vector specifying the branching factor at each level.
#' @param type Whether to create an undirected tree or a directed tree with
#' edges pointing outward (`"out"`) or inward (`"in"`).
#' @return An igraph graph.
#' @family deterministic constructors
#' @export
#' @examples
#' make_symmetric_tree(c(2, 3))
#' make_symmetric_tree(c(2, 2, 3), type = "out")
#' @cdocs igraph_symmetric_tree
make_symmetric_tree <- function(branches, type = c("out", "in", "undirected")) {
symmetric_tree_impl(branches = branches, type = type)
}

#' Create a triangular lattice
#'
#' A triangular lattice is a two-dimensional lattice where each vertex is
#' connected to its six neighbors in a triangular pattern.
#'
#' @param dimvector A numeric vector of length 2 specifying the dimensions of the lattice.
#' @param directed Whether to create a directed lattice.
#' @param mutual Whether directed edges should be mutual (bidirectional).
#' @return An igraph graph.
#' @family deterministic constructors
#' @export
#' @examples
#' make_triangular_lattice(c(5, 5))
#' make_triangular_lattice(c(4, 6), directed = TRUE, mutual = TRUE)
#' @cdocs igraph_triangular_lattice
make_triangular_lattice <- function(
dimvector,
directed = FALSE,
mutual = FALSE
) {
triangular_lattice_impl(
dimvector = dimvector,
directed = directed,
mutual = mutual
)
}
31 changes: 31 additions & 0 deletions R/structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -3478,6 +3478,37 @@ which_mutual <- function(graph, eids = E(graph), loops = TRUE) {
)
}

#' Check if a graph has any mutual edges
#'
#' This function checks whether a directed graph has any mutual edges at all.
#'
#' In a directed graph an (A,B) edge is mutual if the graph also includes a
#' (B,A) directed edge.
#'
#' Undirected graphs always have mutual edges by definition.
#'
#' @param graph The input graph.
#' @param loops Logical, whether to consider directed self-loops to be mutual.
#' @return A logical scalar, `TRUE` if the graph has at least one mutual edge,
#' `FALSE` otherwise.
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}
#' @seealso [which_mutual()], [reciprocity()], [dyad_census()]
#' @keywords graphs
#' @examples
#'
#' g <- sample_gnm(10, 50, directed = TRUE)
#' any_mutual(g)
#' reciprocity(g)
#' @family structural.properties
#' @export
#' @cdocs igraph_has_mutual
any_mutual <- function(graph, loops = TRUE) {
has_mutual_impl(
graph = graph,
loops = loops
)
}


#' Average nearest neighbor degree
#'
Expand Down
21 changes: 21 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,24 @@ modify_list <- function(x, y) {

utils::modifyList(x, y)
}

#' Invalidate cached properties of a graph
#'
#' This function invalidates all cached properties of a graph.
#' It is primarily useful for debugging purposes.
#'
#' igraph caches some properties of graphs to improve performance.
#' This function forces igraph to recompute these properties when they are
#' next accessed.
#'
#' @param graph The input graph.
#' @return The graph with invalidated cache.
#' This function is called for its side effects and returns the modified graph.
#' @export
#' @cdocs igraph_invalidate_cache
#' @examples
#' g <- make_ring(10)
#' g <- invalidate_cache(g)
invalidate_cache <- function(graph) {
invalidate_cache_impl(graph = graph)
}
69 changes: 69 additions & 0 deletions man/any_mutual.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/bfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/components.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/constraint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading