加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 使用graphviz绘制自定义BGL图

发布时间:2020-12-16 07:33:30 所属栏目:百科 来源:网络整理
导读:我是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::pairusing namespace boost;usi
我是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

我会非常感谢任何帮助

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读