Drawing a custom BGL graph using Graphviz

I am new to Boost graph library and I am trying 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 the following error:

http://pastebin.com/KmTyyUHh

I will be very grateful for any help

+4
source share
1 answer

You may find the same problem in these questions ( 1 , 2 ). The problem is that write_graphviz requires displaying the vertex index property (as many other Boost.Graph functions do). The adjacency_list with listS as its VertexList does not have a default list. If you really don't need listS , just use vecS in your second template parameter. Another alternative that you can find in the first related answer is to create and initialize an external vertex index property map, and then use write_graphviz overload, which allows you to pass it explicitly. This is really useful for many algorithms when you need to use listS or setS in your graph.

+2
source

Source: https://habr.com/ru/post/1446243/


All Articles