initialize with greedy matching

This commit is contained in:
Maximilian Keßler 2023-11-04 19:49:54 +01:00
parent 750ab37457
commit c162b92e8c
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -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);
}