Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaxClique.h
Go to the documentation of this file.
1 
8 #ifndef LIMBO_ALGORITHMS_MAXCLIQUE_H
9 #define LIMBO_ALGORITHMS_MAXCLIQUE_H
10 
11 #include <iostream>
12 #include <vector>
13 using std::cout;
14 using std::endl;
15 using std::vector;
16 
17 #include <deque>
18 #include <boost/graph/bron_kerbosch_all_cliques.hpp>
19 
21 namespace limbo
22 {
24 namespace algorithms
25 {
26 
29 template <typename GraphType>
31 {
33  typedef GraphType graph_type;
34  typedef typename boost::graph_traits<graph_type>::vertex_descriptor vertex_descriptor_type;
35  typedef vector<vertex_descriptor_type> clique_type;
36  typedef vector<clique_type> clique_container_type;
38 
39  clique_container_type& vClique;
40 
43  max_clique_visitor_type(clique_container_type& vc) : vClique(vc) {}
46  max_clique_visitor_type(clique_container_type const& rhs) : vClique(rhs.vClique) {}
47 
51  template <typename CliqueType>
52  void clique(CliqueType const& c, graph_type const& cg)
53  {
54  // convert to vertices in original graph
55 
56  // for debug
57  if (boost::num_vertices(cg) > 0)
58  assert(!c.empty());
59 
60  vClique.push_back(clique_type(c.begin(), c.end()));
61  }
62 };
63 
69 template <typename GraphType>
70 inline vector<vector<typename boost::graph_traits<GraphType>::vertex_descriptor> >
71 max_clique(GraphType const& g, size_t clique_num)
72 {
73  vector<vector<typename boost::graph_traits<GraphType>::vertex_descriptor> > vClique;
74  // search for all cliques with at least clique_num vertices
75  boost::bron_kerbosch_all_cliques(g, max_clique_visitor_type<GraphType>(vClique), clique_num);
76 
77  return vClique;
78 }
79 
80 } // namespace algorithms
81 } // namespace limbo
82 
83 #endif
max_clique_visitor_type(clique_container_type const &rhs)
Definition: MaxClique.h:46
clique_container_type & vClique
container to store cliques
Definition: MaxClique.h:39
void clique(CliqueType const &c, graph_type const &cg)
Definition: MaxClique.h:52
namespace for Limbo
Definition: GraphUtility.h:22
max_clique_visitor_type(clique_container_type &vc)
Definition: MaxClique.h:43
vector< vector< typename boost::graph_traits< GraphType >::vertex_descriptor > > max_clique(GraphType const &g, size_t clique_num)
use boost::bron_kerbosch_all_cliques to find all cliques and the maximum ones
Definition: MaxClique.h:71
callback for boost::bron_kerbosch_all_cliques
Definition: MaxClique.h:30