Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cumulative.h
Go to the documentation of this file.
1// Copyright 2010-2025 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#ifndef ORTOOLS_SAT_CUMULATIVE_H_
15#define ORTOOLS_SAT_CUMULATIVE_H_
16
17#include <functional>
18#include <vector>
19
20#include "absl/types/span.h"
23#include "ortools/sat/model.h"
26
27namespace operations_research {
28namespace sat {
29
30// Adds a cumulative constraint on the given intervals, the associated demands
31// and the capacity expressions.
32//
33// Each interval represents a task to be scheduled in time such that the task
34// consumes the resource during the time range [lb, ub) where lb and ub
35// respectively represent the lower and upper bounds of the corresponding
36// interval variable. The amount of resource consumed by the task is the value
37// of its associated demand variable.
38//
39// The cumulative constraint forces the set of task to be scheduled such that
40// the sum of the demands of all the tasks that overlap any time point cannot
41// exceed the capacity of the resource.
42//
43// This constraint assumes that an interval can be optional or have a size
44// of zero. The demands and the capacity can be any non-negative number.
45//
46// Optimization: If one already have an helper constructed from the interval
47// variable, it can be passed as last argument.
48std::function<void(Model*)> Cumulative(
49 const std::vector<Literal>& enforcement_literals,
50 const std::vector<IntervalVariable>& vars,
51 absl::Span<const AffineExpression> demands, AffineExpression capacity,
52 SchedulingConstraintHelper* helper = nullptr);
53
54// Adds a simple cumulative constraint. See the comment of Cumulative() above
55// for a definition of the constraint. This is only used for testing.
56//
57// This constraint assumes that task demands and the resource capacity are fixed
58// to non-negative number.
59std::function<void(Model*)> CumulativeTimeDecomposition(
60 absl::Span<const Literal> enforcement_literals,
61 absl::Span<const IntervalVariable> vars,
62 absl::Span<const AffineExpression> demands, AffineExpression capacity,
63 SchedulingConstraintHelper* helper = nullptr);
64
65// Another testing code, same assumptions as the CumulativeTimeDecomposition().
66std::function<void(Model*)> CumulativeUsingReservoir(
67 absl::Span<const Literal> enforcement_literals,
68 absl::Span<const IntervalVariable> vars,
69 absl::Span<const AffineExpression> demands, AffineExpression capacity,
70 SchedulingConstraintHelper* helper = nullptr);
71
72} // namespace sat
73} // namespace operations_research
74
75#endif // ORTOOLS_SAT_CUMULATIVE_H_
std::function< void(Model *)> CumulativeUsingReservoir(absl::Span< const Literal > enforcement_literals, absl::Span< const IntervalVariable > vars, absl::Span< const AffineExpression > demands, AffineExpression capacity, SchedulingConstraintHelper *)
std::function< void(Model *)> Cumulative(const std::vector< Literal > &enforcement_literals, const std::vector< IntervalVariable > &vars, absl::Span< const AffineExpression > demands, AffineExpression capacity, SchedulingConstraintHelper *helper)
Definition cumulative.cc:45
std::function< void(Model *)> CumulativeTimeDecomposition(absl::Span< const Literal > enforcement_literals, absl::Span< const IntervalVariable > vars, absl::Span< const AffineExpression > demands, AffineExpression capacity, SchedulingConstraintHelper *)
OR-Tools root namespace.