boost::adjacency_matrix example (Boost Graph Library)


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

http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/adjacency_matrix.html


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. #include <boost/graph/graph_utility.hpp>
  3. #include <boost/graph/adjacency_matrix.hpp>
  4.  
  5.  
  6. enum { A, B, C, D, E, F, N };
  7. const char* name = "ABCDEF";
  8.  
  9. typedef boost::adjacency_matrix<boost::directedS> Graph;
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13. Graph g(N);
  14. add_edge(B, C, g);
  15. add_edge(B, F, g);
  16. add_edge(C, A, g);
  17. add_edge(C, C, g);
  18. add_edge(D, E, g);
  19. add_edge(E, D, g);
  20. add_edge(F, A, g);
  21.  
  22. std::cout << "vertex set: ";
  23. boost::print_vertices(g, name);
  24. std::cout << std::endl;
  25.  
  26. std::cout << "edge set: ";
  27. boost::print_edges(g, name);
  28. std::cout << std::endl;
  29.  
  30. std::cout << "out-edges: " << std::endl;
  31. boost::print_graph(g, name);
  32. std::cout << std::endl;
  33. return 0;
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.