Limbo
3.5.4
Toggle main menu visibility
Loading...
Searching...
No Matches
limbo
algorithms
MaxIndependentSet.h
Go to the documentation of this file.
1
10
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>
16
#include <
limbo/algorithms/GraphUtility.h
>
17
18
namespace
limbo
{
namespace
algorithms
{
19
22
struct
MaxIndependentSetByMaxClique
23
{
29
template
<
typename
GraphType,
typename
MisVisitorType>
30
struct
clique_visitor_type
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
GraphUtility.h
some graph utilities such as compute complement graph and graphviz writer.
limbo::algorithms
namespace for Limbo.algorithms
Definition
GraphUtility.h:26
limbo::algorithms::complement_graph
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
limbo::algorithms::max_independent_set
void max_independent_set(GraphType const &g, VisitorType vis, AlgorithmType const &)
limbo
namespace for Limbo
Definition
GraphUtility.h:23
limbo::algorithms::MaxIndependentSetByMaxClique::clique_visitor_type
callback for boost::bron_kerbosch_all_cliques
Definition
MaxIndependentSet.h:31
limbo::algorithms::MaxIndependentSetByMaxClique::clique_visitor_type::clique
void clique(CliqueType const &c, graph_type const &cg)
Definition
MaxIndependentSet.h:54
limbo::algorithms::MaxIndependentSetByMaxClique::clique_visitor_type::mis_visitor
MisVisitorType & mis_visitor
bind mis visitor
Definition
MaxIndependentSet.h:39
limbo::algorithms::MaxIndependentSetByMaxClique::clique_visitor_type::clique_visitor_type
clique_visitor_type(clique_visitor_type const &rhs)
Definition
MaxIndependentSet.h:48
limbo::algorithms::MaxIndependentSetByMaxClique::clique_visitor_type::clique_visitor_type
clique_visitor_type(mis_visitor_type &mv, map_type &mCG2G)
Definition
MaxIndependentSet.h:45
limbo::algorithms::MaxIndependentSetByMaxClique::clique_visitor_type::mCompG2G
map_type & mCompG2G
bind vertex mapping from complement graph to original graph
Definition
MaxIndependentSet.h:40
limbo::algorithms::MaxIndependentSetByMaxClique
Definition
MaxIndependentSet.h:23
Generated on
for Limbo by
1.17.0