36 const std::vector<IntervalVariable>& vars,
40 if (vars.empty())
return;
51 for (
int i = 0; i < demands.size(); ++i) {
52 if (intervals->MaxSize(vars[i]) == 0)
continue;
55 builder.
AddTerm(demands[i], IntegerValue(1));
59 std::vector<Literal> enforcement_literals;
60 if (intervals->IsOptional(vars[i])) {
61 enforcement_literals.push_back(intervals->PresenceLiteral(vars[i]));
67 if (intervals->MinSize(vars[i]) == 0) {
68 enforcement_literals.push_back(encoder->GetOrCreateAssociatedLiteral(
69 intervals->Size(vars[i]).GreaterOrEqual(IntegerValue(1))));
72 if (enforcement_literals.empty()) {
79 if (vars.size() == 1)
return;
93 std::vector<IntervalVariable> in_disjunction;
94 for (
int i = 0; i < vars.size(); ++i) {
95 if (intervals->MinSize(vars[i]) > 0 &&
96 2 * integer_trail->LowerBound(demands[i]) >
97 integer_trail->UpperBound(
capacity)) {
98 in_disjunction.push_back(vars[i]);
119 if (in_disjunction.size() == vars.size())
return;
122 if (helper ==
nullptr) {
124 model->TakeOwnership(helper);
142 std::vector<IntegerVariable> index_to_end_vars;
143 std::vector<int> index_to_task;
144 std::vector<PrecedencesPropagator::IntegerPrecedences> before;
145 index_to_end_vars.clear();
146 for (
int t = 0; t < helper->
NumTasks(); ++t) {
151 index_to_end_vars.push_back(end_exp.
var);
152 index_to_task.push_back(t);
155 index_to_end_vars, &before);
156 const int size = before.size();
157 for (
int i = 0; i < size;) {
158 const IntegerVariable
var = before[i].var;
162 std::vector<int> subtasks;
163 for (; i < size && before[i].var ==
var; ++i) {
164 const int t = index_to_task[before[i].index];
165 subtasks.push_back(t);
175 if (subtasks.size() > 1) {
179 integer_trail, helper);
181 model->TakeOwnership(constraint);
192 model->TakeOwnership(time_tabling);
207 model->TakeOwnership(time_table_edge_finding);
213 const std::vector<IntervalVariable>& vars,
217 if (vars.empty())
return;
224 const int num_tasks = vars.size();
229 std::vector<IntegerVariable> start_vars;
230 std::vector<IntegerVariable> end_vars;
231 std::vector<IntegerValue> fixed_demands;
233 for (
int t = 0; t < num_tasks; ++t) {
234 start_vars.push_back(intervals->StartVar(vars[t]));
235 end_vars.push_back(intervals->EndVar(vars[t]));
237 fixed_demands.push_back(integer_trail->
LowerBound(demands[t]));
243 for (
int t = 0; t < num_tasks; ++t) {
248 for (IntegerValue
time = min_start;
time < max_end; ++
time) {
249 std::vector<LiteralWithCoeff> literals_with_coeff;
250 for (
int t = 0; t < num_tasks; ++t) {
259 std::vector<Literal> consume_condition;
263 if (intervals->IsOptional(vars[t])) {
264 consume_condition.push_back(intervals->PresenceLiteral(vars[t]));
268 consume_condition.push_back(encoder->GetOrCreateAssociatedLiteral(
270 consume_condition.push_back(encoder->GetOrCreateAssociatedLiteral(
272 IntegerValue(
time + 1))));
280 literals_with_coeff.push_back(
285 fixed_capacity, &literals_with_coeff);
294 const std::vector<IntervalVariable>& vars,
298 if (vars.empty())
return;
305 const IntegerValue fixed_capacity(
306 integer_trail->UpperBound(
capacity).value());
308 std::vector<AffineExpression> times;
309 std::vector<IntegerValue> deltas;
310 std::vector<Literal> presences;
312 const int num_tasks = vars.size();
313 for (
int t = 0; t < num_tasks; ++t) {
314 CHECK(integer_trail->IsFixed(demands[t]));
315 times.push_back(intervals->StartVar(vars[t]));
316 deltas.push_back(integer_trail->LowerBound(demands[t]));
317 times.push_back(intervals->EndVar(vars[t]));
318 deltas.push_back(-integer_trail->LowerBound(demands[t]));
319 if (intervals->IsOptional(vars[t])) {
320 presences.push_back(intervals->PresenceLiteral(vars[t]));
321 presences.push_back(intervals->PresenceLiteral(vars[t]));
323 presences.push_back(encoder->GetTrueLiteral());
324 presences.push_back(encoder->GetTrueLiteral());
std::function< BooleanVariable(Model *)> NewBooleanVariable()
bool use_overload_checker_in_cumulative_constraint() const
void AddCumulativeOverloadChecker(const std::vector< AffineExpression > &demands, AffineExpression capacity, SchedulingConstraintHelper *helper, Model *model)
Class that owns everything related to a particular optimization model.
constexpr IntegerValue kMinIntegerValue(-kMaxIntegerValue)
static IntegerLiteral LowerOrEqual(IntegerVariable i, IntegerValue bound)
std::function< void(Model *)> ReifiedBoolAnd(const std::vector< Literal > &literals, Literal r)
IntegerValue LowerBound(IntegerVariable i) const
void RegisterWith(GenericLiteralWatcher *watcher)
void AddTerm(IntegerVariable var, IntegerValue coeff)
constexpr IntegerValue kMaxIntegerValue(std::numeric_limits< IntegerValue::ValueType >::max() - 1)
std::function< void(Model *)> CumulativeUsingReservoir(const std::vector< IntervalVariable > &vars, const std::vector< AffineExpression > &demands, AffineExpression capacity, SchedulingConstraintHelper *helper=nullptr)
#define DCHECK_NE(val1, val2)
bool use_timetable_edge_finding_in_cumulative_constraint() const
void RegisterWith(GenericLiteralWatcher *watcher)
std::function< void(Model *)> Disjunctive(const std::vector< IntervalVariable > &vars)
bool AddLinearConstraint(bool use_lower_bound, Coefficient lower_bound, bool use_upper_bound, Coefficient upper_bound, std::vector< LiteralWithCoeff > *cst)
const std::vector< AffineExpression > & Ends() const
std::tuple< int64_t, int64_t, const double > Coefficient
std::function< void(Model *)> CumulativeTimeDecomposition(const std::vector< IntervalVariable > &vars, const std::vector< AffineExpression > &demands, AffineExpression capacity, SchedulingConstraintHelper *helper=nullptr)
void AddReservoirConstraint(std::vector< AffineExpression > times, std::vector< IntegerValue > deltas, std::vector< Literal > presences, int64_t min_level, int64_t max_level, Model *model)
IntegerValue UpperBound(IntegerVariable i) const
void RegisterWith(GenericLiteralWatcher *watcher)
bool IsModelUnsat() const
Collection of objects used to extend the Constraint Solver library.
const IntegerVariable kNoIntegerVariable(-1)
static IntegerLiteral GreaterOrEqual(IntegerVariable i, IntegerValue bound)
void LoadLinearConstraint(const ConstraintProto &ct, Model *m)
bool use_disjunctive_constraint_in_cumulative_constraint() const
void LoadConditionalLinearConstraint(const absl::Span< const Literal > enforcement_literals, const LinearConstraint &cst, Model *model)
std::function< void(Model *)> Cumulative(const std::vector< IntervalVariable > &vars, const std::vector< AffineExpression > &demands, AffineExpression capacity, SchedulingConstraintHelper *helper=nullptr)
bool IsFixed(IntegerVariable i) const