Limbo 3.5.4
Loading...
Searching...
No Matches
MaxClique.h
Go to the documentation of this file.
1
7
8#ifndef LIMBO_ALGORITHMS_MAXCLIQUE_H
9#define LIMBO_ALGORITHMS_MAXCLIQUE_H
10
11#include <iostream>
12#include <vector>
13using std::cout;
14using std::endl;
15using std::vector;
16
17#include <deque>
18#include <boost/graph/bron_kerbosch_all_cliques.hpp>
19
21namespace limbo
22{
24namespace algorithms
25{
26
29template <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
69template <typename GraphType>
70inline vector<vector<typename boost::graph_traits<GraphType>::vertex_descriptor> >
71max_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
namespace for Limbo.algorithms
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
namespace for Limbo
callback for boost::bron_kerbosch_all_cliques
Definition MaxClique.h:31
clique_container_type & vClique
container to store cliques
Definition MaxClique.h:39
max_clique_visitor_type(clique_container_type const &rhs)
Definition MaxClique.h:46
max_clique_visitor_type(clique_container_type &vc)
Definition MaxClique.h:43
void clique(CliqueType const &c, graph_type const &cg)
Definition MaxClique.h:52