Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cpp/rcspp/algorithm/greedy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ class GreedyAlgorithm : public Algorithm<ResourceType, LabelContainerType> {
// Note: do NOT keep a reference to path_.back() across pop_back() calls
// (that'd be a dangling reference). Re-query path_.back() each loop.
// try to extend the label greedily
//
// The sibling-switching backtrack below can enumerate many partial
// paths inside this single call, so poll should_stop() and the
// memory limit every 4096 steps.
size_t steps = 0;
while (!path_.empty()) {
if ((++steps & 0xFFFU) == 0 &&
(this->should_stop() || this->memory_limit_.is_exceeded())) {
return;
}
Comment on lines +97 to +102
bool extended = false;
while (extend_label(path_.back().first)) {
extended = true; // successfully extended
Expand Down
9 changes: 9 additions & 0 deletions cpp/rcspp/algorithm/improving_tabu_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,16 @@ class ImprovingTabuSearch : public BacktrackingDiveAlgorithm<ResourceType, Label
private:
// ─── helpers ─────────────────────────────────────────────────────────
bool dive_to_sink() {
// A single dive can enumerate exponentially many partial paths
// between main_loop()'s per-iteration checks — and each extension
// allocates a label — so poll should_stop() and the memory limit
// every 4096 steps.
size_t steps = 0;
while (!this->path_.empty()) {
if ((++steps & 0xFFFU) == 0 &&
(this->should_stop() || this->memory_limit_.is_exceeded())) {
return false;
}
Comment on lines +220 to +225
auto* current = this->path_.back().first;
if (current->get_end_node()->sink) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion cpp/rcspp/algorithm/pulling_dominance_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PullingDominanceAlgorithm : public DominanceAlgorithm<ResourceType, LabelC

void main_loop() override { // NOLINT
size_t i = 0;
while (number_of_labels() > 0 && i < this->params_.max_iterations) {
while (number_of_labels() > 0 && !this->should_stop(i)) {
// Periodic memory check (pulling: each iteration processes one node).
if (i > 0 && this->memory_limit_.effective_limit > 0 &&
i % this->params_.memory_check_interval == 0) {
Expand Down
9 changes: 9 additions & 0 deletions cpp/rcspp/algorithm/tabu_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ class TabuSearchAlgorithm : public BacktrackingDiveAlgorithm<ResourceType, Label
// ------------------------------------------------------------------

bool dive_to_sink() {
// A single dive can enumerate exponentially many partial paths
// between main_loop()'s per-iteration checks — and each extension
// allocates a label — so poll should_stop() and the memory limit
// every 4096 steps.
size_t steps = 0;
while (!this->path_.empty()) {
if ((++steps & 0xFFFU) == 0 &&
(this->should_stop() || this->memory_limit_.is_exceeded())) {
return false;
}
Comment on lines 147 to +151
auto* current = this->path_.back().first;
if (current->get_end_node()->sink) {
return true;
Expand Down
Loading