]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/bron_kerbosch_print_cliques.cpp
21c83b690da683814562ebdb4fd4f40b7ecf2707
1 // (C) Copyright Andrew Sutton 2007
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)
7 //[code_bron_kerbosch_print_cliques
10 #include <boost/graph/undirected_graph.hpp>
11 #include <boost/graph/bron_kerbosch_all_cliques.hpp>
16 using namespace boost
;
18 // The clique_printer is a visitor that will print the vertices that comprise
19 // a clique. Note that the vertices are not given in any specific order.
20 template < typename OutputStream
> struct clique_printer
22 clique_printer(OutputStream
& stream
) : os(stream
) {}
24 template < typename Clique
, typename Graph
>
25 void clique(const Clique
& c
, const Graph
& g
)
27 // Iterate over the clique and print each vertex within it.
28 typename
Clique::const_iterator i
, end
= c
.end();
29 for (i
= c
.begin(); i
!= end
; ++i
)
31 os
<< g
[*i
].name
<< " ";
38 // The Actor type stores the name of each vertex in the graph.
44 // Declare the graph type and its vertex and edge types.
45 typedef undirected_graph
< Actor
> Graph
;
46 typedef graph_traits
< Graph
>::vertex_descriptor Vertex
;
47 typedef graph_traits
< Graph
>::edge_descriptor Edge
;
49 // The name map provides an abstract accessor for the names of
50 // each vertex. This is used during graph creation.
51 typedef property_map
< Graph
, string
Actor::* >::type NameMap
;
53 int main(int argc
, char* argv
[])
55 // Create the graph and and its name map accessor.
57 NameMap
nm(get(&Actor::name
, g
));
59 // Read the graph from standard input.
60 read_graph(g
, nm
, cin
);
62 // Instantiate the visitor for printing cliques
63 clique_printer
< ostream
> vis(cout
);
65 // Use the Bron-Kerbosch algorithm to find all cliques, printing them
67 bron_kerbosch_all_cliques(g
, vis
);