MinLCA algorithms
greedy_random_outerplanar.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <lemon/smart_graph.h>
3 #include <utils/graph_utils.hh>
4 #include <minlca/greedy.hh>
5 #include <utils/timer.hh>
6 #include <minlca/profiler.hh>
7 #include <lemon/graph_to_eps.h>
9 using namespace std;
10 using namespace lemon;
11 using namespace minlca;
12 using namespace minlca::utils;
13 
14 template<typename Graph>
15 int shape(typename Graph::Node)
16 {
17  return 0;
18 }
19 
24 
31 int main(int argc, char **argv)
32 {
33  GRAPH_TYPEDEFS(RandomOuterplanar<>);
34 
35  Timer timer;
36  RandomOuterplanar<> g(atoi(argv[2]));
37  g.init(atoi(argv[1])).generate();
38  int top = g.sideA();
39 
40  cout << "Graph generation time: " << timer.elapsed() << endl;
41  cout << endl;
42 
43  int n = countNodes(g);
44  cout << "Total nodes: " << n << endl;
45  cout << "Total edges: " << countEdges(g) << endl;
46  cout << "Random seed: " << argv[2] << endl;
47 
48  cout << endl;
49  cout << "Using greedy nearest:" << endl;
50 
52  cout << "Creation elapsed time: " << greedyNearest.creationTime() << endl;
53  greedyNearest.init();
54  cout << "Initialisation elapsed time: " << greedyNearest.initTime() << endl;
55 
56  if (greedyNearest.run() == SOLUTION_FOUND) {
57  cout << "Algorithm running time: " << greedyNearest.runTime() << endl;
58  cout << "Max colours: " << greedyNearest.maxK() << endl;
59  cout << "Colours used: " << greedyNearest.totalColours() << endl;
60  cout << "LCA value: " << greedyNearest.lcaValue() << endl;
61  }
62  else {
63  cout << "Could not find a solution!" << endl;
64  }
65 
66  cout << endl;
67 
68  cout << "Using greedy least cost:" << endl;
69 
71  g);
72  cout << "Creation elapsed time: " << greedyLeastCost.creationTime() << endl;
73  greedyLeastCost.init();
74  cout << "Initialisation elapsed time: " << greedyLeastCost.initTime() << endl;
75 
76  if (greedyLeastCost.run() == SOLUTION_FOUND) {
77  cout << "Algorithm running time: " << greedyLeastCost.runTime() << endl;
78  cout << "Max colours: " << greedyLeastCost.maxK() << endl;
79  cout << "Colours used: " << greedyLeastCost.totalColours() << endl;
80  cout << "LCA value: " << greedyLeastCost.lcaValue() << endl;
81  }
82  else {
83  cout << "Could not find a solution!" << endl;
84  }
85 
86  if (argc > 3) {
87  RandomOuterplanar<>::NodeMap <dim2::Point<double>> coords(g);
88 
89  double pi2 = 2.0 * M_PI;
90 
91  for (int v = 0; v < top; ++v) {
92  double angle = v * pi2 / n;
93  coords[g.nodeFromId(v)] = dim2::Point<double>(cos(angle), sin(angle));
94  }
95 
96  for (int v = top; v < n; ++v) {
97  double angle = (n - 1 - v + top) * pi2 / n;
98  coords[g.nodeFromId(v)] = dim2::Point<double>(cos(angle), sin(angle));
99  }
100 
101  auto shapes = functorToMap(shape<RandomOuterplanar<>>);
102  graphToEps(g, argv[3])
103  .coords(coords)
104  .nodeShapes(shapes)
105  .nodeScale(.003)
106  //.hideNodes()
107  .edgeWidthScale(.00005)
108  .undirected()
109  .scaleToA4()
110  .run();
111  }
112 }
113 
Contains definition for RandomOuterplanar graphs.
double runTime()
Retrieve the duration of running the algorithm.
Definition: profiler.hh:62
virtual MinLCAStatus run()
Run the algorithm.
Definition: profiler.hh:50
Solution has been found after running.
Definition: base.hh:22
LEMON namespace.
Definition: grb.cc:29
Default namespace Default namespace for MinLCA algorithms.
Definition: base.hh:15
Class for timing MinLCA algorithms.
Definition: profiler.hh:16
int main(int argc, char **argv)
Main function.
Functions for reading graphs and getting graph properties.
double initTime()
Retrieve the duration of initialising the algorithm.
Definition: profiler.hh:70
int sideA() const
Retrieve number of vertices on side A
Definition: outerplanar.hh:143
Description of Timer.
Simple timing class.
Definition: timer.hh:14
double creationTime()
Retrieve the duration of instantiating the algorithm class.
Definition: profiler.hh:78
Contains the definitions for timing MinLCA algorithms.
double elapsed() const
Retrieve elapsed time.
Definition: timer.cc:20
Class defining random geometric graphs.
Definition: outerplanar.hh:22
virtual void generate()
Generate graph.
Definition: outerplanar.hh:61
void init(Args &&...args)
Reset the data structures of the algorithm.
Definition: profiler.hh:39
Graph & init(int n)
Initialise the generator.
Definition: outerplanar.hh:53
Namespace for util functions and classes.
Definition: binomial.hh:14