From b39ab99f1d064cfdd47b177b45a70b42c891068a Mon Sep 17 00:00:00 2001 From: GroteGnoom <8137208+GroteGnoom@users.noreply.github.com> Date: Sat, 9 Dec 2023 15:54:13 +0100 Subject: [PATCH] simplify case of 2 terminals --- src/paths/steiner.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/paths/steiner.cpp b/src/paths/steiner.cpp index e45c33627e..0459dd3b75 100644 --- a/src/paths/steiner.cpp +++ b/src/paths/steiner.cpp @@ -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; }