BGL: How do I get direct access to data of nodes and edges?
I have another problem regarding the Boost Graphic Library which I could not answer myself by googling nor reading the documentation. It's not directly related to my other questions so I thought I'd better start a new thread.
I have a graph with an adjacency layout and use bundled properties to get access to the data of nodes and edges. I use a typedef for my Graph for convenience. Thus I can access the data which is stored, e.g. for a vertex_descriptor, by typing something like this:
Graph[my_vertex_descriptor].setX(4);
Graph[my_vertex_descriptor].setY(10);
Now I would like to define a reference to开发者_JAVA技巧 the data-storing object to be able to type something like that:
typedef Graph[vertex_descriptor]::type Vertex;
Vertex v = Graph[my_vertex_descriptor];
v.setX(4);
v.setY(10);
By this or a similar approach I seek to avoid unnecessary recalculations of the mapped value which is accessed by using the []operator
of the map and a specific descriptor object. My vertices and edges contain lots of data so in certain situations my current code produces many recalculations of the same value to deal with this data. This seems to be ugly.
Does anybody know if it is possibly to achieve what I'm trying to do?
I used bundled properties and:
Bundled_vertex_property prop_v = get(vertex_bundle, my_graph) // or get(vertex_bundle, v, my_graph)
Bundled_edge_property prop_e = get(edge_bundle, my_graph) // or get(edge_bundle, v, my_graph)
to get the bundled property directly.
Off the top of my head, this should work (assuming you are using one of the built in graph types with a well defined graph_traits
):
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
Vertex v = Graph[my_vertex_descriptor];
v.setX(4);
v.setY(10);
you can actually access a lot this way, take a look at BGL's graph concepts for more info: http://www.boost.org/doc/libs/1_45_0/libs/graph/doc/graph_concepts.html
精彩评论