1 #ifndef __MINLCA_UTILS_GENERATORS_OUTERPLANAR_HH
2 #define __MINLCA_UTILS_GENERATORS_OUTERPLANAR_HH
4 #include <lemon/smart_graph.h>
5 #include <lemon/random.h>
21 template<
typename BaseGraph = lemon::SmartGraph>
29 TEMPLATE_GRAPH_TYPEDEFS(Graph);
39 template<
typename Number =
int>
63 using namespace lemon;
65 this->reserveNode(_n);
66 this->reserveEdge(2 * _n);
68 _side_a =
_r->integer(1, _n / 2);
70 for (
int i = 0; i <
_n; ++i) {
76 for (
int i = 0; i < _side_a - 1; ++i)
77 if (findEdge(*
this, this->nodeFromId(i), this->nodeFromId(i + 1)) == INVALID) {
78 this->addEdge(this->nodeFromId(i), this->nodeFromId(i + 1));
81 for (
int i = _side_a; i < _n - 1; ++i)
82 if (findEdge(*
this, this->nodeFromId(i), this->nodeFromId(i + 1)) == INVALID) {
83 this->addEdge(this->nodeFromId(i), this->nodeFromId(i + 1));
86 if (findEdge(*
this, this->nodeFromId(0),
87 this->nodeFromId(_side_a)) == INVALID) {
88 this->addEdge(this->nodeFromId(0), this->nodeFromId(_side_a));
91 if (findEdge(*
this, this->nodeFromId(_side_a - 1),
92 this->nodeFromId(_n - 1)) == INVALID) {
93 this->addEdge(this->nodeFromId(_side_a - 1), this->nodeFromId(_n - 1));
98 while (bridgeLeft < _side_a) {
99 while (bridgeLeft < _side_a
100 and
degree(*
this, this->nodeFromId(bridgeLeft)) > 2) {
104 int bridgeRight = bridgeLeft;
106 while (bridgeRight < _side_a
107 and
degree(*
this, this->nodeFromId(bridgeRight)) == 2) {
111 if (bridgeRight < _side_a) {
115 bridgeLeft = bridgeRight + 1;
120 while (bridgeLeft < _n) {
121 while (bridgeLeft < _n and
degree(*
this, this->nodeFromId(bridgeLeft)) > 2) {
125 int bridgeRight = bridgeLeft;
127 while (bridgeRight < _n
128 and
degree(*
this, this->nodeFromId(bridgeRight)) == 2) {
132 if (bridgeRight < _n) {
136 bridgeLeft = bridgeRight + 1;
152 if (r1 < l1 or r2 < l2) {
156 int top =
_r->integer(l1, r1 + 1);
157 int bottom =
_r->integer(l2, r2 + 1);
158 this->addEdge(this->nodeFromId(top), this->nodeFromId(bottom));
183 this->addEdge(this->nodeFromId(l), this->nodeFromId(r));
186 switch (
_r->integer(3)) {
void _bridges(int l, int r)
Add bridges.
int _n
Number of vertices.
lemon::Random * _r
Random number generator.
void seed(Number seed)
Change the random number generator seed.
Contains base definitions for defining particular random graphs.
Default namespace Default namespace for MinLCA algorithms.
RandomOuterplanar(Number seed=0)
Constructor with seed.
Functions for reading graphs and getting graph properties.
RandomOuterplanar(lemon::Random &r)
Constructor with custom random number generator.
void _crossingChords(int l1, int r1, int l2, int r2)
Add chrossing chords.
int sideA() const
Retrieve number of vertices on side A
int degree(const Graph &g, const typename Graph::Node &v)
Degree of a vertex.
int _side_a
Number of vertices on side A
Class defining random geometric graphs.
virtual void generate()
Generate graph.
Graph & init(int n)
Initialise the generator.
Base class for random graph generators.