简体   繁体   中英

drawing custom BGL graph with 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

I'll be very thankful for any help

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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