22#include "absl/strings/str_cat.h"
31 const std::vector<IntegerVariable>& vars) {
32 std::vector<IntegerVariable> result(vars.size());
33 for (
int i = 0; i < vars.size(); ++i) {
41 ", value = ",
value.value(),
")");
55 <<
"Domain too large for full encoding.";
66 for (
const int64_t v : (*domains_)[
var].Values()) {
67 tmp_values_.push_back(IntegerValue(v));
69 for (
const IntegerValue v : tmp_values_) {
81 if (
index >= is_fully_encoded_.size())
return false;
84 if (is_fully_encoded_[
index])
return true;
91 const int64_t initial_domain_size = (*domains_)[
var].Size();
92 if (equality_by_var_[
index].size() < initial_domain_size)
return false;
101 const auto& ref = equality_by_var_[
index];
103 for (
const int64_t v : (*domains_)[
var].Values()) {
104 if (i < ref.size() && v == ref[i].value) {
108 if (i == ref.size()) {
109 is_fully_encoded_[
index] =
true;
111 return is_fully_encoded_[
index];
115 IntegerVariable
var)
const {
121 IntegerVariable
var)
const {
124 if (
index >= equality_by_var_.size())
return {};
127 std::vector<ValueLiteralPair>& ref = equality_by_var_[
index];
128 for (
int i = 0; i < ref.size(); ++i) {
137 ref[new_size++] = pair;
139 ref.resize(new_size);
142 std::vector<ValueLiteralPair> result = ref;
144 std::reverse(result.begin(), result.end());
151 IntegerVariable
var)
const {
154 if (
index >= equality_by_var_.size())
return {};
156 return equality_by_var_[
index];
162void IntegerEncoder::AddImplications(
163 const std::map<IntegerValue, Literal>& map,
164 std::map<IntegerValue, Literal>::const_iterator it,
166 if (!add_implications_)
return;
172 if (after_it != map.end()) {
174 {after_it->second.Negated(), associated_lit});
178 if (it != map.begin()) {
182 {associated_lit.
Negated(), before_it->second});
188 add_implications_ =
true;
189 for (
const std::map<IntegerValue, Literal>& encoding : encoding_by_var_) {
191 for (
const auto value_literal : encoding) {
192 const Literal lit = value_literal.second;
197 previous = lit.
Index();
204 const IntegerVariable
var(i_lit.
var);
205 IntegerValue after(i_lit.
bound);
206 IntegerValue before(i_lit.
bound - 1);
211 if (before > previous && before <
interval.start) before = previous;
221 if (i_lit.
bound <= (*domains_)[i_lit.
var].Min()) {
224 if (i_lit.
bound > (*domains_)[i_lit.
var].Max()) {
236 ++num_created_variables_;
243 VLOG(1) <<
"Created a fixed literal for no reason!";
249std::pair<PositiveOnlyIndex, IntegerValue> PositiveVarKey(IntegerVariable
var,
250 IntegerValue
value) {
257 IntegerVariable
var, IntegerValue
value)
const {
259 equality_to_associated_literal_.find(PositiveVarKey(
var,
value));
260 if (it != equality_to_associated_literal_.end()) {
261 return it->second.Index();
267 IntegerVariable
var, IntegerValue
value) {
270 equality_to_associated_literal_.find(PositiveVarKey(
var,
value));
271 if (it != equality_to_associated_literal_.end()) {
285 ++num_created_variables_;
295 VLOG(1) <<
"Created a fixed literal for no reason!";
302 const auto& domain = (*domains_)[i_lit.
var];
303 const IntegerValue
min(domain.Min());
304 const IntegerValue
max(domain.Max());
311 HalfAssociateGivenLiteral(pair.first,
literal);
312 HalfAssociateGivenLiteral(pair.second,
literal.Negated());
317 if (pair.first.bound ==
max) {
320 if (-pair.second.bound ==
min) {
328 IntegerValue
value) {
333 if (
value == 1 && domain.
Min() >= 0 && domain.
Max() <= 1) {
334 if (
literal.Index() >= literal_view_.size()) {
341 if (
value == -1 && domain.
Min() >= -1 && domain.
Max() <= 0) {
342 if (
literal.Index() >= literal_view_.size()) {
352 const auto insert_result = equality_to_associated_literal_.insert(
354 if (!insert_result.second) {
375 if (
index >= equality_by_var_.size()) {
376 equality_by_var_.resize(
index.value() + 1);
377 is_fully_encoded_.resize(
index.value() + 1);
379 equality_by_var_[
index].push_back(
414 const int new_size = 1 +
literal.Index().value();
415 if (new_size > full_reverse_encoding_.size()) {
416 full_reverse_encoding_.resize(new_size);
418 full_reverse_encoding_[
literal.Index()].push_back(le);
419 full_reverse_encoding_[
literal.Index()].push_back(ge);
426void IntegerEncoder::HalfAssociateGivenLiteral(
IntegerLiteral i_lit,
429 const int new_size = 1 +
literal.Index().value();
430 if (new_size > reverse_encoding_.size()) {
431 reverse_encoding_.resize(new_size);
433 if (new_size > full_reverse_encoding_.size()) {
434 full_reverse_encoding_.resize(new_size);
438 if (i_lit.
var >= encoding_by_var_.size()) {
439 encoding_by_var_.resize(i_lit.
var.value() + 1);
441 auto& var_encoding = encoding_by_var_[i_lit.
var];
442 auto insert_result = var_encoding.insert({i_lit.
bound,
literal});
443 if (insert_result.second) {
444 AddImplications(var_encoding, insert_result.first,
literal);
447 newly_fixed_integer_literals_.push_back(i_lit);
452 reverse_encoding_[
literal.Index()].push_back(i_lit);
453 full_reverse_encoding_[
literal.Index()].push_back(i_lit);
455 const Literal associated(insert_result.first->second);
465 if (i.
var >= encoding_by_var_.size())
return false;
466 const std::map<IntegerValue, Literal>& encoding = encoding_by_var_[i.
var];
467 return encoding.find(i.
bound) != encoding.end();
472 const std::map<IntegerValue, Literal>& encoding = encoding_by_var_[i.
var];
473 const auto result = encoding.find(i.
bound);
475 return result->second.Index();
483 const std::map<IntegerValue, Literal>& encoding = encoding_by_var_[i.
var];
484 auto after_it = encoding.upper_bound(i.
bound);
487 *
bound = after_it->first;
488 return after_it->second.Index();
493 VLOG(1) <<
"Num decisions to break propagation loop: "
494 << num_decisions_to_break_loop_;
505 if (level > integer_search_levels_.size()) {
506 integer_search_levels_.push_back(integer_trail_.size());
507 reason_decision_levels_.push_back(literals_reason_starts_.size());
513 var_to_current_lb_interval_index_.SetLevel(level);
526 if (!
Enqueue(i_lit, {}, {}))
return false;
532 if (!
Enqueue(i_lit, {}, {}))
return false;
534 integer_literal_to_fix_.clear();
536 for (
const Literal lit : literal_to_fix_) {
541 literal_to_fix_.clear();
546 while (propagation_trail_index_ < trail->
Index()) {
552 if (!EnqueueAssociatedIntegerLiteral(i_lit,
literal)) {
563 conditional_lbs_.clear();
565 var_to_current_lb_interval_index_.SetLevel(level);
569 if (level < first_level_without_full_propagation_) {
570 first_level_without_full_propagation_ = -1;
575 if (level >= integer_search_levels_.size())
return;
576 const int target = integer_search_levels_[level];
577 integer_search_levels_.resize(level);
579 CHECK_LE(target, integer_trail_.size());
581 for (
int index = integer_trail_.size() - 1;
index >= target; --
index) {
582 const TrailEntry& entry = integer_trail_[
index];
583 if (entry.var < 0)
continue;
584 vars_[entry.var].current_trail_index = entry.prev_trail_index;
585 vars_[entry.var].current_bound =
586 integer_trail_[entry.prev_trail_index].bound;
588 integer_trail_.resize(target);
591 const int old_size = reason_decision_levels_[level];
592 reason_decision_levels_.resize(level);
593 if (old_size < literals_reason_starts_.size()) {
594 literals_reason_buffer_.resize(literals_reason_starts_[old_size]);
596 const int bound_start = bounds_reason_starts_[old_size];
597 bounds_reason_buffer_.resize(bound_start);
598 if (bound_start < trail_index_reason_buffer_.size()) {
599 trail_index_reason_buffer_.resize(bound_start);
602 literals_reason_starts_.resize(old_size);
603 bounds_reason_starts_.resize(old_size);
613 const int size = 2 * num_vars;
615 is_ignored_literals_.reserve(size);
616 integer_trail_.reserve(size);
618 var_trail_index_cache_.reserve(size);
619 tmp_var_to_trail_index_in_queue_.reserve(size);
629 DCHECK(integer_search_levels_.empty());
630 DCHECK_EQ(vars_.size(), integer_trail_.size());
632 const IntegerVariable i(vars_.size());
634 vars_.push_back({
lower_bound,
static_cast<int>(integer_trail_.size())});
643 vars_.push_back({-
upper_bound,
static_cast<int>(integer_trail_.size())});
647 var_trail_index_cache_.resize(vars_.size(), integer_trail_.size());
648 tmp_var_to_trail_index_in_queue_.resize(vars_.size(), 0);
659 IntegerValue(domain.
Max()));
665 return (*domains_)[
var];
673 if (old_domain == domain)
return true;
675 if (domain.
IsEmpty())
return false;
676 (*domains_)[
var] = domain;
679 var_to_current_lb_interval_index_.Set(
var, 0);
697 if (i == domain.
NumIntervals() || pair.value < domain[i].start) {
707 <<
"Domain intersection fixed " << num_fixed
708 <<
" equality literal corresponding to values outside the new domain.";
715 IntegerValue
value) {
719 insert.first->second = new_var;
726 return insert.first->second;
732 return (constant_map_.size() + 1) / 2;
736 int threshold)
const {
740 const int index_in_queue = tmp_var_to_trail_index_in_queue_[
var];
741 if (threshold <= index_in_queue) {
743 has_dependency_ =
true;
748 int trail_index = vars_[
var].current_trail_index;
751 if (trail_index > threshold) {
752 const int cached_index = var_trail_index_cache_[
var];
753 if (cached_index >= threshold && cached_index < trail_index &&
754 integer_trail_[cached_index].
var ==
var) {
755 trail_index = cached_index;
759 while (trail_index >= threshold) {
760 trail_index = integer_trail_[trail_index].prev_trail_index;
761 if (trail_index >= var_trail_index_cache_threshold_) {
762 var_trail_index_cache_[
var] = trail_index;
766 const int num_vars = vars_.size();
767 return trail_index < num_vars ? -1 : trail_index;
770int IntegerTrail::FindLowestTrailIndexThatExplainBound(
774 int trail_index = vars_[i_lit.
var].current_trail_index;
782 const int cached_index = var_trail_index_cache_[i_lit.
var];
783 if (cached_index < trail_index) {
784 const TrailEntry& entry = integer_trail_[cached_index];
785 if (entry.var == i_lit.
var && entry.bound >= i_lit.
bound) {
786 trail_index = cached_index;
791 int prev_trail_index = trail_index;
793 if (trail_index >= var_trail_index_cache_threshold_) {
794 var_trail_index_cache_[i_lit.
var] = trail_index;
796 const TrailEntry& entry = integer_trail_[trail_index];
797 if (entry.bound == i_lit.
bound)
return trail_index;
798 if (entry.bound < i_lit.
bound)
return prev_trail_index;
799 prev_trail_index = trail_index;
800 trail_index = entry.prev_trail_index;
806 IntegerValue slack, absl::Span<const IntegerValue> coeffs,
807 std::vector<IntegerLiteral>* reason)
const {
809 if (slack == 0)
return;
810 const int size = reason->size();
811 tmp_indices_.resize(size);
812 for (
int i = 0; i < size; ++i) {
815 tmp_indices_[i] = vars_[(*reason)[i].var].current_trail_index;
821 for (
const int i : tmp_indices_) {
823 integer_trail_[i].
bound));
828 IntegerValue slack, absl::Span<const IntegerValue> coeffs,
829 absl::Span<const IntegerVariable> vars,
830 std::vector<IntegerLiteral>* reason)
const {
831 tmp_indices_.clear();
832 for (
const IntegerVariable
var : vars) {
833 tmp_indices_.push_back(vars_[
var].current_trail_index);
836 for (
const int i : tmp_indices_) {
838 integer_trail_[i].
bound));
843 absl::Span<const IntegerValue> coeffs,
844 std::vector<int>* trail_indices)
const {
846 DCHECK(relax_heap_.empty());
853 const int size = coeffs.size();
854 const int num_vars = vars_.size();
855 for (
int i = 0; i < size; ++i) {
856 const int index = (*trail_indices)[i];
859 if (
index < num_vars)
continue;
862 const IntegerValue coeff = coeffs[i];
864 (*trail_indices)[new_size++] =
index;
871 const TrailEntry& entry = integer_trail_[
index];
873 index <= tmp_var_to_trail_index_in_queue_[entry.var]) {
874 (*trail_indices)[new_size++] =
index;
879 const TrailEntry& previous_entry = integer_trail_[entry.prev_trail_index];
881 CapProd(coeff.value(), (entry.bound - previous_entry.bound).value());
883 (*trail_indices)[new_size++] =
index;
887 relax_heap_.push_back({
index, coeff, diff});
889 trail_indices->resize(new_size);
890 std::make_heap(relax_heap_.begin(), relax_heap_.end());
892 while (slack > 0 && !relax_heap_.empty()) {
893 const RelaxHeapEntry heap_entry = relax_heap_.front();
894 std::pop_heap(relax_heap_.begin(), relax_heap_.end());
895 relax_heap_.pop_back();
898 if (heap_entry.diff > slack) {
899 trail_indices->push_back(heap_entry.index);
904 slack -= heap_entry.diff;
905 const int index = integer_trail_[heap_entry.index].prev_trail_index;
908 if (
index < num_vars)
continue;
909 if (heap_entry.coeff > slack) {
910 trail_indices->push_back(
index);
913 const TrailEntry& entry = integer_trail_[
index];
915 index <= tmp_var_to_trail_index_in_queue_[entry.var]) {
916 trail_indices->push_back(
index);
920 const TrailEntry& previous_entry = integer_trail_[entry.prev_trail_index];
921 const int64_t diff =
CapProd(heap_entry.coeff.value(),
922 (entry.bound - previous_entry.bound).value());
924 trail_indices->push_back(
index);
927 relax_heap_.push_back({
index, heap_entry.coeff, diff});
928 std::push_heap(relax_heap_.begin(), relax_heap_.end());
933 for (
const RelaxHeapEntry& entry : relax_heap_) {
934 trail_indices->push_back(entry.index);
940 std::vector<IntegerLiteral>* reason)
const {
944 (*reason)[new_size++] =
literal;
946 reason->resize(new_size);
949std::vector<Literal>* IntegerTrail::InitializeConflict(
950 IntegerLiteral integer_literal,
const LazyReasonFunction& lazy_reason,
951 absl::Span<const Literal> literals_reason,
952 absl::Span<const IntegerLiteral> bounds_reason) {
953 DCHECK(tmp_queue_.empty());
955 if (lazy_reason ==
nullptr) {
956 conflict->assign(literals_reason.begin(), literals_reason.end());
957 const int num_vars = vars_.size();
959 const int trail_index = FindLowestTrailIndexThatExplainBound(
literal);
960 if (trail_index >= num_vars) tmp_queue_.push_back(trail_index);
965 lazy_reason(integer_literal, integer_trail_.size(), conflict, &tmp_queue_);
972std::string ReasonDebugString(absl::Span<const Literal> literal_reason,
973 absl::Span<const IntegerLiteral> integer_reason) {
974 std::string result =
"literals:{";
975 for (
const Literal l : literal_reason) {
976 if (result.back() !=
'{') result +=
",";
977 result += l.DebugString();
979 result +=
"} bounds:{";
980 for (
const IntegerLiteral l : integer_reason) {
981 if (result.back() !=
'{') result +=
",";
982 result += l.DebugString();
990std::string IntegerTrail::DebugString() {
991 std::string result =
"trail:{";
992 const int num_vars = vars_.size();
994 std::min(num_vars + 30,
static_cast<int>(integer_trail_.size()));
995 for (
int i = num_vars; i < limit; ++i) {
996 if (result.back() !=
'{') result +=
",";
999 integer_trail_[i].
bound)
1002 if (limit < integer_trail_.size()) {
1010 IntegerLiteral i_lit, absl::Span<const IntegerLiteral> integer_reason) {
1013 std::vector<IntegerLiteral> cleaned_reason;
1015 DCHECK(!lit.IsFalseLiteral());
1016 if (lit.IsTrueLiteral())
continue;
1017 cleaned_reason.push_back(lit);
1023 return Enqueue(i_lit, {}, cleaned_reason);
1028 absl::Span<const Literal> literal_reason,
1029 absl::Span<const IntegerLiteral> integer_reason) {
1030 return EnqueueInternal(i_lit,
nullptr, literal_reason, integer_reason,
1031 integer_trail_.size());
1036 std::vector<IntegerLiteral>* integer_reason) {
1044 return Enqueue(i_lit, *literal_reason, *integer_reason);
1048 literal_reason->push_back(lit.
Negated());
1049 return Enqueue(i_lit, *literal_reason, *integer_reason);
1053 integer_reason->push_back(
1069 const auto [it, inserted] =
1070 conditional_lbs_.insert({{lit.
Index(), i_lit.
var}, i_lit.
bound});
1079 absl::Span<const Literal> literal_reason,
1080 absl::Span<const IntegerLiteral> integer_reason,
1081 int trail_index_with_same_reason) {
1082 return EnqueueInternal(i_lit,
nullptr, literal_reason, integer_reason,
1083 trail_index_with_same_reason);
1088 return EnqueueInternal(i_lit, lazy_reason, {}, {}, integer_trail_.size());
1091bool IntegerTrail::ReasonIsValid(
1092 absl::Span<const Literal> literal_reason,
1093 absl::Span<const IntegerLiteral> integer_reason) {
1095 for (
const Literal lit : literal_reason) {
1098 for (
const IntegerLiteral i_lit : integer_reason) {
1099 if (i_lit.
bound > vars_[i_lit.
var].current_bound) {
1102 LOG(
INFO) <<
"Reason " << i_lit <<
" is not true!"
1103 <<
" optional variable:" << i_lit.
var
1106 <<
" current_lb:" << vars_[i_lit.
var].current_bound;
1108 LOG(
INFO) <<
"Reason " << i_lit <<
" is not true!"
1109 <<
" non-optional variable:" << i_lit.
var
1110 <<
" current_lb:" << vars_[i_lit.
var].current_bound;
1118 if (!integer_search_levels_.empty()) {
1119 int num_literal_assigned_after_root_node = 0;
1120 for (
const Literal lit : literal_reason) {
1121 if (trail_->
Info(lit.Variable()).
level > 0) {
1122 num_literal_assigned_after_root_node++;
1125 for (
const IntegerLiteral i_lit : integer_reason) {
1127 num_literal_assigned_after_root_node++;
1130 if (num_literal_assigned_after_root_node == 0) {
1131 VLOG(2) <<
"Propagating a literal with no reason at a positive level!\n"
1132 <<
"level:" << integer_search_levels_.size() <<
" "
1133 << ReasonDebugString(literal_reason, integer_reason) <<
"\n"
1143 absl::Span<const IntegerLiteral> integer_reason) {
1144 EnqueueLiteralInternal(
literal,
nullptr, literal_reason, integer_reason);
1147void IntegerTrail::EnqueueLiteralInternal(
1149 absl::Span<const Literal> literal_reason,
1150 absl::Span<const IntegerLiteral> integer_reason) {
1152 DCHECK(lazy_reason !=
nullptr ||
1153 ReasonIsValid(literal_reason, integer_reason));
1154 if (integer_search_levels_.empty()) {
1161 if (!integer_search_levels_.empty() && integer_reason.empty() &&
1162 literal_reason.empty() && lazy_reason ==
nullptr) {
1163 literal_to_fix_.push_back(
literal);
1166 const int trail_index = trail_->
Index();
1167 if (trail_index >= boolean_trail_index_to_integer_one_.size()) {
1168 boolean_trail_index_to_integer_one_.resize(trail_index + 1);
1170 boolean_trail_index_to_integer_one_[trail_index] = integer_trail_.size();
1172 int reason_index = literals_reason_starts_.size();
1173 if (lazy_reason !=
nullptr) {
1174 if (integer_trail_.size() >= lazy_reasons_.size()) {
1175 lazy_reasons_.resize(integer_trail_.size() + 1,
nullptr);
1177 lazy_reasons_[integer_trail_.size()] = lazy_reason;
1181 literals_reason_starts_.push_back(literals_reason_buffer_.size());
1182 literals_reason_buffer_.insert(literals_reason_buffer_.end(),
1183 literal_reason.begin(),
1184 literal_reason.end());
1185 bounds_reason_starts_.push_back(bounds_reason_buffer_.size());
1186 bounds_reason_buffer_.insert(bounds_reason_buffer_.end(),
1187 integer_reason.begin(), integer_reason.end());
1190 integer_trail_.push_back({IntegerValue(0),
1202 const int num_vars = vars_.size();
1203 return (!integer_search_levels_.empty() &&
1204 integer_trail_.size() - integer_search_levels_.back() >
1213 ++num_decisions_to_break_loop_;
1214 std::vector<IntegerVariable> vars;
1215 for (
int i = integer_search_levels_.back(); i < integer_trail_.size(); ++i) {
1216 const IntegerVariable
var = integer_trail_[i].var;
1219 vars.push_back(
var);
1222 std::sort(vars.begin(), vars.end());
1223 IntegerVariable best_var = vars[0];
1226 for (
int i = 1; i < vars.size(); ++i) {
1227 if (vars[i] != vars[i - 1]) {
1231 if (count > best_count) {
1241 return first_level_without_full_propagation_ != -1;
1245 for (IntegerVariable
var(0);
var < vars_.size();
var += 2) {
1252bool IntegerTrail::EnqueueInternal(
1254 absl::Span<const Literal> literal_reason,
1255 absl::Span<const IntegerLiteral> integer_reason,
1256 int trail_index_with_same_reason) {
1257 DCHECK(lazy_reason !=
nullptr ||
1258 ReasonIsValid(literal_reason, integer_reason));
1260 const IntegerVariable
var(i_lit.
var);
1268 if (i_lit.
bound <= vars_[
var].current_bound)
return true;
1277 if ((*domains_)[
var].NumIntervals() > 1) {
1278 const auto& domain = (*domains_)[
var];
1279 int index = var_to_current_lb_interval_index_.FindOrDie(
var);
1280 const int size = domain.NumIntervals();
1281 while (index < size && i_lit.bound > domain[
index].end) {
1284 if (
index == size) {
1287 var_to_current_lb_interval_index_.Set(
var,
index);
1298 Literal(is_ignored_literals_[
var]))) {
1301 auto* conflict = InitializeConflict(i_lit, lazy_reason, literal_reason,
1304 conflict->push_back(Literal(is_ignored_literals_[
var]));
1307 const int trail_index = FindLowestTrailIndexThatExplainBound(ub_reason);
1308 const int num_vars = vars_.size();
1309 if (trail_index >= num_vars) tmp_queue_.push_back(trail_index);
1311 MergeReasonIntoInternal(conflict);
1318 const Literal is_ignored = Literal(is_ignored_literals_[
var]);
1319 if (integer_search_levels_.empty()) {
1326 if (lazy_reason !=
nullptr) {
1327 lazy_reason(i_lit, integer_trail_.size(), &lazy_reason_literals_,
1328 &lazy_reason_trail_indices_);
1329 std::vector<IntegerLiteral> temp;
1330 for (
const int trail_index : lazy_reason_trail_indices_) {
1331 const TrailEntry& entry = integer_trail_[trail_index];
1332 temp.push_back(IntegerLiteral(entry.var, entry.bound));
1340 bounds_reason_buffer_.push_back(ub_reason);
1360 if (i_lit.
bound - lb < (ub - lb) / 2) {
1361 if (first_level_without_full_propagation_ == -1) {
1369 for (SparseBitset<IntegerVariable>* bitset : watchers_) {
1370 bitset->Set(i_lit.
var);
1373 if (!integer_search_levels_.empty() && integer_reason.empty() &&
1374 literal_reason.empty() && lazy_reason ==
nullptr &&
1375 trail_index_with_same_reason >= integer_trail_.size()) {
1376 integer_literal_to_fix_.push_back(i_lit);
1392 const LiteralIndex literal_index =
1395 const Literal to_enqueue = Literal(literal_index);
1397 auto* conflict = InitializeConflict(i_lit, lazy_reason, literal_reason,
1399 conflict->push_back(to_enqueue);
1400 MergeReasonIntoInternal(conflict);
1410 EnqueueLiteralInternal(to_enqueue, lazy_reason, literal_reason,
1413 return EnqueueAssociatedIntegerLiteral(i_lit, to_enqueue);
1417 if (integer_search_levels_.empty()) {
1423 const int trail_index = trail_->
Index();
1424 if (trail_index >= boolean_trail_index_to_integer_one_.size()) {
1425 boolean_trail_index_to_integer_one_.resize(trail_index + 1);
1427 boolean_trail_index_to_integer_one_[trail_index] =
1428 trail_index_with_same_reason;
1435 if (integer_search_levels_.empty()) {
1436 ++num_level_zero_enqueues_;
1437 vars_[i_lit.
var].current_bound = i_lit.
bound;
1438 integer_trail_[i_lit.
var.value()].bound = i_lit.
bound;
1449 int reason_index = literals_reason_starts_.size();
1450 if (lazy_reason !=
nullptr) {
1451 if (integer_trail_.size() >= lazy_reasons_.size()) {
1452 lazy_reasons_.resize(integer_trail_.size() + 1,
nullptr);
1454 lazy_reasons_[integer_trail_.size()] = lazy_reason;
1456 }
else if (trail_index_with_same_reason >= integer_trail_.size()) {
1458 literals_reason_starts_.push_back(literals_reason_buffer_.size());
1459 if (!literal_reason.empty()) {
1460 literals_reason_buffer_.insert(literals_reason_buffer_.end(),
1461 literal_reason.begin(),
1462 literal_reason.end());
1464 bounds_reason_starts_.push_back(bounds_reason_buffer_.size());
1465 if (!integer_reason.empty()) {
1466 bounds_reason_buffer_.insert(bounds_reason_buffer_.end(),
1467 integer_reason.begin(),
1468 integer_reason.end());
1471 reason_index = integer_trail_[trail_index_with_same_reason].reason_index;
1474 const int prev_trail_index = vars_[i_lit.
var].current_trail_index;
1475 integer_trail_.push_back({i_lit.
bound,
1480 vars_[i_lit.
var].current_bound = i_lit.
bound;
1481 vars_[i_lit.
var].current_trail_index = integer_trail_.size() - 1;
1485bool IntegerTrail::EnqueueAssociatedIntegerLiteral(IntegerLiteral i_lit,
1486 Literal literal_reason) {
1487 DCHECK(ReasonIsValid({literal_reason.Negated()}, {}));
1491 if (i_lit.bound <= vars_[i_lit.var].current_bound)
return true;
1499 return Enqueue(i_lit, {literal_reason.Negated()}, {});
1503 for (SparseBitset<IntegerVariable>* bitset : watchers_) {
1504 bitset->Set(i_lit.var);
1508 if (integer_search_levels_.empty()) {
1509 vars_[i_lit.var].current_bound = i_lit.bound;
1510 integer_trail_[i_lit.var.value()].bound = i_lit.bound;
1521 const int reason_index = literals_reason_starts_.size();
1522 CHECK_EQ(reason_index, bounds_reason_starts_.size());
1523 literals_reason_starts_.push_back(literals_reason_buffer_.size());
1524 bounds_reason_starts_.push_back(bounds_reason_buffer_.size());
1525 literals_reason_buffer_.push_back(literal_reason.Negated());
1527 const int prev_trail_index = vars_[i_lit.var].current_trail_index;
1528 integer_trail_.push_back({i_lit.bound,
1533 vars_[i_lit.var].current_bound = i_lit.bound;
1534 vars_[i_lit.var].current_trail_index = integer_trail_.size() - 1;
1538void IntegerTrail::ComputeLazyReasonIfNeeded(
int trail_index)
const {
1539 const int reason_index = integer_trail_[trail_index].reason_index;
1540 if (reason_index == -1) {
1541 const TrailEntry& entry = integer_trail_[trail_index];
1542 const IntegerLiteral
literal(entry.var, entry.bound);
1543 lazy_reasons_[trail_index](
literal, trail_index, &lazy_reason_literals_,
1544 &lazy_reason_trail_indices_);
1548absl::Span<const int> IntegerTrail::Dependencies(
int trail_index)
const {
1549 const int reason_index = integer_trail_[trail_index].reason_index;
1550 if (reason_index == -1) {
1551 return absl::Span<const int>(lazy_reason_trail_indices_);
1554 const int start = bounds_reason_starts_[reason_index];
1555 const int end = reason_index + 1 < bounds_reason_starts_.size()
1556 ? bounds_reason_starts_[reason_index + 1]
1557 : bounds_reason_buffer_.size();
1558 if (start == end)
return {};
1565 if (end > trail_index_reason_buffer_.size()) {
1566 trail_index_reason_buffer_.resize(end, -1);
1568 if (trail_index_reason_buffer_[start] == -1) {
1569 int new_end = start;
1570 const int num_vars = vars_.size();
1571 for (
int i = start; i < end; ++i) {
1573 FindLowestTrailIndexThatExplainBound(bounds_reason_buffer_[i]);
1574 if (dep >= num_vars) {
1575 trail_index_reason_buffer_[new_end++] = dep;
1578 return absl::Span<const int>(&trail_index_reason_buffer_[start],
1584 return absl::Span<const int>(&trail_index_reason_buffer_[start],
1589void IntegerTrail::AppendLiteralsReason(
int trail_index,
1590 std::vector<Literal>* output)
const {
1591 CHECK_GE(trail_index, vars_.size());
1592 const int reason_index = integer_trail_[trail_index].reason_index;
1593 if (reason_index == -1) {
1594 for (
const Literal l : lazy_reason_literals_) {
1595 if (!added_variables_[l.Variable()]) {
1596 added_variables_.Set(l.Variable());
1597 output->push_back(l);
1603 const int start = literals_reason_starts_[reason_index];
1604 const int end = reason_index + 1 < literals_reason_starts_.size()
1605 ? literals_reason_starts_[reason_index + 1]
1606 : literals_reason_buffer_.size();
1607 for (
int i = start; i < end; ++i) {
1608 const Literal l = literals_reason_buffer_[i];
1609 if (!added_variables_[l.Variable()]) {
1610 added_variables_.Set(l.Variable());
1611 output->push_back(l);
1617 std::vector<Literal> reason;
1625 std::vector<Literal>* output)
const {
1626 DCHECK(tmp_queue_.empty());
1627 const int num_vars = vars_.size();
1629 const int trail_index = FindLowestTrailIndexThatExplainBound(
literal);
1633 if (trail_index >= num_vars) tmp_queue_.push_back(trail_index);
1635 return MergeReasonIntoInternal(output);
1640void IntegerTrail::MergeReasonIntoInternal(std::vector<Literal>* output)
const {
1643 DCHECK(std::all_of(tmp_var_to_trail_index_in_queue_.begin(),
1644 tmp_var_to_trail_index_in_queue_.end(),
1645 [](
int v) { return v == 0; }));
1647 added_variables_.ClearAndResize(BooleanVariable(trail_->
NumVariables()));
1648 for (
const Literal l : *output) {
1649 added_variables_.Set(l.Variable());
1654 for (
const int trail_index : tmp_queue_) {
1656 DCHECK_LT(trail_index, integer_trail_.size());
1657 const TrailEntry& entry = integer_trail_[trail_index];
1658 tmp_var_to_trail_index_in_queue_[entry.var] =
1659 std::max(tmp_var_to_trail_index_in_queue_[entry.var], trail_index);
1664 std::make_heap(tmp_queue_.begin(), tmp_queue_.end());
1669 tmp_to_clear_.clear();
1670 while (!tmp_queue_.empty()) {
1671 const int trail_index = tmp_queue_.front();
1672 const TrailEntry& entry = integer_trail_[trail_index];
1673 std::pop_heap(tmp_queue_.begin(), tmp_queue_.end());
1674 tmp_queue_.pop_back();
1679 if (tmp_var_to_trail_index_in_queue_[entry.var] != trail_index) {
1686 var_trail_index_cache_threshold_ = trail_index;
1691 const LiteralIndex associated_lit =
1693 IntegerVariable(entry.var), entry.bound));
1696 const int reason_index = integer_trail_[trail_index].reason_index;
1699 const int start = literals_reason_starts_[reason_index];
1700 const int end = reason_index + 1 < literals_reason_starts_.size()
1701 ? literals_reason_starts_[reason_index + 1]
1702 : literals_reason_buffer_.size();
1704 CHECK_EQ(literals_reason_buffer_[start],
1705 Literal(associated_lit).Negated());
1708 const int start = bounds_reason_starts_[reason_index];
1709 const int end = reason_index + 1 < bounds_reason_starts_.size()
1710 ? bounds_reason_starts_[reason_index + 1]
1711 : bounds_reason_buffer_.size();
1725 tmp_var_to_trail_index_in_queue_[entry.var] = 0;
1726 has_dependency_ =
false;
1728 ComputeLazyReasonIfNeeded(trail_index);
1729 AppendLiteralsReason(trail_index, output);
1730 for (
const int next_trail_index : Dependencies(trail_index)) {
1731 if (next_trail_index < 0)
break;
1732 DCHECK_LT(next_trail_index, trail_index);
1733 const TrailEntry& next_entry = integer_trail_[next_trail_index];
1739 const int index_in_queue =
1740 tmp_var_to_trail_index_in_queue_[next_entry.var];
1742 has_dependency_ =
true;
1743 if (next_trail_index > index_in_queue) {
1744 tmp_var_to_trail_index_in_queue_[next_entry.var] = next_trail_index;
1745 tmp_queue_.push_back(next_trail_index);
1746 std::push_heap(tmp_queue_.begin(), tmp_queue_.end());
1751 if (!has_dependency_) {
1752 tmp_to_clear_.push_back(entry.var);
1753 tmp_var_to_trail_index_in_queue_[entry.var] =
1759 for (
const IntegerVariable
var : tmp_to_clear_) {
1760 tmp_var_to_trail_index_in_queue_[
var] = 0;
1765 int trail_index)
const {
1766 const int index = boolean_trail_index_to_integer_one_[trail_index];
1768 added_variables_.ClearAndResize(BooleanVariable(trail_->
NumVariables()));
1770 ComputeLazyReasonIfNeeded(
index);
1771 AppendLiteralsReason(
index, reason);
1772 DCHECK(tmp_queue_.empty());
1773 for (
const int prev_trail_index : Dependencies(
index)) {
1774 if (prev_trail_index < 0)
break;
1775 DCHECK_GE(prev_trail_index, vars_.size());
1776 tmp_queue_.push_back(prev_trail_index);
1778 MergeReasonIntoInternal(reason);
1785 tmp_marked_.ClearAndResize(IntegerVariable(vars_.size()));
1788 const int end = vars_.size();
1789 for (
int i = integer_trail_.size(); --i >= end;) {
1790 const TrailEntry& entry = integer_trail_[i];
1792 if (tmp_marked_[entry.var])
continue;
1794 tmp_marked_.Set(entry.var);
1811 &id_to_greatest_common_level_since_last_call_);
1813 queue_by_priority_.resize(2);
1816void GenericLiteralWatcher::UpdateCallingNeeds(
Trail* trail) {
1818 while (propagation_trail_index_ < trail->
Index()) {
1820 if (
literal.Index() >= literal_to_watcher_.size())
continue;
1821 for (
const auto entry : literal_to_watcher_[
literal.Index()]) {
1822 if (!in_queue_[entry.id]) {
1823 in_queue_[entry.id] =
true;
1824 queue_by_priority_[id_to_priority_[entry.id]].push_back(entry.id);
1826 if (entry.watch_index >= 0) {
1827 id_to_watch_indices_[entry.id].push_back(entry.watch_index);
1833 for (
const IntegerVariable
var : modified_vars_.PositionsSetAtLeastOnce()) {
1834 if (
var.value() >= var_to_watcher_.size())
continue;
1835 for (
const auto entry : var_to_watcher_[
var]) {
1836 if (!in_queue_[entry.id]) {
1837 in_queue_[entry.id] =
true;
1838 queue_by_priority_[id_to_priority_[entry.id]].push_back(entry.id);
1840 if (entry.watch_index >= 0) {
1841 id_to_watch_indices_[entry.id].push_back(entry.watch_index);
1847 const std::vector<IntegerVariable>& modified_vars =
1848 modified_vars_.PositionsSetAtLeastOnce();
1849 for (
const auto&
callback : level_zero_modified_variable_callback_) {
1862 for (
const int id : propagator_ids_to_call_at_level_zero_) {
1863 if (in_queue_[
id])
continue;
1864 in_queue_[id] =
true;
1865 queue_by_priority_[id_to_priority_[id]].push_back(
id);
1869 UpdateCallingNeeds(trail);
1874 for (
int priority = 0; priority < queue_by_priority_.size(); ++priority) {
1881 if (test_limit > 100) {
1886 std::deque<int>& queue = queue_by_priority_[priority];
1887 while (!queue.empty()) {
1888 const int id = queue.front();
1896 id_to_greatest_common_level_since_last_call_[IdType(
id)];
1897 const int high = id_to_level_at_last_call_[id];
1898 if (low < high || level > low) {
1899 id_to_level_at_last_call_[id] = level;
1900 id_to_greatest_common_level_since_last_call_.MutableRef(IdType(
id)) =
1903 if (low < high) rev->SetLevel(low);
1904 if (level > low) rev->SetLevel(level);
1906 for (
int* rev_int : id_to_reversible_ints_[
id]) {
1907 rev_int_repository_->
SaveState(rev_int);
1913 const int64_t old_integer_timestamp = integer_trail_->
num_enqueues();
1914 const int64_t old_boolean_timestamp = trail->
Index();
1917 std::vector<int>& watch_indices_ref = id_to_watch_indices_[id];
1919 watch_indices_ref.empty()
1920 ? watchers_[id]->Propagate()
1921 : watchers_[id]->IncrementalPropagate(watch_indices_ref);
1923 watch_indices_ref.clear();
1924 in_queue_[id] =
false;
1930 if (id_to_idempotence_[
id]) {
1934 UpdateCallingNeeds(trail);
1935 watch_indices_ref.clear();
1936 in_queue_[id] =
false;
1941 watch_indices_ref.clear();
1942 in_queue_[id] =
false;
1943 UpdateCallingNeeds(trail);
1949 if (trail->
Index() > old_boolean_timestamp) {
1961 if (integer_trail_->
num_enqueues() > old_integer_timestamp) {
1979 for (std::deque<int>& queue : queue_by_priority_) {
1980 for (
const int id : queue) {
1981 id_to_watch_indices_[id].clear();
1991 in_queue_.assign(watchers_.size(),
false);
1996 const int id = watchers_.size();
1997 watchers_.push_back(propagator);
1998 id_to_level_at_last_call_.push_back(0);
1999 id_to_greatest_common_level_since_last_call_.GrowByOne();
2000 id_to_reversible_classes_.push_back(std::vector<ReversibleInterface*>());
2001 id_to_reversible_ints_.push_back(std::vector<int*>());
2002 id_to_watch_indices_.push_back(std::vector<int>());
2003 id_to_priority_.push_back(1);
2004 id_to_idempotence_.push_back(
true);
2013 in_queue_.push_back(
true);
2014 queue_by_priority_[1].push_back(
id);
2019 id_to_priority_[id] = priority;
2020 if (priority >= queue_by_priority_.size()) {
2021 queue_by_priority_.resize(priority + 1);
2027 id_to_idempotence_[id] =
false;
2031 propagator_ids_to_call_at_level_zero_.push_back(
id);
2036 id_to_reversible_classes_[id].push_back(rev);
2040 id_to_reversible_ints_[id].push_back(rev);
2044std::function<void(
Model*)>
2052 std::vector<Literal> clause_to_exclude_solution;
2053 clause_to_exclude_solution.reserve(current_level);
2054 for (
int i = 0; i < current_level; ++i) {
2055 bool include_decision =
true;
2061 encoder->GetIntegerLiterals(decision);
2063 if (integer_trail->IsCurrentlyIgnored(
bound.var)) {
2069 clause_to_exclude_solution.push_back(
2070 integer_trail->IsIgnoredLiteral(
bound.var).Negated());
2071 include_decision =
false;
2075 if (include_decision) {
2076 clause_to_exclude_solution.push_back(decision.
Negated());
#define DCHECK_LE(val1, val2)
#define CHECK_LT(val1, val2)
#define CHECK_EQ(val1, val2)
#define CHECK_GE(val1, val2)
#define DCHECK_GE(val1, val2)
#define CHECK_NE(val1, val2)
#define DCHECK_GT(val1, val2)
#define DCHECK_LT(val1, val2)
#define DCHECK(condition)
#define CHECK_LE(val1, val2)
#define DCHECK_EQ(val1, val2)
#define VLOG(verboselevel)
void reserve(size_type n)
void push_back(const value_type &x)
We call domain any subset of Int64 = [kint64min, kint64max].
Domain Negation() const
Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.
bool Contains(int64_t value) const
Returns true iff value is in Domain.
int NumIntervals() const
Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals.
Domain IntersectionWith(const Domain &domain) const
Returns the intersection of D and domain.
int64_t Min() const
Returns the min value of the domain.
bool IsEmpty() const
Returns true if this is the empty set.
int64_t Max() const
Returns the max value of the domain.
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
void SaveState(T *object)
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
bool LimitReached()
Returns true when the external limit is true, or the deterministic time is over the deterministic lim...
bool Propagate(Trail *trail) final
void AlwaysCallAtLevelZero(int id)
void RegisterReversibleInt(int id, int *rev)
void RegisterReversibleClass(int id, ReversibleInterface *rev)
GenericLiteralWatcher(Model *model)
void SetPropagatorPriority(int id, int priority)
int Register(PropagatorInterface *propagator)
void NotifyThatPropagatorMayNotReachFixedPointInOnePass(int id)
void Untrail(const Trail &trail, int literal_trail_index) final
Literal GetOrCreateLiteralAssociatedToEquality(IntegerVariable var, IntegerValue value)
LiteralIndex SearchForLiteralAtOrBefore(IntegerLiteral i, IntegerValue *bound) const
const std::vector< IntegerLiteral > NewlyFixedIntegerLiterals() const
LiteralIndex GetAssociatedLiteral(IntegerLiteral i_lit) const
void FullyEncodeVariable(IntegerVariable var)
Literal GetFalseLiteral()
std::pair< IntegerLiteral, IntegerLiteral > Canonicalize(IntegerLiteral i_lit) const
void ClearNewlyFixedIntegerLiterals()
void AssociateToIntegerEqualValue(Literal literal, IntegerVariable var, IntegerValue value)
std::vector< ValueLiteralPair > PartialDomainEncoding(IntegerVariable var) const
bool LiteralIsAssociated(IntegerLiteral i_lit) const
std::vector< ValueLiteralPair > FullDomainEncoding(IntegerVariable var) const
void AddAllImplicationsBetweenAssociatedLiterals()
bool VariableIsFullyEncoded(IntegerVariable var) const
const InlinedIntegerLiteralVector & GetIntegerLiterals(Literal lit) const
std::vector< ValueLiteralPair > RawDomainEncoding(IntegerVariable var) const
LiteralIndex GetAssociatedEqualityLiteral(IntegerVariable var, IntegerValue value) const
void AssociateToIntegerLiteral(Literal literal, IntegerLiteral i_lit)
Literal GetOrCreateAssociatedLiteral(IntegerLiteral i_lit)
IntegerVariable FirstUnassignedVariable() const
ABSL_MUST_USE_RESULT bool Enqueue(IntegerLiteral i_lit, absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
IntegerVariable GetOrCreateConstantIntegerVariable(IntegerValue value)
int64_t num_enqueues() const
void RegisterWatcher(SparseBitset< IntegerVariable > *p)
bool Propagate(Trail *trail) final
void ReserveSpaceForNumVariables(int num_vars)
int FindTrailIndexOfVarBefore(IntegerVariable var, int threshold) const
bool IsCurrentlyIgnored(IntegerVariable i) const
std::vector< Literal > ReasonFor(IntegerLiteral literal) const
std::function< void(IntegerLiteral literal_to_explain, int trail_index_of_literal, std::vector< Literal > *literals, std::vector< int > *dependencies)> LazyReasonFunction
bool IsFixed(IntegerVariable i) const
LiteralIndex OptionalLiteralIndex(IntegerVariable i) const
absl::Span< const Literal > Reason(const Trail &trail, int trail_index) const final
bool CurrentBranchHadAnIncompletePropagation()
bool InPropagationLoop() const
bool ReportConflict(absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
void EnqueueLiteral(Literal literal, absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
IntegerVariable NextVariableToBranchOnInPropagationLoop() const
IntegerValue UpperBound(IntegerVariable i) const
ABSL_MUST_USE_RESULT bool SafeEnqueue(IntegerLiteral i_lit, absl::Span< const IntegerLiteral > integer_reason)
void AppendRelaxedLinearReason(IntegerValue slack, absl::Span< const IntegerValue > coeffs, absl::Span< const IntegerVariable > vars, std::vector< IntegerLiteral > *reason) const
IntegerValue LevelZeroLowerBound(IntegerVariable var) const
void RelaxLinearReason(IntegerValue slack, absl::Span< const IntegerValue > coeffs, std::vector< IntegerLiteral > *reason) const
void AppendNewBounds(std::vector< IntegerLiteral > *output) const
IntegerValue LowerBound(IntegerVariable i) const
int NumConstantVariables() const
void MergeReasonInto(absl::Span< const IntegerLiteral > literals, std::vector< Literal > *output) const
Literal IsIgnoredLiteral(IntegerVariable i) const
bool IsOptional(IntegerVariable i) const
ABSL_MUST_USE_RESULT bool ConditionalEnqueue(Literal lit, IntegerLiteral i_lit, std::vector< Literal > *literal_reason, std::vector< IntegerLiteral > *integer_reason)
bool IntegerLiteralIsFalse(IntegerLiteral l) const
void RemoveLevelZeroBounds(std::vector< IntegerLiteral > *reason) const
IntegerVariable AddIntegerVariable()
void RegisterReversibleClass(ReversibleInterface *rev)
const Domain & InitialVariableDomain(IntegerVariable var) const
void Untrail(const Trail &trail, int literal_trail_index) final
IntegerVariable NumIntegerVariables() const
bool UpdateInitialDomain(IntegerVariable var, Domain domain)
LiteralIndex Index() const
std::string DebugString() const
Class that owns everything related to a particular optimization model.
bool log_search_progress() const
::operations_research::sat::SatParameters_SearchBranching search_branching() const
static constexpr SearchBranching FIXED_SEARCH
int propagation_trail_index_
bool AddClauseDuringSearch(absl::Span< const Literal > literals)
BooleanVariable NewBooleanVariable()
const VariablesAssignment & Assignment() const
const std::vector< Decision > & Decisions() const
bool AddBinaryClause(Literal a, Literal b)
void Backtrack(int target_level)
int CurrentDecisionLevel() const
bool AddUnitClause(Literal true_literal)
void Enqueue(Literal true_literal, int propagator_id)
std::vector< Literal > * GetEmptyVectorToStoreReason(int trail_index) const
const VariablesAssignment & Assignment() const
std::vector< Literal > * MutableConflict()
const AssignmentInfo & Info(BooleanVariable var) const
int CurrentDecisionLevel() const
void EnqueueWithUnitReason(Literal true_literal)
bool LiteralIsAssigned(Literal literal) const
bool LiteralIsTrue(Literal literal) const
bool LiteralIsFalse(Literal literal) const
void InsertOrDie(Collection *const collection, const typename Collection::value_type &value)
absl::InlinedVector< IntegerLiteral, 2 > InlinedIntegerLiteralVector
constexpr IntegerValue kMaxIntegerValue(std::numeric_limits< IntegerValue::ValueType >::max() - 1)
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
const LiteralIndex kNoLiteralIndex(-1)
constexpr IntegerValue kMinIntegerValue(-kMaxIntegerValue)
std::function< void(Model *)> ClauseConstraint(absl::Span< const Literal > literals)
const IntegerVariable kNoIntegerVariable(-1)
IntegerVariable PositiveVariable(IntegerVariable i)
std::vector< IntegerVariable > NegationOf(const std::vector< IntegerVariable > &vars)
std::function< void(Model *)> ExcludeCurrentSolutionWithoutIgnoredVariableAndBacktrack()
PositiveOnlyIndex GetPositiveOnlyIndex(IntegerVariable var)
bool VariableIsPositive(IntegerVariable i)
Collection of objects used to extend the Constraint Solver library.
int64_t CapProd(int64_t x, int64_t y)
Represents a closed interval [start, end].
static IntegerLiteral LowerOrEqual(IntegerVariable i, IntegerValue bound)
static IntegerLiteral GreaterOrEqual(IntegerVariable i, IntegerValue bound)
std::string DebugString() const
bool IsTrueLiteral() const
bool IsFalseLiteral() const
std::string DebugString() const