Skip to content

Commit

Permalink
simplify case of 2 terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
GroteGnoom committed Dec 9, 2023
1 parent b720c1b commit b39ab99
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/paths/steiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,15 @@ igraph_error_t igraph_steiner_dreyfus_wagner(
*res = 0.0;
flag_terminals = true;
} else if (no_of_terminals == 2) {
igraph_vector_int_t vertices;
igraph_real_t tree_weight = 0.0;
igraph_vector_int_t edges_res;

IGRAPH_VECTOR_INT_INIT_FINALLY(&vertices, 0);
IGRAPH_VECTOR_INT_INIT_FINALLY(&edges_res, 0);

IGRAPH_CHECK(igraph_get_shortest_path_dijkstra(
graph, &vertices, &edges_res, VECTOR(*terminals)[0],
graph, NULL, res_tree, VECTOR(*terminals)[0],
VECTOR(*terminals)[1], pweights, IGRAPH_ALL));
igraph_integer_t tree_size = igraph_vector_int_size(&edges_res);
igraph_integer_t tree_size = igraph_vector_int_size(res_tree);

*res = 0.0;
for (igraph_integer_t i = 0; i < tree_size; i++) {
tree_weight += VECTOR(*pweights)[VECTOR(edges_res)[i]];
*res += VECTOR(*pweights)[VECTOR(*res_tree)[i]];
}
*res = tree_weight;

IGRAPH_CHECK(igraph_vector_int_append(res_tree, &edges_res));

igraph_vector_int_destroy(&vertices);
igraph_vector_int_destroy(&edges_res);
IGRAPH_FINALLY_CLEAN(2);

flag_terminals = true;
}
Expand Down

0 comments on commit b39ab99

Please sign in to comment.