MinLCA algorithms
greedy_random_geometric.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 <lemon/graph_to_eps.h>
6 #include <minlca/profiler.hh>
8 using namespace std;
9 using namespace lemon;
10 using namespace minlca;
11 using namespace minlca::utils;
12 
13 template<typename Graph>
14 int shape(typename Graph::Node)
15 {
16  return 0;
17 }
18 
23 
31 int main(int argc, char **argv)
32 {
33  GRAPH_TYPEDEFS(RandomGeometric<>);
34 
35  Timer timer;
36  RandomGeometric<> g(atoi(argv[3]));
37  g.init(atoi(argv[1]), atof(argv[2])).generate();
38 
39  cout << "Graph generation time: " << timer.elapsed() << endl;
40  cout << endl;
41 
42  int n = countNodes(g);
43  cout << "Total nodes: " << n << endl;
44  cout << "Total edges: " << countEdges(g) << endl;
45  cout << "Radius squared: " << atof(argv[2]) << endl;
46  cout << "Random seed: " << argv[3] << 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  cout << "Creation elapsed time: " << greedyLeastCost.creationTime() << endl;
72  greedyLeastCost.init();
73  cout << "Initialisation elapsed time: " << greedyLeastCost.initTime() << endl;
74 
75  if (greedyLeastCost.run() == SOLUTION_FOUND) {
76  cout << "Algorithm running time: " << greedyLeastCost.runTime() << endl;
77  cout << "Max colours: " << greedyLeastCost.maxK() << endl;
78  cout << "Colours used: " << greedyLeastCost.totalColours() << endl;
79  cout << "LCA value: " << greedyLeastCost.lcaValue() << endl;
80  }
81  else {
82  cout << "Could not find a solution!" << endl;
83  }
84 
85  auto shapes = functorToMap(shape<RandomGeometric<>>);
86 
87  if (argc > 4)
88  graphToEps(g, argv[4])
89  .coords(g.coords())
90  .nodeShapes(shapes)
91  .nodeScale(.003)
92  .edgeWidthScale(.0005)
93  .undirected()
94  .scaleToA4()
95  .run();
96 }
97 
virtual void generate()
Generate graph.
Definition: geometric.hh:65
double runTime()
Retrieve the duration of running the algorithm.
Definition: profiler.hh:62
Class defining random geometric graphs.
Definition: geometric.hh:21
virtual MinLCAStatus run()
Run the algorithm.
Definition: profiler.hh:50
int main(int argc, char **argv)
Main function.
Contains definition for RandomGeometric graphs.
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
Graph & init(int n, double radSq)
Initialise the generator.
Definition: geometric.hh:54
Class for timing MinLCA algorithms.
Definition: profiler.hh:16
Functions for reading graphs and getting graph properties.
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
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
const Coords & coords() const
Retrieve all the coordinates.
Definition: geometric.hh:101
Namespace for util functions and classes.
Definition: binomial.hh:14