Skip to content

Commit 86d183b

Browse files
Copilotkrlmlr
andauthored
feat: add make_wheel() to expose igraph_wheel() (#2409)
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 500ca7b commit 86d183b

20 files changed

+190
-16
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ export(make_star)
674674
export(make_tree)
675675
export(make_turan)
676676
export(make_undirected_graph)
677+
export(make_wheel)
677678
export(match_vertices)
678679
export(max_bipartite_match)
679680
export(max_cardinality)
@@ -902,6 +903,7 @@ export(walktrap.community)
902903
export(watts.strogatz.game)
903904
export(weighted_clique_num)
904905
export(weighted_cliques)
906+
export(wheel)
905907
export(which_loop)
906908
export(which_multiple)
907909
export(which_mutual)

R/make.R

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,70 @@ ring <- function(...) constructor_spec(make_ring, ...)
20712071

20722072
## -----------------------------------------------------------------
20732073

2074+
#' Create a wheel graph
2075+
#'
2076+
#' @description
2077+
#' `r lifecycle::badge("experimental")`
2078+
#'
2079+
#' A wheel graph is created by connecting a center vertex to all vertices of a
2080+
#' cycle graph.
2081+
#' A wheel graph on `n` vertices can be thought of as a wheel with `n - 1`
2082+
#' spokes.
2083+
#' The cycle graph part makes up the rim, while the star graph part adds the
2084+
#' spokes.
2085+
#'
2086+
#' Note that the two and three-vertex wheel graphs are non-simple: The
2087+
#' two-vertex wheel graph contains a self-loop, while the three-vertex wheel
2088+
#' graph contains parallel edges (a 1-cycle and a 2-cycle, respectively).
2089+
#'
2090+
#' @concept Wheel graph
2091+
#' @param n Number of vertices.
2092+
#' @inheritParams rlang::args_dots_empty
2093+
#' @param mode It defines the direction of the edges.
2094+
#' `in`: the edges point *to* the center, `out`: the edges point *from* the
2095+
#' center, `mutual`: a directed wheel is created with mutual edges,
2096+
#' `undirected`: the edges are undirected.
2097+
#' @param center ID of the center vertex.
2098+
#' @return An igraph graph.
2099+
#'
2100+
#' @family deterministic constructors
2101+
#' @export
2102+
#' @examples
2103+
#' make_wheel(10, mode = "out")
2104+
#' make_wheel(5, mode = "undirected")
2105+
#' @cdocs igraph_wheel
2106+
make_wheel <- function(
2107+
n,
2108+
...,
2109+
mode = c("in", "out", "mutual", "undirected"),
2110+
center = 1
2111+
) {
2112+
check_dots_empty()
2113+
res <- wheel_impl(
2114+
n = n,
2115+
mode = mode,
2116+
center = center - 1
2117+
)
2118+
if (igraph_opt("add.params")) {
2119+
res$name <- switch(
2120+
igraph_match_arg(mode),
2121+
"in" = "In-wheel",
2122+
"out" = "Out-wheel",
2123+
"Wheel"
2124+
)
2125+
res$mode <- mode
2126+
res$center <- center
2127+
}
2128+
res
2129+
}
2130+
2131+
#' @rdname make_wheel
2132+
#' @param ... Passed to `make_wheel()`.
2133+
#' @export
2134+
wheel <- function(...) constructor_spec(make_wheel, ...)
2135+
2136+
## -----------------------------------------------------------------
2137+
20742138
#' Create tree graphs
20752139
#'
20762140
#' Create a k-ary tree graph, where almost all vertices other than the leaves

man/graph_from_atlas.Rd

Lines changed: 2 additions & 1 deletion
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: 2 additions & 1 deletion
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: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/make_.Rd

Lines changed: 2 additions & 1 deletion
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: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/make_circulant.Rd

Lines changed: 2 additions & 1 deletion
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: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/make_full_citation_graph.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)