@@ -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.
@@ -2582,6 +2617,117 @@ bipartite_graph <- function(...) constructor_spec(make_bipartite_graph, ...)
25822617
25832618# # -----------------------------------------------------------------
25842619
2620+ # ' Create a full multipartite graph
2621+ # '
2622+ # ' A multipartite graph contains multiple types of vertices and connections
2623+ # ' are only possible between vertices of different types. This function
2624+ # ' creates a complete multipartite graph where all possible edges between
2625+ # ' different partitions are present.
2626+ # '
2627+ # ' @param n A numeric vector giving the number of vertices in each partition.
2628+ # ' @param directed Logical scalar, whether to create a directed graph.
2629+ # ' @param mode Character scalar, the type of connections for directed graphs.
2630+ # ' If `"out"`, then edges point from vertices of partitions with lower
2631+ # ' indices to partitions with higher indices; if `"in"`, then the opposite
2632+ # ' direction is realized; `"all"` creates mutual edges. This parameter is
2633+ # ' ignored for undirected graphs.
2634+ # ' @return An igraph graph with a vertex attribute `type` storing the
2635+ # ' partition index of each vertex. Partition indices start from 1.
2636+ # '
2637+ # ' @family deterministic constructors
2638+ # ' @export
2639+ # ' @examples
2640+ # ' # Create a multipartite graph with partitions of size 2, 3, and 4
2641+ # ' g <- make_full_multipartite(c(2, 3, 4))
2642+ # ' plot(g)
2643+ # '
2644+ # ' # Create a directed multipartite graph
2645+ # ' g2 <- make_full_multipartite(c(2, 2, 2), directed = TRUE, mode = "out")
2646+ # ' plot(g2)
2647+ # ' @cdocs igraph_full_multipartite
2648+ make_full_multipartite <- function (
2649+ n ,
2650+ directed = FALSE ,
2651+ mode = c(" all" , " out" , " in" )
2652+ ) {
2653+ n <- as.numeric(n )
2654+ directed <- as.logical(directed )
2655+ mode <- igraph.match.arg(mode )
2656+
2657+ res <- full_multipartite_impl(n = n , directed = directed , mode = mode )
2658+ graph <- set_vertex_attr(res $ graph , " type" , value = res $ types )
2659+
2660+ # Transfer graph attributes from res to graph if add.params is enabled
2661+ if (igraph_opt(" add.params" )) {
2662+ for (attr_name in setdiff(names(res ), c(" graph" , " types" ))) {
2663+ graph <- set_graph_attr(graph , attr_name , res [[attr_name ]])
2664+ }
2665+ }
2666+ graph
2667+ }
2668+
2669+ # ' @rdname make_full_multipartite
2670+ # ' @param ... Passed to `make_full_multipartite()`.
2671+ # ' @export
2672+ full_multipartite <- function (... ) {
2673+ constructor_spec(make_full_multipartite , ... )
2674+ }
2675+
2676+ # # -----------------------------------------------------------------
2677+
2678+ # ' Create a Turán graph
2679+ # '
2680+ # ' Turán graphs are complete multipartite graphs with the property that the
2681+ # ' sizes of the partitions are as close to equal as possible.
2682+ # '
2683+ # ' @details
2684+ # ' The Turán graph with `n` vertices and `r` partitions is the densest
2685+ # ' graph on `n` vertices that does not contain a clique of size `r+1`.
2686+ # '
2687+ # ' This function generates undirected graphs. The null graph is
2688+ # ' returned when the number of vertices is zero. A complete graph is
2689+ # ' returned if the number of partitions is greater than the number of vertices.
2690+ # '
2691+ # ' @param n Integer, the number of vertices in the graph.
2692+ # ' @param r Integer, the number of partitions in the graph, must be positive.
2693+ # ' @return An igraph graph with a vertex attribute `type` storing the
2694+ # ' partition index of each vertex. Partition indices start from 1.
2695+ # '
2696+ # ' @family deterministic constructors
2697+ # ' @export
2698+ # ' @examples
2699+ # ' # Create a Turán graph with 10 vertices and 3 partitions
2700+ # ' g <- make_turan(10, 3)
2701+ # ' plot(g)
2702+ # '
2703+ # ' # The sizes of the partitions are as balanced as possible
2704+ # ' table(V(g)$type)
2705+ # ' @cdocs igraph_turan
2706+ make_turan <- function (n , r ) {
2707+ n <- as.numeric(n )
2708+ r <- as.numeric(r )
2709+
2710+ res <- turan_impl(n = n , r = r )
2711+ graph <- set_vertex_attr(res $ graph , " type" , value = res $ types )
2712+
2713+ # Transfer graph attributes from res to graph if add.params is enabled
2714+ if (igraph_opt(" add.params" )) {
2715+ for (attr_name in setdiff(names(res ), c(" graph" , " types" ))) {
2716+ graph <- set_graph_attr(graph , attr_name , res [[attr_name ]])
2717+ }
2718+ }
2719+ graph
2720+ }
2721+
2722+ # ' @rdname make_turan
2723+ # ' @param ... Passed to `make_turan()`.
2724+ # ' @export
2725+ turan <- function (... ) {
2726+ constructor_spec(make_turan , ... )
2727+ }
2728+
2729+ # # -----------------------------------------------------------------
2730+
25852731# ' Create a complete (full) citation graph
25862732# '
25872733# ' `make_full_citation_graph()` creates a full citation graph. This is a
0 commit comments