问题
So after my circular dependency problem with the BGL was solved I've come to another obstacle.
I'm currently using an adjacency-list to model my graph. Bundled properties for both nodes and edges are applied to store some information in the graph. So I have something like this:
class Node {
int x, int y // position
};
class Edge {
float length;
};
boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Node, Edge>
The problem arises when I want to store shortcuts to specific nodes and edges somewhere else in my code (e.g. for a street that has several lanes). My first approach was to save edge_descriptors and vertex_descriptors where I needed them. But I'm wondering how big (in terms of bytes) such descriptors would be. Maybe there is a better solution such as to store just a fraction of information to get the same results.
Does anybody know the amount of memory that is used for a vector of this type:
std::vector<edge_descriptor> ?
I already thought about just storing pointers to edge_descriptors but I don't know if and how that would work.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EDIT: Now that my first question has been thorougly answered I am still wondering one thing. I want to build some kind of interface for my graph class. This interface shall seperate the graph class details from other classes which must not be aware of the details of the graph. Thus other classes should preferably recognize nodes and edges as numbers. So I came up with two ideas:
- I use a hash_map
std::tr1::unordered_map<int, edge_descriptor>
to be able to translate the numbers to descriptors which again are then used as indices to my graph-object. This might be one step to much - maybe the calculation of the hash values will take too much time if there are enough nodes and edges to be calculated. That's why I had a second idea. - The graph itself shall internally convert these numbers to edges and nodes. I know that internal properties together with property maps can be used to realize my idea. You can then access a node by just typing something like:
boost::property_map<My_Graph, my_prop>::type index = get(my_prop(), G);
But is there a way to combine such property maps with my bundled properties?
Or do you have another idea which I didn't hit on, yet?
回答1:
Vertex and edge descriptors take a very small size.
Vertex descriptors are numbers. Edge descriptors are a small structure containing source and target vertex descriptors, and a pointer to internal data attached to edge descriptors.
Therefore the answer to your question is that you can use them in vectors. It won't constitue a memory issue.
来源:https://stackoverflow.com/questions/4276666/bgl-how-do-i-store-edge-descriptors-and-vertex-descriptors-efficiently