MinLCA algorithms
cliques.hh
Go to the documentation of this file.
1 #ifndef __MINLCA_UTILS_GENERATORS_CLIQUES_HH
2 #define __MINLCA_UTILS_GENERATORS_CLIQUES_HH
3 
4 #include <lemon/smart_graph.h>
5 #include <lemon/random.h>
7 
10 
11 namespace minlca
12 {
13 namespace utils
14 {
15 
17 template<typename BaseGraph = lemon::SmartGraph>
18 class CliqueSet : public BaseGraph
19 {
20 protected:
22  int _s;
23  int _c;
24 
25 public:
27  virtual Graph &init(
28  int s,
29  int c
30  )
31  {
32  _s = s;
33  _c = c;
34 
35  return *this;
36  }
37 
40  int cliqueOrder() const
41  {
42  return _s;
43  }
44 
47  int cliques() const
48  {
49  return _c;
50  }
51 
52  virtual void generate()
53  {
54  this->clear();
55  this->reserveNode(_c * _s);
56 
57  for (int i = 0; i < _c; ++i) {
58  for (int j = 0; j < _s; ++j) {
59  this->addNode();
60 
61  for (int l = i * _s; l < i * _s + j; ++l) {
62  this->addEdge(this->nodeFromId(l), this->nodeFromId(i * _s + j));
63  }
64  }
65  }
66  }
67 };
68 
73 template<typename BaseGraph = lemon::SmartGraph>
74 class CliqueCycle : public CliqueSet<BaseGraph>
75 {
76 protected:
77  typedef CliqueCycle<BaseGraph> Graph;
78  typedef CliqueSet<BaseGraph> Base;
79  using Base::_s;
80  using Base::_c;
81 
82 public:
83  virtual Graph &init(int s, int c)
84  {
85  Base::init(s, c);
86 
87  return *this;
88  }
89 
90  virtual void generate()
91  {
92  Base::generate();
93 
94  for (int i = 0; i < _c - 1; ++i) {
95  this->addEdge(this->nodeFromId(i * _s), this->nodeFromId(i * _s + 1));
96  }
97 
98  this->addEdge(this->nodeFromId((_c - 1) * _s), this->nodeFromId(1));
99  }
100 };
101 
106 template<typename BaseGraph = lemon::SmartGraph>
107 class CliqueGraph : public RandomGraph<CliqueSet<BaseGraph>>
108 {
109 protected:
110  typedef CliqueGraph<BaseGraph> Graph;
111  typedef RandomGraph<CliqueSet<BaseGraph>> Base;
112  using Base::_s;
113  using Base::_c;
114  using Base::_r;
115  double _p;
116 
117 public:
120  template<typename Number = int>
121  CliqueGraph(Number seed = 0)
122  : Base(seed)
123  {
124  }
125 
128  CliqueGraph(lemon::Random &r)
129  : Base(r)
130  {
131  }
132 
133  double p()
134  {
135  return _p;
136  }
137 
140  virtual Graph &init(
141  int s,
142  int c,
143  double p
144  )
145  {
146  Base::init(s, c);
147  _p = std::max(0.0, std::min(1.0, p));
148 
149  return *this;
150  }
151 
152  virtual void generate()
153  {
155 
156  for (int i = 0; i < _c; ++i) {
157  for (int j = i + 1; j < _c; ++j)
158  if (_r->boolean(_p))
159  this->addEdge(this->nodeFromId(i * _s + _r->integer(_s)),
160  this->nodeFromId(j * _s + _r->integer(_s)));
161  }
162  }
163 };
164 }
165 }
166 
167 #endif
CliqueGraph(Number seed=0)
Constructor with seed.
Definition: cliques.hh:121
Class describing a cycle of cliques.
Definition: cliques.hh:74
lemon::Random * _r
Random number generator.
Definition: random-graph.hh:19
void seed(Number seed)
Change the random number generator seed.
Definition: random-graph.hh:56
int cliqueOrder() const
Retrieve the order of each clique.
Definition: cliques.hh:40
virtual Graph & init(int s, int c)
Initialise the generator.
Definition: cliques.hh:83
virtual Graph & init(int s, int c, double p)
Initialise the generator.
Definition: cliques.hh:140
virtual void generate()
Generate graph.
Definition: cliques.hh:152
Contains base definitions for defining particular random graphs.
int _c
Number of cliques.
Definition: cliques.hh:23
Default namespace Default namespace for MinLCA algorithms.
Definition: base.hh:15
int cliques() const
Retrieve the number of cliques.
Definition: cliques.hh:47
Class describing a random graph with cliques.
Definition: cliques.hh:107
int _s
Order of each clique.
Definition: cliques.hh:22
virtual Graph & init(int s, int c)
Initialise the generator.
Definition: cliques.hh:27
double _p
Probability of edge between cliques.
Definition: cliques.hh:115
Class describing a set of non-adjacent cliques.
Definition: cliques.hh:18
Base class for random graph generators.
Definition: random-graph.hh:16
CliqueGraph(lemon::Random &r)
Constructor with custom random number generator.
Definition: cliques.hh:128