绘制自定义BGL的图与graphviz的 [英] drawing custom BGL graph with graphviz

查看:217
本文介绍了绘制自定义BGL的图与graphviz的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来提升图形库,我尝试使用的Graphviz画一个图。

I'm new to Boost graph library and I try to draw a graph using 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;
}

但我得到以下错误:

But I got following error:

http://pastebin.com/KmTyyUHh

我会任何帮助非常感谢

推荐答案

您可以在此发现的问题完全相同的问题(<一个href=\"http://stackoverflow.com/questions/7935417/how-provide-a-vertex-index-property-for-my-graph\">1, <一href=\"http://stackoverflow.com/questions/5781301/why-cant-i-use-boost-graph-write-graphviz-with-outedgelist-lists-and-vertexlist\">2).问题是,write_graphviz需要一个顶点索引属性映射(许多其他Boost.Graph功能一样)。使用列表作为其VertexList时,一个的adjacency_list不会有一个默认情况下,除非你真的需要列出只需在您的第二个模板参数血管内皮细胞使用。你可以在第一个链接的答案找到另一种方法是创建和初始化外部顶点索引属性映射和然后用 write_graphviz 的过载,使您可以明确地传递,这对算法众多真正有用的,当你需要使用列出设置在图形中。

You can find the exact same problem in this questions (1, 2). The problem is that write_graphviz requires a vertex index property map (as many other Boost.Graph functions do). An adjacency_list with listS as its VertexList doesn't have one by default. Unless you really need listS simply use vecS in your second template parameter. Another alternative that you can find in the first linked answer is to create and initialize an external vertex index property map and then use an overload of write_graphviz that allows you to pass it explicitly. This is really useful for a multitude of algorithms when you need to use listS or setS in your graph.

这篇关于绘制自定义BGL的图与graphviz的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆