equal
deleted
inserted
replaced
260 |
260 |
261 // Reduce deviates greedily, using the "best" selection at each step to reduce the number of deviating tag sets |
261 // Reduce deviates greedily, using the "best" selection at each step to reduce the number of deviating tag sets |
262 while (n_deviates > 0) { |
262 while (n_deviates > 0) { |
263 size_t prev_deviates = n_deviates; |
263 size_t prev_deviates = n_deviates; |
264 int max_score = 0; |
264 int max_score = 0; |
265 const LogSelection* best_selection = NULL; |
265 |
|
266 guarantee(n_selections > 0, "Cannot find maximal selection."); |
|
267 const LogSelection* best_selection = &selections[0]; |
266 for (size_t i = 0; i < n_selections; i++) { |
268 for (size_t i = 0; i < n_selections; i++) { |
267 |
269 |
268 // Give the selection a score based on how many deviating tag sets it selects (with correct level) |
270 // Give the selection a score based on how many deviating tag sets it selects (with correct level) |
269 int score = 0; |
271 int score = 0; |
270 for (size_t d = 0; d < n_deviates; d++) { |
272 for (size_t d = 0; d < n_deviates; d++) { |
285 } |
287 } |
286 } |
288 } |
287 |
289 |
288 // Pick the selection with the best score, or in the case of a tie, the one with fewest tags |
290 // Pick the selection with the best score, or in the case of a tie, the one with fewest tags |
289 if (score > max_score || |
291 if (score > max_score || |
290 (score == max_score && best_selection != NULL && selections[i].ntags() < best_selection->ntags())) { |
292 (score == max_score && selections[i].ntags() < best_selection->ntags())) { |
291 max_score = score; |
293 max_score = score; |
292 best_selection = &selections[i]; |
294 best_selection = &selections[i]; |
293 } |
295 } |
294 } |
296 } |
295 |
297 |
296 assert(best_selection != NULL, "must always find a maximal selection"); |
|
297 add_to_config_string(*best_selection); |
298 add_to_config_string(*best_selection); |
298 |
299 |
299 // Remove all deviates that this selection covered |
300 // Remove all deviates that this selection covered |
300 for (size_t d = 0; d < n_deviates;) { |
301 for (size_t d = 0; d < n_deviates;) { |
301 if (deviates[d]->level_for(this) == best_selection->level() && best_selection->selects(*deviates[d])) { |
302 if (deviates[d]->level_for(this) == best_selection->level() && best_selection->selects(*deviates[d])) { |