MinLCA algorithms
greedy_rnd_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>
6 #include <cstdlib>
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  readGraph(g, format, graphFile);
36 
37  int n = countNodes(g);
38  int source = rand() % n;
39  cout << "Source node: " << source << endl;
40  cout << "Total nodes: " << n << endl;
41  cout << "Total edges: " << countEdges(g) << endl;
42 
43  cout << endl;
44  cout << "Using greedy nearest:" << endl;
45  MinLCAGreedyNearestBfs<SmartGraph> greedyNearest(g);
46  greedyNearest.init();
47  greedyNearest.setSourceNode(g.nodeFromId(source));
48 
49  if (greedyNearest.run() == SOLUTION_FOUND) {
50  cout << "Max colours: " << greedyNearest.maxK() << endl;
51  cout << "Colours used: " << greedyNearest.totalColours() << endl;
52  cout << "LCA value: " << greedyNearest.lcaValue() << endl;
53  }
54  else {
55  cout << "Could not find a solution!" << endl;
56  }
57 
58  cout << endl;
59  cout << "Using greedy nearest random:" << endl;
60  MinLCAGreedyNearestRndBfs<SmartGraph> greedyNearestRnd(g, atoi(argv[4]));
61  greedyNearestRnd.p(atof(argv[3]));
62  greedyNearestRnd.seed(time(NULL));
63  greedyNearestRnd.init();
64  greedyNearestRnd.setSourceNode(g.nodeFromId(source));
65 
66  if (greedyNearestRnd.run() == SOLUTION_FOUND) {
67  cout << "Max colours: " << greedyNearestRnd.maxK() << endl;
68  cout << "Colours used: " << greedyNearestRnd.totalColours() << endl;
69  cout << "LCA value: " << greedyNearestRnd.lcaValue() << endl;
70  }
71  else {
72  cout << "Could not find a solution!" << endl;
73  }
74 }
75 
GraphFormat
Available graph formats.
Definition: graph_utils.hh:20
int main(int argc, char **argv)
Main function.
void readGraph(Graph &g, GraphFormat f=RMF, IS &in=std::cin)
Read a graph.
Definition: graph_utils.hh:160
void setSourceNode(const Node &v)
Set source node.
Definition: greedy.hh:114
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 greedy algorithms using a breadth-first search.
Definition: greedy.hh:52
Functions for reading graphs and getting graph properties.
Definitions of randomised greedy algorithms.
Namespace for util functions and classes.
Definition: binomial.hh:14