我是 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;
}
但是我得到了以下错误:
我将非常感谢任何帮助
最佳答案
您可以在这个问题中找到完全相同的问题(1,2)。问题是 write_graphviz 需要一个顶点索引属性映射(正如许多其他 Boost.Graph 函数所做的那样)。默认情况下,以 listS 作为其 VertexList 的 adjacency_list 没有。除非您真的需要 listS
,否则只需在第二个模板参数中使用 vecS
。您可以在第一个链接答案中找到的另一种替代方法是创建并初始化外部顶点索引属性映射,然后使用 write_graphviz
的重载允许您显式传递它。当您需要在图表中使用 listS
或 setS
时,这对于大量算法非常有用。
关于c++ - 使用 graphviz 绘制自定义 BGL 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13398865/