繁体   English   中英

使用graphviz绘制自定义BGL图

[英]drawing custom BGL graph with 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;
}

但是我收到以下错误:

http://pastebin.com/KmTyyUHh

我将非常感谢您的帮助

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM