MinLCA algorithms
greedy-lp.hh
Go to the documentation of this file.
1 #ifndef __MINLCA_MINLCA_GREEDY_LP_HH
2 #define __MINLCA_MINLCA_GREEDY_LP_HH
3 
4 #include <minlca/greedy.hh>
5 #include "lp-model.hh"
6 
9 
10 namespace minlca
11 {
12 
22 template<typename Graph = lemon::SmartGraph>
24  : public MinLCAGreedy<Graph>
25 {
26  friend class lemon::BfsVisit<Graph, MinLCAGreedyLp<Graph>>;
27 
28 protected:
29  TEMPLATE_GRAPH_TYPEDEFS(Graph);
31  using Base::_g;
32  using Base::_c;
33  using Base::_max_k;
34  using Base::_lca;
35  using Base::_k;
36 
38 
43  MinLCAGreedyLp(const Graph &g, int maxK = 0)
44  : Base(g, maxK), model(g, _max_k)
45  {
46  }
47 
48  void solveModel()
49  {
50  model.solve();
51  }
52 
53  virtual void paintVertex(const Node &v)
54  {
55 
56  std::vector<bool> colours(_max_k, true);
57 
58  for (IncEdgeIt e(_g, v); e != lemon::INVALID; ++e) {
59  Node n = _g.oppositeNode(v, e);
60  int nColour = _c[n];
61 
62  if (nColour != -1) {
63  colours[nColour] = false;
64  }
65  }
66 
67  std::vector<int> colourOrder = model.getColourOrder(v);
68  int vColour = -1;
69 
70  for (int i = 0; i < _max_k and vColour == -1; ++i) {
71  int currentColour = colourOrder[i];
72 
73  if (colours[currentColour]) {
74  vColour = currentColour;
75  }
76  }
77 
78  this->setColour(v, vColour);
79  }
80 };
81 
82 
84 template<typename Graph = lemon::SmartGraph>
86  public MinLCAGreedyBfs<MinLCAGreedyLp, Graph>
87 {
89 public:
95  MinLCAGreedyLpBfs(const Graph &g, int maxK = 0) : Base(g, maxK)
96  {
97  }
98 
99  virtual MinLCAStatus run()
100  {
101  this->solveModel();
102  return Base::run();
103  }
104 };
105 }
106 
107 #endif
virtual MinLCAStatus run()
Run the algorithm.
Definition: greedy-lp.hh:99
Class defining a relaxed linear programming model for MinLCA.
Definition: lp-model.hh:27
virtual void setColour(const Node &v, int vColour)
Set the colour of a vertex.
Definition: base.hh:60
MinLCAStatus
Possible status for MinLCA solution.
Definition: base.hh:20
Base class for greedy algorithms.
Definition: greedy.hh:23
const Graph & _g
A const reference to the graph we want to arrange.
Definition: base.hh:36
int _k
Largest index of the colours used.
Definition: base.hh:37
virtual void paintVertex(const Node &v)
Assign a colour to a vertex using a greedy approach.
Definition: greedy-lp.hh:53
Colouring _c
The vertex colouring.
Definition: base.hh:40
Default namespace Default namespace for MinLCA algorithms.
Definition: base.hh:15
Class for greedy algorithms using a breadth-first search.
Definition: greedy.hh:52
int _max_k
Maximum number of colours allowed.
Definition: base.hh:38
MinLCAGreedy< Graph > Base
The greedy base class.
Definition: greedy-lp.hh:30
Defines the relaxed linear programming model for MinLCA.
Use the MinLCAGreedyLp with Bfs.
Definition: greedy-lp.hh:85
Use the relaxed linear model as a base for colour preferences.
Definition: greedy-lp.hh:23
double solve()
Solve the linear model.
Definition: lp-model.hh:118
MinLCAGreedyLp(const Graph &g, int maxK=0)
Constructor.
Definition: greedy-lp.hh:43
MinLCALpModel< Graph > model
Relaxed linear model for the graph.
Definition: greedy-lp.hh:37
int maxK()
Maximum number of allowed colours.
Definition: base.hh:205
std::vector< int > getColourOrder(const Node &v)
Get the colour preference induced by the solution.
Definition: lp-model.hh:137
long long _lca
Cost of the current solution.
Definition: base.hh:39
MinLCAGreedyLpBfs(const Graph &g, int maxK=0)
Constructor.
Definition: greedy-lp.hh:95