adjacency_matrix.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //=======================================================================
  2. // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
  3. // Author: Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #include <boost/config.hpp>
  10. #include <iostream>
  11. #include <boost/graph/adjacency_matrix.hpp>
  12. #include <boost/graph/graph_utility.hpp>
  13. int main()
  14. {
  15. using namespace boost;
  16. enum { A, B, C, D, E, F, N };
  17. const char* name = "ABCDEF";
  18. // A directed graph
  19. typedef adjacency_matrix<directedS> Graph;
  20. Graph g(N);
  21. add_edge(B, C, g);
  22. add_edge(B, F, g);
  23. add_edge(C, A, g);
  24. add_edge(C, C, g);
  25. add_edge(D, E, g);
  26. add_edge(E, D, g);
  27. add_edge(F, A, g);
  28. std::cout << "vertex set: ";
  29. print_vertices(g, name);
  30. std::cout << std::endl;
  31. std::cout << "edge set: ";
  32. print_edges(g, name);
  33. std::cout << std::endl;
  34. std::cout << "out-edges: " << std::endl;
  35. print_graph(g, name);
  36. std::cout << std::endl;
  37. // An undirected graph
  38. typedef adjacency_matrix<undirectedS> UGraph;
  39. UGraph ug(N);
  40. add_edge(B, C, ug);
  41. add_edge(B, F, ug);
  42. add_edge(C, A, ug);
  43. add_edge(D, E, ug);
  44. add_edge(F, A, ug);
  45. std::cout << "vertex set: ";
  46. print_vertices(ug, name);
  47. std::cout << std::endl;
  48. std::cout << "edge set: ";
  49. print_edges(ug, name);
  50. std::cout << std::endl;
  51. std::cout << "incident edges: " << std::endl;
  52. print_graph(ug, name);
  53. std::cout << std::endl;
  54. return 0;
  55. }