Skip to content

Commit 00bf05a

Browse files
Copilotkrlmlrszhorvat
authored
feat: add make_circulant() to expose igraph_circulant() (#2407)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: krlmlr <[email protected]> Co-authored-by: Kirill Müller <[email protected]> Co-authored-by: szhorvat <[email protected]>
1 parent 9c2feae commit 00bf05a

20 files changed

+150
-2
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export(centralize)
222222
export(centralize.scores)
223223
export(chordal_ring)
224224
export(chung_lu)
225+
export(circulant)
225226
export(cit_cit_types)
226227
export(cit_types)
227228
export(cited.type.game)
@@ -650,6 +651,7 @@ export(local_scan)
650651
export(make_)
651652
export(make_bipartite_graph)
652653
export(make_chordal_ring)
654+
export(make_circulant)
653655
export(make_clusters)
654656
export(make_de_bruijn_graph)
655657
export(make_directed_graph)

R/aaa-auto.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ circulant_impl <- function(
845845
directed
846846
)
847847

848+
if (igraph_opt("add.params")) {
849+
res$name <- 'Circulant graph'
850+
res$shifts <- shifts
851+
}
852+
848853
res
849854
}
850855

R/make.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,41 @@ chordal_ring <- function(...) constructor_spec(make_chordal_ring, ...)
22862286

22872287
## -----------------------------------------------------------------
22882288

2289+
#' Create a circulant graph
2290+
#'
2291+
#' A circulant graph \eqn{C_n^{\textrm{shifts}}} consists of \eqn{n} vertices
2292+
#' \eqn{v_0, \ldots, v_{n-1}} such that for each \eqn{s_i} in the list of offsets
2293+
#' `shifts`, \eqn{v_j} is connected to \eqn{v_{(j + s_i) \mod n}} for all \eqn{j}.
2294+
#'
2295+
#' The function can generate either directed or undirected graphs.
2296+
#' It does not generate multi-edges or self-loops.
2297+
#'
2298+
#' @param n Integer, the number of vertices in the circulant graph.
2299+
#' @param shifts Integer vector, a list of the offsets within the circulant graph.
2300+
#' @param directed Boolean, whether to create a directed graph.
2301+
#' @return An igraph graph.
2302+
#'
2303+
#' @family deterministic constructors
2304+
#' @export
2305+
#' @examples
2306+
#' # Create a circulant graph with 10 vertices and shifts 1 and 3
2307+
#' g <- make_circulant(10, c(1, 3))
2308+
#' plot(g, layout = layout_in_circle)
2309+
#'
2310+
#' # A directed circulant graph
2311+
#' g2 <- make_circulant(10, c(1, 3), directed = TRUE)
2312+
#' plot(g2, layout = layout_in_circle)
2313+
make_circulant <- function(n, shifts, directed = FALSE) {
2314+
circulant_impl(n = n, shifts = shifts, directed = directed)
2315+
}
2316+
2317+
#' @rdname make_circulant
2318+
#' @param ... Passed to `make_circulant()`.
2319+
#' @export
2320+
circulant <- function(...) constructor_spec(make_circulant, ...)
2321+
2322+
## -----------------------------------------------------------------
2323+
22892324
#' Line graph of a graph
22902325
#'
22912326
#' This function calculates the line graph of another graph.

man/graph_from_atlas.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/graph_from_edgelist.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/graph_from_literal.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/make_.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/make_chordal_ring.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/make_circulant.Rd

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

man/make_empty_graph.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)