Accelerator Library - minimum example of vertex colors and graph output

Being new to the acceleration graph library, it is often difficult for me to tease which parts of the examples are tied to a specific example and which parts are universal for use.

As an exercise, I try to make a simple graph, assign a color property to the vertices, and print the result in graphviz so that the colors appear as color attributes that get rendered. Any help would be appreciated! Here is what I have so far (more specific use questions in the comments here):

#include "fstream" #include "boost/graph/graphviz.hpp" #include "boost/graph/adjacency_list.hpp" struct vertex_info { int color; }; typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex_info> Graph; typedef std::pair<int, int> Edge; int main(void) { Graph g; add_edge(0, 1, g); add_edge(1, 2, g); // replace this with some traversing and assigning of colors to the 3 vertices ... // should I use bundled properties for this? // it unclear how I would get write_graphviz to recognize a bundled property as the color attribute g[0].color = 1; std::ofstream outf("min.gv"); write_graphviz(outf, g); // how can I make write_graphviz output the vertex colors? } 
+7
source share
1 answer

Try:

 boost::dynamic_properties dp; dp.property("color", get(&vertex_info::color, g)); dp.property("node_id", get(boost::vertex_index, g)); write_graphviz_dp(outf, g, dp); 

instead of your call to write_graphviz . For an example, see http://www.boost.org/doc/libs/1_47_0/libs/graph/example/graphviz.cpp . Please note that the code I sent will write the colors as integers, not the color names like Dot.

+5
source

All Articles