initialize with greedy matching
This commit is contained in:
parent
750ab37457
commit
c162b92e8c
1 changed files with 19 additions and 1 deletions
20
edmonds.cpp
20
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue