1 #ifndef __MINLCA_MINLCA_GREEDY_RANDOM_HH
2 #define __MINLCA_MINLCA_GREEDY_RANDOM_HH
5 #include <lemon/random.h>
19 template<
typename Graph = lemon::SmartGraph>
36 TEMPLATE_GRAPH_TYPEDEFS(Graph);
42 template<
typename Number =
unsigned long long>
57 std::vector<int> colours(
_max_k, 0);
59 for (IncEdgeIt e(
_g, v); e != lemon::INVALID; ++e) {
60 Node n =
_g.oppositeNode(v, e);
64 colours[nColour] = -1;
66 if (nColour - 1 >= 0 and colours[nColour - 1] != -1) {
67 ++colours[nColour - 1];
70 if (nColour + 1 <
_max_k and colours[nColour + 1] != -1) {
71 ++colours[nColour + 1];
77 colours[vColour] = -1;
81 if (nonNeg.size() > 0 and _r.boolean(_p)) {
82 vColour = nonNeg[_r.integer(0, static_cast<int>(nonNeg.size()))];
98 template<
typename Number>
108 template<
typename Graph>
109 #ifndef USING_NOT_AVAILABLE
118 template<
typename Number =
unsigned long long>
std::vector< int > nonNegative(const std::vector< int > &v)
Vector of non-negative indices.
MinLCAGreedyNearestRnd(const Graph &g, int maxK=0, double p=0.0, Number seed=0ULL)
Constructor.
MinLCAGreedyBfs< MinLCAGreedyNearestRnd, Graph > MinLCAGreedyNearestRndBfs
Class defined to ease the use of MinLCAGreedyNearestRnd with Bfs.
void p(double p)
Change the probability of choosing a random colour.
virtual void setColour(const Node &v, int vColour)
Set the colour of a vertex.
double _p
Probability of choosing a random colour.
Base class for greedy algorithms.
const Graph & _g
A const reference to the graph we want to arrange.
int _k
Largest index of the colours used.
lemon::Random _r
Random number generator.
Colouring _c
The vertex colouring.
Default namespace Default namespace for MinLCA algorithms.
Class for greedy algorithms using a breadth-first search.
int _max_k
Maximum number of colours allowed.
void seed(Number seed)
Change the seed for the internal random number generator.
int posMax(const std::vector< T > &v)
Index of the maximum position.
int maxK()
Maximum number of allowed colours.
long long _lca
Cost of the current solution.
Randomised greedy nearest colour approach for MinLCA.
virtual void paintVertex(const Node &v)
Assign a colour to a vertex using a greedy approach.