adjacency_list_graph.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2008-2010 Gordon Woodhull
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. // mplgraph.cpp : Defines the entry point for the console application.
  5. //
  6. #include <boost/msm/mpl_graph/adjacency_list_graph.hpp>
  7. #include <boost/msm/mpl_graph/mpl_utils.hpp>
  8. #include <boost/mpl/equal.hpp>
  9. namespace mpl_graph = boost::msm::mpl_graph;
  10. namespace mpl_utils = mpl_graph::mpl_utils;
  11. namespace mpl = boost::mpl;
  12. /*
  13. test graph and tests are almost identical to incidence_list_graph.cpp
  14. A -> B -> C -\--> D
  15. \ |--> E
  16. \ \--> F
  17. \-----/
  18. G // except this
  19. */
  20. // vertices
  21. struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{}; struct G{};
  22. // edges
  23. struct A_B{}; struct B_C{}; struct C_D{}; struct C_E{}; struct C_F{}; struct B_F{};
  24. typedef mpl::vector<
  25. mpl::pair<A, mpl::vector<mpl::pair<A_B, B> > >,
  26. mpl::pair<B, mpl::vector<mpl::pair<B_C, C>,
  27. mpl::pair<B_F, F> > >,
  28. mpl::pair<C, mpl::vector<mpl::pair<C_D, D>,
  29. mpl::pair<C_E, E>,
  30. mpl::pair<C_F, F> > >,
  31. mpl::pair<G, mpl::vector<> > >
  32. some_adjacency_list;
  33. typedef mpl_graph::adjacency_list_graph<some_adjacency_list> some_graph;
  34. BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<B_C,some_graph>::type, B> ));
  35. BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<C_D,some_graph>::type, C> ));
  36. BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<C_D,some_graph>::type, D> ));
  37. BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<B_F,some_graph>::type, F> ));
  38. // shouldn't assume the order but this seems to work
  39. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<C,some_graph>::type, mpl::vector<C_D,C_E,C_F> > ));
  40. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<B,some_graph>::type, mpl::vector<B_C,B_F> > ));
  41. BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<B,some_graph>::value), ==, 2 );
  42. BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<C,some_graph>::value), ==, 3 );
  43. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<C,some_graph>::type, mpl::vector<B_C> > ));
  44. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<F,some_graph>::type, mpl::vector<B_F,C_F> > ));
  45. BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<A,some_graph>::value), ==, 0 );
  46. BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<F,some_graph>::value), ==, 2 );
  47. BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<A,some_graph>::value), ==, 1 );
  48. BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<C,some_graph>::value), ==, 4 );
  49. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<A,some_graph>::type, mpl::vector<B> > ));
  50. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<C,some_graph>::type, mpl::vector<D,E,F> > ));
  51. BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::vertices<some_graph>::type, mpl::vector<A,B,C,D,E,F,G> > ));
  52. BOOST_MPL_ASSERT_RELATION( mpl_graph::num_vertices<some_graph>::value, ==, 7 );
  53. BOOST_MPL_ASSERT_RELATION( mpl_graph::num_edges<some_graph>::value, ==, 6 );
  54. int main(int argc, char* argv[])
  55. {
  56. return 0;
  57. }