问题
I'm new to Boost graph library and I try to draw a graph using graphviz.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/utility.hpp> // for boost::tie
#include <iostream>
#include <utility> // for std::pair
using namespace boost;
using namespace std;
class V {};
class C {};
void draw_test(){
typedef boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS, V, C > MyGraph;
typedef boost::graph_traits<MyGraph>::vertex_descriptor vertex_descriptor;
MyGraph g;
vertex_descriptor a = add_vertex(V(), g);
vertex_descriptor b = add_vertex(V(), g);
add_edge(a, b, g);
write_graphviz(std::cout, g);
}
int main() {
draw_test();
return 0;
}
But I got following error:
http://pastebin.com/KmTyyUHh
I'll be very thankful for any help
回答1:
You can find the exact same problem in this questions (1, 2). The problem is that write_graphviz requires a vertex index property map (as many other Boost.Graph functions do). An adjacency_list with listS as its VertexList doesn't have one by default. Unless you really need listS
simply use vecS
in your second template parameter. Another alternative that you can find in the first linked answer is to create and initialize an external vertex index property map and then use an overload of write_graphviz
that allows you to pass it explicitly. This is really useful for a multitude of algorithms when you need to use listS
or setS
in your graph.
来源:https://stackoverflow.com/questions/13398865/drawing-custom-bgl-graph-with-graphviz