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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export(has_eulerian_cycle)
export(has_eulerian_path)
export(head_of)
export(head_print)
export(hex_lattice)
export(hierarchical_sbm)
export(hierarchy)
export(hits_scores)
Expand Down Expand Up @@ -665,6 +666,7 @@ export(make_full_citation_graph)
export(make_full_graph)
export(make_full_multipartite)
export(make_graph)
export(make_hex_lattice)
export(make_kautz_graph)
export(make_lattice)
export(make_line_graph)
Expand Down
22 changes: 22 additions & 0 deletions R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,28 @@ triangular_lattice_impl <- function(
res
}

hexagonal_lattice_impl <- function(
dimvector,
directed = FALSE,
mutual = FALSE
) {
# Argument checks
dimvector <- as.numeric(dimvector)
directed <- as.logical(directed)
mutual <- as.logical(mutual)

on.exit(.Call(R_igraph_finalizer))
# Function call
res <- .Call(
R_igraph_hexagonal_lattice,
dimvector,
directed,
mutual
)

res
}

path_graph_impl <- function(
n,
directed = FALSE,
Expand Down
74 changes: 74 additions & 0 deletions R/make.R
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,80 @@ lattice <- function(...) constructor_spec(make_lattice, ...)

## -----------------------------------------------------------------

#' Create a hexagonal lattice graph
#'
#' `r lifecycle::badge("experimental")`
#'
#' `make_hex_lattice()` creates a hexagonal lattice where each interior vertex
#' has degree 3. The hexagonal lattice and triangular lattice are different
#' structures; they are planar duals of each other. See `igraph_triangular_lattice()`
#' in the C library for the triangular lattice.
#'
#' @details
#' A hexagonal lattice is a lattice structure where each interior vertex
#' (not on the boundary) has degree 3. The function supports creating lattices
#' with different boundary shapes.
#'
#' The `dims` parameter determines the boundary shape of the lattice:
#' \itemize{
#' \item If `dims` is a single number, the lattice has a triangular boundary
#' where each side contains `dims` vertices.
#' \item If `dims` is a vector of length 2, the lattice has a rectangular
#' boundary with sides containing `dims[1]` and `dims[2]` vertices.
#' \item If `dims` is a vector of length 3, the lattice has a hexagonal
#' boundary where the sides contain `dims[1]`, `dims[2]`, and `dims[3]`
#' vertices.
#' }
#'
#' @param dims Integer vector, defines the shape of the lattice. See details below.
#' @param ... These dots are for future extensions and must be empty.
#' @param directed Logical scalar, whether to create a directed graph.
#' @param mutual Logical scalar, if the graph is directed this parameter
#' controls whether edges are mutual (bidirectional).
#' @return An igraph graph.
#'
#' @family deterministic constructors
#' @export
#' @examples
#' # Triangular shape with 5 vertices on each side
#' g1 <- make_hex_lattice(5)
#' plot(g1)
#'
#' # Rectangular shape
#' g2 <- make_hex_lattice(c(3, 4))
#' plot(g2)
#'
#' # Hexagonal shape
#' g3 <- make_hex_lattice(c(3, 3, 3))
#' plot(g3)
#' @cdocs igraph_hexagonal_lattice
make_hex_lattice <- function(dims, ..., directed = FALSE, mutual = FALSE) {
check_dots_empty()

graph <- hexagonal_lattice_impl(
dimvector = dims,
directed = directed,
mutual = mutual
)

if (igraph_opt("add.params")) {
graph <- set_graph_attr(graph, "name", "Hexagonal lattice")
graph <- set_graph_attr(graph, "dimvector", dims)
graph <- set_graph_attr(graph, "directed", directed)
graph <- set_graph_attr(graph, "mutual", mutual)
}
graph
}

#' @rdname make_hex_lattice
#' @export
hex_lattice <- function(dims, ..., directed = FALSE, mutual = FALSE) {
check_dots_empty()
constructor_spec(make_hex_lattice, dims = dims, directed = directed, mutual = mutual)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructor_spec(make_hex_lattice, dims = dims, directed = directed, mutual = mutual)
check_dots_empty()
constructor_spec(make_hex_lattice, dims = dims, directed = directed, mutual = mutual)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed in a5e6b2f. Added check_dots_empty() to hex_lattice() as suggested.

}

## -----------------------------------------------------------------

#' Create a ring graph
#'
#' A ring is a one-dimensional lattice and this function is a special case
Expand Down
1 change: 1 addition & 0 deletions man/graph_from_atlas.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/graph_from_edgelist.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/graph_from_literal.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/make_.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/make_chordal_ring.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/make_circulant.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/make_empty_graph.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/make_full_citation_graph.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/make_full_graph.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/make_full_multipartite.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/make_graph.Rd

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

83 changes: 83 additions & 0 deletions man/make_hex_lattice.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/make_lattice.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/make_ring.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/make_star.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/make_tree.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/make_turan.Rd

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

2 changes: 2 additions & 0 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ extern SEXP R_igraph_harmonic_centrality_cutoff(SEXP, SEXP, SEXP, SEXP, SEXP, SE
extern SEXP R_igraph_has_loop(SEXP);
extern SEXP R_igraph_has_multiple(SEXP);
extern SEXP R_igraph_has_mutual(SEXP, SEXP);
extern SEXP R_igraph_hexagonal_lattice(SEXP, SEXP, SEXP);
extern SEXP R_igraph_hrg_consensus(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_igraph_hrg_create(SEXP, SEXP);
extern SEXP R_igraph_hrg_fit(SEXP, SEXP, SEXP, SEXP);
Expand Down Expand Up @@ -735,6 +736,7 @@ static const R_CallMethodDef CallEntries[] = {
{"R_igraph_has_loop", (DL_FUNC) &R_igraph_has_loop, 1},
{"R_igraph_has_multiple", (DL_FUNC) &R_igraph_has_multiple, 1},
{"R_igraph_has_mutual", (DL_FUNC) &R_igraph_has_mutual, 2},
{"R_igraph_hexagonal_lattice", (DL_FUNC) &R_igraph_hexagonal_lattice, 3},
{"R_igraph_hrg_consensus", (DL_FUNC) &R_igraph_hrg_consensus, 4},
{"R_igraph_hrg_create", (DL_FUNC) &R_igraph_hrg_create, 2},
{"R_igraph_hrg_fit", (DL_FUNC) &R_igraph_hrg_fit, 4},
Expand Down
35 changes: 35 additions & 0 deletions src/rinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,41 @@ SEXP R_igraph_triangular_lattice(SEXP dimvector, SEXP directed, SEXP mutual) {
return(r_result);
}

/*-------------------------------------------/
/ igraph_hexagonal_lattice /
/-------------------------------------------*/
SEXP R_igraph_hexagonal_lattice(SEXP dimvector, SEXP directed, SEXP mutual) {
/* Declarations */
igraph_t c_graph;
igraph_vector_int_t c_dimvector;
igraph_bool_t c_directed;
igraph_bool_t c_mutual;
SEXP graph;

SEXP r_result;
/* Convert input */
IGRAPH_R_CHECK(R_SEXP_to_vector_int_copy(dimvector, &c_dimvector));
IGRAPH_FINALLY(igraph_vector_int_destroy, &c_dimvector);
IGRAPH_R_CHECK_BOOL(directed);
c_directed = LOGICAL(directed)[0];
IGRAPH_R_CHECK_BOOL(mutual);
c_mutual = LOGICAL(mutual)[0];
/* Call igraph */
IGRAPH_R_CHECK(igraph_hexagonal_lattice(&c_graph, &c_dimvector, c_directed, c_mutual));

/* Convert output */
IGRAPH_FINALLY(igraph_destroy, &c_graph);
PROTECT(graph=R_igraph_to_SEXP(&c_graph));
IGRAPH_I_DESTROY(&c_graph);
IGRAPH_FINALLY_CLEAN(1);
igraph_vector_int_destroy(&c_dimvector);
IGRAPH_FINALLY_CLEAN(1);
r_result = graph;

UNPROTECT(1);
return(r_result);
}

/*-------------------------------------------/
/ igraph_path_graph /
/-------------------------------------------*/
Expand Down
Loading