Skip to content

Commit

Permalink
[CP-SAT] remove problematic DCHECK; tweak glue-clause-sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Aug 5, 2024
1 parent 3e1ca33 commit 39b07a9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions ortools/sat/cp_model_solver_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ int RegisterClausesLevelZeroImport(int id,
return false;
}
}
clause_stream->RemoveWorstClauses();
return true;
};
model->GetOrCreate<LevelZeroCallbackHelper>()->callbacks.push_back(
Expand Down
3 changes: 2 additions & 1 deletion ortools/sat/feasibility_jump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,8 @@ bool FeasibilityJumpSolver::DoSomeGeneralIterations() {
// Check that the score for undoing the move is -score with both the
// default weights (which may be `state_->weights` or
// `state_->compound_weights`), and with `weights` explicitly.
if (!state_->options.use_decay) {
// TODO(user): Re-enable DCHECK.
if (/* DISABLES CODE */ false && !state_->options.use_decay) {
DCHECK_EQ(-score, ComputeScore(state_->weights, var,
prev_value - new_value, false));
DCHECK_EQ(-score, ComputeScore(ScanWeights(), var,
Expand Down
1 change: 0 additions & 1 deletion ortools/sat/sat_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <limits>
#include <memory>
#include <string>
Expand Down
6 changes: 2 additions & 4 deletions ortools/sat/synchronization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,8 @@ void SharedClausesManager::Synchronize() {
num_buffered_literals <
UniqueClauseStream::kMaxLiteralsPerBatch / num_workers;
const bool overfull =
num_buffered_literals > UniqueClauseStream::kMaxLiteralsPerBatch;
num_buffered_literals >
2 * UniqueClauseStream::kMaxLiteralsPerBatch / num_workers;
const int new_lbd = std::clamp(lbd_threshold + underfull - overfull, 2,
UniqueClauseStream::kMaxClauseSize);
if (new_lbd != lbd_threshold) {
Expand Down Expand Up @@ -1329,9 +1330,6 @@ void SharedClausesManager::Synchronize() {
VLOG(2) << "Batch #" << batches_.size() << " w/ " << batches_.back().size()
<< " clauses max size = "
<< batches_.back()[batches_.back().size() - 1].size();
for (auto& stream : id_to_clause_stream_) {
stream.RemoveWorstClauses();
}
}
// Delete batches that have been consumed by all workers.
// Keep a few batches around for startup (min finished batch doesn't count
Expand Down
10 changes: 6 additions & 4 deletions ortools/sat/synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,10 @@ class UniqueClauseStream {
// Export 4KiB of clauses per batch.
static constexpr int kMaxLiteralsPerBatch = 4096 / sizeof(int);
// Bound the total literals we buffer, approximately enforced so shorter
// clauses can replace longer ones.
static constexpr int kMaxBufferedLiterals = 4 * kMaxLiteralsPerBatch;
// clauses can replace longer ones. This can be larger than
// kMaxLiteralsPerBatch (hence the separate constant), but experiments suggest
// that this doesn't help.
static constexpr int kMaxBufferedLiterals = kMaxLiteralsPerBatch;

UniqueClauseStream();
// Move only - this is an expensive class to copy.
Expand Down Expand Up @@ -637,8 +639,8 @@ class UniqueClauseStream {

// Delete longest clauses while keeping at least kMaxBufferedLiterals.
// This guarantees that CanAccept will return the same result as before, and
// at least the next 4 batches will contain the same clauses, but we will emit
// fewer old, long clauses many batches in the future.
// at least the next batch will contain the same clauses, but we will emit
// fewer old, long clauses in the future.
void RemoveWorstClauses();

int lbd_threshold() const ABSL_LOCKS_EXCLUDED(mutex_) {
Expand Down

0 comments on commit 39b07a9

Please sign in to comment.