]>
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
)
26 template <typename Path
, typename Graph
>
27 void cycle(const Path
& p
, const Graph
& g
)
30 // Check to make sure that each of the vertices in the path
31 // is truly connected and that the back is connected to the
32 // front - it's not validating that we find all paths, just
33 // that the paths are valid.
34 typename
Path::const_iterator i
, j
, last
= prior(p
.end());
35 for(i
= p
.begin(); i
!= last
; ++i
) {
37 BOOST_ASSERT(edge(*i
, *j
, g
).second
);
39 BOOST_ASSERT(edge(p
.back(), p
.front(), g
).second
);
45 template <typename Graph
>
48 typedef erdos_renyi_iterator
<boost::minstd_rand
, Graph
> er
;
50 // Generate random graphs with 15 vertices and 15% probability
51 // of edge connection.
52 static const size_t N
= 20;
53 static const double P
= 0.1;
54 boost::minstd_rand rng
;
56 Graph
g(er(rng
, N
, P
), er(), N
);
58 print_edges(g
, get(vertex_index
, g
));
61 cycle_validator
vis(cycles
);
62 tiernan_all_cycles(g
, vis
);
63 cout
<< "# cycles: " << vis
.cycles
<< "\n";
69 typedef undirected_graph
<> Graph
;
70 typedef directed_graph
<> DiGraph
;
72 std::cout
<< "*** undirected ***\n";
75 std::cout
<< "*** directed ***\n";