[Graph] Adjacency list scalability with a Dijkstra algorithm
Hi,
Assuming that I want a graph made of 6 nodes, numbered 1, 2, 3, 4, 5 and
4242. I build the graph this way:
typedef boost::adjacency_list
On Wed, Mar 25, 2009 at 12:08 PM,
Hi,
Assuming that I want a graph made of 6 nodes, numbered 1, 2, 3, 4, 5 and 4242. I build the graph this way:
<snip>
Here is the problem: I would have imagined that, in my case, boost::num_vertices(graph) would have returned 6, but it actually returns the higher vertex number + 1, that is... 4243 ! So each of my vector has a size of 4243 * sizeof(tVertex) bytes... Is there a way to handle that? I probably misuse the API, but it would be better if the container would be dimensioned to the actual number of vertices, since I am in a CPU and memory constraint environment...
With vecS storage, vertex numbering begins at 0, just like an array. So if you only did: MyGraph graph; add_edge(3, 11, graph); num_vertices(graph); // returns 12 num_edges(graph); // returns 1 --Michael Fawcett
Here is the problem: I would have imagined that, in my case, boost::num_vertices(graph) would have returned 6, but it actually returns the higher vertex number + 1, that is... 4243 ! So each of my vector has a size of 4243 * sizeof(tVertex) bytes... Is there a way to handle that? I probably misuse the API, but it would be better if the container would be dimensioned to the actual number of vertices, since I am in a CPU and memory constraint environment...
You're confusing the notions of "index" and "descriptor". With the vertex set using vecS, the descriptor of a vertex is the same as its index -- hence the confusion. Therefore, when you call add_edge(4242, 1, ...), the graph thinks you mean the vertex whose descriptor is 4242 and resizes itself accordingly. You have to remember - whatever the examples may indicate - that you should never actually use a literal value and descriptors interchangeably. This isn't documented very well, either. You could use a std::map to associate your own identifiers with vertex descriptors. Andrew Sutton andrew.n.sutton@gmail.com
Hi, I have two questions regarding concept checking. The first is whether BOOST_CONCEPT_REQUIRES can be used for constructors and how. The second is to know if it's possible to specialize templates, or perform conditional compilation in some way, for object implementing some concept or not. For example, if I have an algorithm for directed graphs that requires IncidenceGraphConcept, can I specialize the code for graphs that implement BidirecionalGraphConcept? Thanks, Juan Farré
You might find specially easy to understand and use bundled properties: http://www.boost.org/doc/libs/1_38_0/libs/graph/doc/bundles.html Good luck :)
Hello, I have a problem with adjacency_matrix template. It claims to implement VertexAndEdgeListGraphConcept, BidirectionalGraphConcept and MutablePropertyGraphConcept. But when I try to compile, it complains about using the next functions with an adjacency_matrix: num_vertices(graph) vertices(graph) num_edges(graph) edges(graph) source(edge_descriptor, graph) target(edge_descriptor, graph) and also with get(&V::property, graph), where V is a vetex bundled-properties type get(&E::property, graph), where E is an edge bundled-properties type (these get functions should return a property map for the corresponding bundled property and they work correctly for adjacency_list, just like the rest). Is this a bug or an error in the documentation? Thanks a lot, Juan
participants (4)
-
Andrew Sutton
-
Florian.PONROY@fr.thalesgroup.com
-
Juan Antonio Farré Basurte
-
Michael Fawcett