49#ifndef OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVERI_H_
50#define OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVERI_H_
62#include "absl/container/flat_hash_map.h"
63#include "absl/strings/str_cat.h"
98class LocalSearchMonitor;
138 enum { CHUNK_SIZE = 16 };
141 const Chunk*
const next_;
142 explicit Chunk(
const Chunk*
next) : next_(
next) {}
150 : chunk_(l->chunks_), value_(l->
Last()) {}
151 bool ok()
const {
return (value_ !=
nullptr); }
155 if (value_ == chunk_->data_ + CHUNK_SIZE) {
156 chunk_ = chunk_->next_;
157 value_ = chunk_ ? chunk_->data_ :
nullptr;
169 if (pos_.Value() == 0) {
170 Chunk*
const chunk = s->UnsafeRevAlloc(
new Chunk(chunks_));
172 reinterpret_cast<void*
>(chunk));
173 pos_.SetValue(s, CHUNK_SIZE - 1);
177 chunks_->data_[pos_.Value()] = val;
182 if (chunks_ ==
nullptr ||
LastValue() != val) {
189 return chunks_ ? &chunks_->data_[pos_.Value()] :
nullptr;
192 T*
MutableLast() {
return chunks_ ? &chunks_->data_[pos_.Value()] :
nullptr; }
197 return chunks_->data_[pos_.Value()];
203 chunks_->data_[pos_.Value()] = v;
226 a = (
a + 0x7ed55d16) + (
a << 12);
227 a = (
a ^ 0xc761c23c) ^ (
a >> 19);
228 a = (
a + 0x165667b1) + (
a << 5);
229 a = (
a + 0xd3a2646c) ^ (
a << 9);
230 a = (
a + 0xfd7046c5) + (
a << 3);
231 a = (
a ^ 0xb55a4f09) ^ (
a >> 16);
241inline uint64_t
Hash1(
void*
const ptr) {
242#if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || \
244 return Hash1(
reinterpret_cast<uint64_t
>(ptr));
246 return Hash1(
reinterpret_cast<uint32_t
>(ptr));
251uint64_t
Hash1(
const std::vector<T*>& ptrs) {
252 if (ptrs.empty())
return 0;
253 if (ptrs.size() == 1)
return Hash1(ptrs[0]);
255 for (
int i = 1; i < ptrs.size(); ++i) {
261inline uint64_t
Hash1(
const std::vector<int64_t>& ptrs) {
262 if (ptrs.empty())
return 0;
263 if (ptrs.size() == 1)
return Hash1(ptrs[0]);
265 for (
int i = 1; i < ptrs.size(); ++i) {
273template <
class K,
class V>
278 array_(solver->UnsafeRevAllocArray(new Cell*[initial_size])),
281 memset(array_, 0,
sizeof(*array_) * size_.Value());
290 uint64_t code =
Hash1(key) % size_.Value();
291 Cell* tmp = array_[code];
293 if (tmp->key() == key) {
305 uint64_t code =
Hash1(key) % size_.Value();
306 Cell* tmp = array_[code];
308 if (tmp->key() == key) {
313 return default_value;
318 const int position =
Hash1(key) % size_.Value();
320 solver_->UnsafeRevAlloc(
new Cell(key,
value, array_[position]));
322 reinterpret_cast<void*
>(cell));
323 num_items_.Incr(solver_);
324 if (num_items_.Value() > 2 * size_.Value()) {
332 Cell(
const K& key,
const V&
value, Cell*
const next)
333 : key_(key), value_(
value), next_(
next) {}
335 void SetRevNext(Solver*
const solver, Cell*
const next) {
336 solver->SaveAndSetValue(
reinterpret_cast<void**
>(&next_),
337 reinterpret_cast<void*
>(
next));
340 Cell*
next()
const {
return next_; }
342 const K& key()
const {
return key_; }
344 const V&
value()
const {
return value_; }
353 Cell**
const old_cell_array = array_;
354 const int old_size = size_.Value();
355 size_.SetValue(solver_, size_.Value() * 2);
357 reinterpret_cast<void**
>(&array_),
358 reinterpret_cast<void*
>(
359 solver_->UnsafeRevAllocArray(
new Cell*[size_.Value()])));
360 memset(array_, 0, size_.Value() *
sizeof(*array_));
361 for (
int i = 0; i < old_size; ++i) {
362 Cell* tmp = old_cell_array[i];
363 while (tmp !=
nullptr) {
364 Cell*
const to_reinsert = tmp;
366 const uint64_t new_position =
Hash1(to_reinsert->key()) % size_.Value();
367 to_reinsert->SetRevNext(solver_, array_[new_position]);
369 reinterpret_cast<void**
>(&array_[new_position]),
370 reinterpret_cast<void*
>(to_reinsert));
375 Solver*
const solver_;
377 NumericalRev<int> size_;
378 NumericalRev<int> num_items_;
409 return (bits_.Value() != 0) && !(bits_.Value() & (bits_.Value() - 1));
448 void Save(
Solver*
const solver,
int offset);
450 const int64_t length_;
487 const int64_t columns_;
501 : constraint_(
ct), method_(method), name_(
name) {}
505 void Run(
Solver*
const s)
override { (constraint_->*method_)(); }
508 return "CallMethod_" + name_ +
"(" + constraint_->DebugString() +
")";
512 T*
const constraint_;
513 void (T::*
const method_)();
514 const std::string name_;
519 const std::string&
name) {
525 return absl::StrCat(param);
531 return param->DebugString();
535template <
class T,
class P>
540 : constraint_(
ct), method_(method), name_(
name), param1_(param1) {}
544 void Run(
Solver*
const s)
override { (constraint_->*method_)(param1_); }
547 return absl::StrCat(
"CallMethod_", name_,
"(", constraint_->DebugString(),
552 T*
const constraint_;
553 void (T::*
const method_)(P);
554 const std::string name_;
558template <
class T,
class P>
560 const std::string&
name, P param1) {
565template <
class T,
class P,
class Q>
579 (constraint_->*method_)(param1_, param2_);
583 return absl::StrCat(absl::StrCat(
"CallMethod_", name_),
584 absl::StrCat(
"(", constraint_->DebugString()),
590 T*
const constraint_;
591 void (T::*
const method_)(P, Q);
592 const std::string name_;
597template <
class T,
class P,
class Q>
599 void (T::*method)(P, Q),
const std::string&
name,
600 P param1, Q param2) {
605template <
class T,
class P,
class Q,
class R>
609 P param1, Q param2, R param3)
620 (constraint_->*method_)(param1_, param2_, param3_);
624 return absl::StrCat(absl::StrCat(
"CallMethod_", name_),
625 absl::StrCat(
"(", constraint_->DebugString()),
632 T*
const constraint_;
633 void (T::*
const method_)(P, Q, R);
634 const std::string name_;
640template <
class T,
class P,
class Q,
class R>
642 void (T::*method)(P, Q, R),
const std::string&
name,
643 P param1, Q param2, R param3) {
659 : constraint_(
ct), method_(method), name_(
name) {}
663 void Run(
Solver*
const s)
override { (constraint_->*method_)(); }
670 return "DelayedCallMethod_" + name_ +
"(" + constraint_->DebugString() +
675 T*
const constraint_;
676 void (T::*
const method_)();
677 const std::string name_;
683 const std::string&
name) {
688template <
class T,
class P>
693 : constraint_(
ct), method_(method), name_(
name), param1_(param1) {}
697 void Run(
Solver*
const s)
override { (constraint_->*method_)(param1_); }
704 return absl::StrCat(
"DelayedCallMethod_", name_,
"(",
705 constraint_->DebugString(),
", ",
710 T*
const constraint_;
711 void (T::*
const method_)(P);
712 const std::string name_;
716template <
class T,
class P>
718 void (T::*method)(P),
719 const std::string&
name, P param1) {
724template <
class T,
class P,
class Q>
728 const std::string&
name, P param1, Q param2)
738 (constraint_->*method_)(param1_, param2_);
746 return absl::StrCat(absl::StrCat(
"DelayedCallMethod_", name_),
747 absl::StrCat(
"(", constraint_->DebugString()),
753 T*
const constraint_;
754 void (T::*
const method_)(P, Q);
755 const std::string name_;
760template <
class T,
class P,
class Q>
762 void (T::*method)(P, Q),
763 const std::string&
name, P param1,
806template <
class V,
class Val,
class Handler>
820 const int size =
Size();
822 <<
"Assignment contains fewer variables than operator";
823 for (
int i = 0; i < size; ++i) {
896 vars_.insert(
vars_.end(), vars.begin(), vars.end());
897 const int64_t size =
Size();
946 std::vector<int>* assignment_indices, int64_t
index,
951 if (assignment_indices !=
nullptr) {
952 if ((*assignment_indices)[
index] == -1) {
953 (*assignment_indices)[
index] = container->
Size();
991#if defined(SWIGPYTHON)
993%unignore VarLocalSearchOperator<IntVar, int64_t,
994 IntVarLocalSearchHandler>::Size;
995%unignore VarLocalSearchOperator<IntVar, int64_t,
996 IntVarLocalSearchHandler>
::Value;
997%unignore VarLocalSearchOperator<IntVar, int64_t,
998 IntVarLocalSearchHandler>::OldValue;
999%unignore VarLocalSearchOperator<IntVar, int64_t,
1000 IntVarLocalSearchHandler>::SetValue;
1001%feature(
"director") VarLocalSearchOperator<IntVar, int64_t,
1002 IntVarLocalSearchHandler>::IsIncremental;
1003%feature("director") VarLocalSearchOperator<IntVar, int64_t,
1004 IntVarLocalSearchHandler>::OnStart;
1005%unignore VarLocalSearchOperator<IntVar, int64_t,
1006 IntVarLocalSearchHandler>::IsIncremental;
1007%unignore VarLocalSearchOperator<IntVar, int64_t,
1008 IntVarLocalSearchHandler>::OnStart;
1013%rename(IntVarLocalSearchOperatorTemplate)
1014 VarLocalSearchOperator<IntVar, int64_t, IntVarLocalSearchHandler>;
1015%
template(IntVarLocalSearchOperatorTemplate)
1016 VarLocalSearchOperator<IntVar, int64_t, IntVarLocalSearchHandler>;
1028 bool keep_inverse_values =
false)
1031 max_inverse_value_(keep_inverse_values ? vars.size() - 1 : -1) {
1033 if (keep_inverse_values) {
1034 int64_t max_value = -1;
1038 inverse_values_.resize(max_value + 1, -1);
1039 old_inverse_values_.resize(max_value + 1, -1);
1058 virtual bool MakeOneNeighbor();
1062 return index <= max_inverse_value_;
1068 return old_inverse_values_[
index];
1080 const int64_t max_inverse_value_;
1081 std::vector<int64_t> old_inverse_values_;
1082 std::vector<int64_t> inverse_values_;
1089 if (element->
Var() !=
var) {
1091 <<
"Assignment does not contain operator variable " <<
var;
1120 bool active, std::vector<int>* assignment_indices,
1124 void OnRevertChanges(int64_t
index,
const std::vector<int>&
value);
1139 SequenceVar, std::vector<int>, SequenceVarLocalSearchHandler>;
1141 SequenceVar, std::vector<int>, SequenceVarLocalSearchHandler>;
1145typedef VarLocalSearchOperator<SequenceVar, std::vector<int>,
1146 SequenceVarLocalSearchHandler>
1181 std::vector<int>* assignment_indices, int64_t
index,
1186 if (assignment_indices !=
nullptr) {
1187 if ((*assignment_indices)[
index] == -1) {
1188 (*assignment_indices)[
index] = container->
Size();
1207 std::vector<int>*
value) {
1211 if (element->
Var() !=
var) {
1213 <<
"Assignment does not contain operator variable " <<
var;
1219 *
value = element_value;
1224 int64_t
index,
const std::vector<int>&
value) {
1261 explicit BaseLns(
const std::vector<IntVar*>& vars);
1275 void OnStart()
override;
1276 std::vector<int> fragment_;
1285 explicit ChangeValue(
const std::vector<IntVar*>& vars);
1294 void OnStart()
override;
1337 const std::vector<IntVar*>& path_vars,
1340 const std::vector<IntVar*>& path_vars,
int number_of_base_nodes,
1341 bool skip_locally_optimal_paths,
bool accept_path_end_base,
1342 std::function<
int(int64_t)> start_empty_path_class)
1344 next_vars, path_vars,
1345 {number_of_base_nodes, skip_locally_optimal_paths,
1346 accept_path_end_base, std::move(start_empty_path_class)}) {}
1349 void Reset()
override;
1385 int64_t
BaseNode(
int i)
const {
return base_nodes_[i]; }
1391 const int alternative_index = alternative_index_[
BaseNode(i)];
1392 return alternative_index >= 0
1393 ? alternative_sets_[alternative_index][base_alternatives_[i]]
1398 return base_sibling_alternatives_[i];
1403 const int sibling_alternative_index =
1405 return sibling_alternative_index >= 0
1406 ? alternative_sets_[sibling_alternative_index]
1407 [base_sibling_alternatives_[i]]
1411 int64_t
StartNode(
int i)
const {
return path_starts_[base_paths_[i]]; }
1413 const std::vector<int64_t>&
path_starts()
const {
return path_starts_; }
1469 bool MoveChain(int64_t before_chain, int64_t chain_end, int64_t destination);
1473 bool ReverseChain(int64_t before_chain, int64_t after_chain,
1474 int64_t* chain_last);
1477 bool MakeActive(int64_t node, int64_t destination);
1485 void SetNext(int64_t from, int64_t to, int64_t path) {
1504 return !
IsPathEnd(node) && inactives_[node];
1519 const int alternative = alternative_sets_.size();
1520 for (int64_t node : alternative_set) {
1521 DCHECK_EQ(-1, alternative_index_[node]);
1522 alternative_index_[node] = alternative;
1524 alternative_sets_.push_back(alternative_set);
1525 sibling_alternative_.push_back(-1);
1532 const std::vector<std::pair<std::vector<int64_t>, std::vector<int64_t>>>&
1533 pair_alternative_sets) {
1534 for (
const auto& pair_alternative_set : pair_alternative_sets) {
1536 sibling_alternative_.back() = alternative + 1;
1542 int64_t GetActiveInAlternativeSet(int alternative_index) const {
1543 return alternative_index >= 0
1544 ? active_in_alternative_set_[alternative_index]
1549 return GetActiveInAlternativeSet(alternative_index_[node]);
1553 if (node >= alternative_index_.size())
return -1;
1554 const int alternative = alternative_index_[node];
1555 return alternative >= 0 ? sibling_alternative_[alternative] : -1;
1560 if (node >= alternative_index_.size())
return -1;
1561 const int alternative = alternative_index_[node];
1562 const int sibling_alternative =
1563 alternative >= 0 ? sibling_alternative_[alternative] : -1;
1564 return GetActiveInAlternativeSet(sibling_alternative);
1568 bool CheckChainValidity(int64_t before_chain, int64_t chain_end,
1569 int64_t exclude)
const;
1578 void OnStart()
override;
1580 bool OnSamePath(int64_t node1, int64_t node2)
const;
1582 bool CheckEnds()
const {
1583 const int base_node_size = base_nodes_.size();
1584 for (
int i = base_node_size - 1; i >= 0; --i) {
1585 if (base_nodes_[i] != end_nodes_[i]) {
1591 bool IncrementPosition();
1592 void InitializePathStarts();
1593 void InitializeInactives();
1594 void InitializeBaseNodes();
1595 void InitializeAlternatives();
1598 std::vector<int> base_nodes_;
1599 std::vector<int> base_alternatives_;
1600 std::vector<int> base_sibling_alternatives_;
1601 std::vector<int> end_nodes_;
1602 std::vector<int> base_paths_;
1603 std::vector<int64_t> path_starts_;
1604 std::vector<bool> inactives_;
1607 IterationParameters iteration_parameters_;
1608 bool optimal_paths_enabled_;
1609 std::vector<int> path_basis_;
1610 std::vector<bool> optimal_paths_;
1613 std::vector<std::vector<int64_t>> alternative_sets_;
1615 std::vector<int> alternative_index_;
1616 std::vector<int64_t> active_in_alternative_set_;
1617 std::vector<int> sibling_alternative_;
1623 Solver* solver,
const std::vector<IntVar*>& vars,
1624 const std::vector<IntVar*>& secondary_vars,
1625 std::function<
int(int64_t)> start_empty_path_class);
1654class LocalSearchVariable;
1671 void RelaxVariableBounds(
int variable_index);
1672 bool TightenVariableMin(
int variable_index, int64_t
value);
1673 bool TightenVariableMax(
int variable_index, int64_t
value);
1674 int64_t VariableMin(
int variable_index)
const;
1675 int64_t VariableMax(
int variable_index)
const;
1677 std::vector<Bounds> initial_variable_bounds_;
1678 std::vector<Bounds> variable_bounds_;
1679 std::vector<std::pair<Bounds, int>> saved_variable_bounds_trail_;
1680 std::vector<bool> variable_is_relaxed_;
1681 bool state_is_valid_ =
true;
1691 int64_t
Min()
const {
return state_->VariableMin(variable_index_); }
1692 int64_t
Max()
const {
return state_->VariableMax(variable_index_); }
1694 return state_->TightenVariableMin(variable_index_, new_min);
1697 return state_->TightenVariableMax(variable_index_, new_max);
1699 void Relax() { state_->RelaxVariableBounds(variable_index_); }
1706 : state_(state), variable_index_(variable_index) {}
1709 const int variable_index_;
1747 int64_t objective_min, int64_t objective_max) = 0;
1784 return "LocalSearchFilterManager";
1800 const Assignment* deltadelta, int64_t objective_min,
1801 int64_t objective_max);
1808 void InitializeForcedEvents();
1810 std::vector<FilterEvent> filter_events_;
1811 int last_event_called_ = -1;
1816 std::vector<int> next_forced_events_;
1817 int64_t synchronized_value_;
1818 int64_t accepted_value_;
1827 void Synchronize(
const Assignment* assignment,
1832 const int var_index =
var->index();
1833 *
index = (var_index < var_index_to_index_.size())
1834 ? var_index_to_index_[var_index]
1840 void AddVars(
const std::vector<IntVar*>& vars);
1845 return values_[
index];
1851 void SynchronizeOnAssignment(
const Assignment* assignment);
1854 std::vector<IntVar*>
vars_;
1855 std::vector<int64_t> values_;
1856 std::vector<bool> var_synced_;
1857 std::vector<int> var_index_to_index_;
1865 std::string
DebugString()
const override {
return "PropagationMonitor"; }
1887 int64_t new_max) = 0;
1892 int64_t new_max) = 0;
1898 const std::vector<int64_t>& values) = 0;
1900 const std::vector<int64_t>& values) = 0;
1905 int64_t new_max) = 0;
1909 int64_t new_max) = 0;
1913 int64_t new_max) = 0;
1921 const std::vector<int>& rank_first,
1922 const std::vector<int>& rank_last,
1923 const std::vector<int>& unperformed) = 0;
1925 void Install()
override;
1933 std::string
DebugString()
const override {
return "LocalSearchMonitor"; }
1944 bool neighbor_found) = 0;
1947 bool neighbor_found) = 0;
1952 void Install()
override;
1960 :
IntVar(s,
name), value_(kUnboundBooleanVarValue) {}
1964 int64_t
Min()
const override {
return (value_ == 1); }
1965 void SetMin(int64_t m)
override;
1966 int64_t
Max()
const override {
return (value_ != 0); }
1967 void SetMax(int64_t m)
override;
1968 void SetRange(int64_t mi, int64_t ma)
override;
1969 bool Bound()
const override {
return (value_ != kUnboundBooleanVarValue); }
1971 CHECK_NE(value_, kUnboundBooleanVarValue) <<
"variable is not bound";
1974 void RemoveValue(int64_t v)
override;
1975 void RemoveInterval(int64_t l, int64_t u)
override;
1976 void WhenBound(
Demon* d)
override;
1979 uint64_t Size()
const override;
1980 bool Contains(int64_t v)
const override;
1981 IntVarIterator* MakeHoleIterator(
bool reversible)
const override;
1982 IntVarIterator* MakeDomainIterator(
bool reversible)
const override;
1983 std::string DebugString()
const override;
1986 IntVar* IsEqual(int64_t constant)
override;
1987 IntVar* IsDifferent(int64_t constant)
override;
1988 IntVar* IsGreaterOrEqual(int64_t constant)
override;
1989 IntVar* IsLessOrEqual(int64_t constant)
override;
1992 std::string
BaseName()
const override {
return "BooleanVar"; }
2010 : symmetry_manager_(nullptr), index_in_symmetry_manager_(-1) {}
2013 void AddIntegerVariableEqualValueClause(
IntVar*
const var, int64_t
value);
2014 void AddIntegerVariableGreaterOrEqualValueClause(
IntVar*
const var,
2016 void AddIntegerVariableLessOrEqualValueClause(
IntVar*
const var,
2022 CHECK(symmetry_manager_ ==
nullptr);
2023 CHECK_EQ(-1, index_in_symmetry_manager_);
2024 symmetry_manager_ = manager;
2025 index_in_symmetry_manager_ =
index;
2027 SymmetryManager* symmetry_manager()
const {
return symmetry_manager_; }
2028 int index_in_symmetry_manager()
const {
return index_in_symmetry_manager_; }
2030 SymmetryManager* symmetry_manager_;
2032 int index_in_symmetry_manager_;
2040 double scaling_factor,
double offset,
2041 std::function<std::string()> display_callback,
2042 bool display_on_new_solutions_only,
int period);
2044 void EnterSearch()
override;
2045 void ExitSearch()
override;
2046 bool AtSolution()
override;
2047 void BeginFail()
override;
2048 void NoMoreSolutions()
override;
2050 void ApplyDecision(
Decision*
const decision)
override;
2051 void RefuteDecision(
Decision*
const decision)
override;
2052 void OutputDecision();
2054 void BeginInitialPropagation()
override;
2055 void EndInitialPropagation()
override;
2056 std::string DebugString()
const override;
2060 virtual void OutputLine(
const std::string& line);
2066 std::unique_ptr<WallTimer> timer_;
2069 const double scaling_factor_;
2071 std::function<std::string()> display_callback_;
2072 const bool display_on_new_solutions_only_;
2075 int64_t objective_min_;
2076 int64_t objective_max_;
2077 int min_right_depth_;
2079 int sliding_min_depth_;
2080 int sliding_max_depth_;
2090 VOID_FALSE_CONSTRAINT = 0,
2096 VAR_CONSTANT_EQUALITY = 0,
2104 VAR_CONSTANT_CONSTANT_BETWEEN = 0,
2109 EXPR_EXPR_EQUALITY = 0,
2126 EXPR_EXPR_DIFFERENCE = 0,
2140 EXPR_EXPR_CONSTANT_CONDITIONAL = 0,
2145 EXPR_CONSTANT_DIFFERENCE = 0,
2158 VAR_CONSTANT_CONSTANT_SEMI_CONTINUOUS = 0,
2163 VAR_CONSTANT_ARRAY_ELEMENT = 0,
2168 VAR_ARRAY_CONSTANT_ARRAY_SCAL_PROD = 0,
2180 VAR_ARRAY_CONSTANT_INDEX = 0,
2208 IntVar*
const var, int64_t value1, int64_t value2,
2269 IntVar*
const var, int64_t value1, int64_t value2,
2279 IntVar*
const var,
const std::vector<int64_t>& values,
2284 const std::vector<int64_t>& values,
2293 const std::vector<IntVar*>& vars,
2299 const std::vector<IntVar*>& vars,
const std::vector<int64_t>& values,
2303 IntExpr*
const expression,
const std::vector<IntVar*>&
var,
2304 const std::vector<int64_t>& values,
2310 const std::vector<IntVar*>& vars, int64_t
value,
2314 IntExpr*
const expression,
const std::vector<IntVar*>&
var, int64_t
value,
2328 const std::string& TypeName()
const;
2329 void SetTypeName(
const std::string& type_name);
2332 void SetIntegerArgument(
const std::string& arg_name, int64_t
value);
2333 void SetIntegerArrayArgument(
const std::string& arg_name,
2334 const std::vector<int64_t>& values);
2335 void SetIntegerMatrixArgument(
const std::string& arg_name,
2337 void SetIntegerExpressionArgument(
const std::string& arg_name,
2339 void SetIntegerVariableArrayArgument(
const std::string& arg_name,
2340 const std::vector<IntVar*>& vars);
2341 void SetIntervalArgument(
const std::string& arg_name,
IntervalVar*
const var);
2342 void SetIntervalArrayArgument(
const std::string& arg_name,
2343 const std::vector<IntervalVar*>& vars);
2344 void SetSequenceArgument(
const std::string& arg_name,
SequenceVar*
const var);
2345 void SetSequenceArrayArgument(
const std::string& arg_name,
2346 const std::vector<SequenceVar*>& vars);
2349 bool HasIntegerExpressionArgument(
const std::string& arg_name)
const;
2350 bool HasIntegerVariableArrayArgument(
const std::string& arg_name)
const;
2353 int64_t FindIntegerArgumentWithDefault(
const std::string& arg_name,
2355 int64_t FindIntegerArgumentOrDie(
const std::string& arg_name)
const;
2356 const std::vector<int64_t>& FindIntegerArrayArgumentOrDie(
2357 const std::string& arg_name)
const;
2358 const IntTupleSet& FindIntegerMatrixArgumentOrDie(
2359 const std::string& arg_name)
const;
2361 IntExpr* FindIntegerExpressionArgumentOrDie(
2362 const std::string& arg_name)
const;
2363 const std::vector<IntVar*>& FindIntegerVariableArrayArgumentOrDie(
2364 const std::string& arg_name)
const;
2367 std::string type_name_;
2368 absl::flat_hash_map<std::string, int64_t> integer_argument_;
2369 absl::flat_hash_map<std::string, std::vector<int64_t>>
2370 integer_array_argument_;
2371 absl::flat_hash_map<std::string, IntTupleSet> matrix_argument_;
2372 absl::flat_hash_map<std::string, IntExpr*> integer_expression_argument_;
2373 absl::flat_hash_map<std::string, IntervalVar*> interval_argument_;
2374 absl::flat_hash_map<std::string, SequenceVar*> sequence_argument_;
2375 absl::flat_hash_map<std::string, std::vector<IntVar*>>
2376 integer_variable_array_argument_;
2377 absl::flat_hash_map<std::string, std::vector<IntervalVar*>>
2378 interval_array_argument_;
2379 absl::flat_hash_map<std::string, std::vector<SequenceVar*>>
2380 sequence_array_argument_;
2391 void BeginVisitModel(
const std::string& solver_name)
override;
2392 void EndVisitModel(
const std::string& solver_name)
override;
2393 void BeginVisitConstraint(
const std::string& type_name,
2394 const Constraint*
const constraint)
override;
2395 void EndVisitConstraint(
const std::string& type_name,
2396 const Constraint*
const constraint)
override;
2397 void BeginVisitIntegerExpression(
const std::string& type_name,
2398 const IntExpr*
const expr)
override;
2399 void EndVisitIntegerExpression(
const std::string& type_name,
2400 const IntExpr*
const expr)
override;
2401 void VisitIntegerVariable(
const IntVar*
const variable,
2402 IntExpr*
const delegate)
override;
2403 void VisitIntegerVariable(
const IntVar*
const variable,
2404 const std::string& operation, int64_t
value,
2405 IntVar*
const delegate)
override;
2406 void VisitIntervalVariable(
const IntervalVar*
const variable,
2407 const std::string& operation, int64_t
value,
2409 void VisitSequenceVariable(
const SequenceVar*
const variable)
override;
2411 void VisitIntegerArgument(
const std::string& arg_name,
2412 int64_t
value)
override;
2413 void VisitIntegerArrayArgument(
const std::string& arg_name,
2414 const std::vector<int64_t>& values)
override;
2415 void VisitIntegerMatrixArgument(
const std::string& arg_name,
2418 void VisitIntegerExpressionArgument(
const std::string& arg_name,
2419 IntExpr*
const argument)
override;
2420 void VisitIntegerVariableArrayArgument(
2421 const std::string& arg_name,
2422 const std::vector<IntVar*>& arguments)
override;
2424 void VisitIntervalArgument(
const std::string& arg_name,
2426 void VisitIntervalArrayArgument(
2427 const std::string& arg_name,
2428 const std::vector<IntervalVar*>& arguments)
override;
2430 void VisitSequenceArgument(
const std::string& arg_name,
2432 void VisitSequenceArrayArgument(
2433 const std::string& arg_name,
2434 const std::vector<SequenceVar*>& arguments)
override;
2437 void PushArgumentHolder();
2438 void PopArgumentHolder();
2442 std::vector<ArgumentHolder*> holders_;
2449 : index_min_(index_min),
2450 index_max_(index_max),
2451 values_(new T[index_max - index_min + 1]) {
2460 return values_[
index - index_min_];
2469 std::string
DebugString()
const override {
return "ArrayWithOffset"; }
2472 const int64_t index_min_;
2473 const int64_t index_max_;
2474 std::unique_ptr<T[]> values_;
2482template <
class T,
class C>
2486 : block_size_(block_size), block_offset_(0) {
2491 for (
int i = 0; i < elements_.size(); ++i) {
2492 delete[] elements_[i];
2497 const int64_t block_index = ComputeBlockIndex(
index);
2498 const int64_t relative_index = block_index - block_offset_;
2499 if (relative_index < 0 || relative_index >= elements_.size()) {
2502 const T* block = elements_[relative_index];
2503 return block !=
nullptr ? block[
index - block_index * block_size_] : T();
2507 const int64_t block_index = ComputeBlockIndex(
index);
2508 T*
const block = GetOrCreateBlock(block_index);
2509 const int64_t residual =
index - block_index * block_size_;
2511 reinterpret_cast<C
>(
value));
2515 T* NewBlock()
const {
2516 T*
const result =
new T[block_size_];
2517 for (
int i = 0; i < block_size_; ++i) {
2523 T* GetOrCreateBlock(
int block_index) {
2524 if (elements_.size() == 0) {
2525 block_offset_ = block_index;
2526 GrowUp(block_index);
2527 }
else if (block_index < block_offset_) {
2528 GrowDown(block_index);
2529 }
else if (block_index - block_offset_ >= elements_.size()) {
2530 GrowUp(block_index);
2532 T* block = elements_[block_index - block_offset_];
2533 if (block ==
nullptr) {
2535 elements_[block_index - block_offset_] = block;
2540 int64_t ComputeBlockIndex(int64_t
value)
const {
2542 : (
value - block_size_ + 1) / block_size_;
2545 void GrowUp(int64_t block_index) {
2546 elements_.resize(block_index - block_offset_ + 1);
2549 void GrowDown(int64_t block_index) {
2550 const int64_t
delta = block_offset_ - block_index;
2551 block_offset_ = block_index;
2553 elements_.insert(elements_.begin(),
delta,
nullptr);
2556 const int64_t block_size_;
2557 std::vector<T*> elements_;
2568 static constexpr int kNoInserted = -1;
2576 delete_position_(true) {
2577 for (
int i = 0; i <
capacity; ++i) {
2578 position_[i] = kNoInserted;
2587 position_(shared_positions),
2588 delete_position_(false) {
2589 for (
int i = 0; i < shared_positions_size; ++i) {
2590 position_[i] = kNoInserted;
2595 if (delete_position_) {
2600 int Size()
const {
return num_elements_.Value(); }
2607 return elements_[i];
2612 DCHECK_LT(i + num_elements_.Value(), capacity_);
2613 return elements_[i + num_elements_.Value()];
2617 const int position = num_elements_.Value();
2619 DCHECK(NotAlreadyInserted(elt));
2620 elements_[position] = elt;
2621 position_[elt] = position;
2622 num_elements_.Incr(solver);
2626 num_elements_.Decr(solver);
2627 SwapTo(value_index, num_elements_.Value());
2631 SwapTo(value_index, num_elements_.Value());
2632 num_elements_.Incr(solver);
2635 void Clear(
Solver*
const solver) { num_elements_.SetValue(solver, 0); }
2644 bool NotAlreadyInserted(
const T& elt) {
2645 for (
int i = 0; i < num_elements_.Value(); ++i) {
2646 if (elt == elements_[i]) {
2653 void SwapTo(T value_index,
int next_position) {
2654 const int current_position = position_[value_index];
2655 if (current_position != next_position) {
2656 const T next_value_index = elements_[next_position];
2657 elements_[current_position] = next_value_index;
2658 elements_[next_position] = value_index;
2659 position_[value_index] = next_position;
2660 position_[next_value_index] = current_position;
2665 std::unique_ptr<T[]> elements_;
2667 NumericalRev<int> num_elements_;
2669 const int capacity_;
2673 const bool delete_position_;
2683 last_ranked_(items.size() - 1),
2684 size_(items.size()),
2685 position_(new int[size_]) {
2686 for (
int i = 0; i < size_; ++i) {
2687 elements_[i] = items[i];
2695 last_ranked_(size - 1),
2697 position_(new int[size_]) {
2698 for (
int i = 0; i < size_; ++i) {
2716 return elements_[
index];
2721 DCHECK_LE(first_ranked_.Value(), last_ranked_.Value());
2722 SwapTo(elt, first_ranked_.Value());
2723 first_ranked_.Incr(solver);
2727 DCHECK_LE(first_ranked_.Value(), last_ranked_.Value());
2728 SwapTo(elt, last_ranked_.Value());
2729 last_ranked_.Decr(solver);
2733 const int position = position_[elt];
2734 return (position < first_ranked_.Value() ||
2735 position > last_ranked_.Value());
2739 std::string result =
"[";
2740 for (
int i = 0; i < first_ranked_.Value(); ++i) {
2741 absl::StrAppend(&result, elements_[i]);
2742 if (i != first_ranked_.Value() - 1) {
2747 for (
int i = first_ranked_.Value(); i <= last_ranked_.Value(); ++i) {
2748 absl::StrAppend(&result, elements_[i]);
2749 if (i != last_ranked_.Value()) {
2754 for (
int i = last_ranked_.Value() + 1; i < size_; ++i) {
2755 absl::StrAppend(&result, elements_[i]);
2756 if (i != size_ - 1) {
2765 void SwapTo(
int elt,
int next_position) {
2766 const int current_position = position_[elt];
2767 if (current_position != next_position) {
2768 const int next_elt = elements_[next_position];
2769 elements_[current_position] = next_elt;
2770 elements_[next_position] = elt;
2771 position_[elt] = next_position;
2772 position_[next_elt] = current_position;
2777 std::vector<int> elements_;
2779 NumericalRev<int> first_ranked_;
2781 NumericalRev<int> last_ranked_;
2785 std::unique_ptr<int[]> position_;
2801 void Init(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2805 bool RevSubtract(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2809 bool RevAnd(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2816 bool Empty()
const {
return active_words_.Size() == 0; }
2825 bool Intersects(
const std::vector<uint64_t>& mask,
int* support_index);
2835 void CleanUpActives(
Solver*
const solver);
2837 const int64_t bit_size_;
2838 const int64_t word_size_;
2846 for (
int i = 0; i < values.size(); ++i) {
2847 if (values[i] !=
value) {
2856 for (
int i = 0; i < values.size(); ++i) {
2857 if (values[i] != 0 && values[i] != 1) {
2876 for (
const T& current_value : values) {
2877 if (current_value <
value) {
2886 for (
const T& current_value : values) {
2887 if (current_value >
value) {
2916 for (
int i = 0; i < values.size() - 1; ++i) {
2917 if (values[i + 1] != values[i] + 1) {
2926 for (
int i = 0; i < values.size() - 1; ++i) {
2927 if (values[i + 1] < values[i]) {
2937 for (
int i = 0; i < vars.size(); ++i) {
2938 if (vars[i]->Min() < range_min || vars[i]->Max() > range_max) {
2946 for (
int i = 0; i < vars.size(); ++i) {
2947 if (!vars[i]->Bound()) {
2962 const std::vector<T>& values) {
2963 for (
int i = 0; i < vars.size(); ++i) {
2964 if (values[i] != 0 && !vars[i]->Bound()) {
2973 for (
int i = 0; i < vars.size(); ++i) {
2974 if (!vars[i]->Bound() || vars[i]->Min() !=
value) {
2984 for (
int i = 0; i < vars.size(); ++i) {
2986 result = std::max<int64_t>(result, vars[i]->Max());
2994 for (
int i = 0; i < vars.size(); ++i) {
2996 result = std::min<int64_t>(result, vars[i]->Min());
3002 std::vector<int64_t>*
const values) {
3004 values->resize(vars.size());
3005 for (
int i = 0; i < vars.size(); ++i) {
3006 (*values)[i] = vars[i]->Value();
3012 return (e < 0 || e % v == 0) ? e / v : e / v + 1;
3017 return (e >= 0 || e % v == 0) ? e / v : e / v - 1;
3082 PathState(
int num_nodes, std::vector<int> path_start,
3083 std::vector<int> path_end);
3092 int Start(
int path)
const {
return path_start_end_[path].start; }
3094 int End(
int path)
const {
return path_start_end_[path].end; }
3100 return committed_nodes_[committed_index_[node]].path;
3105 return changed_arcs_;
3111 ChainRange Chains(
int path)
const;
3113 NodeRange Nodes(
int path)
const;
3120 changed_arcs_.emplace_back(node, new_next);
3141 struct PathStartEnd {
3142 PathStartEnd(
int start,
int end) : start(start), end(end) {}
3151 struct ChainBounds {
3152 ChainBounds() =
default;
3153 ChainBounds(
int begin_index,
int end_index)
3154 : begin_index(begin_index), end_index(end_index) {}
3158 struct CommittedNode {
3159 CommittedNode(
int node,
int path) : node(node), path(path) {}
3167 struct TailHeadIndices {
3174 bool operator<(
const IndexArc& other)
const {
return index < other.index; }
3179 void MakeChainsFromChangedPathsAndArcsWithSelectionAlgorithm();
3182 void MakeChainsFromChangedPathsAndArcsWithGenericAlgorithm();
3186 void CopyNewPathAtEndOfNodes(
int path);
3189 void IncrementalCommit();
3195 const int num_nodes_;
3196 const int num_paths_;
3197 std::vector<PathStartEnd> path_start_end_;
3224 std::vector<CommittedNode> committed_nodes_;
3225 std::vector<int> committed_index_;
3226 const int num_nodes_threshold_;
3227 std::vector<ChainBounds> chains_;
3228 std::vector<PathBounds> paths_;
3232 std::vector<std::pair<int, int>> changed_arcs_;
3233 std::vector<int> changed_paths_;
3234 std::vector<bool> path_has_changed_;
3238 std::vector<TailHeadIndices> tail_head_indices_;
3239 std::vector<IndexArc> arcs_by_tail_index_;
3240 std::vector<IndexArc> arcs_by_head_index_;
3241 std::vector<int> next_arc_;
3244 bool is_invalid_ =
false;
3258 return current_node_ != other.current_node_;
3264 explicit Iterator(
const CommittedNode* node) : current_node_(node) {}
3265 const CommittedNode* current_node_;
3270 Chain(
const CommittedNode* begin_node,
const CommittedNode* end_node)
3271 : begin_(begin_node), end_(end_node) {}
3274 int First()
const {
return begin_->node; }
3275 int Last()
const {
return (end_ - 1)->node; }
3280 const CommittedNode*
const begin_;
3281 const CommittedNode*
const end_;
3294 return {first_node_ + current_chain_->begin_index,
3295 first_node_ + current_chain_->end_index};
3298 return current_chain_ != other.current_chain_;
3304 Iterator(
const ChainBounds* chain,
const CommittedNode*
const first_node)
3305 : current_chain_(chain), first_node_(first_node) {}
3306 const ChainBounds* current_chain_;
3307 const CommittedNode*
const first_node_;
3313 const ChainBounds*
const end_chain,
3314 const CommittedNode*
const first_node)
3315 : begin_(begin_chain), end_(end_chain), first_node_(first_node) {}
3321 const ChainBounds*
const begin_;
3322 const ChainBounds*
const end_;
3323 const CommittedNode*
const first_node_;
3334 if (current_node_ == end_node_) {
3338 const ChainBounds
bounds = *current_chain_;
3339 current_node_ = first_node_ +
bounds.begin_index;
3340 end_node_ = first_node_ +
bounds.end_index;
3346 return current_chain_ != other.current_chain_;
3352 Iterator(
const ChainBounds* current_chain,
3353 const CommittedNode*
const first_node)
3354 : current_node_(first_node + current_chain->begin_index),
3355 end_node_(first_node + current_chain->end_index),
3356 current_chain_(current_chain),
3357 first_node_(first_node) {}
3358 const CommittedNode* current_node_;
3359 const CommittedNode* end_node_;
3360 const ChainBounds* current_chain_;
3361 const CommittedNode*
const first_node_;
3366 NodeRange(
const ChainBounds* begin_chain,
const ChainBounds* end_chain,
3367 const CommittedNode* first_node)
3368 : begin_chain_(begin_chain),
3369 end_chain_(end_chain),
3370 first_node_(first_node) {}
3377 const ChainBounds* begin_chain_;
3378 const ChainBounds* end_chain_;
3379 const CommittedNode*
const first_node_;
3404 std::vector<Interval> path_capacity,
3405 std::vector<int> path_class,
3406 std::vector<std::vector<Interval>>
demand,
3407 std::vector<Interval> node_capacity);
3423 Interval GetMinMaxPartialDemandSum(
int first_node_index,
3424 int last_node_index)
const;
3430 bool SubpathOnlyHasTrivialNodes(
int first_node_index,
3431 int last_node_index)
const;
3437 void IncrementalCommit();
3440 void AppendPathDemandsToSums(
int path);
3446 void UpdateRMQStructure(
int begin_index,
int end_index);
3449 const std::vector<Interval> path_capacity_;
3450 const std::vector<int> path_class_;
3451 const std::vector<std::vector<Interval>> demand_;
3452 const std::vector<Interval> node_capacity_;
3458 std::vector<int> index_;
3468 std::vector<std::vector<Interval>> partial_demand_sums_rmq_;
3471 const int maximum_partial_demand_layer_size_;
3476 std::vector<int> previous_nontrivial_index_;
3485 std::unique_ptr<PathState> path_state,
3486 const std::vector<IntVar*>& nexts);
3496 Solver* solver, std::unique_ptr<UnaryDimensionChecker> checker,
3497 const std::string& dimension_name);
const std::vector< IntVar * > vars_
#define DCHECK_LE(val1, val2)
#define CHECK_EQ(val1, val2)
#define CHECK_GE(val1, val2)
#define CHECK_GT(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)
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
bool Contains(const V *const var) const
const E & Element(const V *const var) const
E * MutableElement(const V *const var)
An Assignment is a variable -> domains mapping, used to report solutions to the user.
SequenceContainer * MutableSequenceVarContainer()
const SequenceContainer & SequenceVarContainer() const
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 SetContentFromBitsetOfSameSize(const Bitset64< OtherIndexType > &other)
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 int64_t Max() const =0
The class IntVar is a subset of IntExpr.
The class Iterator has two direct subclasses.
virtual void OnSynchronize(const Assignment *delta)
IntVar * Var(int index) const
bool FindIndex(IntVar *const var, int64_t *index) const
int64_t Value(int index) const
bool IsVarSynced(int index) const
bool ValueFromAssignment(const Assignment &assignment, IntVar *var, int64_t index, int64_t *value)
IntVarLocalSearchHandler()
IntVarLocalSearchHandler(const IntVarLocalSearchHandler &other)
IntVarLocalSearchHandler(IntVarLocalSearchOperator *op)
void OnRevertChanges(int64_t index, int64_t value)
void AddToAssignment(IntVar *var, int64_t value, bool active, std::vector< int > *assignment_indices, int64_t index, Assignment *assignment) const
Specialization of LocalSearchOperator built from an array of IntVars which specifies the scope of the...
int64_t OldInverseValue(int64_t index) const
int64_t InverseValue(int64_t index) const
friend class IntVarLocalSearchHandler
void SetOldInverseValue(int64_t index, int64_t value)
~IntVarLocalSearchOperator() override
void SetInverseValue(int64_t index, int64_t value)
IntVarLocalSearchOperator()
IntVarLocalSearchOperator(const std::vector< IntVar * > &vars, bool keep_inverse_values=false)
bool IsInverseValue(int64_t index) const
Interval variables are often used in scheduling.
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
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.
virtual IntExpr * FindVarArrayExpression(const std::vector< IntVar * > &vars, VarArrayExpressionType type) const =0
Var Array Expressions.
virtual IntExpr * FindVarArrayConstantArrayExpression(const std::vector< IntVar * > &vars, const std::vector< int64_t > &values, VarArrayConstantArrayExpressionType type) const =0
Var Array Constant Array Expressions.
virtual IntExpr * FindExprConstantExpression(IntExpr *const expr, int64_t value, ExprConstantExpressionType type) const =0
Expr Constant Expressions.
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 * FindExprExpression(IntExpr *const expr, ExprExpressionType type) const =0
Expr Expressions.
virtual IntExpr * FindVarConstantConstantExpression(IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantExpressionType type) const =0
Var Constant Constant 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 * FindExprExprConstantExpression(IntExpr *const var1, IntExpr *const var2, int64_t constant, ExprExprConstantExpressionType type) const =0
Expr Expr Constant Expressions.
VarConstantConstantExpressionType
@ VAR_CONSTANT_CONSTANT_EXPRESSION_MAX
VarConstantConstantConstraintType
@ VAR_CONSTANT_CONSTANT_CONSTRAINT_MAX
virtual void InsertVoidConstraint(Constraint *const ct, VoidConstraintType type)=0
virtual Constraint * FindVarConstantConstraint(IntVar *const var, int64_t value, VarConstantConstraintType type) const =0
Var Constant Constraints.
@ 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 * FindVoidConstraint(VoidConstraintType type) const =0
Void constraints.
virtual IntExpr * FindVarConstantArrayExpression(IntVar *const var, const std::vector< int64_t > &values, VarConstantArrayExpressionType type) const =0
Var Constant Array Expressions.
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 IntExpr * FindVarArrayConstantExpression(const std::vector< IntVar * > &vars, int64_t value, VarArrayConstantExpressionType type) const =0
Var Array Constant Expressions.
virtual Constraint * FindVarConstantConstantConstraint(IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantConstraintType type) const =0
Var Constant Constant Constraints.
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 IntExpr * FindExprExprExpression(IntExpr *const var1, IntExpr *const var2, ExprExprExpressionType type) const =0
Expr Expr Expressions.
virtual void InsertVarConstantConstantExpression(IntExpr *const expression, IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantExpressionType type)=0
VarConstantArrayExpressionType
@ VAR_CONSTANT_ARRAY_EXPRESSION_MAX
virtual void InsertVarConstantConstantConstraint(Constraint *const ct, IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantConstraintType type)=0
virtual Constraint * FindExprExprConstraint(IntExpr *const expr1, IntExpr *const expr2, ExprExprConstraintType type) const =0
Expr Expr Constraints.
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
Subclass of Rev<T> which adds numerical operations.
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.
const std::vector< int64_t > & path_starts() const
Returns the vector of path start nodes.
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_
void SetNext(int64_t from, int64_t to, int64_t path)
Sets 'to' to be the node after 'from' on the given path.
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 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.
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.
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(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
const std::vector< std::pair< int, int > > & ChangedArcs() const
int Start(int path) const
void ChangeNext(int node, int new_next)
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.
Reversible array of POD types.
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)
This class adds reversibility to a POD type.
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)
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.
bool ContainsKey(const K &key) const
Returns true if the multi-map contains at least one instance of 'key'.
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)
const int & operator[](int index) const
void RankFirst(Solver *const solver, int elt)
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.
The SequenceVarElement stores a partial representation of ranked interval variables in the underlying...
void SetBackwardSequence(const std::vector< int > &backward_sequence)
const std::vector< int > & ForwardSequence() const
void SetForwardSequence(const std::vector< int > &forward_sequence)
SequenceVar * Var() const
A sequence variable is a variable whose domain is a set of possible orderings of the interval variabl...
void OnRevertChanges(int64_t index, const std::vector< int > &value)
bool ValueFromAssignment(const Assignment &assignment, SequenceVar *var, int64_t index, std::vector< int > *value)
SequenceVarLocalSearchHandler(const SequenceVarLocalSearchHandler &other)
SequenceVarLocalSearchHandler()
SequenceVarLocalSearchHandler(SequenceVarLocalSearchOperator *op)
void AddToAssignment(SequenceVar *var, const std::vector< int > &value, bool active, std::vector< int > *assignment_indices, int64_t index, Assignment *assignment) const
void SetBackwardSequence(int64_t index, const std::vector< int > &value)
void SetForwardSequence(int64_t index, const std::vector< int > &value)
~SequenceVarLocalSearchOperator() override
const std::vector< int > & Sequence(int64_t index) const
Returns the value in the current assignment of the variable of given index.
std::vector< std::vector< int > > backward_values_
SequenceVarLocalSearchOperator(const std::vector< SequenceVar * > &vars)
const std::vector< int > & OldSequence(int64_t index) const
SequenceVarLocalSearchOperator()
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.
const T * Last() const
Returns the last item of the FIFO.
const T & LastValue() const
Returns 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)
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...
void SaveAndSetValue(T *adr, T val)
All-in-one SaveAndSetValue.
T * RevAlloc(T *object)
Registers the given object as being reversible.
void Set(IntegerType index)
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
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()
const RevIntSet< int > & active_words() const
Returns the set of active word indices.
bool Empty() const
This method returns true if the active bitset is null.
int ActiveWordSize() const
This method returns the number of non null 64 bit words in the bitset representation.
Base operator class for operators manipulating variables.
void Activate(int64_t index)
void RevertChanges(bool incremental)
void Deactivate(int64_t index)
std::vector< Val > old_values_
virtual bool SkipUnchanged(int index) const
void SetValue(int64_t index, const Val &value)
bool HoldsDelta() const override
std::vector< Val > values_
const Val & Value(int64_t index) const
Returns the value in the current assignment of the variable of given index.
SparseBitset delta_changes_
std::vector< Val > prev_values_
const Val & OldValue(int64_t index) const
std::vector< int > assignment_indices_
bool Activated(int64_t index) const
V * Var(int64_t index) const
Returns the variable of given index.
virtual bool IsIncremental() const
bool ApplyChanges(Assignment *delta, Assignment *deltadelta) const
VarLocalSearchOperator(Handler var_handler)
virtual void OnStart()
Called by Start() after synchronizing the operator with the current assignment.
void MarkChange(int64_t index)
OnStart() should really be protected, but then SWIG doesn't see it.
~VarLocalSearchOperator() override
void AddVars(const std::vector< V * > &vars)
void Start(const Assignment *assignment) override
This method should not be overridden.
std::vector< int64_t > to_remove_
SharedBoundsManager * bounds
GurobiMPCallbackContext * context
static const int64_t kint64max
static const int64_t kint64min
std::function< int64_t(const Model &)> Value(IntegerVariable v)
Collection of objects used to extend the Constraint Solver library.
std::string ParameterDebugString(P param)
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.
LocalSearchFilter * MakeUnaryDimensionFilter(Solver *solver, std::unique_ptr< UnaryDimensionChecker > checker, const std::string &dimension_name)
Demon * MakeConstraintDemon3(Solver *const s, T *const ct, void(T::*method)(P, Q, R), const std::string &name, P param1, Q param2, R param3)
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)
bool IsArrayBoolean(const std::vector< T > &values)
VarTypes
This enum is used internally to do dynamic typing on subclasses of integer variables.
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)
Demon * MakeConstraintDemon2(Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
Demon * MakeDelayedConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
Demon * MakeDelayedConstraintDemon2(Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
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)
bool AreAllStrictlyNegative(const std::vector< T > &values)
int64_t MinVarArray(const std::vector< IntVar * > &vars)
Demon * MakeConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
bool IsIncreasingContiguous(const std::vector< T > &values)
bool AreAllNull(const std::vector< T > &values)
bool AreAllPositive(const std::vector< T > &values)
std::vector< int64_t > ToInt64Vector(const std::vector< int > &input)
Demon * MakeDelayedConstraintDemon1(Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1)
VarLocalSearchOperator< SequenceVar, std::vector< int >, SequenceVarLocalSearchHandler > SequenceVarLocalSearchOperatorTemplate
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
Demon * MakeConstraintDemon1(Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1)
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)
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.