![](/img/trans.png)
[英]in boost graph lib, how do I get a specific out-edge of a vertex without iterating over all the out-edges of that vertex?
[英]Boost: how to remove all the out-edges for a vertex
在boost圖形庫中,remove_edge將使邊迭代器失效,那么刪除一個頂點的所有外邊的正確方法是什么,例如,我試圖刪除頂點0的所有外邊。 中的代碼片段下面不能正常工作。
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);
}
您將在源頂點上為出邊調用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 中移除所有邊。 頂點仍然出現在圖形的頂點集中。
對描述符和迭代器穩定性的影響與為所有以 u 作為源或目標的邊調用 remove_edge() 的影響相同。
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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.