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;
137 class SimpleRevFIFO {
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__) || \ 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_;
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,
771 #endif // !defined(SWIG) 807 template <
class V,
class Val,
class Handler>
821 const int size =
Size();
823 <<
"Assignment contains fewer variables than operator";
824 for (
int i = 0; i < size; ++i) {
897 vars_.insert(
vars_.end(), vars.begin(), vars.end());
898 const int64_t size =
Size();
947 std::vector<int>* assignment_indices, int64_t
index,
952 if (assignment_indices !=
nullptr) {
953 if ((*assignment_indices)[
index] == -1) {
954 (*assignment_indices)[
index] = container->
Size();
992 #if defined(SWIGPYTHON) 994 %unignore VarLocalSearchOperator<IntVar, int64_t,
995 IntVarLocalSearchHandler>::Size;
996 %unignore VarLocalSearchOperator<IntVar, int64_t,
997 IntVarLocalSearchHandler>
::Value;
998 %unignore VarLocalSearchOperator<IntVar, int64_t,
999 IntVarLocalSearchHandler>::OldValue;
1000 %unignore VarLocalSearchOperator<IntVar, int64_t,
1001 IntVarLocalSearchHandler>::SetValue;
1002 %feature(
"director") VarLocalSearchOperator<IntVar, int64_t,
1003 IntVarLocalSearchHandler>::IsIncremental;
1004 %feature("director") VarLocalSearchOperator<IntVar, int64_t,
1005 IntVarLocalSearchHandler>::OnStart;
1006 %unignore VarLocalSearchOperator<IntVar, int64_t,
1007 IntVarLocalSearchHandler>::IsIncremental;
1008 %unignore VarLocalSearchOperator<IntVar, int64_t,
1009 IntVarLocalSearchHandler>::OnStart;
1011 #endif // SWIGPYTHON 1014 %rename(IntVarLocalSearchOperatorTemplate)
1015 VarLocalSearchOperator<IntVar, int64_t, IntVarLocalSearchHandler>;
1016 %
template(IntVarLocalSearchOperatorTemplate)
1017 VarLocalSearchOperator<IntVar, int64_t, IntVarLocalSearchHandler>;
1029 bool keep_inverse_values =
false)
1032 max_inverse_value_(keep_inverse_values ? vars.size() - 1 : -1) {
1034 if (keep_inverse_values) {
1035 int64_t max_value = -1;
1039 inverse_values_.resize(max_value + 1, -1);
1040 old_inverse_values_.resize(max_value + 1, -1);
1059 virtual bool MakeOneNeighbor();
1063 return index <= max_inverse_value_;
1069 return old_inverse_values_[
index];
1081 const int64_t max_inverse_value_;
1082 std::vector<int64_t> old_inverse_values_;
1083 std::vector<int64_t> inverse_values_;
1090 if (element->
Var() !=
var) {
1092 <<
"Assignment does not contain operator variable " <<
var;
1121 bool active, std::vector<int>* assignment_indices,
1125 void OnRevertChanges(int64_t
index,
const std::vector<int>&
value);
1140 SequenceVar, std::vector<int>, SequenceVarLocalSearchHandler>;
1142 SequenceVar, std::vector<int>, SequenceVarLocalSearchHandler>;
1146 typedef VarLocalSearchOperator<SequenceVar, std::vector<int>,
1147 SequenceVarLocalSearchHandler>
1182 std::vector<int>* assignment_indices, int64_t
index,
1187 if (assignment_indices !=
nullptr) {
1188 if ((*assignment_indices)[
index] == -1) {
1189 (*assignment_indices)[
index] = container->
Size();
1208 std::vector<int>*
value) {
1212 if (element->
Var() !=
var) {
1214 <<
"Assignment does not contain operator variable " <<
var;
1220 *
value = element_value;
1225 int64_t
index,
const std::vector<int>&
value) {
1262 explicit BaseLns(
const std::vector<IntVar*>& vars);
1276 void OnStart()
override;
1277 std::vector<int> fragment_;
1286 explicit ChangeValue(
const std::vector<IntVar*>& vars);
1295 void OnStart()
override;
1338 const std::vector<IntVar*>& path_vars,
1341 const std::vector<IntVar*>& path_vars,
int number_of_base_nodes,
1342 bool skip_locally_optimal_paths,
bool accept_path_end_base,
1343 std::function<
int(int64_t)> start_empty_path_class)
1345 next_vars, path_vars,
1346 {number_of_base_nodes, skip_locally_optimal_paths,
1347 accept_path_end_base, std::move(start_empty_path_class)}) {}
1350 void Reset()
override;
1386 int64_t
BaseNode(
int i)
const {
return base_nodes_[i]; }
1392 const int alternative_index = alternative_index_[
BaseNode(i)];
1393 return alternative_index >= 0
1394 ? alternative_sets_[alternative_index][base_alternatives_[i]]
1399 return base_sibling_alternatives_[i];
1404 const int sibling_alternative_index =
1406 return sibling_alternative_index >= 0
1407 ? alternative_sets_[sibling_alternative_index]
1408 [base_sibling_alternatives_[i]]
1412 int64_t
StartNode(
int i)
const {
return path_starts_[base_paths_[i]]; }
1414 const std::vector<int64_t>&
path_starts()
const {
return path_starts_; }
1470 bool MoveChain(int64_t before_chain, int64_t chain_end, int64_t destination);
1474 bool ReverseChain(int64_t before_chain, int64_t after_chain,
1475 int64_t* chain_last);
1478 bool MakeActive(int64_t node, int64_t destination);
1486 void SetNext(int64_t from, int64_t to, int64_t path) {
1505 return !
IsPathEnd(node) && inactives_[node];
1520 const int alternative = alternative_sets_.size();
1521 for (int64_t node : alternative_set) {
1522 DCHECK_EQ(-1, alternative_index_[node]);
1523 alternative_index_[node] = alternative;
1525 alternative_sets_.push_back(alternative_set);
1526 sibling_alternative_.push_back(-1);
1533 const std::vector<std::pair<std::vector<int64_t>, std::vector<int64_t>>>&
1534 pair_alternative_sets) {
1535 for (
const auto& pair_alternative_set : pair_alternative_sets) {
1537 sibling_alternative_.back() = alternative + 1;
1544 return alternative_index >= 0
1545 ? active_in_alternative_set_[alternative_index]
1554 if (node >= alternative_index_.size())
return -1;
1555 const int alternative = alternative_index_[node];
1556 return alternative >= 0 ? sibling_alternative_[alternative] : -1;
1561 if (node >= alternative_index_.size())
return -1;
1562 const int alternative = alternative_index_[node];
1563 const int sibling_alternative =
1564 alternative >= 0 ? sibling_alternative_[alternative] : -1;
1570 int64_t exclude)
const;
1579 void OnStart()
override;
1581 bool OnSamePath(int64_t node1, int64_t node2)
const;
1583 bool CheckEnds()
const {
1584 const int base_node_size = base_nodes_.size();
1585 for (
int i = base_node_size - 1; i >= 0; --i) {
1586 if (base_nodes_[i] != end_nodes_[i]) {
1592 bool IncrementPosition();
1593 void InitializePathStarts();
1594 void InitializeInactives();
1595 void InitializeBaseNodes();
1596 void InitializeAlternatives();
1599 std::vector<int> base_nodes_;
1600 std::vector<int> base_alternatives_;
1601 std::vector<int> base_sibling_alternatives_;
1602 std::vector<int> end_nodes_;
1603 std::vector<int> base_paths_;
1604 std::vector<int64_t> path_starts_;
1605 std::vector<bool> inactives_;
1608 IterationParameters iteration_parameters_;
1609 bool optimal_paths_enabled_;
1610 std::vector<int> path_basis_;
1611 std::vector<bool> optimal_paths_;
1614 std::vector<std::vector<int64_t>> alternative_sets_;
1616 std::vector<int> alternative_index_;
1617 std::vector<int64_t> active_in_alternative_set_;
1618 std::vector<int> sibling_alternative_;
1624 Solver* solver,
const std::vector<IntVar*>& vars,
1625 const std::vector<IntVar*>& secondary_vars,
1626 std::function<
int(int64_t)> start_empty_path_class);
1655 class LocalSearchVariable;
1672 void RelaxVariableBounds(
int variable_index);
1673 bool TightenVariableMin(
int variable_index, int64_t
value);
1674 bool TightenVariableMax(
int variable_index, int64_t
value);
1675 int64_t VariableMin(
int variable_index)
const;
1676 int64_t VariableMax(
int variable_index)
const;
1678 std::vector<Bounds> initial_variable_bounds_;
1679 std::vector<Bounds> variable_bounds_;
1680 std::vector<std::pair<Bounds, int>> saved_variable_bounds_trail_;
1681 std::vector<bool> variable_is_relaxed_;
1682 bool state_is_valid_ =
true;
1692 int64_t
Min()
const {
return state_->VariableMin(variable_index_); }
1693 int64_t
Max()
const {
return state_->VariableMax(variable_index_); }
1695 return state_->TightenVariableMin(variable_index_, new_min);
1698 return state_->TightenVariableMax(variable_index_, new_max);
1700 void Relax() { state_->RelaxVariableBounds(variable_index_); }
1707 : state_(state), variable_index_(variable_index) {}
1710 const int variable_index_;
1712 #endif // !defined(SWIG) 1748 int64_t objective_min, int64_t objective_max) = 0;
1785 return "LocalSearchFilterManager";
1801 const Assignment* deltadelta, int64_t objective_min,
1802 int64_t objective_max);
1809 void InitializeForcedEvents();
1811 std::vector<FilterEvent> filter_events_;
1812 int last_event_called_ = -1;
1817 std::vector<int> next_forced_events_;
1818 int64_t synchronized_value_;
1819 int64_t accepted_value_;
1833 const int var_index =
var->index();
1834 *
index = (var_index < var_index_to_index_.size())
1835 ? var_index_to_index_[var_index]
1837 return *
index != kUnassigned;
1841 void AddVars(
const std::vector<IntVar*>& vars);
1842 int Size()
const {
return vars_.size(); }
1846 return values_[
index];
1855 std::vector<IntVar*> vars_;
1856 std::vector<int64_t> values_;
1857 std::vector<bool> var_synced_;
1858 std::vector<int> var_index_to_index_;
1859 static const int kUnassigned;
1866 std::string
DebugString()
const override {
return "PropagationMonitor"; }
1885 virtual void SetMin(
IntExpr*
const expr, int64_t new_min) = 0;
1886 virtual void SetMax(
IntExpr*
const expr, int64_t new_max) = 0;
1888 int64_t new_max) = 0;
1893 int64_t new_max) = 0;
1899 const std::vector<int64_t>& values) = 0;
1901 const std::vector<int64_t>& values) = 0;
1906 int64_t new_max) = 0;
1910 int64_t new_max) = 0;
1914 int64_t new_max) = 0;
1922 const std::vector<int>& rank_first,
1923 const std::vector<int>& rank_last,
1924 const std::vector<int>& unperformed) = 0;
1934 std::string
DebugString()
const override {
return "LocalSearchMonitor"; }
1945 bool neighbor_found) = 0;
1948 bool neighbor_found) = 0;
1966 void SetMin(int64_t m)
override;
1968 void SetMax(int64_t m)
override;
1969 void SetRange(int64_t mi, int64_t ma)
override;
1980 uint64_t
Size()
const override;
1981 bool Contains(int64_t v)
const override;
1993 std::string
BaseName()
const override {
return "BooleanVar"; }
2011 : symmetry_manager_(nullptr), index_in_symmetry_manager_(-1) {}
2023 CHECK(symmetry_manager_ ==
nullptr);
2024 CHECK_EQ(-1, index_in_symmetry_manager_);
2025 symmetry_manager_ = manager;
2026 index_in_symmetry_manager_ =
index;
2028 SymmetryManager* symmetry_manager()
const {
return symmetry_manager_; }
2029 int index_in_symmetry_manager()
const {
return index_in_symmetry_manager_; }
2033 int index_in_symmetry_manager_;
2041 double scaling_factor,
double offset,
2042 std::function<std::string()> display_callback,
2043 bool display_on_new_solutions_only,
int period);
2061 virtual void OutputLine(
const std::string& line);
2064 static std::string MemoryUsage();
2067 std::unique_ptr<WallTimer> timer_;
2070 const double scaling_factor_;
2071 const double offset_;
2072 std::function<std::string()> display_callback_;
2073 const bool display_on_new_solutions_only_;
2076 int64_t objective_min_;
2077 int64_t objective_max_;
2078 int min_right_depth_;
2080 int sliding_min_depth_;
2081 int sliding_max_depth_;
2188 virtual void Clear() = 0;
2209 IntVar*
const var, int64_t value1, int64_t value2,
2270 IntVar*
const var, int64_t value1, int64_t value2,
2280 IntVar*
const var,
const std::vector<int64_t>& values,
2285 const std::vector<int64_t>& values,
2294 const std::vector<IntVar*>& vars,
2300 const std::vector<IntVar*>& vars,
const std::vector<int64_t>& values,
2304 IntExpr*
const expression,
const std::vector<IntVar*>&
var,
2305 const std::vector<int64_t>& values,
2311 const std::vector<IntVar*>& vars, int64_t
value,
2315 IntExpr*
const expression,
const std::vector<IntVar*>&
var, int64_t
value,
2329 const std::string&
TypeName()
const;
2335 const std::vector<int64_t>& values);
2341 const std::vector<IntVar*>& vars);
2344 const std::vector<IntervalVar*>& vars);
2347 const std::vector<SequenceVar*>& vars);
2358 const std::string& arg_name)
const;
2360 const std::string& arg_name)
const;
2363 const std::string& arg_name)
const;
2365 const std::string& arg_name)
const;
2368 std::string type_name_;
2369 absl::flat_hash_map<std::string, int64_t> integer_argument_;
2370 absl::flat_hash_map<std::string, std::vector<int64_t>>
2371 integer_array_argument_;
2372 absl::flat_hash_map<std::string, IntTupleSet> matrix_argument_;
2373 absl::flat_hash_map<std::string, IntExpr*> integer_expression_argument_;
2374 absl::flat_hash_map<std::string, IntervalVar*> interval_argument_;
2375 absl::flat_hash_map<std::string, SequenceVar*> sequence_argument_;
2376 absl::flat_hash_map<std::string, std::vector<IntVar*>>
2377 integer_variable_array_argument_;
2378 absl::flat_hash_map<std::string, std::vector<IntervalVar*>>
2379 interval_array_argument_;
2380 absl::flat_hash_map<std::string, std::vector<SequenceVar*>>
2381 sequence_array_argument_;
2393 void EndVisitModel(
const std::string& solver_name)
override;
2395 const Constraint*
const constraint)
override;
2397 const Constraint*
const constraint)
override;
2399 const IntExpr*
const expr)
override;
2401 const IntExpr*
const expr)
override;
2403 IntExpr*
const delegate)
override;
2405 const std::string& operation, int64_t
value,
2406 IntVar*
const delegate)
override;
2408 const std::string& operation, int64_t
value,
2413 int64_t
value)
override;
2415 const std::vector<int64_t>& values)
override;
2420 IntExpr*
const argument)
override;
2422 const std::string& arg_name,
2423 const std::vector<IntVar*>& arguments)
override;
2428 const std::string& arg_name,
2429 const std::vector<IntervalVar*>& arguments)
override;
2434 const std::string& arg_name,
2435 const std::vector<SequenceVar*>& arguments)
override;
2443 std::vector<ArgumentHolder*> holders_;
2450 : index_min_(index_min),
2451 index_max_(index_max),
2452 values_(new T[index_max - index_min + 1]) {
2461 return values_[
index - index_min_];
2470 std::string
DebugString()
const override {
return "ArrayWithOffset"; }
2473 const int64_t index_min_;
2474 const int64_t index_max_;
2475 std::unique_ptr<T[]> values_;
2483 template <
class T,
class C>
2487 : block_size_(block_size), block_offset_(0) {
2492 for (
int i = 0; i < elements_.size(); ++i) {
2493 delete[] elements_[i];
2498 const int64_t block_index = ComputeBlockIndex(
index);
2499 const int64_t relative_index = block_index - block_offset_;
2500 if (relative_index < 0 || relative_index >= elements_.size()) {
2503 const T* block = elements_[relative_index];
2504 return block !=
nullptr ? block[
index - block_index * block_size_] : T();
2508 const int64_t block_index = ComputeBlockIndex(
index);
2509 T*
const block = GetOrCreateBlock(block_index);
2510 const int64_t residual =
index - block_index * block_size_;
2512 reinterpret_cast<C>(
value));
2516 T* NewBlock()
const {
2517 T*
const result =
new T[block_size_];
2518 for (
int i = 0; i < block_size_; ++i) {
2524 T* GetOrCreateBlock(
int block_index) {
2525 if (elements_.size() == 0) {
2526 block_offset_ = block_index;
2527 GrowUp(block_index);
2528 }
else if (block_index < block_offset_) {
2529 GrowDown(block_index);
2530 }
else if (block_index - block_offset_ >= elements_.size()) {
2531 GrowUp(block_index);
2533 T* block = elements_[block_index - block_offset_];
2534 if (block ==
nullptr) {
2536 elements_[block_index - block_offset_] = block;
2541 int64_t ComputeBlockIndex(int64_t
value)
const {
2543 : (
value - block_size_ + 1) / block_size_;
2546 void GrowUp(int64_t block_index) {
2547 elements_.resize(block_index - block_offset_ + 1);
2550 void GrowDown(int64_t block_index) {
2551 const int64_t
delta = block_offset_ - block_index;
2552 block_offset_ = block_index;
2554 elements_.insert(elements_.begin(),
delta,
nullptr);
2557 const int64_t block_size_;
2558 std::vector<T*> elements_;
2577 delete_position_(true) {
2578 for (
int i = 0; i <
capacity; ++i) {
2588 position_(shared_positions),
2589 delete_position_(false) {
2590 for (
int i = 0; i < shared_positions_size; ++i) {
2596 if (delete_position_) {
2608 return elements_[i];
2614 return elements_[i + num_elements_.
Value()];
2618 const int position = num_elements_.
Value();
2620 DCHECK(NotAlreadyInserted(elt));
2621 elements_[position] = elt;
2622 position_[elt] = position;
2623 num_elements_.
Incr(solver);
2627 num_elements_.
Decr(solver);
2628 SwapTo(value_index, num_elements_.
Value());
2632 SwapTo(value_index, num_elements_.
Value());
2633 num_elements_.
Incr(solver);
2645 bool NotAlreadyInserted(
const T& elt) {
2646 for (
int i = 0; i < num_elements_.
Value(); ++i) {
2647 if (elt == elements_[i]) {
2654 void SwapTo(T value_index,
int next_position) {
2655 const int current_position = position_[value_index];
2656 if (current_position != next_position) {
2657 const T next_value_index = elements_[next_position];
2658 elements_[current_position] = next_value_index;
2659 elements_[next_position] = value_index;
2660 position_[value_index] = next_position;
2661 position_[next_value_index] = current_position;
2666 std::unique_ptr<T[]> elements_;
2668 NumericalRev<int> num_elements_;
2670 const int capacity_;
2674 const bool delete_position_;
2684 last_ranked_(items.size() - 1),
2685 size_(items.size()),
2686 position_(new int[size_]) {
2687 for (
int i = 0; i < size_; ++i) {
2688 elements_[i] = items[i];
2696 last_ranked_(size - 1),
2698 position_(new int[size_]) {
2699 for (
int i = 0; i < size_; ++i) {
2717 return elements_[
index];
2723 SwapTo(elt, first_ranked_.
Value());
2724 first_ranked_.
Incr(solver);
2729 SwapTo(elt, last_ranked_.
Value());
2730 last_ranked_.
Decr(solver);
2734 const int position = position_[elt];
2735 return (position < first_ranked_.
Value() ||
2736 position > last_ranked_.
Value());
2740 std::string result =
"[";
2741 for (
int i = 0; i < first_ranked_.
Value(); ++i) {
2742 absl::StrAppend(&result, elements_[i]);
2743 if (i != first_ranked_.
Value() - 1) {
2748 for (
int i = first_ranked_.
Value(); i <= last_ranked_.
Value(); ++i) {
2749 absl::StrAppend(&result, elements_[i]);
2750 if (i != last_ranked_.
Value()) {
2755 for (
int i = last_ranked_.
Value() + 1; i < size_; ++i) {
2756 absl::StrAppend(&result, elements_[i]);
2757 if (i != size_ - 1) {
2766 void SwapTo(
int elt,
int next_position) {
2767 const int current_position = position_[elt];
2768 if (current_position != next_position) {
2769 const int next_elt = elements_[next_position];
2770 elements_[current_position] = next_elt;
2771 elements_[next_position] = elt;
2772 position_[elt] = next_position;
2773 position_[next_elt] = current_position;
2778 std::vector<int> elements_;
2780 NumericalRev<int> first_ranked_;
2782 NumericalRev<int> last_ranked_;
2786 std::unique_ptr<int[]> position_;
2802 void Init(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2810 bool RevAnd(
Solver*
const solver,
const std::vector<uint64_t>& mask);
2826 bool Intersects(
const std::vector<uint64_t>& mask,
int* support_index);
2836 void CleanUpActives(
Solver*
const solver);
2838 const int64_t bit_size_;
2839 const int64_t word_size_;
2842 std::vector<int> to_remove_;
2847 for (
int i = 0; i < values.size(); ++i) {
2848 if (values[i] !=
value) {
2857 for (
int i = 0; i < values.size(); ++i) {
2858 if (values[i] != 0 && values[i] != 1) {
2877 for (
const T& current_value : values) {
2878 if (current_value <
value) {
2887 for (
const T& current_value : values) {
2888 if (current_value >
value) {
2917 for (
int i = 0; i < values.size() - 1; ++i) {
2918 if (values[i + 1] != values[i] + 1) {
2927 for (
int i = 0; i < values.size() - 1; ++i) {
2928 if (values[i + 1] < values[i]) {
2938 for (
int i = 0; i < vars.size(); ++i) {
2939 if (vars[i]->Min() < range_min || vars[i]->Max() > range_max) {
2947 for (
int i = 0; i < vars.size(); ++i) {
2948 if (!vars[i]->Bound()) {
2963 const std::vector<T>& values) {
2964 for (
int i = 0; i < vars.size(); ++i) {
2965 if (values[i] != 0 && !vars[i]->Bound()) {
2974 for (
int i = 0; i < vars.size(); ++i) {
2975 if (!vars[i]->Bound() || vars[i]->Min() !=
value) {
2985 for (
int i = 0; i < vars.size(); ++i) {
2987 result = std::max<int64_t>(result, vars[i]->Max());
2995 for (
int i = 0; i < vars.size(); ++i) {
2997 result = std::min<int64_t>(result, vars[i]->Min());
3003 std::vector<int64_t>*
const values) {
3005 values->resize(vars.size());
3006 for (
int i = 0; i < vars.size(); ++i) {
3007 (*values)[i] = vars[i]->Value();
3013 return (e < 0 || e % v == 0) ? e / v : e / v + 1;
3018 return (e >= 0 || e % v == 0) ? e / v : e / v - 1;
3077 PathState(
int num_nodes, std::vector<int> path_start,
3078 std::vector<int> path_end);
3087 int Start(
int path)
const {
return path_start_end_[path].start; }
3089 int End(
int path)
const {
return path_start_end_[path].end; }
3095 return committed_nodes_[committed_index_[node]].path;
3100 return changed_arcs_;
3106 ChainRange
Chains(
int path)
const;
3108 NodeRange
Nodes(
int path)
const;
3115 changed_arcs_.emplace_back(node, new_next);
3136 struct PathStartEnd {
3137 PathStartEnd(
int start,
int end) : start(start), end(end) {}
3146 struct ChainBounds {
3147 ChainBounds() =
default;
3148 ChainBounds(
int begin_index,
int end_index)
3149 : begin_index(begin_index), end_index(end_index) {}
3153 struct CommittedNode {
3154 CommittedNode(
int node,
int path) : node(node), path(path) {}
3162 struct TailHeadIndices {
3169 bool operator<(
const IndexArc& other)
const {
return index < other.index; }
3174 void MakeChainsFromChangedPathsAndArcsWithSelectionAlgorithm();
3177 void MakeChainsFromChangedPathsAndArcsWithGenericAlgorithm();
3181 void CopyNewPathAtEndOfNodes(
int path);
3184 void IncrementalCommit();
3190 const int num_nodes_;
3191 const int num_paths_;
3192 std::vector<PathStartEnd> path_start_end_;
3219 std::vector<CommittedNode> committed_nodes_;
3220 std::vector<int> committed_index_;
3221 const int num_nodes_threshold_;
3222 std::vector<ChainBounds> chains_;
3223 std::vector<PathBounds> paths_;
3227 std::vector<std::pair<int, int>> changed_arcs_;
3228 std::vector<int> changed_paths_;
3229 std::vector<bool> path_has_changed_;
3233 std::vector<TailHeadIndices> tail_head_indices_;
3234 std::vector<IndexArc> arcs_by_tail_index_;
3235 std::vector<IndexArc> arcs_by_head_index_;
3236 std::vector<int> next_arc_;
3239 bool is_invalid_ =
false;
3253 return current_node_ != other.current_node_;
3259 explicit Iterator(
const CommittedNode* node) : current_node_(node) {}
3260 const CommittedNode* current_node_;
3265 Chain(
const CommittedNode* begin_node,
const CommittedNode* end_node)
3266 : begin_(begin_node), end_(end_node) {}
3269 int First()
const {
return begin_->node; }
3270 int Last()
const {
return (end_ - 1)->node; }
3275 const CommittedNode*
const begin_;
3276 const CommittedNode*
const end_;
3289 return {first_node_ + current_chain_->begin_index,
3290 first_node_ + current_chain_->end_index};
3293 return current_chain_ != other.current_chain_;
3299 Iterator(
const ChainBounds* chain,
const CommittedNode*
const first_node)
3300 : current_chain_(chain), first_node_(first_node) {}
3301 const ChainBounds* current_chain_;
3302 const CommittedNode*
const first_node_;
3308 const ChainBounds*
const end_chain,
3309 const CommittedNode*
const first_node)
3310 : begin_(begin_chain), end_(end_chain), first_node_(first_node) {}
3316 const ChainBounds*
const begin_;
3317 const ChainBounds*
const end_;
3318 const CommittedNode*
const first_node_;
3329 if (current_node_ == end_node_) {
3333 const ChainBounds
bounds = *current_chain_;
3334 current_node_ = first_node_ +
bounds.begin_index;
3335 end_node_ = first_node_ +
bounds.end_index;
3341 return current_chain_ != other.current_chain_;
3347 Iterator(
const ChainBounds* current_chain,
3348 const CommittedNode*
const first_node)
3349 : current_node_(first_node + current_chain->begin_index),
3350 end_node_(first_node + current_chain->end_index),
3351 current_chain_(current_chain),
3352 first_node_(first_node) {}
3353 const CommittedNode* current_node_;
3354 const CommittedNode* end_node_;
3355 const ChainBounds* current_chain_;
3356 const CommittedNode*
const first_node_;
3361 NodeRange(
const ChainBounds* begin_chain,
const ChainBounds* end_chain,
3362 const CommittedNode* first_node)
3363 : begin_chain_(begin_chain),
3364 end_chain_(end_chain),
3365 first_node_(first_node) {}
3372 const ChainBounds* begin_chain_;
3373 const ChainBounds* end_chain_;
3374 const CommittedNode*
const first_node_;
3399 std::vector<Interval> path_capacity,
3400 std::vector<int> path_class,
3401 std::vector<std::vector<Interval>>
demand,
3402 std::vector<Interval> node_capacity);
3418 Interval GetMinMaxPartialDemandSum(
int first_node_index,
3419 int last_node_index)
const;
3425 bool SubpathOnlyHasTrivialNodes(
int first_node_index,
3426 int last_node_index)
const;
3432 void IncrementalCommit();
3435 void AppendPathDemandsToSums(
int path);
3441 void UpdateRMQStructure(
int begin_index,
int end_index);
3444 const std::vector<Interval> path_capacity_;
3445 const std::vector<int> path_class_;
3446 const std::vector<std::vector<Interval>> demand_;
3447 const std::vector<Interval> node_capacity_;
3453 std::vector<int> index_;
3463 std::vector<std::vector<Interval>> partial_demand_sums_rmq_;
3466 const int maximum_partial_demand_layer_size_;
3471 std::vector<int> previous_nontrivial_index_;
3480 std::unique_ptr<PathState> path_state,
3481 const std::vector<IntVar*>& nexts);
3491 Solver* solver, std::unique_ptr<UnaryDimensionChecker> checker,
3492 const std::string& dimension_name);
3494 #endif // !defined(SWIG) 3498 #endif // OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVERI_H_
void BeginVisitConstraint(const std::string &type_name, const Constraint *const constraint) override
~VarLocalSearchOperator() override
Low-priority demon proxy to a method on the constraint with two arguments.
IntVar * Var() override
Creates a variable from the expression.
Base operator class for operators manipulating variables.
bool HasIntegerExpressionArgument(const std::string &arg_name) const
Checks if arguments exist.
This is the base class for building an Lns operator.
void AddIntegerVariableEqualValueClause(IntVar *const var, int64_t value)
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...
SparseBitset delta_changes_
void VisitIntervalArgument(const std::string &arg_name, IntervalVar *const argument) override
Visit interval argument.
This is a special class to represent a 'residual' set of T.
void SetContentFromBitsetOfSameSize(const Bitset64< OtherIndexType > &other)
SequenceContainer * MutableSequenceVarContainer()
const std::vector< int64_t > & FindIntegerArrayArgumentOrDie(const std::string &arg_name) const
virtual void RestoreValue()=0
std::string DebugString() const override
bool IsRanked(int elt) const
~DelayedCallMethod1() override
~SymmetryBreaker() override
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.
LocalSearchFilter * MakeUnaryDimensionFilter(Solver *solver, std::unique_ptr< UnaryDimensionChecker > checker, const std::string &dimension_name)
IntVar * IsDifferent(int64_t constant) override
bool FindIndex(IntVar *const var, int64_t *index) const
bool IsCardinalityOne() const
Does it contains only one bit set?
Set of parameters used to configure how the neighnorhood is traversed.
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 ...
virtual IntExpr * FindVarArrayConstantExpression(const std::vector< IntVar * > &vars, int64_t value, VarArrayConstantExpressionType type) const =0
Var Array Constant Expressions.
void Run(Solver *const s) override
This is the main callback of the demon.
void RankFirst(Solver *const solver, int elt)
void SetToZero(Solver *const solver, int64_t pos)
Erases the 'pos' bit.
void SetBackwardSequence(const std::vector< int > &backward_sequence)
void WhenBound(Demon *d) override
This method attaches a demon that will be awakened when the variable is bound.
std::vector< Val > old_values_
virtual bool MakeNeighbor()=0
The base class for all local search operators.
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.
const SequenceContainer & SequenceVarContainer() const
virtual void Relax(const Assignment *delta, const Assignment *deltadelta)
Lets the filter know what delta and deltadelta will be passed in the next Accept().
void AddVars(const std::vector< V * > &vars)
LocalSearchFilter * filter
int64_t GetFirstBit(int row, int start) const
Returns the first bit in the row 'row' which position is >= 'start'.
void Activate(int64_t index)
int64_t BaseSiblingAlternativeNode(int i) const
Returns the alternative node for the sibling of the ith base node.
void Set(IntegerType index)
std::string DebugString() const override
void EndVisitConstraint(const std::string &type_name, const Constraint *const constraint) override
int64_t PosIntDivDown(int64_t e, int64_t v)
bool operator!=(Iterator other) const
int64_t BaseAlternativeNode(int i) const
Returns the alternative node for the ith base node.
IntVarLocalSearchOperator(const std::vector< IntVar * > &vars, bool keep_inverse_values=false)
--— RevPartialSequence --—
void EndVisitModel(const std::string &solver_name) override
const std::vector< int > & ForwardSequence() const
#define CHECK_GE(val1, val2)
virtual bool NextFragment()=0
bool IsArrayBoolean(const std::vector< T > &values)
int GetSiblingAlternativeIndex(int node) const
Returns the index of the alternative set of the sibling of node.
void VisitIntegerVariableArrayArgument(const std::string &arg_name, const std::vector< IntVar * > &arguments) override
void SetValue(int64_t index, const Val &value)
virtual void EndAcceptNeighbor(const LocalSearchOperator *op, bool neighbor_found)=0
IntVarElement * FastAdd(IntVar *const var)
Adds without checking if variable has been previously added.
Base class of the local search operators dedicated to path modifications (a path is a set of nodes li...
const std::vector< IntVar * > & FindIntegerVariableArrayArgumentOrDie(const std::string &arg_name) const
IntVarLocalSearchHandler(IntVarLocalSearchOperator *op)
int64_t GetSynchronizedObjectiveValue() const
const int number_of_nexts_
virtual void InsertExprExprExpression(IntExpr *const expression, IntExpr *const var1, IntExpr *const var2, ExprExprExpressionType type)=0
bool IsSet(int64_t index) const
Returns whether the 'index' bit is set.
void VisitSequenceVariable(const SequenceVar *const variable) override
bool ContainsKey(const K &key) const
Returns true if the multi-map contains at least one instance of 'key'.
void Restore(Solver *const solver, const T &value_index)
int64_t PosIntDivUp(int64_t e, int64_t v)
bool RevSubtract(Solver *const solver, const std::vector< uint64_t > &mask)
This method subtracts the mask from the active bitset.
void SetToOne(Solver *const solver, int64_t index)
Sets the 'index' bit.
uint64_t Size() const override
This method returns the number of values in the domain of the variable.
virtual void SetEndMax(IntervalVar *const var, int64_t new_max)=0
T RemovedElement(int i) const
bool AreAllStrictlyNegative(const std::vector< T > &values)
Matrix version of the RevBitSet class.
SearchLog(Solver *const s, OptimizeVar *const obj, IntVar *const var, double scaling_factor, double offset, std::function< std::string()> display_callback, bool display_on_new_solutions_only, int period)
void VisitIntervalVariable(const IntervalVar *const variable, const std::string &operation, int64_t value, IntervalVar *const delegate) override
void SetNext(int64_t from, int64_t to, int64_t path)
Sets 'to' to be the node after 'from' on the given path.
ExprExprConstantExpressionType
std::vector< int > assignment_indices_
int64_t StartNode(int i) const
Returns the start node of the ith base node.
#define CHECK_GT(val1, val2)
LocalSearchVariable AddVariable(int64_t initial_min, int64_t initial_max)
bool IsCardinalityOne() const
Does it contains only one bit set?
void RevertChanges(bool incremental)
const std::string & TypeName() const
Type of the argument.
void SaveAndSetValue(T *adr, T val)
All-in-one SaveAndSetValue.
void BeginVisitIntegerExpression(const std::string &type_name, const IntExpr *const expr) override
ChainRange Chains(int path) const
void EndInitialPropagation() override
After the initial propagation.
int64_t BaseNode(int i) const
Returns the ith base node of the operator.
void Synchronize(const Assignment *assignment, const Assignment *delta) override
This method should not be overridden.
bool skip_locally_optimal_paths
Skip paths which have been proven locally optimal.
int PathClass(int i) const
Returns the class of the path of the ith base node.
bool SkipUnchanged(int index) const override
virtual void BeginMakeNextNeighbor(const LocalSearchOperator *op)=0
void SetInverseValue(int64_t index, int64_t value)
IntVar * Var(int index) const
bool Contains(int64_t v) const override
This method returns whether the value 'v' is in the domain of the variable.
virtual IntExpr * FindExprExprConstantExpression(IntExpr *const var1, IntExpr *const var2, int64_t constant, ExprExprConstantExpressionType type) const =0
Expr Expr Constant Expressions.
A Demon is the base element of a propagation queue.
DelayedCallMethod1(T *const ct, void(T::*method)(P), const std::string &name, P param1)
void SetSequenceArrayArgument(const std::string &arg_name, const std::vector< SequenceVar * > &vars)
virtual void SetDurationMax(IntervalVar *const var, int64_t new_max)=0
CallMethod2(T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
A DecisionVisitor is used to inspect a decision.
void ExitSearch() override
End of the search.
virtual void EndNestedConstraintInitialPropagation(Constraint *const parent, Constraint *const nested)=0
std::string DebugString() const override
Demon * MakeDelayedConstraintDemon1(Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1)
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)
std::string DebugString() const override
virtual std::string name() const
Object naming.
void VisitIntegerMatrixArgument(const std::string &arg_name, const IntTupleSet &values) override
virtual void OnSynchronize(const Assignment *delta)
virtual void SetPerformed(IntervalVar *const var, bool value)=0
virtual void InsertVarConstantConstraint(Constraint *const ct, IntVar *const var, int64_t value, VarConstantConstraintType type)=0
Low-priority demon proxy to a method on the constraint with one argument.
SequenceVarLocalSearchOperator(const std::vector< SequenceVar * > &vars)
void VisitIntegerArrayArgument(const std::string &arg_name, const std::vector< int64_t > &values) override
void ClearAll(Solver *const solver)
Cleans all bits.
int64_t OldPrev(int64_t node) const
virtual void BeginFiltering(const LocalSearchFilter *filter)=0
This class represents a reversible bitset.
const std::vector< std::pair< int, int > > & ChangedArcs() const
A constraint is the main modeling object.
std::vector< Val > prev_values_
int64_t Min() const override
V * Var(int64_t index) const
Returns the variable of given index.
virtual IntExpr * FindExprExprExpression(IntExpr *const var1, IntExpr *const var2, ExprExprExpressionType type) const =0
Expr Expr Expressions.
This class is a reversible growing array.
void RankLast(Solver *const solver, int elt)
RevGrowingArray(int64_t block_size)
bool IsInactive(int64_t node) const
Returns true if node is inactive.
const IntTupleSet & FindIntegerMatrixArgumentOrDie(const std::string &arg_name) const
int next_base_to_increment_
void OnRevertChanges(int64_t index, const std::vector< int > &value)
#define DCHECK_GT(val1, val2)
bool IsSet(int64_t row, int64_t column) const
Returns whether the 'column' bit in the 'row' row is set.
void Install() override
Install itself on the solver.
virtual void RankNotLast(SequenceVar *const var, int index)=0
virtual bool HoldsDelta() const
void Run(Solver *const s) override
This is the main callback of the demon.
void ClearAll(Solver *const solver)
Cleans all bits.
int64_t GetActiveAlternativeSibling(int node) const
Returns the active node in the alternative set of the sibling of the given node.
const E & Element(const V *const var) const
virtual int64_t ModifyValue(int64_t index, int64_t value)=0
IntVarLocalSearchOperator()
bool IsArrayInRange(const std::vector< IntVar * > &vars, T range_min, T range_max)
const std::vector< int > & OldSequence(int64_t index) const
void Run(Solver *const s) override
This is the main callback of the demon.
void AddToAssignment(IntVar *var, int64_t value, bool active, std::vector< int > *assignment_indices, int64_t index, Assignment *assignment) const
virtual void EndDemonRun(Demon *const demon)=0
void WhenDomain(Demon *d) override
This method attaches a demon that will watch any domain modification of the domain of the variable.
bool operator!=(Iterator other) const
void SetToOne(Solver *const solver, int64_t row, int64_t column)
Sets the 'column' bit in the 'row' row.
virtual void OnNodeInitialization()
Called by OnStart() after initializing node information.
void BeginFail() override
Just when the failure occurs.
IntVarLocalSearchHandler()
DelayedCallMethod0(T *const ct, void(T::*method)(), const std::string &name)
virtual void OnStart()
Called by Start() after synchronizing the operator with the current assignment.
virtual void RankLast(SequenceVar *const var, int index)=0
void SetIntegerExpressionArgument(const std::string &arg_name, IntExpr *const expr)
void SetForwardSequence(const std::vector< int > &forward_sequence)
void FillValues(const std::vector< IntVar * > &vars, std::vector< int64_t > *const values)
void BeginInitialPropagation() override
Before the initial propagation.
void RemoveValue(int64_t v) override
This method removes the value 'v' from the domain of the variable.
Defines operators which change the value of variables; each neighbor corresponds to one modified vari...
virtual void InsertExprExprConstantExpression(IntExpr *const expression, IntExpr *const var1, IntExpr *const var2, int64_t constant, ExprExprConstantExpressionType type)=0
virtual void SetValue(IntVar *const var, int64_t value)=0
virtual void RegisterDemon(Demon *const demon)=0
virtual void BeginConstraintInitialPropagation(Constraint *const constraint)=0
Propagation events.
virtual void InsertVarConstantConstantExpression(IntExpr *const expression, IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantExpressionType type)=0
void Push(Solver *const s, T val)
std::function< int64_t(const Model &)> Value(IntegerVariable v)
void SetIntegerArrayArgument(const std::string &arg_name, const std::vector< int64_t > &values)
void SetOldInverseValue(int64_t index, int64_t value)
virtual void SetDurationRange(IntervalVar *const var, int64_t new_min, int64_t new_max)=0
int number_of_nexts() const
Number of next variables.
BaseLns(const std::vector< IntVar * > &vars)
BooleanVar(Solver *const s, const std::string &name="")
Interval variables are often used in scheduling.
virtual void SetRange(IntExpr *const expr, int64_t new_min, int64_t new_max)=0
virtual void Start(const Assignment *assignment)=0
static constexpr int kNoInserted
This class represents a reversible bitset.
std::string DebugString() const override
void AddVars(const std::vector< IntVar * > &vars)
Add variables to "track" to the filter.
virtual void PushContext(const std::string &context)=0
bool Contains(const V *const var) const
Demon * MakeConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
const bool ignore_path_vars_
void OnRevertChanges(int64_t index, int64_t value)
std::string DebugString() const override
const std::vector< int64_t > & path_starts() const
Returns the vector of path start nodes.
bool AreAllBoundTo(const std::vector< IntVar * > &vars, int64_t value)
Returns true if all variables are assigned to 'value'.
virtual void BeginFilterNeighbor(const LocalSearchOperator *op)=0
std::string DebugString() const override
IntVarLocalSearchHandler(const IntVarLocalSearchHandler &other)
int64_t Next(int64_t node) const
Returns the node after node in the current delta.
bool StateIsValid() const
bool IsCardinalityZero() const
Is bitset null?
static const int64_t kint64min
int64_t Cardinality() const
Returns the number of bits set to one.
bool IsInverseValue(int64_t index) const
IntVarLocalSearchFilter(const std::vector< IntVar * > &vars)
virtual void BeginOperatorStart()=0
Local search operator events.
bool AreAllBooleans(const std::vector< IntVar * > &vars)
std::vector< int64_t > ToInt64Vector(const std::vector< int > &input)
int64_t bit_size() const
Returns the number of bits given in the constructor of the bitset.
void ApplyDecision(Decision *const decision) override
Before applying the decision.
IntVarIterator * MakeHoleIterator(bool reversible) const override
Creates a hole iterator.
Implements a complete cache for model elements: expressions and constraints.
int64_t GetFirstOne() const
Gets the index of the first bit set starting from 0.
Solver::DemonPriority priority() const override
This method returns the priority of the demon.
void CopyBucket(const Bitset64< IndexType > &other, IndexType i)
void SetToZero(Solver *const solver, int64_t row, int64_t column)
Erases the 'column' bit in the 'row' row.
void NoMoreSolutions() override
When the search tree is finished.
static const int64_t kint64max
Filter manager: when a move is made, filters are executed to decide whether the solution is feasible ...
void Remove(Solver *const solver, const T &value_index)
RevIntSet(int capacity)
Capacity is the fixed size of the set (it cannot grow).
Reversible Immutable MultiMap class.
void SetRange(int64_t mi, int64_t ma) override
This method sets both the min and the max of the expression.
SequenceVarLocalSearchHandler(const SequenceVarLocalSearchHandler &other)
This class encapsulates an objective.
void Run(Solver *const s) override
This is the main callback of the demon.
int64_t word_size() const
Returns the number of 64 bit words used to store the bitset.
std::vector< int64_t > start_to_path_
void AddIntegerVariableGreaterOrEqualValueClause(IntVar *const var, int64_t value)
IntExpr * FindIntegerExpressionArgumentOrDie(const std::string &arg_name) const
virtual bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta)=0
SequenceVarLocalSearchHandler(SequenceVarLocalSearchOperator *op)
bool AreAllGreaterOrEqual(const std::vector< T > &values, const T &value)
VarConstantConstantConstraintType
virtual void RemoveValues(IntVar *const var, const std::vector< int64_t > &values)=0
const std::vector< int > & ChangedPaths() const
The class Iterator has two direct subclasses.
~ArrayWithOffset() override
bool IsVarSynced(int index) const
bool CheckChainValidity(int64_t before_chain, int64_t chain_end, int64_t exclude) const
Returns true if the chain is a valid path without cycles from before_chain to chain_end and does not ...
virtual void EndProcessingIntegerVariable(IntVar *const var)=0
~DelayedCallMethod2() override
Demon proxy to a method on the constraint with no arguments.
CallMethod0(T *const ct, void(T::*method)(), const std::string &name)
virtual IntExpr * FindExprConstantExpression(IntExpr *const expr, int64_t value, ExprConstantExpressionType type) const =0
Expr Constant Expressions.
virtual void Revert()
Cancels the changes made by the last Relax()/Accept() calls.
void PushIfNotTop(Solver *const s, T val)
Pushes the var on top if is not a duplicate of the current top object.
void SynchronizeOnAssignment(const Assignment *assignment)
const int & operator[](int index) const
bool accept_path_end_base
True if path ends should be considered when iterating over neighbors.
The base class of all search logs that periodically outputs information when the search is running.
bool RevAnd(Solver *const solver, const std::vector< uint64_t > &mask)
This method ANDs the mask with the active bitset.
#define CHECK_LE(val1, val2)
virtual void InsertVoidConstraint(Constraint *const ct, VoidConstraintType type)=0
const Val & Value(int64_t index) const
Returns the value in the current assignment of the variable of given index.
UnaryDimensionChecker(const PathState *path_state, std::vector< Interval > path_capacity, std::vector< int > path_class, std::vector< std::vector< Interval >> demand, std::vector< Interval > node_capacity)
virtual void BeginNestedConstraintInitialPropagation(Constraint *const parent, Constraint *const nested)=0
bool Empty() const
This method returns true if the active bitset is null.
int NumLastRanked() const
void AppendToFragment(int index)
virtual void InsertVarArrayConstantExpression(IntExpr *const expression, const std::vector< IntVar * > &var, int64_t value, VarArrayConstantExpressionType type)=0
int64_t OldPath(int64_t node) const
bool ApplyChanges(Assignment *delta, Assignment *deltadelta) const
bool MakeOneNeighbor() override
This method should not be overridden. Override MakeNeighbor() instead.
VarTypes
This enum is used internally to do dynamic typing on subclasses of integer variables.
T At(int64_t index) const
void SetToOne(Solver *const solver, int64_t pos)
Sets the 'pos' bit.
~IntVarLocalSearchOperator() override
void Deactivate(int64_t index)
int64_t Path(int64_t node) const
Returns the index of the path to which node belongs in the current delta.
std::string DebugString() const
IntContainer * MutableIntVarContainer()
SimpleRevFIFO< Demon * > delayed_bound_demons_
virtual void SetStartRange(IntervalVar *const var, int64_t new_min, int64_t new_max)=0
The SequenceVarElement stores a partial representation of ranked interval variables in the underlying...
bool HasFragments() const override
VarConstantConstraintType
bool IsCardinalityZero() const
Is bitset null?
virtual void SetEndMin(IntervalVar *const var, int64_t new_min)=0
bool AreAllStrictlyPositive(const std::vector< T > &values)
DelayedCallMethod2(T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
std::string ParameterDebugString(P param)
virtual void EndFiltering(const LocalSearchFilter *filter, bool reject)=0
virtual void EndOperatorStart()=0
virtual void EndFilterNeighbor(const LocalSearchOperator *op, bool neighbor_found)=0
static int input(yyscan_t yyscanner)
A reversible switch that can switch once from false to true.
Iterator(const SimpleRevFIFO< T > *l)
bool SwapActiveAndInactive(int64_t active, int64_t inactive)
Replaces active by inactive in the current path, making active inactive.
VarArrayConstantExpressionType
virtual IntExpr * FindVarArrayExpression(const std::vector< IntVar * > &vars, VarArrayExpressionType type) const =0
Var Array Expressions.
int BaseAlternative(int i) const
Returns the alternative for the ith base node.
virtual void InsertVarArrayConstantArrayExpression(IntExpr *const expression, const std::vector< IntVar * > &var, const std::vector< int64_t > &values, VarArrayConstantArrayExpressionType type)=0
ModelCache(Solver *const solver)
void EndVisitIntegerExpression(const std::string &type_name, const IntExpr *const expr) override
virtual bool IsIncremental() const
SequenceVar * Var() const
int64_t Value() const override
This method returns the value of the variable.
An Assignment is a variable -> domains mapping, used to report solutions to the user.
void SetBackwardSequence(int64_t index, const std::vector< int > &value)
void SetIntervalArgument(const std::string &arg_name, IntervalVar *const var)
bool IsIncreasingContiguous(const std::vector< T > &values)
void VisitSequenceArrayArgument(const std::string &arg_name, const std::vector< SequenceVar * > &arguments) override
std::string DebugString() const override
bool Activated(int64_t index) const
void RemoveInterval(int64_t l, int64_t u) override
This method removes the interval 'l' .
Low-priority demon proxy to a method on the constraint with no arguments.
Argument Holder: useful when visiting a model.
virtual void SetMin(IntExpr *const expr, int64_t new_min)=0
IntExpr modifiers.
friend class SymmetryManager
A BaseObject is the root of all reversibly allocated objects.
virtual void SetStartMax(IntervalVar *const var, int64_t new_max)=0
Solver::DemonPriority priority() const override
This method returns the priority of the demon.
The class IntVar is a subset of IntExpr.
~DelayedCallMethod0() override
int64_t FindIntegerArgumentOrDie(const std::string &arg_name) const
#define DCHECK_GE(val1, val2)
void EnterSearch() override
Beginning of the search.
void RevInsert(Solver *const solver, int64_t index, T value)
int64_t GetFirstBit(int start) const
Gets the index of the first bit set starting from start.
ChainRange(const ChainBounds *const begin_chain, const ChainBounds *const end_chain, const CommittedNode *const first_node)
virtual void SetValues(IntVar *const var, const std::vector< int64_t > &values)=0
int NumFirstRanked() const
void AddIntegerVariableLessOrEqualValueClause(IntVar *const var, int64_t value)
The class IntExpr is the base of all integer expressions in constraint programming.
const T * const_iterator
Iterators on the indices.
bool ValueFromAssignment(const Assignment &assignment, SequenceVar *var, int64_t index, std::vector< int > *value)
~IntVarLocalSearchFilter() override
LocalSearchMonitor(Solver *const solver)
bool IsArrayConstant(const std::vector< T > &values, const T &value)
int number_of_base_nodes
Number of nodes needed to define a neighbor.
int Start(int path) const
const RevIntSet< int > & active_words() const
Returns the set of active word indices.
bool AreAllOnes(const std::vector< T > &values)
NodeRange(const ChainBounds *begin_chain, const ChainBounds *end_chain, const CommittedNode *first_node)
virtual void SetNextBaseToIncrement(int64_t base_index)
Set the next base to increment on next iteration.
virtual void RemoveInterval(IntVar *const var, int64_t imin, int64_t imax)=0
virtual bool ConsiderAlternatives(int64_t base_index) const
Indicates if alternatives should be considered when iterating over base nodes.
#define CHECK_EQ(val1, val2)
void Incr(Solver *const s)
std::string DebugString() const override
int64_t MaxVarArray(const std::vector< IntVar * > &vars)
bool SetMin(int64_t new_min)
int64_t OldInverseValue(int64_t index) const
bool AreAllNegative(const std::vector< T > &values)
uint64_t Hash1(uint64_t value)
Hash functions.
void VisitSequenceArgument(const std::string &arg_name, SequenceVar *const argument) override
Visit sequence argument.
UnsortedNullableRevBitset(int bit_size)
Size is the number of bits to store in the bitset.
void RefuteDecision(Decision *const decision) override
Before refuting the decision.
virtual void SetStartMin(IntervalVar *const var, int64_t new_min)=0
IntervalVar modifiers.
SmallRevBitSet(int64_t size)
E * MutableElement(const V *const var)
PropagationMonitor(Solver *const solver)
int BaseSiblingAlternative(int i) const
Returns the alternative for the sibling of the ith base node.
bool Accept(LocalSearchMonitor *const monitor, const Assignment *delta, const Assignment *deltadelta, int64_t objective_min, int64_t objective_max)
Returns true iff all filters return true, and the sum of their accepted objectives is between objecti...
This class represent a reversible FIFO structure.
virtual void InsertExprConstantExpression(IntExpr *const expression, IntExpr *const var, int64_t value, ExprConstantExpressionType type)=0
friend class IntVarLocalSearchHandler
T * RevAlloc(T *object)
Registers the given object as being reversible.
virtual void EndConstraintInitialPropagation(Constraint *const constraint)=0
CallMethod1(T *const ct, void(T::*method)(P), const std::string &name, P param1)
SequenceVarLocalSearchHandler()
void Run(Solver *const s) override
This is the main callback of the demon.
void VisitIntegerArgument(const std::string &arg_name, int64_t value) override
Integer arguments.
ChangeValue(const std::vector< IntVar * > &vars)
void PushArgumentHolder()
Demon proxy to a method on the constraint with three arguments.
VarLocalSearchOperator< SequenceVar, std::vector< int >, SequenceVarLocalSearchHandler > SequenceVarLocalSearchOperatorTemplate
void SetMax(int64_t m) override
IntVar * IsLessOrEqual(int64_t constant) override
#define DCHECK(condition)
void ResetPosition()
Reset the position of the operator to its position when Start() was last called; this can be used to ...
A sequence variable is a variable whose domain is a set of possible orderings of the interval variabl...
bool AreAllBound(const std::vector< IntVar * > &vars)
virtual void BeginDemonRun(Demon *const demon)=0
Demon proxy to a method on the constraint with one argument.
virtual IntExpr * FindVarConstantArrayExpression(IntVar *const var, const std::vector< int64_t > &values, VarConstantArrayExpressionType type) const =0
Var Constant Array Expressions.
virtual bool InitPosition() const
Returns true if the operator needs to restart its initial position at each call to Start()
SimpleRevFIFO< Demon * > bound_demons_
int64_t OldNext(int64_t node) const
virtual bool RestartAtPathStartOnSynchronize()
When the operator is being synchronized with a new solution (when Start() is called),...
int64_t GetActiveInAlternativeSet(int alternative_index) const
Returns the active node in the given alternative set.
std::string BaseName() const override
Returns a base name for automatic naming.
int AddAlternativeSet(const std::vector< int64_t > &alternative_set)
Handling node alternatives.
virtual int64_t GetAcceptedObjectiveValue() const
Objective value from the last time Accept() was called and returned true.
int64_t Max() const override
bool Bound() const override
Returns true if the min and the max of the expression are equal.
bool HasIntegerVariableArrayArgument(const std::string &arg_name) const
const std::vector< int > & Sequence(int64_t index) const
Returns the value in the current assignment of the variable of given index.
virtual bool IsIncremental() const
virtual void SetEndRange(IntervalVar *const var, int64_t new_min, int64_t new_max)=0
const T * Last() const
Returns the last item of the FIFO.
int64_t Prev(int64_t node) const
Returns the node before node in the current delta.
RevImmutableMultiMap(Solver *const solver, int initial_size)
virtual void SetDurationMin(IntervalVar *const var, int64_t new_min)=0
VarArrayConstantArrayExpressionType
#define DCHECK_EQ(val1, val2)
virtual void RankFirst(SequenceVar *const var, int index)=0
SequenceVar modifiers.
RevBitMatrix(int64_t rows, int64_t columns)
void ClearAndResize(IntegerType size)
virtual void RankSequence(SequenceVar *const var, const std::vector< int > &rank_first, const std::vector< int > &rank_last, const std::vector< int > &unperformed)=0
void AddToAssignment(SequenceVar *var, const std::vector< int > &value, bool active, std::vector< int > *assignment_indices, int64_t index, Assignment *assignment) const
virtual const LocalSearchOperator * Self() const
RevIntSet(int capacity, int *shared_positions, int shared_positions_size)
Capacity is the fixed size of the set (it cannot grow).
void SetIntegerVariableArrayArgument(const std::string &arg_name, const std::vector< IntVar * > &vars)
~PropagationMonitor() override
std::vector< Val > values_
void Insert(Solver *const solver, const T &elt)
virtual bool SkipUnchanged(int index) const
int64_t MinVarArray(const std::vector< IntVar * > &vars)
void SetValue(Solver *const s, const T &val)
bool MakeOneNeighbor() override
This method should not be overridden. Override NextFragment() instead.
DemonPriority
This enum represents the three possible priorities for a demon in the Solver queue.
A Decision represents a choice point in the search tree.
virtual int64_t GetSynchronizedObjectiveValue() const
Objective value from last time Synchronize() was called.
void BeginVisitModel(const std::string &solver_name) override
Header/footers.
~SequenceVarLocalSearchOperator() override
int64_t Value(int index) const
void Start(const Assignment *assignment) override
This method should not be overridden.
void Init(Solver *const solver, const std::vector< uint64_t > &mask)
This methods overwrites the active bitset with the mask.
std::string DebugString() const override
void WhenRange(Demon *d) override
Attach a demon that will watch the min or the max of the expression.
void Clear(Solver *const solver)
bool Intersects(const std::vector< uint64_t > &mask, int *support_index)
This method returns true iff the mask and the active bitset have a non null intersection.
void Run(Solver *const s) override
This is the main callback of the demon.
bool HoldsDelta() const override
#define DCHECK_LE(val1, val2)
A search monitor is a simple set of callbacks to monitor all search events.
virtual IntExpr * FindVarConstantConstantExpression(IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantExpressionType type) const =0
Var Constant Constant Expressions.
bool operator!=(Iterator other) const
int ActiveWordSize() const
This method returns the number of non null 64 bit words in the bitset representation.
virtual void PopContext()=0
void AcceptUncheckedNeighbor() override
After accepting an unchecked neighbor during local search.
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
bool AtSolution() override
This method is called when a valid solution is found.
virtual Constraint * FindVoidConstraint(VoidConstraintType type) const =0
Void constraints.
virtual Constraint * FindVarConstantConstraint(IntVar *const var, int64_t value, VarConstantConstraintType type) const =0
Var Constant Constraints.
SharedBoundsManager * bounds
virtual void StartProcessingIntegerVariable(IntVar *const var)=0
virtual bool HasFragments() const
virtual Constraint * FindVarConstantConstantConstraint(IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantConstraintType type) const =0
Var Constant Constant Constraints.
ExprConstantExpressionType
This iterator is not stable with respect to deletion.
void Switch(Solver *const solver)
Collection of objects used to extend the Constraint Solver library.
virtual void SetMax(IntExpr *const expr, int64_t new_max)=0
RevPartialSequence(const std::vector< int > &items)
void VisitIntervalArrayArgument(const std::string &arg_name, const std::vector< IntervalVar * > &arguments) override
std::string DebugString() const override
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.
IntVar * IsGreaterOrEqual(int64_t constant) override
SequenceVarLocalSearchOperator()
virtual T Evaluate(int64_t index) const
void Decr(Solver *const s)
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...
CallMethod3(T *const ct, void(T::*method)(P, Q, R), const std::string &name, P param1, Q param2, R param3)
A symmetry breaker is an object that will visit a decision and create the 'symmetrical' decision in r...
bool AreAllNull(const std::vector< T > &values)
virtual void BeginAcceptNeighbor(const LocalSearchOperator *op)=0
int64_t GetAcceptedObjectiveValue() const
void SetMin(int64_t m) override
int64_t GetActiveAlternativeNode(int node) const
Returns the active node in the alternative set of the given node.
void SetSequenceArgument(const std::string &arg_name, SequenceVar *const var)
int VarType() const override
void SetLastValue(const T &v)
Sets the last value in the FIFO.
void Synchronize(const Assignment *assignment, const Assignment *delta)
Synchronizes all filters to assignment.
const_iterator end() const
virtual void RemoveValue(IntVar *const var, int64_t value)=0
int64_t FindIntegerArgumentWithDefault(const std::string &arg_name, int64_t def) const
Getters.
int64_t Cardinality() const
Returns the number of bits set to one.
void Run(Solver *const s) override
This is the main callback of the demon.
bool AreAllPositive(const std::vector< T > &values)
Demon * MakeDelayedConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
virtual void InsertVarConstantArrayExpression(IntExpr *const expression, IntVar *const var, const std::vector< int64_t > &values, VarConstantArrayExpressionType type)=0
bool MakeActive(int64_t node, int64_t destination)
Insert the inactive node after destination.
Chain(const CommittedNode *begin_node, const CommittedNode *end_node)
void SetValue(int64_t index, T value)
ArrayWithOffset(int64_t index_min, int64_t index_max)
BaseIntExpr(Solver *const s)
virtual void InsertVarConstantConstantConstraint(Constraint *const ct, IntVar *const var, int64_t value1, int64_t value2, VarConstantConstantConstraintType type)=0
VarConstantConstantExpressionType
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.
Demon * MakeDelayedConstraintDemon2(Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
void ChangeNext(int node, int new_next)
virtual void EndMakeNextNeighbor(const LocalSearchOperator *op, bool neighbor_found, const Assignment *delta, const Assignment *deltadelta)=0
void VisitIntegerExpressionArgument(const std::string &arg_name, IntExpr *const argument) override
Variables.
NodeRange Nodes(int path) const
LocalSearchFilterManager(std::vector< FilterEvent > filter_events)
VarLocalSearchOperator(Handler var_handler)
void SetIntegerMatrixArgument(const std::string &arg_name, const IntTupleSet &values)
Demon * MakeConstraintDemon2(Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2)
virtual IntVar * CastToVar()
int64_t InverseValue(int64_t index) const
void VisitIntegerVariable(const IntVar *const variable, IntExpr *const delegate) override
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...
~LocalSearchOperator() override
bool IsPathStart(int64_t node) const
Returns true if node is the first node on the path.
bool ValueFromAssignment(const Assignment &assignment, IntVar *var, int64_t index, int64_t *value)
void SetIntegerArgument(const std::string &arg_name, int64_t value)
Setters.
Specialization of LocalSearchOperator built from an array of IntVars which specifies the scope of the...
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 ...
virtual void InsertExprExpression(IntExpr *const expression, IntExpr *const expr, ExprExpressionType type)=0
void Resize(IndexType size)
LocalSearchFilter * MakePathStateFilter(Solver *solver, std::unique_ptr< PathState > path_state, const std::vector< IntVar * > &nexts)
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.
virtual Constraint * FindExprExprConstraint(IntExpr *const expr1, IntExpr *const expr2, ExprExprConstraintType type) const =0
Expr Expr Constraints.
std::string DebugString() const override
GurobiMPCallbackContext * context
Demon proxy to a method on the constraint with two arguments.
virtual IntExpr * FindVarArrayConstantArrayExpression(const std::vector< IntVar * > &vars, const std::vector< int64_t > &values, VarArrayConstantArrayExpressionType type) const =0
Var Array Constant Array Expressions.
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.
IntVarIterator * MakeDomainIterator(bool reversible) const override
Creates a domain iterator.
virtual void OutputLine(const std::string &line)
const T & LastValue() const
Returns the last value in the FIFO.
std::function< int(int64_t)> start_empty_path_class
Callback returning an index such that if c1 = start_empty_path_class(StartNode(p1)),...
const IntContainer & IntVarContainer() const
void Install() override
Install itself on the solver.
virtual void InsertExprExprConstraint(Constraint *const ct, IntExpr *const expr1, IntExpr *const expr2, ExprExprConstraintType type)=0
virtual void Commit(const Assignment *delta, const Assignment *deltadelta)
Dual of Relax(), lets the filter know that the delta was accepted.
VarConstantArrayExpressionType
~UnsortedNullableRevBitset()
const Val & OldValue(int64_t index) const
void SetForwardSequence(int64_t index, const std::vector< int > &value)
Local Search Filters are used for fast neighbor pruning.
virtual IntExpr * FindExprExpression(IntExpr *const expr, ExprExpressionType type) const =0
Expr Expressions.
bool MakeOneNeighbor() override
This method should not be overridden. Override ModifyValue() instead.
bool SetMax(int64_t new_max)
This class represents a small reversible bitset (size <= 64).
DELAYED_PRIORITY is the lowest priority: Demons will be processed after VAR_PRIORITY and NORMAL_PRIOR...
bool AreAllLessOrEqual(const std::vector< T > &values, const T &value)
Demon * MakeConstraintDemon1(Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1)
virtual void InitFragments()
void Insert(const K &key, const V &value)
Inserts (key, value) in the multi-map.
void MarkChange(int64_t index)
OnStart() should really be protected, but then SWIG doesn't see it.
std::vector< std::vector< int > > backward_values_
#define CHECK_NE(val1, val2)
std::string DebugString() const override
RevPartialSequence(int size)
void SetIntervalArrayArgument(const std::string &arg_name, const std::vector< IntervalVar * > &vars)
void SetTypeName(const std::string &type_name)
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...
virtual int64_t Max() const =0
~LocalSearchMonitor() override
const_iterator begin() const
ArgumentHolder * Top() const
#define DCHECK_LT(val1, val2)
virtual void RankNotFirst(SequenceVar *const var, int index)=0
IntVar * IsEqual(int64_t constant) override
IsEqual.
Demon * MakeConstraintDemon3(Solver *const s, T *const ct, void(T::*method)(P, Q, R), const std::string &name, P param1, Q param2, R param3)
void SetToZero(Solver *const solver, int64_t index)
Erases the 'index' bit.
FilterEventType event_type
virtual void Reset()
Sets the filter to empty solution.
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 void InsertVarArrayExpression(IntExpr *const expression, const std::vector< IntVar * > &vars, VarArrayExpressionType type)=0
bool IsIncreasing(const std::vector< T > &values)
PathState(int num_nodes, std::vector< int > path_start, std::vector< int > path_end)
static const int kUnboundBooleanVarValue
Solver::DemonPriority priority() const override
This method returns the priority of the demon.