49 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVERI_H_
50 #define OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVERI_H_
57 #include <initializer_list>
63 #include "absl/container/flat_hash_map.h"
64 #include "absl/strings/str_cat.h"
99 class LocalSearchMonitor;
139 enum { CHUNK_SIZE = 16 };
142 const Chunk*
const next_;
143 explicit Chunk(
const Chunk*
next) : next_(
next) {}
151 : chunk_(l->chunks_), value_(l->
Last()) {}
152 bool ok()
const {
return (value_ !=
nullptr); }
156 if (value_ == chunk_->data_ + CHUNK_SIZE) {
157 chunk_ = chunk_->next_;
158 value_ = chunk_ ? chunk_->data_ :
nullptr;
170 if (pos_.
Value() == 0) {
171 Chunk*
const chunk = s->UnsafeRevAlloc(
new Chunk(chunks_));
173 reinterpret_cast<void*
>(chunk));
178 chunks_->data_[pos_.
Value()] = val;
183 if (chunks_ ==
nullptr ||
LastValue() != val) {
190 return chunks_ ? &chunks_->data_[pos_.
Value()] :
nullptr;
198 return chunks_->data_[pos_.
Value()];
204 chunks_->data_[pos_.
Value()] = v;
227 a = (
a + 0x7ed55d16) + (
a << 12);
228 a = (
a ^ 0xc761c23c) ^ (
a >> 19);
229 a = (
a + 0x165667b1) + (
a << 5);
230 a = (
a + 0xd3a2646c) ^ (
a << 9);
231 a = (
a + 0xfd7046c5) + (
a << 3);
232 a = (
a ^ 0xb55a4f09) ^ (
a >> 16);
242 inline uint64_t
Hash1(
void*
const ptr) {
243 #if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || \
244 defined(__aarch64__) || (defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64))
245 return Hash1(
reinterpret_cast<uint64_t
>(ptr));
247 return Hash1(
reinterpret_cast<uint32_t
>(ptr));
252 uint64_t
Hash1(
const std::vector<T*>& ptrs) {
253 if (ptrs.empty())
return 0;
254 if (ptrs.size() == 1)
return Hash1(ptrs[0]);
256 for (
int i = 1; i < ptrs.size(); ++i) {
262 inline uint64_t
Hash1(
const std::vector<int64_t>& ptrs) {
263 if (ptrs.empty())
return 0;
264 if (ptrs.size() == 1)
return Hash1(ptrs[0]);
266 for (
int i = 1; i < ptrs.size(); ++i) {
274 template <
class K,
class V>
279 array_(solver->UnsafeRevAllocArray(new Cell*[initial_size])),
282 memset(array_, 0,
sizeof(*array_) * size_.
Value());
292 Cell* tmp = array_[code];
294 if (tmp->key() == key) {
307 Cell* tmp = array_[code];
309 if (tmp->key() == key) {
314 return default_value;
319 const int position =
Hash1(key) % size_.
Value();
321 solver_->UnsafeRevAlloc(
new Cell(key,
value, array_[position]));
323 reinterpret_cast<void*
>(cell));
324 num_items_.
Incr(solver_);
333 Cell(
const K& key,
const V&
value, Cell*
const next)
334 : key_(key), value_(
value), next_(
next) {}
336 void SetRevNext(Solver*
const solver, Cell*
const next) {
337 solver->SaveAndSetValue(
reinterpret_cast<void**
>(&next_),
338 reinterpret_cast<void*
>(
next));
341 Cell*
next()
const {
return next_; }
343 const K& key()
const {
return key_; }
345 const V&
value()
const {
return value_; }
354 Cell**
const old_cell_array = array_;
355 const int old_size = size_.
Value();
358 reinterpret_cast<void**
>(&array_),
359 reinterpret_cast<void*
>(
360 solver_->UnsafeRevAllocArray(
new Cell*[size_.
Value()])));
361 memset(array_, 0, size_.
Value() *
sizeof(*array_));
362 for (
int i = 0; i < old_size; ++i) {
363 Cell* tmp = old_cell_array[i];
364 while (tmp !=
nullptr) {
365 Cell*
const to_reinsert = tmp;
367 const uint64_t new_position =
Hash1(to_reinsert->key()) % size_.
Value();
368 to_reinsert->SetRevNext(solver_, array_[new_position]);
370 reinterpret_cast<void**
>(&array_[new_position]),
371 reinterpret_cast<void*
>(to_reinsert));
376 Solver*
const solver_;
378 NumericalRev<int> size_;
379 NumericalRev<int> num_items_;
449 void Save(
Solver*
const solver,
int offset);
451 const int64_t length_;
469 DCHECK_LT(
row, rows_);
471 DCHECK_LT(
column, columns_);
488 const int64_t columns_;
502 : constraint_(
ct), method_(method), name_(
name) {}
506 void Run(
Solver*
const s)
override { (constraint_->*method_)(); }
509 return "CallMethod_" + name_ +
"(" + constraint_->DebugString() +
")";
513 T*
const constraint_;
514 void (T::*
const method_)();
515 const std::string name_;
520 const std::string&
name) {
526 return absl::StrCat(param);
532 return param->DebugString();
536 template <
class T,
class P>
541 : constraint_(
ct), method_(method), name_(
name), param1_(param1) {}
545 void Run(
Solver*
const s)
override { (constraint_->*method_)(param1_); }
548 return absl::StrCat(
"CallMethod_", name_,
"(", constraint_->DebugString(),
553 T*
const constraint_;
554 void (T::*
const method_)(P);
555 const std::string name_;
559 template <
class T,
class P>
561 const std::string&
name, P param1) {
566 template <
class T,
class P,
class Q>
580 (constraint_->*method_)(param1_, param2_);
584 return absl::StrCat(absl::StrCat(
"CallMethod_", name_),
585 absl::StrCat(
"(", constraint_->DebugString()),
591 T*
const constraint_;
592 void (T::*
const method_)(P, Q);
593 const std::string name_;
598 template <
class T,
class P,
class Q>
600 void (T::*method)(P, Q),
const std::string&
name,
601 P param1, Q param2) {
606 template <
class T,
class P,
class Q,
class R>
610 P param1, Q param2, R param3)
621 (constraint_->*method_)(param1_, param2_, param3_);
625 return absl::StrCat(absl::StrCat(
"CallMethod_", name_),
626 absl::StrCat(
"(", constraint_->DebugString()),
633 T*
const constraint_;
634 void (T::*
const method_)(P, Q, R);
635 const std::string name_;
641 template <
class T,
class P,
class Q,
class R>
643 void (T::*method)(P, Q, R),
const std::string&
name,
644 P param1, Q param2, R param3) {
660 : constraint_(
ct), method_(method), name_(
name) {}
664 void Run(
Solver*
const s)
override { (constraint_->*method_)(); }
671 return "DelayedCallMethod_" + name_ +
"(" + constraint_->DebugString() +
676 T*
const constraint_;
677 void (T::*
const method_)();
678 const std::string name_;
684 const std::string&
name) {
689 template <
class T,
class P>
694 : constraint_(
ct), method_(method), name_(
name), param1_(param1) {}
698 void Run(
Solver*
const s)
override { (constraint_->*method_)(param1_); }
705 return absl::StrCat(
"DelayedCallMethod_", name_,
"(",
706 constraint_->DebugString(),
", ",
711 T*
const constraint_;
712 void (T::*
const method_)(P);
713 const std::string name_;
717 template <
class T,
class P>
719 void (T::*method)(P),
720 const std::string&
name, P param1) {
725 template <
class T,
class P,
class Q>
729 const std::string&
name, P param1, Q param2)
739 (constraint_->*method_)(param1_, param2_);
747 return absl::StrCat(absl::StrCat(
"DelayedCallMethod_", name_),
748 absl::StrCat(
"(", constraint_->DebugString()),
754 T*
const constraint_;
755 void (T::*
const method_)(P, Q);
756 const std::string name_;
761 template <
class T,
class P,
class Q>
763 void (T::*method)(P, Q),
764 const std::string&
name, P param1,
775 template <
typename F>
780 std::function<
bool()> deep_serialize)
784 values_(std::move(values)),
785 deep_serialize_(std::move(deep_serialize)) {}
790 solver(),
this, &LightIntFunctionElementCt::IndexBound,
"IndexBound");
795 if (index_->
Bound()) {
801 return absl::StrFormat(
"LightIntFunctionElementCt(%s, %s)",
812 if (deep_serialize_ ==
nullptr || deep_serialize_()) {
820 void IndexBound() { var_->
SetValue(values_(index_->
Min())); }
823 IntVar*
const index_;
825 std::function<bool()> deep_serialize_;
830 template <
typename F>
835 F values, std::function<
bool()> deep_serialize)
840 values_(std::move(values)),
841 deep_serialize_(std::move(deep_serialize)) {}
845 solver(),
this, &LightIntIntFunctionElementCt::IndexBound,
853 return "LightIntIntFunctionElementCt";
865 const int64_t index1_min = index1_->
Min();
866 const int64_t index1_max = index1_->
Max();
869 if (deep_serialize_ ==
nullptr || deep_serialize_()) {
870 for (
int i = index1_min; i <= index1_max; ++i) {
872 [
this, i](int64_t j) {
return values_(i, j); }, index2_->
Min(),
887 IntVar*
const index1_;
888 IntVar*
const index2_;
890 std::function<bool()> deep_serialize_;
931 max_inversible_index_ = candidate_values_.size();
932 candidate_value_to_index_.resize(max_value + 1, -1);
933 committed_value_to_index_.resize(max_value + 1, -1);
939 DCHECK_LT(
index, candidate_values_.size());
940 return candidate_values_[
index];
943 return committed_values_[
index];
946 return checkpoint_values_[
index];
950 if (
index < max_inversible_index_) {
957 return candidate_is_active_[
index];
970 const int64_t
value = candidate_values_[
index];
972 if (
index < max_inversible_index_) {
981 void CheckPoint() { checkpoint_values_ = committed_values_; }
985 if (only_incremental)
return;
988 const int64_t committed_value = committed_values_[
index];
989 candidate_values_[
index] = committed_value;
990 if (
index < max_inversible_index_) {
991 candidate_value_to_index_[committed_value] =
index;
1006 candidate_values_.resize(size);
1007 committed_values_.resize(size);
1008 checkpoint_values_.resize(size);
1009 candidate_is_active_.
Resize(size);
1010 committed_is_active_.
Resize(size);
1016 return candidate_value_to_index_[
value];
1019 return committed_value_to_index_[
value];
1023 void MarkChange(int64_t
index) {
1028 std::vector<int64_t> candidate_values_;
1029 std::vector<int64_t> committed_values_;
1030 std::vector<int64_t> checkpoint_values_;
1032 Bitset64<> candidate_is_active_;
1033 Bitset64<> committed_is_active_;
1035 SparseBitset<> changes_;
1036 SparseBitset<> incremental_changes_;
1038 int64_t max_inversible_index_ = -1;
1039 std::vector<int64_t> candidate_value_to_index_;
1040 std::vector<int64_t> committed_value_to_index_;
1054 bool keep_inverse_values =
false) {
1056 if (keep_inverse_values) {
1057 int64_t max_value = -1;
1072 const int size =
Size();
1073 CHECK_LE(size, assignment->
Size())
1074 <<
"Assignment contains fewer variables than operator";
1076 for (
int i = 0; i < size; ++i) {
1078 if (element->
Var() != vars_[i]) {
1079 CHECK(container.
Contains(vars_[i]))
1080 <<
"Assignment does not contain operator variable " << vars_[i];
1081 element = &(container.
Element(vars_[i]));
1091 int Size()
const {
return vars_.size(); }
1095 DCHECK_LT(
index, vars_.size());
1139 candidate_has_changes_ = change_was_incremental &&
IsIncremental();
1141 if (!candidate_has_changes_) {
1143 assignment_indices_[
index] = -1;
1146 state_.
Revert(candidate_has_changes_);
1150 if (!vars.empty()) {
1151 vars_.insert(vars_.end(), vars.begin(), vars.end());
1152 const int64_t size =
Size();
1153 assignment_indices_.resize(size, -1);
1189 std::vector<int>* assignment_indices, int64_t
index,
1194 if (assignment_indices !=
nullptr) {
1195 if ((*assignment_indices)[
index] == -1) {
1196 (*assignment_indices)[
index] = container->
Size();
1213 std::vector<IntVar*> vars_;
1214 mutable std::vector<int> assignment_indices_;
1215 bool candidate_has_changes_ =
false;
1249 explicit BaseLns(
const std::vector<IntVar*>& vars);
1263 void OnStart()
override;
1264 std::vector<int> fragment_;
1273 explicit ChangeValue(
const std::vector<IntVar*>& vars);
1282 void OnStart()
override;
1325 const std::vector<IntVar*>& path_vars,
1328 const std::vector<IntVar*>& path_vars,
int number_of_base_nodes,
1329 bool skip_locally_optimal_paths,
bool accept_path_end_base,
1330 std::function<
int(int64_t)> start_empty_path_class)
1332 next_vars, path_vars,
1333 {number_of_base_nodes, skip_locally_optimal_paths,
1334 accept_path_end_base, std::move(start_empty_path_class)}) {}
1337 void Reset()
override;
1373 int64_t
BaseNode(
int i)
const {
return base_nodes_[i]; }
1379 const int alternative_index = alternative_index_[
BaseNode(i)];
1380 return alternative_index >= 0
1381 ? alternative_sets_[alternative_index][base_alternatives_[i]]
1386 return base_sibling_alternatives_[i];
1391 const int sibling_alternative_index =
1393 return sibling_alternative_index >= 0
1394 ? alternative_sets_[sibling_alternative_index]
1395 [base_sibling_alternatives_[i]]
1399 int64_t
StartNode(
int i)
const {
return path_starts_[base_paths_[i]]; }
1401 int64_t
EndNode(
int i)
const {
return path_ends_[base_paths_[i]]; }
1403 const std::vector<int64_t>&
path_starts()
const {
return path_starts_; }
1464 bool MoveChain(int64_t before_chain, int64_t chain_end, int64_t destination);
1468 bool ReverseChain(int64_t before_chain, int64_t after_chain,
1469 int64_t* chain_last);
1472 bool MakeActive(int64_t node, int64_t destination);
1480 void SetNext(int64_t from, int64_t to, int64_t path) {
1498 return !
IsPathEnd(node) && inactives_[node];
1513 const int alternative = alternative_sets_.size();
1514 for (int64_t node : alternative_set) {
1515 DCHECK_EQ(-1, alternative_index_[node]);
1516 alternative_index_[node] = alternative;
1518 alternative_sets_.push_back(alternative_set);
1519 sibling_alternative_.push_back(-1);
1526 const std::vector<std::pair<std::vector<int64_t>, std::vector<int64_t>>>&
1527 pair_alternative_sets) {
1528 for (
const auto& pair_alternative_set : pair_alternative_sets) {
1530 sibling_alternative_.back() = alternative + 1;
1536 int64_t GetActiveInAlternativeSet(int alternative_index) const {
1537 return alternative_index >= 0
1538 ? active_in_alternative_set_[alternative_index]
1543 return GetActiveInAlternativeSet(alternative_index_[node]);
1547 if (node >= alternative_index_.size())
return -1;
1548 const int alternative = alternative_index_[node];
1549 return alternative >= 0 ? sibling_alternative_[alternative] : -1;
1554 if (node >= alternative_index_.size())
return -1;
1555 const int alternative = alternative_index_[node];
1556 const int sibling_alternative =
1557 alternative >= 0 ? sibling_alternative_[alternative] : -1;
1558 return GetActiveInAlternativeSet(sibling_alternative);
1562 bool CheckChainValidity(int64_t before_chain, int64_t chain_end,
1563 int64_t exclude)
const;
1572 void OnStart()
override;
1574 bool OnSamePath(int64_t node1, int64_t node2)
const;
1576 bool CheckEnds()
const {
1577 const int base_node_size = base_nodes_.size();
1578 for (
int i = base_node_size - 1; i >= 0; --i) {
1579 if (base_nodes_[i] != end_nodes_[i]) {
1585 bool IncrementPosition();
1586 void InitializePathStarts();
1587 void InitializeInactives();
1588 void InitializeBaseNodes();
1589 void InitializeAlternatives();
1592 std::vector<int> base_nodes_;
1593 std::vector<int> base_alternatives_;
1594 std::vector<int> base_sibling_alternatives_;
1595 std::vector<int> end_nodes_;
1596 std::vector<int> base_paths_;
1597 std::vector<int64_t> path_starts_;
1598 std::vector<int64_t> path_ends_;
1599 std::vector<bool> inactives_;
1602 IterationParameters iteration_parameters_;
1603 bool optimal_paths_enabled_;
1604 std::vector<int> path_basis_;
1605 std::vector<bool> optimal_paths_;
1608 std::vector<std::vector<int64_t>> alternative_sets_;
1610 std::vector<int> alternative_index_;
1611 std::vector<int64_t> active_in_alternative_set_;
1612 std::vector<int> sibling_alternative_;
1618 Solver* solver,
const std::vector<IntVar*>& vars,
1619 const std::vector<IntVar*>& secondary_vars,
1620 std::function<
int(int64_t)> start_empty_path_class);
1649 class LocalSearchVariable;
1666 void RelaxVariableBounds(
int variable_index);
1667 bool TightenVariableMin(
int variable_index, int64_t
value);
1668 bool TightenVariableMax(
int variable_index, int64_t
value);
1669 int64_t VariableMin(
int variable_index)
const;
1670 int64_t VariableMax(
int variable_index)
const;
1672 std::vector<Bounds> initial_variable_bounds_;
1673 std::vector<Bounds> variable_bounds_;
1674 std::vector<std::pair<Bounds, int>> saved_variable_bounds_trail_;
1675 std::vector<bool> variable_is_relaxed_;
1676 bool state_is_valid_ =
true;
1686 int64_t
Min()
const {
return state_->VariableMin(variable_index_); }
1687 int64_t
Max()
const {
return state_->VariableMax(variable_index_); }
1689 return state_->TightenVariableMin(variable_index_, new_min);
1692 return state_->TightenVariableMax(variable_index_, new_max);
1694 void Relax() { state_->RelaxVariableBounds(variable_index_); }
1701 : state_(state), variable_index_(variable_index) {}
1704 const int variable_index_;
1742 int64_t objective_min, int64_t objective_max) = 0;
1780 return "LocalSearchFilterManager";
1796 const Assignment* deltadelta, int64_t objective_min,
1797 int64_t objective_max);
1806 void FindIncrementalEventEnd();
1808 std::vector<FilterEvent> events_;
1809 int last_event_called_ = -1;
1814 int incremental_events_end_ = 0;
1815 int64_t synchronized_value_;
1816 int64_t accepted_value_;
1825 void Synchronize(
const Assignment* assignment,
1829 DCHECK(
index !=
nullptr);
1830 const int var_index =
var->index();
1831 *
index = (var_index < var_index_to_index_.size())
1832 ? var_index_to_index_[var_index]
1838 void AddVars(
const std::vector<IntVar*>& vars);
1842 DCHECK(IsVarSynced(
index));
1843 return values_[
index];
1849 void SynchronizeOnAssignment(
const Assignment* assignment);
1852 std::vector<IntVar*>
vars_;
1853 std::vector<int64_t> values_;
1854 std::vector<bool> var_synced_;
1855 std::vector<int> var_index_to_index_;
1863 std::string
DebugString()
const override {
return "PropagationMonitor"; }
1885 int64_t new_max) = 0;
1890 int64_t new_max) = 0;
1896 const std::vector<int64_t>& values) = 0;
1898 const std::vector<int64_t>& values) = 0;
1903 int64_t new_max) = 0;
1907 int64_t new_max) = 0;
1911 int64_t new_max) = 0;
1919 const std::vector<int>& rank_first,
1920 const std::vector<int>& rank_last,
1921 const std::vector<int>& unperformed) = 0;
1923 void Install()
override;
1931 std::string
DebugString()
const override {
return "LocalSearchMonitor"; }
1942 bool neighbor_found) = 0;
1945 bool neighbor_found) = 0;
1950 void Install()
override;
1958 :
IntVar(s,
name), value_(kUnboundBooleanVarValue) {}
1962 int64_t
Min()
const override {
return (value_ == 1); }
1963 void SetMin(int64_t m)
override;
1964 int64_t
Max()
const override {
return (value_ != 0); }
1965 void SetMax(int64_t m)
override;
1966 void SetRange(int64_t mi, int64_t ma)
override;
1967 bool Bound()
const override {
return (value_ != kUnboundBooleanVarValue); }
1969 CHECK_NE(value_, kUnboundBooleanVarValue) <<
"variable is not bound";
1972 void RemoveValue(int64_t v)
override;
1973 void RemoveInterval(int64_t l, int64_t u)
override;
1974 void WhenBound(
Demon* d)
override;
1977 uint64_t Size()
const override;
1978 bool Contains(int64_t v)
const override;
1979 IntVarIterator* MakeHoleIterator(
bool reversible)
const override;
1980 IntVarIterator* MakeDomainIterator(
bool reversible)
const override;
1981 std::string DebugString()
const override;
1984 IntVar* IsEqual(int64_t constant)
override;
1985 IntVar* IsDifferent(int64_t constant)
override;
1986 IntVar* IsGreaterOrEqual(int64_t constant)
override;
1987 IntVar* IsLessOrEqual(int64_t constant)
override;
1990 std::string
BaseName()
const override {
return "BooleanVar"; }
2008 : symmetry_manager_(nullptr), index_in_symmetry_manager_(-1) {}
2011 void AddIntegerVariableEqualValueClause(
IntVar*
const var, int64_t
value);
2012 void AddIntegerVariableGreaterOrEqualValueClause(
IntVar*
const var,
2014 void AddIntegerVariableLessOrEqualValueClause(
IntVar*
const var,
2020 CHECK(symmetry_manager_ ==
nullptr);
2021 CHECK_EQ(-1, index_in_symmetry_manager_);
2022 symmetry_manager_ = manager;
2023 index_in_symmetry_manager_ =
index;
2025 SymmetryManager* symmetry_manager()
const {
return symmetry_manager_; }
2026 int index_in_symmetry_manager()
const {
return index_in_symmetry_manager_; }
2028 SymmetryManager* symmetry_manager_;
2030 int index_in_symmetry_manager_;
2038 double scaling_factor,
double offset,
2039 std::function<std::string()> display_callback,
2040 bool display_on_new_solutions_only,
int period);
2042 void EnterSearch()
override;
2043 void ExitSearch()
override;
2044 bool AtSolution()
override;
2045 void BeginFail()
override;
2046 void NoMoreSolutions()
override;
2048 void ApplyDecision(
Decision*
const decision)
override;
2049 void RefuteDecision(
Decision*
const decision)
override;
2050 void OutputDecision();
2052 void BeginInitialPropagation()
override;
2053 void EndInitialPropagation()
override;
2054 std::string DebugString()
const override;
2058 virtual void OutputLine(
const std::string&
line);
2064 std::unique_ptr<WallTimer> timer_;
2067 const double scaling_factor_;
2069 std::function<std::string()> display_callback_;
2070 const bool display_on_new_solutions_only_;
2073 int64_t objective_min_;
2074 int64_t objective_max_;
2075 int min_right_depth_;
2077 int sliding_min_depth_;
2078 int sliding_max_depth_;
2088 VOID_FALSE_CONSTRAINT = 0,
2094 VAR_CONSTANT_EQUALITY = 0,
2102 VAR_CONSTANT_CONSTANT_BETWEEN = 0,
2107 EXPR_EXPR_EQUALITY = 0,
2124 EXPR_EXPR_DIFFERENCE = 0,
2138 EXPR_EXPR_CONSTANT_CONDITIONAL = 0,
2143 EXPR_CONSTANT_DIFFERENCE = 0,
2156 VAR_CONSTANT_CONSTANT_SEMI_CONTINUOUS = 0,
2161 VAR_CONSTANT_ARRAY_ELEMENT = 0,
2166 VAR_ARRAY_CONSTANT_ARRAY_SCAL_PROD = 0,
2178 VAR_ARRAY_CONSTANT_INDEX = 0,
2206 IntVar*
const var, int64_t value1, int64_t value2,
2267 IntVar*
const var, int64_t value1, int64_t value2,
2277 IntVar*
const var,
const std::vector<int64_t>& values,
2282 const std::vector<int64_t>& values,
2291 const std::vector<IntVar*>& vars,
2297 const std::vector<IntVar*>& vars,
const std::vector<int64_t>& values,
2301 IntExpr*
const expression,
const std::vector<IntVar*>&
var,
2302 const std::vector<int64_t>& values,
2308 const std::vector<IntVar*>& vars, int64_t
value,
2312 IntExpr*
const expression,
const std::vector<IntVar*>&
var, int64_t
value,
2326 const std::string& TypeName()
const;
2327 void SetTypeName(
const std::string& type_name);
2330 void SetIntegerArgument(
const std::string& arg_name, int64_t
value);
2331 void SetIntegerArrayArgument(
const std::string& arg_name,
2332 const std::vector<int64_t>& values);
2333 void SetIntegerMatrixArgument(
const std::string& arg_name,
2335 void SetIntegerExpressionArgument(
const std::string& arg_name,
2337 void SetIntegerVariableArrayArgument(
const std::string& arg_name,
2338 const std::vector<IntVar*>& vars);
2339 void SetIntervalArgument(
const std::string& arg_name,
IntervalVar*
const var);
2340 void SetIntervalArrayArgument(
const std::string& arg_name,
2341 const std::vector<IntervalVar*>& vars);
2342 void SetSequenceArgument(
const std::string& arg_name,
SequenceVar*
const var);
2343 void SetSequenceArrayArgument(
const std::string& arg_name,
2344 const std::vector<SequenceVar*>& vars);
2347 bool HasIntegerExpressionArgument(
const std::string& arg_name)
const;
2348 bool HasIntegerVariableArrayArgument(
const std::string& arg_name)
const;
2351 int64_t FindIntegerArgumentWithDefault(
const std::string& arg_name,
2353 int64_t FindIntegerArgumentOrDie(
const std::string& arg_name)
const;
2354 const std::vector<int64_t>& FindIntegerArrayArgumentOrDie(
2355 const std::string& arg_name)
const;
2356 const IntTupleSet& FindIntegerMatrixArgumentOrDie(
2357 const std::string& arg_name)
const;
2359 IntExpr* FindIntegerExpressionArgumentOrDie(
2360 const std::string& arg_name)
const;
2361 const std::vector<IntVar*>& FindIntegerVariableArrayArgumentOrDie(
2362 const std::string& arg_name)
const;
2365 std::string type_name_;
2366 absl::flat_hash_map<std::string, int64_t> integer_argument_;
2367 absl::flat_hash_map<std::string, std::vector<int64_t>>
2368 integer_array_argument_;
2369 absl::flat_hash_map<std::string, IntTupleSet> matrix_argument_;
2370 absl::flat_hash_map<std::string, IntExpr*> integer_expression_argument_;
2371 absl::flat_hash_map<std::string, IntervalVar*> interval_argument_;
2372 absl::flat_hash_map<std::string, SequenceVar*> sequence_argument_;
2373 absl::flat_hash_map<std::string, std::vector<IntVar*>>
2374 integer_variable_array_argument_;
2375 absl::flat_hash_map<std::string, std::vector<IntervalVar*>>
2376 interval_array_argument_;
2377 absl::flat_hash_map<std::string, std::vector<SequenceVar*>>
2378 sequence_array_argument_;
2389 void BeginVisitModel(
const std::string& solver_name)
override;
2390 void EndVisitModel(
const std::string& solver_name)
override;
2391 void BeginVisitConstraint(
const std::string& type_name,
2392 const Constraint*
const constraint)
override;
2393 void EndVisitConstraint(
const std::string& type_name,
2394 const Constraint*
const constraint)
override;
2395 void BeginVisitIntegerExpression(
const std::string& type_name,
2396 const IntExpr*
const expr)
override;
2397 void EndVisitIntegerExpression(
const std::string& type_name,
2398 const IntExpr*
const expr)
override;
2399 void VisitIntegerVariable(
const IntVar*
const variable,
2400 IntExpr*
const delegate)
override;
2401 void VisitIntegerVariable(
const IntVar*
const variable,
2402 const std::string& operation, int64_t
value,
2403 IntVar*
const delegate)
override;
2404 void VisitIntervalVariable(
const IntervalVar*
const variable,
2405 const std::string& operation, int64_t
value,
2407 void VisitSequenceVariable(
const SequenceVar*
const variable)
override;
2409 void VisitIntegerArgument(
const std::string& arg_name,
2410 int64_t
value)
override;
2411 void VisitIntegerArrayArgument(
const std::string& arg_name,
2412 const std::vector<int64_t>& values)
override;
2413 void VisitIntegerMatrixArgument(
const std::string& arg_name,
2416 void VisitIntegerExpressionArgument(
const std::string& arg_name,
2417 IntExpr*
const argument)
override;
2418 void VisitIntegerVariableArrayArgument(
2419 const std::string& arg_name,
2420 const std::vector<IntVar*>& arguments)
override;
2422 void VisitIntervalArgument(
const std::string& arg_name,
2424 void VisitIntervalArrayArgument(
2425 const std::string& arg_name,
2426 const std::vector<IntervalVar*>& arguments)
override;
2428 void VisitSequenceArgument(
const std::string& arg_name,
2430 void VisitSequenceArrayArgument(
2431 const std::string& arg_name,
2432 const std::vector<SequenceVar*>& arguments)
override;
2435 void PushArgumentHolder();
2436 void PopArgumentHolder();
2440 std::vector<ArgumentHolder*> holders_;
2447 : index_min_(index_min),
2448 index_max_(index_max),
2449 values_(new T[index_max - index_min + 1]) {
2450 DCHECK_LE(index_min, index_max);
2456 DCHECK_GE(
index, index_min_);
2457 DCHECK_LE(
index, index_max_);
2458 return values_[
index - index_min_];
2462 DCHECK_GE(
index, index_min_);
2463 DCHECK_LE(
index, index_max_);
2467 std::string
DebugString()
const override {
return "ArrayWithOffset"; }
2470 const int64_t index_min_;
2471 const int64_t index_max_;
2472 std::unique_ptr<T[]> values_;
2480 template <
class T,
class C>
2484 : block_size_(block_size), block_offset_(0) {
2485 CHECK_GT(block_size, 0);
2489 for (
int i = 0; i < elements_.size(); ++i) {
2490 delete[] elements_[i];
2495 const int64_t block_index = ComputeBlockIndex(
index);
2496 const int64_t relative_index = block_index - block_offset_;
2497 if (relative_index < 0 || relative_index >= elements_.size()) {
2500 const T* block = elements_[relative_index];
2501 return block !=
nullptr ? block[
index - block_index * block_size_] : T();
2505 const int64_t block_index = ComputeBlockIndex(
index);
2506 T*
const block = GetOrCreateBlock(block_index);
2507 const int64_t residual =
index - block_index * block_size_;
2509 reinterpret_cast<C
>(
value));
2513 T* NewBlock()
const {
2514 T*
const result =
new T[block_size_];
2515 for (
int i = 0; i < block_size_; ++i) {
2521 T* GetOrCreateBlock(
int block_index) {
2522 if (elements_.size() == 0) {
2523 block_offset_ = block_index;
2524 GrowUp(block_index);
2525 }
else if (block_index < block_offset_) {
2526 GrowDown(block_index);
2527 }
else if (block_index - block_offset_ >= elements_.size()) {
2528 GrowUp(block_index);
2530 T* block = elements_[block_index - block_offset_];
2531 if (block ==
nullptr) {
2533 elements_[block_index - block_offset_] = block;
2538 int64_t ComputeBlockIndex(int64_t
value)
const {
2540 : (
value - block_size_ + 1) / block_size_;
2543 void GrowUp(int64_t block_index) {
2544 elements_.resize(block_index - block_offset_ + 1);
2547 void GrowDown(int64_t block_index) {
2548 const int64_t
delta = block_offset_ - block_index;
2549 block_offset_ = block_index;
2550 DCHECK_GT(
delta, 0);
2551 elements_.insert(elements_.begin(),
delta,
nullptr);
2554 const int64_t block_size_;
2555 std::vector<T*> elements_;
2566 static constexpr
int kNoInserted = -1;
2574 delete_position_(true) {
2575 for (
int i = 0; i <
capacity; ++i) {
2576 position_[i] = kNoInserted;
2585 position_(shared_positions),
2586 delete_position_(false) {
2587 for (
int i = 0; i < shared_positions_size; ++i) {
2588 position_[i] = kNoInserted;
2593 if (delete_position_) {
2598 int Size()
const {
return num_elements_.Value(); }
2604 DCHECK_LT(i, num_elements_.Value());
2605 return elements_[i];
2610 DCHECK_LT(i + num_elements_.Value(), capacity_);
2611 return elements_[i + num_elements_.Value()];
2615 const int position = num_elements_.Value();
2616 DCHECK_LT(position, capacity_);
2617 DCHECK(NotAlreadyInserted(elt));
2618 elements_[position] = elt;
2619 position_[elt] = position;
2620 num_elements_.Incr(solver);
2624 num_elements_.Decr(solver);
2625 SwapTo(value_index, num_elements_.Value());
2629 SwapTo(value_index, num_elements_.Value());
2630 num_elements_.Incr(solver);
2633 void Clear(
Solver*
const solver) { num_elements_.SetValue(solver, 0); }
2642 bool NotAlreadyInserted(
const T& elt) {
2643 for (
int i = 0; i < num_elements_.Value(); ++i) {
2644 if (elt == elements_[i]) {
2651 void SwapTo(T value_index,
int next_position) {
2652 const int current_position = position_[value_index];
2653 if (current_position != next_position) {
2654 const T next_value_index = elements_[next_position];
2655 elements_[current_position] = next_value_index;
2656 elements_[next_position] = value_index;
2657 position_[value_index] = next_position;
2658 position_[next_value_index] = current_position;
2663 std::unique_ptr<T[]> elements_;
2665 NumericalRev<int> num_elements_;
2667 const int capacity_;
2671 const bool delete_position_;
2681 last_ranked_(items.size() - 1),
2682 size_(items.size()),
2683 position_(new int[size_]) {
2684 for (
int i = 0; i < size_; ++i) {
2685 elements_[i] = items[i];
2693 last_ranked_(size - 1),
2695 position_(new int[size_]) {
2696 for (
int i = 0; i < size_; ++i) {
2712 DCHECK_GE(
index, 0);
2713 DCHECK_LT(
index, size_);
2714 return elements_[
index];
2719 DCHECK_LE(first_ranked_.Value(), last_ranked_.Value());
2720 SwapTo(elt, first_ranked_.Value());
2721 first_ranked_.Incr(solver);
2725 DCHECK_LE(first_ranked_.Value(), last_ranked_.Value());
2726 SwapTo(elt, last_ranked_.Value());
2727 last_ranked_.Decr(solver);
2731 const int position = position_[elt];
2732 return (position < first_ranked_.Value() ||
2733 position > last_ranked_.Value());
2737 std::string result =
"[";
2738 for (
int i = 0; i < first_ranked_.Value(); ++i) {
2739 absl::StrAppend(&result, elements_[i]);
2740 if (i != first_ranked_.Value() - 1) {
2745 for (
int i = first_ranked_.Value(); i <= last_ranked_.Value(); ++i) {
2746 absl::StrAppend(&result, elements_[i]);
2747 if (i != last_ranked_.Value()) {
2752 for (
int i = last_ranked_.Value() + 1; i < size_; ++i) {
2753 absl::StrAppend(&result, elements_[i]);
2754 if (i != size_ - 1) {
2763 void SwapTo(
int elt,
int next_position) {
2764 const int current_position = position_[elt];
2765 if (current_position != next_position) {
2766 const int next_elt = elements_[next_position];
2767 elements_[current_position] = next_elt;
2768 elements_[next_position] = elt;
2769 position_[elt] = next_position;
2770 position_[next_elt] = current_position;
2775 std::vector<int> elements_;
2777 NumericalRev<int> first_ranked_;
2779 NumericalRev<int> last_ranked_;
2783 std::unique_ptr<int[]> position_;
2799 void Init(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2803 bool RevSubtract(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2807 bool RevAnd(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2814 bool Empty()
const {
return active_words_.Size() == 0; }
2823 bool Intersects(
const std::vector<uint64_t>& mask,
int* support_index);
2833 void CleanUpActives(
Solver*
const solver);
2835 const int64_t bit_size_;
2836 const int64_t word_size_;
2844 for (
int i = 0; i < values.size(); ++i) {
2845 if (values[i] !=
value) {
2854 for (
int i = 0; i < values.size(); ++i) {
2855 if (values[i] != 0 && values[i] != 1) {
2874 for (
const T& current_value : values) {
2875 if (current_value <
value) {
2884 for (
const T& current_value : values) {
2885 if (current_value >
value) {
2914 for (
int i = 0; i < values.size() - 1; ++i) {
2915 if (values[i + 1] != values[i] + 1) {
2924 for (
int i = 0; i < values.size() - 1; ++i) {
2925 if (values[i + 1] < values[i]) {
2935 for (
int i = 0; i < vars.size(); ++i) {
2936 if (vars[i]->Min() < range_min || vars[i]->Max() > range_max) {
2944 for (
int i = 0; i < vars.size(); ++i) {
2945 if (!vars[i]->Bound()) {
2960 const std::vector<T>& values) {
2961 for (
int i = 0; i < vars.size(); ++i) {
2962 if (values[i] != 0 && !vars[i]->Bound()) {
2971 for (
int i = 0; i < vars.size(); ++i) {
2972 if (!vars[i]->Bound() || vars[i]->Min() !=
value) {
2980 DCHECK(!vars.empty());
2982 for (
int i = 0; i < vars.size(); ++i) {
2984 result = std::max<int64_t>(result, vars[i]->Max());
2990 DCHECK(!vars.empty());
2992 for (
int i = 0; i < vars.size(); ++i) {
2994 result = std::min<int64_t>(result, vars[i]->Min());
3000 std::vector<int64_t>*
const values) {
3002 values->resize(vars.size());
3003 for (
int i = 0; i < vars.size(); ++i) {
3004 (*values)[i] = vars[i]->Value();
3010 return (e < 0 || e % v == 0) ? e / v : e / v + 1;
3015 return (e >= 0 || e % v == 0) ? e / v : e / v - 1;
3075 : begin_index(begin_index), end_index(end_index) {}
3084 PathState(
int num_nodes, std::vector<int> path_start,
3085 std::vector<int> path_end);
3094 int Start(
int path)
const {
return path_start_end_[path].start; }
3096 int End(
int path)
const {
return path_start_end_[path].end; }
3102 return committed_nodes_[committed_index_[node]].path;
3110 ChainRange Chains(
int path)
const;
3112 NodeRange Nodes(
int path)
const;
3121 void ChangePath(
int path,
const std::vector<ChainBounds>& chains);
3124 void ChangePath(
int path,
const std::initializer_list<ChainBounds>& chains) {
3125 changed_paths_.push_back(path);
3126 const int path_begin_index = chains_.size();
3127 chains_.insert(chains_.end(), chains.begin(), chains.end());
3128 const int path_end_index = chains_.size();
3129 paths_[path] = {path_begin_index, path_end_index};
3131 chains_.emplace_back(0, 0);
3135 void ChangeLoops(
const std::vector<int>& new_loops);
3151 struct PathStartEnd {
3161 struct CommittedNode {
3162 CommittedNode(
int node,
int path) : node(node), path(path) {}
3172 void CopyNewPathAtEndOfNodes(
int path);
3175 void IncrementalCommit();
3181 const int num_nodes_;
3182 const int num_paths_;
3183 std::vector<PathStartEnd> path_start_end_;
3211 std::vector<CommittedNode> committed_nodes_;
3212 std::vector<int> committed_index_;
3213 const int num_nodes_threshold_;
3214 std::vector<ChainBounds> chains_;
3215 std::vector<PathBounds> paths_;
3218 std::vector<int> changed_paths_;
3219 std::vector<int> changed_loops_;
3222 bool is_invalid_ =
false;
3236 return current_node_ != other.current_node_;
3242 explicit Iterator(
const CommittedNode* node) : current_node_(node) {}
3243 const CommittedNode* current_node_;
3248 Chain(
const CommittedNode* begin_node,
const CommittedNode* end_node)
3249 : begin_(begin_node), end_(end_node) {}
3252 int First()
const {
return begin_->node; }
3253 int Last()
const {
return (end_ - 1)->node; }
3260 const CommittedNode*
const begin_;
3261 const CommittedNode*
const end_;
3274 return {first_node_ + current_chain_->begin_index,
3275 first_node_ + current_chain_->end_index};
3278 return current_chain_ != other.current_chain_;
3285 : current_chain_(chain), first_node_(first_node) {}
3287 const CommittedNode*
const first_node_;
3294 const CommittedNode*
const first_node)
3295 : begin_(begin_chain), end_(end_chain), first_node_(first_node) {}
3303 const CommittedNode*
const first_node_;
3314 if (current_node_ == end_node_) {
3319 current_node_ = first_node_ +
bounds.begin_index;
3320 end_node_ = first_node_ +
bounds.end_index;
3326 return current_chain_ != other.current_chain_;
3333 const CommittedNode*
const first_node)
3334 : current_node_(first_node + current_chain->begin_index),
3335 end_node_(first_node + current_chain->end_index),
3336 current_chain_(current_chain),
3337 first_node_(first_node) {}
3338 const CommittedNode* current_node_;
3339 const CommittedNode* end_node_;
3341 const CommittedNode*
const first_node_;
3347 const CommittedNode* first_node)
3348 : begin_chain_(begin_chain),
3349 end_chain_(end_chain),
3350 first_node_(first_node) {}
3359 const CommittedNode*
const first_node_;
3391 std::vector<Interval> path_capacity,
3392 std::vector<int> path_class,
3393 std::vector<std::function<
Interval(int64_t, int64_t)>>
3394 demand_per_path_class,
3395 std::vector<Interval> node_capacity,
3396 int min_range_size_for_riq = kOptimalMinRangeSizeForRIQ);
3406 static constexpr
int kOptimalMinRangeSizeForRIQ = 4;
3413 int first_node_index,
int last_node_index,
3420 int first_node_index,
int last_node_index)
const;
3426 int last_node_index)
const;
3431 int last_node_index)
const;
3437 void IncrementalCommit();
3440 void AppendPathDemandsToSums(
int path);
3446 void UpdateRIQStructure(
int begin_index,
int end_index);
3449 const std::vector<ExtendedInterval> path_capacity_;
3450 const std::vector<int> path_class_;
3451 const std::vector<std::function<
Interval(int64_t, int64_t)>>
3452 demand_per_path_class_;
3453 std::vector<ExtendedInterval> cached_demand_;
3454 const std::vector<ExtendedInterval> node_capacity_;
3460 std::vector<int> index_;
3467 std::vector<std::vector<ExtendedInterval>> forwards_demand_sums_riq_;
3470 std::vector<std::vector<ExtendedInterval>> forwards_node_capacity_riq_;
3473 std::vector<std::vector<ExtendedInterval>> backwards_node_capacity_riq_;
3476 const int maximum_riq_layer_size_;
3478 const int min_range_size_for_riq_;
3487 std::unique_ptr<PathState> path_state,
3488 const std::vector<IntVar*>& nexts);
3498 Solver* solver, std::unique_ptr<DimensionChecker> checker,
3499 const std::string& dimension_name);
const std::vector< IntVar * > vars_
int64_t MemoryUsage(int unused)
Argument Holder: useful when visiting a model.
virtual T Evaluate(int64_t index) const
~ArrayWithOffset() override
ArrayWithOffset(int64_t index_min, int64_t index_max)
void SetValue(int64_t index, T value)
std::string DebugString() const override
E * MutableElement(const V *const var)
bool Contains(const V *const var) const
const E & Element(const V *const var) const
An Assignment is a variable -> domains mapping, used to report solutions to the user.
IntContainer * MutableIntVarContainer()
const IntContainer & IntVarContainer() const
IntVarElement * FastAdd(IntVar *const var)
Adds without checking if variable has been previously added.
BaseIntExpr(Solver *const s)
virtual IntVar * CastToVar()
IntVar * Var() override
Creates a variable from the expression.
This is the base class for building an Lns operator.
virtual bool NextFragment()=0
bool HasFragments() const override
void AppendToFragment(int index)
BaseLns(const std::vector< IntVar * > &vars)
bool MakeOneNeighbor() override
This method should not be overridden. Override NextFragment() instead.
virtual void InitFragments()
A BaseObject is the root of all reversibly allocated objects.
void Resize(IndexType size)
void CopyBucket(const Bitset64< IndexType > &other, IndexType i)
int VarType() const override
virtual void RestoreValue()=0
bool Bound() const override
Returns true if the min and the max of the expression are equal.
void WhenRange(Demon *d) override
Attach a demon that will watch the min or the max of the expression.
SimpleRevFIFO< Demon * > delayed_bound_demons_
int64_t Min() const override
void WhenDomain(Demon *d) override
This method attaches a demon that will watch any domain modification of the domain of the variable.
static const int kUnboundBooleanVarValue
int64_t Value() const override
This method returns the value of the variable.
int64_t Max() const override
SimpleRevFIFO< Demon * > bound_demons_
std::string BaseName() const override
Returns a base name for automatic naming.
BooleanVar(Solver *const s, const std::string &name="")
Demon proxy to a method on the constraint with no arguments.
CallMethod0(T *const ct, void(T::*method)(), const std::string &name)
void Run(Solver *const s) override
This is the main callback of the demon.
std::string DebugString() const override
Demon proxy to a method on the constraint with one argument.
void Run(Solver *const s) override
This is the main callback of the demon.
std::string DebugString() const override
CallMethod1(T *const ct, void(T::*method)(P), const std::string &name, P param1)
Demon proxy to a method on the constraint with two arguments.
CallMethod2(T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
void Run(Solver *const s) override
This is the main callback of the demon.
std::string DebugString() const override
Demon proxy to a method on the constraint with three arguments.
CallMethod3(T *const ct, void(T::*method)(P, Q, R), const std::string &name, P param1, Q param2, R param3)
void Run(Solver *const s) override
This is the main callback of the demon.
std::string DebugString() const override
Defines operators which change the value of variables; each neighbor corresponds to one modified vari...
ChangeValue(const std::vector< IntVar * > &vars)
virtual int64_t ModifyValue(int64_t index, int64_t value)=0
bool MakeOneNeighbor() override
This method should not be overridden. Override ModifyValue() instead.
A constraint is the main modeling object.
A Decision represents a choice point in the search tree.
A DecisionVisitor is used to inspect a decision.
Low-priority demon proxy to a method on the constraint with no arguments.
Solver::DemonPriority priority() const override
This method returns the priority of the demon.
~DelayedCallMethod0() override
void Run(Solver *const s) override
This is the main callback of the demon.
DelayedCallMethod0(T *const ct, void(T::*method)(), const std::string &name)
std::string DebugString() const override
Low-priority demon proxy to a method on the constraint with one argument.
Solver::DemonPriority priority() const override
This method returns the priority of the demon.
DelayedCallMethod1(T *const ct, void(T::*method)(P), const std::string &name, P param1)
void Run(Solver *const s) override
This is the main callback of the demon.
std::string DebugString() const override
~DelayedCallMethod1() override
Low-priority demon proxy to a method on the constraint with two arguments.
Solver::DemonPriority priority() const override
This method returns the priority of the demon.
~DelayedCallMethod2() override
DelayedCallMethod2(T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
void Run(Solver *const s) override
This is the main callback of the demon.
std::string DebugString() const override
A Demon is the base element of a propagation queue.
The class IntExpr is the base of all integer expressions in constraint programming.
virtual bool Bound() const
Returns true if the min and the max of the expression are equal.
virtual void SetValue(int64_t v)
This method sets the value of the expression.
virtual int64_t Min() const =0
virtual int64_t Max() const =0
The class IntVar is a subset of IntExpr.
virtual void WhenBound(Demon *d)=0
This method attaches a demon that will be awakened when the variable is bound.
The class Iterator has two direct subclasses.
virtual void OnSynchronize(const Assignment *delta)
bool FindIndex(IntVar *const var, int64_t *index) const
int64_t Value(int index) const
IntVar * Var(int index) const
bool IsVarSynced(int index) const
Specialization of LocalSearchOperator built from an array of IntVars which specifies the scope of the...
void Activate(int64_t index)
void SetValue(int64_t index, int64_t value)
void Deactivate(int64_t index)
int64_t OldInverseValue(int64_t index) const
virtual bool SkipUnchanged(int index) const
bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta) override
OnStart() should really be protected, but then SWIG doesn't see it.
int64_t InverseValue(int64_t index) const
bool HoldsDelta() const override
void RevertChanges(bool change_was_incremental)
~IntVarLocalSearchOperator() override
bool Activated(int64_t index) const
virtual bool IsIncremental() const
bool ApplyChanges(Assignment *delta, Assignment *deltadelta) const
virtual void OnStart()
Called by Start() after synchronizing the operator with the current assignment.
int64_t PrevValue(int64_t index) const
int64_t OldValue(int64_t index) const
int64_t Value(int64_t index) const
Returns the value in the current assignment of the variable of given index.
virtual bool MakeOneNeighbor()
Creates a new neighbor.
IntVarLocalSearchOperator(const std::vector< IntVar * > &vars, bool keep_inverse_values=false)
IntVar * Var(int64_t index) const
Returns the variable of given index.
void AddVars(const std::vector< IntVar * > &vars)
void AddToAssignment(IntVar *var, int64_t value, bool active, std::vector< int > *assignment_indices, int64_t index, Assignment *assignment) const
void Start(const Assignment *assignment) override
This method should not be overridden.
Interval variables are often used in scheduling.
LightIntFunctionElementCt(Solver *const solver, IntVar *const var, IntVar *const index, F values, std::function< bool()> deep_serialize)
void Post() override
This method is called when the constraint is processed by the solver.
void InitialPropagate() override
This method performs the initial propagation of the constraint.
~LightIntFunctionElementCt() override
void Accept(ModelVisitor *const visitor) const override
Accepts the given visitor.
std::string DebugString() const override
void Post() override
This method is called when the constraint is processed by the solver.
void InitialPropagate() override
This method performs the initial propagation of the constraint.
LightIntIntFunctionElementCt(Solver *const solver, IntVar *const var, IntVar *const index1, IntVar *const index2, F values, std::function< bool()> deep_serialize)
void Accept(ModelVisitor *const visitor) const override
Accepts the given visitor.
~LightIntIntFunctionElementCt() override
std::string DebugString() const override
Local Search Filters are used for fast neighbor pruning.
virtual void Synchronize(const Assignment *assignment, const Assignment *delta)=0
Synchronizes the filter with the current solution, delta being the difference with the solution passe...
virtual int64_t GetAcceptedObjectiveValue() const
Objective value from the last time Accept() was called and returned true.
virtual void Reset()
Sets the filter to empty solution.
virtual void Relax(const Assignment *delta, const Assignment *deltadelta)
Lets the filter know what delta and deltadelta will be passed in the next Accept().
virtual bool Accept(const Assignment *delta, const Assignment *deltadelta, int64_t objective_min, int64_t objective_max)=0
Accepts a "delta" given the assignment with which the filter has been synchronized; the delta holds t...
virtual bool IsIncremental() const
virtual int64_t GetSynchronizedObjectiveValue() const
Objective value from last time Synchronize() was called.
virtual void Revert()
Cancels the changes made by the last Relax()/Accept() calls.
virtual void Commit(const Assignment *delta, const Assignment *deltadelta)
Dual of Relax(), lets the filter know that the delta was accepted.
Filter manager: when a move is made, filters are executed to decide whether the solution is feasible ...
int64_t GetAcceptedObjectiveValue() const
int64_t GetSynchronizedObjectiveValue() const
std::string DebugString() const override
virtual void EndMakeNextNeighbor(const LocalSearchOperator *op, bool neighbor_found, const Assignment *delta, const Assignment *deltadelta)=0
virtual void EndAcceptNeighbor(const LocalSearchOperator *op, bool neighbor_found)=0
virtual void EndOperatorStart()=0
virtual void BeginMakeNextNeighbor(const LocalSearchOperator *op)=0
virtual void BeginOperatorStart()=0
Local search operator events.
virtual void EndFiltering(const LocalSearchFilter *filter, bool reject)=0
virtual void BeginFilterNeighbor(const LocalSearchOperator *op)=0
virtual void BeginAcceptNeighbor(const LocalSearchOperator *op)=0
virtual void BeginFiltering(const LocalSearchFilter *filter)=0
virtual void EndFilterNeighbor(const LocalSearchOperator *op, bool neighbor_found)=0
std::string DebugString() const override
The base class for all local search operators.
virtual bool HasFragments() const
virtual bool HoldsDelta() const
virtual const LocalSearchOperator * Self() const
virtual bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta)=0
virtual void Start(const Assignment *assignment)=0
~LocalSearchOperator() override
int64_t CandidateInverseValue(int64_t value) const
bool CandidateIsActive(int64_t index) const
void SetCandidateValue(int64_t index, int64_t value)
int64_t CheckPointValue(int64_t index) const
LocalSearchOperatorState()
int64_t CandidateValue(int64_t index) const
Returns the value in the current assignment of the variable of given index.
void Revert(bool only_incremental)
void SetCurrentDomainInjectiveAndKeepInverseValues(int max_value)
void SetCandidateActive(int64_t index, bool active)
int64_t CommittedInverseValue(int64_t value) const
const std::vector< int64_t > & IncrementalIndicesChanged() const
int64_t CommittedValue(int64_t index) const
const std::vector< int64_t > & CandidateIndicesChanged() const
bool StateIsValid() const
bool SetMax(int64_t new_max)
bool SetMin(int64_t new_min)
Implements a complete cache for model elements: expressions and constraints.
ExprConstantExpressionType
@ EXPR_CONSTANT_EXPRESSION_MAX
@ EXPR_CONSTANT_IS_GREATER_OR_EQUAL
@ EXPR_CONSTANT_IS_NOT_EQUAL
@ EXPR_CONSTANT_IS_LESS_OR_EQUAL
virtual void InsertExprExprConstantExpression(IntExpr *const expression, IntExpr *const var1, IntExpr *const var2, int64_t constant, ExprExprConstantExpressionType type)=0
VarConstantConstraintType
@ VAR_CONSTANT_GREATER_OR_EQUAL
@ VAR_CONSTANT_NON_EQUALITY
@ VAR_CONSTANT_CONSTRAINT_MAX
@ VAR_CONSTANT_LESS_OR_EQUAL
virtual IntExpr * FindExprExprConstantExpression(IntExpr *const var1, IntExpr *const var2, int64_t constant, ExprExprConstantExpressionType type) const =0
Expr Expr Constant Expressions.
virtual IntExpr * FindVarConstantArrayExpression(IntVar *const var, const std::vector< int64_t > &values, VarConstantArrayExpressionType type) const =0
Var Constant Array Expressions.
virtual void InsertExprExprExpression(IntExpr *const expression, IntExpr *const var1, IntExpr *const var2, ExprExprExpressionType type)=0
virtual void InsertVarConstantArrayExpression(IntExpr *const expression, IntVar *const var, const std::vector< int64_t > &values, VarConstantArrayExpressionType type)=0
VarArrayConstantArrayExpressionType
@ VAR_ARRAY_CONSTANT_ARRAY_EXPRESSION_MAX
virtual IntExpr * FindVarArrayConstantExpression(const std::vector< IntVar * > &vars, int64_t value, VarArrayConstantExpressionType type) const =0
Var Array Constant Expressions.
VarConstantConstantExpressionType
@ VAR_CONSTANT_CONSTANT_EXPRESSION_MAX
VarConstantConstantConstraintType
@ VAR_CONSTANT_CONSTANT_CONSTRAINT_MAX
virtual void InsertVoidConstraint(Constraint *const ct, VoidConstraintType type)=0
@ EXPR_EXPR_EXPRESSION_MAX
@ EXPR_EXPR_IS_LESS_OR_EQUAL
@ EXPR_EXPR_GREATER_OR_EQUAL
@ EXPR_EXPR_CONSTRAINT_MAX
@ EXPR_EXPR_LESS_OR_EQUAL
virtual void InsertVarArrayExpression(IntExpr *const expression, const std::vector< IntVar * > &vars, VarArrayExpressionType type)=0
virtual Constraint * FindExprExprConstraint(IntExpr *const expr1, IntExpr *const expr2, ExprExprConstraintType type) const =0
Expr Expr Constraints.
virtual IntExpr * FindExprExpression(IntExpr *const expr, ExprExpressionType type) const =0
Expr Expressions.
virtual Constraint * FindVoidConstraint(VoidConstraintType type) const =0
Void constraints.
virtual void InsertVarArrayConstantExpression(IntExpr *const expression, const std::vector< IntVar * > &var, int64_t value, VarArrayConstantExpressionType type)=0
ExprExprConstantExpressionType
@ EXPR_EXPR_CONSTANT_EXPRESSION_MAX
virtual void InsertVarConstantConstraint(Constraint *const ct, IntVar *const var, int64_t value, VarConstantConstraintType type)=0
virtual Constraint * FindVarConstantConstraint(IntVar *const var, int64_t value, VarConstantConstraintType type) const =0
Var Constant Constraints.
virtual IntExpr * FindExprConstantExpression(IntExpr *const expr, int64_t value, ExprConstantExpressionType type) const =0
Expr Constant Expressions.
VarArrayConstantExpressionType
@ VAR_ARRAY_CONSTANT_EXPRESSION_MAX
virtual void InsertVarArrayConstantArrayExpression(IntExpr *const expression, const std::vector< IntVar * > &var, const std::vector< int64_t > &values, VarArrayConstantArrayExpressionType type)=0
virtual void InsertExprConstantExpression(IntExpr *const expression, IntExpr *const var, int64_t value, ExprConstantExpressionType type)=0
@ VAR_ARRAY_EXPRESSION_MAX
virtual void InsertVarConstantConstantExpression(IntExpr *const expression, IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantExpressionType type)=0
virtual IntExpr * FindExprExprExpression(IntExpr *const var1, IntExpr *const var2, ExprExprExpressionType type) const =0
Expr Expr Expressions.
VarConstantArrayExpressionType
@ VAR_CONSTANT_ARRAY_EXPRESSION_MAX
virtual IntExpr * FindVarConstantConstantExpression(IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantExpressionType type) const =0
Var Constant Constant Expressions.
virtual IntExpr * FindVarArrayExpression(const std::vector< IntVar * > &vars, VarArrayExpressionType type) const =0
Var Array Expressions.
virtual void InsertVarConstantConstantConstraint(Constraint *const ct, IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantConstraintType type)=0
virtual Constraint * FindVarConstantConstantConstraint(IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantConstraintType type) const =0
Var Constant Constant Constraints.
virtual IntExpr * FindVarArrayConstantArrayExpression(const std::vector< IntVar * > &vars, const std::vector< int64_t > &values, VarArrayConstantArrayExpressionType type) const =0
Var Array Constant Array Expressions.
virtual void InsertExprExpression(IntExpr *const expression, IntExpr *const expr, ExprExpressionType type)=0
virtual void InsertExprExprConstraint(Constraint *const ct, IntExpr *const expr1, IntExpr *const expr2, ExprExprConstraintType type)=0
static const char kIndex2Argument[]
static const char kMinArgument[]
virtual void VisitIntegerArgument(const std::string &arg_name, int64_t value)
Visit integer arguments.
void VisitInt64ToInt64Extension(const Solver::IndexEvaluator1 &eval, int64_t index_min, int64_t index_max)
static const char kTargetArgument[]
static const char kMaxArgument[]
static const char kLightElementEqual[]
virtual void EndVisitConstraint(const std::string &type_name, const Constraint *const constraint)
virtual void VisitIntegerExpressionArgument(const std::string &arg_name, IntExpr *const argument)
Visit integer expression argument.
static const char kIndexArgument[]
virtual void BeginVisitConstraint(const std::string &type_name, const Constraint *const constraint)
void Decr(Solver *const s)
void Incr(Solver *const s)
This class encapsulates an objective.
Base class of the local search operators dedicated to path modifications (a path is a set of nodes li...
int64_t StartNode(int i) const
Returns the start node of the ith base node.
bool IsInactive(int64_t node) const
Returns true if node is inactive.
int64_t OldPrev(int64_t node) const
virtual bool ConsiderAlternatives(int64_t base_index) const
Indicates if alternatives should be considered when iterating over base nodes.
virtual bool MakeNeighbor()=0
int PathClass(int i) const
Returns the class of the path of the ith base node.
virtual void OnNodeInitialization()
Called by OnStart() after initializing node information.
virtual bool OnSamePathAsPreviousBase(int64_t base_index)
Returns true if a base node has to be on the same path as the "previous" base node (base node of inde...
int64_t OldPath(int64_t node) const
bool IsPathStart(int64_t node) const
Returns true if node is the first node on the path.
int64_t GetActiveAlternativeNode(int node) const
Returns the active node in the alternative set of the given node.
int number_of_nexts() const
Number of next variables.
int AddAlternativeSet(const std::vector< int64_t > &alternative_set)
Handling node alternatives.
virtual bool RestartAtPathStartOnSynchronize()
When the operator is being synchronized with a new solution (when Start() is called),...
bool IsPathEnd(int64_t node) const
Returns true if node is the last node on the path; defined by the fact that node is outside the range...
int BaseSiblingAlternative(int i) const
Returns the alternative for the sibling of the ith base node.
int64_t Next(int64_t node) const
Returns the node after node in the current delta.
bool MoveChain(int64_t before_chain, int64_t chain_end, int64_t destination)
Moves the chain starting after the node before_chain and ending at the node chain_end after the node ...
bool MakeActive(int64_t node, int64_t destination)
Insert the inactive node after destination.
int BaseAlternative(int i) const
Returns the alternative for the ith base node.
bool ReverseChain(int64_t before_chain, int64_t after_chain, int64_t *chain_last)
Reverses the chain starting after before_chain and ending before after_chain.
std::vector< int64_t > start_to_path_
const std::vector< int64_t > & path_starts() const
Returns the vector of path start nodes.
void SetNext(int64_t from, int64_t to, int64_t path)
Sets 'to' to be the node after 'from' on the given path.
int64_t BaseSiblingAlternativeNode(int i) const
Returns the alternative node for the sibling of the ith base node.
int64_t Prev(int64_t node) const
Returns the node before node in the current delta.
int64_t GetActiveAlternativeSibling(int node) const
Returns the active node in the alternative set of the sibling of the given node.
int64_t OldNext(int64_t node) const
bool SkipUnchanged(int index) const override
const int number_of_nexts_
bool SwapActiveAndInactive(int64_t active, int64_t inactive)
Replaces active by inactive in the current path, making active inactive.
void ResetPosition()
Reset the position of the operator to its position when Start() was last called; this can be used to ...
virtual int64_t GetBaseNodeRestartPosition(int base_index)
Returns the index of the node to which the base node of index base_index must be set to when it reach...
int64_t BaseNode(int i) const
Returns the ith base node of the operator.
PathOperator(const std::vector< IntVar * > &next_vars, const std::vector< IntVar * > &path_vars, int number_of_base_nodes, bool skip_locally_optimal_paths, bool accept_path_end_base, std::function< int(int64_t)> start_empty_path_class)
int next_base_to_increment_
int64_t BaseAlternativeNode(int i) const
Returns the alternative node for the ith base node.
int GetSiblingAlternativeIndex(int node) const
Returns the index of the alternative set of the sibling of node.
bool MakeOneNeighbor() override
This method should not be overridden. Override MakeNeighbor() instead.
void AddPairAlternativeSets(const std::vector< std::pair< std::vector< int64_t >, std::vector< int64_t >>> &pair_alternative_sets)
Adds all sets of node alternatives of a vector of alternative pairs.
int64_t Path(int64_t node) const
Returns the index of the path to which node belongs in the current delta.
virtual bool InitPosition() const
Returns true if the operator needs to restart its initial position at each call to Start()
const bool ignore_path_vars_
PathOperator(const std::vector< IntVar * > &next_vars, const std::vector< IntVar * > &path_vars, IterationParameters iteration_parameters)
Builds an instance of PathOperator from next and path variables.
virtual void SetNextBaseToIncrement(int64_t base_index)
Set the next base to increment on next iteration.
int64_t EndNode(int i) const
Returns the end node of the ith base node.
int64_t PrevNext(int64_t node) const
bool MakeChainInactive(int64_t before_chain, int64_t chain_end)
Makes the nodes on the chain starting after before_chain and ending at chain_end inactive.
bool operator!=(Iterator other) const
Chain WithoutFirstNode() const
Chain(const CommittedNode *begin_node, const CommittedNode *end_node)
bool operator!=(Iterator other) const
ChainRange(const ChainBounds *const begin_chain, const ChainBounds *const end_chain, const CommittedNode *const first_node)
bool operator!=(Iterator other) const
NodeRange(const ChainBounds *begin_chain, const ChainBounds *end_chain, const CommittedNode *first_node)
const std::vector< int > & ChangedPaths() const
int CommittedIndex(int node) const
ChainBounds CommittedPathRange(int path) const
void ChangePath(int path, const std::initializer_list< ChainBounds > &chains)
int Start(int path) const
const std::vector< int > & ChangedLoops() const
std::string DebugString() const override
virtual void SetValues(IntVar *const var, const std::vector< int64_t > &values)=0
virtual void SetDurationMax(IntervalVar *const var, int64_t new_max)=0
virtual void SetDurationRange(IntervalVar *const var, int64_t new_min, int64_t new_max)=0
virtual void SetMax(IntExpr *const expr, int64_t new_max)=0
virtual void RankLast(SequenceVar *const var, int index)=0
virtual void EndConstraintInitialPropagation(Constraint *const constraint)=0
virtual void SetMin(IntVar *const var, int64_t new_min)=0
IntVar modifiers.
virtual void RemoveValue(IntVar *const var, int64_t value)=0
virtual void SetValue(IntVar *const var, int64_t value)=0
virtual void SetDurationMin(IntervalVar *const var, int64_t new_min)=0
virtual void SetStartMin(IntervalVar *const var, int64_t new_min)=0
IntervalVar modifiers.
virtual void RankNotLast(SequenceVar *const var, int index)=0
virtual void RankNotFirst(SequenceVar *const var, int index)=0
virtual void BeginDemonRun(Demon *const demon)=0
virtual void SetRange(IntExpr *const expr, int64_t new_min, int64_t new_max)=0
virtual void RankSequence(SequenceVar *const var, const std::vector< int > &rank_first, const std::vector< int > &rank_last, const std::vector< int > &unperformed)=0
virtual void SetEndRange(IntervalVar *const var, int64_t new_min, int64_t new_max)=0
virtual void SetEndMax(IntervalVar *const var, int64_t new_max)=0
virtual void PushContext(const std::string &context)=0
virtual void RemoveInterval(IntVar *const var, int64_t imin, int64_t imax)=0
virtual void SetEndMin(IntervalVar *const var, int64_t new_min)=0
virtual void BeginNestedConstraintInitialPropagation(Constraint *const parent, Constraint *const nested)=0
virtual void EndNestedConstraintInitialPropagation(Constraint *const parent, Constraint *const nested)=0
virtual void SetMax(IntVar *const var, int64_t new_max)=0
virtual void SetPerformed(IntervalVar *const var, bool value)=0
virtual void StartProcessingIntegerVariable(IntVar *const var)=0
virtual void BeginConstraintInitialPropagation(Constraint *const constraint)=0
Propagation events.
virtual void SetRange(IntVar *const var, int64_t new_min, int64_t new_max)=0
virtual void SetMin(IntExpr *const expr, int64_t new_min)=0
IntExpr modifiers.
virtual void SetStartMax(IntervalVar *const var, int64_t new_max)=0
virtual void EndDemonRun(Demon *const demon)=0
virtual void RegisterDemon(Demon *const demon)=0
virtual void EndProcessingIntegerVariable(IntVar *const var)=0
virtual void PopContext()=0
virtual void RemoveValues(IntVar *const var, const std::vector< int64_t > &values)=0
std::string DebugString() const override
virtual void SetStartRange(IntervalVar *const var, int64_t new_min, int64_t new_max)=0
virtual void RankFirst(SequenceVar *const var, int index)=0
SequenceVar modifiers.
Matrix version of the RevBitSet class.
void SetToZero(Solver *const solver, int64_t row, int64_t column)
Erases the 'column' bit in the 'row' row.
bool IsSet(int64_t row, int64_t column) const
Returns whether the 'column' bit in the 'row' row is set.
void SetToOne(Solver *const solver, int64_t row, int64_t column)
Sets the 'column' bit in the 'row' row.
void ClearAll(Solver *const solver)
Cleans all bits.
int64_t GetFirstBit(int row, int start) const
Returns the first bit in the row 'row' which position is >= 'start'.
This class represents a reversible bitset.
void SetToOne(Solver *const solver, int64_t index)
Sets the 'index' bit.
bool IsCardinalityOne() const
Does it contains only one bit set?
void SetToZero(Solver *const solver, int64_t index)
Erases the 'index' bit.
int64_t Cardinality() const
Returns the number of bits set to one.
int64_t GetFirstBit(int start) const
Gets the index of the first bit set starting from start.
bool IsSet(int64_t index) const
Returns whether the 'index' bit is set.
void ClearAll(Solver *const solver)
Cleans all bits.
friend class RevBitMatrix
bool IsCardinalityZero() const
Is bitset null?
This class is a reversible growing array.
void RevInsert(Solver *const solver, int64_t index, T value)
T At(int64_t index) const
RevGrowingArray(int64_t block_size)
void SetValue(Solver *const s, const T &val)
Reversible Immutable MultiMap class.
void Insert(const K &key, const V &value)
Inserts (key, value) in the multi-map.
RevImmutableMultiMap(Solver *const solver, int initial_size)
bool ContainsKey(const K &key) const
Returns true if the multi-map contains at least one instance of 'key'.
const V & FindWithDefault(const K &key, const V &default_value) const
Returns one value attached to 'key', or 'default_value' if 'key' is not in the multi-map.
This is a special class to represent a 'residual' set of T.
void Insert(Solver *const solver, const T &elt)
RevIntSet(int capacity)
Capacity is the fixed size of the set (it cannot grow).
const_iterator begin() const
const T * const_iterator
Iterators on the indices.
T RemovedElement(int i) const
RevIntSet(int capacity, int *shared_positions, int shared_positions_size)
Capacity is the fixed size of the set (it cannot grow).
void Restore(Solver *const solver, const T &value_index)
const_iterator end() const
void Remove(Solver *const solver, const T &value_index)
void Clear(Solver *const solver)
--— RevPartialSequence --—
int NumLastRanked() const
RevPartialSequence(int size)
int NumFirstRanked() const
bool IsRanked(int elt) const
std::string DebugString() const
void RankLast(Solver *const solver, int elt)
void RankFirst(Solver *const solver, int elt)
const int & operator[](int index) const
RevPartialSequence(const std::vector< int > &items)
A reversible switch that can switch once from false to true.
void Switch(Solver *const solver)
The base class of all search logs that periodically outputs information when the search is running.
A search monitor is a simple set of callbacks to monitor all search events.
A sequence variable is a variable whose domain is a set of possible orderings of the interval variabl...
This iterator is not stable with respect to deletion.
Iterator(const SimpleRevFIFO< T > *l)
This class represent a reversible FIFO structure.
void SetLastValue(const T &v)
Sets the last value in the FIFO.
void PushIfNotTop(Solver *const s, T val)
Pushes the var on top if is not a duplicate of the current top object.
void Push(Solver *const s, T val)
const T & LastValue() const
Returns the last value in the FIFO.
const T * Last() const
Returns the last item of the FIFO.
This class represents a small reversible bitset (size <= 64).
bool IsCardinalityOne() const
Does it contains only one bit set?
int64_t Cardinality() const
Returns the number of bits set to one.
SmallRevBitSet(int64_t size)
void SetToZero(Solver *const solver, int64_t pos)
Erases the 'pos' bit.
bool IsCardinalityZero() const
Is bitset null?
int64_t GetFirstOne() const
Gets the index of the first bit set starting from 0.
void SetToOne(Solver *const solver, int64_t pos)
Sets the 'pos' bit.
DemonPriority
This enum represents the three possible priorities for a demon in the Solver queue.
@ DELAYED_PRIORITY
DELAYED_PRIORITY is the lowest priority: Demons will be processed after VAR_PRIORITY and NORMAL_PRIOR...
std::function< int64_t(int64_t, int64_t)> IndexEvaluator2
void SaveAndSetValue(T *adr, T val)
All-in-one SaveAndSetValue.
T * RevAlloc(T *object)
Registers the given object as being reversible.
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
void Set(IntegerType index)
void ClearAndResize(IntegerType size)
A symmetry breaker is an object that will visit a decision and create the 'symmetrical' decision in r...
~SymmetryBreaker() override
This class represents a reversible bitset.
int64_t word_size() const
Returns the number of 64 bit words used to store the bitset.
int64_t bit_size() const
Returns the number of bits given in the constructor of the bitset.
~UnsortedNullableRevBitset()
bool Empty() const
This method returns true if the active bitset is null.
const RevIntSet< int > & active_words() const
Returns the set of active word indices.
int ActiveWordSize() const
This method returns the number of non null 64 bit words in the bitset representation.
std::vector< int64_t > to_remove_
SharedBoundsManager * bounds
GurobiMPCallbackContext * context
static const int64_t kint64max
static const int64_t kint64min
Collection of objects used to extend the Constraint Solver library.
std::string ParameterDebugString(P param)
Demon * MakeDelayedConstraintDemon1(Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1)
bool IsArrayConstant(const std::vector< T > &values, const T &value)
bool AreAllLessOrEqual(const std::vector< T > &values, const T &value)
LocalSearchOperator * MakeLocalSearchOperator(Solver *solver, const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64_t)> start_empty_path_class)
Operator Factories.
Demon * MakeDelayedConstraintDemon2(Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
bool AreAllNegative(const std::vector< T > &values)
bool AreAllGreaterOrEqual(const std::vector< T > &values, const T &value)
bool IsIncreasing(const std::vector< T > &values)
bool AreAllStrictlyPositive(const std::vector< T > &values)
Demon * MakeConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
bool IsArrayBoolean(const std::vector< T > &values)
VarTypes
This enum is used internally to do dynamic typing on subclasses of integer variables.
Demon * MakeConstraintDemon2(Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
Demon * MakeConstraintDemon1(Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1)
bool AreAllBoundOrNull(const std::vector< IntVar * > &vars, const std::vector< T > &values)
Returns true if all the variables are assigned to a single value, or if their corresponding value is ...
int64_t MaxVarArray(const std::vector< IntVar * > &vars)
bool AreAllBoundTo(const std::vector< IntVar * > &vars, int64_t value)
Returns true if all variables are assigned to 'value'.
void FillValues(const std::vector< IntVar * > &vars, std::vector< int64_t > *const values)
bool AreAllBooleans(const std::vector< IntVar * > &vars)
Demon * MakeDelayedConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
bool AreAllStrictlyNegative(const std::vector< T > &values)
int64_t MinVarArray(const std::vector< IntVar * > &vars)
LocalSearchFilter * MakeDimensionFilter(Solver *solver, std::unique_ptr< DimensionChecker > checker, const std::string &dimension_name)
bool IsIncreasingContiguous(const std::vector< T > &values)
bool AreAllNull(const std::vector< T > &values)
bool AreAllPositive(const std::vector< T > &values)
Demon * MakeConstraintDemon3(Solver *const s, T *const ct, void(T::*method)(P, Q, R), const std::string &name, P param1, Q param2, R param3)
std::vector< int64_t > ToInt64Vector(const std::vector< int > &input)
int64_t PosIntDivDown(int64_t e, int64_t v)
bool IsArrayInRange(const std::vector< IntVar * > &vars, T range_min, T range_max)
static const int kUnassigned
LocalSearchFilter * MakePathStateFilter(Solver *solver, std::unique_ptr< PathState > path_state, const std::vector< IntVar * > &nexts)
bool AreAllOnes(const std::vector< T > &values)
bool AreAllBound(const std::vector< IntVar * > &vars)
uint64_t Hash1(uint64_t value)
Hash functions.
void AcceptUncheckedNeighbor(Search *const search)
int64_t PosIntDivUp(int64_t e, int64_t v)
static int input(yyscan_t yyscanner)
std::optional< int64_t > end
int64_t num_positive_infinity
int64_t num_negative_infinity
LocalSearchFilter * filter
FilterEventType event_type
Set of parameters used to configure how the neighnorhood is traversed.
bool accept_path_end_base
True if path ends should be considered when iterating over neighbors.
int number_of_base_nodes
Number of nodes needed to define a neighbor.
std::function< int(int64_t)> start_empty_path_class
Callback returning an index such that if c1 = start_empty_path_class(StartNode(p1)),...
bool skip_locally_optimal_paths
Skip paths which have been proven locally optimal.
ChainBounds(int begin_index, int end_index)