14#ifndef ORTOOLS_SAT_INTERVALS_H_
15#define ORTOOLS_SAT_INTERVALS_H_
23#include "absl/container/flat_hash_map.h"
24#include "absl/log/check.h"
25#include "absl/types/span.h"
63 IntegerVariable size, IntegerValue fixed_size,
64 LiteralIndex is_present);
68 bool add_linear_relation =
false);
98 IntegerValue
MinSize(IntervalVariable
i)
const {
99 return integer_trail_->LowerBound(sizes_[
i]);
104 return integer_trail_->UpperBound(sizes_[
i]);
109 std::vector<IntervalVariable> result;
123 std::vector<Literal> enforcement_literals,
124 const std::vector<IntervalVariable>& variables,
125 bool register_as_disjunctive_helper =
false);
128 std::vector<Literal> enforcement_literals,
129 const std::vector<IntervalVariable>& x_variables,
130 const std::vector<IntervalVariable>& y_variables);
137 absl::Span<const AffineExpression> demands);
172 return disjunctive_helpers_;
183 cumulative_helpers_.push_back(helper);
186 return cumulative_helpers_;
213 std::pair<std::vector<Literal>, std::vector<IntervalVariable>>,
217 std::tuple<std::vector<Literal>, std::vector<IntervalVariable>,
218 std::vector<IntervalVariable>>,
220 no_overlap_2d_helper_repository_;
222 std::pair<SchedulingConstraintHelper*, std::vector<AffineExpression>>,
224 demand_helper_repository_;
227 absl::flat_hash_map<std::pair<IntervalDefinition, IntervalDefinition>,
229 disjunctive_precedences_;
232 std::vector<SchedulingConstraintHelper*> disjunctive_helpers_;
233 std::vector<CumulativeHelper> cumulative_helpers_;
240inline std::function<int64_t(
const Model&)>
MinSize(IntervalVariable v) {
241 return [=](
const Model& model) {
246inline std::function<int64_t(
const Model&)>
MaxSize(IntervalVariable v) {
247 return [=](
const Model& model) {
252inline std::function<bool(
const Model&)>
IsOptional(IntervalVariable v) {
253 return [=](
const Model& model) {
259 IntervalVariable v) {
265inline std::function<IntervalVariable(
Model*)>
NewInterval(int64_t min_start,
268 return [=](
Model* model) {
269 CHECK_LE(min_start + size, max_end);
270 const IntegerVariable start =
281 IntegerVariable start, IntegerVariable
end, IntegerVariable size) {
289 int64_t min_start, int64_t max_end, int64_t min_size, int64_t max_size) {
301 int64_t min_start, int64_t max_end, int64_t size, Literal is_present) {
303 CHECK_LE(min_start + size, max_end);
304 const IntegerVariable start =
306 const IntervalVariable interval =
322 IntegerVariable start, IntegerVariable
end, IntegerVariable size,
324 return [=](
Model* model) {
326 start,
end, size, IntegerValue(0), is_present.
Index());
330inline std::function<IntervalVariable(
Model*)>
332 int64_t min_size, int64_t max_size,
334 return [=](
Model* model) {
344 const AffineExpression& capacity, SchedulingDemandHelper* demands_helper,
345 Model* model, std::vector<IntegerVariable>* vars);
IntervalsRepository(const IntervalsRepository &)=delete
SchedulingConstraintHelper * GetOrCreateHelper(std::vector< Literal > enforcement_literals, const std::vector< IntervalVariable > &variables, bool register_as_disjunctive_helper=false)
SchedulingDemandHelper * GetOrCreateDemandHelper(SchedulingConstraintHelper *helper, absl::Span< const AffineExpression > demands)
AffineExpression Start(IntervalVariable i) const
AffineExpression Size(IntervalVariable i) const
AffineExpression End(IntervalVariable i) const
Literal GetOrCreatePrecedenceLiteral(AffineExpression x, AffineExpression y)
LiteralIndex GetPrecedenceLiteral(AffineExpression x, AffineExpression y) const
bool IsAbsent(IntervalVariable i) const
const std::vector< CumulativeHelper > & AllCumulativeHelpers() const
void InitAllDecomposedEnergies()
Literal PresenceLiteral(IntervalVariable i) const
void CreateDisjunctivePrecedenceLiteral(IntervalVariable a, IntervalVariable b)
bool CreatePrecedenceLiteralIfNonTrivial(AffineExpression x, AffineExpression y)
LiteralIndex GetOrCreateDisjunctivePrecedenceLiteralIfNonTrivial(const IntervalDefinition &a, const IntervalDefinition &b)
const std::vector< SchedulingConstraintHelper * > & AllDisjunctiveHelpers() const
bool IsOptional(IntervalVariable i) const
NoOverlap2DConstraintHelper * GetOrCreate2DHelper(std::vector< Literal > enforcement_literals, const std::vector< IntervalVariable > &x_variables, const std::vector< IntervalVariable > &y_variables)
void RegisterCumulative(CumulativeHelper helper)
IntervalVariable CreateInterval(IntegerVariable start, IntegerVariable end, IntegerVariable size, IntegerValue fixed_size, LiteralIndex is_present)
IntegerValue MaxSize(IntervalVariable i) const
IntegerValue MinSize(IntervalVariable i) const
IntervalsRepository(Model *model)
IntervalsRepository & operator=(const IntervalsRepository &)=delete
std::vector< IntervalVariable > AllIntervals() const
bool IsPresent(IntervalVariable i) const
LiteralIndex Index() const
std::function< int64_t(const Model &)> MaxSize(IntervalVariable v)
std::function< IntervalVariable(Model *)> NewOptionalIntervalWithVariableSize(int64_t min_start, int64_t max_end, int64_t min_size, int64_t max_size, Literal is_present)
std::function< Literal(const Model &)> IsPresentLiteral(IntervalVariable v)
const LiteralIndex kNoLiteralIndex(-1)
std::function< IntervalVariable(Model *)> NewIntervalWithVariableSize(int64_t min_start, int64_t max_end, int64_t min_size, int64_t max_size)
std::function< IntervalVariable(Model *)> NewInterval(int64_t min_start, int64_t max_end, int64_t size)
std::function< void(Model *)> Implication(absl::Span< const Literal > enforcement_literals, IntegerLiteral i)
std::function< IntervalVariable(Model *)> NewOptionalInterval(int64_t min_start, int64_t max_end, int64_t size, Literal is_present)
void AppendVariablesFromCapacityAndDemands(const AffineExpression &capacity, SchedulingDemandHelper *demands_helper, Model *model, std::vector< IntegerVariable > *vars)
std::function< IntegerVariable(Model *)> NewIntegerVariable(int64_t lb, int64_t ub)
std::function< int64_t(const Model &)> MinSize(IntervalVariable v)
std::function< bool(const Model &)> IsOptional(IntervalVariable v)
ClosedInterval::Iterator end(ClosedInterval interval)
static IntegerLiteral LowerOrEqual(IntegerVariable i, IntegerValue bound)
SchedulingDemandHelper * demand_helper
AffineExpression capacity
SchedulingConstraintHelper * task_helper