OR-Tools  8.1
intervals.cc
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #include "ortools/sat/intervals.h"
15 
16 #include <memory>
17 
18 #include "ortools/sat/integer.h"
19 #include "ortools/util/sort.h"
20 
21 namespace operations_research {
22 namespace sat {
23 
24 IntervalVariable IntervalsRepository::CreateInterval(IntegerVariable start,
25  IntegerVariable end,
26  IntegerVariable size,
27  IntegerValue fixed_size,
28  LiteralIndex is_present) {
30  size == kNoIntegerVariable
31  ? AffineExpression(fixed_size)
32  : AffineExpression(size),
33  is_present, /*add_linear_relation=*/true);
34 }
35 
37  AffineExpression end,
38  AffineExpression size,
39  LiteralIndex is_present,
40  bool add_linear_relation) {
41  // Create the interval.
42  const IntervalVariable i(starts_.size());
43  starts_.push_back(start);
44  ends_.push_back(end);
45  sizes_.push_back(size);
46  is_present_.push_back(is_present);
47 
48  std::vector<Literal> enforcement_literals;
49  if (is_present != kNoLiteralIndex) {
50  enforcement_literals.push_back(Literal(is_present));
51  }
52 
53  if (add_linear_relation) {
54  LinearConstraintBuilder builder(model_, IntegerValue(0), IntegerValue(0));
55  builder.AddTerm(Start(i), IntegerValue(1));
56  builder.AddTerm(Size(i), IntegerValue(1));
57  builder.AddTerm(End(i), IntegerValue(-1));
58  LoadConditionalLinearConstraint(enforcement_literals, builder.Build(),
59  model_);
60  }
61 
62  return i;
63 }
64 
66  const std::vector<IntervalVariable>& tasks, Model* model)
67  : trail_(model->GetOrCreate<Trail>()),
68  integer_trail_(model->GetOrCreate<IntegerTrail>()),
69  precedences_(model->GetOrCreate<PrecedencesPropagator>()) {
70  starts_.clear();
71  ends_.clear();
72  minus_ends_.clear();
73  minus_starts_.clear();
74  sizes_.clear();
75  reason_for_presence_.clear();
76 
77  auto* repository = model->GetOrCreate<IntervalsRepository>();
78  for (const IntervalVariable i : tasks) {
79  if (repository->IsOptional(i)) {
80  reason_for_presence_.push_back(repository->PresenceLiteral(i).Index());
81  } else {
82  reason_for_presence_.push_back(kNoLiteralIndex);
83  }
84  sizes_.push_back(repository->Size(i));
85  starts_.push_back(repository->Start(i));
86  ends_.push_back(repository->End(i));
87  minus_starts_.push_back(repository->Start(i).Negated());
88  minus_ends_.push_back(repository->End(i).Negated());
89  }
90 
91  RegisterWith(model->GetOrCreate<GenericLiteralWatcher>());
92  InitSortedVectors();
94 }
95 
97  Model* model)
98  : trail_(model->GetOrCreate<Trail>()),
99  integer_trail_(model->GetOrCreate<IntegerTrail>()),
100  precedences_(model->GetOrCreate<PrecedencesPropagator>()) {
101  starts_.resize(num_tasks);
102  CHECK_EQ(NumTasks(), num_tasks);
103 }
104 
106  recompute_all_cache_ = true;
107  return true;
108 }
109 
111  const std::vector<int>& watch_indices) {
112  for (const int t : watch_indices) recompute_cache_[t] = true;
113  return true;
114 }
115 
117  // If there was an Untrail before, we need to refresh the cache so that
118  // we never have value from lower in the search tree.
119  //
120  // TODO(user): We could be smarter here, but then this is not visible in our
121  // cpu_profile since we call many times IncrementalPropagate() for each new
122  // decision, but just call Propagate() once after each Untrail().
123  if (level < previous_level_) {
124  recompute_all_cache_ = true;
125  }
126  previous_level_ = level;
127 }
128 
130  const int id = watcher->Register(this);
131  const int num_tasks = starts_.size();
132  for (int t = 0; t < num_tasks; ++t) {
133  watcher->WatchIntegerVariable(sizes_[t].var, id, t);
134  watcher->WatchIntegerVariable(starts_[t].var, id, t);
135  watcher->WatchIntegerVariable(ends_[t].var, id, t);
136  }
137  watcher->SetPropagatorPriority(id, 0);
138 
139  // Note that it is important to register with the integer_trail_ so we are
140  // ALWAYS called before any propagator that depends on this helper.
141  integer_trail_->RegisterReversibleClass(this);
142 }
143 
144 void SchedulingConstraintHelper::UpdateCachedValues(int t) {
145  recompute_cache_[t] = false;
146 
147  const IntegerValue dmin = integer_trail_->LowerBound(sizes_[t]);
148  const IntegerValue smin = integer_trail_->LowerBound(starts_[t]);
149  const IntegerValue smax = integer_trail_->UpperBound(starts_[t]);
150  const IntegerValue emin = integer_trail_->LowerBound(ends_[t]);
151  const IntegerValue emax = integer_trail_->UpperBound(ends_[t]);
152 
153  cached_duration_min_[t] = dmin;
154  cached_start_min_[t] = smin;
155  cached_negated_end_max_[t] = -emax;
156 
157  // Sometimes, for optional interval with non-optional bounds, the two
158  // part of the max here is not the same. We always consider the value assuming
159  // the interval is present.
160  cached_end_min_[t] = std::max(emin, smin + dmin);
161  cached_negated_start_max_[t] = -std::min(smax, emax - dmin);
162 
163  // Note that we use the cached value here for EndMin()/StartMax().
164  const IntegerValue new_shifted_start_min = EndMin(t) - dmin;
165  if (new_shifted_start_min != cached_shifted_start_min_[t]) {
166  recompute_shifted_start_min_ = true;
167  cached_shifted_start_min_[t] = new_shifted_start_min;
168  }
169  const IntegerValue new_negated_shifted_end_max = -(StartMax(t) + dmin);
170  if (new_negated_shifted_end_max != cached_negated_shifted_end_max_[t]) {
171  recompute_negated_shifted_end_max_ = true;
172  cached_negated_shifted_end_max_[t] = new_negated_shifted_end_max;
173  }
174 }
175 
177  const SchedulingConstraintHelper& other, absl::Span<const int> tasks) {
178  current_time_direction_ = other.current_time_direction_;
179 
180  const int num_tasks = tasks.size();
181  starts_.resize(num_tasks);
182  ends_.resize(num_tasks);
183  minus_ends_.resize(num_tasks);
184  minus_starts_.resize(num_tasks);
185  sizes_.resize(num_tasks);
186  reason_for_presence_.resize(num_tasks);
187  for (int i = 0; i < num_tasks; ++i) {
188  const int t = tasks[i];
189  starts_[i] = other.starts_[t];
190  ends_[i] = other.ends_[t];
191  minus_ends_[i] = other.minus_ends_[t];
192  minus_starts_[i] = other.minus_starts_[t];
193  sizes_[i] = other.sizes_[t];
194  reason_for_presence_[i] = other.reason_for_presence_[t];
195  }
196 
197  InitSortedVectors();
199 }
200 
201 void SchedulingConstraintHelper::InitSortedVectors() {
202  const int num_tasks = starts_.size();
203 
204  recompute_all_cache_ = true;
205  recompute_cache_.resize(num_tasks, true);
206 
207  cached_shifted_start_min_.resize(num_tasks);
208  cached_negated_shifted_end_max_.resize(num_tasks);
209  cached_duration_min_.resize(num_tasks);
210  cached_start_min_.resize(num_tasks);
211  cached_end_min_.resize(num_tasks);
212  cached_negated_start_max_.resize(num_tasks);
213  cached_negated_end_max_.resize(num_tasks);
214 
215  task_by_increasing_start_min_.resize(num_tasks);
216  task_by_increasing_end_min_.resize(num_tasks);
217  task_by_decreasing_start_max_.resize(num_tasks);
218  task_by_decreasing_end_max_.resize(num_tasks);
219  task_by_increasing_shifted_start_min_.resize(num_tasks);
220  task_by_negated_shifted_end_max_.resize(num_tasks);
221  for (int t = 0; t < num_tasks; ++t) {
222  task_by_increasing_start_min_[t].task_index = t;
223  task_by_increasing_end_min_[t].task_index = t;
224  task_by_decreasing_start_max_[t].task_index = t;
225  task_by_decreasing_end_max_[t].task_index = t;
226  task_by_increasing_shifted_start_min_[t].task_index = t;
227  task_by_negated_shifted_end_max_[t].task_index = t;
228  }
229 
230  recompute_shifted_start_min_ = true;
231  recompute_negated_shifted_end_max_ = true;
232 }
233 
235  bool is_forward) {
236  if (current_time_direction_ != is_forward) {
237  current_time_direction_ = is_forward;
238 
239  std::swap(starts_, minus_ends_);
240  std::swap(ends_, minus_starts_);
241 
242  std::swap(task_by_increasing_start_min_, task_by_decreasing_end_max_);
243  std::swap(task_by_increasing_end_min_, task_by_decreasing_start_max_);
244  std::swap(task_by_increasing_shifted_start_min_,
245  task_by_negated_shifted_end_max_);
246 
247  std::swap(cached_start_min_, cached_negated_end_max_);
248  std::swap(cached_end_min_, cached_negated_start_max_);
249  std::swap(cached_shifted_start_min_, cached_negated_shifted_end_max_);
250  std::swap(recompute_shifted_start_min_, recompute_negated_shifted_end_max_);
251  }
252  if (recompute_all_cache_) {
253  for (int t = 0; t < recompute_cache_.size(); ++t) {
254  UpdateCachedValues(t);
255  }
256  } else {
257  for (int t = 0; t < recompute_cache_.size(); ++t) {
258  if (recompute_cache_[t]) UpdateCachedValues(t);
259  }
260  }
261  recompute_all_cache_ = false;
262 }
263 
264 const std::vector<TaskTime>&
266  const int num_tasks = NumTasks();
267  for (int i = 0; i < num_tasks; ++i) {
268  TaskTime& ref = task_by_increasing_start_min_[i];
269  ref.time = StartMin(ref.task_index);
270  }
271  IncrementalSort(task_by_increasing_start_min_.begin(),
272  task_by_increasing_start_min_.end());
273  return task_by_increasing_start_min_;
274 }
275 
276 const std::vector<TaskTime>&
278  const int num_tasks = NumTasks();
279  for (int i = 0; i < num_tasks; ++i) {
280  TaskTime& ref = task_by_increasing_end_min_[i];
281  ref.time = EndMin(ref.task_index);
282  }
283  IncrementalSort(task_by_increasing_end_min_.begin(),
284  task_by_increasing_end_min_.end());
285  return task_by_increasing_end_min_;
286 }
287 
288 const std::vector<TaskTime>&
290  const int num_tasks = NumTasks();
291  for (int i = 0; i < num_tasks; ++i) {
292  TaskTime& ref = task_by_decreasing_start_max_[i];
293  ref.time = StartMax(ref.task_index);
294  }
295  IncrementalSort(task_by_decreasing_start_max_.begin(),
296  task_by_decreasing_start_max_.end(),
297  std::greater<TaskTime>());
298  return task_by_decreasing_start_max_;
299 }
300 
301 const std::vector<TaskTime>&
303  const int num_tasks = NumTasks();
304  for (int i = 0; i < num_tasks; ++i) {
305  TaskTime& ref = task_by_decreasing_end_max_[i];
306  ref.time = EndMax(ref.task_index);
307  }
308  IncrementalSort(task_by_decreasing_end_max_.begin(),
309  task_by_decreasing_end_max_.end(), std::greater<TaskTime>());
310  return task_by_decreasing_end_max_;
311 }
312 
313 const std::vector<TaskTime>&
315  if (recompute_shifted_start_min_) {
316  recompute_shifted_start_min_ = false;
317  const int num_tasks = NumTasks();
318  bool is_sorted = true;
319  IntegerValue previous = kMinIntegerValue;
320  for (int i = 0; i < num_tasks; ++i) {
321  TaskTime& ref = task_by_increasing_shifted_start_min_[i];
322  ref.time = ShiftedStartMin(ref.task_index);
323  is_sorted = is_sorted && ref.time >= previous;
324  previous = ref.time;
325  }
326  if (is_sorted) return task_by_increasing_shifted_start_min_;
327  IncrementalSort(task_by_increasing_shifted_start_min_.begin(),
328  task_by_increasing_shifted_start_min_.end());
329  }
330  return task_by_increasing_shifted_start_min_;
331 }
332 
333 // Produces a relaxed reason for StartMax(before) < EndMin(after).
335  int after) {
336  AddOtherReason(before);
337  AddOtherReason(after);
338 
339  std::vector<IntegerVariable> vars;
340 
341  // Reason for StartMax(before).
342  const IntegerValue smax_before = StartMax(before);
343  if (smax_before >= integer_trail_->UpperBound(starts_[before])) {
344  if (starts_[before].var != kNoIntegerVariable) {
345  vars.push_back(NegationOf(starts_[before].var));
346  }
347  } else {
348  if (ends_[before].var != kNoIntegerVariable) {
349  vars.push_back(NegationOf(ends_[before].var));
350  }
351  if (sizes_[before].var != kNoIntegerVariable) {
352  vars.push_back(sizes_[before].var);
353  }
354  }
355 
356  // Reason for EndMin(after);
357  const IntegerValue emin_after = EndMin(after);
358  if (emin_after <= integer_trail_->LowerBound(ends_[after])) {
359  if (ends_[after].var != kNoIntegerVariable) {
360  vars.push_back(ends_[after].var);
361  }
362  } else {
363  if (starts_[after].var != kNoIntegerVariable) {
364  vars.push_back(starts_[after].var);
365  }
366  if (sizes_[after].var != kNoIntegerVariable) {
367  vars.push_back(sizes_[after].var);
368  }
369  }
370 
371  DCHECK_LT(smax_before, emin_after);
372  const IntegerValue slack = emin_after - smax_before - 1;
373  integer_trail_->AppendRelaxedLinearReason(
374  slack, std::vector<IntegerValue>(vars.size(), IntegerValue(1)), vars,
375  &integer_reason_);
376 }
377 
379  CHECK(other_helper_ == nullptr);
380  return integer_trail_->Enqueue(lit, literal_reason_, integer_reason_);
381 }
382 
384  int t, IntegerLiteral lit) {
385  if (IsAbsent(t)) return true;
386  AddOtherReason(t);
387 
388  // TODO(user): we can also push lit.var if its presence implies the interval
389  // presence.
390  if (IsOptional(t) && integer_trail_->OptionalLiteralIndex(lit.var) !=
391  reason_for_presence_[t]) {
392  if (IsPresent(t)) {
393  // We can still push, but we do need the presence reason.
395  } else {
396  // In this case we cannot push lit.var, but we may detect the interval
397  // absence.
398  if (lit.bound > integer_trail_->UpperBound(lit.var)) {
399  integer_reason_.push_back(
400  IntegerLiteral::LowerOrEqual(lit.var, lit.bound - 1));
401  if (!PushTaskAbsence(t)) return false;
402  }
403  return true;
404  }
405  }
406 
408  if (!integer_trail_->Enqueue(lit, literal_reason_, integer_reason_)) {
409  return false;
410  }
411  return true;
412 }
413 
414 // We also run directly the precedence propagator for this variable so that when
415 // we push an interval start for example, we have a chance to push its end.
416 bool SchedulingConstraintHelper::PushIntervalBound(int t, IntegerLiteral lit) {
417  if (!PushIntegerLiteralIfTaskPresent(t, lit)) return false;
418  if (IsAbsent(t)) return true;
419  if (!precedences_->PropagateOutgoingArcs(lit.var)) return false;
420  UpdateCachedValues(t);
421  return true;
422 }
423 
425  IntegerValue new_start_min) {
426  return PushIntervalBound(t, starts_[t].GreaterOrEqual(new_start_min));
427 }
428 
430  IntegerValue new_end_max) {
431  return PushIntervalBound(t, ends_[t].LowerOrEqual(new_end_max));
432 }
433 
435  DCHECK_NE(reason_for_presence_[t], kNoLiteralIndex);
436  DCHECK(!IsAbsent(t));
437 
438  AddOtherReason(t);
439 
440  if (IsPresent(t)) {
441  literal_reason_.push_back(Literal(reason_for_presence_[t]).Negated());
442  return ReportConflict();
443  }
445  integer_trail_->EnqueueLiteral(Literal(reason_for_presence_[t]).Negated(),
446  literal_reason_, integer_reason_);
447  return true;
448 }
449 
451  DCHECK_NE(reason_for_presence_[t], kNoLiteralIndex);
452  DCHECK(!IsPresent(t));
453 
454  AddOtherReason(t);
455 
456  if (IsAbsent(t)) {
457  literal_reason_.push_back(Literal(reason_for_presence_[t]));
458  return ReportConflict();
459  }
461  integer_trail_->EnqueueLiteral(Literal(reason_for_presence_[t]),
462  literal_reason_, integer_reason_);
463  return true;
464 }
465 
468  return integer_trail_->ReportConflict(literal_reason_, integer_reason_);
469 }
470 
472  GenericLiteralWatcher* watcher,
473  bool watch_start_max,
474  bool watch_end_max) const {
475  const int num_tasks = starts_.size();
476  for (int t = 0; t < num_tasks; ++t) {
477  watcher->WatchLowerBound(starts_[t], id);
478  watcher->WatchLowerBound(ends_[t], id);
479  watcher->WatchLowerBound(sizes_[t], id);
480  if (watch_start_max) {
481  watcher->WatchUpperBound(starts_[t], id);
482  }
483  if (watch_end_max) {
484  watcher->WatchUpperBound(ends_[t], id);
485  }
486  if (!IsPresent(t) && !IsAbsent(t)) {
487  watcher->WatchLiteral(Literal(reason_for_presence_[t]), id);
488  }
489  }
490 }
491 
492 void SchedulingConstraintHelper::AddOtherReason(int t) {
493  if (other_helper_ == nullptr || already_added_to_other_reasons_[t]) return;
494  already_added_to_other_reasons_[t] = true;
495  other_helper_->AddStartMaxReason(t, event_for_other_helper_);
496  other_helper_->AddEndMinReason(t, event_for_other_helper_ + 1);
497 }
498 
499 void SchedulingConstraintHelper::ImportOtherReasons() {
500  if (other_helper_ != nullptr) ImportOtherReasons(*other_helper_);
501 }
502 
503 void SchedulingConstraintHelper::ImportOtherReasons(
504  const SchedulingConstraintHelper& other_helper) {
505  literal_reason_.insert(literal_reason_.end(),
506  other_helper.literal_reason_.begin(),
507  other_helper.literal_reason_.end());
508  integer_reason_.insert(integer_reason_.end(),
509  other_helper.integer_reason_.begin(),
510  other_helper.integer_reason_.end());
511 }
512 
514  return absl::StrCat("t=", t, " is_present=", IsPresent(t),
515  " min_size=", SizeMin(t).value(), " start=[",
516  StartMin(t).value(), ",", StartMax(t).value(), "]",
517  " end=[", EndMin(t).value(), ",", EndMax(t).value(), "]");
518 }
519 
520 } // namespace sat
521 } // namespace operations_research
var
IntVar * var
Definition: expr_array.cc:1858
operations_research::sat::IntervalsRepository::CreateInterval
IntervalVariable CreateInterval(IntegerVariable start, IntegerVariable end, IntegerVariable size, IntegerValue fixed_size, LiteralIndex is_present)
Definition: intervals.cc:24
operations_research::sat::LowerBound
std::function< int64(const Model &)> LowerBound(IntegerVariable v)
Definition: integer.h:1450
operations_research::sat::GenericLiteralWatcher::Register
int Register(PropagatorInterface *propagator)
Definition: integer.cc:1910
operations_research::sat::IntervalsRepository::End
AffineExpression End(IntervalVariable i) const
Definition: intervals.h:94
operations_research::sat::SchedulingConstraintHelper::StartMin
IntegerValue StartMin(int t) const
Definition: intervals.h:228
min
int64 min
Definition: alldiff_cst.cc:138
operations_research::sat::AffineExpression
Definition: integer.h:205
DCHECK_LT
#define DCHECK_LT(val1, val2)
Definition: base/logging.h:888
operations_research::sat::IntegerTrail
Definition: integer.h:533
absl::StrongVector::push_back
void push_back(const value_type &x)
Definition: strong_vector.h:158
operations_research::sat::kNoIntegerVariable
const IntegerVariable kNoIntegerVariable(-1)
max
int64 max
Definition: alldiff_cst.cc:139
operations_research::sat::GenericLiteralWatcher::WatchLowerBound
void WatchLowerBound(IntegerVariable var, int id, int watch_index=-1)
Definition: integer.h:1356
operations_research::sat::LinearConstraintBuilder::Build
LinearConstraint Build()
Definition: linear_constraint.cc:113
operations_research::sat::SchedulingConstraintHelper::TaskByIncreasingShiftedStartMin
const std::vector< TaskTime > & TaskByIncreasingShiftedStartMin()
Definition: intervals.cc:314
operations_research::sat::SchedulingConstraintHelper::ImportOtherReasons
void ImportOtherReasons(const SchedulingConstraintHelper &other_helper)
Definition: intervals.cc:503
operations_research::sat::kNoLiteralIndex
const LiteralIndex kNoLiteralIndex(-1)
operations_research::sat::SchedulingConstraintHelper::WatchAllTasks
void WatchAllTasks(int id, GenericLiteralWatcher *watcher, bool watch_start_max=true, bool watch_end_max=true) const
Definition: intervals.cc:471
operations_research::sat::SchedulingConstraintHelper::EndMin
IntegerValue EndMin(int t) const
Definition: intervals.h:229
operations_research::sat::SchedulingConstraintHelper::SetLevel
void SetLevel(int level) final
Definition: intervals.cc:116
value
int64 value
Definition: demon_profiler.cc:43
operations_research::sat::SchedulingConstraintHelper::IsOptional
bool IsOptional(int t) const
Definition: intervals.h:449
operations_research::sat::SchedulingConstraintHelper::TaskByDecreasingEndMax
const std::vector< TaskTime > & TaskByDecreasingEndMax()
Definition: intervals.cc:302
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::sat::IntegerTrail::EnqueueLiteral
void EnqueueLiteral(Literal literal, absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
Definition: integer.cc:1058
operations_research::sat::NegationOf
std::vector< IntegerVariable > NegationOf(const std::vector< IntegerVariable > &vars)
Definition: integer.cc:27
operations_research::sat::IntegerTrail::OptionalLiteralIndex
LiteralIndex OptionalLiteralIndex(IntegerVariable i) const
Definition: integer.h:627
operations_research::sat::SchedulingConstraintHelper::EndMax
IntegerValue EndMax(int t) const
Definition: intervals.h:231
operations_research::sat::IntervalsRepository::Start
AffineExpression Start(IntervalVariable i) const
Definition: intervals.h:93
operations_research::sat::SchedulingConstraintHelper::TaskByDecreasingStartMax
const std::vector< TaskTime > & TaskByDecreasingStartMax()
Definition: intervals.cc:289
operations_research::sat::SchedulingConstraintHelper::RegisterWith
void RegisterWith(GenericLiteralWatcher *watcher)
Definition: intervals.cc:129
operations_research::sat::SchedulingConstraintHelper::TaskByIncreasingStartMin
const std::vector< TaskTime > & TaskByIncreasingStartMin()
Definition: intervals.cc:265
operations_research::sat::LinearConstraintBuilder::AddTerm
void AddTerm(IntegerVariable var, IntegerValue coeff)
Definition: linear_constraint.cc:22
operations_research::sat::SchedulingConstraintHelper::ShiftedStartMin
IntegerValue ShiftedStartMin(int t) const
Definition: intervals.h:247
operations_research::sat::GenericLiteralWatcher
Definition: integer.h:1091
DCHECK_NE
#define DCHECK_NE(val1, val2)
Definition: base/logging.h:886
operations_research::sat::IntegerLiteral::var
IntegerVariable var
Definition: integer.h:189
operations_research::sat::SchedulingConstraintHelper::DecreaseEndMax
ABSL_MUST_USE_RESULT bool DecreaseEndMax(int t, IntegerValue new_start_max)
Definition: intervals.cc:429
operations_research::sat::IntegerTrail::AppendRelaxedLinearReason
void AppendRelaxedLinearReason(IntegerValue slack, absl::Span< const IntegerValue > coeffs, absl::Span< const IntegerVariable > vars, std::vector< IntegerLiteral > *reason) const
Definition: integer.cc:807
operations_research::sat::TaskTime
Definition: intervals.h:159
operations_research::sat::SchedulingConstraintHelper::ReportConflict
ABSL_MUST_USE_RESULT bool ReportConflict()
Definition: intervals.cc:466
operations_research::sat::LinearConstraintBuilder
Definition: linear_constraint.h:87
operations_research::sat::GenericLiteralWatcher::SetPropagatorPriority
void SetPropagatorPriority(int id, int priority)
Definition: integer.cc:1933
operations_research::sat::SchedulingConstraintHelper
Definition: intervals.h:172
operations_research::sat::TaskTime::time
IntegerValue time
Definition: intervals.h:161
operations_research::sat::IntegerTrail::UpperBound
IntegerValue UpperBound(IntegerVariable i) const
Definition: integer.h:1287
operations_research::sat::SchedulingConstraintHelper::StartMax
IntegerValue StartMax(int t) const
Definition: intervals.h:230
operations_research::sat::IntegerTrail::Enqueue
ABSL_MUST_USE_RESULT bool Enqueue(IntegerLiteral i_lit, absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
Definition: integer.cc:989
operations_research::sat::PrecedencesPropagator
Definition: precedences.h:51
intervals.h
operations_research::IncrementalSort
void IncrementalSort(int max_comparisons, Iterator begin, Iterator end, Compare comp=Compare{}, bool is_stable=false)
Definition: sort.h:46
CHECK_EQ
#define CHECK_EQ(val1, val2)
Definition: base/logging.h:697
operations_research::sat::SchedulingConstraintHelper::IsAbsent
bool IsAbsent(int t) const
Definition: intervals.h:458
operations_research::sat::IntegerTrail::RegisterReversibleClass
void RegisterReversibleClass(ReversibleInterface *rev)
Definition: integer.h:816
operations_research::sat::Model
Class that owns everything related to a particular optimization model.
Definition: sat/model.h:38
operations_research::sat::SchedulingConstraintHelper::PushTaskPresence
ABSL_MUST_USE_RESULT bool PushTaskPresence(int t)
Definition: intervals.cc:450
operations_research::sat::IntegerLiteral::bound
IntegerValue bound
Definition: integer.h:190
operations_research::sat::SchedulingConstraintHelper::NumTasks
int NumTasks() const
Definition: intervals.h:202
operations_research::sat::SchedulingConstraintHelper::AddReasonForBeingBefore
void AddReasonForBeingBefore(int before, int after)
Definition: intervals.cc:334
operations_research::sat::IntegerLiteral
Definition: integer.h:153
operations_research::sat::LowerOrEqual
std::function< void(Model *)> LowerOrEqual(IntegerVariable v, int64 ub)
Definition: integer.h:1492
operations_research::sat::GenericLiteralWatcher::WatchIntegerVariable
void WatchIntegerVariable(IntegerVariable i, int id, int watch_index=-1)
Definition: integer.h:1380
operations_research::sat::SchedulingConstraintHelper::Propagate
bool Propagate() final
Definition: intervals.cc:105
DCHECK
#define DCHECK(condition)
Definition: base/logging.h:884
operations_research::sat::SchedulingConstraintHelper::AddStartMaxReason
void AddStartMaxReason(int t, IntegerValue upper_bound)
Definition: intervals.h:513
operations_research::sat::SchedulingConstraintHelper::SynchronizeAndSetTimeDirection
void SynchronizeAndSetTimeDirection(bool is_forward)
Definition: intervals.cc:234
operations_research::sat::IntegerLiteral::LowerOrEqual
static IntegerLiteral LowerOrEqual(IntegerVariable i, IntegerValue bound)
Definition: integer.h:1253
operations_research::sat::SchedulingConstraintHelper::SchedulingConstraintHelper
SchedulingConstraintHelper(const std::vector< IntervalVariable > &tasks, Model *model)
Definition: intervals.cc:65
model
GRBmodel * model
Definition: gurobi_interface.cc:269
operations_research::sat::Literal
Definition: sat_base.h:64
operations_research::sat::SchedulingConstraintHelper::IncreaseStartMin
ABSL_MUST_USE_RESULT bool IncreaseStartMin(int t, IntegerValue new_start_min)
Definition: intervals.cc:424
operations_research::sat::SchedulingConstraintHelper::ResetFromSubset
void ResetFromSubset(const SchedulingConstraintHelper &other, absl::Span< const int > tasks)
Definition: intervals.cc:176
sort.h
operations_research::sat::IntervalsRepository::Size
AffineExpression Size(IntervalVariable i) const
Definition: intervals.h:92
operations_research::sat::SchedulingConstraintHelper::SizeMin
IntegerValue SizeMin(int t) const
Definition: intervals.h:223
operations_research::sat::GenericLiteralWatcher::WatchLiteral
void WatchLiteral(Literal l, int id, int watch_index=-1)
Definition: integer.h:1348
operations_research::sat::IntegerTrail::ReportConflict
bool ReportConflict(absl::Span< const Literal > literal_reason, absl::Span< const IntegerLiteral > integer_reason)
Definition: integer.h:793
operations_research::sat::kMinIntegerValue
constexpr IntegerValue kMinIntegerValue(-kMaxIntegerValue)
operations_research::sat::GreaterOrEqual
std::function< void(Model *)> GreaterOrEqual(IntegerVariable v, int64 lb)
Definition: integer.h:1478
operations_research::sat::SchedulingConstraintHelper::IsPresent
bool IsPresent(int t) const
Definition: intervals.h:453
operations_research::sat::IntervalsRepository
Definition: intervals.h:45
operations_research::sat::TaskTime::task_index
int task_index
Definition: intervals.h:160
operations_research::sat::SchedulingConstraintHelper::TaskDebugString
std::string TaskDebugString(int t) const
Definition: intervals.cc:513
operations_research::sat::SchedulingConstraintHelper::AddEndMinReason
void AddEndMinReason(int t, IntegerValue lower_bound)
Definition: intervals.h:535
operations_research::sat::SchedulingConstraintHelper::PushTaskAbsence
ABSL_MUST_USE_RESULT bool PushTaskAbsence(int t)
Definition: intervals.cc:434
operations_research::sat::IntegerTrail::LowerBound
IntegerValue LowerBound(IntegerVariable i) const
Definition: integer.h:1283
operations_research::sat::LoadConditionalLinearConstraint
void LoadConditionalLinearConstraint(const absl::Span< const Literal > enforcement_literals, const LinearConstraint &cst, Model *model)
Definition: integer_expr.h:572
operations_research::sat::PrecedencesPropagator::PropagateOutgoingArcs
bool PropagateOutgoingArcs(IntegerVariable var)
Definition: precedences.cc:95
operations_research::sat::SchedulingConstraintHelper::TaskByIncreasingEndMin
const std::vector< TaskTime > & TaskByIncreasingEndMin()
Definition: intervals.cc:277
CHECK
#define CHECK(condition)
Definition: base/logging.h:495
operations_research::sat::SchedulingConstraintHelper::IncrementalPropagate
bool IncrementalPropagate(const std::vector< int > &watch_indices) final
Definition: intervals.cc:110
integer.h
operations_research::sat::GenericLiteralWatcher::WatchUpperBound
void WatchUpperBound(IntegerVariable var, int id, int watch_index=-1)
Definition: integer.h:1374
operations_research::sat::Trail
Definition: sat_base.h:233
operations_research::sat::SchedulingConstraintHelper::AddPresenceReason
void AddPresenceReason(int t)
Definition: intervals.h:472
operations_research::sat::SchedulingConstraintHelper::PushIntegerLiteral
ABSL_MUST_USE_RESULT bool PushIntegerLiteral(IntegerLiteral lit)
Definition: intervals.cc:378
operations_research::sat::SchedulingConstraintHelper::PushIntegerLiteralIfTaskPresent
ABSL_MUST_USE_RESULT bool PushIntegerLiteralIfTaskPresent(int t, IntegerLiteral lit)
Definition: intervals.cc:383