Skip to content

Commit

Permalink
vendor: Update vendored sources to igraph/igraph@12299c4
Browse files Browse the repository at this point in the history
fix: temporary fix for simple cycle search mishandling self-loops, ref igraph/igraph#2692
test: minimum cycle length for igraph_simple_cycles()
  • Loading branch information
krlmlr committed Jan 5, 2025
1 parent 4851711 commit 91a3b88
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
38 changes: 33 additions & 5 deletions src/vendor/cigraph/src/cycles/simple_cycles.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static igraph_error_t igraph_i_simple_cycle_search_state_init(
graph,
&state->IK,
mode,
IGRAPH_LOOPS_ONCE // each self-loop counts as a single cycle
IGRAPH_NO_LOOPS // ignore self-loops
));
IGRAPH_FINALLY(igraph_inclist_destroy, &state->IK);

Expand Down Expand Up @@ -526,18 +526,46 @@ igraph_error_t igraph_simple_cycles_callback(
IGRAPH_CHECK(igraph_i_simple_cycle_search_state_init(&state, graph, mode));
IGRAPH_FINALLY(igraph_i_simple_cycle_search_state_destroy, &state);

// Special case: identify self-loops in advance.
// We will skip them during the main cycle search.
// Re-use state.vertex_stack and state.edge_stack for convenience.
if (min_cycle_length <= 1) {
const igraph_integer_t ecount = igraph_ecount(graph);

IGRAPH_CHECK(igraph_vector_int_resize(&state.vertex_stack, 1));
IGRAPH_CHECK(igraph_vector_int_resize(&state.edge_stack, 1));

for (igraph_integer_t eid = 0; eid < ecount; eid++) {
const igraph_integer_t v = IGRAPH_FROM(graph, eid);
if (IGRAPH_TO(graph, eid) == v) {
igraph_error_t ret;

VECTOR(state.vertex_stack)[0] = v;
VECTOR(state.edge_stack)[0] = eid;
IGRAPH_CHECK_CALLBACK(callback(&state.vertex_stack, &state.edge_stack, arg), &ret);
if (ret == IGRAPH_STOP) {
state.stop_search = true;
break;
}
}
}

igraph_vector_int_clear(&state.vertex_stack);
igraph_vector_int_clear(&state.edge_stack);
}

// TODO: depending on the graph, it is rather unreasonable to search cycles
// from each and every node
for (igraph_integer_t i = 0; i < state.N; i++) {
if (state.stop_search) {
state.stop_search = false;
break;
}
if (!igraph_vector_int_empty(igraph_adjlist_get(&state.AK, i))) {
IGRAPH_CHECK(igraph_i_simple_cycles_search_callback_from_one_vertex(
&state, i, min_cycle_length, max_cycle_length, callback, arg));
IGRAPH_ALLOW_INTERRUPTION();
}
if (state.stop_search) {
state.stop_search = false;
break;
}
}

igraph_i_simple_cycle_search_state_destroy(&state);
Expand Down
4 changes: 2 additions & 2 deletions src/vendor/igraph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

__BEGIN_DECLS

#define IGRAPH_VERSION "0.10.13-159-g26d3718b3"
#define IGRAPH_VERSION "0.10.13-161-g12299c492"
#define IGRAPH_VERSION_MAJOR 0
#define IGRAPH_VERSION_MINOR 10
#define IGRAPH_VERSION_PATCH 13
#define IGRAPH_VERSION_PRERELEASE "159-g26d3718b3"
#define IGRAPH_VERSION_PRERELEASE "161-g12299c492"

IGRAPH_EXPORT void igraph_version(const char **version_string,
int *major,
Expand Down

0 comments on commit 91a3b88

Please sign in to comment.