@@ -19,7 +19,7 @@ namespace graph_colouring {
19
19
/* *< The used colouring strategy */
20
20
size_t strategyId;
21
21
/* *< The number of colors used for the colouring strategy */
22
- size_t target_k;
22
+ ColorCount target_k;
23
23
/* *< The index of the first colouring */
24
24
size_t colouring;
25
25
};
@@ -29,7 +29,7 @@ namespace graph_colouring {
29
29
*/
30
30
struct MasterPackage {
31
31
/* *< The next k to be searched */
32
- size_t next_k;
32
+ ColorCount next_k;
33
33
};
34
34
35
35
/* *
@@ -40,9 +40,9 @@ namespace graph_colouring {
40
40
std::atomic<size_t > wpCount;
41
41
};
42
42
43
- size_t colorCount (const Colouring &s) {
43
+ ColorCount colorCount (const Colouring &s) {
44
44
std::vector<bool > usedColor (s.size ());
45
- size_t color_count = 0 ;
45
+ ColorCount color_count = 0 ;
46
46
for (auto n : s) {
47
47
if (n != UNCOLORED && !usedColor[n]) {
48
48
usedColor[n] = true ;
@@ -105,6 +105,15 @@ namespace graph_colouring {
105
105
return nextTry;
106
106
}
107
107
108
+ inline bool hasFinished (const std::vector<ColouringStrategyContext> &context) {
109
+ for (auto &c : context) {
110
+ if (c.wpCount > 0 ) {
111
+ return false ;
112
+ }
113
+ }
114
+ return true ;
115
+ }
116
+
108
117
static void workerThread (const std::vector<std::shared_ptr<ColouringStrategy>> &strategies,
109
118
const graph_access &G,
110
119
const size_t populationSize,
@@ -115,7 +124,7 @@ namespace graph_colouring {
115
124
boost::lockfree::queue<MasterPackage> &masterQueue,
116
125
std::vector<Colouring> &population,
117
126
std::vector<std::atomic<bool >> &lock,
118
- std::atomic<size_t > &target_k,
127
+ std::atomic<ColorCount > &target_k,
119
128
std::atomic<bool > &terminated) {
120
129
typedef std::mt19937::result_type seed_type;
121
130
typename std::chrono::system_clock seed_clock;
@@ -125,7 +134,7 @@ namespace graph_colouring {
125
134
std::mt19937 generator (init_seed);
126
135
127
136
// Only used to avoid rapid reporting of already known colourings
128
- size_t last_reported_k = target_k + 1 ;
137
+ ColorCount last_reported_k = target_k + 1 ;
129
138
130
139
WorkingPackage wp = {0 , 0 , 0 , 0 };
131
140
while (!terminated) {
@@ -157,7 +166,7 @@ namespace graph_colouring {
157
166
auto lsOp = strategies[wp.strategyId ]->lsOperators [
158
167
lsOprDist (generator)];
159
168
160
- result = lsOp (G, crossoverOp (G, *parents[0 ], *parents[1 ]) );
169
+ result = lsOp (crossoverOp (*parents[0 ], *parents[1 ], G), G );
161
170
*parents[weakerParent] = result;
162
171
163
172
lock[p1] = false ;
@@ -175,7 +184,7 @@ namespace graph_colouring {
175
184
auto initOpr = strategy.initOperators [initOprDist (generator)];
176
185
auto lsOpr = strategy.lsOperators [lsOprDist (generator)];
177
186
178
- result = lsOpr (G, initOpr (G, wp.target_k ));
187
+ result = lsOpr (initOpr (G, wp.target_k ), G );
179
188
population[wp.strategyId * populationSize + wp.colouring ] = result;
180
189
181
190
lock[wp.strategyId * populationSize + wp.colouring ] = false ;
@@ -196,19 +205,10 @@ namespace graph_colouring {
196
205
}
197
206
}
198
207
199
- bool hasFinished (const std::vector<ColouringStrategyContext> &context) {
200
- for (auto &c : context) {
201
- if (c.wpCount > 0 ) {
202
- return false ;
203
- }
204
- }
205
- return true ;
206
- }
207
-
208
208
std::vector<ColouringResult>
209
209
ColouringAlgorithm::perform (const std::vector<std::shared_ptr<ColouringStrategy>> &strategies,
210
210
const graph_access &G,
211
- const size_t k,
211
+ const ColorCount k,
212
212
const size_t populationSize,
213
213
const size_t maxItr,
214
214
const size_t threadCount) {
@@ -228,7 +228,7 @@ namespace graph_colouring {
228
228
std::vector<ColouringStrategyContext> context (strategies.size ());
229
229
230
230
// Represents the smallest number of colors used in a recently found colouring
231
- std::atomic<size_t > target_k (k);
231
+ std::atomic<ColorCount > target_k (k);
232
232
boost::lockfree::queue<WorkingPackage> workQueue (populationSize * strategies.size ());
233
233
234
234
// It is possible that all threads report the same found k colouring
0 commit comments