14 #ifndef OR_TOOLS_SAT_INTERVALS_H_
15 #define OR_TOOLS_SAT_INTERVALS_H_
20 #include "absl/types/span.h"
58 IntervalVariable
CreateInterval(IntegerVariable start, IntegerVariable end,
59 IntegerVariable size, IntegerValue fixed_size,
60 LiteralIndex is_present);
77 IntegerVariable
SizeVar(IntervalVariable i)
const {
return size_vars_[i]; }
78 IntegerVariable
StartVar(IntervalVariable i)
const {
return start_vars_[i]; }
79 IntegerVariable
EndVar(IntervalVariable i)
const {
return end_vars_[i]; }
82 IntegerValue
MinSize(IntervalVariable i)
const {
83 const IntegerVariable size_var = size_vars_[i];
89 IntegerValue
MaxSize(IntervalVariable i)
const {
90 const IntegerVariable size_var = size_vars_[i];
97 std::vector<IntervalVariable> result;
154 absl::Span<const int> tasks);
157 int NumTasks()
const {
return start_vars_.size(); }
170 IntegerValue
SizeMin(
int t)
const;
171 IntegerValue
SizeMax(
int t)
const;
174 IntegerValue
EndMin(
int t)
const;
175 IntegerValue
EndMax(
int t)
const;
239 return &integer_reason_;
251 ABSL_MUST_USE_RESULT
bool IncreaseStartMin(
int t, IntegerValue new_min_start);
252 ABSL_MUST_USE_RESULT
bool DecreaseEndMax(
int t, IntegerValue new_max_end);
261 const std::vector<IntegerVariable>&
StartVars()
const {
return start_vars_; }
262 const std::vector<IntegerVariable>&
EndVars()
const {
return end_vars_; }
263 const std::vector<IntegerVariable>&
SizeVars()
const {
return size_vars_; }
273 bool watch_start_max =
true,
274 bool watch_end_max =
true)
const;
282 IntegerValue event) {
283 CHECK(other_helper !=
nullptr);
284 other_helper_ = other_helper;
285 event_for_other_helper_ = event;
297 void InitSortedVectors();
306 void AddOtherReason(
int t);
309 void ImportOtherReasons();
316 bool current_time_direction_ =
true;
320 std::vector<IntegerVariable> start_vars_;
321 std::vector<IntegerVariable> end_vars_;
322 std::vector<IntegerVariable> size_vars_;
323 std::vector<IntegerValue> fixed_sizes_;
324 std::vector<LiteralIndex> reason_for_presence_;
328 std::vector<IntegerVariable> minus_start_vars_;
329 std::vector<IntegerVariable> minus_end_vars_;
332 std::vector<TaskTime> task_by_increasing_start_min_;
333 std::vector<TaskTime> task_by_increasing_end_min_;
334 std::vector<TaskTime> task_by_decreasing_start_max_;
335 std::vector<TaskTime> task_by_decreasing_end_max_;
337 std::vector<TaskTime> task_by_increasing_shifted_start_min_;
338 std::vector<TaskTime> task_by_negated_shifted_end_max_;
339 int64 shifted_start_min_timestamp_ = -1;
340 int64 negated_shifted_end_max_timestamp_ = -1;
343 std::vector<Literal> literal_reason_;
344 std::vector<IntegerLiteral> integer_reason_;
348 IntegerValue event_for_other_helper_;
349 std::vector<bool> already_added_to_other_reasons_;
371 : integer_trail_->
IsFixed(size_vars_[t]);
375 return integer_trail_->
LowerBound(start_vars_[t]);
379 return integer_trail_->
UpperBound(start_vars_[t]);
383 return integer_trail_->
LowerBound(end_vars_[t]);
387 return integer_trail_->
UpperBound(end_vars_[t]);
418 integer_reason_.clear();
419 literal_reason_.clear();
422 already_added_to_other_reasons_.assign(
NumTasks(),
false);
430 literal_reason_.push_back(
Literal(reason_for_presence_[t]).Negated());
438 literal_reason_.push_back(
Literal(reason_for_presence_[t]));
445 integer_reason_.push_back(
451 int t, IntegerValue lower_bound) {
455 integer_reason_.push_back(
461 int t, IntegerValue lower_bound) {
464 integer_reason_.push_back(
469 int t, IntegerValue upper_bound) {
472 integer_reason_.push_back(
477 int t, IntegerValue lower_bound) {
479 if (
EndMin(t) < lower_bound) {
483 const IntegerValue size_min =
SizeMin(t);
485 integer_reason_.push_back(
488 integer_reason_.push_back(
492 integer_reason_.push_back(
497 int t, IntegerValue upper_bound) {
500 integer_reason_.push_back(
505 int t, IntegerValue energy_min, IntegerValue
time) {
508 integer_reason_.push_back(
511 integer_reason_.push_back(
515 integer_reason_.push_back(
525 IntervalVariable v) {
531 inline std::function<IntegerVariable(
const Model&)>
EndVar(IntervalVariable v) {
538 IntervalVariable v) {
563 IntervalVariable v) {
581 IntegerVariable start, IntegerVariable end, IntegerVariable size) {
605 IntegerValue(size), is_present.
Index());
609 inline std::function<IntervalVariable(Model*)>
614 const IntegerVariable start =
616 const IntegerVariable end =
620 integer_trail->MarkIntegerVariableAsOptional(end, is_present);
627 IntegerVariable start, IntegerVariable end, IntegerVariable size,
631 start, end, size, IntegerValue(0), is_present.
Index());
635 inline std::function<IntervalVariable(Model*)>
650 IntervalVariable master,
const std::vector<IntervalVariable>& members) {
654 std::vector<Literal> presences;
655 std::vector<IntegerValue> sizes;
658 std::vector<LiteralWithCoeff> sat_ct;
659 for (
const IntervalVariable member : members) {
662 sat_ct.push_back({is_present, Coefficient(1)});
671 presences.push_back(is_present);
672 sizes.push_back(intervals->
MinSize(member));
681 std::vector<IntegerVariable> starts;
682 starts.reserve(members.size());
683 for (
const IntervalVariable member : members) {
684 starts.push_back(intervals->
StartVar(member));
690 std::vector<IntegerVariable> ends;
691 ends.reserve(members.size());
692 for (
const IntervalVariable member : members) {
693 ends.push_back(intervals->
EndVar(member));
703 #endif // OR_TOOLS_SAT_INTERVALS_H_