63 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVER_H_ 64 #define OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVER_H_ 73 #include "absl/container/flat_hash_map.h" 74 #include "absl/container/flat_hash_set.h" 75 #include "absl/strings/str_format.h" 76 #include "ortools/base/commandlineflags.h" 77 #include "ortools/base/hash.h" 78 #include "ortools/base/integral_types.h" 79 #include "ortools/base/logging.h" 80 #include "ortools/base/macros.h" 81 #include "ortools/base/map_util.h" 82 #include "ortools/base/random.h" 83 #include "ortools/base/sysinfo.h" 84 #include "ortools/base/timer.h" 85 #include "ortools/constraint_solver/solver_parameters.pb.h" 86 #include "ortools/util/piecewise_linear_function.h" 87 #include "ortools/util/sorted_interval_list.h" 88 #include "ortools/util/tuple_set.h" 95 class AssignmentProto;
99 class CpIntegerExpression;
100 class CpIntervalVariable;
101 class CpSequenceVariable;
109 class LocalSearchProfiler;
112 class ExpressionCache;
116 class IntVarAssignment;
119 class IntervalVarAssignment;
124 class LocalSearchPhaseParameters;
136 class RegularLimitParameters;
141 class SequenceVarAssignment;
145 class ConstraintSolverParameters;
729 typedef std::function<int64(
Solver* solver,
const std::vector<IntVar*>& vars,
730 int64 first_unbound, int64 last_unbound)>
742 explicit Solver(
const std::string& name);
743 Solver(
const std::string& name,
const ConstraintSolverParameters&
parameters);
747 ConstraintSolverParameters
parameters()
const {
return parameters_; }
759 InternalSaveValue(o);
774 template <
typename T>
776 return reinterpret_cast<T*>(SafeRevAlloc(
object));
785 template <
typename T>
787 return reinterpret_cast<T*>(SafeRevAllocArray(
object));
872 const std::vector<SearchMonitor*>& monitors);
894 const std::vector<SearchMonitor*>& monitors);
919 const std::vector<SearchMonitor*>& monitors);
959 absl::Time
Now()
const;
991 uint64
stamp()
const;
998 return optimization_direction_;
1001 optimization_direction_ = direction;
1016 IntVar*
MakeIntVar(
const std::vector<int64>& values,
const std::string& name);
1019 IntVar*
MakeIntVar(
const std::vector<int>& values,
const std::string& name);
1046 const std::string& name, std::vector<IntVar*>* vars);
1050 std::vector<IntVar*>* vars);
1053 const std::string& name);
1059 std::vector<IntVar*>* vars);
1077 const std::vector<int64>& coefs);
1080 const std::vector<int>& coefs);
1144 IntVar*
const target_var);
1166 int64 early_date, int64 late_date,
1180 const PiecewiseLinearFunction& f);
1192 int64 unperformed_value);
1307 const std::vector<int64>& coefficients,
1310 const std::vector<int>& coefficients,
1313 const std::vector<int64>& coefficients,
1316 const std::vector<int>& coefficients,
1319 const std::vector<int64>& coeffs,
1322 const std::vector<int>& coeffs,
1325 const std::vector<int64>& coefficients,
1328 const std::vector<int>& coefficients,
1343 IntVar*
const index, int64 target);
1351 IntVar*
const index, int64 target);
1364 Demon* MakeClosureDemon(Closure closure); 1388 const std::vector<int64>& values);
1393 const std::vector<int64>& values);
1395 const std::vector<int>& values);
1399 std::vector<int64> ends);
1402 std::vector<int> ends);
1406 SortedDisjointIntervalList intervals);
1407 #endif // !defined(SWIG) 1411 const std::vector<int64>& values,
1414 const std::vector<int>& values,
1417 const std::vector<int64>& values);
1428 IntVar*
const max_count);
1432 const std::vector<int64>& values,
1433 const std::vector<IntVar*>& cards);
1436 const std::vector<int>& values,
1437 const std::vector<IntVar*>& cards);
1440 const std::vector<IntVar*>& cards);
1444 int64 card_max, int64 card_size);
1449 const std::vector<int64>& card_min,
1450 const std::vector<int64>& card_max);
1455 const std::vector<int>& card_min,
1456 const std::vector<int>& card_max);
1461 const std::vector<int64>& values,
1462 const std::vector<int64>& card_min,
1463 const std::vector<int64>& card_max);
1468 const std::vector<int>& values,
1469 const std::vector<int>& card_min,
1470 const std::vector<int>& card_max);
1477 IntVar*
const deviation_var, int64 total_sum);
1487 bool stronger_propagation);
1492 int64 escape_value);
1511 const std::vector<IntVar*>& sorted);
1519 const std::vector<IntVar*>& right);
1524 const std::vector<IntVar*>& right);
1531 const std::vector<IntVar*>& left,
const std::vector<IntVar*>& right);
1536 IntVar* index,
const std::vector<IntVar*>& vars);
1541 IntVar* index,
const std::vector<IntVar*>& vars);
1548 const std::vector<IntVar*>& second_vars);
1556 const std::vector<IntVar*>& second_vars,
1557 int64 escape_value);
1572 const std::vector<IntVar*>& active,
1575 const std::vector<IntVar*>& active,
1590 const std::vector<IntVar*>& active,
1591 const std::vector<IntVar*>& cumuls,
1592 const std::vector<IntVar*>& transits);
1597 const std::vector<IntVar*>& active,
1598 const std::vector<IntVar*>& cumuls,
1599 const std::vector<IntVar*>& transits);
1607 const std::vector<IntVar*>& active,
1608 const std::vector<IntVar*>& cumuls,
1618 const std::vector<IntVar*>& active,
1619 const std::vector<IntVar*>& cumuls,
1620 const std::vector<IntVar*>& slacks,
1627 std::vector<int64> sources,
1628 std::vector<int64> sinks,
1629 std::vector<IntVar*> status);
1637 std::vector<IntVar*> nexts,
1638 const std::vector<std::pair<int, int>>& precedences);
1648 std::vector<IntVar*> nexts,
1649 const std::vector<std::pair<int, int>>& precedences,
1650 const std::vector<int>& lifo_path_starts,
1651 const std::vector<int>& fifo_path_starts);
1655 std::vector<IntVar*> nexts, std::vector<IntVar*> transits,
1656 const std::vector<std::pair<int, int>>& precedences);
1662 const std::vector<IntVar*>& actives);
1669 const IntTupleSet& tuples);
1679 const IntTupleSet& transition_table,
1680 int64 initial_state,
1681 const std::vector<int64>& final_states);
1691 const IntTupleSet& transition_table,
1692 int64 initial_state,
1693 const std::vector<int>& final_states);
1695 #if defined(SWIGPYTHON) 1698 const std::vector<IntVar*>& vars,
1699 const std::vector<std::vector<int64>>& raw_tuples) {
1700 IntTupleSet tuples(vars.size());
1701 tuples.InsertAll(raw_tuples);
1706 const std::vector<IntVar*>& vars,
1707 const std::vector<std::vector<int64>>& raw_transitions,
1708 int64 initial_state,
const std::vector<int>& final_states) {
1709 IntTupleSet transitions(3);
1710 transitions.InsertAll(raw_transitions);
1725 const std::vector<IntVar*>& x_vars,
const std::vector<IntVar*>& y_vars,
1726 const std::vector<IntVar*>& x_size,
const std::vector<IntVar*>& y_size);
1728 const std::vector<IntVar*>& x_vars,
const std::vector<IntVar*>& y_vars,
1729 const std::vector<int64>& x_size,
const std::vector<int64>& y_size);
1731 const std::vector<IntVar*>& x_vars,
const std::vector<IntVar*>& y_vars,
1732 const std::vector<int>& x_size,
const std::vector<int>& y_size);
1743 const std::vector<IntVar*>& x_vars,
const std::vector<IntVar*>& y_vars,
1744 const std::vector<IntVar*>& x_size,
const std::vector<IntVar*>& y_size);
1746 const std::vector<IntVar*>& x_vars,
const std::vector<IntVar*>& y_vars,
1747 const std::vector<int64>& x_size,
const std::vector<int64>& y_size);
1749 const std::vector<IntVar*>& x_vars,
const std::vector<IntVar*>& y_vars,
1750 const std::vector<int>& x_size,
const std::vector<int>& y_size);
1757 Pack*
MakePack(
const std::vector<IntVar*>& vars,
int number_of_bins);
1764 int64 duration,
bool optional,
1765 const std::string& name);
1770 int count, int64 start_min, int64 start_max, int64 duration,
1771 bool optional,
const std::string& name,
1772 std::vector<IntervalVar*>*
const array);
1778 const std::string& name);
1784 IntVar*
const performed_variable,
1785 const std::string& name);
1790 const std::vector<IntVar*>& start_variables, int64 duration,
1791 const std::string& name, std::vector<IntervalVar*>*
const array);
1796 const std::vector<IntVar*>& start_variables,
1797 const std::vector<int64>& durations,
const std::string& name,
1798 std::vector<IntervalVar*>*
const array);
1802 const std::vector<IntVar*>& start_variables,
1803 const std::vector<int>& durations,
const std::string& name,
1804 std::vector<IntervalVar*>*
const array);
1809 const std::vector<IntVar*>& start_variables,
1810 const std::vector<int64>& durations,
1811 const std::vector<IntVar*>& performed_variables,
const std::string& name,
1812 std::vector<IntervalVar*>*
const array);
1817 const std::vector<IntVar*>& start_variables,
1818 const std::vector<int>& durations,
1819 const std::vector<IntVar*>& performed_variables,
const std::string& name,
1820 std::vector<IntervalVar*>*
const array);
1824 const std::string& name);
1829 int64 duration_min, int64 duration_max,
1830 int64 end_min, int64 end_max,
bool optional,
1831 const std::string& name);
1836 int64 duration_min, int64 duration_max,
1837 int64 end_min, int64 end_max,
bool optional,
1838 const std::string& name,
1839 std::vector<IntervalVar*>*
const array);
1850 IntervalVar*
const interval_var, int64 duration, int64 offset);
1857 IntervalVar*
const interval_var, int64 duration, int64 offset);
1864 IntervalVar*
const interval_var, int64 duration, int64 offset);
1871 IntervalVar*
const interval_var, int64 duration, int64 offset);
1919 IntervalVar*
const t2);
1927 IntervalVar*
const t2,
1934 IntervalVar*
const t2,
IntVar*
const alt);
1939 IntervalVar*
const t2);
1944 const std::vector<IntervalVar*>& intervals,
const std::string& name);
1950 const std::vector<IntervalVar*>& intervals,
const std::string& name);
1962 const std::vector<int64>& demands, int64 capacity,
1963 const std::string& name);
1975 const std::vector<int>& demands, int64 capacity,
1976 const std::string& name);
1988 const std::vector<int64>& demands,
1989 IntVar*
const capacity,
const std::string& name);
2001 const std::vector<int>& demands,
2002 IntVar*
const capacity,
const std::string& name);
2012 const std::vector<IntVar*>& demands,
2013 int64 capacity,
const std::string& name);
2023 const std::vector<IntVar*>& demands,
2024 IntVar*
const capacity,
const std::string& name);
2032 IntervalVar*
const target_var);
2045 const Assignment*
const assignment);
2052 const Assignment*
const assignment);
2062 const Assignment*
const assignment,
bool maximize);
2074 const Assignment*
const assignment,
int solution_count,
bool maximize);
2080 const Assignment*
const assignment);
2097 const std::vector<int64>& weights,
2103 const std::vector<int>& weights,
2108 const std::vector<int64>& weights,
2113 const std::vector<int>& weights,
2118 const std::vector<IntVar*>& sub_objectives,
2119 const std::vector<int64>& weights,
2124 const std::vector<IntVar*>& sub_objectives,
2125 const std::vector<int>& weights,
2147 const std::vector<IntVar*>& vars,
2148 int64 keep_tenure, int64 forbid_tenure,
2149 double tabu_factor);
2155 const std::vector<IntVar*>& tabu_vars,
2156 int64 forbid_tenure);
2161 int64 step, int64 initial_temperature);
2168 const std::vector<IntVar*>& vars,
2169 double penalty_factor);
2171 bool maximize,
IntVar*
const objective,
2173 const std::vector<IntVar*>& vars,
2174 const std::vector<IntVar*>& secondary_vars,
double penalty_factor);
2208 int64
solutions,
bool smart_time_check);
2215 RegularLimit*
MakeLimit(
const RegularLimitParameters& proto);
2242 std::function<std::string()> display_callback);
2247 std::function<std::string()> display_callback);
2256 std::function<std::string()> display_callback);
2291 absl::flat_hash_map<const IntVar*, int>*
const map);
2292 #endif // !defined(SWIG) 2296 const std::vector<SymmetryBreaker*>& visitors);
2313 bool start_with_lower_half);
2317 const std::vector<int64>& values);
2418 int64*
const marker);
2426 int64*
const marker);
2466 const std::vector<IntVar*>& vars);
2492 const std::vector<SearchMonitor*>& monitors);
2525 int64 step,
const std::vector<SearchMonitor*>& monitors);
2539 const std::vector<IntVar*>& secondary_vars,
2547 const std::vector<IntVar*>& secondary_vars,
2559 int number_of_variables);
2561 int number_of_variables,
2578 const std::vector<IntVar*>& variables,
2579 const std::vector<int64>& target_values);
2612 const std::vector<LocalSearchOperator*>& ops);
2614 const std::vector<LocalSearchOperator*>& ops,
bool restart);
2616 const std::vector<LocalSearchOperator*>& ops,
2617 std::function<int64(
int,
int)> evaluator);
2621 const std::vector<LocalSearchOperator*>& ops);
2627 const std::vector<LocalSearchOperator*>& ops, int32 seed);
2666 LocalSearchPhaseParameters*
const parameters);
2668 const std::vector<IntVar*>& vars,
DecisionBuilder*
const first_solution,
2669 LocalSearchPhaseParameters*
const parameters);
2672 const std::vector<IntVar*>& vars,
DecisionBuilder*
const first_solution,
2674 LocalSearchPhaseParameters*
const parameters);
2676 const std::vector<SequenceVar*>& vars,
2678 LocalSearchPhaseParameters*
const parameters);
2693 const std::vector<LocalSearchFilter*>& filters);
2704 const std::vector<LocalSearchFilter*>& filters);
2716 const std::vector<IntVar*>& vars,
2717 const std::vector<IntVar*>& secondary_vars,
2721 const std::vector<IntVar*>& vars,
2722 const std::vector<IntVar*>& secondary_vars,
2762 InternalSaveValue(adr);
2771 InternalSaveValue(adr);
2777 int64
Rand64(int64 size) {
return random_.Next64() % size; }
2780 int32
Rand32(int32 size) {
return random_.Next() % size; }
2783 void ReSeed(int32 seed) { random_.Reset(seed); }
2812 fail_intercept_ = std::move(fail_intercept);
2814 #endif // !defined(SWIG) 2822 use_fast_local_search_ = use_fast_local_search;
2895 template <
class K,
class V>
2903 bool* is_negated)
const;
2924 if (!should_fail_)
return;
2925 should_fail_ =
false;
2933 void PushSentinel(
int magic_code);
2934 void BacktrackToSentinel(
int magic_code);
2935 void ProcessConstraints();
2936 bool BacktrackOneLevel(
Decision** fail_decision);
2937 void JumpToSentinelWhenNested();
2938 void JumpToSentinel();
2939 void check_alloc_state();
2941 void EnqueueVar(
Demon*
const d);
2942 void EnqueueDelayedDemon(
Demon*
const d);
2945 void UnfreezeQueue();
2946 void reset_action_on_fail();
2947 void set_action_on_fail(
Action a);
2948 void set_variable_to_clean_on_fail(
IntVar* v);
2949 void IncrementUncheckedSolutionCounter();
2950 bool IsUncheckedSolutionLimitReached();
2952 void InternalSaveValue(
int* valptr);
2953 void InternalSaveValue(int64* valptr);
2954 void InternalSaveValue(uint64* valptr);
2955 void InternalSaveValue(
double* valptr);
2956 void InternalSaveValue(
bool* valptr);
2957 void InternalSaveValue(
void** valptr);
2958 void InternalSaveValue(int64** valptr) {
2959 InternalSaveValue(reinterpret_cast<void**>(valptr));
2962 BaseObject* SafeRevAlloc(BaseObject* ptr);
2964 int* SafeRevAllocArray(
int* ptr);
2965 int64* SafeRevAllocArray(int64* ptr);
2966 uint64* SafeRevAllocArray(uint64* ptr);
2967 double* SafeRevAllocArray(
double* ptr);
2968 BaseObject** SafeRevAllocArray(BaseObject** ptr);
2970 IntExpr** SafeRevAllocArray(IntExpr** ptr);
2974 void* UnsafeRevAllocAux(
void* ptr);
2976 T* UnsafeRevAlloc(T* ptr) {
2977 return reinterpret_cast<T*>(
2978 UnsafeRevAllocAux(reinterpret_cast<void*>(ptr)));
2980 void** UnsafeRevAllocArrayAux(
void** ptr);
2982 T** UnsafeRevAllocArray(T** ptr) {
2983 return reinterpret_cast<T**>(
2984 UnsafeRevAllocArrayAux(reinterpret_cast<void**>(ptr)));
2987 void InitCachedIntConstants();
2988 void InitCachedConstraint();
2993 Search* TopLevelSearch()
const {
return searches_.at(1); }
2997 Search* ParentSearch()
const {
2998 const size_t search_size = searches_.size();
2999 DCHECK_GT(search_size, 1);
3000 return searches_[search_size - 2];
3009 int GetNewIntVarIndex() {
return num_int_vars_++; }
3012 bool IsADifference(IntExpr* expr, IntExpr**
const left,
3013 IntExpr**
const right);
3015 const std::string name_;
3016 const ConstraintSolverParameters parameters_;
3017 absl::flat_hash_map<const PropagationBaseObject*, std::string>
3018 propagation_object_names_;
3019 absl::flat_hash_map<const PropagationBaseObject*, IntegerCastInfo>
3021 absl::flat_hash_set<const Constraint*> cast_constraints_;
3022 const std::string empty_name_;
3023 std::unique_ptr<Queue> queue_;
3024 std::unique_ptr<Trail> trail_;
3025 std::vector<Constraint*> constraints_list_;
3026 std::vector<Constraint*> additional_constraints_list_;
3027 std::vector<int> additional_constraints_parent_list_;
3034 int64 filtered_neighbors_;
3035 int64 accepted_neighbors_;
3037 std::unique_ptr<ClockTimer> timer_;
3038 std::vector<Search*> searches_;
3041 std::unique_ptr<Decision> balancing_decision_;
3043 std::function<void()> fail_intercept_;
3047 bool use_fast_local_search_;
3051 std::unique_ptr<Assignment> local_search_state_;
3054 enum { MIN_CACHED_INT_CONST = -8, MAX_CACHED_INT_CONST = 8 };
3055 IntVar* cached_constants_[MAX_CACHED_INT_CONST + 1 - MIN_CACHED_INT_CONST];
3061 std::unique_ptr<Decision> fail_decision_;
3062 int constraint_index_;
3063 int additional_constraint_index_;
3066 std::unique_ptr<ModelCache> model_cache_;
3067 std::unique_ptr<PropagationMonitor> propagation_monitor_;
3068 PropagationMonitor* print_trace_;
3069 std::unique_ptr<LocalSearchMonitor> local_search_monitor_;
3070 int anonymous_variable_index_;
3073 DISALLOW_COPY_AND_ASSIGN(
Solver);
3076 std::ostream&
operator<<(std::ostream& out,
const Solver*
const s);
3084 inline int64
One() {
return 1; }
3099 std::ostream&
operator<<(std::ostream& out,
const BaseObject* o);
3110 if (
name().empty()) {
3111 return "PropagationBaseObject";
3113 return absl::StrFormat(
"PropagationBaseObject: %s",
name());
3138 solver_->set_action_on_fail(std::move(a));
3140 #endif // !defined(SWIG) 3147 solver_->set_variable_to_clean_on_fail(v);
3151 virtual std::string
name()
const;
3156 virtual std::string
BaseName()
const;
3181 DISALLOW_COPY_AND_ASSIGN(
Decision);
3192 bool start_with_lower_half);
3221 std::vector<SearchMonitor*>*
const extras);
3264 void set_stamp(int64 stamp) { stamp_ = stamp; }
3265 uint64 stamp()
const {
return stamp_; }
3267 DISALLOW_COPY_AND_ASSIGN(
Demon);
3465 const std::string& operation, int64 value,
3468 const std::string& operation, int64 value,
3475 const std::vector<int64>& values);
3477 const IntTupleSet& tuples);
3484 const std::string& arg_name,
const std::vector<IntVar*>& arguments);
3491 const std::string& arg_name,
const std::vector<IntervalVar*>& arguments);
3497 const std::string& arg_name,
const std::vector<SequenceVar*>& arguments);
3508 int64 index_min, int64 index_max);
3511 const std::string& arg_name, int64 index_max);
3512 #endif // #if !defined(SWIG) 3528 virtual void Post() = 0;
3674 explicit Rev(
const T& val) : stamp_(0), value_(val) {}
3676 const T&
Value()
const {
return value_; }
3679 if (val != value_) {
3680 if (stamp_ < s->stamp()) {
3682 stamp_ = s->
stamp();
3717 : stamps_(new uint64[
size]), values_(new T[
size]), size_(
size) {
3718 for (
int i = 0; i <
size; ++i) {
3726 int64
size()
const {
return size_; }
3728 const T&
Value(
int index)
const {
return values_[index]; }
3735 DCHECK_LT(index, size_);
3736 if (val != values_[index]) {
3737 if (stamps_[index] < s->
stamp()) {
3739 stamps_[index] = s->
stamp();
3741 values_[index] = val;
3746 std::unique_ptr<uint64[]> stamps_;
3747 std::unique_ptr<T[]> values_;
3778 virtual int64
Min()
const = 0;
3779 virtual void SetMin(int64 m) = 0;
3780 virtual int64
Max()
const = 0;
3781 virtual void SetMax(int64 m) = 0;
3785 virtual void Range(int64* l, int64* u) {
3802 virtual bool IsVar()
const {
return false; }
3828 virtual void Accept(ModelVisitor*
const visitor)
const;
3831 DISALLOW_COPY_AND_ASSIGN(
IntExpr);
3856 virtual void Init() = 0;
3859 virtual bool Ok()
const = 0;
3862 virtual int64
Value()
const = 0;
3865 virtual void Next() = 0;
3868 std::string
DebugString()
const override {
return "IntVar::Iterator"; }
3872 class InitAndGetValues {
3881 : it_(it), begin_was_called_(false) {
3887 DCHECK(!begin_was_called_);
3888 begin_was_called_ =
true;
3905 return it_->
Value();
3913 DCHECK(other.it_ == it_);
3914 DCHECK(other.is_end_);
3926 IntVarIterator*
const it_;
3927 bool begin_was_called_;
3940 bool IsVar()
const override {
return true; }
3945 virtual int64
Value()
const = 0;
3955 virtual void RemoveValues(
const std::vector<int64>& values);
3958 virtual void SetValues(
const std::vector<int64>& values);
3994 virtual uint64
Size()
const = 0;
3998 virtual bool Contains(int64 v)
const = 0;
4011 virtual int64
OldMin()
const = 0;
4014 virtual int64
OldMax()
const = 0;
4019 void Accept(ModelVisitor*
const visitor)
const override;
4032 DISALLOW_COPY_AND_ASSIGN(
IntVar);
4043 std::string
DebugString()
const override {
return "SolutionCollector"; }
4047 void Add(
const std::vector<IntVar*>& vars);
4049 void Add(
const std::vector<IntervalVar*>& vars);
4051 void Add(
const std::vector<SequenceVar*>& vars);
4158 virtual std::string
Print()
const;
4188 virtual bool Check() = 0;
4191 virtual void Init() = 0;
4206 return absl::StrFormat(
"SearchLimit(crossed = %i)", crossed_);
4210 void TopPeriodicCheck();
4221 int64
solutions,
bool smart_time_check,
bool cumulative);
4226 bool Check()
override;
4227 void Init()
override;
4233 return duration_limit_ == absl::InfiniteDuration()
4245 return solver_time_at_limit_start_ + duration_limit_;
4252 absl::Duration TimeElapsed();
4253 static int64 GetPercent(int64 value, int64 offset, int64 total) {
4254 return (total > 0 && total < kint64max) ? 100 * (value - offset) / total
4258 absl::Duration duration_limit_;
4259 absl::Time solver_time_at_limit_start_;
4260 absl::Duration last_time_elapsed_;
4263 bool smart_time_check_;
4265 int64 branches_offset_;
4267 int64 failures_offset_;
4269 int64 solutions_offset_;
4304 virtual int64
StartMin()
const = 0;
4305 virtual int64
StartMax()
const = 0;
4358 virtual int64
EndMin()
const = 0;
4359 virtual int64
EndMax()
const = 0;
4422 virtual IntExpr*
EndExpr() = 0;
4427 virtual IntExpr*
SafeStartExpr(int64 unperformed_value) = 0;
4429 virtual IntExpr*
SafeEndExpr(int64 unperformed_value) = 0;
4432 virtual void Accept(ModelVisitor*
const visitor)
const = 0;
4447 const std::vector<IntVar*>& nexts,
const std::string&
name);
4454 void DurationRange(int64*
const dmin, int64*
const dmax)
const;
4460 void HorizonRange(int64*
const hmin, int64*
const hmax)
const;
4468 int*
const unperformed)
const;
4469 #endif // !defined(SWIG) 4490 std::vector<int>*
const possible_lasts);
4498 const std::vector<int>& rank_last,
4499 const std::vector<int>& unperformed);
4510 std::vector<int>*
const rank_last,
4511 std::vector<int>*
const unperformed)
const;
4520 int64
size()
const {
return intervals_.size(); }
4526 int ComputeForwardFrontier();
4527 int ComputeBackwardFrontier();
4528 void UpdatePrevious()
const;
4530 const std::vector<IntervalVar*> intervals_;
4531 const std::vector<IntVar*> nexts_;
4532 mutable std::vector<int> previous_;
4560 if (var_ !=
nullptr) {
4564 void LoadFromProto(
const IntVarAssignment& int_var_assignment_proto);
4565 void WriteToProto(IntVarAssignment* int_var_assignment_proto)
const;
4567 int64
Min()
const {
return min_; }
4569 int64
Max()
const {
return max_; }
4572 DCHECK_EQ(min_, max_);
4576 bool Bound()
const {
return (max_ == min_); }
4589 return !(*
this == element);
4609 const IntervalVarAssignment& interval_var_assignment_proto);
4610 void WriteToProto(IntervalVarAssignment* interval_var_assignment_proto)
const;
4615 CHECK_EQ(start_max_, start_min_);
4621 CHECK_EQ(duration_max_, duration_min_);
4622 return duration_max_;
4627 CHECK_EQ(end_max_, end_min_);
4633 CHECK_EQ(performed_max_, performed_min_);
4634 return performed_max_;
4669 performed_min_ = mi;
4670 performed_max_ = ma;
4677 return (start_min_ == start_max_ && duration_min_ == duration_max_ &&
4678 end_min_ == end_max_ && performed_min_ == performed_max_);
4683 return !(*
this == element);
4689 int64 duration_min_;
4690 int64 duration_max_;
4693 int64 performed_min_;
4694 int64 performed_max_;
4722 const SequenceVarAssignment& sequence_var_assignment_proto);
4723 void WriteToProto(SequenceVarAssignment* sequence_var_assignment_proto)
const;
4728 void SetSequence(
const std::vector<int>& forward_sequence,
4729 const std::vector<int>& backward_sequence,
4730 const std::vector<int>& unperformed);
4735 return forward_sequence_.size() + unperformed_.size() == var_->
size();
4742 return !(*
this == element);
4746 bool CheckClassInvariants();
4749 std::vector<int> forward_sequence_;
4750 std::vector<int> backward_sequence_;
4751 std::vector<int> unperformed_;
4754 template <
class V,
class E>
4759 CHECK(var !=
nullptr);
4761 if (!Find(var, &index)) {
4764 return &elements_[index];
4769 DCHECK(var !=
nullptr);
4770 elements_.emplace_back(var);
4771 return &elements_.back();
4776 elements_[position].Reset(var);
4777 return &elements_[position];
4781 if (!elements_map_.empty()) {
4782 elements_map_.clear();
4787 void Resize(
size_t size) { elements_.resize(size); }
4788 bool Empty()
const {
return elements_.empty(); }
4792 for (
int i = 0; i < container.elements_.size(); ++i) {
4793 const E& element = container.elements_[i];
4794 const V*
const var = element.Var();
4796 if (i < elements_.size() && elements_[i].Var() == var) {
4798 }
else if (!Find(var, &index)) {
4801 DCHECK_GE(index, 0);
4802 E*
const local_element = &elements_[index];
4803 local_element->Copy(element);
4804 if (element.Activated()) {
4805 local_element->Activate();
4807 local_element->Deactivate();
4815 for (
int i = 0; i < container.elements_.size(); ++i) {
4816 const E& element = container.elements_[i];
4822 return Find(var, &index);
4826 DCHECK(element !=
nullptr)
4827 <<
"Unknown variable " << var->DebugString() <<
" in solution";
4832 if (Find(var, &index)) {
4839 DCHECK(element !=
nullptr)
4840 <<
"Unknown variable " << var->DebugString() <<
" in solution";
4845 if (Find(var, &index)) {
4850 const std::vector<E>&
elements()
const {
return elements_; }
4852 const E&
Element(
int index)
const {
return elements_[index]; }
4853 int Size()
const {
return elements_.size(); }
4855 for (E& element : elements_) {
4860 for (E& element : elements_) {
4861 if (element.Activated()) {
4867 for (
const E& element : elements_) {
4868 if (!element.Bound())
return false;
4882 EnsureMapIsUpToDate();
4886 for (
const E& element : container.elements_) {
4887 const int position =
4888 gtl::FindWithDefault(elements_map_, element.Var(), -1);
4889 if (position < 0 || elements_[position] != element) {
4896 return !(*
this == container);
4900 void EnsureMapIsUpToDate()
const {
4901 absl::flat_hash_map<const V*, int>* map =
4902 const_cast<absl::flat_hash_map<const V*, int>*
>(&elements_map_);
4903 for (
int i = map->size(); i < elements_.size(); ++i) {
4904 (*map)[elements_[i].Var()] = i;
4907 bool Find(
const V*
const var,
int* index)
const {
4909 const size_t kMaxSizeForLinearAccess = 11;
4910 if (
Size() <= kMaxSizeForLinearAccess) {
4914 for (
int i = 0; i < elements_.size(); ++i) {
4915 if (var == elements_[i].Var()) {
4922 EnsureMapIsUpToDate();
4923 DCHECK_EQ(elements_map_.size(), elements_.size());
4924 return gtl::FindCopy(elements_map_, var, index);
4928 std::vector<E> elements_;
4929 absl::flat_hash_map<const V*, int> elements_map_;
4948 return int_var_container_.
Empty() && interval_var_container_.
Empty() &&
4949 sequence_var_container_.
Empty();
4962 bool Load(
const std::string& filename);
4964 bool Load(File* file);
4966 void Load(const AssignmentProto& assignment_proto); 4967 bool Save(
const std::string& filename)
const;
4970 bool Save(File* file)
const;
4971 #endif // #if !defined(SWIG) 4972 void Save(AssignmentProto*
const assignment_proto)
const;
4988 void Add(
const std::vector<IntVar*>& vars);
4991 int64
Min(
const IntVar*
const var)
const;
4992 int64
Max(
const IntVar*
const var)
const;
5001 void Add(
const std::vector<IntervalVar*>& vars);
5034 void Add(
const std::vector<SequenceVar*>& vars);
5041 const std::vector<int>& forward_sequence,
5042 const std::vector<int>& backward_sequence,
5043 const std::vector<int>& unperformed);
5045 const std::vector<int>& forward_sequence);
5047 const std::vector<int>& backward_sequence);
5049 const std::vector<int>& unperformed);
5088 return interval_var_container_;
5091 return &interval_var_container_;
5094 return sequence_var_container_;
5097 return &sequence_var_container_;
5100 return int_var_container_ == assignment.int_var_container_ &&
5101 interval_var_container_ == assignment.interval_var_container_ &&
5102 sequence_var_container_ == assignment.sequence_var_container_ &&
5103 objective_element_ == assignment.objective_element_;
5106 return !(*
this == assignment);
5118 const Assignment& assignment);
5126 const std::vector<IntVar*>& target_vars,
5127 const Assignment* source_assignment,
5128 const std::vector<IntVar*>& source_vars);
5132 Pack(
Solver*
const s,
const std::vector<IntVar*>& vars,
int number_of_bins);
5145 const std::vector<int64>& weights,
const std::vector<int64>& bounds);
5164 const std::vector<IntVar*>& loads);
5170 const std::vector<IntVar*>& loads);
5182 const std::vector<IntVar*>& usage,
const std::vector<int64>& capacity);
5197 void Post()
override;
5204 bool IsUndecided(
int var_index,
int bin_index)
const;
5206 void Assign(
int var_index,
int bin_index);
5208 bool IsPossible(
int var_index,
int bin_index)
const;
5220 bool IsInProcess()
const;
5221 const std::vector<IntVar*> vars_;
5223 std::vector<Dimension*> dims_;
5224 std::unique_ptr<RevBitMatrix> unprocessed_;
5225 std::vector<std::vector<int>> forced_;
5226 std::vector<std::vector<int>> removed_;
5227 std::vector<IntVarIterator*> holes_;
5230 std::vector<std::pair<int, int>> to_set_;
5231 std::vector<std::pair<int, int>> to_unset_;
5238 const std::vector<IntervalVar*>& intervals,
5239 const std::string&
name);
5257 virtual const std::vector<IntVar*>&
nexts()
const = 0;
5258 virtual const std::vector<IntVar*>&
actives()
const = 0;
5259 virtual const std::vector<IntVar*>&
time_cumuls()
const = 0;
5260 virtual const std::vector<IntVar*>&
time_slacks()
const = 0;
5261 #endif // !defined(SWIG) 5296 #endif // OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVER_H_ void WhenStartRange(Solver::Action action)
Implements a complete cache for model elements: expressions and constraints.
void SetObjectiveRange(int64 l, int64 u)
static const char kEndExpr[]
const T & operator[](int index) const
virtual void VisitIntegerVariableEvaluatorArgument(const std::string &arg_name, const Solver::Int64ToIntVar &arguments)
Helpers.
int64 ObjectiveValue() const
void Accept(ModelVisitor *const visitor) const override
Accepts the given visitor.
static const char kIntegerVariable[]
void SetPerformedMin(const IntervalVar *const var, int64 m)
bool IsUncheckedSolutionLimitReached() override
Returns true if the limit of solutions has been reached including unchecked solutions.
bool run_all_heuristics
The default phase will run heuristics periodically.
static const char kModuloArgument[]
Operator which makes an inactive node active and an active one inactive.
virtual void Apply(Solver *const s)=0
Apply will be called first when the decision is executed.
DecisionBuilder * MakeDecisionBuilderFromAssignment(Assignment *const assignment, DecisionBuilder *const db, const std::vector< IntVar * > &vars)
Returns a decision builder for which the left-most leaf corresponds to assignment,...
static const char kOptionalArgument[]
void SetDurationRange(int64 mi, int64 ma)
Relocate neighborhood with length of 1 (see OROPT comment).
static const char kSequenceVariable[]
Demon * MakeConstraintInitialPropagateCallback(Constraint *const ct)
This method is a specialized case of the MakeConstraintDemon method to call the InitiatePropagate of ...
virtual IntExpr * EndExpr()=0
static const char kVarsArgument[]
bool IsPerformedBound() const
~SearchMonitor() override
virtual void Range(int64 *l, int64 *u)
By default calls Min() and Max(), but can be redefined when Min and Max code can be factorized.
const std::vector< int > & Unperformed(int n, SequenceVar *const var) const
This is a shortcut to get the list of unperformed of 'var' in the nth solution.
virtual void WhenBound(Demon *d)=0
This method attaches a demon that will be awakened when the variable is bound.
void AssignAllRemainingItems()
IntExpr * MakeAbs(IntExpr *const expr)
|expr|
void SetAssignmentFromAssignment(Assignment *target_assignment, const std::vector< IntVar * > &target_vars, const Assignment *source_assignment, const std::vector< IntVar * > &source_vars)
NOLINT.
int initialization_splits
Maximum number of intervals that the initialization of impacts will scan per variable.
virtual bool SyncNeeded(Assignment *const local_assignment)=0
This method checks if the local solution needs to be updated with an external one.
virtual int64 StartMax() const =0
static const char kFixedChargeArgument[]
static const char kLinkExprVar[]
void Add(Solver *const s, int index, const T &to_add)
IntVar * RegisterIntVar(IntVar *const var)
Registers a new IntVar and wraps it inside a TraceIntVar if necessary.
SearchMonitor * MakeConstantRestart(int frequency)
This search monitor will restart the search periodically after 'frequency' failures.
static const char kIntervalVariable[]
virtual void WhenRange(Demon *d)=0
Attach a demon that will watch the min or the max of the expression.
SearchMonitor * MakeAtSolutionCallback(std::function< void()> callback)
void SetValue(Solver *const s, int index, const T &val)
Decision * MakeSplitVariableDomain(IntVar *const var, int64 val, bool start_with_lower_half)
IntervalVar * MakeMirrorInterval(IntervalVar *const interval_var)
Creates an interval var that is the mirror image of the given one, that is, the interval var obtained...
void MakeBoolVarArray(int var_count, const std::string &name, std::vector< IntVar * > *vars)
This method will append the vector vars with 'var_count' boolean variables having name "name<i>" wher...
std::string DebugString() const override
Operator which makes path nodes inactive.
SolutionCollector * MakeBestValueSolutionCollector(const Assignment *const assignment, bool maximize)
Collect the solution corresponding to the optimal value of the objective of 'assignment'; if 'assignm...
virtual void SetDurationMax(int64 m)=0
SearchMonitor * MakeGenericTabuSearch(bool maximize, IntVar *const v, int64 step, const std::vector< IntVar * > &tabu_vars, int64 forbid_tenure)
Creates a Tabu Search based on the vars |vars|.
virtual void VisitSequenceVariable(const SequenceVar *const variable)
virtual void SetDurationRange(int64 mi, int64 ma)=0
virtual void Install()
Registers itself on the solver such that it gets notified of the search and propagation events.
static const char kVariableUsageLessConstantExtension[]
const std::vector< IntervalVar * > intervals_
std::function< int64(int64, int64, int64)> IndexEvaluator3
static const char kSortingConstraint[]
LocalSearchOperator * MakeRandomLnsOperator(const std::vector< IntVar * > &vars, int number_of_variables)
Creates a large neighborhood search operator which creates fragments (set of relaxed variables) with ...
Subclass of RevArray<T> which adds numerical operations.
const std::vector< int > & ForwardSequence() const
IntVar * MakeIsLessCstVar(IntExpr *const var, int64 value)
status var of (var < value)
IntVar * MakeIsLessVar(IntExpr *const left, IntExpr *const right)
status var of (left < right)
static const char kAbs[]
Constraint and Expression types.
Constraint * MakeDistribute(const std::vector< IntVar * > &vars, const std::vector< int64 > &values, const std::vector< IntVar * > &cards)
Aggregated version of count: |{i | v[i] == values[j]}| == cards[j].
IntervalVar * Var() const
static const char kDelayedPathCumul[]
void AddCastConstraint(CastConstraint *const constraint, IntVar *const target_var, IntExpr *const expr)
Adds 'constraint' to the solver and marks it as a cast constraint, that is, a constraint created call...
IntVar * MakeBoolVar()
MakeBoolVar will create a variable with a {0, 1} domain.
const T & Value(int index) const
virtual bool IsVar() const
Returns true if the expression is indeed a variable.
void SetStartMax(const IntervalVar *const var, int64 m)
const std::vector< int > & BackwardSequence(const SequenceVar *const var) const
IntVar * MakeIsGreaterVar(IntExpr *const left, IntExpr *const right)
status var of (left > right)
void ExportProfilingOverview(const std::string &filename)
Exports the profiling information in a human readable overview.
virtual void Accept(ModelVisitor *const visitor) const
Accepts the given model visitor.
static const char kSmartTimeCheckArgument[]
static const char kIntervalsArgument[]
void Decr(Solver *const s, int index)
virtual int64 EndMin() const =0
These methods query, set, and watch the end position of the interval var.
DecisionBuilder * MakeConstraintAdder(Constraint *const ct)
Returns a decision builder that will add the given constraint to the model.
void SetForwardSequence(const SequenceVar *const var, const std::vector< int > &forward_sequence)
void SetPerformedRange(const IntervalVar *const var, int64 mi, int64 ma)
void AddWeightedSumLessOrEqualConstantDimension(const std::vector< int64 > &weights, const std::vector< int64 > &bounds)
Dimensions are additional constraints than can restrict what is possible with the pack constraint.
IntervalVar(Solver *const solver, const std::string &name)
std::vector< SolutionData > solution_data_
static const char kLess[]
LocalSearchPhaseParameters * MakeLocalSearchPhaseParameters(LocalSearchOperator *const ls_operator, DecisionBuilder *const sub_decision_builder)
Local Search Phase Parameters.
This class represent a reversible FIFO structure.
void SetDurationValue(const IntervalVar *const var, int64 value)
static const char kValueArgument[]
virtual IntExpr * SafeEndExpr(int64 unperformed_value)=0
bool NameAllVariables() const
Returns whether all variables should be named.
void UnfreezeQueue()
This method unfreezes the propagation queue.
virtual Decision * Next(Solver *const s)=0
This is the main method of the decision builder class.
bool operator==(const IntervalVarElement &element) const
std::vector< int64 > tmp_vector_
Unsafe temporary vector.
Matrix version of the RevBitSet class.
Decision * MakeScheduleOrPostpone(IntervalVar *const var, int64 est, int64 *const marker)
Returns a decision that tries to schedule a task at a given time.
virtual void RefuteDecision(Decision *const d)
Before refuting the decision.
int64 DurationValue(int n, IntervalVar *const var) const
This is a shortcut to get the DurationValue of 'var' in the nth solution.
static const char kEndsArgument[]
Constraint * MakeAllowedAssignments(const std::vector< IntVar * > &vars, const IntTupleSet &tuples)
This method creates a constraint where the graph of the relation between the variables is given in ex...
static const char kLateDateArgument[]
static const char kCountAssignedItemsExtension[]
Extension names:
void SetBranchSelector(BranchSelector bs)
Sets the given branch selector on the current active search.
Constraint * MakeGreaterOrEqual(IntExpr *const left, IntExpr *const right)
left >= right
Decision * MakeAssignVariableValueOrFail(IntVar *const var, int64 value)
IntVar * MakeIsDifferentVar(IntExpr *const v1, IntExpr *const v2)
status var of (v1 != v2)
Lin–Kernighan local search.
Pack(Solver *const s, const std::vector< IntVar * > &vars, int number_of_bins)
Constraint * MakeCircuit(const std::vector< IntVar * > &nexts)
Force the "nexts" variable to create a complete Hamiltonian path.
static const char kSumGreaterOrEqual[]
virtual std::string name() const
Object naming.
void PostAndPropagate()
Calls Post and then Propagate to initialize the constraints.
std::string DebugString() const override
void BeginNextDecision(DecisionBuilder *const b) override
Before calling DecisionBuilder::Next.
IntExpr * MakeSemiContinuousExpr(IntExpr *const expr, int64 fixed_charge, int64 step)
Semi continuous Expression (x <= 0 -> f(x) = 0; x > 0 -> f(x) = ax + b) a >= 0 and b >= 0.
static const char kOpposite[]
virtual void EndVisitExtension(const std::string &type)
static const char kCountUsedBinsExtension[]
void Copy(const IntVarElement &element)
EvaluatorLocalSearchOperators
This enum is used in Solver::MakeOperator associated with an evaluator to specify the neighborhood to...
static const char kDisjunctive[]
void AddObjective(IntVar *const objective)
virtual IntVarIterator * MakeDomainIterator(bool reversible) const =0
Creates a domain iterator.
bool HasName() const
Returns whether the object has been named or not.
virtual void Initialize(Assignment *const assignment)=0
This method is called to initialize the solution pool with the assignment from the local search.
static const char kNonEqual[]
void Copy(const SearchLimit *const limit) override
Copy a limit.
void SetStartRange(const IntervalVar *const var, int64 mi, int64 ma)
void RemoveAllPossibleFromBin(int bin_index)
static const char kMaximizeArgument[]
Constraint * MakeIfThenElseCt(IntVar *const condition, IntExpr *const then_expr, IntExpr *const else_expr, IntVar *const target_var)
Special cases with arrays of size two.
bool HasName(const PropagationBaseObject *object) const
Returns whether the object has been named or not.
Right branches are ignored.
IntervalStrategy
This enum describes the straregy used to select the next interval variable and its value to be fixed.
bool IsLocalSearchProfilingEnabled() const
Returns whether we are profiling local search.
virtual IntVarIterator * MakeHoleIterator(bool reversible) const =0
Creates a hole iterator.
IntervalContainer * MutableIntervalVarContainer()
IntExpr * MakePiecewiseLinearExpr(IntExpr *expr, const PiecewiseLinearFunction &f)
General piecewise-linear function expression, built from f(x) where f is piecewise-linear.
Operator which cross exchanges the starting chains of 2 paths, including exchanging the whole paths.
ModelVisitor * MakeVariableDegreeVisitor(absl::flat_hash_map< const IntVar *, int > *const map)
Compute the number of constraints a variable is attached to.
IntValueStrategy
This enum describes the strategy used to select the next variable value to set.
int64 DurationValue() const
virtual IntVar * IsGreaterOrEqual(int64 constant)=0
IntExpr * MakeConditionalExpression(IntVar *const condition, IntExpr *const expr, int64 unperformed_value)
Conditional Expr condition ? expr : unperformed_value.
static const char kTransitsArgument[]
void CopyIntersection(const Assignment *assignment)
Copies the intersection of the two assignments to the current assignment.
virtual void RemoveValues(const std::vector< int64 > &values)
This method remove the values from the domain of the variable.
std::function< void(Solver *)> Action
void Copy(const SequenceVarElement &element)
bool Solve(DecisionBuilder *const db, const std::vector< SearchMonitor * > &monitors)
IntExpr * MakePower(IntExpr *const expr, int64 n)
expr ^ n (n > 0)
virtual void EnterSearch()
Beginning of the search.
virtual void SetMin(int64 m)=0
static const char kEndMinArgument[]
bool operator==(const SequenceVarElement &element) const
Constraint * MakeLess(IntExpr *const left, IntExpr *const right)
left < right
static const char kLexLess[]
IntExpr * MakeModulo(IntExpr *const x, int64 mod)
Modulo expression x % mod (with the python convention for modulo).
static const char kSquare[]
Constraint * MakeNonEquality(IntExpr *const left, IntExpr *const right)
left != right
virtual int64 Value() const =0
This method returns the current value of the iterator.
DELAYED_PRIORITY is the lowest priority: Demons will be processed after VAR_PRIORITY and NORMAL_PRIOR...
const std::vector< int > & BackwardSequence(int n, SequenceVar *const var) const
This is a shortcut to get the BackwardSequence of 'var' in the nth solution.
IntExpr * MakeSum(IntExpr *const left, IntExpr *const right)
left + right.
std::function< void()> Closure
Decision * MakeAssignVariableValue(IntVar *const var, int64 val)
Decisions.
DecisionBuilder * MakePhase(const std::vector< IntVar * > &vars, IntVarStrategy var_str, IntValueStrategy val_str)
Phases on IntVar arrays.
virtual void WhenEndBound(Demon *const d)=0
Constraint * MakeNullIntersectExcept(const std::vector< IntVar * > &first_vars, const std::vector< IntVar * > &second_vars, int64 escape_value)
Creates a constraint that states that all variables in the first vector are different from all variab...
Solver(const std::string &name)
Solver API.
void RestartCurrentSearch()
SearchMonitor * MakeGuidedLocalSearch(bool maximize, IntVar *const objective, IndexEvaluator2 objective_function, int64 step, const std::vector< IntVar * > &vars, double penalty_factor)
Creates a Guided Local Search monitor.
void SetUnperformed(const SequenceVar *const var, const std::vector< int > &unperformed)
Constraint * MakeIsGreaterCstCt(IntExpr *const v, int64 c, IntVar *const b)
b == (v > c)
RegularLimit * MakeIdenticalClone() const
static const char kTimeLimitArgument[]
virtual void PeriodicCheck()
Periodic call to check limits in long running methods.
virtual int64 DurationMin() const =0
These methods query, set, and watch the duration of the interval var.
void VisitInt64ToBoolExtension(Solver::IndexFilter1 filter, int64 index_min, int64 index_max)
Using SWIG on callbacks is troublesome, so we hide these methods during the wrapping.
int64 StartValue(const IntervalVar *const var) const
static const char kDemandsArgument[]
IntExpr * MakeMax(const std::vector< IntVar * > &vars)
std::max(vars)
t1 starts after t2 end, i.e. Start(t1) >= End(t2) + delay.
OptimizeVar * MakeOptimize(bool maximize, IntVar *const v, int64 step)
Creates a objective with a given sense (true = maximization).
t ends before d, i.e. End(t) <= d.
IntVar * MakeIsGreaterOrEqualVar(IntExpr *const left, IntExpr *const right)
status var of (left >= right)
std::string DebugString() const
static const char kDistribute[]
static const char kIntervalDisjunction[]
Move is accepted when the current objective value <= objective.Max.
SolutionPool * MakeDefaultSolutionPool()
Solution Pool.
Decision * MakeRankLastInterval(SequenceVar *const sequence, int index)
Returns a decision that tries to rank last the ith interval var in the sequence variable.
virtual SearchLimit * MakeClone() const =0
Allocates a clone of the limit.
virtual void Accept(ModelVisitor *const visitor) const
Accepts the given visitor.
void PeriodicCheck() override
Periodic call to check limits in long running methods.
LocalSearchOperators
This enum is used in Solver::MakeOperator to specify the neighborhood to create.
LocalSearchOperator * RandomConcatenateOperators(const std::vector< LocalSearchOperator * > &ops)
Randomized version of local search concatenator; calls a random operator at each call to MakeNextNeig...
int64 demon_runs(DemonPriority p) const
The number of demons executed during search for a given priority.
IntVar * MakeIsDifferentCstVar(IntExpr *const var, int64 value)
status var of (var != value)
virtual void AcceptUncheckedNeighbor()
After accepting an unchecked neighbor during local search.
friend class FindOneNeighbor
Constraint * MakeNotMemberCt(IntExpr *const expr, const std::vector< int64 > &values)
expr not in set.
static const char kModulo[]
Constraint * MakeIsEqualCt(IntExpr *const v1, IntExpr *v2, IntVar *const b)
b == (v1 == v2)
bool use_last_conflict
Should we use last conflict method. The default is false.
Cast constraints are special channeling constraints designed to keep a variable in sync with an expre...
static const char kMaxArgument[]
void SetSearchContext(Search *search, const std::string &search_context)
Constraint * MakeSumEquality(const std::vector< IntVar * > &vars, int64 cst)
DecisionBuilder * MakeNestedOptimize(DecisionBuilder *const db, Assignment *const solution, bool maximize, int64 step)
NestedOptimize will collapse a search tree described by a decision builder 'db' and a set of monitors...
static const char kMapDomain[]
void WriteToProto(IntervalVarAssignment *interval_var_assignment_proto) const
static const char kNoCycle[]
void WhenBound(Solver::Closure closure)
This method attaches a closure that will be awakened when the variable is bound.
virtual void VisitUnknownDecision()
IntervalVar * MakeFixedDurationEndSyncedOnEndIntervalVar(IntervalVar *const interval_var, int64 duration, int64 offset)
Creates an interval var with a fixed duration whose end is synchronized with the end of another inter...
SequenceStrategy
Used for scheduling. Not yet implemented.
void WhenAnything(Demon *const d)
Attaches a demon awakened when anything about this interval changes.
t ends after d, i.e. End(t) >= d.
bool AcceptSolution() override
This method is called when a solution is found.
virtual int ProgressPercent()
Returns a percentage representing the propress of the search before reaching limits.
static const char kRelaxedMaxOperation[]
IntVar * AssignVar(int var_index, int bin_index) const
static const char kNullIntersect[]
NumericalRev(const T &val)
static const char kSemiContinuous[]
IntExpr * MakeMin(const std::vector< IntVar * > &vars)
std::min(vars)
Decision * MakeAssignVariableValueOrDoNothing(IntVar *const var, int64 value)
void SetRange(int64 l, int64 u)
Applies right branch first.
bool Save(const std::string &filename) const
Saves the assignment to a file.
virtual void Init()=0
This method must be called before each loop.
int64 PerformedValue(int n, IntervalVar *const var) const
This is a shortcut to get the PerformedValue of 'var' in the nth solution.
static const char kPositionXArgument[]
DemonPriority
This enum represents the three possible priorities for a demon in the Solver queue.
void SetUnperformed(const std::vector< int > &unperformed)
virtual void EndNextDecision(DecisionBuilder *const b, Decision *const d)
After calling DecisionBuilder::Next, along with the returned decision.
int NumIntervalVars() const
virtual void SetDurationMin(int64 m)=0
int64 branches(int n) const
Returns the number of branches when the nth solution was found.
After search, the model is infeasible.
Before search, after search.
virtual void Accept(ModelVisitor *const visitor) const
Accepts the given visitor.
Constraint * MakeIsDifferentCt(IntExpr *const v1, IntExpr *const v2, IntVar *const b)
b == (v1 != v2)
void Activate(const IntVar *const var)
t1 ends at t2 end, i.e. End(t1) == End(t2) + delay.
void WhenDurationRange(Solver::Action action)
void RankNotFirst(int index)
Indicates that the index_th interval var will not be ranked first of all currently unranked interval ...
DecisionBuilder * Try(DecisionBuilder *const db1, DecisionBuilder *const db2)
Creates a decision builder which will create a search tree where each decision builder is called from...
Constraint * MakeMaxEquality(const std::vector< IntVar * > &vars, IntVar *const max_var)
bool IsBooleanVar(IntExpr *const expr, IntVar **inner_var, bool *is_negated) const
Returns true if expr represents either boolean_var or 1 - boolean_var.
friend class DemonProfiler
int64 best() const
Returns the best value found during search.
IntExpr * MakeConvexPiecewiseExpr(IntExpr *expr, int64 early_cost, int64 early_date, int64 late_date, int64 late_cost)
Convex piecewise function.
SequenceVar(Solver *const s, const std::vector< IntervalVar * > &intervals, const std::vector< IntVar * > &nexts, const std::string &name)
static const char kIndex2Argument[]
bool AtSolution() override
This method is called when a valid solution is found.
Move is accepted when the current objective value >= objective.Min.
Constraint * MakeDelayedPathCumul(const std::vector< IntVar * > &nexts, const std::vector< IntVar * > &active, const std::vector< IntVar * > &cumuls, const std::vector< IntVar * > &transits)
Delayed version of the same constraint: propagation on the nexts variables is delayed until all const...
void WhenStartRange(Solver::Closure closure)
static const char kLessOrEqual[]
Constraint * MakeCumulative(const std::vector< IntervalVar * > &intervals, const std::vector< int64 > &demands, int64 capacity, const std::string &name)
This constraint forces that, for any integer t, the sum of the demands corresponding to an interval c...
virtual void Init()=0
This method is called when the search limit is initialized.
int64 One()
This method returns 1.
virtual void VisitIntegerVariable(const IntVar *const variable, IntExpr *const delegate)
virtual void VisitScheduleOrExpedite(IntervalVar *const var, int64 est)
void RefuteDecision(Decision *const d) override
Before refuting the decision.
static const char kSizeXArgument[]
IntVar * Objective() const
A sequence variable is a variable whose domain is a set of possible orderings of the interval variabl...
Constraint * MakeIsLessOrEqualCstCt(IntExpr *const var, int64 value, IntVar *const boolvar)
boolvar == (var <= value)
This class encapsulates an objective.
virtual IntExpr * SafeStartExpr(int64 unperformed_value)=0
These methods create expressions encapsulating the start, end and duration of the interval var.
virtual void AfterDecision(Decision *const d, bool apply)
Just after refuting or applying the decision, apply is true after Apply.
bool CurrentlyInSolve() const
Returns true whether the current search has been created using a Solve() call instead of a NewSearch ...
static const char kRangeArgument[]
DecisionBuilder * MakeApplyBranchSelector(BranchSelector bs)
Creates a decision builder that will set the branch selector.
void AddObjective(IntVar *const v)
std::string SearchContext() const
Constraint * MakeNullIntersect(const std::vector< IntVar * > &first_vars, const std::vector< IntVar * > &second_vars)
Creates a constraint that states that all variables in the first vector are different from all variab...
Constraint * MakeSumGreaterOrEqual(const std::vector< IntVar * > &vars, int64 cst)
int64 DurationMax(const IntervalVar *const var) const
void SetValue(const IntVar *const var, int64 value)
static const char kIsMember[]
int64 PerformedValue(const IntervalVar *const var) const
static int64 MemoryUsage()
Current memory usage in bytes.
Constraint * MakeElementEquality(const std::vector< int64 > &vals, IntVar *const index, IntVar *const target)
bool HasObjective() const
SolutionCollector * MakeFirstSolutionCollector()
Collect the first solution of the search.
Decision * MakeVariableGreaterOrEqualValue(IntVar *const var, int64 value)
Constraint * MakeTransitionConstraint(const std::vector< IntVar * > &vars, const IntTupleSet &transition_table, int64 initial_state, const std::vector< int64 > &final_states)
This constraint create a finite automaton that will check the sequence of variables vars.
static const char kPartialArgument[]
void clear_fail_intercept()
void ComputeStatistics(int *const ranked, int *const not_ranked, int *const unperformed) const
Compute statistics on the sequence.
Constraint * MakeAbsEquality(IntVar *const var, IntVar *const abs_var)
Creates the constraint abs(var) == abs_var.
std::string DebugString() const override
static const char kTransition[]
static const char kInversePermutation[]
This is the base class for all expressions that are not variables.
virtual void BeginInitialPropagation()
Before the initial propagation.
int64 Value(const IntVar *const var) const
static const char kValuesArgument[]
virtual void BeginVisitModel(const std::string &solver_name)
--— Virtual methods for visitors --—
static const char kPathCumul[]
void WhenDurationBound(Solver::Closure closure)
bool operator!=(const IntVarElement &element) const
virtual int64 OldEndMin() const =0
virtual void WhenEndRange(Demon *const d)=0
IntExpr * MakeProd(IntExpr *const left, IntExpr *const right)
left * right
virtual void VisitSplitVariableDomain(IntVar *const var, int64 value, bool start_with_lower_half)
virtual void VisitSetVariableValue(IntVar *const var, int64 value)
void check_index(int n) const
IntVarStrategy
This enum describes the strategy used to select the next branching variable at each node during the s...
void SetMin(const IntVar *const var, int64 m)
OptimizeVar(Solver *const s, bool maximize, IntVar *const a, int64 step)
void AddLocalSearchMonitor(LocalSearchMonitor *monitor)
Adds the local search monitor to the solver.
void PushSolution()
Push the current state as a new solution.
A Demon is the base element of a propagation queue.
RegularLimit * MakeSolutionsLimit(int64 solutions)
Creates a search limit that constrains the number of solutions found during the search.
void SetEndMin(const IntervalVar *const var, int64 m)
IntExpr * MakeScalProd(const std::vector< IntVar * > &vars, const std::vector< int64 > &coefs)
scalar product
int64 solutions() const
The number of solutions found since the start of the search.
void SetEndMax(const IntervalVar *const var, int64 m)
Relocate: OROPT and RELOCATE.
int64 PerformedMax(const IntervalVar *const var) const
virtual std::string DebugString() const
Constraint * MakeMemberCt(IntExpr *const expr, const std::vector< int64 > &values)
expr in set.
virtual void RegisterNewSolution(Assignment *const assignment)=0
This method is called when a new solution has been accepted by the local search.
bool operator!=(const AssignmentContainer< V, E > &container) const
static const char kVariableGroupExtension[]
virtual int64 StartMin() const =0
These methods query, set, and watch the start position of the interval var.
static const char kIntervalUnaryRelation[]
static const char kGlobalCardinality[]
IntervalVar * MakeFixedDurationEndSyncedOnStartIntervalVar(IntervalVar *const interval_var, int64 duration, int64 offset)
Creates an interval var with a fixed duration whose end is synchronized with the start of another int...
std::function< bool(int64, int64, int64)> VariableValueComparator
void Add(IntVar *const var)
Add API.
void FillSequence(std::vector< int > *const rank_first, std::vector< int > *const rank_last, std::vector< int > *const unperformed) const
Clears 'rank_first' and 'rank_last', and fills them with the intervals in the order of the ranks.
void Copy(const AssignmentContainer< V, E > &container)
Copies all the elements of 'container' to this container, clearing its previous content.
static const char kTuplesArgument[]
IntVar * MakeIntConst(int64 val, const std::string &name)
IntConst will create a constant expression.
virtual void RemoveInterval(int64 l, int64 u)=0
This method removes the interval 'l' .
int64 wall_time() const
DEPRECATED: Use Now() instead.
void Deactivate(const IntVar *const var)
SearchMonitor * MakeTabuSearch(bool maximize, IntVar *const v, int64 step, const std::vector< IntVar * > &vars, int64 keep_tenure, int64 forbid_tenure, double tabu_factor)
MetaHeuristics which try to get the search out of local optima.
static const char kWeightedSumOfAssignedEqualVariableExtension[]
Constraint * MakeScalProdLessOrEqual(const std::vector< IntVar * > &vars, const std::vector< int64 > &coefficients, int64 cst)
bool IsUndecided(int var_index, int bin_index) const
Constraint * MakeIndexOfFirstMinValueConstraint(IntVar *index, const std::vector< IntVar * > &vars)
Creates a constraint that binds the index variable to the index of the first variable with the minimu...
void SetPerformedMax(int64 m)
Constraint * MakeDeviation(const std::vector< IntVar * > &vars, IntVar *const deviation_var, int64 total_sum)
Deviation constraint: sum_i |n * vars[i] - total_sum| <= deviation_var and sum_i vars[i] == total_sum...
void SetTransitionTime(Solver::IndexEvaluator2 transition_time)
Add a transition time between intervals.
int NumSequenceVars() const
ModelVisitor * MakePrintModelVisitor()
Prints the model.
static const char kIsLessOrEqual[]
static const char kElementEqual[]
int solution_count() const
Returns how many solutions were stored during the search.
int64 ObjectiveMin() const
Left branches are ignored.
IntContainer * MutableIntVarContainer()
virtual IntVar * Var()
Creates a Boolean variable representing the status of the constraint (false = constraint is violated,...
virtual void RestartSearch()
Restart the search.
static const char kNotMember[]
virtual void VisitIntervalArgument(const std::string &arg_name, IntervalVar *const argument)
Visit interval argument.
virtual void WhenStartRange(Demon *const d)=0
OptimizeVar * MakeWeightedOptimize(bool maximize, const std::vector< IntVar * > &sub_objectives, const std::vector< int64 > &weights, int64 step)
Creates a weighted objective with a given sense (true = maximization).
bool crossed() const
Returns true if the limit has been crossed.
bool IsCastConstraint() const
Is the constraint created by a cast from expression to integer variable?
Demon()
This indicates the priority of a demon.
Assignment * solution(int n) const
Returns the nth solution.
Constraint * MakeInversePermutationConstraint(const std::vector< IntVar * > &left, const std::vector< IntVar * > &right)
Creates a constraint that enforces that 'left' and 'right' both represent permutations of [0....
bool Bound(const IntVar *const var) const
friend class PropagationBaseObject
OptimizationDirection
Optimization directions.
void Resize(size_t size)
Advanced usage: Resizes the container, potentially adding elements with null variables.
std::string DebugString() const override
friend class SearchMonitor
void InitialPropagate() override
This method performs the initial propagation of the constraint.
bool IsVar() const override
Returns true if the expression is indeed a variable.
bool AreAllElementsBound() const
The simple selection is CHOOSE_FIRST_UNBOUND.
void SetAssigned(int var_index)
LocalSearchMonitor * GetLocalSearchMonitor() const
Returns the local search monitor.
void SetDurationMax(int64 m)
void AddBacktrackAction(Action a, bool fast)
When SaveValue() is not the best way to go, one can create a reversible action that will be called up...
virtual SequenceVar * MakeSequenceVar()=0
Creates a sequence variable from the constraint.
void AddCountAssignedItemsDimension(IntVar *const count_var)
This dimension links 'count_var' to the actual number of items assigned to a bin in the pack.
IntVar * MakeIsMemberVar(IntExpr *const expr, const std::vector< int64 > &values)
LocalSearchFilterBound
This enum is used in Solver::MakeLocalSearchObjectiveFilter.
void AssignFirstPossibleToBin(int bin_index)
Selects the variable with the lowest starting time of all variables, and fixes its starting time to t...
~DisjunctiveConstraint() override
This class is used to manage a pool of solutions.
void SetSequence(const std::vector< int > &forward_sequence, const std::vector< int > &backward_sequence, const std::vector< int > &unperformed)
static const char kElement[]
void EnterSearch() override
Internal methods.
int64 DurationMax() const
static const char kScalProd[]
void UnassignAllRemainingItems()
virtual void SetEndMax(int64 m)=0
int64 ObjectiveMax() const
void VisitInt64ToInt64AsArray(const Solver::IndexEvaluator1 &eval, const std::string &arg_name, int64 index_max)
Expands function as array when index min is 0.
static const char kStartSyncOnStartOperation[]
std::string DebugString() const
Constraint * MakeTrueConstraint()
This constraint always succeeds.
virtual void Accept(DecisionVisitor *const visitor) const
Accepts the given visitor.
CastConstraint(Solver *const solver, IntVar *const target_var)
This class adds reversibility to a POD type.
Among unbound variables, select the variable with the highest maximal value.
~PropagationBaseObject() override
static const char kCover[]
static const char kGreater[]
void TopPeriodicCheck()
Performs PeriodicCheck on the top-level search; for instance, can be called from a nested solve to ch...
IntervalVar * MakeFixedInterval(int64 start, int64 duration, const std::string &name)
Creates a fixed and performed interval.
IntVar * MakeIsEqualCstVar(IntExpr *const var, int64 value)
status var of (var == value)
OptimizeVar * objective
SearchMonitors will display values of objective or variable (both cannot be used together).
Operator which replaces an active node by an inactive one.
std::string DebugString() const override
std::string DebugString() const override
Pretty Print.
std::string DebugString() const override
void LoadFromProto(const IntervalVarAssignment &interval_var_assignment_proto)
virtual void VisitRankLastInterval(SequenceVar *const sequence, int index)
static const char kUsageEqualVariableExtension[]
static const char kMaxEqual[]
RegularLimit * MakeLimit(int64 time, int64 branches, int64 failures, int64 solutions)
Limits the search with the 'time', 'branches', 'failures' and 'solutions' limits.
void Post() override
This method is called when the constraint is processed by the solver.
void AssignAllPossibleToBin(int bin_index)
static const char kFalseConstraint[]
void SetDurationMin(const IntervalVar *const var, int64 m)
Among unbound variables, select the variable with the largest gap between the first and the second va...
void MakeIntVarArray(int var_count, int64 vmin, int64 vmax, const std::string &name, std::vector< IntVar * > *vars)
This method will append the vector vars with 'var_count' variables having bounds vmin and vmax and ha...
static const char kEarlyDateArgument[]
static Iterator End(IntVarIterator *it)
static const char kLeftArgument[]
virtual void ApplyDecision(Decision *const d)
Before applying the decision.
virtual IntExpr * DurationExpr()=0
virtual int64 OldStartMin() const =0
int heuristic_period
The distance in nodes between each run of the heuristics.
Selects the next unbound variable on a path, the path being defined by the variables: var[i] correspo...
virtual void BeginFail()
Just when the failure occurs.
int64 StartValue(int n, IntervalVar *const var) const
This is a shortcut to get the StartValue of 'var' in the nth solution.
BinaryIntervalRelation
This enum is used in Solver::MakeIntervalVarRelation to specify the temporal relation between the two...
Assignment(Solver *const s)
static const char kStartSyncOnEndOperation[]
static const char kCumulativeArgument[]
STARTS_AFTER or ENDS_BEFORE, i.e.
IntVar * MakeIsGreaterOrEqualCstVar(IntExpr *const var, int64 value)
status var of (var >= value)
static const char kVarBoundWatcher[]
void Accept(ModelVisitor *const visitor) const override
Accepts the given model visitor.
void SetSequence(const SequenceVar *const var, const std::vector< int > &forward_sequence, const std::vector< int > &backward_sequence, const std::vector< int > &unperformed)
virtual void VisitIntervalArrayArgument(const std::string &arg_name, const std::vector< IntervalVar * > &arguments)
virtual void VisitScheduleOrPostpone(IntervalVar *const var, int64 est)
VariableSelection var_selection_schema
This parameter describes how the next variable to instantiate will be chosen.
t starts before d, i.e. Start(t) <= d.
static const char kBetween[]
void WhenEndBound(Solver::Closure closure)
virtual void WhenPerformedBound(Demon *const d)=0
Constraint * MakeIsBetweenCt(IntExpr *const expr, int64 l, int64 u, IntVar *const b)
b == (l <= expr <= u)
bool operator!=(const IntervalVarElement &element) const
STARTS_AT_START and ENDS_AT_END at the same time.
IntVar * Next(int index) const
Returns the next of the index_th interval of the sequence.
Constraint * MakeIsLessCstCt(IntExpr *const v, int64 c, IntVar *const b)
b == (v < c)
void LoadFromProto(const SequenceVarAssignment &sequence_var_assignment_proto)
void SetEndRange(const IntervalVar *const var, int64 mi, int64 ma)
int64 Rand64(int64 size)
Returns a random value between 0 and 'size' - 1;.
bool CheckConstraint(Constraint *const ct)
Checks whether adding this constraint will lead to an immediate failure.
static const char kDeviation[]
virtual int64 OldDurationMin() const =0
Constraint * MakeGreater(IntExpr *const left, IntExpr *const right)
left > right
OptimizeVar * MakeWeightedMaximize(const std::vector< IntVar * > &sub_objectives, const std::vector< int64 > &weights, int64 step)
Creates a maximization weigthed objective.
void Copy(const Assignment *assignment)
Copies 'assignment' to the current assignment, clearing its previous content.
void ExitSearch() override
End of the search.
void set_name(const std::string &name)
absl::Duration duration_limit() const
bool CheckAssignment(Assignment *const solution)
Checks whether the given assignment satisfies all relevant constraints.
int64 filtered_neighbors() const
The number of filtered neighbors (neighbors accepted by filters).
virtual const std::vector< IntVar * > & time_cumuls() const =0
std::string DebugString() const
!defined(SWIG)
int random_seed
Seed used to initialize the random part in some heuristics.
static const char kVarValueWatcher[]
static const char kStartMaxArgument[]
bool operator!=(const SequenceVarElement &element) const
const std::vector< int > & Unperformed(const SequenceVar *const var) const
void AddPropagationMonitor(PropagationMonitor *const monitor)
Adds the propagation monitor to the solver.
static const char kMinArgument[]
void set_action_on_fail(Solver::Action a)
static const char kDifferenceOperation[]
virtual int64 OldDurationMax() const =0
Constraint * MakeIsLessCt(IntExpr *const left, IntExpr *const right, IntVar *const b)
b == (left < right)
~IntVarIterator() override
int64 PerformedMin(const IntervalVar *const var) const
virtual void WhenDurationBound(Demon *const d)=0
void WhenPerformedBound(Solver::Action action)
static const char kSequencesArgument[]
static const char kPower[]
static const char kLateCostArgument[]
ModelVisitor * MakeStatisticsModelVisitor()
Displays some nice statistics on the model.
int64 TransitionTime(int before_index, int after_index)
Constraint * MakeFalseConstraint()
This constraint always fails.
virtual void VisitIntegerArgument(const std::string &arg_name, int64 value)
Visit integer arguments.
Constraint * MakeLexicalLess(const std::vector< IntVar * > &left, const std::vector< IntVar * > &right)
std::vector<IntVar*>* const sorted);
const IntContainer & IntVarContainer() const
static const char kSearchLimitExtension[]
static const char kEquality[]
std::string DebugString() const override
virtual void SetPerformed(bool val)=0
const std::vector< int > & ForwardSequence(int n, SequenceVar *const var) const
This is a shortcut to get the ForwardSequence of 'var' in the nth solution.
int constraints() const
Counts the number of constraints that have been added to the solver before the search.
Constraint * MakeSumLessOrEqual(const std::vector< IntVar * > &vars, int64 cst)
Variation on arrays.
virtual bool AcceptSolution()
This method is called when a solution is found.
static const char kCountEqual[]
int SearchDepth() const
Gets the search depth of the current active search.
IntervalVar * MakeFixedDurationIntervalVar(int64 start_min, int64 start_max, int64 duration, bool optional, const std::string &name)
Creates an interval var with a fixed duration.
Constraint * MakeNonOverlappingNonStrictBoxesConstraint(const std::vector< IntVar * > &x_vars, const std::vector< IntVar * > &y_vars, const std::vector< IntVar * > &x_size, const std::vector< IntVar * > &y_size)
This constraint states that all the boxes must not overlap.
IntervalVar * MakeIntervalRelaxedMin(IntervalVar *const interval_var)
Creates and returns an interval variable that wraps around the given one, relaxing the min start and ...
virtual void BeginVisitExtension(const std::string &type)
DecisionBuilder * MakeStoreAssignment(Assignment *assignment)
Returns a DecisionBuilder which stores an Assignment (calls void Assignment::Store())
IntervalVar * MakeFixedDurationStartSyncedOnStartIntervalVar(IntervalVar *const interval_var, int64 duration, int64 offset)
Creates an interval var with a fixed duration whose start is synchronized with the start of another i...
static const char kIsLess[]
virtual bool MustBePerformed() const =0
These methods query, set, and watch the performed status of the interval var.
NORMAL_PRIORITY is the highest priority: Demons will be processed first.
static const char kFinalStatesArgument[]
Creates a search monitor from logging parameters.
The default behavior is CHOOSE_FIRST_UNBOUND.
virtual int64 OldMax() const =0
Returns the previous max.
static const char kIsEqual[]
Operator which defines one neighbor per variable.
SearchMonitor * MakeSimulatedAnnealing(bool maximize, IntVar *const v, int64 step, int64 initial_temperature)
Creates a Simulated Annealing monitor.
static const char kIndexOf[]
t1 ends at t2 start, i.e. End(t1) == Start(t2) + delay.
void WhenAnything(Solver::Closure closure)
Attaches a closure awakened when anything about this interval changes.
void PopSolution()
Remove and delete the last popped solution.
void SetObjectiveValue(int64 value)
void SetValue(Solver *const s, const T &val)
static const char kAllDifferent[]
Pack * MakePack(const std::vector< IntVar * > &vars, int number_of_bins)
This constraint packs all variables onto 'number_of_bins' variables.
Constraint * MakeIntervalVarRelationWithDelay(IntervalVar *const t1, BinaryIntervalRelation r, IntervalVar *const t2, int64 delay)
This method creates a relation between two interval vars.
static const char kStepArgument[]
void Assign(int var_index, int bin_index)
SolutionCollector * MakeAllSolutionCollector()
Collect all solutions of the search.
virtual void VisitRankFirstInterval(SequenceVar *const sequence, int index)
bool InstrumentsDemons() const
Returns whether we are instrumenting demons.
int TopProgressPercent()
Returns a percentage representing the propress of the search before reaching the limits of the top-le...
static const char kNextsArgument[]
Move is accepted when the current objective value is in the interval objective.Min .
void DeactivateObjective()
virtual void ExitSearch()
End of the search.
int64 accepted_neighbors() const
The number of accepted neighbors.
void ExecuteAll(const SimpleRevFIFO< Demon * > &demons)
SolutionCollector(Solver *const solver, const Assignment *assignment)
RegularLimit * MakeFailuresLimit(int64 failures)
Creates a search limit that constrains the number of failures that can happen when exploring the sear...
Constraint * MakeLessOrEqual(IntExpr *const left, IntExpr *const right)
left <= right
static const char kMember[]
void set_optimization_direction(OptimizationDirection direction)
Holds semantic information stating that the 'expression' has been cast into 'variable' using the Var(...
Constraint * MakeIsMemberCt(IntExpr *const expr, const std::vector< int64 > &values, IntVar *const boolvar)
boolvar == (expr in set)
virtual void Accept(ModelVisitor *const visitor) const
SolverState state() const
State of the solver.
ValueSelection value_selection_schema
This parameter describes which value to select for a given var.
void RankFirst(int index)
Ranks the index_th interval var first of all unranked interval vars.
virtual void VisitIntegerVariableArrayArgument(const std::string &arg_name, const std::vector< IntVar * > &arguments)
T * RevAllocArray(T *object)
Like RevAlloc() above, but for an array of objects: the array must have been allocated with the new[]...
virtual void RemoveValue(int64 v)=0
This method removes the value 'v' from the domain of the variable.
const std::vector< int > & ForwardSequence(const SequenceVar *const var) const
virtual void SetStartMin(int64 m)=0
static const char kDurationMinArgument[]
E * MutableElement(int index)
int64 objective_value(int n) const
Returns the objective value of the nth solution.
DecisionBuilder * Compose(DecisionBuilder *const db1, DecisionBuilder *const db2)
Creates a decision builder which sequentially composes decision builders.
virtual void VisitIntegerMatrixArgument(const std::string &arg_name, const IntTupleSet &tuples)
virtual void SetEndMin(int64 m)=0
virtual void SetStartRange(int64 mi, int64 ma)=0
Selects the max value of the selected variable.
The simple is INTERVAL_SET_TIMES_FORWARD.
void Fail()
Abandon the current branch in the search tree. A backtrack will follow.
void AddWeightedSumEqualVarDimension(const std::vector< int64 > &weights, const std::vector< IntVar * > &loads)
This dimension imposes that for all bins b, the weighted sum (weights[i]) of all objects i assigned t...
static const char kInt64ToInt64Extension[]
void Push(const SolutionData &data)
STARTS_BEFORE and ENDS_AFTER at the same time, i.e.
const E * ElementPtrOrNull(const V *const var) const
int64 DurationMin() const
The simple selection is ASSIGN_MIN_VALUE.
virtual std::string BaseName() const
Returns a base name for automatic naming.
static const char kIsBetween[]
Constraint * MakeIsGreaterOrEqualCstCt(IntExpr *const var, int64 value, IntVar *const boolvar)
boolvar == (var >= value)
void SetUseFastLocalSearch(bool use_fast_local_search)
enabled for metaheuristics.
static const char kDivide[]
This class is the root class of all solution collectors.
static const char kAllowedAssignments[]
Constraint * MakeCover(const std::vector< IntervalVar * > &vars, IntervalVar *const target_var)
This constraint states that the target_var is the convex hull of the intervals.
IntExpr * MakeDiv(IntExpr *const expr, int64 value)
expr / value (integer division)
A DecisionBuilder is responsible for creating the search tree.
void RankNotLast(int index)
Indicates that the index_th interval var will not be ranked first of all currently unranked interval ...
uint64 stamp() const
The stamp indicates how many moves in the search tree we have performed.
static const char kCoefficientsArgument[]
void WriteToProto(SequenceVarAssignment *sequence_var_assignment_proto) const
void ReSeed(int32 seed)
Reseed the solver random generator.
static ConstraintSolverParameters DefaultSolverParameters()
Create a ConstraintSolverParameters proto with all the default values.
const IntervalContainer & IntervalVarContainer() const
void SetObjectiveMax(int64 m)
void EnqueueDelayedDemon(Demon *const d)
This method pushes the demon onto the propagation queue.
void Reset(IntVar *const var)
static const char kTrace[]
void ShouldFail()
These methods are only useful for the SWIG wrappers, which need a way to externally cause the Solver ...
Operator which relaxes two sub-chains of three consecutive arcs each.
void PushState()
The PushState and PopState methods manipulates the states of the reversible objects.
static const char kCountArgument[]
InitAndGetValues(IntVarIterator *it)
IntervalVarElement * Clone()
t starts after d, i.e. Start(t) >= d.
NumericalRevArray(int size, const T &val)
bool InstrumentsVariables() const
Returns whether we are tracing variables.
void WhenEndBound(Solver::Action action)
After failed NextSolution and before EndSearch.
static const char kPerformedExpr[]
void SetPerformedRange(int64 mi, int64 ma)
SearchMonitor * MakeSearchLog(int branch_period)
The SearchMonitors below will display a periodic search log on LOG(INFO) every branch_period branches...
virtual void Copy(const SearchLimit *const limit)=0
Copy a limit.
void SetEndValue(int64 v)
void Init() override
This method is called when the search limit is initialized.
void SetEndValue(const IntervalVar *const var, int64 value)
void SetStartValue(int64 v)
void OneDomain(int var_index)
bool found_initial_solution_
DecisionModification
The Solver is responsible for creating the search tree.
PropagationBaseObject(Solver *const s)
static const char kInt64ToBoolExtension[]
virtual IntVar * Var()=0
Creates a variable from the expression.
std::string DebugString() const override
AssignmentContainer< IntVar, IntVarElement > IntContainer
virtual bool Contains(int64 v) const =0
This method returns whether the value 'v' is in the domain of the variable.
OptimizationDirection optimization_direction() const
The direction of optimization, getter and setter.
void SetStartRange(int64 mi, int64 ma)
int64 PerformedValue() const
Constraint * MakeAtMost(std::vector< IntVar * > vars, int64 value, int64 max_count)
|{i | vars[i] == value}| <= max_count
static const char kAbsEqual[]
virtual void BeginVisitIntegerExpression(const std::string &type_name, const IntExpr *const expr)
virtual void VisitSequenceArrayArgument(const std::string &arg_name, const std::vector< SequenceVar * > &arguments)
bool operator==(const AssignmentContainer< V, E > &container) const
Returns true if this and 'container' both represent the same V* -> E map.
Randomly select one of the remaining unbound variables.
SolutionData BuildSolutionDataForCurrentState()
void SaveAndAdd(T *adr, T val)
All-in-one SaveAndAdd_value.
void ClearLocalSearchState()
Clears the local search state.
bool persistent_impact
Whether to keep the impact from the first search for other searches, or to recompute the impact for e...
Constraint * MakeIndexOfConstraint(const std::vector< IntVar * > &vars, IntVar *const index, int64 target)
This constraint is a special case of the element constraint with an array of integer variables,...
int64 failures(int n) const
Returns the number of failures encountered at the time of the nth solution.
virtual void EndVisitConstraint(const std::string &type_name, const Constraint *const constraint)
Constraint * MakeIndexOfFirstMaxValueConstraint(IntVar *index, const std::vector< IntVar * > &vars)
Creates a constraint that binds the index variable to the index of the first variable with the maximu...
Pairs are compared at the first call of the selector, and results are cached.
void Accept(ModelVisitor *const visitor) const override
Accepts the given model visitor.
virtual int64 Value() const =0
This method returns the value of the variable.
SequenceVarElement * Clone()
virtual void SetMax(int64 m)=0
int64 DurationMin(const IntervalVar *const var) const
Constraint * MakeNonOverlappingBoxesConstraint(const std::vector< IntVar * > &x_vars, const std::vector< IntVar * > &y_vars, const std::vector< IntVar * > &x_size, const std::vector< IntVar * > &y_size)
This constraint states that all the boxes must not overlap.
Local Search Filters are used for fast neighbor pruning.
int64 PerformedMax() const
virtual void VisitIntegerArrayArgument(const std::string &arg_name, const std::vector< int64 > &values)
Constraint * MakeIsGreaterOrEqualCt(IntExpr *const left, IntExpr *const right, IntVar *const b)
b == (left >= right)
void RankLast(int index)
Ranks the index_th interval var first of all unranked interval vars.
Constraint * MakeNotBetweenCt(IntExpr *const expr, int64 l, int64 u)
(expr < l || expr > u) This constraint is lazy as it will not make holes in the domain of variables.
Constraint * MakeEquality(IntExpr *const left, IntExpr *const right)
left == right
Operator which inserts an inactive node into a path.
The default is INTERVAL_SET_TIMES_FORWARD.
IntVar * target_var() const
static const char kScalProdLessOrEqual[]
virtual void WhenDomain(Demon *d)=0
This method attaches a demon that will watch any domain modification of the domain of the variable.
IntExpr * MakeDifference(IntExpr *const left, IntExpr *const right)
left - right
std::ostream & operator<<(std::ostream &out, const Solver *const s)
void SetPerformedMax(const IntervalVar *const var, int64 m)
std::string DebugString() const override
void FinishCurrentSearch()
Tells the solver to kill or restart the current search.
bool ActivatedObjective() const
void Accept(ModelVisitor *const visitor) const
Accepts the given model visitor.
static const char kCircuit[]
virtual const std::vector< IntVar * > & nexts() const =0
int SearchLeftDepth() const
Gets the search left depth of the current active search.
Constraint * MakeMapDomain(IntVar *const var, const std::vector< IntVar * > &actives)
This constraint maps the domain of 'var' onto the array of variables 'actives'.
void SetDurationRange(const IntervalVar *const var, int64 mi, int64 ma)
RevArray(int size, const T &val)
Constraint * MakeSubCircuit(const std::vector< IntVar * > &nexts)
Force the "nexts" variable to create a complete Hamiltonian path for those that do not loop upon them...
A constraint is the main modeling object.
E * MutableElement(const V *const var)
t1 starts at t2 end, i.e. Start(t1) == End(t2) + delay.
SolutionCollector * MakeLastSolutionCollector()
Collect the last solution of the search.
SearchMonitor(Solver *const s)
virtual IntExpr * SafeDurationExpr(int64 unperformed_value)=0
uint64 fail_stamp() const
The fail_stamp() is incremented after each backtrack.
virtual void NoMoreSolutions()
When the search tree is finished.
Operator which defines one neighbor per variable.
virtual void SetRange(int64 l, int64 u)
This method sets both the min and the max of the expression.
void SetStartValue(const IntervalVar *const var, int64 value)
static const char kIndexArgument[]
IntervalVar * MakeFixedDurationStartSyncedOnEndIntervalVar(IntervalVar *const interval_var, int64 duration, int64 offset)
Creates an interval var with a fixed duration whose start is synchronized with the end of another int...
Decision * MakeScheduleOrExpedite(IntervalVar *const var, int64 est, int64 *const marker)
Returns a decision that tries to schedule a task at a given time.
void SetDurationValue(int64 v)
bool AcceptDelta(Assignment *delta, Assignment *deltadelta) override
Internal methods.
IntervalVar * Interval(int index) const
Returns the index_th interval of the sequence.
Operator which reverses a sub-chain of a path.
Among unbound variables, select the variable with the smallest minimal value.
const E & Element(const V *const var) const
virtual bool WasPerformedBound() const =0
This struct holds all parameters for the default search.
SequenceContainer * MutableSequenceVarContainer()
static const char kObjectiveExtension[]
const SequenceContainer & SequenceVarContainer() const
static const char kProductOperation[]
Selects the variable with the highest ending time of all variables, and fixes the ending time to this...
Operator which relaxes one entire path and all inactive nodes, thus defining num_paths neighbors.
void EnqueueAll(const SimpleRevFIFO< Demon * > &demons)
OptimizeVar * MakeMaximize(IntVar *const v, int64 step)
Creates a maximization objective.
bool AreAllElementsBound() const
static Iterator Begin(IntVarIterator *it)
These are the only way to construct an Iterator.
LocalSearchFilter * MakeVariableDomainFilter()
Local Search Filters.
void LoadFromProto(const IntVarAssignment &int_var_assignment_proto)
int64 Value(int n, IntVar *const var) const
This is a shortcut to get the Value of 'var' in the nth solution.
void RankSequence(const std::vector< int > &rank_first, const std::vector< int > &rank_last, const std::vector< int > &unperformed)
Applies the following sequence of ranks, ranks first, then rank last.
E * MutableElementOrNull(const V *const var)
A DecisionVisitor is used to inspect a decision.
void Copy(const IntervalVarElement &element)
IntVarElement * FastAdd(IntVar *const var)
Adds without checking if variable has been previously added.
bool ObjectiveBound() const
static const int64 kMaxValidValue
The largest acceptable value to be returned by EndMax()
void EnterSearch() override
Beginning of the search.
Decision * balancing_decision() const
int64 neighbors() const
The number of neighbors created.
IntExpr * RegisterIntExpr(IntExpr *const expr)
Registers a new IntExpr and wraps it inside a TraceIntExpr if necessary.
SearchMonitor * MakeLubyRestart(int scale_factor)
This search monitor will restart the search periodically.
Among unbound variables, select the variable with the highest size.
bool operator==(const IntVarElement &element) const
virtual void Accept(ModelVisitor *const visitor) const =0
Accepts the given visitor.
Decision * MakeDecision(Action apply, Action refute)
Selects randomly one of the possible values of the selected variable.
virtual bool Check()=0
This method is called to check the status of the limit.
ModelCache * Cache() const
Returns the cache of the model.
std::function< DecisionModification()> BranchSelector
SearchMonitor * MakeExitSearchCallback(std::function< void()> callback)
Constraint(Solver *const solver)
void SetStartMin(const IntervalVar *const var, int64 m)
~SolutionCollector() override
virtual void Refute(Solver *const s)=0
Refute will be called after a backtrack.
virtual bool LocalOptimum()
When a local optimum is reached.
void Accept(ModelVisitor *const visitor) const override
Accepts the given visitor.
virtual void GetNextSolution(Assignment *const assignment)=0
This method is called when the local search starts a new neighborhood to initialize the default assig...
static const char kDurationMaxArgument[]
void RefuteDecision(Decision *const d) override
Before refuting the decision.
IntVar * MakeIsGreaterCstVar(IntExpr *const var, int64 value)
status var of (var > value)
Constraint * MakeNoCycle(const std::vector< IntVar * > &nexts, const std::vector< IntVar * > &active, IndexFilter1 sink_handler=nullptr)
Prevent cycles.
Among unbound variables, select the variable with the smallest size, i.e., the smallest number of pos...
virtual int64 Min() const =0
IntVar * MakeIsLessOrEqualVar(IntExpr *const left, IntExpr *const right)
status var of (left <= right)
virtual void SetValues(const std::vector< int64 > &values)
This method intersects the current domain with the values in the array.
Constraint * MakeIsLessOrEqualCt(IntExpr *const left, IntExpr *const right, IntVar *const b)
b == (left <= right)
virtual int64 EndMax() const =0
virtual void WhenDurationRange(Demon *const d)=0
Split the domain in two around the center, and choose the lower part first.
virtual void Next()=0
This method moves the iterator to the next value.
void VisitInt64ToInt64Extension(const Solver::IndexEvaluator1 &eval, int64 index_min, int64 index_max)
void WhenEndRange(Solver::Action action)
virtual void SetValue(int64 v)
This method sets the value of the expression.
static const char kGreaterOrEqual[]
UnaryIntervalRelation
This enum is used in Solver::MakeIntervalVarRelation to specify the temporal relation between an inte...
void MakeFixedDurationIntervalVarArray(int count, int64 start_min, int64 start_max, int64 duration, bool optional, const std::string &name, std::vector< IntervalVar * > *const array)
This method fills the vector with 'count' interval variables built with the corresponding parameters.
void SetUnassigned(int var_index)
void set_fail_intercept(std::function< void()> fail_intercept)
Internal.
IntExpr * CastExpression(const IntVar *const var) const
!defined(SWIG)
IntExpr * MakeMonotonicElement(IndexEvaluator1 values, bool increasing, IntVar *const index)
Function based element.
virtual void WhenStartBound(Demon *const d)=0
static const char kScalProdGreaterOrEqual[]
static const char kTrueConstraint[]
void SetImpossible(int var_index, int bin_index)
void WhenPerformedBound(Solver::Closure closure)
Among unbound variables, select the variable with the smallest size, i.e., the smallest number of pos...
SequenceVar * Var() const
virtual void VisitSequenceArgument(const std::string &arg_name, SequenceVar *const argument)
Visit sequence argument.
bool Load(const std::string &filename)
Loads an assignment from a file; does not add variables to the assignment (only the variables contain...
static const char kTargetArgument[]
int SolveDepth() const
Gets the number of nested searches.
MarkerType
This enum is used internally in private methods Solver::PushState and Solver::PopState to tag states ...
LocalSearchOperator * MakeMoveTowardTargetOperator(const Assignment &target)
Creates a local search operator that tries to move the assignment of some variables toward a target.
int64 wall_time(int n) const
Returns the wall time in ms for the nth solution.
LocalSearchOperator * ConcatenateOperators(const std::vector< LocalSearchOperator * > &ops)
Creates a local search operator which concatenates a vector of operators.
std::unique_ptr< Assignment > prototype_
std::string DebugString() const override
Constraint * MakePathConnected(std::vector< IntVar * > nexts, std::vector< int64 > sources, std::vector< int64 > sinks, std::vector< IntVar * > status)
Constraint enforcing that status[i] is true iff there's a path defined on next variables from sources...
RegularLimitParameters MakeDefaultRegularLimitParameters() const
Creates a regular limit proto containing default values.
E * FastAdd(V *var)
Adds element without checking its presence in the container.
~DecisionBuilder() override
Constraint * MakePathTransitPrecedenceConstraint(std::vector< IntVar * > nexts, std::vector< IntVar * > transits, const std::vector< std::pair< int, int >> &precedences)
Same as MakePathPrecedenceConstraint but will force i to be before j if the sum of transits on the pa...
static const int64 kMinValidValue
The smallest acceptable value to be returned by StartMin()
virtual int64 Max() const =0
void WhenStartBound(Solver::Closure closure)
virtual void Accept(ModelVisitor *const visitor) const
Accepts the given visitor.
virtual bool IsUncheckedSolutionLimitReached()
Returns true if the limit of solutions has been reached including unchecked solutions.
int64 DurationValue(const IntervalVar *const var) const
DisjunctiveConstraint * MakeDisjunctiveConstraint(const std::vector< IntervalVar * > &intervals, const std::string &name)
This constraint forces all interval vars into an non-overlapping sequence.
int index() const
Returns the index of the variable.
Assignment * GetOrCreateLocalSearchState()
Returns (or creates) an assignment representing the state of local search.
Demon * MakeActionDemon(Action action)
Creates a demon from a callback.
void SetBackwardSequence(const SequenceVar *const var, const std::vector< int > &backward_sequence)
static const char kCardsArgument[]
Operator which makes a "chain" of path nodes inactive.
virtual void BeginVisitConstraint(const std::string &type_name, const Constraint *const constraint)
friend class LocalSearchProfiler
virtual const std::vector< IntVar * > & actives() const =0
int64 EndMin(const IntervalVar *const var) const
static const char kSequenceArgument[]
Constraint * MakePathPrecedenceConstraint(std::vector< IntVar * > nexts, const std::vector< std::pair< int, int >> &precedences)
Contraint enforcing, for each pair (i,j) in precedences, i to be before j in paths defined by next va...
DecisionBuilder * MakeRestoreAssignment(Assignment *assignment)
Returns a DecisionBuilder which restores an Assignment (calls void Assignment::Restore())
void EnqueueVar(Demon *const d)
SearchLimit * MakeCustomLimit(std::function< bool()> limiter)
Callback-based search limit.
Usual limit based on wall_time, number of explored branches and number of failures in the search tree...
Constraint * MakeLexicalLessOrEqual(const std::vector< IntVar * > &left, const std::vector< IntVar * > &right)
Creates a constraint that enforces that left is lexicographically less than or equal to right.
int64 Max(const IntVar *const var) const
const E & Element(int index) const
void Reset(SequenceVar *const var)
void Add(Solver *const s, const T &to_add)
void UpdateLimits(int64 time, int64 branches, int64 failures, int64 solutions)
static const char kStartsArgument[]
virtual bool AcceptDelta(Assignment *delta, Assignment *deltadelta)
Demon * RegisterDemon(Demon *const demon)
Adds a new demon and wraps it inside a DemonProfiler if necessary.
virtual int VarType() const
IntVar * MakeIntVar(int64 min, int64 max, const std::string &name)
MakeIntVar will create the best range based int var for the bounds given.
virtual bool Bound() const
Returns true if the min and the max of the expression are equal.
friend void InternalSaveBooleanVarValue(Solver *const, IntVar *const)
std::function< IntVar *(int64)> Int64ToIntVar
DecisionBuilder * MakeDefaultPhase(const std::vector< IntVar * > &vars)
Constraint * MakeScalProdEquality(const std::vector< IntVar * > &vars, const std::vector< int64 > &coefficients, int64 cst)
A BaseObject is the root of all reversibly allocated objects.
void SetPerformedValue(int64 v)
T * RevAlloc(T *object)
Registers the given object as being reversible.
DecisionBuilder * MakeSolveOnce(DecisionBuilder *const db)
SolveOnce will collapse a search tree described by a decision builder 'db' and a set of monitors and ...
The class IntExpr is the base of all integer expressions in constraint programming.
static const char kMinEqual[]
void WhenDurationBound(Solver::Action action)
bool operator<(const SolutionData &other) const
Executing the search code.
static const int kNumPriorities
Number of priorities for demons.
static const char kIsGreaterOrEqual[]
A search monitor is a simple set of callbacks to monitor all search events.
std::string DebugString() const override
The default behavior is ASSIGN_MIN_VALUE.
IntExpr * MakeOpposite(IntExpr *const expr)
-expr
Reversible array of POD types.
Operator which exchanges the positions of two nodes.
IntVar *const target_var_
Among unbound variables, select the variable with the smallest size, i.e., the smallest number of pos...
OptimizeVar * MakeWeightedMinimize(const std::vector< IntVar * > &sub_objectives, const std::vector< int64 > &weights, int64 step)
Creates a minimization weighted objective.
bool CannotBePerformed() const
std::string DebugString() const override
int64 size() const
Returns the number of interval vars in the sequence.
virtual const std::vector< IntVar * > & time_slacks() const =0
std::string model_name() const
Returns the name of the model.
std::function< bool(int64)> IndexFilter1
IntExpr * MakeElement(const std::vector< int64 > &values, IntVar *const index)
values[index]
static const char kEndMaxArgument[]
SearchMonitor * MakeSymmetryManager(const std::vector< SymmetryBreaker * > &visitors)
Symmetry Breaking.
AssignmentContainer< IntervalVar, IntervalVarElement > IntervalContainer
ConstraintSolverParameters parameters() const
Stored Parameters.
static const char kSizeArgument[]
SolutionCollector * MakeNBestValueSolutionCollector(const Assignment *const assignment, int solution_count, bool maximize)
Same as MakeBestValueSolutionCollector but collects the best solution_count solutions.
int ProgressPercent() override
Returns a percentage representing the propress of the search before reaching limits.
virtual void InitialPropagate()=0
This method performs the initial propagation of the constraint.
virtual std::string Print() const
static const char kInitialState[]
bool UseFastLocalSearch() const
Returns true if fast local search is enabled.
Split the domain in two around the center, and choose the lower part first.
Decision * MakeFailDecision()
std::function< void(int64)> ObjectiveWatcher
Search * ActiveSearch() const
Returns the active search, nullptr outside search.
void SetPerformedMin(int64 m)
virtual IntVar * IsDifferent(int64 constant)=0
The class IntVar is a subset of IntExpr.
static const char kCapacityArgument[]
IntervalVar * RegisterIntervalVar(IntervalVar *const var)
Registers a new IntervalVar and wraps it inside a TraceIntervalVar if necessary.
A symmetry breaker is an object that will visit a decision and create the 'symmetrical' decision in r...
Among unbound variables, select the variable with the smallest size, i.e., the smallest number of pos...
int64 StartMax(const IntervalVar *const var) const
IntVarLocalSearchFilter * MakeSumObjectiveFilter(const std::vector< IntVar * > &vars, IndexEvaluator2 values, IntVar *const objective, Solver::LocalSearchFilterBound filter_enum)
int64 failures() const
The number of failures encountered since the creation of the solver.
E * AddAtPosition(V *var, int position)
Advanced usage: Adds element at a given position; position has to have been allocated with Assignment...
static const char kEvaluatorArgument[]
const std::vector< int > & Unperformed() const
int64 unchecked_solutions() const
The number of unchecked solutions found by local search.
RegularLimit(Solver *const s, int64 time, int64 branches, int64 failures, int64 solutions, bool smart_time_check, bool cumulative)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Constraint * MakeScalProdGreaterOrEqual(const std::vector< IntVar * > &vars, const std::vector< int64 > &coeffs, int64 cst)
static const char kRightArgument[]
void AddConstraint(Constraint *const c)
Adds the constraint 'c' to the model.
virtual IntExpr * PerformedExpr()=0
virtual bool MayBePerformed() const =0
static const char kMirrorOperation[]
Operations.
virtual int64 OldMin() const =0
Returns the previous min.
bool operator!=(const Assignment &assignment) const
Constraint * MakeBetweenCt(IntExpr *const expr, int64 l, int64 u)
(l <= expr <= u)
The class Iterator has two direct subclasses.
void FreezeQueue()
This method freezes the propagation queue.
~CastConstraint() override
DisjunctiveConstraint(Solver *const s, const std::vector< IntervalVar * > &intervals, const std::string &name)
Constraint * MakeIsDifferentCstCt(IntExpr *const var, int64 value, IntVar *const boolvar)
boolvar == (var != value)
static const char kVariableArgument[]
virtual Solver::DemonPriority priority() const
This method returns the priority of the demon.
IntVar * Var() const
Returns the variable that is optimized.
static const char kConditionalExpr[]
IntVarElement * Add(IntVar *const var)
t1 starts at t2 start, i.e. Start(t1) == Start(t2) + delay.
IntegerCastInfo(IntVar *const v, IntExpr *const e, Constraint *const c)
bool operator==(const Assignment &assignment) const
static const char kSizeYArgument[]
VAR_PRIORITY is between DELAYED_PRIORITY and NORMAL_PRIORITY.
void SetBackwardSequence(const std::vector< int > &backward_sequence)
bool IsProfilingEnabled() const
Returns whether we are profiling the solver.
Demon * MakeDelayedConstraintInitialPropagateCallback(Constraint *const ct)
This method is a specialized case of the MakeConstraintDemon method to call the InitiatePropagate of ...
int branch_period
SearchMonitors will display a periodic search log every branch_period branches explored.
t ends at d, i.e. End(t) == d.
DisjunctiveConstraint * MakeStrictDisjunctiveConstraint(const std::vector< IntervalVar * > &intervals, const std::string &name)
This constraint forces all interval vars into an non-overlapping sequence.
virtual bool Ok() const =0
This method indicates if we can call Value() or not.
Select the first unbound variable.
void BeginNextDecision(DecisionBuilder *const db) override
Before calling DecisionBuilder::Next.
static const char kStartMinArgument[]
~DecisionVisitor() override
absl::Time AbsoluteSolverDeadline() const
static const char kProduct[]
OptimizeVar * MakeMinimize(IntVar *const v, int64 step)
Creates a minimization objective.
static const char kRelaxedMinOperation[]
SearchMonitor * MakeEnterSearchCallback(std::function< void()> callback)
--— Callback-based search monitors --—
virtual void EndVisitIntegerExpression(const std::string &type_name, const IntExpr *const expr)
static const char kSumOperation[]
void Incr(Solver *const s)
void SetForwardSequence(const std::vector< int > &forward_sequence)
Constraint * MakeAllDifferent(const std::vector< IntVar * > &vars)
All variables are pairwise different.
void DurationRange(int64 *const dmin, int64 *const dmax) const
Returns the minimum and maximum duration of combined interval vars in the sequence.
static const char kUsageLessConstantExtension[]
Decision * MakeAssignVariablesValues(const std::vector< IntVar * > &vars, const std::vector< int64 > &values)
virtual uint64 Size() const =0
This method returns the number of values in the domain of the variable.
static const char kIsGreater[]
DisplayLevel display_level
This represents the amount of information displayed by the default search.
t1 ends after t2 end, i.e. End(t1) >= End(t2) + delay.
static const char kIntervalArgument[]
void desinhibit(Solver *const s)
This method un-inhibits the demon that was previously inhibited.
Pairs are compared each time a variable is selected.
virtual void SetEndRange(int64 mi, int64 ma)=0
virtual void Run(Solver *const s)=0
This is the main callback of the demon.
static const char kPositionYArgument[]
static const char kEarlyCostArgument[]
Constraint * MakePathCumul(const std::vector< IntVar * > &nexts, const std::vector< IntVar * > &active, const std::vector< IntVar * > &cumuls, const std::vector< IntVar * > &transits)
Creates a constraint which accumulates values along a path such that: cumuls[next[i]] = cumuls[i] + t...
virtual int64 DurationMax() const =0
void SetDurationMin(int64 m)
static const int kNoProgress
static const char kCumulative[]
IntVar * Var() override
Creates a variable from the expression.
virtual void EndInitialPropagation()
After the initial propagation.
Selects the min value of the selected variable.
SearchMonitor * MakeSearchTrace(const std::string &prefix)
Creates a search monitor that will trace precisely the behavior of the search.
Decision * MakeVariableLessOrEqualValue(IntVar *const var, int64 value)
std::function< int64(const IntVar *v, int64 id)> VariableValueSelector
void HorizonRange(int64 *const hmin, int64 *const hmax) const
Returns the minimum start min and the maximum end max of all interval vars in the sequence.
static const char kTraceOperation[]
virtual void SetStartMax(int64 m)=0
This class represents a reversible bitset.
Constraint * MakeIntervalVarRelation(IntervalVar *const t, UnaryIntervalRelation r, int64 d)
This method creates a relation between an interval var and a date.
std::string DebugString() const
A Decision represents a choice point in the search tree.
virtual void VisitIntervalVariable(const IntervalVar *const variable, const std::string &operation, int64 value, IntervalVar *const delegate)
Constraint * MakeIsEqualCstCt(IntExpr *const var, int64 value, IntVar *const boolvar)
boolvar == (var == value)
static const char kBranchesLimitArgument[]
Operator which relaxes all inactive nodes and one sub-chain of six consecutive arcs.
static const char kExpressionArgument[]
bool Contains(const V *const var) const
void Reset(IntervalVar *const var)
std::function< int64(int64, int64)> IndexEvaluator2
PropagationMonitor * GetPropagationMonitor() const
Returns the propagation monitor.
IntVar * MakeIsEqualVar(IntExpr *const v1, IntExpr *v2)
status var of (v1 == v2)
Interval variables are often used in scheduling.
static const char kIntervalBinaryRelation[]
static const char kAtMost[]
virtual IntVar * IsEqual(int64 constant)=0
IsEqual.
void WhenEndRange(Solver::Closure closure)
void SaveValue(T *o)
reversibility
SolverState
This enum represents the state of the solver w.r.t. the search.
int64 EndValue(const IntervalVar *const var) const
bool SolveAndCommit(DecisionBuilder *const db, const std::vector< SearchMonitor * > &monitors)
SolveAndCommit using a decision builder and up to three search monitors, usually one for the objectiv...
void reset_action_on_fail()
This method clears the failure callback.
static const char kStartExpr[]
virtual void AppendMonitors(Solver *const solver, std::vector< SearchMonitor * > *const extras)
This method will be called at the start of the search.
Assignment * MakeAssignment()
This method creates an empty assignment.
std::function< int64(int64)> IndexEvaluator1
Callback typedefs.
Among unbound variables, select the variable with the smallest size.
static const char kNotBetween[]
IntervalVar * MakeIntervalRelaxedMax(IntervalVar *const interval_var)
Creates and returns an interval variable that wraps around the given one, relaxing the max start and ...
void WriteToProto(IntVarAssignment *int_var_assignment_proto) const
virtual bool AtSolution()
This method is called when a valid solution is found.
void ActiveHorizonRange(int64 *const hmin, int64 *const hmax) const
Returns the minimum start min and the maximum end max of all unranked interval vars in the sequence.
Constraint * MakeAllDifferentExcept(const std::vector< IntVar * > &vars, int64 escape_value)
All variables are pairwise different, unless they are assigned to the escape value.
void SetStartMin(int64 m)
virtual void EndFail()
After completing the backtrack.
virtual void Post()=0
This method is called when the constraint is processed by the solver.
std::function< std::string()> display_callback
SearchMonitors will display the result of display_callback at each new solution found.
Subclass of Rev<T> which adds numerical operations.
void WhenStartBound(Solver::Action action)
virtual void BeginNextDecision(DecisionBuilder *const b)
Before calling DecisionBuilder::Next.
int32 Rand32(int32 size)
Returns a random value between 0 and 'size' - 1;.
void WhenDurationRange(Solver::Closure closure)
void Decr(Solver *const s)
static const char kRelationArgument[]
Keeps the default behavior, i.e.
void SetMax(const IntVar *const var, int64 m)
std::function< int64(Solver *solver, const std::vector< IntVar * > &vars, int64 first_unbound, int64 last_unbound)> VariableIndexSelector
static const char kScalProdEqual[]
void SaveAndSetValue(T *adr, T val)
All-in-one SaveAndSetValue.
SearchLimit * MakeClone() const override
Allocates a clone of the limit.
virtual IntVar * IsLessOrEqual(int64 constant)=0
std::string LocalSearchProfile() const
Returns local search profiling information in a human readable format.
std::vector< Assignment * > recycle_solutions_
bool Check() override
This method is called to check the status of the limit.
void AddWeightedSumOfAssignedDimension(const std::vector< int64 > &weights, IntVar *const cost_var)
This dimension enforces that cost_var == sum of weights[i] for all objects 'i' assigned to a bin.
bool operator!=(const Iterator &other) const
IntExpr * MakeIndexExpression(const std::vector< IntVar * > &vars, int64 value)
Returns the expression expr such that vars[expr] == value.
int64 PerformedMin() const
Solver::IndexEvaluator2 transition_time_
Constraint * MakeCount(const std::vector< IntVar * > &vars, int64 value, int64 max_count)
|{i | vars[i] == value}| == max_count
int64 EndMax(const IntervalVar *const var) const
void SetStartMax(int64 m)
IntVar * MakeIsLessOrEqualCstVar(IntExpr *const var, int64 value)
status var of (var <= value)
static const char kActiveArgument[]
argument names:
SearchLimit(Solver *const s)
bool IsAssignedStatusKnown(int var_index) const
double scaling_factor
Objective or var values are unscaled by this factor when displayed.
After successful NextSolution and before EndSearch.
AssignmentContainer< SequenceVar, SequenceVarElement > SequenceContainer
t1 starts after t2 start, i.e. Start(t1) >= Start(t2) + delay.
static const char kDurationExpr[]
void AddSumVariableWeightsLessOrEqualConstantDimension(const std::vector< IntVar * > &usage, const std::vector< int64 > &capacity)
This dimension imposes: forall b in bins, sum (i in items: usage[i] * is_assigned(i,...
static const char kSolutionLimitArgument[]
static const char kFailuresLimitArgument[]
static const char kDifference[]
virtual int64 OldEndMax() const =0
IntVar * VarWithName(const std::string &name)
Creates a variable from the expression and set the name of the resulting var.
bool Contains(const IntVar *const var) const
void SetDurationMax(const IntervalVar *const var, int64 m)
Base class of all search limits.
void SetPerformedValue(const IntervalVar *const var, int64 value)
Operator which defines a neighborhood to decrement values.
int64 StartMin(const IntervalVar *const var) const
static const char kSumLessOrEqual[]
static const char kConvexPiecewise[]
void AddCountUsedBinDimension(IntVar *const count_var)
This dimension links 'count_var' to the actual number of bins used in the pack.
virtual void EndVisitModel(const std::string &solver_name)
void inhibit(Solver *const s)
This method inhibits the demon in the search tree below the current position.
DemonProfiler * demon_profiler() const
Access to demon profiler.
Constraint * MakeMinEquality(const std::vector< IntVar * > &vars, IntVar *const min_var)
const std::vector< int > & BackwardSequence() const
DecisionBuilder * decision_builder
When defined, this overrides the default impact based decision builder.
IntervalVar * MakeIntervalVar(int64 start_min, int64 start_max, int64 duration_min, int64 duration_max, int64 end_min, int64 end_max, bool optional, const std::string &name)
Creates an interval var by specifying the bounds on start, duration, and end.
EvaluatorStrategy
This enum is used by Solver::MakePhase to specify how to select variables and values during the searc...
IntVar * MakeIsBetweenVar(IntExpr *const v, int64 l, int64 u)
RegularLimit * MakeTimeLimit(int64 time_in_ms)
Creates a search limit that constrains the running time given in milliseconds.
void FreeSolution(Assignment *solution)
void NewSearch(DecisionBuilder *const db, const std::vector< SearchMonitor * > &monitors)
Constraint * MakeTemporalDisjunction(IntervalVar *const t1, IntervalVar *const t2, IntVar *const alt)
This constraint implements a temporal disjunction between two interval vars t1 and t2.
IntExpr * MakeSquare(IntExpr *const expr)
expr * expr
static const char kCumulsArgument[]
Backtracks to the previous decisions, i.e.
void WhenRange(Solver::Closure closure)
Attach a demon that will watch the min or the max of the expression.
void EnterSearch() override
Beginning of the search.
bool IsProduct(IntExpr *const expr, IntExpr **inner_expr, int64 *coefficient)
Returns true if expr represents a product of a expr and a constant.
static const char kIsDifferent[]
void SetRange(const IntVar *const var, int64 l, int64 u)
The SequenceVarElement stores a partial representation of ranked interval variables in the underlying...
int64 Min(const IntVar *const var) const
t1 ends after t2 start, i.e. End(t1) >= Start(t2) + delay.
static const char kAssumePathsArgument[]
void ComputePossibleFirstsAndLasts(std::vector< int > *const possible_firsts, std::vector< int > *const possible_lasts)
Computes the set of indices of interval variables that can be ranked first in the set of unranked act...
virtual int64 OldStartMax() const =0
LocalSearchOperator * MakeNeighborhoodLimit(LocalSearchOperator *const op, int64 limit)
Creates a local search operator that wraps another local search operator and limits the number of nei...
virtual void VisitIntegerExpressionArgument(const std::string &arg_name, IntExpr *const argument)
Visit integer expression argument.
An Assignment is a variable -> domains mapping, used to report solutions to the user.
static const char kPack[]
void MakeIntervalVarArray(int count, int64 start_min, int64 start_max, int64 duration_min, int64 duration_max, int64 end_min, int64 end_max, bool optional, const std::string &name, std::vector< IntervalVar * > *const array)
This method fills the vector with 'count' interval var built with the corresponding parameters.
RegularLimit * MakeBranchesLimit(int64 branches)
Creates a search limit that constrains the number of branches explored in the search tree.
The base class for all local search operators.
Decision * MakeRankFirstInterval(SequenceVar *const sequence, int index)
Returns a decision that tries to rank first the ith interval var in the sequence variable.
void SetObjectiveMin(int64 m)
void Incr(Solver *const s, int index)
virtual IntExpr * StartExpr()=0
These methods create expressions encapsulating the start, end and duration of the interval var.
t starts at d, i.e. Start(t) == d.
virtual void AcceptNeighbor()
After accepting a neighbor during local search.
Reversible Immutable MultiMap class.
static const char kSumEqual[]
bool IsPossible(int var_index, int bin_index) const
Constraint * MakeSortingConstraint(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &sorted)
Creates a constraint binding the arrays of variables "vars" and "sorted_vars": sorted_vars[0] must be...
Selects the first possible value which is the closest to the center of the domain of the selected var...
int heuristic_num_failures_limit
The failure limit for each heuristic that we run.
void SetEndRange(int64 mi, int64 ma)
void CopyIntersection(const AssignmentContainer< V, E > &container)
Copies the elements of 'container' which are already in the calling container.
LocalSearchOperator * MakeOperator(const std::vector< IntVar * > &vars, LocalSearchOperators op)
Local Search Operators.
Constraint * MakeIsGreaterCt(IntExpr *const left, IntExpr *const right, IntVar *const b)
b == (left > right)
DecisionBuilder * MakeLocalSearchPhase(Assignment *const assignment, LocalSearchPhaseParameters *const parameters)
Local Search decision builders factories.
int64 EndValue(int n, IntervalVar *const var) const
This is a shortcut to get the EndValue of 'var' in the nth solution.
bool Activated(const IntVar *const var) const
const std::vector< E > & elements() const
void set_variable_to_clean_on_fail(IntVar *v)
Shortcut for variable cleaner.
int64 branches() const
The number of branches explored since the creation of the solver.
void WhenDomain(Solver::Closure closure)
This method attaches a closure that will watch any domain modification of the domain of the variable.
absl::Time Now() const
The 'absolute time' as seen by the solver.