MinLCA algorithms
greedy_binomial_random.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <lemon/smart_graph.h>
4 #include <minlca/greedy.hh>
5 #include <minlca/profiler.hh>
6 #include <lemon/graph_to_eps.h>
7 using namespace std;
8 using namespace lemon;
9 using namespace minlca;
10 using namespace minlca::utils;
11 
12 template<typename Graph>
13 int shape(typename Graph::Node)
14 {
15  return 0;
16 }
17 
22 
30 int main(int argc, char **argv)
31 {
32  GRAPH_TYPEDEFS(BinomialRandom<>);
33  Timer timer;
34  BinomialRandom<> g(atoi(argv[3]));
35  g.init(atoi(argv[1]), atof(argv[2])).generate();
36  cout << "Graph generation time: " << timer.elapsed() << endl;
37  cout << endl;
38 
39  int n = countNodes(g);
40  cout << "Total nodes: " << n << endl;
41  cout << "Total edges: " << countEdges(g) << endl;
42  cout << "Edge prob.: " << g.p() << endl;
43  cout << "Random seed: " << argv[3] << endl;
44 
45  cout << endl;
46  cout << "Using greedy nearest:" << endl;
47 
49  cout << "Creation elapsed time: " << greedyNearest.creationTime() << endl;
50  greedyNearest.init();
51  cout << "Initialisation elapsed time: " << greedyNearest.initTime() << endl;
52 
53  if (greedyNearest.run() == SOLUTION_FOUND) {
54  cout << "Algorithm running time: " << greedyNearest.runTime() << endl;
55  cout << "Max colours: " << greedyNearest.maxK() << endl;
56  cout << "Colours used: " << greedyNearest.totalColours() << endl;
57  cout << "LCA value: " << greedyNearest.lcaValue() << endl;
58  }
59  else {
60  cout << "Could not find a solution!" << endl;
61  }
62 
63  cout << endl;
64 
65  cout << "Using greedy least cost:" << endl;
66 
68  cout << "Creation elapsed time: " << greedyLeastCost.creationTime() << endl;
69  greedyLeastCost.init();
70  cout << "Initialisation elapsed time: " << greedyLeastCost.initTime() << endl;
71 
72  if (greedyLeastCost.run() == SOLUTION_FOUND) {
73  cout << "Algorithm running time: " << greedyLeastCost.runTime() << endl;
74  cout << "Max colours: " << greedyLeastCost.maxK() << endl;
75  cout << "Colours used: " << greedyLeastCost.totalColours() << endl;
76  cout << "LCA value: " << greedyLeastCost.lcaValue() << endl;
77  }
78  else {
79  cout << "Could not find a solution!" << endl;
80  }
81 
82  BinomialRandom<>::NodeMap<dim2::Point<double>> coords(g);
83 
84  for (NodeIt v(g); v != INVALID; ++v) {
85  int id = g.id(v);
86  coords[v] = dim2::Point<double>(cos(id * 2.0 * M_PI / n),
87  sin(id * 2.0 * M_PI / n));
88  }
89 
90  auto shapes = functorToMap(shape<BinomialRandom<>>);
91 
92  if (argc > 4)
93  graphToEps(g, argv[4])
94  .coords(coords)
95  .nodeShapes(shapes)
96  .nodeScale(.003)
97  .edgeWidthScale(.0005)
98  .undirected()
99  .scaleToA4()
100  .run();
101 }
102 
Class defining binomial random graphs.
Definition: binomial.hh:19
double p() const
Retrieve the edge probability.
Definition: binomial.hh:64
double runTime()
Retrieve the duration of running the algorithm.
Definition: profiler.hh:62
Graph & init(int n, double p)
Initialise the generator.
Definition: binomial.hh:52
Contains definition for BinomialRandom graphs.
virtual void generate()
Generate graph.
Definition: binomial.hh:69
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
double initTime()
Retrieve the duration of initialising the algorithm.
Definition: profiler.hh:70
Simple timing class.
Definition: timer.hh:14
double creationTime()
Retrieve the duration of instantiating the algorithm class.
Definition: profiler.hh:78
int main(int argc, char **argv)
Main function.
Contains the definitions for timing MinLCA algorithms.
double elapsed() const
Retrieve elapsed time.
Definition: timer.cc:20
void init(Args &&...args)
Reset the data structures of the algorithm.
Definition: profiler.hh:39
Namespace for util functions and classes.
Definition: binomial.hh:14