问题
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