Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

NodeColoringWigderson.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/basic.h>
39 
40 #include <cmath>
41 
42 namespace ogdf {
43 template<class E>
44 class List;
45 
54 public:
58  enum class MaxDegreeProcedure {
59  smallestIndex,
60  minDegreeRecursion,
61  maxDegreeRecursion,
62  minDegreeOriginal,
63  maxDegreeOriginal,
64  minDegreeNeighbors,
65  maxDegreeNeighbors,
66  };
67 
72  trivialColoring,
73  sequentialColoringSimple,
74  sequentialColoringDegree,
75  pooled,
76  };
77 
81  enum class BruteForceProcedure {
82  sequentialColoringSimple,
83  sequentialColoringDegree,
84  pooled,
85  };
86 
93  : m_coloringSimple()
94  , m_sequentialColoring()
95  , m_searchProcedure(SearchProcedure::wigdersonSearch)
96  , m_maxDegreeProcedure(MaxDegreeProcedure::smallestIndex)
97  , m_recursionAnchorProcedure(RecursionAnchorProcedure::pooled)
98  , m_bruteForceProcedure(BruteForceProcedure::pooled) { }
99 
105  inline void setSearchProcedure(SearchProcedure searchProcedure) {
106  m_searchProcedure = searchProcedure;
107  }
108 
113  inline void setMaxDegreeProcedure(MaxDegreeProcedure maxDegreeProcedure) {
114  m_maxDegreeProcedure = maxDegreeProcedure;
115  }
116 
121  inline void setRecursionAnchorProcedure(RecursionAnchorProcedure recursionAnchorProcedure) {
122  m_recursionAnchorProcedure = recursionAnchorProcedure;
123  }
124 
129  inline void setBruteForceProcedure(BruteForceProcedure bruteForceProcedure) {
130  m_bruteForceProcedure = bruteForceProcedure;
131  }
132 
133  virtual NodeColor call(const Graph& graph, NodeArray<NodeColor>& colors,
134  NodeColor start = 0) override;
135 
136 private:
139  SearchProcedure m_searchProcedure;
143 
152  inline int wigdersonFunction(int n, int k) const {
153  OGDF_ASSERT(n >= 0);
154  OGDF_ASSERT(k >= 1);
155  return std::ceil(std::pow(n, 1.0 - (1.0 / (static_cast<double>(k) - 1.0))));
156  }
157 
167  bool wigdersonCaller(const Graph& graph, NodeArray<NodeColor>& colors, NodeColor& color, int k);
168 
179  bool wigdersonRecursive(const Graph& graph, NodeArray<NodeColor>& colors, NodeColor& color,
180  int k, NodeArray<int>& degreesOriginal, List<node>& nodesToBeColored);
181 
192  SearchWrapperWigderson(NodeColoringWigderson& coloringWigderson, const Graph& graph,
194  : m_coloring(coloringWigderson), m_graph(graph), m_colors(colors) { }
195 
196  bool step(int k) override {
197  NodeColor start = NodeColor(1);
198  return m_coloring.wigdersonCaller(m_graph, m_colors, start, k);
199  }
200 
202  const Graph& m_graph;
204  };
205 };
206 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::NodeColoringWigderson::m_searchProcedure
SearchProcedure m_searchProcedure
Definition: NodeColoringWigderson.h:139
Graph.h
Includes declaration of graph class.
ogdf::NodeColoringWigderson::RecursionAnchorProcedure
RecursionAnchorProcedure
Declares the procedure dealing with the recursion anchor coloring.
Definition: NodeColoringWigderson.h:71
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::NodeColoringWigderson::setMaxDegreeProcedure
void setMaxDegreeProcedure(MaxDegreeProcedure maxDegreeProcedure)
Sets the procedure of finding maximum degree nodes.
Definition: NodeColoringWigderson.h:113
ogdf::NodeColoringWigderson::setBruteForceProcedure
void setBruteForceProcedure(BruteForceProcedure bruteForceProcedure)
Sets the brute force procedure.
Definition: NodeColoringWigderson.h:129
ogdf::NodeColoringWigderson::MaxDegreeProcedure
MaxDegreeProcedure
Declares procedure to find the maximum degree nodes.
Definition: NodeColoringWigderson.h:58
ogdf::NodeColoringWigderson::SearchWrapperWigderson::m_coloring
NodeColoringWigderson & m_coloring
Definition: NodeColoringWigderson.h:201
ogdf::NodeColoringWigderson
Approximation algorithms for the node coloring problem in graphs.
Definition: NodeColoringWigderson.h:53
ogdf::NodeColoringSimple
Approximation algorithms for the node coloring problem in graphs.
Definition: NodeColoringSimple.h:44
ogdf::colors
const std::array< Color, 63 > colors
An array of 63 different colors to cycle through.
ogdf::NodeColoringWigderson::m_coloringSimple
NodeColoringSimple m_coloringSimple
Definition: NodeColoringWigderson.h:137
ogdf::NodeColoringWigderson::SearchWrapperWigderson::m_colors
NodeArray< NodeColor > & m_colors
Definition: NodeColoringWigderson.h:203
ogdf::NodeColoringWigderson::setSearchProcedure
void setSearchProcedure(SearchProcedure searchProcedure)
Sets the search procedure to find the smallest possible parameter k such as the graph is k-colorable.
Definition: NodeColoringWigderson.h:105
ogdf::NodeColoringModule
Approximation algorithms for the node coloring problem in graphs.
Definition: NodeColoringModule.h:48
ogdf::NodeColoringSequential
Approximation algorithms for the node coloring problem in graphs.
Definition: NodeColoringSequential.h:48
ogdf::NodeColoringWigderson::m_recursionAnchorProcedure
RecursionAnchorProcedure m_recursionAnchorProcedure
Definition: NodeColoringWigderson.h:141
ogdf::NodeColoringWigderson::m_bruteForceProcedure
BruteForceProcedure m_bruteForceProcedure
Definition: NodeColoringWigderson.h:142
ogdf::NodeColoringWigderson::SearchWrapperWigderson::SearchWrapperWigderson
SearchWrapperWigderson(NodeColoringWigderson &coloringWigderson, const Graph &graph, NodeArray< NodeColor > &colors)
Creates the wrapper.
Definition: NodeColoringWigderson.h:192
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
NodeColoringSimple.h
Trivial node coloring which assigns every node a different color.
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
NodeColoringModule.h
Template of base class of node coloring algorithms.
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::NodeColoringWigderson::SearchWrapperWigderson
Wraps the Wigderson recursive algorithm.
Definition: NodeColoringWigderson.h:185
ogdf::NodeColoringModule::NodeColor
unsigned int NodeColor
Data type of the node colors.
Definition: NodeColoringModule.h:53
ogdf::NodeColoringWigderson::SearchWrapperWigderson::step
bool step(int k) override
Performs a step in the search procedure.
Definition: NodeColoringWigderson.h:196
NodeColoringSequential.h
Applies the sequential coloring algorithm to a given graph.
ogdf::NodeColoringWigderson::wigdersonFunction
int wigdersonFunction(int n, int k) const
Calculates the function for the graph maximum degree specified by Wigderson.
Definition: NodeColoringWigderson.h:152
ogdf::NodeColoringWigderson::m_maxDegreeProcedure
MaxDegreeProcedure m_maxDegreeProcedure
Definition: NodeColoringWigderson.h:140
ogdf::NodeColoringWigderson::m_sequentialColoring
NodeColoringSequential m_sequentialColoring
Definition: NodeColoringWigderson.h:138
ogdf::NodeColoringWigderson::BruteForceProcedure
BruteForceProcedure
Declares the procedure dealing with the brute force coloring.
Definition: NodeColoringWigderson.h:81
ogdf::NodeColoringWigderson::SearchWrapperWigderson::m_graph
const Graph & m_graph
Definition: NodeColoringWigderson.h:202
ogdf::NodeColoringWigderson::NodeColoringWigderson
NodeColoringWigderson()
The constructor.
Definition: NodeColoringWigderson.h:92
ogdf::NodeColoringWigderson::setRecursionAnchorProcedure
void setRecursionAnchorProcedure(RecursionAnchorProcedure recursionAnchorProcedure)
Sets the recursion anchor procedure.
Definition: NodeColoringWigderson.h:121
ogdf::NodeColoringModule::SearchWrapper
Wraps the search for the minimum parameter k so that the same code can be reused for all algorithms.
Definition: NodeColoringModule.h:196