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