[英]drawing custom BGL graph with graphviz
I'm new to Boost graph library and I try to draw a graph using graphviz. 我是Boost图形库的新手,我尝试使用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 http://pastebin.com/KmTyyUHh
I'll be very thankful for any help 我将非常感谢您的帮助
You can find the exact same problem in this questions ( 1 , 2 ). 你可以找到在这个问题(完全相同的问题1 , 2 )。 The problem is that write_graphviz requires a vertex index property map (as many other Boost.Graph functions do). 问题是write_graphviz需要一个顶点索引属性映射(就像许多其他Boost.Graph函数一样)。 An adjacency_list with listS as its VertexList doesn't have one by default. 默认情况下,以listS作为其VertexList的adjacency_list没有一个。 Unless you really need listS
simply use vecS
in your second template parameter. 除非您确实需要listS
否则只需在第二个模板参数中使用vecS
。 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. 在第一个链接的答案中可以找到的另一种选择是创建并初始化外部顶点索引属性映射,然后使用write_graphviz
的重载允许您显式传递它。 This is really useful for a multitude of algorithms when you need to use listS
or setS
in your graph. 当您需要在图形中使用listS
或setS
时,这对于多种算法非常有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.