How to merge two vertices/contract edge at Boost.Graph?
I need to move edges from vertex A to vertex B, and delete vertex A - is there any built-in function? Or mayb
Doing it manually, you should manually remove each b edge, not the vertex:
void collapse_vertices(V b, V a, G& g)
{
auto be = boost::adjacent_vertices(b, g);
for (auto beit = be.first; beit != be.second; ++beit)
{
add_edge(a, *beit, g);
remove_edge(b, *beit, g);
}
}
gives out your wanted {1,3}, {1,4},.
I don't know why it isn't included (in my knowledge) in the BGL, but this function is what does it.