Skip to content

Commit ec5cd94

Browse files
committed
vendor: Update vendored sources to igraph/igraph@5c74801
feat: functionality for listing all simple cycles
1 parent c544ab1 commit ec5cd94

File tree

11 files changed

+770
-4
lines changed

11 files changed

+770
-4
lines changed

R/aaa-auto.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,6 +3528,38 @@ find_cycle_impl <- function(graph, mode=c("out", "in", "all", "total")) {
35283528
res
35293529
}
35303530

3531+
simple_cycles_impl <- function(graph, mode=c("out", "in", "all", "total"), max.cycle.length=-1) {
3532+
# Argument checks
3533+
ensure_igraph(graph)
3534+
mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L)
3535+
max.cycle.length <- as.numeric(max.cycle.length)
3536+
3537+
on.exit( .Call(R_igraph_finalizer) )
3538+
# Function call
3539+
res <- .Call(R_igraph_simple_cycles, graph, mode, max.cycle.length)
3540+
if (igraph_opt("return.vs.es")) {
3541+
res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph))
3542+
}
3543+
if (igraph_opt("return.vs.es")) {
3544+
res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph))
3545+
}
3546+
res
3547+
}
3548+
3549+
simple_cycles_callback_impl <- function(graph, mode=c("out", "in", "all", "total"), max.cycle.length=-1, cycle.handler) {
3550+
# Argument checks
3551+
ensure_igraph(graph)
3552+
mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L)
3553+
max.cycle.length <- as.numeric(max.cycle.length)
3554+
3555+
on.exit( .Call(R_igraph_finalizer) )
3556+
# Function call
3557+
res <- .Call(R_igraph_simple_cycles_callback, graph, mode, max.cycle.length, cycle.handler)
3558+
3559+
3560+
res
3561+
}
3562+
35313563
is_eulerian_impl <- function(graph) {
35323564
# Argument checks
35333565
ensure_igraph(graph)

src/cpp11.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ extern SEXP R_igraph_similarity_inverse_log_weighted(SEXP, SEXP, SEXP);
400400
extern SEXP R_igraph_similarity_jaccard(SEXP, SEXP, SEXP, SEXP);
401401
extern SEXP R_igraph_similarity_jaccard_es(SEXP, SEXP, SEXP, SEXP);
402402
extern SEXP R_igraph_similarity_jaccard_pairs(SEXP, SEXP, SEXP, SEXP);
403+
extern SEXP R_igraph_simple_cycles(SEXP, SEXP, SEXP);
404+
extern SEXP R_igraph_simple_cycles_callback(SEXP, SEXP, SEXP, SEXP);
403405
extern SEXP R_igraph_simple_interconnected_islands_game(SEXP, SEXP, SEXP, SEXP);
404406
extern SEXP R_igraph_simplify(SEXP, SEXP, SEXP, SEXP);
405407
extern SEXP R_igraph_simplify_and_colorize(SEXP);
@@ -853,6 +855,8 @@ static const R_CallMethodDef CallEntries[] = {
853855
{"R_igraph_similarity_jaccard", (DL_FUNC) &R_igraph_similarity_jaccard, 4},
854856
{"R_igraph_similarity_jaccard_es", (DL_FUNC) &R_igraph_similarity_jaccard_es, 4},
855857
{"R_igraph_similarity_jaccard_pairs", (DL_FUNC) &R_igraph_similarity_jaccard_pairs, 4},
858+
{"R_igraph_simple_cycles", (DL_FUNC) &R_igraph_simple_cycles, 3},
859+
{"R_igraph_simple_cycles_callback", (DL_FUNC) &R_igraph_simple_cycles_callback, 4},
856860
{"R_igraph_simple_interconnected_islands_game", (DL_FUNC) &R_igraph_simple_interconnected_islands_game, 4},
857861
{"R_igraph_simplify", (DL_FUNC) &R_igraph_simplify, 4},
858862
{"R_igraph_simplify_and_colorize", (DL_FUNC) &R_igraph_simplify_and_colorize, 1},

src/rinterface.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11171,6 +11171,84 @@ SEXP R_igraph_find_cycle(SEXP graph, SEXP mode) {
1117111171
return(r_result);
1117211172
}
1117311173

11174+
/*-------------------------------------------/
11175+
/ igraph_simple_cycles /
11176+
/-------------------------------------------*/
11177+
SEXP R_igraph_simple_cycles(SEXP graph, SEXP mode, SEXP max_cycle_length) {
11178+
/* Declarations */
11179+
igraph_t c_graph;
11180+
igraph_vector_int_list_t c_vertices;
11181+
igraph_vector_int_list_t c_edges;
11182+
igraph_neimode_t c_mode;
11183+
igraph_integer_t c_max_cycle_length;
11184+
SEXP vertices;
11185+
SEXP edges;
11186+
11187+
SEXP r_result, r_names;
11188+
/* Convert input */
11189+
R_SEXP_to_igraph(graph, &c_graph);
11190+
if (0 != igraph_vector_int_list_init(&c_vertices, 0)) {
11191+
igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM);
11192+
}
11193+
IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices);
11194+
if (0 != igraph_vector_int_list_init(&c_edges, 0)) {
11195+
igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM);
11196+
}
11197+
IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges);
11198+
c_mode = (igraph_neimode_t) Rf_asInteger(mode);
11199+
IGRAPH_R_CHECK_INT(max_cycle_length);
11200+
c_max_cycle_length = (igraph_integer_t) REAL(max_cycle_length)[0];
11201+
/* Call igraph */
11202+
IGRAPH_R_CHECK(igraph_simple_cycles(&c_graph, &c_vertices, &c_edges, c_mode, c_max_cycle_length));
11203+
11204+
/* Convert output */
11205+
PROTECT(r_result=NEW_LIST(2));
11206+
PROTECT(r_names=NEW_CHARACTER(2));
11207+
PROTECT(vertices=R_igraph_vector_int_list_to_SEXPp1(&c_vertices));
11208+
igraph_vector_int_list_destroy(&c_vertices);
11209+
IGRAPH_FINALLY_CLEAN(1);
11210+
PROTECT(edges=R_igraph_vector_int_list_to_SEXPp1(&c_edges));
11211+
igraph_vector_int_list_destroy(&c_edges);
11212+
IGRAPH_FINALLY_CLEAN(1);
11213+
SET_VECTOR_ELT(r_result, 0, vertices);
11214+
SET_VECTOR_ELT(r_result, 1, edges);
11215+
SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices"));
11216+
SET_STRING_ELT(r_names, 1, Rf_mkChar("edges"));
11217+
SET_NAMES(r_result, r_names);
11218+
UNPROTECT(3);
11219+
11220+
UNPROTECT(1);
11221+
return(r_result);
11222+
}
11223+
11224+
/*-------------------------------------------/
11225+
/ igraph_simple_cycles_callback /
11226+
/-------------------------------------------*/
11227+
SEXP R_igraph_simple_cycles_callback(SEXP graph, SEXP mode, SEXP max_cycle_length, SEXP cycle_handler) {
11228+
/* Declarations */
11229+
igraph_t c_graph;
11230+
igraph_neimode_t c_mode;
11231+
igraph_integer_t c_max_cycle_length;
11232+
igraph_cycle_handler_t c_cycle_handler;
11233+
11234+
igraph_error_t c_result;
11235+
SEXP r_result;
11236+
/* Convert input */
11237+
R_SEXP_to_igraph(graph, &c_graph);
11238+
c_mode = (igraph_neimode_t) Rf_asInteger(mode);
11239+
IGRAPH_R_CHECK_INT(max_cycle_length);
11240+
c_max_cycle_length = (igraph_integer_t) REAL(max_cycle_length)[0];
11241+
/* Call igraph */
11242+
IGRAPH_R_CHECK(igraph_simple_cycles_callback(&c_graph, c_mode, c_max_cycle_length, c_cycle_handler, 0));
11243+
11244+
/* Convert output */
11245+
11246+
11247+
11248+
UNPROTECT(1);
11249+
return(r_result);
11250+
}
11251+
1117411252
/*-------------------------------------------/
1117511253
/ igraph_is_eulerian /
1117611254
/-------------------------------------------*/

0 commit comments

Comments
 (0)