2015-04-28 45 views
1

在boost圖庫中,remove_edge會使邊緣迭代器無效,那麼刪除頂點的所有外邊緣的正確方法是什麼,例如,我是試圖刪除頂點0的所有邊緣。下面的代碼片段無法正常工作。Boost:如何去除頂點的所有外邊緣

Graph G(N); 
graph_traits <Graph>::out_edge_iterator ei, ei_end; 
for (boost::tie(ei, ei_end) = out_edges(0, G); ei != ei_end; ++ei) { 
    vertex targ = target(*ei, G); 
    cout << "target vtx = " << targ << endl; 

    if (edge(0, targ, G).second != 0) 
    remove_edge(0, targ, G); 
} 

回答

0

你會打電話clear_out_edges對源頂點的出邊(http://www.boost.org/doc/libs/1_58_0/libs/graph/doc/adjacency_list.html

  • void clear_vertex(vertex_descriptor u, adjacency_list& g) 
    

    移除所有邊和頂點u。頂點仍然出現在圖的頂點集中。

    對描述符和迭代器穩定性的影響與調用remove_edge()對所有具有u作爲源或目標的邊的影響相同。

  • void clear_out_edges(vertex_descriptor u, adjacency_list& g) 
    

    從頂點u刪除所有出邊。頂點仍然出現在圖的頂點集中。

    對描述符和迭代器穩定性的影響與爲所有以u爲源的邊調用remove_edge()相同。

    此操作不適用於無向圖(使用clear_vertex()代替)。

  • void clear_in_edges(vertex_descriptor u, adjacency_list& g) 
    

我必須支持任何MutableGraph,只有clear_vertex

+0

謝謝!我應該再次閱讀這篇文檔。 – user3658306

相關問題