24#include "absl/cleanup/cleanup.h"
25#include "absl/container/btree_map.h"
26#include "absl/container/btree_set.h"
27#include "absl/container/flat_hash_set.h"
28#include "absl/log/check.h"
29#include "absl/log/log.h"
30#include "absl/log/vlog_is_on.h"
31#include "absl/strings/str_cat.h"
32#include "absl/strings/str_format.h"
33#include "absl/types/span.h"
59 std::vector<Literal>* core) {
61 absl::btree_set<LiteralIndex> moved_last;
62 std::vector<Literal> candidate(core->begin(), core->end());
72 if (target_level == -1)
break;
91 moved_last.insert(candidate.back().Index());
95 if (candidate.size() < core->size()) {
96 VLOG(1) <<
"minimization with propag " << core->size() <<
" -> "
100 absl::flat_hash_set<LiteralIndex> set;
101 for (
const Literal l : candidate) set.insert(l.Index());
103 for (
const Literal l : *core) {
104 if (set.contains(l.Index())) {
105 (*core)[new_size++] = l;
108 core->resize(new_size);
113 std::vector<Literal>* core) {
117 if (core->size() > 100 || core->size() == 1)
return;
122 const int old_size = core->size();
123 std::vector<Literal> assumptions;
124 absl::flat_hash_set<LiteralIndex> removed_once;
128 while (core->size() > 1) {
137 for (
int i = core->size(); --
i >= 0;) {
139 const auto [_, inserted] = removed_once.insert(l.
Index());
145 if (to_remove == -1)
break;
148 for (
int i = 0;
i < core->size(); ++
i) {
149 if (
i == to_remove)
continue;
150 assumptions.push_back((*core)[
i]);
160 if (core->size() < old_size) {
161 VLOG(1) <<
"minimization with search " << old_size <<
" -> "
180 {assumption}, 1'000);
198 std::vector<Literal>* core) {
200 for (
const Literal lit : *core) {
207 (*core)[new_size++] = lit;
209 core->resize(new_size);
213 IntegerVariable objective_var,
214 const std::function<
void()>& feasible_solution_observer,
Model* model) {
229 if (debug_sol && integer_trail->LowerBound(objective_var) <=
239 const IntegerValue objective = integer_trail->LowerBound(objective_var);
242 if (feasible_solution_observer !=
nullptr) {
243 feasible_solution_observer();
245 if (parameters.stop_after_first_solution()) {
251 if (!integer_trail->Enqueue(
260 IntegerVariable objective_var,
261 const std::function<
void()>& feasible_solution_observer,
Model* model) {
278 IntegerValue unknown_min = integer_trail->UpperBound(objective_var);
279 IntegerValue unknown_max = integer_trail->LowerBound(objective_var);
281 sat_solver->Backtrack(0);
282 const IntegerValue lb = integer_trail->LowerBound(objective_var);
283 const IntegerValue ub = integer_trail->UpperBound(objective_var);
284 unknown_min = std::min(unknown_min, ub);
285 unknown_max = std::max(unknown_max, lb);
289 if (lb < unknown_min) {
290 target = lb + (unknown_min - lb) / 2;
291 }
else if (unknown_max < ub) {
292 target = ub - (ub - unknown_max) / 2;
294 VLOG(1) <<
"Binary-search, done.";
297 VLOG(1) <<
"Binary-search, objective: [" << lb <<
"," << ub <<
"]"
298 <<
" tried: [" << unknown_min <<
"," << unknown_max <<
"]"
299 <<
" target: obj<=" << target;
302 const Literal assumption = integer_encoder->GetOrCreateAssociatedLiteral(
316 sat_solver->Backtrack(0);
317 if (!integer_trail->Enqueue(
326 const IntegerValue objective = integer_trail->LowerBound(objective_var);
327 if (feasible_solution_observer !=
nullptr) {
328 feasible_solution_observer();
333 sat_solver->Backtrack(0);
334 if (!integer_trail->Enqueue(
342 unknown_min = std::min(target, unknown_min);
343 unknown_max = std::max(target, unknown_max);
349 sat_solver->Backtrack(0);
377 std::vector<IntegerValue> assumption_weights,
378 IntegerValue stratified_threshold,
Model* model,
379 std::vector<std::vector<Literal>>* cores) {
381 SatSolver* sat_solver = model->GetOrCreate<SatSolver>();
389 std::vector<Literal> core = sat_solver->GetLastIncompatibleDecisions();
390 if (sat_solver->parameters().core_minimization_level() > 0) {
393 if (core.size() == 1) {
394 if (!sat_solver->AddUnitClause(core[0].Negated())) {
398 if (core.empty())
return sat_solver->UnsatStatus();
399 cores->push_back(core);
400 if (!sat_solver->parameters().find_multiple_cores())
break;
404 std::vector<int> indices;
406 absl::btree_set<Literal> temp(core.begin(), core.end());
407 for (
int i = 0;
i < assumptions.size(); ++
i) {
408 if (temp.contains(assumptions[
i])) {
409 indices.push_back(
i);
419 IntegerValue min_weight = assumption_weights[indices.front()];
420 for (
const int i : indices) {
421 min_weight = std::min(min_weight, assumption_weights[
i]);
423 for (
const int i : indices) {
424 assumption_weights[
i] -= min_weight;
430 for (
int i = 0;
i < assumptions.size(); ++
i) {
431 if (assumption_weights[
i] < stratified_threshold)
continue;
432 assumptions[new_size] = assumptions[
i];
433 assumption_weights[new_size] = assumption_weights[
i];
436 assumptions.resize(new_size);
437 assumption_weights.resize(new_size);
438 }
while (!assumptions.empty());
445 IntegerVariable objective_var, absl::Span<const IntegerVariable> variables,
446 absl::Span<const IntegerValue> coefficients,
447 std::function<
void()> feasible_solution_observer,
Model* model)
449 sat_solver_(model->GetOrCreate<
SatSolver>()),
451 time_limit_(model->GetOrCreate<
TimeLimit>()),
456 objective_var_(objective_var),
457 feasible_solution_observer_(
std::move(feasible_solution_observer)) {
458 CHECK_EQ(variables.size(), coefficients.size());
459 for (
int i = 0;
i < variables.size(); ++
i) {
460 if (coefficients[
i] > 0) {
461 terms_.push_back({variables[
i], coefficients[
i]});
462 }
else if (coefficients[
i] < 0) {
463 terms_.push_back({
NegationOf(variables[
i]), -coefficients[
i]});
467 terms_.back().depth = 0;
473 stratification_threshold_ = parameters_->max_sat_stratification() ==
479bool CoreBasedOptimizer::ProcessSolution() {
482 IntegerValue objective(0);
483 for (ObjectiveTerm& term : terms_) {
484 const IntegerValue value = integer_trail_->
LowerBound(term.var);
485 objective += term.weight * value;
489 term.cover_ub = std::min(term.cover_ub, value);
499 if (feasible_solution_observer_ !=
nullptr) {
500 feasible_solution_observer_();
502 if (parameters_->stop_after_first_solution()) {
508 sat_solver_->Backtrack(0);
509 sat_solver_->SetAssumptionLevel(0);
510 return integer_trail_->Enqueue(
514bool CoreBasedOptimizer::PropagateObjectiveBounds() {
516 bool some_bound_were_tightened =
true;
517 while (some_bound_were_tightened) {
518 some_bound_were_tightened =
false;
519 if (!sat_solver_->ResetToLevelZero())
return false;
520 if (time_limit_->LimitReached())
return true;
523 IntegerValue implied_objective_lb(0);
524 for (ObjectiveTerm& term : terms_) {
525 const IntegerValue var_lb = integer_trail_->LowerBound(term.var);
526 term.old_var_lb = var_lb;
527 implied_objective_lb += term.weight * var_lb.value();
531 if (implied_objective_lb > integer_trail_->LowerBound(objective_var_)) {
533 objective_var_, implied_objective_lb),
538 some_bound_were_tightened =
true;
547 const IntegerValue gap =
548 integer_trail_->UpperBound(objective_var_) - implied_objective_lb;
550 for (
const ObjectiveTerm& term : terms_) {
551 if (term.weight == 0)
continue;
552 const IntegerValue var_lb = integer_trail_->LowerBound(term.var);
553 const IntegerValue var_ub = integer_trail_->UpperBound(term.var);
554 if (var_lb == var_ub)
continue;
561 if (gap / term.weight < var_ub - var_lb) {
562 some_bound_were_tightened =
true;
563 const IntegerValue new_ub = var_lb + gap / term.weight;
564 DCHECK_LT(new_ub, var_ub);
565 if (!integer_trail_->Enqueue(
584void CoreBasedOptimizer::ComputeNextStratificationThreshold() {
585 std::vector<IntegerValue> weights;
586 for (ObjectiveTerm& term : terms_) {
587 if (term.weight >= stratification_threshold_)
continue;
588 if (term.weight == 0)
continue;
590 const IntegerValue var_lb = integer_trail_->LevelZeroLowerBound(term.var);
591 const IntegerValue var_ub = integer_trail_->LevelZeroUpperBound(term.var);
592 if (var_lb == var_ub)
continue;
594 weights.push_back(term.weight);
596 if (weights.empty()) {
597 stratification_threshold_ = IntegerValue(0);
602 stratification_threshold_ =
603 weights[
static_cast<int>(std::floor(0.9 * weights.size()))];
606bool CoreBasedOptimizer::CoverOptimization() {
607 if (!sat_solver_->ResetToLevelZero())
return false;
611 constexpr double max_dtime_per_core = 0.5;
612 const double old_time_limit = parameters_->max_deterministic_time();
613 parameters_->set_max_deterministic_time(max_dtime_per_core);
614 auto cleanup = ::absl::MakeCleanup([old_time_limit,
this]() {
615 parameters_->set_max_deterministic_time(old_time_limit);
618 for (
const ObjectiveTerm& term : terms_) {
622 if (term.depth == 0)
continue;
628 const IntegerVariable var = term.var;
630 std::min(term.cover_ub, integer_trail_->UpperBound(var));
635 if (best <= integer_trail_->
LowerBound(var))
continue;
639 const double deterministic_limit =
640 time_limit_->GetElapsedDeterministicTime() + max_dtime_per_core;
644 while (best > integer_trail_->LowerBound(var)) {
645 const Literal assumption = integer_encoder_->GetOrCreateAssociatedLiteral(
650 best = integer_trail_->LowerBound(var);
651 VLOG(1) <<
"cover_opt var:" << var <<
" domain:["
652 << integer_trail_->LevelZeroLowerBound(var) <<
"," << best <<
"]";
653 if (!ProcessSolution())
return false;
654 if (!sat_solver_->ResetToLevelZero())
return false;
656 time_limit_->GetElapsedDeterministicTime() > deterministic_limit) {
662 if (!sat_solver_->ResetToLevelZero())
return false;
674 return PropagateObjectiveBounds();
678 absl::Span<const Literal> literals, absl::Span<const IntegerVariable> vars,
679 absl::Span<const Coefficient> coefficients, Coefficient offset) {
693 for (
int i = 0;
i < literals.size(); ++
i) {
694 CHECK_GT(coefficients[
i], 0);
700 CHECK_EQ(vars.size(), coefficients.size());
701 for (
int i = 0;
i < vars.size(); ++
i) {
702 CHECK_GT(coefficients[
i], 0);
703 const IntegerVariable var = vars[
i];
704 const IntegerValue var_lb = integer_trail_->LowerBound(var);
705 const IntegerValue var_ub = integer_trail_->UpperBound(var);
706 if (var_ub - var_lb == 1) {
707 const Literal lit = integer_encoder_->GetOrCreateAssociatedLiteral(
715 const int ub =
static_cast<int>(var_ub.value() - var_lb.value());
718 [var, var_lb,
this](
int x) {
719 return integer_encoder_->GetOrCreateAssociatedLiteral(
721 var_lb + IntegerValue(x + 1)));
730 Coefficient lower_bound(0);
733 Coefficient stratified_lower_bound(0);
734 if (parameters_->max_sat_stratification() !=
737 stratified_lower_bound = std::max(stratified_lower_bound, n->weight());
743 std::string previous_core_info =
"";
744 for (
int iter = 0;;) {
751 const Coefficient upper_bound(
752 integer_trail_->UpperBound(objective_var_).value() - offset.value());
755 const IntegerValue new_obj_lb(lower_bound.value() + offset.value());
756 if (new_obj_lb > integer_trail_->LowerBound(objective_var_)) {
757 if (!integer_trail_->Enqueue(
766 const int num_bools = sat_solver_->NumVariables();
767 const int num_fixed = sat_solver_->NumFixedVariables();
769 absl::StrFormat(
"bool_%s (num_cores=%d [%s] a=%u d=%d "
770 "fixed=%d/%d clauses=%s)",
771 model_->Name(), iter, previous_core_info,
772 encoder.
nodes().size(), max_depth, num_fixed,
774 new_obj_lb, integer_trail_->LevelZeroUpperBound(objective_var_));
777 if (parameters_->cover_optimization() && encoder.
nodes().size() > 1) {
778 const Literal last_assumption =
783 if (sat_solver_->Assignment().LiteralIsAssigned(last_assumption)) {
784 previous_core_info =
"cover";
792 const Coefficient gap = upper_bound - lower_bound;
793 if (stratified_lower_bound > (gap + 2) / 2) {
794 stratified_lower_bound = (gap + 2) / 2;
796 std::vector<Literal> assumptions;
800 if (!assumptions.empty())
break;
802 stratified_lower_bound =
804 if (stratified_lower_bound > 0)
continue;
810 VLOG(2) <<
"[Core] #nodes " << encoder.
nodes().size()
811 <<
" #assumptions:" << assumptions.size()
812 <<
" stratification:" << stratified_lower_bound <<
" gap:" << gap;
831 stratified_lower_bound =
833 if (stratified_lower_bound > 0)
continue;
839 std::vector<Literal> core = sat_solver_->GetLastIncompatibleDecisions();
840 if (parameters_->core_minimization_level() > 0) {
843 if (parameters_->core_minimization_level() > 1) {
854 absl::StrFormat(
"size:%u mw:%d", core.size(), min_weight.value());
858 if (!encoder.
ProcessCore(core, min_weight, gap, &previous_core_info)) {
861 max_depth = std::max(max_depth, encoder.
nodes().back()->depth());
868 std::vector<Coefficient>* coefficients,
869 Coefficient* offset) {
871 std::vector<std::pair<LiteralIndex, Coefficient>> pairs;
872 const int size = literals->size();
873 for (
int i = 0;
i < size; ++
i) {
874 pairs.push_back({(*literals)[
i].Index(), (*coefficients)[
i]});
876 std::sort(pairs.begin(), pairs.end());
880 for (
const auto& [index, coeff] : pairs) {
882 if (pairs[new_size - 1].first == index) {
883 pairs[new_size - 1].second += coeff;
885 }
else if (pairs[new_size - 1].first ==
Literal(index).NegatedIndex()) {
887 pairs[new_size - 1].second -= coeff;
892 pairs[new_size++] = {index, coeff};
894 pairs.resize(new_size);
898 coefficients->clear();
899 for (
const auto& [index, coeff] : pairs) {
901 literals->push_back(
Literal(index));
902 coefficients->push_back(coeff);
903 }
else if (coeff < 0) {
906 literals->push_back(
Literal(index).Negated());
907 coefficients->push_back(-coeff);
912void CoreBasedOptimizer::PresolveObjectiveWithAtMostOne(
913 std::vector<Literal>* literals, std::vector<Coefficient>* coefficients,
914 Coefficient* offset) {
932 std::vector<Literal> candidates;
933 const int num_terms = literals->size();
934 for (
int i = 0;
i < num_terms; ++
i) {
935 const Literal lit = (*literals)[
i];
936 const Coefficient coeff = (*coefficients)[
i];
941 weights[lit] = coeff;
943 candidates.push_back(lit.Negated());
944 is_candidate[lit.NegatedIndex()] =
true;
947 int num_at_most_ones = 0;
948 Coefficient overall_lb_increase(0);
950 std::vector<Literal> at_most_one;
951 std::vector<std::pair<Literal, Coefficient>> new_obj_terms;
953 for (
const Literal root : candidates) {
954 if (weights[root.NegatedIndex()] == 0)
continue;
955 if (implications_->
WorkDone() > 1e8)
continue;
958 CHECK_EQ(weights[root], 0);
964 {root}, is_candidate, preferences);
965 if (at_most_one.size() <= 1)
continue;
973 for (
const Literal lit : at_most_one) {
974 const Coefficient coeff = weights[lit.NegatedIndex()];
975 lb_increase += coeff;
976 max_coeff = std::max(max_coeff, coeff);
978 lb_increase -= max_coeff;
980 *offset += lb_increase;
981 overall_lb_increase += lb_increase;
983 for (
const Literal lit : at_most_one) {
984 is_candidate[lit] =
false;
985 const Coefficient new_weight = max_coeff - weights[lit.NegatedIndex()];
986 CHECK_EQ(weights[lit], 0);
987 weights[lit] = new_weight;
988 weights[lit.NegatedIndex()] = 0;
989 if (new_weight > 0) {
993 is_candidate[lit.NegatedIndex()] =
true;
998 const Literal new_lit(sat_solver_->NewBooleanVariable(),
true);
999 new_obj_terms.push_back({new_lit, max_coeff});
1002 at_most_one.push_back(new_lit);
1003 sat_solver_->AddProblemClause(at_most_one);
1004 is_candidate.resize(implications_->literal_size(),
false);
1005 preferences.
resize(implications_->literal_size(), 1.0);
1008 if (overall_lb_increase > 0) {
1010 model_->GetOrCreate<SharedResponseManager>()->UpdateInnerObjectiveBounds(
1011 absl::StrFormat(
"am1_presolve (num_literals=%d num_am1=%d "
1012 "increase=%lld work_done=%lld)",
1013 (
int)candidates.size(), num_at_most_ones,
1014 overall_lb_increase.value(), implications_->WorkDone()),
1015 IntegerValue(offset->value()),
1016 integer_trail_->LevelZeroUpperBound(objective_var_));
1021 coefficients->clear();
1022 for (
const Literal root : candidates) {
1023 if (weights[root] > 0) {
1024 CHECK_EQ(weights[root.NegatedIndex()], 0);
1025 literals->push_back(root);
1026 coefficients->push_back(weights[root]);
1028 if (weights[root.NegatedIndex()] > 0) {
1029 CHECK_EQ(weights[root], 0);
1030 literals->push_back(root.Negated());
1031 coefficients->push_back(weights[root.NegatedIndex()]);
1034 for (
const auto& [lit, coeff] : new_obj_terms) {
1035 literals->push_back(lit);
1036 coefficients->push_back(coeff);
1045 if (!parameters_->interleave_search()) {
1046 Coefficient offset(0);
1047 std::vector<Literal> literals;
1048 std::vector<IntegerVariable> vars;
1049 std::vector<Coefficient> coefficients;
1050 bool all_booleans =
true;
1051 IntegerValue range(0);
1052 for (
const ObjectiveTerm& term : terms_) {
1053 const IntegerVariable var = term.var;
1054 const IntegerValue coeff = term.weight;
1055 const IntegerValue lb = integer_trail_->LowerBound(var);
1056 const IntegerValue ub = integer_trail_->UpperBound(var);
1057 offset += Coefficient((lb * coeff).value());
1058 if (lb == ub)
continue;
1060 vars.push_back(var);
1061 coefficients.push_back(Coefficient(coeff.value()));
1063 literals.push_back(integer_encoder_->GetOrCreateAssociatedLiteral(
1066 all_booleans =
false;
1085 PresolveObjectiveWithAtMostOne(&literals, &coefficients, &offset);
1097 absl::btree_map<LiteralIndex, int> literal_to_term_index;
1111 if (parameters_->cover_optimization()) {
1117 std::vector<int> term_indices;
1118 std::vector<IntegerLiteral> integer_assumptions;
1119 std::vector<IntegerValue> assumption_weights;
1120 IntegerValue objective_offset(0);
1121 bool some_assumptions_were_skipped =
false;
1122 for (
int i = 0;
i < terms_.size(); ++
i) {
1123 const ObjectiveTerm term = terms_[
i];
1126 if (term.weight == 0)
continue;
1132 const IntegerValue var_lb = integer_trail_->LowerBound(term.var);
1133 const IntegerValue var_ub = integer_trail_->UpperBound(term.var);
1134 if (var_lb == var_ub) {
1135 objective_offset += term.weight * var_lb.value();
1140 if (term.weight >= stratification_threshold_) {
1141 integer_assumptions.push_back(
1143 assumption_weights.push_back(term.weight);
1144 term_indices.push_back(
i);
1146 some_assumptions_were_skipped =
true;
1151 if (term_indices.empty() && some_assumptions_were_skipped) {
1152 ComputeNextStratificationThreshold();
1157 if (term_indices.size() <= 2 && !some_assumptions_were_skipped) {
1158 VLOG(1) <<
"Switching to linear scan...";
1159 if (!already_switched_to_linear_scan_) {
1160 already_switched_to_linear_scan_ =
true;
1161 std::vector<IntegerVariable> constraint_vars;
1162 std::vector<int64_t> constraint_coeffs;
1163 for (
const int index : term_indices) {
1164 constraint_vars.push_back(terms_[index].var);
1165 constraint_coeffs.push_back(terms_[index].weight.value());
1167 constraint_vars.push_back(objective_var_);
1168 constraint_coeffs.push_back(-1);
1170 -objective_offset.value()));
1174 objective_var_, feasible_solution_observer_, model_);
1178 if (VLOG_IS_ON(1)) {
1180 for (
const ObjectiveTerm& term : terms_) {
1181 max_depth = std::max(max_depth, term.depth);
1183 const int64_t lb = integer_trail_->LowerBound(objective_var_).value();
1184 const int64_t ub = integer_trail_->UpperBound(objective_var_).value();
1188 :
static_cast<int>(std::ceil(
1189 100.0 * (ub - lb) / std::max(std::abs(ub), std::abs(lb))));
1190 VLOG(1) << absl::StrCat(
"unscaled_next_obj_range:[", lb,
",", ub,
1193 gap,
"%",
" assumptions:", term_indices.size(),
1194 " strat:", stratification_threshold_.value(),
1195 " depth:", max_depth,
1196 " bool: ", sat_solver_->NumVariables());
1200 std::vector<Literal> assumptions;
1201 literal_to_term_index.clear();
1202 for (
int i = 0;
i < integer_assumptions.size(); ++
i) {
1203 assumptions.push_back(integer_encoder_->GetOrCreateAssociatedLiteral(
1204 integer_assumptions[
i]));
1212 literal_to_term_index[assumptions.back()] = term_indices[
i];
1220 std::vector<std::vector<Literal>> cores;
1222 FindCores(assumptions, assumption_weights, stratification_threshold_,
1228 if (cores.empty()) {
1229 ComputeNextStratificationThreshold();
1238 for (
const std::vector<Literal>& core : cores) {
1241 if (core.size() == 1) {
1242 if (!sat_solver_->AddUnitClause(core[0].Negated())) {
1251 bool ignore_this_core =
false;
1253 IntegerValue max_weight(0);
1254 IntegerValue new_var_lb(1);
1255 IntegerValue new_var_ub(0);
1257 for (
const Literal lit : core) {
1258 const int index = literal_to_term_index.at(lit.Index());
1262 if (terms_[index].old_var_lb <
1263 integer_trail_->LowerBound(terms_[index].var)) {
1264 ignore_this_core =
true;
1268 const IntegerValue weight = terms_[index].weight;
1269 min_weight = std::min(min_weight, weight);
1270 max_weight = std::max(max_weight, weight);
1271 new_depth = std::max(new_depth, terms_[index].depth + 1);
1272 new_var_lb += integer_trail_->LowerBound(terms_[index].var);
1273 new_var_ub += integer_trail_->UpperBound(terms_[index].var);
1275 if (ignore_this_core)
continue;
1277 VLOG(1) << absl::StrFormat(
1278 "core:%u weight:[%d,%d] domain:[%d,%d] depth:%d", core.size(),
1279 min_weight.value(), max_weight.value(), new_var_lb.value(),
1280 new_var_ub.value(), new_depth);
1284 const IntegerVariable new_var =
1285 integer_trail_->AddIntegerVariable(new_var_lb, new_var_ub);
1286 terms_.push_back({new_var, min_weight, new_depth});
1287 terms_.back().cover_ub = new_var_ub;
1291 std::vector<IntegerVariable> constraint_vars;
1292 std::vector<int64_t> constraint_coeffs;
1293 for (
const Literal lit : core) {
1294 const int index = literal_to_term_index.at(lit.Index());
1295 terms_[index].weight -= min_weight;
1296 constraint_vars.push_back(terms_[index].var);
1297 constraint_coeffs.push_back(1);
1299 constraint_vars.push_back(new_var);
1300 constraint_coeffs.push_back(-1);
bool Contains(int64_t value) const
void EnableLogging(bool enable)
bool LoggingIsEnabled() const
std::vector< Literal > ExpandAtMostOneWithWeight(absl::Span< const Literal > at_most_one, const util_intops::StrongVector< LiteralIndex, bool > &can_be_included, const util_intops::StrongVector< LiteralIndex, double > &expanded_lp_values)
int64_t literal_size() const
SatSolver::Status OptimizeWithSatEncoding(absl::Span< const Literal > literals, absl::Span< const IntegerVariable > vars, absl::Span< const Coefficient > coefficients, Coefficient offset)
SatSolver::Status Optimize()
CoreBasedOptimizer(IntegerVariable objective_var, absl::Span< const IntegerVariable > variables, absl::Span< const IntegerValue > coefficients, std::function< void()> feasible_solution_observer, Model *model)
static EncodingNode GenericNode(int lb, int ub, std::function< Literal(int x)> create_lit, Coefficient weight)
static EncodingNode LiteralNode(Literal l, Coefficient weight)
IntegerValue LowerBound(IntegerVariable i) const
const Domain & InitialVariableDomain(IntegerVariable var) const
LiteralIndex Index() const
T Get(std::function< T(const Model &)> f) const
Similar to Add() but this is const.
std::vector< EncodingNode * > * mutable_nodes()
void AddBaseNode(EncodingNode node)
const std::vector< EncodingNode * > & nodes() const
bool ProcessCore(absl::Span< const Literal > core, Coefficient min_weight, Coefficient gap, std::string *info)
void set_max_number_of_conflicts(::int64_t value)
::int32_t binary_search_num_conflicts() const
static constexpr MaxSatStratificationAlgorithm STRATIFICATION_NONE
Status EnqueueDecisionAndBacktrackOnConflict(Literal true_literal, int *first_propagation_index=nullptr)
SolverLogger * mutable_logger()
void NotifyThatModelIsUnsat()
std::vector< Literal > GetLastIncompatibleDecisions()
bool ModelIsUnsat() const
void Backtrack(int target_level)
ABSL_MUST_USE_RESULT bool Propagate()
ABSL_MUST_USE_RESULT bool AddUnitClause(Literal true_literal)
Status ResetAndSolveWithGivenAssumptions(const std::vector< Literal > &assumptions, int64_t max_number_of_conflicts=-1)
const VariablesAssignment & Assignment() const
int CurrentDecisionLevel() const
ABSL_MUST_USE_RESULT bool ResetToLevelZero()
bool BacktrackAndPropagateReimplications(int target_level)
int EnqueueDecisionAndBackjumpOnConflict(Literal true_literal, std::optional< ConflictCallback > callback=std::nullopt)
bool LiteralIsFalse(Literal literal) const
bool LiteralIsTrue(Literal literal) const
void resize(size_type new_size)
void STLSortAndRemoveDuplicates(T *v, const LessFunc &less_func)
std::tuple< int64_t, int64_t, const double > Coefficient
constexpr IntegerValue kMaxIntegerValue(std::numeric_limits< IntegerValue::ValueType >::max() - 1)
std::vector< Literal > ExtractAssumptions(Coefficient stratified_lower_bound, const std::vector< EncodingNode * > &nodes, SatSolver *solver)
std::function< int64_t(const Model &)> LowerBound(IntegerVariable v)
std::vector< IntegerVariable > NegationOf(absl::Span< const IntegerVariable > vars)
void ReduceNodes(Coefficient upper_bound, Coefficient *lower_bound, std::vector< EncodingNode * > *nodes, SatSolver *solver)
void MinimizeCoreWithPropagation(TimeLimit *limit, SatSolver *solver, std::vector< Literal > *core)
void FilterAssignedLiteral(const VariablesAssignment &assignment, std::vector< Literal > *core)
Coefficient ComputeCoreMinWeight(const std::vector< EncodingNode * > &nodes, absl::Span< const Literal > core)
void MinimizeCoreWithSearch(TimeLimit *limit, SatSolver *solver, std::vector< Literal > *core)
void PresolveBooleanLinearExpression(std::vector< Literal > *literals, std::vector< Coefficient > *coefficients, Coefficient *offset)
bool ProbeLiteral(Literal assumption, SatSolver *solver)
SatSolver::Status MinimizeIntegerVariableWithLinearScanAndLazyEncoding(IntegerVariable objective_var, const std::function< void()> &feasible_solution_observer, Model *model)
int MoveOneUnprocessedLiteralLast(const absl::btree_set< LiteralIndex > &processed, int relevant_prefix_size, std::vector< Literal > *literals)
SatSolver::Status ResetAndSolveIntegerProblem(const std::vector< Literal > &assumptions, Model *model)
void RestrictObjectiveDomainWithBinarySearch(IntegerVariable objective_var, const std::function< void()> &feasible_solution_observer, Model *model)
Coefficient MaxNodeWeightSmallerThan(const std::vector< EncodingNode * > &nodes, Coefficient upper_bound)
std::function< void(Model *)> WeightedSumLowerOrEqual(absl::Span< const IntegerVariable > vars, const VectorInt &coefficients, int64_t upper_bound)
std::string FormatCounter(int64_t num)
IntegerValue inner_objective_value
static IntegerLiteral GreaterOrEqual(IntegerVariable i, IntegerValue bound)
static IntegerLiteral LowerOrEqual(IntegerVariable i, IntegerValue bound)