• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 // mplgraph.cpp : Defines the entry point for the console application.
6 //
7 
8 #include <boost/msm/mpl_graph/adjacency_list_graph.hpp>
9 #include <boost/msm/mpl_graph/mpl_utils.hpp>
10 #include <boost/mpl/equal.hpp>
11 
12 
13 namespace mpl_graph = boost::msm::mpl_graph;
14 namespace mpl_utils = mpl_graph::mpl_utils;
15 namespace mpl = boost::mpl;
16 
17 /*
18     test graph and tests are almost identical to incidence_list_graph.cpp
19     A -> B -> C -\--> D
20            \     |--> E
21             \    \--> F
22              \-----/
23     G  // except this
24 */
25 
26 // vertices
27 struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{}; struct G{};
28 
29 // edges
30 struct A_B{}; struct B_C{}; struct C_D{}; struct C_E{}; struct C_F{}; struct B_F{};
31 
32 typedef mpl::vector<
33             mpl::pair<A, mpl::vector<mpl::pair<A_B, B> > >,
34             mpl::pair<B, mpl::vector<mpl::pair<B_C, C>,
35                                      mpl::pair<B_F, F> > >,
36             mpl::pair<C, mpl::vector<mpl::pair<C_D, D>,
37                                      mpl::pair<C_E, E>,
38                                      mpl::pair<C_F, F> > >,
39             mpl::pair<G, mpl::vector<> > >
40     some_adjacency_list;
41 typedef mpl_graph::adjacency_list_graph<some_adjacency_list> some_graph;
42 
43 BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<B_C,some_graph>::type, B> ));
44 BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<C_D,some_graph>::type, C> ));
45 
46 BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<C_D,some_graph>::type, D> ));
47 BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<B_F,some_graph>::type, F> ));
48 
49 
50 // shouldn't assume the order but this seems to work
51 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<C,some_graph>::type, mpl::vector<C_D,C_E,C_F> > ));
52 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<B,some_graph>::type, mpl::vector<B_C,B_F> > ));
53 
54 BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<B,some_graph>::value), ==, 2 );
55 BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<C,some_graph>::value), ==, 3 );
56 
57 
58 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<C,some_graph>::type, mpl::vector<B_C> > ));
59 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<F,some_graph>::type, mpl::vector<B_F,C_F> > ));
60 
61 BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<A,some_graph>::value), ==, 0 );
62 BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<F,some_graph>::value), ==, 2 );
63 
64 
65 BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<A,some_graph>::value), ==, 1 );
66 BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<C,some_graph>::value), ==, 4 );
67 
68 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<A,some_graph>::type, mpl::vector<B> > ));
69 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<C,some_graph>::type, mpl::vector<D,E,F> > ));
70 
71 BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::vertices<some_graph>::type, mpl::vector<A,B,C,D,E,F,G> > ));
72 
73 BOOST_MPL_ASSERT_RELATION( mpl_graph::num_vertices<some_graph>::value, ==, 7 );
74 
75 BOOST_MPL_ASSERT_RELATION( mpl_graph::num_edges<some_graph>::value, ==, 6 );
76 
77 
main(int argc,char * argv[])78 int main(int argc, char* argv[])
79 {
80     return 0;
81 }
82 
83