Tuesday, April 10, 2012

How to print a boost graph in graphviz with one of the properties displayed?

I see examples of this when using property maps, but not when using structs to handle the vertices and edges (I think this is called 'bundles').


I have vertices and edges defined as such, in an adjacency list graph.


struct Vertex
 {
     string name;
     int some_int;
 };
 
 struct Edge
 {
     double weight;
 };
 


The graph is constructed as follows:


typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Vertex, Edge> boost_graph;
 


I want to print my graph of these objects in Graphviz format, so I can view it as an image. However, I don't only want the nodes and edges. I also want the attribute name on vertices and weight on edges to appear in the image. How can I do this?


Answer:

I gave bad info the first time. Here is the correct answer.
#include <boost/graph/graphviz.hpp>
using namespace boost;
// Graph type
typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperty> Graph;
Graph g;
std::vector<std::string> NameVec; // for dot file names

// write the dot file
std::ofstream dotfile (strDotFile.c_str ());
write_graphviz (dotfile, g, make_label_writer(&NameVec[0]));

No comments:

Post a Comment