]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/test/tiernan_all_cycles.cpp
1 // (C) Copyright 2007-2009 Andrew Sutton
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0 (See accompanying file
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/graph/graph_utility.hpp>
10 #include <boost/graph/undirected_graph.hpp>
11 #include <boost/graph/directed_graph.hpp>
12 #include <boost/graph/tiernan_all_cycles.hpp>
13 #include <boost/graph/erdos_renyi_generator.hpp>
15 #include <boost/random/linear_congruential.hpp>
18 using namespace boost
;
20 struct cycle_validator
22 cycle_validator(size_t& c
) : cycles(c
) {}
24 template < typename Path
, typename Graph
>
25 void cycle(const Path
& p
, const Graph
& g
)
28 // Check to make sure that each of the vertices in the path
29 // is truly connected and that the back is connected to the
30 // front - it's not validating that we find all paths, just
31 // that the paths are valid.
32 typename
Path::const_iterator i
, j
, last
= prior(p
.end());
33 for (i
= p
.begin(); i
!= last
; ++i
)
36 BOOST_ASSERT(edge(*i
, *j
, g
).second
);
38 BOOST_ASSERT(edge(p
.back(), p
.front(), g
).second
);
44 template < typename Graph
> void test()
46 typedef erdos_renyi_iterator
< boost::minstd_rand
, Graph
> er
;
48 // Generate random graphs with 15 vertices and 15% probability
49 // of edge connection.
50 static const size_t N
= 20;
51 static const double P
= 0.1;
52 boost::minstd_rand rng
;
54 Graph
g(er(rng
, N
, P
), er(), N
);
56 print_edges(g
, get(vertex_index
, g
));
59 cycle_validator
vis(cycles
);
60 tiernan_all_cycles(g
, vis
);
61 cout
<< "# cycles: " << vis
.cycles
<< "\n";
64 int main(int, char*[])
66 typedef undirected_graph
<> Graph
;
67 typedef directed_graph
<> DiGraph
;
69 std::cout
<< "*** undirected ***\n";
72 std::cout
<< "*** directed ***\n";