forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cumulative.h
63 lines (55 loc) · 2.53 KB
/
cumulative.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2010-2018 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef OR_TOOLS_SAT_CUMULATIVE_H_
#define OR_TOOLS_SAT_CUMULATIVE_H_
#include <functional>
#include <vector>
#include "ortools/sat/integer.h"
#include "ortools/sat/intervals.h"
#include "ortools/sat/model.h"
namespace operations_research {
namespace sat {
// Adds a cumulative constraint on the given intervals, the associated demands
// and the capacity expressions.
//
// Each interval represents a task to be scheduled in time such that the task
// consumes the resource during the time range [lb, ub) where lb and ub
// respectively represent the lower and upper bounds of the corresponding
// interval variable. The amount of resource consumed by the task is the value
// of its associated demand variable.
//
// The cumulative constraint forces the set of task to be scheduled such that
// the sum of the demands of all the tasks that overlap any time point cannot
// exceed the capacity of the resource.
//
// This constraint assumes that an interval can be optional or have a duration
// of zero. The demands and the capacity can be any non-negative number.
//
// Optimization: If one already have an helper constructed from the interval
// variable, it can be passed as last argument.
std::function<void(Model*)> Cumulative(
const std::vector<IntervalVariable>& vars,
const std::vector<AffineExpression>& demands, AffineExpression capacity,
SchedulingConstraintHelper* helper = nullptr);
// Adds a simple cumulative constraint. See the comment of Cumulative() above
// for a definition of the constraint. This is only used for testing.
//
// This constraint assumes that task demands and the resource capacity are fixed
// to non-negative number.
std::function<void(Model*)> CumulativeTimeDecomposition(
const std::vector<IntervalVariable>& vars,
const std::vector<AffineExpression>& demands, AffineExpression capacity,
SchedulingConstraintHelper* helper = nullptr);
} // namespace sat
} // namespace operations_research
#endif // OR_TOOLS_SAT_CUMULATIVE_H_