14#ifndef OR_TOOLS_SAT_INTERVALS_H_
15#define OR_TOOLS_SAT_INTERVALS_H_
23#include "absl/container/flat_hash_map.h"
24#include "absl/log/check.h"
25#include "absl/types/span.h"
49 sat_solver_(model->GetOrCreate<
SatSolver>()),
66 IntervalVariable
CreateInterval(IntegerVariable start, IntegerVariable end,
67 IntegerVariable size, IntegerValue fixed_size,
68 LiteralIndex is_present);
72 bool add_linear_relation =
false);
103 return integer_trail_->LowerBound(sizes_[
i]);
108 return integer_trail_->UpperBound(sizes_[
i]);
113 std::vector<IntervalVariable> result;
127 const std::vector<IntervalVariable>& variables,
128 bool register_as_disjunctive_helper =
false);
131 const std::vector<IntervalVariable>& x_variables,
132 const std::vector<IntervalVariable>& y_variables);
139 absl::Span<const AffineExpression> demands);
168 return disjunctive_helpers_;
179 cumulative_helpers_.push_back(helper);
182 return cumulative_helpers_;
204 absl::flat_hash_map<std::vector<IntervalVariable>,
208 std::pair<std::vector<IntervalVariable>, std::vector<IntervalVariable>>,
210 no_overlap_2d_helper_repository_;
212 std::pair<SchedulingConstraintHelper*, std::vector<AffineExpression>>,
214 demand_helper_repository_;
221 absl::flat_hash_map<std::pair<IntervalDefinition, IntervalDefinition>,
223 disjunctive_precedences_;
224 absl::flat_hash_map<std::pair<AffineExpression, AffineExpression>,
Literal>
228 std::vector<SchedulingConstraintHelper*> disjunctive_helpers_;
229 std::vector<CumulativeHelper> cumulative_helpers_;
236inline std::function<int64_t(
const Model&)>
MinSize(IntervalVariable v) {
237 return [=](
const Model& model) {
242inline std::function<int64_t(
const Model&)>
MaxSize(IntervalVariable v) {
243 return [=](
const Model& model) {
248inline std::function<bool(
const Model&)>
IsOptional(IntervalVariable v) {
249 return [=](
const Model& model) {
255 IntervalVariable v) {
261inline std::function<IntervalVariable(
Model*)>
NewInterval(int64_t min_start,
264 return [=](
Model* model) {
265 CHECK_LE(min_start + size, max_end);
266 const IntegerVariable start =
277 IntegerVariable start, IntegerVariable end, IntegerVariable size) {
285 int64_t min_start, int64_t max_end, int64_t min_size, int64_t max_size) {
297 int64_t min_start, int64_t max_end, int64_t size, Literal is_present) {
299 CHECK_LE(min_start + size, max_end);
300 const IntegerVariable start =
302 const IntervalVariable interval =
318 IntegerVariable start, IntegerVariable end, IntegerVariable size,
320 return [=](
Model* model) {
322 start, end, size, IntegerValue(0), is_present.
Index());
326inline std::function<IntervalVariable(
Model*)>
328 int64_t min_size, int64_t max_size,
330 return [=](
Model* model) {
340 const AffineExpression& capacity, SchedulingDemandHelper* demands_helper,
341 Model* model, std::vector<IntegerVariable>* vars);
IntervalsRepository(const IntervalsRepository &)=delete
This type is neither copyable nor movable.
SchedulingDemandHelper * GetOrCreateDemandHelper(SchedulingConstraintHelper *helper, absl::Span< const AffineExpression > demands)
AffineExpression Start(IntervalVariable i) const
AffineExpression Size(IntervalVariable i) const
AffineExpression End(IntervalVariable i) const
LiteralIndex GetPrecedenceLiteral(AffineExpression x, AffineExpression y) const
LiteralIndex GetOrCreateDisjunctivePrecedenceLiteral(const IntervalDefinition &a, const IntervalDefinition &b)
bool IsAbsent(IntervalVariable i) const
const std::vector< CumulativeHelper > & AllCumulativeHelpers() const
void InitAllDecomposedEnergies()
Calls InitDecomposedEnergies on all SchedulingDemandHelper created.
Literal PresenceLiteral(IntervalVariable i) const
void CreateDisjunctivePrecedenceLiteral(IntervalVariable a, IntervalVariable b)
const std::vector< SchedulingConstraintHelper * > & AllDisjunctiveHelpers() const
bool IsOptional(IntervalVariable i) const
Returns whether or not a interval is optional and the associated literal.
void RegisterCumulative(CumulativeHelper helper)
IntervalVariable CreateInterval(IntegerVariable start, IntegerVariable end, IntegerVariable size, IntegerValue fixed_size, LiteralIndex is_present)
IntegerValue MaxSize(IntervalVariable i) const
Return the maximum size of the given IntervalVariable.
IntegerValue MinSize(IntervalVariable i) const
Return the minimum size of the given IntervalVariable.
SchedulingConstraintHelper * GetOrCreateHelper(const std::vector< IntervalVariable > &variables, bool register_as_disjunctive_helper=false)
IntervalsRepository(Model *model)
IntervalsRepository & operator=(const IntervalsRepository &)=delete
NoOverlap2DConstraintHelper * GetOrCreate2DHelper(const std::vector< IntervalVariable > &x_variables, const std::vector< IntervalVariable > &y_variables)
std::vector< IntervalVariable > AllIntervals() const
Utility function that returns a vector will all intervals.
bool CreatePrecedenceLiteral(AffineExpression x, AffineExpression y)
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)
In SWIG mode, we don't want anything besides these top-level includes.
static IntegerLiteral LowerOrEqual(IntegerVariable i, IntegerValue bound)
SchedulingDemandHelper * demand_helper
AffineExpression capacity
SchedulingConstraintHelper * task_helper