On 08/25/2011 10:12 PM, parvizp wrote:
Is it possible to write the code for graph traversal in C++ rather than using the Python wrappers? I need the graph search to be as fast as possible. I tried something simple like this: http://pastebin.com/m2pwFQKy It looks like the typedefs for 'graph_graph_t' don't appear until after the support code: http://pastebin.com/itT73DxT Is there an example of how to achieve something similar?
Yes, this is possible. The idea is that the *_graph_t types will be different, depending if your graph is directed, undirected, filtered, reversed, etc. So it is not defined (typedef'd) before the type of your graph known. This _could_ be pushed before the support code comes, I suppose, but the way I use it is to define everything in the support code as templates, so the actual type gets picked up automatically. Something like: class MyVisitor : public boost::default_dfs_visitor { public: template <class Vertex, class Graph> void discover_vertex(Vertex v, Graph& g) { std::cout << v << std::endl; return; } }; Then your code would be: MyVisitor vis; boost::depth_first_search(graph, boost::visitor(vis)); And there is no necessity of actually knowing the type of the graph (but if you ever need it, it is there as a typedef).
Thanks Tiago Peixoto for developing/maintaining this great library!
You're welcome! Cheers, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>