OR-Tools  9.2
scheduling_cuts.h
Go to the documentation of this file.
1 // Copyright 2010-2021 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_SCHEDULING_CUTS_H_
15 #define OR_TOOLS_SAT_SCHEDULING_CUTS_H_
16 
17 #include <functional>
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 #include "ortools/base/int_type.h"
24 #include "ortools/sat/cuts.h"
25 #include "ortools/sat/integer.h"
26 #include "ortools/sat/intervals.h"
29 #include "ortools/sat/model.h"
31 
32 namespace operations_research {
33 namespace sat {
34 
35 // For a given set of intervals and demands, we compute the energy of
36 // each task and make sure their sum fits in the span of the intervals * its
37 // capacity.
38 //
39 // If an interval is optional, it contributes
40 // min_demand * min_size * presence_literal
41 // amount of total energy.
42 //
43 // If an interval is performed, we use the linear energy formulation (if
44 // defined, that is if different from a constant -1), or the McCormick
45 // relaxation of the product size * demand if not defined.
46 //
47 // The maximum energy is capacity * span of intervals at level 0.
49  const std::vector<IntervalVariable>& intervals,
50  const AffineExpression& capacity,
51  const std::vector<AffineExpression>& demands,
52  const std::vector<LinearExpression>& energies, Model* model);
53 
54 // For a given set of intervals and demands, we first compute the mandatory part
55 // of the interval as [start_max , end_min]. We use this to calculate mandatory
56 // demands for each start_max time points for eligible intervals.
57 // Since the sum of these mandatory demands must be smaller or equal to the
58 // capacity, we create a cut representing that.
59 //
60 // If an interval is optional, it contributes min_demand * presence_literal
61 // amount of demand to the mandatory demands sum. So the final cut is generated
62 // as follows:
63 // sum(demands of always present intervals)
64 // + sum(presence_literal * min_of_demand) <= capacity.
66  const std::vector<IntervalVariable>& intervals,
67  const AffineExpression& capacity,
68  const std::vector<AffineExpression>& demands, Model* model);
69 
70 // Completion time cuts for the cumulative constraint. It is a simple relaxation
71 // where we replace a cumulative task with demand k and duration d by a
72 // no_overlap task with duration d * k / capacity_max.
74  const std::vector<IntervalVariable>& intervals,
75  const AffineExpression& capacity,
76  const std::vector<AffineExpression>& demands,
77  const std::vector<LinearExpression>& energies, Model* model);
78 
79 // For a given set of intervals in a cumulative constraint, we detect violated
80 // mandatory precedences and create a cut for these.
82  const std::vector<IntervalVariable>& intervals,
83  const AffineExpression& capacity,
84  const std::vector<AffineExpression>& demands, Model* model);
85 
86 // Completion time cuts for the no_overlap_2d constraint. It actually generates
87 // the completion time cumulative cuts in both axis.
89  const std::vector<IntervalVariable>& x_intervals,
90  const std::vector<IntervalVariable>& y_intervals, Model* model);
91 
92 // Energetic cuts for the no_overlap_2d constraint.
93 //
94 // For a given set of rectangles, we compute the area of each rectangle
95 // and make sure their sum is less than the area of the bounding interval.
96 //
97 // If an interval is optional, it contributes
98 // min_size_x * min_size_y * presence_literal
99 // amount of total area.
100 //
101 // If an interval is performed, we use the linear area formulation (if
102 // possible), or the McCormick relaxation of the size_x * size_y.
103 //
104 // The maximum area is the area of the bounding rectangle of each intervals
105 // at level 0.
107  const std::vector<IntervalVariable>& x_intervals,
108  const std::vector<IntervalVariable>& y_intervals, Model* model);
109 
110 // For a given set of intervals, we first compute the min and max of all
111 // intervals. Then we create a cut that indicates that all intervals must fit
112 // in that span.
113 //
114 // If an interval is optional, it contributes min_size * presence_literal
115 // amount of demand to the mandatory demands sum. So the final cut is generated
116 // as follows:
117 // sum(sizes of always present intervals)
118 // + sum(presence_literal * min_of_size) <= span of all intervals.
120  const std::vector<IntervalVariable>& intervals, Model* model);
121 
122 // For a given set of intervals in a no_overlap constraint, we detect violated
123 // mandatory precedences and create a cut for these.
125  const std::vector<IntervalVariable>& intervals, Model* model);
126 
127 // For a given set of intervals in a no_overlap constraint, we detect violated
128 // area based cuts from Queyranne 93 [see note in the code] and create a cut for
129 // these.
131  const std::vector<IntervalVariable>& intervals, Model* model);
132 
133 } // namespace sat
134 } // namespace operations_research
135 
136 #endif // OR_TOOLS_SAT_SCHEDULING_CUTS_H_
CutGenerator CreateNoOverlapEnergyCutGenerator(const std::vector< IntervalVariable > &intervals, Model *model)
GRBmodel * model
CutGenerator CreateNoOverlap2dEnergyCutGenerator(const std::vector< IntervalVariable > &x_intervals, const std::vector< IntervalVariable > &y_intervals, Model *model)
int64_t capacity
CutGenerator CreateNoOverlapPrecedenceCutGenerator(const std::vector< IntervalVariable > &intervals, Model *model)
CutGenerator CreateCumulativeTimeTableCutGenerator(const std::vector< IntervalVariable > &intervals, const AffineExpression &capacity, const std::vector< AffineExpression > &demands, Model *model)
CutGenerator CreateCumulativeEnergyCutGenerator(const std::vector< IntervalVariable > &intervals, const AffineExpression &capacity, const std::vector< AffineExpression > &demands, const std::vector< LinearExpression > &energies, Model *model)
CutGenerator CreateCumulativeCompletionTimeCutGenerator(const std::vector< IntervalVariable > &intervals, const AffineExpression &capacity, const std::vector< AffineExpression > &demands, const std::vector< LinearExpression > &energies, Model *model)
Collection of objects used to extend the Constraint Solver library.
CutGenerator CreateNoOverlap2dCompletionTimeCutGenerator(const std::vector< IntervalVariable > &x_intervals, const std::vector< IntervalVariable > &y_intervals, Model *model)
CutGenerator CreateNoOverlapCompletionTimeCutGenerator(const std::vector< IntervalVariable > &intervals, Model *model)
CutGenerator CreateCumulativePrecedenceCutGenerator(const std::vector< IntervalVariable > &intervals, const AffineExpression &capacity, const std::vector< AffineExpression > &demands, Model *model)