c++ - 使用 graphviz 绘制自定义 BGL 图

标签 c++ boost graphviz boost-graph

我是 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;
}

但是我得到了以下错误:

http://pastebin.com/KmTyyUHh

我将非常感谢任何帮助

最佳答案

您可以在这个问题中找到完全相同的问题(12)。问题是 write_graphviz 需要一个顶点索引属性映射(正如许多其他 Boost.Graph 函数所做的那样)。默认情况下,以 listS 作为其 VertexList 的 adjacency_list 没有。除非您真的需要 listS,否则只需在第二个模板参数中使用 vecS。您可以在第一个链接答案中找到的另一种替代方法是创建并初始化外部顶点索引属性映射,然后使用 write_graphviz 的重载允许您显式传递它。当您需要在图表中使用 listSsetS 时,这对于大量算法非常有用。

关于c++ - 使用 graphviz 绘制自定义 BGL 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13398865/

相关文章:

c++ - 静态 map 初始化函数错误

c++ - 拥有 unique_ptr 对象的唯一所有权意味着什么?

c++ - 对 boost::timer::auto_cpu_timer 的 undefined reference

tree - graphviz,如何将节点放置在图像上

graphviz - Graphviz 中的奇怪行为(错误?)

python - Xgboost plot_tree 错误 : ValueError: booster must be Booster instance

c++ - 我遇到与模板参数相关的问题

c++ - 在Windows上构建pytorch时出现C1001内部编译器错误

c++ - Boost::thread 如何获取指向调用我的函数的线程的指针?

linux - 尝试静态链接 Boost