Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 627e879

Browse files
committed
Update scoring function and add strategy class for partial legal colorings
1 parent 18c72e5 commit 627e879

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

‎framework/colouring/graph_colouring.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ namespace graph_colouring {
4747
return color_count;
4848
}
4949

50+
int64_t squaredColorClassSizes(const Colouring &s) {
51+
ColorCount numColors = colorCount(s);
52+
std::vector<int64_t> colorClassSizes(numColors);
53+
for (auto n : s) {
54+
colorClassSizes[n]++;
55+
}
56+
return -1 * std::accumulate(colorClassSizes.begin(), colorClassSizes.end(), 0, [&] (int64_t a, int64_t b) {return a + b * b;});
57+
}
58+
5059
bool allowedInClass(const graph_access &G,
5160
const Colouring &c,
5261
const Color color,
@@ -86,6 +95,16 @@ namespace graph_colouring {
8695
return count / 2;
8796
}
8897

98+
size_t sumUncoloredDegree(const graph_access &G, const Colouring &s) {
99+
ColorCount degree_count = 0;
100+
for (NodeID id = 0; id < G.number_of_nodes(); ++id) {
101+
if (s[id] == UNCOLORED) {
102+
degree_count += G.getNodeDegree(id);
103+
}
104+
}
105+
return degree_count;
106+
}
107+
89108
inline size_t chooseParent(const size_t strategyId,
90109
const size_t populationSize,
91110
std::vector<std::atomic<bool>> &lock,

‎framework/colouring/graph_colouring.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <thread>
1010
#include <boost/lockfree/queue.hpp>
11+
#include <cstdint>
1112

1213
template<typename T>
1314
std::ostream &operator<<(std::ostream &strm, const std::set<T> &set) {
@@ -77,6 +78,12 @@ namespace graph_colouring {
7778
*/
7879
ColorCount colorCount(const Colouring &s);
7980

81+
/**
82+
* @param s a graph colouring
83+
* @return the sum of squared color class sizes used in the configuration times -1 \s
84+
*/
85+
int64_t squaredColorClassSizes(const Colouring &s);
86+
8087
/**
8188
* @param G the target graph
8289
* @param s the colouring of graph \p G
@@ -107,6 +114,15 @@ namespace graph_colouring {
107114
size_t numberOfConflictingEdges(const graph_access &G,
108115
const Colouring &s);
109116

117+
/**
118+
*
119+
* @param G the target graph
120+
* @param s the colouring of graph \p G
121+
* @return the sum of the degrees of the vertices that are uncolored
122+
*/
123+
size_t sumUncoloredDegree(const graph_access &G,
124+
const Colouring &s);
125+
110126
/**
111127
* @param s a colouring
112128
* @return the number of nodes thate have no associated color
@@ -209,6 +225,23 @@ namespace graph_colouring {
209225
}
210226
};
211227

228+
/**
229+
* This strategy is supposed for operator families which can handle invalid colourings
230+
*/
231+
class FixedKPartialColouringStrategy : public ColouringStrategy {
232+
public:
233+
bool compare(const graph_access &G,
234+
const Colouring &a,
235+
const Colouring &b) const override {
236+
return sumUncoloredDegree(G, a) >
237+
sumUncoloredDegree(G, b);
238+
}
239+
240+
bool isFixedKStrategy() const override {
241+
return true;
242+
}
243+
};
244+
212245
/**
213246
* This strategy is supposed for operator families which can handle valid colourings
214247
*/
@@ -217,8 +250,8 @@ namespace graph_colouring {
217250
bool compare(const graph_access &G,
218251
const Colouring &a,
219252
const Colouring &b) const override {
220-
return colorCount(a) >
221-
colorCount(b);
253+
return squaredColorClassSizes(a) >
254+
squaredColorClassSizes(b);
222255
}
223256

224257
bool isFixedKStrategy() const override {
@@ -262,4 +295,4 @@ namespace graph_colouring {
262295
};
263296

264297

265-
}
298+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /