MinLCA algorithms
greedy_lp_read_graph.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <lemon/smart_graph.h>
4 #include <utils/graph_utils.hh>
5 #include <minlca/greedy.hh>
6 #include <minlca/greedy-lp.hh>
7 using namespace std;
8 using namespace lemon;
9 using namespace minlca;
10 using namespace minlca::utils;
11 
17 
23 int main(int argc, char **argv)
24 {
25  GRAPH_TYPEDEFS(SmartGraph);
26  SmartGraph g;
27  ifstream graphFile(argv[1]);
28  GraphFormat format = RMF;
29 
30  if (string(argv[2]) == "GRA") {
31  format = GRA;
32  }
33 
34  readGraph(g, format, graphFile);
35 
36  int n = countNodes(g);
37  int source = rand() % n;
38  cout << "Source node: " << source << endl;
39  cout << "Total nodes: " << n << endl;
40  cout << "Total edges: " << countEdges(g) << endl;
41 
42  cout << endl;
43  cout << "Using greedy nearest:" << endl;
44  MinLCAGreedyNearestBfs<SmartGraph> greedyNearest(g);
45  greedyNearest.init();
46  greedyNearest.setSourceNode(g.nodeFromId(source));
47 
48  if (greedyNearest.run() == SOLUTION_FOUND) {
49  cout << "Max colours: " << greedyNearest.maxK() << endl;
50  cout << "Colours used: " << greedyNearest.totalColours() << endl;
51  cout << "LCA value: " << greedyNearest.lcaValue() << endl;
52  }
53  else {
54  cout << "Could not find a solution!" << endl;
55  }
56 
57  cout << endl;
58 
59  cout << endl;
60  cout << "Using greedy LP:" << endl;
61  MinLCAGreedyLpBfs<SmartGraph> greedyLp(g, greedyNearest.totalColours());
62  greedyLp.init();
63  greedyLp.setSourceNode(g.nodeFromId(source));
64 
65  if (greedyLp.run() == SOLUTION_FOUND) {
66  cout << "Max colours: " << greedyLp.maxK() << endl;
67  cout << "Colours used: " << greedyLp.totalColours() << endl;
68  cout << "LCA value: " << greedyLp.lcaValue() << endl;
69  }
70  else {
71  cout << "Could not find a solution!" << endl;
72  }
73 }
74 
GraphFormat
Available graph formats.
Definition: graph_utils.hh:20
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.
int main(int argc, char **argv)
Main function.
Use the MinLCAGreedyLp with Bfs.
Definition: greedy-lp.hh:85
Definitions for the greedy algorithms using linear programming.
Namespace for util functions and classes.
Definition: binomial.hh:14