Skip to content

Commit

Permalink
Merge branch 'v99bugfix' of github.com:google/or-tools into v99bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Nov 25, 2024
2 parents df28118 + bec5857 commit 52e7341
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/amd64_linux_bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Check mvn
run: mvn --version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/amd64_linux_cmake_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
sudo apt install -y swig
swig -version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Update Path
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/amd64_macos_bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Check mvn
run: mvn --version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/amd64_macos_cmake_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
brew install swig
swig -version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Update Path
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/amd64_windows_bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Check mvn
run: mvn --version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/amd64_windows_cmake_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Install python3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arm64_macos_bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Check mvn
run: mvn --version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arm64_macos_cmake_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
brew install swig
swig -version
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Update Path
Expand Down
1 change: 1 addition & 0 deletions ortools/graph/christofides.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <cstdint>
#include <functional>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions ortools/graph/cliques.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <limits>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

#include "absl/strings/str_cat.h"
Expand Down
1 change: 1 addition & 0 deletions ortools/sat/cp_model_solver_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#include "absl/flags/declare.h"
Expand Down
3 changes: 3 additions & 0 deletions ortools/sat/cuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <limits>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

Expand Down
2 changes: 2 additions & 0 deletions ortools/sat/disjunctive.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <algorithm>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "absl/types/span.h"
Expand Down
1 change: 1 addition & 0 deletions ortools/sat/precedences.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cstdint>
#include <deque>
#include <functional>
#include <memory>
#include <utility>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions ortools/sat/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstdint>
#include <deque>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
Expand Down
14 changes: 7 additions & 7 deletions ortools/sat/work_assignment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ std::optional<ProtoLiteral> ProtoLiteral::EncodeLiteral(
return result;
}

ProtoTrail::ProtoTrail() { target_phase_.reserve(kMaxPhaseSize); }

void ProtoTrail::PushLevel(const ProtoLiteral& decision,
IntegerValue objective_lb, int node_id) {
CHECK_GT(node_id, 0);
Expand Down Expand Up @@ -793,8 +795,8 @@ bool SharedTreeWorker::SyncWithSharedTree() {
if (ShouldReplaceSubtree()) {
++num_trees_;
VLOG(2) << parameters_->name() << " acquiring tree #" << num_trees_
<< " after " << num_restarts_ - tree_assignment_restart_
<< " restarts prev depth: " << assigned_tree_.MaxLevel()
<< " after " << restart_policy_->NumRestarts() << " restarts"
<< " prev depth: " << assigned_tree_.MaxLevel()
<< " target: " << assigned_tree_lbds_.WindowAverage()
<< " lbd: " << restart_policy_->LbdAverageSinceReset();
if (parameters_->shared_tree_worker_enable_phase_sharing() &&
Expand All @@ -806,11 +808,10 @@ bool SharedTreeWorker::SyncWithSharedTree() {
// workers.
auto encoded = ProtoLiteral::EncodeLiteral(lit, mapping_);
if (!encoded.has_value()) continue;
assigned_tree_.SetPhase(*encoded);
if (!assigned_tree_.AddPhase(*encoded)) break;
}
}
manager_->ReplaceTree(assigned_tree_);
tree_assignment_restart_ = num_restarts_;
assigned_tree_lbds_.Add(restart_policy_->LbdAverageSinceReset());
restart_policy_->Reset();
if (parameters_->shared_tree_worker_enable_phase_sharing()) {
Expand Down Expand Up @@ -856,9 +857,8 @@ SatSolver::Status SharedTreeWorker::Search(
return sat_solver_->UnsatStatus();
}
if (heuristics_->restart_policies[heuristics_->policy_index]()) {
++num_restarts_;
heuristics_->policy_index =
num_restarts_ % heuristics_->decision_policies.size();
heuristics_->policy_index = restart_policy_->NumRestarts() %
heuristics_->decision_policies.size();
sat_solver_->Backtrack(0);
}
if (!SyncWithLocalTrail()) return sat_solver_->UnsatStatus();
Expand Down
20 changes: 13 additions & 7 deletions ortools/sat/work_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class ProtoLiteral {
// implications may be propagated.
class ProtoTrail {
public:
ProtoTrail();

// Adds a new assigned level to the trail.
void PushLevel(const ProtoLiteral& decision, IntegerValue objective_lb,
int node_id);
Expand Down Expand Up @@ -147,18 +149,25 @@ class ProtoTrail {

const std::vector<ProtoLiteral>& TargetPhase() const { return target_phase_; }
void ClearTargetPhase() { target_phase_.clear(); }
void SetPhase(const ProtoLiteral& lit) {
if (implication_level_.contains(lit)) return;
target_phase_.push_back(lit);
// Appends a literal to the target phase, returns false if the phase is full.
bool AddPhase(const ProtoLiteral& lit) {
if (target_phase_.size() >= kMaxPhaseSize) return false;
if (!implication_level_.contains(lit)) {
target_phase_.push_back(lit);
}
return true;
}
void SetTargetPhase(absl::Span<const ProtoLiteral> phase) {
ClearTargetPhase();
for (const ProtoLiteral& lit : phase) {
SetPhase(lit);
if (!AddPhase(lit)) break;
}
}

private:
// 256 ProtoLiterals take up 4KiB
static constexpr int kMaxPhaseSize = 256;

std::vector<ProtoLiteral>& MutableImplications(int level) {
return implications_[level - 1];
}
Expand Down Expand Up @@ -335,14 +344,11 @@ class SharedTreeWorker {
LevelZeroCallbackHelper* level_zero_callbacks_;
RevIntRepository* reversible_int_repository_;

int64_t num_restarts_ = 0;
int64_t num_trees_ = 0;

ProtoTrail assigned_tree_;
std::vector<Literal> assigned_tree_literals_;
std::vector<std::vector<Literal>> assigned_tree_implications_;
// How many restarts had happened when the current tree was assigned?
int64_t tree_assignment_restart_ = -1;

// True if the last decision may split the assigned tree and has not yet been
// proposed to the SharedTreeManager.
Expand Down
2 changes: 1 addition & 1 deletion ortools/sat/work_assignment_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ TEST(SharedTreeManagerTest, TrailSharing) {
trail1.AddImplication(1, ProtoLiteral(1, 1));
trail1.AddImplication(1, ProtoLiteral(1, 3));
shared_tree_manager->SyncTree(trail1);
trail1.SetPhase(ProtoLiteral(2, 1));
trail1.AddPhase(ProtoLiteral(2, 1));
shared_tree_manager->ReplaceTree(trail1);
shared_tree_manager->ReplaceTree(trail2);

Expand Down

0 comments on commit 52e7341

Please sign in to comment.