MinLCA algorithms
sa_colours_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>
5 #include <utils/timer.hh>
6 #include <minlca/profiler.hh>
7 #include <minlca/greedy.hh>
9 using namespace std;
10 using namespace lemon;
11 using namespace minlca;
12 using namespace minlca::utils;
13 
19 
32 int main(int argc, char **argv)
33 {
34  GRAPH_TYPEDEFS(SmartGraph);
35  SmartGraph g;
36  ifstream graphFile(argv[1]);
37  GraphFormat format = RMF;
38 
39  if (string(argv[2]) == "GRA") {
40  format = GRA;
41  }
42 
43  Timer timer;
44  readGraph(g, format, graphFile);
45 
46  graphFile.close();
47 
48  cout << "Graph reading time: " << timer.elapsed() << endl;
49  cout << endl;
50 
51  int n = countNodes(g);
52  cout << "Total nodes: " << n << endl;
53  cout << "Total edges: " << countEdges(g) << endl;
54 
55  cout << endl;
56  cout << "Using greedy nearest:" << endl;
57 
59  cout << "Creation elapsed time: " << greedyNearest.creationTime() << endl;
60  greedyNearest.init();
61  cout << "Initialisation elapsed time: " << greedyNearest.initTime() << endl;
62 
63  if (greedyNearest.run() == SOLUTION_FOUND) {
64  cout << "Algorithm running time: " << greedyNearest.runTime() << endl;
65  cout << "Max colours: " << greedyNearest.maxK() << endl;
66  cout << "Colours used: " << greedyNearest.totalColours() << endl;
67  cout << "LCA value: " << greedyNearest.lcaValue() << endl;
68  }
69  else {
70  cout << "Could not find a solution!" << endl;
71  }
72 
73  cout << endl;
74  cout << "Using simulated annealing:" << endl;
75 
77  coloursSA(g, 0, atoi(argv[3]));
78  cout << "Creation elapsed time: " << coloursSA.creationTime() << endl;
79  coloursSA.init(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atof(argv[7]));
80  cout << "Initialisation elapsed time: " << coloursSA.initTime() << endl;
81 
82  coloursSA.initialSolution(greedyNearest.colouring());
83  cout << "Initial solution elapsed time: " << coloursSA.initialSolutionTime() <<
84  endl;
85 
86  if (coloursSA.run() == SOLUTION_FOUND) {
87  cout << "Algorithm running time: " << coloursSA.runTime() << endl;
88  cout << "Max colours: " << coloursSA.maxK() << endl;
89  cout << "Colours used: " << coloursSA.totalColours() << endl;
90  cout << "LCA value: " << coloursSA.lcaValue() << endl;
91  }
92  else {
93  cout << "Could not find a solution!" << endl;
94  }
95 }
96 
GraphFormat
Available graph formats.
Definition: graph_utils.hh:20
double initialSolutionTime()
Retrieve the duration of setting the initial solution.
void readGraph(Graph &g, GraphFormat f=RMF, IS &in=std::cin)
Read a graph.
Definition: graph_utils.hh:160
double runTime()
Retrieve the duration of running the algorithm.
Definition: profiler.hh:62
virtual MinLCAStatus run()
Run the algorithm.
Definition: profiler.hh:50
Definitions for a simulated annealing approach changing the colours.
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
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 for timing MinLCA optimisation algorithms.
int main(int argc, char **argv)
Main function.
void init(Args &&...args)
Reset the data structures of the algorithm.
Definition: profiler.hh:39
Contains the definitions for timing MinLCA optimisation algorithms.
Namespace for util functions and classes.
Definition: binomial.hh:14