Boost.Graph how to merge two vertices/contract edge

后端 未结 3 1397
囚心锁ツ
囚心锁ツ 2021-01-02 22:46

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

3条回答
  •  清歌不尽
    2021-01-02 23:29

    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.

提交回复
热议问题