boost/graph/graphviz.hpp : example of write_graphviz


/ Published in: C++
Save to your folder(s)

http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/write-graphviz.html


Copy this code and paste it in your HTML
  1. #include <boost/graph/graphviz.hpp>
  2. #include <boost/graph/adjacency_list.hpp>
  3. #include <string>
  4. #include <fstream>
  5. #include <boost/graph/iteration_macros.hpp>
  6.  
  7. int main(int,char*[])
  8. {
  9. typedef std::pair<int,int> Edge;
  10. Edge used_by[] = {
  11. Edge(1, 5), Edge(1, 7), Edge(1, 2), Edge(2, 7), Edge(2, 12),
  12. Edge(3, 7), Edge(3, 10), Edge(3, 12),
  13. Edge(4, 5), Edge(5, 6),Edge(6, 9),Edge(7, 8),Edge(8, 9),Edge(9, 14),
  14. Edge(10, 11),Edge(11, 14),Edge(12, 13),Edge(13, 14),Edge(14, 15)
  15. };
  16. const int nedges = sizeof(used_by)/sizeof(Edge);
  17. double weights[nedges];
  18. std::fill(weights, weights + nedges, 1.0);
  19. weights[1] = 0.5;
  20. weights[2] = 1.5;
  21. weights[3] = 2.5;
  22.  
  23. using namespace boost;
  24.  
  25. typedef adjacency_list< vecS, vecS, directedS,
  26. property< vertex_color_t, default_color_type >,
  27. property< edge_weight_t, double >
  28. > Graph;
  29. Graph g_write(used_by, used_by + nedges, weights, 16);
  30.  
  31. // write
  32. dynamic_properties dp;
  33. dp.property("weight", get(edge_weight, g_write));
  34. dp.property("node_id", get(vertex_index, g_write));
  35. std::ofstream ofs( "test.dot" );
  36. write_graphviz(ofs, g_write, dp);
  37.  
  38. return 0;
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.