From eb1e7e8dc88a183d6b4f64da955863c1fd72a9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 5 Nov 2023 13:16:16 +0100 Subject: [PATCH] fix: output matching, not whole graph --- src/edmonds.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/edmonds.cpp b/src/edmonds.cpp index 8b81dbf..dd3520b 100644 --- a/src/edmonds.cpp +++ b/src/edmonds.cpp @@ -43,7 +43,7 @@ NodeId find_outer_vertex(Graph const & graph) return invalid_node_id; } -Graph maximum_matching_from_initial_matching(Graph & graph) +void maximum_matching_from_initial_matching(Graph & graph) { graph.reset_forest(); NodeId id; @@ -81,7 +81,7 @@ Graph maximum_matching_from_initial_matching(Graph & graph) } // Note that since this is tail-recursion, this will not generate // new stack frames in OPT mode - return maximum_matching(graph); + maximum_matching(graph); } else { @@ -139,7 +139,6 @@ Graph maximum_matching_from_initial_matching(Graph & graph) } graph.node(id).scanned = true; } - return graph; }; void find_greedy_matching(Graph & graph) @@ -162,7 +161,17 @@ void find_greedy_matching(Graph & graph) Graph maximum_matching(Graph & graph) { find_greedy_matching(graph); - return maximum_matching_from_initial_matching(graph); + maximum_matching_from_initial_matching(graph); + + ED::Graph matching = ED::Graph(graph.num_nodes()); + for (NodeId id = 0; id < graph.num_nodes(); ++id) + { + if (graph.matched_neighbor(id) > id) + { + matching.add_edge(id, graph.matched_neighbor(id)); + } + } + return matching; } }