Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaxIndependentSet.h
Go to the documentation of this file.
1 
11 #ifndef LIMBO_ALGORITHMS_MAXINDEPENDENTSET_H
12 #define LIMBO_ALGORITHMS_MAXINDEPENDENTSET_H
13 
14 #include <deque>
15 #include <boost/graph/bron_kerbosch_all_cliques.hpp>
17 
18 namespace limbo { namespace algorithms {
19 
23 {
29  template <typename GraphType, typename MisVisitorType>
31  {
33  typedef GraphType graph_type;
34  typedef MisVisitorType mis_visitor_type;
35  typedef typename boost::graph_traits<graph_type>::vertex_descriptor vertex_descriptor_type;
36  typedef std::map<vertex_descriptor_type, vertex_descriptor_type> map_type;
38 
39  MisVisitorType& mis_visitor;
40  map_type& mCompG2G;
41 
45  clique_visitor_type(mis_visitor_type& mv, map_type& mCG2G) : mis_visitor(mv), mCompG2G(mCG2G) {}
48  clique_visitor_type(clique_visitor_type const& rhs) : mis_visitor(rhs.mis_visitor), mCompG2G(rhs.mCompG2G) {}
49 
53  template <typename CliqueType>
54  void clique(CliqueType const& c, graph_type const& cg)
55  {
56  // convert to vertices in original graph
57  typedef CliqueType clique_type;
58  clique_type is;
59 
60  // for debug
61  if (boost::num_vertices(cg) > 0)
62  assert(!c.empty());
63 
64  for (typename clique_type::const_iterator it = c.begin();
65  it != c.end(); ++it)
66  is.push_back(mCompG2G[*it]);
67 
68  mis_visitor.mis(is);
69  }
70  };
71 };
72 
81 template <typename GraphType, typename VisitorType, typename AlgorithmType>
82 inline void max_independent_set(GraphType const& g, VisitorType vis, AlgorithmType const&);
83 
92 template <typename GraphType, typename MisVisitorType>
93 inline void max_independent_set(GraphType const& g, MisVisitorType vis, MaxIndependentSetByMaxClique const&)
94 {
95  typedef typename boost::graph_traits<GraphType>::vertex_descriptor vertex_descriptor_type;
96  GraphType cg; // complement graph
97  std::map<vertex_descriptor_type, vertex_descriptor_type> mCompG2G; // mapping from vertices in complement graph to original graph
98 
99  // calculate complement graph
100  limbo::algorithms::complement_graph(g, cg, mCompG2G);
101 
102  // search for all cliques with at least 1 vertex
103  boost::bron_kerbosch_all_cliques(cg, MaxIndependentSetByMaxClique::clique_visitor_type<GraphType, MisVisitorType>(vis, mCompG2G), 1);
104 }
105 
106 } // namespace algorithms
107 } // namespace limbo
108 
109 #endif
void complement_graph(GraphType const &g, GraphType &gp, std::map< typename boost::graph_traits< GraphType >::vertex_descriptor, typename boost::graph_traits< GraphType >::vertex_descriptor > &mCompG2G)
get the complement graph of original graph
Definition: GraphUtility.h:34
some graph utilities such as compute complement graph and graphviz writer.
map_type & mCompG2G
bind vertex mapping from complement graph to original graph
void max_independent_set(GraphType const &g, VisitorType vis, AlgorithmType const &)
namespace for Limbo
Definition: GraphUtility.h:22
void clique(CliqueType const &c, graph_type const &cg)