From c162b92e8ca9c2b2b9b8af1b0a96ffaa3f8d9de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 4 Nov 2023 19:49:54 +0100 Subject: [PATCH] initialize with greedy matching --- edmonds.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/edmonds.cpp b/edmonds.cpp index d69f9f9..d0bb86e 100644 --- a/edmonds.cpp +++ b/edmonds.cpp @@ -121,8 +121,26 @@ Graph maximum_matching_from_initial_matching(Graph & graph) } }; -Graph maximum_matching(Graph & graph) { +void find_greedy_matching(Graph & graph) +{ graph.reset_matching(); + for(NodeId node_id = 0; node_id < graph.num_nodes(); ++node_id) + { + if (graph.matched_neighbor(node_id) == node_id) { + for(NodeId neighbor_id : graph.node(node_id).neighbors()) + { + if(graph.matched_neighbor(neighbor_id) == neighbor_id) + { + graph.node(neighbor_id).matched_neighbor = node_id; + graph.node(node_id).matched_neighbor = neighbor_id; + } + } + } + } +} + +Graph maximum_matching(Graph & graph) { + find_greedy_matching(graph); return maximum_matching_from_initial_matching(graph); }