How to get the OutEdgeList inside a BGL graph

时光怂恿深爱的人放手 提交于 2019-12-12 18:31:34

问题


I use a graph made with the boost graph library and want to access the OutEdgeList to get/set some internal informations (the reserved size of the vectors used to build the OutEdgeList).

I extensively searched the docs but didn't find a function/member, which returns a reference or pointer to the OutEdgeList.

My question is if there is a way to get the graphs OutEdgeList or if boost 'protects' the user from not messing directly with its internals.

In another question I found an example where you could access the EdgeList directly with graph.m_edges and also use it as a vector to do graph.m_edges.reserve(115960001) for example, so I hope there should also be a way to access the OutEdgeList too.

Any help appreciated!


回答1:


The proper way to get the OutEdgeList is by iterating over all m_vertices and access their m_out_edges attribute.

VertexIterator vi, vi_end;
for (boost::tie(vi, vi_end) = vertices(graph); vi != vi_end; ++vi){
     graph.m_vertices[*vi].m_out_edges.reserve(6);
}

By reserving the proper amount of Edges per Vertex I reduced memory usage from 12GB to 10.5GB.

It took my quite a while to find the members, because I expected them to be in boost/graph/adjacency_list.hpp but they where in boost/graph/detail/adjacency_list.hpp



来源:https://stackoverflow.com/questions/43851630/how-to-get-the-outedgelist-inside-a-bgl-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!