MinLCA algorithms
greedy_read_graph.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 using namespace std;
8 using namespace lemon;
9 using namespace minlca;
10 using namespace minlca::utils;
11 
16 
24 int main(int argc, char **argv)
25 {
26  GRAPH_TYPEDEFS(SmartGraph);
27  SmartGraph g;
28  ifstream graphFile(argv[1]);
29  GraphFormat format = RMF;
30 
31  if (string(argv[2]) == "GRA") {
32  format = GRA;
33  }
34 
35  Timer timer;
36  readGraphRandomOrder(g, atoi(argv[3]), format, graphFile);
37 
38  graphFile.close();
39 
40  cout << "Graph reading 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 << "Reading 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 
GraphFormat
Available graph formats.
Definition: graph_utils.hh:20
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
Functions for reading graphs and getting graph properties.
double initTime()
Retrieve the duration of initialising the algorithm.
Definition: profiler.hh:70
int main(int argc, char **argv)
Main function.
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
void readGraphRandomOrder(Graph &g, int seed=0, GraphFormat f=RMF, IS &in=std::cin)
Read a graph in random order.
Definition: graph_utils.hh:131
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