On 06/26/2013 06:41 PM, Giovanni Luca Ciampaglia wrote:
Hi,
I recently moved from NetworkX to graph-tool and I am very impressed with the performance increase, good job!
A bit for learning and also for speeding up a code that creates a graph dynamically, I am trying to implement a batch insertion function with Weave, but I am running into a compilation error. My knowledge of C++ is sketchy at best so please forgive if I am asking something really dumb -- though I suspect that the problem is more in the way graph_tool interacts with the BGL. Anyway, the code is here:
https://gist.github.com/junkieDolphin/5868934
The error I get is:
/home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:822:13: error: ‘adjacency_list’ does not name a type
(full trace below)
So I suspect the problem is in how I tell run_inline to include the proper header files in the generated source. Putting them before the loop is clearly not an option, because it would put the #includes in the middle of a scope. Any idea?
The code you're trying to run is not valid C++ (you cannot mix typedefs and variable definitions). Furthermore you should not try to guess the type of the graph, and instead you should use the pre-defined typedefs. You have to use the following code: _add_code = ''' using namespace boost; typedef graph_traits<graph_graph_t>::vertex_descriptor vertex_t; for (int i = 0; i < n; ++i) { add_edge(vertex_t(edges[i, 0]), vertex_t(edges[i, 1]), graph); } ''' Modifying your script with the above code worked for me. Note that you have to use the development version of graph-tool in git, since the current version has a bug in the run_action module. I think that a function to add several edges at once is a useful one. If you open a ticket for it, I'll implement it when I find some time.
Alternatively, how do I get to call BGL's add_edge with the wrapped graph type, i.e. the one typedef'd automatically by inline?
Everything should work fine with the properly overloaded functions... I.e., whenever you call add_edge(), it should select the appropriately overloaded function for the correct type. Cheers, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>