Skip to content

Commit 6b73f44

Browse files
committed
[CP-SAT] Work on linear1 encodings; more work on lrat; cleanup linear2 code; work on probing
1 parent 8442c7b commit 6b73f44

21 files changed

+1314
-696
lines changed

ortools/linear_solver/proto_solver/sat_proto_solver.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ MPSolutionResponse TimeLimitResponse(SolverLogger& logger) {
160160
MPSolutionResponse SatSolveProto(
161161
LazyMutableCopy<MPModelRequest> request, std::atomic<bool>* interrupt_solve,
162162
std::function<void(const std::string&)> logging_callback,
163-
std::function<void(const MPSolution&)> solution_callback) {
163+
std::function<void(const MPSolution&)> solution_callback,
164+
std::function<void(const double)> best_bound_callback) {
164165
sat::SatParameters params;
165166
params.set_log_search_progress(request->enable_internal_solver_output());
166167

@@ -431,6 +432,9 @@ MPSolutionResponse SatSolveProto(
431432
solution_callback(post_solve(cp_response));
432433
}));
433434
}
435+
if (best_bound_callback != nullptr) {
436+
sat_model.Add(sat::NewBestBoundCallback(best_bound_callback));
437+
}
434438

435439
// Solve.
436440
const sat::CpSolverResponse cp_response =

ortools/linear_solver/proto_solver/sat_proto_solver.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ namespace operations_research {
4949
// found by the solver. The solver may call solution_callback from multiple
5050
// threads, but it will ensure that at most one thread executes
5151
// solution_callback at a time.
52+
//
53+
// The optional best_bound_callback will be called each time the best bound is
54+
// improved. The solver may call solution_callback from multiple
55+
// threads, but it will ensure that at most one thread executes
56+
// solution_callback at a time. It is guaranteed that the best bound is strictly
57+
// improving.
5258
MPSolutionResponse SatSolveProto(
5359
LazyMutableCopy<MPModelRequest> request,
5460
std::atomic<bool>* interrupt_solve = nullptr,
5561
std::function<void(const std::string&)> logging_callback = nullptr,
56-
std::function<void(const MPSolution&)> solution_callback = nullptr);
62+
std::function<void(const MPSolution&)> solution_callback = nullptr,
63+
std::function<void(const double)> best_bound_callback = nullptr);
5764

5865
// Returns a string that describes the version of the CP-SAT solver.
5966
std::string SatSolverVersion();

ortools/sat/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,11 +1470,11 @@ cc_library(
14701470
"//ortools/util:stats",
14711471
"//ortools/util:strong_integers",
14721472
"//ortools/util:time_limit",
1473-
"@abseil-cpp//absl/algorithm:container",
14741473
"@abseil-cpp//absl/base:core_headers",
14751474
"@abseil-cpp//absl/container:btree",
14761475
"@abseil-cpp//absl/container:flat_hash_map",
14771476
"@abseil-cpp//absl/container:flat_hash_set",
1477+
"@abseil-cpp//absl/functional:function_ref",
14781478
"@abseil-cpp//absl/log",
14791479
"@abseil-cpp//absl/log:check",
14801480
"@abseil-cpp//absl/log:vlog_is_on",
@@ -1524,6 +1524,7 @@ cc_library(
15241524
":implied_bounds",
15251525
":integer",
15261526
":integer_base",
1527+
":lrat_proof_handler",
15271528
":model",
15281529
":sat_base",
15291530
":sat_parameters_cc_proto",

ortools/sat/clause.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ void ClauseManager::InternalDetach(SatClause* clause) {
366366
}
367367
if (lrat_proof_handler_ != nullptr) {
368368
const auto it = clause_id_.find(clause);
369-
// TODO(user): why is it necessary to keep binary clauses?
370-
if (it != clause_id_.end() && size != 2) {
369+
if (it != clause_id_.end()) {
371370
lrat_proof_handler_->DeleteClauses({it->second});
372371
clause_id_.erase(it);
373372
}

ortools/sat/clause.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -797,15 +797,6 @@ class BinaryImplicationGraph : public SatPropagator {
797797

798798
void SetDratProofHandler(DratProofHandler* drat_proof_handler);
799799

800-
// Changes the reason of the variable at trail index to a binary reason.
801-
// Note that the implication "new_reason => trail_[trail_index]" should be
802-
// part of the implication graph.
803-
void ChangeReason(int trail_index, Literal new_reason) {
804-
CHECK(trail_->Assignment().LiteralIsTrue(new_reason));
805-
reasons_[trail_index] = new_reason.Negated();
806-
trail_->ChangeReason(trail_index, propagator_id_);
807-
}
808-
809800
// The literals that are "directly" implied when literal is set to true. This
810801
// is not a full "reachability". It includes at most ones propagation. The set
811802
// of all direct implications is enough to describe the implications graph

0 commit comments

Comments
 (0)