【问题标题】:drawing custom BGL graph with graphviz使用 graphviz 绘制自定义 BGL 图
【发布时间】:2012-11-15 13:51:35
【问题描述】:

我是 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 函数一样)。默认情况下,adjacency_listlistS 作为其 VertexList 没有一个。除非您真的需要listS,否则只需在第二个模板参数中使用vecS。或者研究链接的答案。
  • 成功了!非常感谢;)发表您的评论作为答案,以便我接受;

标签: c++ boost graphviz boost-graph


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 2014-09-01
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多