20#include "absl/strings/str_cat.h"
21#include "absl/strings/str_format.h"
22#include "absl/strings/string_view.h"
23#include "absl/types/span.h"
31#pragma warning(disable : 4351 4355 4804 4805)
52 std::numeric_limits<int64_t>::max() >> 2;
56enum IntervalField { START, DURATION, END };
58IntervalVar* NullInterval() {
return nullptr; }
61class MirrorIntervalVar :
public IntervalVar {
63 MirrorIntervalVar(Solver*
const s, IntervalVar*
const t)
64 : IntervalVar(s,
"Mirror<" + t->
name() +
">"), t_(t) {}
67 MirrorIntervalVar(
const MirrorIntervalVar&) =
delete;
68 MirrorIntervalVar& operator=(
const MirrorIntervalVar&) =
delete;
69 ~MirrorIntervalVar()
override {}
73 int64_t StartMin()
const override {
return -t_->EndMax(); }
74 int64_t StartMax()
const override {
return -t_->EndMin(); }
75 void SetStartMin(int64_t m)
override { t_->SetEndMax(-m); }
76 void SetStartMax(int64_t m)
override { t_->SetEndMin(-m); }
77 void SetStartRange(int64_t mi, int64_t ma)
override {
78 t_->SetEndRange(-ma, -mi);
80 int64_t OldStartMin()
const override {
return -t_->OldEndMax(); }
81 int64_t OldStartMax()
const override {
return -t_->OldEndMin(); }
82 void WhenStartRange(Demon*
const d)
override { t_->WhenEndRange(d); }
83 void WhenStartBound(Demon*
const d)
override { t_->WhenEndBound(d); }
86 int64_t DurationMin()
const override {
return t_->DurationMin(); }
87 int64_t DurationMax()
const override {
return t_->DurationMax(); }
88 void SetDurationMin(int64_t m)
override { t_->SetDurationMin(m); }
89 void SetDurationMax(int64_t m)
override { t_->SetDurationMax(m); }
90 void SetDurationRange(int64_t mi, int64_t ma)
override {
91 t_->SetDurationRange(mi, ma);
93 int64_t OldDurationMin()
const override {
return t_->OldDurationMin(); }
94 int64_t OldDurationMax()
const override {
return t_->OldDurationMax(); }
95 void WhenDurationRange(Demon*
const d)
override { t_->WhenDurationRange(d); }
96 void WhenDurationBound(Demon*
const d)
override { t_->WhenDurationBound(d); }
99 int64_t EndMin()
const override {
return -t_->StartMax(); }
100 int64_t EndMax()
const override {
return -t_->StartMin(); }
101 void SetEndMin(int64_t m)
override { t_->SetStartMax(-m); }
102 void SetEndMax(int64_t m)
override { t_->SetStartMin(-m); }
103 void SetEndRange(int64_t mi, int64_t ma)
override {
104 t_->SetStartRange(-ma, -mi);
106 int64_t OldEndMin()
const override {
return -t_->OldStartMax(); }
107 int64_t OldEndMax()
const override {
return -t_->OldStartMin(); }
108 void WhenEndRange(Demon*
const d)
override { t_->WhenStartRange(d); }
109 void WhenEndBound(Demon*
const d)
override { t_->WhenStartBound(d); }
113 bool MustBePerformed()
const override {
return t_->MustBePerformed(); }
114 bool MayBePerformed()
const override {
return t_->MayBePerformed(); }
115 void SetPerformed(
bool val)
override { t_->SetPerformed(val); }
116 bool WasPerformedBound()
const override {
return t_->WasPerformedBound(); }
117 void WhenPerformedBound(Demon*
const d)
override {
118 t_->WhenPerformedBound(d);
121 void Accept(ModelVisitor*
const visitor)
const override {
125 std::string DebugString()
const override {
126 return absl::StrFormat(
"MirrorInterval(%s)", t_->DebugString());
129 IntExpr* StartExpr()
override {
130 return solver()->MakeOpposite(t_->EndExpr());
132 IntExpr* DurationExpr()
override {
return t_->DurationExpr(); }
133 IntExpr* EndExpr()
override {
134 return solver()->MakeOpposite(t_->StartExpr());
136 IntExpr* PerformedExpr()
override {
return t_->PerformedExpr(); }
140 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
141 return solver()->MakeOpposite(t_->SafeEndExpr(-unperformed_value));
143 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
144 return t_->SafeDurationExpr(unperformed_value);
146 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
147 return solver()->MakeOpposite(t_->SafeStartExpr(-unperformed_value));
151 IntervalVar*
const t_;
170class AlwaysPerformedIntervalVarWrapper :
public IntervalVar {
172 explicit AlwaysPerformedIntervalVarWrapper(IntervalVar*
const t)
173 : IntervalVar(t->solver(),
174 absl::StrFormat(
"AlwaysPerformed<%s>", t->
name())),
176 start_expr_(nullptr),
177 duration_expr_(nullptr),
178 end_expr_(nullptr) {}
181 AlwaysPerformedIntervalVarWrapper(
const AlwaysPerformedIntervalVarWrapper&) =
183 AlwaysPerformedIntervalVarWrapper& operator=(
184 const AlwaysPerformedIntervalVarWrapper&) =
delete;
186 ~AlwaysPerformedIntervalVarWrapper()
override {}
187 int64_t StartMin()
const override {
188 return MayUnderlyingBePerformed() ? t_->StartMin() : kMinValidValue;
190 int64_t StartMax()
const override {
191 return MayUnderlyingBePerformed() ? t_->StartMax() : kMaxValidValue;
193 void SetStartMin(int64_t m)
override { t_->SetStartMin(m); }
194 void SetStartMax(int64_t m)
override { t_->SetStartMax(m); }
195 void SetStartRange(int64_t mi, int64_t ma)
override {
196 t_->SetStartRange(mi, ma);
198 int64_t OldStartMin()
const override {
199 return MayUnderlyingBePerformed() ? t_->OldStartMin() : kMinValidValue;
201 int64_t OldStartMax()
const override {
202 return MayUnderlyingBePerformed() ? t_->OldStartMax() : kMaxValidValue;
204 void WhenStartRange(Demon*
const d)
override { t_->WhenStartRange(d); }
205 void WhenStartBound(Demon*
const d)
override { t_->WhenStartBound(d); }
206 int64_t DurationMin()
const override {
207 return MayUnderlyingBePerformed() ? t_->DurationMin() : 0LL;
209 int64_t DurationMax()
const override {
210 return MayUnderlyingBePerformed() ? t_->DurationMax() : 0LL;
212 void SetDurationMin(int64_t m)
override { t_->SetDurationMin(m); }
213 void SetDurationMax(int64_t m)
override { t_->SetDurationMax(m); }
214 void SetDurationRange(int64_t mi, int64_t ma)
override {
215 t_->SetDurationRange(mi, ma);
217 int64_t OldDurationMin()
const override {
218 return MayUnderlyingBePerformed() ? t_->OldDurationMin() : 0LL;
220 int64_t OldDurationMax()
const override {
221 return MayUnderlyingBePerformed() ? t_->OldDurationMax() : 0LL;
223 void WhenDurationRange(Demon*
const d)
override { t_->WhenDurationRange(d); }
224 void WhenDurationBound(Demon*
const d)
override { t_->WhenDurationBound(d); }
225 int64_t EndMin()
const override {
226 return MayUnderlyingBePerformed() ? t_->EndMin() : kMinValidValue;
228 int64_t EndMax()
const override {
229 return MayUnderlyingBePerformed() ? t_->EndMax() : kMaxValidValue;
231 void SetEndMin(int64_t m)
override { t_->SetEndMin(m); }
232 void SetEndMax(int64_t m)
override { t_->SetEndMax(m); }
233 void SetEndRange(int64_t mi, int64_t ma)
override { t_->SetEndRange(mi, ma); }
234 int64_t OldEndMin()
const override {
235 return MayUnderlyingBePerformed() ? t_->OldEndMin() : kMinValidValue;
237 int64_t OldEndMax()
const override {
238 return MayUnderlyingBePerformed() ? t_->OldEndMax() : kMaxValidValue;
240 void WhenEndRange(Demon*
const d)
override { t_->WhenEndRange(d); }
241 void WhenEndBound(Demon*
const d)
override { t_->WhenEndBound(d); }
242 bool MustBePerformed()
const override {
return true; }
243 bool MayBePerformed()
const override {
return true; }
244 void SetPerformed(
bool val)
override {
253 bool WasPerformedBound()
const override {
return true; }
254 void WhenPerformedBound(Demon*
const d)
override {
255 t_->WhenPerformedBound(d);
257 IntExpr* StartExpr()
override {
258 if (start_expr_ ==
nullptr) {
259 solver()->SaveValue(
reinterpret_cast<void**
>(&start_expr_));
264 IntExpr* DurationExpr()
override {
265 if (duration_expr_ ==
nullptr) {
266 solver()->SaveValue(
reinterpret_cast<void**
>(&duration_expr_));
269 return duration_expr_;
271 IntExpr* EndExpr()
override {
272 if (end_expr_ ==
nullptr) {
273 solver()->SaveValue(
reinterpret_cast<void**
>(&end_expr_));
278 IntExpr* PerformedExpr()
override {
return solver()->MakeIntConst(1); }
279 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
282 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
283 return DurationExpr();
285 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
return EndExpr(); }
288 IntervalVar* underlying()
const {
return t_; }
289 bool MayUnderlyingBePerformed()
const {
290 return underlying()->MayBePerformed();
294 IntervalVar*
const t_;
295 IntExpr* start_expr_;
296 IntExpr* duration_expr_;
313class IntervalVarRelaxedMax :
public AlwaysPerformedIntervalVarWrapper {
315 explicit IntervalVarRelaxedMax(IntervalVar*
const t)
316 : AlwaysPerformedIntervalVarWrapper(t) {}
317 ~IntervalVarRelaxedMax()
override {}
318 int64_t StartMax()
const override {
320 return underlying()->MustBePerformed() ? underlying()->StartMax()
321 : (kMaxValidValue - DurationMin());
323 void SetStartMax(int64_t m)
override {
325 <<
"Calling SetStartMax on a IntervalVarRelaxedMax is not supported, "
326 <<
"as it seems there is no legitimate use case.";
328 int64_t EndMax()
const override {
329 return underlying()->MustBePerformed() ? underlying()->EndMax()
332 void SetEndMax(int64_t m)
override {
334 <<
"Calling SetEndMax on a IntervalVarRelaxedMax is not supported, "
335 <<
"as it seems there is no legitimate use case.";
338 void Accept(ModelVisitor*
const visitor)
const override {
343 std::string DebugString()
const override {
344 return absl::StrFormat(
"IntervalVarRelaxedMax(%s)",
345 underlying()->DebugString());
363class IntervalVarRelaxedMin :
public AlwaysPerformedIntervalVarWrapper {
365 explicit IntervalVarRelaxedMin(IntervalVar*
const t)
366 : AlwaysPerformedIntervalVarWrapper(t) {}
367 ~IntervalVarRelaxedMin()
override {}
368 int64_t StartMin()
const override {
369 return underlying()->MustBePerformed() ? underlying()->StartMin()
372 void SetStartMin(int64_t m)
override {
374 <<
"Calling SetStartMin on a IntervalVarRelaxedMin is not supported, "
375 <<
"as it seems there is no legitimate use case.";
377 int64_t EndMin()
const override {
379 return underlying()->MustBePerformed() ? underlying()->EndMin()
380 : (kMinValidValue + DurationMin());
382 void SetEndMin(int64_t m)
override {
384 <<
"Calling SetEndMin on a IntervalVarRelaxedMin is not supported, "
385 <<
"as it seems there is no legitimate use case.";
388 void Accept(ModelVisitor*
const visitor)
const override {
393 std::string DebugString()
const override {
394 return absl::StrFormat(
"IntervalVarRelaxedMin(%s)",
395 underlying()->DebugString());
401class BaseIntervalVar :
public IntervalVar {
403 class Handler :
public Demon {
405 explicit Handler(BaseIntervalVar*
const var) : var_(
var) {}
406 ~Handler()
override {}
407 void Run(Solver*
const s)
override { var_->Process(); }
411 std::string DebugString()
const override {
412 return absl::StrFormat(
"Handler(%s)", var_->DebugString());
416 BaseIntervalVar*
const var_;
419 BaseIntervalVar(Solver*
const s,
const std::string&
name)
420 : IntervalVar(s,
name),
423 cleaner_([this](Solver* s) { CleanInProcess(); }) {}
425 ~BaseIntervalVar()
override {}
427 virtual void Process() = 0;
429 virtual void Push() = 0;
431 void CleanInProcess() { in_process_ =
false; }
433 std::string BaseName()
const override {
return "IntervalVar"; }
435 bool InProcess()
const {
return in_process_; }
443class RangeVar :
public IntExpr {
445 RangeVar(Solver*
const s, BaseIntervalVar*
var, int64_t mi, int64_t ma)
454 cast_var_(
nullptr) {}
456 ~RangeVar()
override {}
458 bool Bound()
const override {
return min_.Value() == max_.Value(); }
460 int64_t Min()
const override {
return min_.Value(); }
462 int64_t Max()
const override {
return max_.Value(); }
464 void SetMin(int64_t m)
override {
466 if (m <= min_.Value()) {
470 if (m > max_.Value()) {
471 var_->SetPerformed(
false);
474 if (var_->InProcess()) {
476 if (m > postponed_max_) {
477 var_->SetPerformed(
false);
479 if (m > postponed_min_) {
484 SyncPreviousBounds();
485 min_.SetValue(solver(), m);
490 int64_t OldMin()
const {
491 DCHECK(var_->InProcess());
492 return previous_min_;
495 void SetMax(int64_t m)
override {
496 if (m >= max_.Value()) {
499 if (m < min_.Value()) {
500 var_->SetPerformed(
false);
503 if (var_->InProcess()) {
505 if (m < postponed_min_) {
506 var_->SetPerformed(
false);
508 if (m < postponed_max_) {
513 SyncPreviousBounds();
514 max_.SetValue(solver(), m);
519 int64_t OldMax()
const {
return previous_min_; }
521 void SetRange(int64_t mi, int64_t ma)
override {
522 if (mi <= min_.Value() && ma >= max_.Value()) {
526 if (mi > max_.Value() || ma < min_.Value() || mi > ma) {
527 var_->SetPerformed(
false);
529 if (var_->InProcess()) {
530 if (mi > postponed_max_ || ma < postponed_min_) {
531 var_->SetPerformed(
false);
533 if (mi > postponed_min_) {
536 if (ma < postponed_max_) {
541 SyncPreviousBounds();
542 if (mi > min_.Value()) {
543 min_.SetValue(solver(), mi);
545 if (ma < max_.Value()) {
546 max_.SetValue(solver(), ma);
552 void WhenRange(Demon*
const demon)
override {
555 delayed_range_demons_.PushIfNotTop(solver(),
558 range_demons_.PushIfNotTop(solver(), solver()->
RegisterDemon(demon));
563 virtual void WhenBound(Demon*
const demon) {
566 delayed_bound_demons_.PushIfNotTop(solver(),
569 bound_demons_.PushIfNotTop(solver(), solver()->
RegisterDemon(demon));
574 void UpdatePostponedBounds() {
575 postponed_min_ = min_.Value();
576 postponed_max_ = max_.Value();
579 void ProcessDemons() {
581 ExecuteAll(bound_demons_);
582 EnqueueAll(delayed_bound_demons_);
584 if (min_.Value() != previous_min_ || max_.Value() != previous_max_) {
585 ExecuteAll(range_demons_);
586 EnqueueAll(delayed_range_demons_);
590 void UpdatePreviousBounds() {
591 previous_min_ = min_.Value();
592 previous_max_ = max_.Value();
596 void ApplyPostponedBounds(IntervalField which) {
597 if (min_.Value() < postponed_min_ || max_.Value() > postponed_max_) {
600 var_->SetStartRange(std::max(postponed_min_, min_.Value()),
601 std::min(postponed_max_, max_.Value()));
604 var_->SetDurationRange(std::max(postponed_min_, min_.Value()),
605 std::min(postponed_max_, max_.Value()));
608 var_->SetEndRange(std::max(postponed_min_, min_.Value()),
609 std::min(postponed_max_, max_.Value()));
615 IntVar* Var()
override {
616 if (cast_var_ ==
nullptr) {
617 solver()->SaveValue(
reinterpret_cast<void**
>(&cast_var_));
618 cast_var_ = solver()->MakeIntVar(min_.Value(), max_.Value());
624 std::string DebugString()
const override {
625 std::string out = absl::StrCat(min_.Value());
627 absl::StrAppendFormat(&out,
" .. %d", max_.Value());
639 void SyncPreviousBounds() {
640 if (previous_min_ > min_.Value()) {
641 previous_min_ = min_.Value();
643 if (previous_max_ < max_.Value()) {
644 previous_max_ = max_.Value();
649 NumericalRev<int64_t> min_;
650 NumericalRev<int64_t> max_;
651 BaseIntervalVar*
const var_;
654 int64_t postponed_min_;
655 int64_t postponed_max_;
658 int64_t previous_min_;
659 int64_t previous_max_;
661 SimpleRevFIFO<Demon*> bound_demons_;
662 SimpleRevFIFO<Demon*> delayed_bound_demons_;
664 SimpleRevFIFO<Demon*> range_demons_;
665 SimpleRevFIFO<Demon*> delayed_range_demons_;
671class PerformedVar :
public BooleanVar {
674 PerformedVar(Solver*
const s, BaseIntervalVar*
const var,
bool optional)
677 previous_value_(
optional ? kUnboundBooleanVarValue : 1),
678 postponed_value_(
optional ? kUnboundBooleanVarValue : 1) {
684 PerformedVar(Solver*
const s, BaseIntervalVar*
var)
685 : BooleanVar(s,
""), var_(
var), previous_value_(0), postponed_value_(0) {
689 ~PerformedVar()
override {}
691 void SetValue(int64_t v)
override {
692 if ((v & 0xfffffffffffffffe) != 0 ||
693 (value_ != kUnboundBooleanVarValue && v != value_)) {
696 if (var_->InProcess()) {
697 if (postponed_value_ != kUnboundBooleanVarValue &&
698 v != postponed_value_) {
701 postponed_value_ = v;
703 }
else if (value_ == kUnboundBooleanVarValue) {
704 previous_value_ = kUnboundBooleanVarValue;
706 value_ =
static_cast<int>(v);
711 int64_t OldMin()
const override {
return previous_value_ == 1; }
713 int64_t OldMax()
const override {
return previous_value_ != 0; }
715 void RestoreValue()
override {
716 previous_value_ = kUnboundBooleanVarValue;
717 value_ = kUnboundBooleanVarValue;
718 postponed_value_ = kUnboundBooleanVarValue;
722 if (previous_value_ != value_) {
723 ExecuteAll(bound_demons_);
724 EnqueueAll(delayed_bound_demons_);
728 void UpdatePostponedValue() { postponed_value_ = value_; }
730 void UpdatePreviousValueAndApplyPostponedValue() {
731 previous_value_ = value_;
732 if (value_ != postponed_value_) {
733 DCHECK_NE(kUnboundBooleanVarValue, postponed_value_);
734 SetValue(postponed_value_);
738 std::string DebugString()
const override {
750 BaseIntervalVar*
const var_;
752 int postponed_value_;
757class FixedDurationIntervalVar :
public BaseIntervalVar {
761 const std::string&
name);
763 FixedDurationIntervalVar(Solver* s,
const std::string&
name);
764 ~FixedDurationIntervalVar()
override {}
766 int64_t StartMin()
const override;
767 int64_t StartMax()
const override;
768 void SetStartMin(int64_t m)
override;
769 void SetStartMax(int64_t m)
override;
770 void SetStartRange(int64_t mi, int64_t ma)
override;
771 int64_t OldStartMin()
const override {
return start_.OldMin(); }
772 int64_t OldStartMax()
const override {
return start_.OldMax(); }
773 void WhenStartRange(Demon*
const d)
override {
774 if (performed_.Max() == 1) {
778 void WhenStartBound(Demon*
const d)
override {
779 if (performed_.Max() == 1) {
784 int64_t DurationMin()
const override;
785 int64_t DurationMax()
const override;
786 void SetDurationMin(int64_t m)
override;
787 void SetDurationMax(int64_t m)
override;
788 void SetDurationRange(int64_t mi, int64_t ma)
override;
789 int64_t OldDurationMin()
const override {
return duration_; }
790 int64_t OldDurationMax()
const override {
return duration_; }
791 void WhenDurationRange(Demon*
const d)
override {}
792 void WhenDurationBound(Demon*
const d)
override {}
794 int64_t EndMin()
const override;
795 int64_t EndMax()
const override;
796 void SetEndMin(int64_t m)
override;
797 void SetEndMax(int64_t m)
override;
798 void SetEndRange(int64_t mi, int64_t ma)
override;
799 int64_t OldEndMin()
const override {
800 return CapAdd(OldStartMin(), duration_);
802 int64_t OldEndMax()
const override {
803 return CapAdd(OldStartMax(), duration_);
805 void WhenEndRange(Demon*
const d)
override { WhenStartRange(d); }
806 void WhenEndBound(Demon*
const d)
override { WhenStartBound(d); }
808 bool MustBePerformed()
const override;
809 bool MayBePerformed()
const override;
810 void SetPerformed(
bool val)
override;
811 bool WasPerformedBound()
const override {
812 return performed_.OldMin() == performed_.OldMax();
814 void WhenPerformedBound(Demon*
const d)
override { performed_.WhenBound(d); }
815 void Process()
override;
816 std::string DebugString()
const override;
818 void Accept(ModelVisitor*
const visitor)
const override {
819 visitor->VisitIntervalVariable(
this,
"", 0, NullInterval());
822 IntExpr* StartExpr()
override {
return &start_; }
823 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
824 IntExpr* EndExpr()
override {
825 return solver()->MakeSum(StartExpr(), duration_);
827 IntExpr* PerformedExpr()
override {
return &performed_; }
828 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
831 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
834 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
838 void Push()
override;
843 PerformedVar performed_;
846FixedDurationIntervalVar::FixedDurationIntervalVar(
849 : BaseIntervalVar(s,
name),
854FixedDurationIntervalVar::FixedDurationIntervalVar(Solver*
const s,
855 const std::string&
name)
856 : BaseIntervalVar(s,
name),
857 start_(s, this, 0, 0),
859 performed_(s, this) {}
861void FixedDurationIntervalVar::Process() {
864 start_.UpdatePostponedBounds();
865 performed_.UpdatePostponedValue();
867 if (performed_.Max() == 1) {
868 start_.ProcessDemons();
870 performed_.Process();
871 reset_action_on_fail();
873 start_.UpdatePreviousBounds();
874 start_.ApplyPostponedBounds(START);
875 performed_.UpdatePreviousValueAndApplyPostponedValue();
878int64_t FixedDurationIntervalVar::StartMin()
const {
879 CHECK_EQ(performed_.Max(), 1);
883int64_t FixedDurationIntervalVar::StartMax()
const {
884 CHECK_EQ(performed_.Max(), 1);
888void FixedDurationIntervalVar::SetStartMin(int64_t m) {
889 if (performed_.Max() == 1) {
894void FixedDurationIntervalVar::SetStartMax(int64_t m) {
895 if (performed_.Max() == 1) {
900void FixedDurationIntervalVar::SetStartRange(int64_t mi, int64_t ma) {
901 if (performed_.Max() == 1) {
902 start_.SetRange(mi, ma);
906int64_t FixedDurationIntervalVar::DurationMin()
const {
907 CHECK_EQ(performed_.Max(), 1);
911int64_t FixedDurationIntervalVar::DurationMax()
const {
912 CHECK_EQ(performed_.Max(), 1);
916void FixedDurationIntervalVar::SetDurationMin(int64_t m) {
922void FixedDurationIntervalVar::SetDurationMax(int64_t m) {
928void FixedDurationIntervalVar::SetDurationRange(int64_t mi, int64_t ma) {
929 if (mi > duration_ || ma < duration_ || mi > ma) {
934int64_t FixedDurationIntervalVar::EndMin()
const {
935 CHECK_EQ(performed_.Max(), 1);
936 return start_.Min() + duration_;
939int64_t FixedDurationIntervalVar::EndMax()
const {
940 CHECK_EQ(performed_.Max(), 1);
941 return CapAdd(start_.Max(), duration_);
944void FixedDurationIntervalVar::SetEndMin(int64_t m) {
945 SetStartMin(
CapSub(m, duration_));
948void FixedDurationIntervalVar::SetEndMax(int64_t m) {
949 SetStartMax(
CapSub(m, duration_));
952void FixedDurationIntervalVar::SetEndRange(int64_t mi, int64_t ma) {
953 SetStartRange(
CapSub(mi, duration_),
CapSub(ma, duration_));
956bool FixedDurationIntervalVar::MustBePerformed()
const {
957 return (performed_.Min() == 1);
960bool FixedDurationIntervalVar::MayBePerformed()
const {
961 return (performed_.Max() == 1);
964void FixedDurationIntervalVar::SetPerformed(
bool val) {
965 performed_.SetValue(val);
968void FixedDurationIntervalVar::Push() {
974std::string FixedDurationIntervalVar::DebugString()
const {
975 const std::string& var_name =
name();
976 if (performed_.Max() == 0) {
977 if (!var_name.empty()) {
978 return absl::StrFormat(
"%s(performed = false)", var_name);
980 return "IntervalVar(performed = false)";
984 if (!var_name.empty()) {
985 out = var_name +
"(start = ";
987 out =
"IntervalVar(start = ";
989 absl::StrAppendFormat(&out,
"%s, duration = %d, performed = %s)",
990 start_.DebugString(), duration_,
991 performed_.DebugString());
998class FixedDurationPerformedIntervalVar :
public BaseIntervalVar {
1000 FixedDurationPerformedIntervalVar(Solver* s, int64_t
start_min,
1002 const std::string&
name);
1004 FixedDurationPerformedIntervalVar(Solver* s,
const std::string&
name);
1005 ~FixedDurationPerformedIntervalVar()
override {}
1007 int64_t StartMin()
const override;
1008 int64_t StartMax()
const override;
1009 void SetStartMin(int64_t m)
override;
1010 void SetStartMax(int64_t m)
override;
1011 void SetStartRange(int64_t mi, int64_t ma)
override;
1012 int64_t OldStartMin()
const override {
return start_.OldMin(); }
1013 int64_t OldStartMax()
const override {
return start_.OldMax(); }
1014 void WhenStartRange(Demon*
const d)
override { start_.WhenRange(d); }
1015 void WhenStartBound(Demon*
const d)
override { start_.WhenBound(d); }
1017 int64_t DurationMin()
const override;
1018 int64_t DurationMax()
const override;
1019 void SetDurationMin(int64_t m)
override;
1020 void SetDurationMax(int64_t m)
override;
1021 void SetDurationRange(int64_t mi, int64_t ma)
override;
1022 int64_t OldDurationMin()
const override {
return duration_; }
1023 int64_t OldDurationMax()
const override {
return duration_; }
1024 void WhenDurationRange(Demon*
const d)
override {}
1025 void WhenDurationBound(Demon*
const d)
override {}
1027 int64_t EndMin()
const override;
1028 int64_t EndMax()
const override;
1029 void SetEndMin(int64_t m)
override;
1030 void SetEndMax(int64_t m)
override;
1031 void SetEndRange(int64_t mi, int64_t ma)
override;
1032 int64_t OldEndMin()
const override {
1033 return CapAdd(OldStartMin(), duration_);
1035 int64_t OldEndMax()
const override {
1036 return CapAdd(OldStartMax(), duration_);
1038 void WhenEndRange(Demon*
const d)
override { WhenStartRange(d); }
1039 void WhenEndBound(Demon*
const d)
override { WhenEndRange(d); }
1041 bool MustBePerformed()
const override;
1042 bool MayBePerformed()
const override;
1043 void SetPerformed(
bool val)
override;
1044 bool WasPerformedBound()
const override {
return true; }
1045 void WhenPerformedBound(Demon*
const d)
override {}
1046 void Process()
override;
1047 std::string DebugString()
const override;
1049 void Accept(ModelVisitor*
const visitor)
const override {
1050 visitor->VisitIntervalVariable(
this,
"", 0, NullInterval());
1053 IntExpr* StartExpr()
override {
return &start_; }
1054 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
1055 IntExpr* EndExpr()
override {
1056 return solver()->MakeSum(StartExpr(), duration_);
1058 IntExpr* PerformedExpr()
override {
return solver()->MakeIntConst(1); }
1059 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
1062 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
1063 return DurationExpr();
1065 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
return EndExpr(); }
1068 void CheckOldPerformed() {}
1069 void Push()
override;
1075FixedDurationPerformedIntervalVar::FixedDurationPerformedIntervalVar(
1077 const std::string&
name)
1078 : BaseIntervalVar(s,
name),
1080 duration_(duration) {}
1082FixedDurationPerformedIntervalVar::FixedDurationPerformedIntervalVar(
1083 Solver*
const s,
const std::string&
name)
1084 : BaseIntervalVar(s,
name), start_(s, this, 0, 0), duration_(0) {}
1086void FixedDurationPerformedIntervalVar::Process() {
1089 start_.UpdatePostponedBounds();
1091 start_.ProcessDemons();
1092 reset_action_on_fail();
1094 start_.UpdatePreviousBounds();
1095 start_.ApplyPostponedBounds(START);
1098int64_t FixedDurationPerformedIntervalVar::StartMin()
const {
1099 return start_.Min();
1102int64_t FixedDurationPerformedIntervalVar::StartMax()
const {
1103 return start_.Max();
1106void FixedDurationPerformedIntervalVar::SetStartMin(int64_t m) {
1110void FixedDurationPerformedIntervalVar::SetStartMax(int64_t m) {
1114void FixedDurationPerformedIntervalVar::SetStartRange(int64_t mi, int64_t ma) {
1115 start_.SetRange(mi, ma);
1118int64_t FixedDurationPerformedIntervalVar::DurationMin()
const {
1122int64_t FixedDurationPerformedIntervalVar::DurationMax()
const {
1126void FixedDurationPerformedIntervalVar::SetDurationMin(int64_t m) {
1127 if (m > duration_) {
1128 SetPerformed(
false);
1132void FixedDurationPerformedIntervalVar::SetDurationMax(int64_t m) {
1133 if (m < duration_) {
1134 SetPerformed(
false);
1137int64_t FixedDurationPerformedIntervalVar::EndMin()
const {
1138 return CapAdd(start_.Min(), duration_);
1141int64_t FixedDurationPerformedIntervalVar::EndMax()
const {
1142 return CapAdd(start_.Max(), duration_);
1145void FixedDurationPerformedIntervalVar::SetEndMin(int64_t m) {
1146 SetStartMin(
CapSub(m, duration_));
1149void FixedDurationPerformedIntervalVar::SetEndMax(int64_t m) {
1150 SetStartMax(
CapSub(m, duration_));
1153void FixedDurationPerformedIntervalVar::SetEndRange(int64_t mi, int64_t ma) {
1154 SetStartRange(
CapSub(mi, duration_),
CapSub(ma, duration_));
1157void FixedDurationPerformedIntervalVar::SetDurationRange(int64_t mi,
1159 if (mi > duration_ || ma < duration_ || mi > ma) {
1160 SetPerformed(
false);
1164bool FixedDurationPerformedIntervalVar::MustBePerformed()
const {
return true; }
1166bool FixedDurationPerformedIntervalVar::MayBePerformed()
const {
return true; }
1168void FixedDurationPerformedIntervalVar::SetPerformed(
bool val) {
1174void FixedDurationPerformedIntervalVar::Push() {
1180std::string FixedDurationPerformedIntervalVar::DebugString()
const {
1182 const std::string& var_name =
name();
1183 if (!var_name.empty()) {
1184 out = var_name +
"(start = ";
1186 out =
"IntervalVar(start = ";
1188 absl::StrAppendFormat(&out,
"%s, duration = %d, performed = true)",
1189 start_.DebugString(), duration_);
1195class StartVarPerformedIntervalVar :
public IntervalVar {
1197 StartVarPerformedIntervalVar(Solver* s, IntVar*
var, int64_t duration,
1198 const std::string&
name);
1199 ~StartVarPerformedIntervalVar()
override {}
1201 int64_t StartMin()
const override;
1202 int64_t StartMax()
const override;
1203 void SetStartMin(int64_t m)
override;
1204 void SetStartMax(int64_t m)
override;
1205 void SetStartRange(int64_t mi, int64_t ma)
override;
1206 int64_t OldStartMin()
const override {
return start_var_->OldMin(); }
1207 int64_t OldStartMax()
const override {
return start_var_->OldMax(); }
1208 void WhenStartRange(Demon*
const d)
override { start_var_->WhenRange(d); }
1209 void WhenStartBound(Demon*
const d)
override { start_var_->WhenBound(d); }
1211 int64_t DurationMin()
const override;
1212 int64_t DurationMax()
const override;
1213 void SetDurationMin(int64_t m)
override;
1214 void SetDurationMax(int64_t m)
override;
1215 void SetDurationRange(int64_t mi, int64_t ma)
override;
1216 int64_t OldDurationMin()
const override {
return duration_; }
1217 int64_t OldDurationMax()
const override {
return duration_; }
1218 void WhenDurationRange(Demon*
const d)
override {}
1219 void WhenDurationBound(Demon*
const d)
override {}
1221 int64_t EndMin()
const override;
1222 int64_t EndMax()
const override;
1223 void SetEndMin(int64_t m)
override;
1224 void SetEndMax(int64_t m)
override;
1225 void SetEndRange(int64_t mi, int64_t ma)
override;
1226 int64_t OldEndMin()
const override {
1227 return CapAdd(OldStartMin(), duration_);
1229 int64_t OldEndMax()
const override {
1230 return CapAdd(OldStartMax(), duration_);
1232 void WhenEndRange(Demon*
const d)
override { start_var_->WhenRange(d); }
1233 void WhenEndBound(Demon*
const d)
override { start_var_->WhenBound(d); }
1235 bool MustBePerformed()
const override;
1236 bool MayBePerformed()
const override;
1237 void SetPerformed(
bool val)
override;
1238 bool WasPerformedBound()
const override {
return true; }
1239 void WhenPerformedBound(Demon*
const d)
override {}
1240 std::string DebugString()
const override;
1242 IntExpr* StartExpr()
override {
return start_var_; }
1243 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
1244 IntExpr* EndExpr()
override {
1245 return solver()->MakeSum(start_var_, duration_);
1247 IntExpr* PerformedExpr()
override {
return solver()->MakeIntConst(1); }
1248 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
1251 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
1252 return DurationExpr();
1254 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
return EndExpr(); }
1256 void Accept(ModelVisitor*
const visitor)
const override {
1257 visitor->VisitIntervalVariable(
this,
"", 0, NullInterval());
1261 IntVar*
const start_var_;
1266StartVarPerformedIntervalVar::StartVarPerformedIntervalVar(
1267 Solver*
const s, IntVar*
const var, int64_t duration,
1268 const std::string&
name)
1269 : IntervalVar(s,
name), start_var_(
var), duration_(duration) {}
1271int64_t StartVarPerformedIntervalVar::StartMin()
const {
1272 return start_var_->Min();
1275int64_t StartVarPerformedIntervalVar::StartMax()
const {
1276 return start_var_->Max();
1279void StartVarPerformedIntervalVar::SetStartMin(int64_t m) {
1280 start_var_->SetMin(m);
1283void StartVarPerformedIntervalVar::SetStartMax(int64_t m) {
1284 start_var_->SetMax(m);
1287void StartVarPerformedIntervalVar::SetStartRange(int64_t mi, int64_t ma) {
1288 start_var_->SetRange(mi, ma);
1291int64_t StartVarPerformedIntervalVar::DurationMin()
const {
return duration_; }
1293int64_t StartVarPerformedIntervalVar::DurationMax()
const {
return duration_; }
1295void StartVarPerformedIntervalVar::SetDurationMin(int64_t m) {
1296 if (m > duration_) {
1301void StartVarPerformedIntervalVar::SetDurationMax(int64_t m) {
1302 if (m < duration_) {
1306int64_t StartVarPerformedIntervalVar::EndMin()
const {
1307 return start_var_->Min() + duration_;
1310int64_t StartVarPerformedIntervalVar::EndMax()
const {
1311 return start_var_->Max() + duration_;
1314void StartVarPerformedIntervalVar::SetEndMin(int64_t m) {
1315 SetStartMin(
CapSub(m, duration_));
1318void StartVarPerformedIntervalVar::SetEndMax(int64_t m) {
1319 SetStartMax(
CapSub(m, duration_));
1322void StartVarPerformedIntervalVar::SetEndRange(int64_t mi, int64_t ma) {
1323 SetStartRange(
CapSub(mi, duration_),
CapSub(ma, duration_));
1326void StartVarPerformedIntervalVar::SetDurationRange(int64_t mi, int64_t ma) {
1327 if (mi > duration_ || ma < duration_ || mi > ma) {
1332bool StartVarPerformedIntervalVar::MustBePerformed()
const {
return true; }
1334bool StartVarPerformedIntervalVar::MayBePerformed()
const {
return true; }
1336void StartVarPerformedIntervalVar::SetPerformed(
bool val) {
1342std::string StartVarPerformedIntervalVar::DebugString()
const {
1344 const std::string& var_name =
name();
1345 if (!var_name.empty()) {
1346 out = var_name +
"(start = ";
1348 out =
"IntervalVar(start = ";
1350 absl::StrAppendFormat(&out,
"%d", start_var_->Min());
1351 if (!start_var_->Bound()) {
1352 absl::StrAppendFormat(&out,
" .. %d", start_var_->Max());
1355 absl::StrAppendFormat(&out,
", duration = %d, performed = true)", duration_);
1361class StartVarIntervalVar :
public BaseIntervalVar {
1363 StartVarIntervalVar(Solver* s, IntVar*
start, int64_t duration,
1365 ~StartVarIntervalVar()
override {}
1367 int64_t StartMin()
const override;
1368 int64_t StartMax()
const override;
1369 void SetStartMin(int64_t m)
override;
1370 void SetStartMax(int64_t m)
override;
1371 void SetStartRange(int64_t mi, int64_t ma)
override;
1372 int64_t OldStartMin()
const override {
return start_->OldMin(); }
1373 int64_t OldStartMax()
const override {
return start_->OldMax(); }
1374 void WhenStartRange(Demon*
const d)
override {
1375 if (performed_->Max() == 1) {
1376 start_->WhenRange(d);
1379 void WhenStartBound(Demon*
const d)
override {
1380 if (performed_->Max() == 1) {
1381 start_->WhenBound(d);
1385 int64_t DurationMin()
const override;
1386 int64_t DurationMax()
const override;
1387 void SetDurationMin(int64_t m)
override;
1388 void SetDurationMax(int64_t m)
override;
1389 void SetDurationRange(int64_t mi, int64_t ma)
override;
1390 int64_t OldDurationMin()
const override {
return duration_; }
1391 int64_t OldDurationMax()
const override {
return duration_; }
1392 void WhenDurationRange(Demon*
const d)
override {}
1393 void WhenDurationBound(Demon*
const d)
override {}
1395 int64_t EndMin()
const override;
1396 int64_t EndMax()
const override;
1397 void SetEndMin(int64_t m)
override;
1398 void SetEndMax(int64_t m)
override;
1399 void SetEndRange(int64_t mi, int64_t ma)
override;
1400 int64_t OldEndMin()
const override {
1401 return CapAdd(OldStartMin(), duration_);
1403 int64_t OldEndMax()
const override {
1404 return CapAdd(OldStartMax(), duration_);
1406 void WhenEndRange(Demon*
const d)
override { WhenStartRange(d); }
1407 void WhenEndBound(Demon*
const d)
override { WhenStartBound(d); }
1409 bool MustBePerformed()
const override;
1410 bool MayBePerformed()
const override;
1411 void SetPerformed(
bool val)
override;
1412 bool WasPerformedBound()
const override {
1413 return performed_->OldMin() == performed_->OldMax();
1415 void WhenPerformedBound(Demon*
const d)
override { performed_->WhenBound(d); }
1416 std::string DebugString()
const override;
1418 void Accept(ModelVisitor*
const visitor)
const override {
1419 visitor->VisitIntervalVariable(
this,
"", 0, NullInterval());
1422 IntExpr* StartExpr()
override {
return start_; }
1423 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
1424 IntExpr* EndExpr()
override {
1425 return solver()->MakeSum(StartExpr(), duration_);
1427 IntExpr* PerformedExpr()
override {
return performed_; }
1428 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
1431 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
1434 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
1438 void Process()
override { LOG(FATAL) <<
"Should not be here"; }
1440 void Push()
override { LOG(FATAL) <<
"Should not be here"; }
1442 int64_t StoredMin()
const {
return start_min_.Value(); }
1443 int64_t StoredMax()
const {
return start_max_.Value(); }
1446 IntVar*
const start_;
1448 IntVar*
const performed_;
1449 Rev<int64_t> start_min_;
1450 Rev<int64_t> start_max_;
1453StartVarIntervalVar::StartVarIntervalVar(Solver*
const s, IntVar*
const start,
1456 const std::string&
name)
1457 : BaseIntervalVar(s,
name),
1459 duration_(duration),
1461 start_min_(
start->Min()),
1462 start_max_(
start->Max()) {}
1464int64_t StartVarIntervalVar::StartMin()
const {
1465 DCHECK_EQ(performed_->Max(), 1);
1466 return std::max(start_->Min(), start_min_.Value());
1469int64_t StartVarIntervalVar::StartMax()
const {
1470 DCHECK_EQ(performed_->Max(), 1);
1471 return std::min(start_->Max(), start_max_.Value());
1474void StartVarIntervalVar::SetStartMin(int64_t m) {
1475 if (performed_->Min() == 1) {
1478 start_min_.SetValue(solver(), std::max(m, start_min_.Value()));
1479 if (start_min_.Value() > std::min(start_max_.Value(), start_->Max())) {
1480 performed_->SetValue(0);
1485void StartVarIntervalVar::SetStartMax(int64_t m) {
1486 if (performed_->Min() == 1) {
1489 start_max_.SetValue(solver(), std::min(m, start_max_.Value()));
1490 if (start_max_.Value() < std::max(start_min_.Value(), start_->Min())) {
1491 performed_->SetValue(0);
1496void StartVarIntervalVar::SetStartRange(int64_t mi, int64_t ma) {
1497 if (performed_->Min() == 1) {
1498 start_->SetRange(mi, ma);
1500 start_min_.SetValue(solver(), std::max(mi, start_min_.Value()));
1501 start_max_.SetValue(solver(), std::min(ma, start_max_.Value()));
1502 if (std::max(start_min_.Value(), start_->Min()) >
1503 std::min(start_max_.Value(), start_->Max())) {
1504 performed_->SetValue(0);
1509int64_t StartVarIntervalVar::DurationMin()
const {
1510 DCHECK_EQ(performed_->Max(), 1);
1514int64_t StartVarIntervalVar::DurationMax()
const {
1515 DCHECK_EQ(performed_->Max(), 1);
1519void StartVarIntervalVar::SetDurationMin(int64_t m) {
1520 if (m > duration_) {
1521 SetPerformed(
false);
1525void StartVarIntervalVar::SetDurationMax(int64_t m) {
1526 if (m < duration_) {
1527 SetPerformed(
false);
1531void StartVarIntervalVar::SetDurationRange(int64_t mi, int64_t ma) {
1532 if (mi > duration_ || ma < duration_ || mi > ma) {
1533 SetPerformed(
false);
1537int64_t StartVarIntervalVar::EndMin()
const {
1538 DCHECK_EQ(performed_->Max(), 1);
1539 return CapAdd(StartMin(), duration_);
1542int64_t StartVarIntervalVar::EndMax()
const {
1543 DCHECK_EQ(performed_->Max(), 1);
1544 return CapAdd(StartMax(), duration_);
1547void StartVarIntervalVar::SetEndMin(int64_t m) {
1548 SetStartMin(
CapSub(m, duration_));
1551void StartVarIntervalVar::SetEndMax(int64_t m) {
1552 SetStartMax(
CapSub(m, duration_));
1555void StartVarIntervalVar::SetEndRange(int64_t mi, int64_t ma) {
1556 SetStartRange(
CapSub(mi, duration_),
CapSub(ma, duration_));
1559bool StartVarIntervalVar::MustBePerformed()
const {
1560 return (performed_->Min() == 1);
1563bool StartVarIntervalVar::MayBePerformed()
const {
1564 return (performed_->Max() == 1);
1567void StartVarIntervalVar::SetPerformed(
bool val) {
1568 const bool was_bound = performed_->Bound();
1569 performed_->SetValue(val);
1570 if (val && !was_bound) {
1571 start_->SetRange(start_min_.Value(), start_max_.Value());
1575std::string StartVarIntervalVar::DebugString()
const {
1576 const std::string& var_name =
name();
1577 if (performed_->Max() == 0) {
1578 if (!var_name.empty()) {
1579 return absl::StrFormat(
"%s(performed = false)", var_name);
1581 return "IntervalVar(performed = false)";
1585 if (!var_name.empty()) {
1586 out = var_name +
"(start = ";
1588 out =
"IntervalVar(start = ";
1590 absl::StrAppendFormat(&out,
"%s, duration = %d, performed = %s)",
1591 start_->DebugString(), duration_,
1592 performed_->DebugString());
1597class LinkStartVarIntervalVar :
public Constraint {
1599 LinkStartVarIntervalVar(Solver*
const solver,
1600 StartVarIntervalVar*
const interval,
1602 : Constraint(solver),
1607 ~LinkStartVarIntervalVar()
override {}
1609 void Post()
override {
1611 solver(),
this, &LinkStartVarIntervalVar::PerformedBound,
1613 performed_->WhenBound(demon);
1616 void InitialPropagate()
override {
1617 if (performed_->Bound()) {
1622 void PerformedBound() {
1623 if (performed_->Min() == 1) {
1624 start_->SetRange(interval_->StoredMin(), interval_->StoredMax());
1629 StartVarIntervalVar*
const interval_;
1630 IntVar*
const start_;
1631 IntVar*
const performed_;
1636class FixedInterval :
public IntervalVar {
1638 FixedInterval(Solver* s, int64_t
start, int64_t duration,
1639 const std::string&
name);
1640 ~FixedInterval()
override {}
1642 int64_t StartMin()
const override {
return start_; }
1643 int64_t StartMax()
const override {
return start_; }
1644 void SetStartMin(int64_t m)
override;
1645 void SetStartMax(int64_t m)
override;
1646 void SetStartRange(int64_t mi, int64_t ma)
override;
1647 int64_t OldStartMin()
const override {
return start_; }
1648 int64_t OldStartMax()
const override {
return start_; }
1649 void WhenStartRange(Demon*
const d)
override {}
1650 void WhenStartBound(Demon*
const d)
override {}
1652 int64_t DurationMin()
const override {
return duration_; }
1653 int64_t DurationMax()
const override {
return duration_; }
1654 void SetDurationMin(int64_t m)
override;
1655 void SetDurationMax(int64_t m)
override;
1656 void SetDurationRange(int64_t mi, int64_t ma)
override;
1657 int64_t OldDurationMin()
const override {
return duration_; }
1658 int64_t OldDurationMax()
const override {
return duration_; }
1659 void WhenDurationRange(Demon*
const d)
override {}
1660 void WhenDurationBound(Demon*
const d)
override {}
1662 int64_t EndMin()
const override {
return start_ + duration_; }
1663 int64_t EndMax()
const override {
return start_ + duration_; }
1664 void SetEndMin(int64_t m)
override;
1665 void SetEndMax(int64_t m)
override;
1666 void SetEndRange(int64_t mi, int64_t ma)
override;
1667 int64_t OldEndMin()
const override {
return start_ + duration_; }
1668 int64_t OldEndMax()
const override {
return start_ + duration_; }
1669 void WhenEndRange(Demon*
const d)
override {}
1670 void WhenEndBound(Demon*
const d)
override {}
1672 bool MustBePerformed()
const override {
return true; }
1673 bool MayBePerformed()
const override {
return true; }
1674 void SetPerformed(
bool val)
override;
1675 bool WasPerformedBound()
const override {
return true; }
1676 void WhenPerformedBound(Demon*
const d)
override {}
1677 std::string DebugString()
const override;
1679 void Accept(ModelVisitor*
const visitor)
const override {
1680 visitor->VisitIntervalVariable(
this,
"", 0, NullInterval());
1683 IntExpr* StartExpr()
override {
return solver()->MakeIntConst(start_); }
1684 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
1685 IntExpr* EndExpr()
override {
1686 return solver()->MakeIntConst(start_ + duration_);
1688 IntExpr* PerformedExpr()
override {
return solver()->MakeIntConst(1); }
1689 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
1692 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
1693 return DurationExpr();
1695 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
return EndExpr(); }
1698 const int64_t start_;
1699 const int64_t duration_;
1702FixedInterval::FixedInterval(Solver*
const s, int64_t
start, int64_t duration,
1703 const std::string&
name)
1704 : IntervalVar(s,
name), start_(
start), duration_(duration) {}
1706void FixedInterval::SetStartMin(int64_t m) {
1712void FixedInterval::SetStartMax(int64_t m) {
1718void FixedInterval::SetStartRange(int64_t mi, int64_t ma) {
1719 if (mi > start_ || ma < start_) {
1724void FixedInterval::SetDurationMin(int64_t m) {
1725 if (m > duration_) {
1730void FixedInterval::SetDurationMax(int64_t m) {
1731 if (m < duration_) {
1736void FixedInterval::SetEndMin(int64_t m) {
1737 if (m > start_ + duration_) {
1742void FixedInterval::SetEndMax(int64_t m) {
1743 if (m < start_ + duration_) {
1748void FixedInterval::SetEndRange(int64_t mi, int64_t ma) {
1749 if (mi > start_ + duration_ || ma < start_ + duration_) {
1754void FixedInterval::SetDurationRange(int64_t mi, int64_t ma) {
1755 if (mi > duration_ || ma < duration_) {
1760void FixedInterval::SetPerformed(
bool val) {
1766std::string FixedInterval::DebugString()
const {
1768 const std::string& var_name =
name();
1769 if (!var_name.empty()) {
1770 out = var_name +
"(start = ";
1772 out =
"IntervalVar(start = ";
1774 absl::StrAppendFormat(&out,
"%d, duration = %d, performed = true)", start_,
1781class VariableDurationIntervalVar :
public BaseIntervalVar {
1783 VariableDurationIntervalVar(Solver*
const s, int64_t
start_min,
1784 int64_t
start_max, int64_t duration_min,
1785 int64_t duration_max, int64_t
end_min,
1787 const std::string&
name)
1788 : BaseIntervalVar(s,
name),
1797 ~VariableDurationIntervalVar()
override {}
1799 int64_t StartMin()
const override {
1800 CHECK_EQ(performed_.Max(), 1);
1801 return start_.Min();
1804 int64_t StartMax()
const override {
1805 CHECK_EQ(performed_.Max(), 1);
1806 return start_.Max();
1809 void SetStartMin(int64_t m)
override {
1810 if (performed_.Max() == 1) {
1815 void SetStartMax(int64_t m)
override {
1816 if (performed_.Max() == 1) {
1821 void SetStartRange(int64_t mi, int64_t ma)
override {
1822 if (performed_.Max() == 1) {
1823 start_.SetRange(mi, ma);
1827 int64_t OldStartMin()
const override {
1828 CHECK_EQ(performed_.Max(), 1);
1830 return start_.OldMin();
1833 int64_t OldStartMax()
const override {
1834 CHECK_EQ(performed_.Max(), 1);
1836 return start_.OldMax();
1839 void WhenStartRange(Demon*
const d)
override {
1840 if (performed_.Max() == 1) {
1841 start_.WhenRange(d);
1845 void WhenStartBound(Demon*
const d)
override {
1846 if (performed_.Max() == 1) {
1847 start_.WhenBound(d);
1851 int64_t DurationMin()
const override {
1852 CHECK_EQ(performed_.Max(), 1);
1853 return duration_.Min();
1856 int64_t DurationMax()
const override {
1857 CHECK_EQ(performed_.Max(), 1);
1858 return duration_.Max();
1861 void SetDurationMin(int64_t m)
override {
1862 if (performed_.Max() == 1) {
1863 duration_.SetMin(m);
1867 void SetDurationMax(int64_t m)
override {
1868 if (performed_.Max() == 1) {
1869 duration_.SetMax(m);
1873 void SetDurationRange(int64_t mi, int64_t ma)
override {
1874 if (performed_.Max() == 1) {
1875 duration_.SetRange(mi, ma);
1879 int64_t OldDurationMin()
const override {
1880 CHECK_EQ(performed_.Max(), 1);
1882 return duration_.OldMin();
1885 int64_t OldDurationMax()
const override {
1886 CHECK_EQ(performed_.Max(), 1);
1888 return duration_.OldMax();
1891 void WhenDurationRange(Demon*
const d)
override {
1892 if (performed_.Max() == 1) {
1893 duration_.WhenRange(d);
1897 void WhenDurationBound(Demon*
const d)
override {
1898 if (performed_.Max() == 1) {
1899 duration_.WhenBound(d);
1903 int64_t EndMin()
const override {
1904 CHECK_EQ(performed_.Max(), 1);
1908 int64_t EndMax()
const override {
1909 CHECK_EQ(performed_.Max(), 1);
1913 void SetEndMin(int64_t m)
override {
1914 if (performed_.Max() == 1) {
1919 void SetEndMax(int64_t m)
override {
1920 if (performed_.Max() == 1) {
1925 void SetEndRange(int64_t mi, int64_t ma)
override {
1926 if (performed_.Max() == 1) {
1927 end_.SetRange(mi, ma);
1931 int64_t OldEndMin()
const override {
1932 CHECK_EQ(performed_.Max(), 1);
1933 DCHECK(in_process_);
1934 return end_.OldMin();
1937 int64_t OldEndMax()
const override {
1938 CHECK_EQ(performed_.Max(), 1);
1939 DCHECK(in_process_);
1940 return end_.OldMax();
1943 void WhenEndRange(Demon*
const d)
override {
1944 if (performed_.Max() == 1) {
1949 void WhenEndBound(Demon*
const d)
override {
1950 if (performed_.Max() == 1) {
1955 bool MustBePerformed()
const override {
return (performed_.Min() == 1); }
1957 bool MayBePerformed()
const override {
return (performed_.Max() == 1); }
1959 void SetPerformed(
bool val)
override { performed_.SetValue(val); }
1961 bool WasPerformedBound()
const override {
1963 return performed_.OldMin() == performed_.OldMax();
1966 void WhenPerformedBound(Demon*
const d)
override { performed_.WhenBound(d); }
1968 void Process()
override {
1969 CHECK(!in_process_);
1971 start_.UpdatePostponedBounds();
1972 duration_.UpdatePostponedBounds();
1973 end_.UpdatePostponedBounds();
1974 performed_.UpdatePostponedValue();
1976 if (performed_.Max() == 1) {
1977 start_.ProcessDemons();
1978 duration_.ProcessDemons();
1979 end_.ProcessDemons();
1981 performed_.Process();
1982 reset_action_on_fail();
1985 start_.UpdatePreviousBounds();
1986 start_.ApplyPostponedBounds(START);
1987 duration_.UpdatePreviousBounds();
1988 duration_.ApplyPostponedBounds(DURATION);
1989 end_.UpdatePreviousBounds();
1990 end_.ApplyPostponedBounds(END);
1991 performed_.UpdatePreviousValueAndApplyPostponedValue();
1994 std::string DebugString()
const override {
1995 const std::string& var_name =
name();
1996 if (performed_.Max() != 1) {
1997 if (!var_name.empty()) {
1998 return absl::StrFormat(
"%s(performed = false)", var_name);
2000 return "IntervalVar(performed = false)";
2004 if (!var_name.empty()) {
2005 out = var_name +
"(start = ";
2007 out =
"IntervalVar(start = ";
2010 absl::StrAppendFormat(&out,
2011 "%s, duration = %s, end = %s, performed = %s)",
2012 start_.DebugString(), duration_.DebugString(),
2013 end_.DebugString(), performed_.DebugString());
2018 void Accept(ModelVisitor*
const visitor)
const override {
2019 visitor->VisitIntervalVariable(
this,
"", 0, NullInterval());
2022 IntExpr* StartExpr()
override {
return &start_; }
2023 IntExpr* DurationExpr()
override {
return &duration_; }
2024 IntExpr* EndExpr()
override {
return &end_; }
2025 IntExpr* PerformedExpr()
override {
return &performed_; }
2026 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
2029 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
2032 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
2037 void Push()
override {
2038 DCHECK(!in_process_);
2039 if (performed_.Max() == 1) {
2043 start_.SetRange(
CapSub(end_.Min(), duration_.Max()),
2044 CapSub(end_.Max(), duration_.Min()));
2045 duration_.SetRange(
CapSub(end_.Min(), start_.Max()),
2046 CapSub(end_.Max(), start_.Min()));
2047 end_.SetRange(
CapAdd(start_.Min(), duration_.Min()),
2048 CapAdd(start_.Max(), duration_.Max()));
2050 EnqueueVar(&handler_);
2051 DCHECK(!in_process_);
2057 PerformedVar performed_;
2062class FixedDurationSyncedIntervalVar :
public IntervalVar {
2064 FixedDurationSyncedIntervalVar(IntervalVar*
const t, int64_t duration,
2065 int64_t offset,
const std::string&
name)
2066 : IntervalVar(t->solver(),
name),
2068 duration_(duration),
2072 FixedDurationSyncedIntervalVar(
const FixedDurationSyncedIntervalVar&) =
2074 FixedDurationSyncedIntervalVar& operator=(
2075 const FixedDurationSyncedIntervalVar&) =
delete;
2076 ~FixedDurationSyncedIntervalVar()
override {}
2077 int64_t DurationMin()
const override {
return duration_; }
2078 int64_t DurationMax()
const override {
return duration_; }
2079 void SetDurationMin(int64_t m)
override {
2080 if (m > duration_) {
2084 void SetDurationMax(int64_t m)
override {
2085 if (m < duration_) {
2089 void SetDurationRange(int64_t mi, int64_t ma)
override {
2090 if (mi > duration_ || ma < duration_ || mi > ma) {
2094 int64_t OldDurationMin()
const override {
return duration_; }
2095 int64_t OldDurationMax()
const override {
return duration_; }
2096 void WhenDurationRange(Demon*
const d)
override {}
2097 void WhenDurationBound(Demon*
const d)
override {}
2098 int64_t EndMin()
const override {
return CapAdd(StartMin(), duration_); }
2099 int64_t EndMax()
const override {
return CapAdd(StartMax(), duration_); }
2100 void SetEndMin(int64_t m)
override { SetStartMin(
CapSub(m, duration_)); }
2101 void SetEndMax(int64_t m)
override { SetStartMax(
CapSub(m, duration_)); }
2102 void SetEndRange(int64_t mi, int64_t ma)
override {
2103 SetStartRange(
CapSub(mi, duration_),
CapSub(ma, duration_));
2105 int64_t OldEndMin()
const override {
2106 return CapAdd(OldStartMin(), duration_);
2108 int64_t OldEndMax()
const override {
2109 return CapAdd(OldStartMax(), duration_);
2111 void WhenEndRange(Demon*
const d)
override { WhenStartRange(d); }
2112 void WhenEndBound(Demon*
const d)
override { WhenStartBound(d); }
2113 bool MustBePerformed()
const override {
return t_->MustBePerformed(); }
2114 bool MayBePerformed()
const override {
return t_->MayBePerformed(); }
2115 void SetPerformed(
bool val)
override { t_->SetPerformed(val); }
2116 bool WasPerformedBound()
const override {
return t_->WasPerformedBound(); }
2117 void WhenPerformedBound(Demon*
const d)
override {
2118 t_->WhenPerformedBound(d);
2122 IntervalVar*
const t_;
2123 const int64_t duration_;
2124 const int64_t offset_;
2129class FixedDurationIntervalVarStartSyncedOnStart
2130 :
public FixedDurationSyncedIntervalVar {
2132 FixedDurationIntervalVarStartSyncedOnStart(IntervalVar*
const t,
2133 int64_t duration, int64_t offset)
2134 : FixedDurationSyncedIntervalVar(
2135 t, duration, offset,
2137 "IntervalStartSyncedOnStart(%s, duration = %d, offset = %d)",
2138 t->name(), duration, offset)) {}
2139 ~FixedDurationIntervalVarStartSyncedOnStart()
override {}
2140 int64_t StartMin()
const override {
return CapAdd(t_->StartMin(), offset_); }
2141 int64_t StartMax()
const override {
return CapAdd(t_->StartMax(), offset_); }
2142 void SetStartMin(int64_t m)
override { t_->SetStartMin(
CapSub(m, offset_)); }
2143 void SetStartMax(int64_t m)
override { t_->SetStartMax(
CapSub(m, offset_)); }
2144 void SetStartRange(int64_t mi, int64_t ma)
override {
2145 t_->SetStartRange(
CapSub(mi, offset_),
CapSub(ma, offset_));
2147 int64_t OldStartMin()
const override {
2148 return CapAdd(t_->OldStartMin(), offset_);
2150 int64_t OldStartMax()
const override {
2151 return CapAdd(t_->OldStartMax(), offset_);
2153 void WhenStartRange(Demon*
const d)
override { t_->WhenStartRange(d); }
2154 void WhenStartBound(Demon*
const d)
override { t_->WhenStartBound(d); }
2155 IntExpr* StartExpr()
override {
2156 return solver()->MakeSum(t_->StartExpr(), offset_);
2158 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
2159 IntExpr* EndExpr()
override {
2160 return solver()->MakeSum(t_->StartExpr(), offset_ + duration_);
2162 IntExpr* PerformedExpr()
override {
return t_->PerformedExpr(); }
2166 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
2169 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
2172 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
2175 void Accept(ModelVisitor*
const visitor)
const override {
2176 visitor->VisitIntervalVariable(
2177 this, ModelVisitor::kStartSyncOnStartOperation, offset_, t_);
2179 std::string DebugString()
const override {
2180 return absl::StrFormat(
2181 "IntervalStartSyncedOnStart(%s, duration = %d, offset = %d)",
2182 t_->DebugString(), duration_, offset_);
2188class FixedDurationIntervalVarStartSyncedOnEnd
2189 :
public FixedDurationSyncedIntervalVar {
2191 FixedDurationIntervalVarStartSyncedOnEnd(IntervalVar*
const t,
2192 int64_t duration, int64_t offset)
2193 : FixedDurationSyncedIntervalVar(
2194 t, duration, offset,
2196 "IntervalStartSyncedOnEnd(%s, duration = %d, offset = %d)",
2197 t->
name(), duration, offset)) {}
2198 ~FixedDurationIntervalVarStartSyncedOnEnd()
override {}
2199 int64_t StartMin()
const override {
return CapAdd(t_->EndMin(), offset_); }
2200 int64_t StartMax()
const override {
return CapAdd(t_->EndMax(), offset_); }
2201 void SetStartMin(int64_t m)
override { t_->SetEndMin(
CapSub(m, offset_)); }
2202 void SetStartMax(int64_t m)
override { t_->SetEndMax(
CapSub(m, offset_)); }
2203 void SetStartRange(int64_t mi, int64_t ma)
override {
2204 t_->SetEndRange(
CapSub(mi, offset_),
CapSub(ma, offset_));
2206 int64_t OldStartMin()
const override {
2207 return CapAdd(t_->OldEndMin(), offset_);
2209 int64_t OldStartMax()
const override {
2210 return CapAdd(t_->OldEndMax(), offset_);
2212 void WhenStartRange(Demon*
const d)
override { t_->WhenEndRange(d); }
2213 void WhenStartBound(Demon*
const d)
override { t_->WhenEndBound(d); }
2214 IntExpr* StartExpr()
override {
2215 return solver()->MakeSum(t_->EndExpr(), offset_);
2217 IntExpr* DurationExpr()
override {
return solver()->MakeIntConst(duration_); }
2218 IntExpr* EndExpr()
override {
2219 return solver()->MakeSum(t_->EndExpr(), offset_ + duration_);
2221 IntExpr* PerformedExpr()
override {
return t_->PerformedExpr(); }
2225 IntExpr* SafeStartExpr(int64_t unperformed_value)
override {
2228 IntExpr* SafeDurationExpr(int64_t unperformed_value)
override {
2231 IntExpr* SafeEndExpr(int64_t unperformed_value)
override {
2235 void Accept(ModelVisitor*
const visitor)
const override {
2236 visitor->VisitIntervalVariable(
this, ModelVisitor::kStartSyncOnEndOperation,
2239 std::string DebugString()
const override {
2240 return absl::StrFormat(
2241 "IntervalStartSyncedOnEnd(%s, duration = %d, offset = %d)",
2242 t_->DebugString(), duration_, offset_);
2250 return RegisterIntervalVar(
2251 RevAlloc(
new MirrorIntervalVar(
this, interval_var)));
2256 return interval_var;
2258 return RegisterIntervalVar(
2259 RevAlloc(
new IntervalVarRelaxedMax(interval_var)));
2265 return interval_var;
2267 return RegisterIntervalVar(
2268 RevAlloc(
new IntervalVarRelaxedMin(interval_var)));
2272void IntervalVar::WhenAnything(
Demon*
const d) {
2274 WhenDurationRange(d);
2276 WhenPerformedBound(d);
2280 const std::string&
name) {
2281 return RevAlloc(
new FixedInterval(
this,
start, duration,
name));
2288 const std::string&
name) {
2292 return RegisterIntervalVar(RevAlloc(
new FixedDurationPerformedIntervalVar(
2295 return RegisterIntervalVar(RevAlloc(
new FixedDurationIntervalVar(
2299void Solver::MakeFixedDurationIntervalVarArray(
2301 bool optional, absl::string_view
name, std::vector<IntervalVar*>* array) {
2303 CHECK(array !=
nullptr);
2305 for (
int i = 0; i < count; ++i) {
2306 const std::string var_name = absl::StrCat(
name, i);
2307 array->push_back(MakeFixedDurationIntervalVar(
2314 const std::string&
name) {
2315 CHECK(start_variable !=
nullptr);
2316 CHECK_GE(duration, 0);
2317 return RegisterIntervalVar(RevAlloc(
2318 new StartVarPerformedIntervalVar(
this, start_variable, duration,
name)));
2324 IntVar*
const start_variable, int64_t duration,
2325 IntVar*
const performed_variable,
const std::string&
name) {
2326 CHECK(start_variable !=
nullptr);
2327 CHECK(performed_variable !=
nullptr);
2328 CHECK_GE(duration, 0);
2329 if (!performed_variable->
Bound()) {
2330 StartVarIntervalVar*
const interval =
2331 reinterpret_cast<StartVarIntervalVar*
>(
2332 RegisterIntervalVar(RevAlloc(
new StartVarIntervalVar(
2333 this, start_variable, duration, performed_variable,
name))));
2334 AddConstraint(RevAlloc(
new LinkStartVarIntervalVar(
2335 this,
interval, start_variable, performed_variable)));
2337 }
else if (performed_variable->
Min() == 1) {
2338 return RegisterIntervalVar(RevAlloc(
new StartVarPerformedIntervalVar(
2339 this, start_variable, duration,
name)));
2344void Solver::MakeFixedDurationIntervalVarArray(
2345 const std::vector<IntVar*>& start_variables, int64_t duration,
2346 absl::string_view
name, std::vector<IntervalVar*>* array) {
2347 CHECK(array !=
nullptr);
2349 for (
int i = 0; i < start_variables.size(); ++i) {
2350 const std::string var_name = absl::StrCat(
name, i);
2352 MakeFixedDurationIntervalVar(start_variables[i], duration, var_name));
2358void Solver::MakeFixedDurationIntervalVarArray(
2359 const std::vector<IntVar*>& start_variables,
2360 absl::Span<const int64_t> durations, absl::string_view
name,
2361 std::vector<IntervalVar*>* array) {
2362 CHECK(array !=
nullptr);
2363 CHECK_EQ(start_variables.size(), durations.size());
2365 for (
int i = 0; i < start_variables.size(); ++i) {
2366 const std::string var_name = absl::StrCat(
name, i);
2367 array->push_back(MakeFixedDurationIntervalVar(start_variables[i],
2368 durations[i], var_name));
2372void Solver::MakeFixedDurationIntervalVarArray(
2373 const std::vector<IntVar*>& start_variables,
2374 absl::Span<const int> durations, absl::string_view
name,
2375 std::vector<IntervalVar*>* array) {
2376 CHECK(array !=
nullptr);
2377 CHECK_EQ(start_variables.size(), durations.size());
2379 for (
int i = 0; i < start_variables.size(); ++i) {
2380 const std::string var_name = absl::StrCat(
name, i);
2381 array->push_back(MakeFixedDurationIntervalVar(start_variables[i],
2382 durations[i], var_name));
2386void Solver::MakeFixedDurationIntervalVarArray(
2387 const std::vector<IntVar*>& start_variables,
2388 absl::Span<const int> durations,
2389 const std::vector<IntVar*>& performed_variables, absl::string_view
name,
2390 std::vector<IntervalVar*>* array) {
2391 CHECK(array !=
nullptr);
2393 for (
int i = 0; i < start_variables.size(); ++i) {
2394 const std::string var_name = absl::StrCat(
name, i);
2395 array->push_back(MakeFixedDurationIntervalVar(
2396 start_variables[i], durations[i], performed_variables[i], var_name));
2400void Solver::MakeFixedDurationIntervalVarArray(
2401 const std::vector<IntVar*>& start_variables,
2402 absl::Span<const int64_t> durations,
2403 const std::vector<IntVar*>& performed_variables, absl::string_view
name,
2404 std::vector<IntervalVar*>* array) {
2405 CHECK(array !=
nullptr);
2407 for (
int i = 0; i < start_variables.size(); ++i) {
2408 const std::string var_name = absl::StrCat(
name, i);
2409 array->push_back(MakeFixedDurationIntervalVar(
2410 start_variables[i], durations[i], performed_variables[i], var_name));
2417 int64_t duration_min, int64_t duration_max,
2420 return RegisterIntervalVar(RevAlloc(
new VariableDurationIntervalVar(
2425void Solver::MakeIntervalVarArray(
int count, int64_t
start_min,
2426 int64_t
start_max, int64_t duration_min,
2427 int64_t duration_max, int64_t
end_min,
2429 absl::string_view
name,
2430 std::vector<IntervalVar*>*
const array) {
2432 CHECK(array !=
nullptr);
2434 for (
int i = 0; i < count; ++i) {
2435 const std::string var_name = absl::StrCat(
name, i);
2444 IntervalVar*
const interval_var, int64_t duration, int64_t offset) {
2445 return RegisterIntervalVar(
2446 RevAlloc(
new FixedDurationIntervalVarStartSyncedOnStart(
2447 interval_var, duration, offset)));
2451 IntervalVar*
const interval_var, int64_t duration, int64_t offset) {
2452 return RegisterIntervalVar(
2453 RevAlloc(
new FixedDurationIntervalVarStartSyncedOnEnd(interval_var,
2454 duration, offset)));
2458 IntervalVar*
const interval_var, int64_t duration, int64_t offset) {
2459 return RegisterIntervalVar(
2460 RevAlloc(
new FixedDurationIntervalVarStartSyncedOnStart(
2461 interval_var, duration,
CapSub(offset, duration))));
2465 IntervalVar*
const interval_var, int64_t duration, int64_t offset) {
2466 return RegisterIntervalVar(
2467 RevAlloc(
new FixedDurationIntervalVarStartSyncedOnEnd(
2468 interval_var, duration,
CapSub(offset, duration))));
virtual bool Bound() const
Returns true if the min and the max of the expression are equal.
virtual int64_t Min() const =0
static const int64_t kMaxValidValue
The largest acceptable value to be returned by EndMax()
static const int64_t kMinValidValue
The smallest acceptable value to be returned by StartMin()
virtual bool MustBePerformed() const =0
static const char kRelaxedMinOperation[]
static const char kMirrorOperation[]
Operations.
static const char kRelaxedMaxOperation[]
@ VAR_PRIORITY
VAR_PRIORITY is between DELAYED_PRIORITY and NORMAL_PRIORITY.
std::function< void(Solver *)> Action
const std::string name
A name for logging purposes.
For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is false
problem is infeasible or unbounded (default).
In SWIG mode, we don't want anything besides these top-level includes.
void InternalSaveBooleanVarValue(Solver *const solver, IntVar *const var)
int64_t CapAdd(int64_t x, int64_t y)
int64_t CapSub(int64_t x, int64_t y)
IntExpr * BuildStartExpr(IntervalVar *var)
--— Expression builders ---—
IntExpr * BuildSafeStartExpr(IntervalVar *var, int64_t unperformed_value)
IntExpr * BuildSafeEndExpr(IntervalVar *var, int64_t unperformed_value)
void RegisterDemon(Solver *const solver, Demon *const demon, DemonProfiler *const monitor)
--— Exported Methods for Unit Tests --—
void LinkVarExpr(Solver *s, IntExpr *expr, IntVar *var)
--— IntExprElement --—
IntExpr * BuildEndExpr(IntervalVar *var)
Demon * MakeConstraintDemon0(Solver *const s, T *const ct, void(T::*method)(), const std::string &name)
IntExpr * BuildDurationExpr(IntervalVar *var)
IntExpr * BuildSafeDurationExpr(IntervalVar *var, int64_t unperformed_value)