Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
timetable_edgefinding.h
Go to the documentation of this file.
1// Copyright 2010-2024 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_TIMETABLE_EDGEFINDING_H_
15#define OR_TOOLS_SAT_TIMETABLE_EDGEFINDING_H_
16
17#include <vector>
18
19#include "ortools/sat/integer.h"
21#include "ortools/sat/model.h"
24
25namespace operations_research {
26namespace sat {
27
28// TimeTableEdgeFinding implements the timetable edge finding filtering rule
29// presented in Vilim Petr, "Timetable edge finding filtering algorithm for
30// discrete cumulative resources", CPAIOR 2011,
31// http://vilim.eu/petr/cpaior2011.pdf.
32//
33// This propagator runs in O(n^2) where n is the number of tasks. It increases
34// both the start times and decreases the ending times of the tasks.
35//
36// Note that this propagator does not ensure that the cumulative constraint
37// holds. It should thus always be used with at least a timetable propagator.
38//
39// ALOGRITHM:
40//
41// The algorithm relies on free tasks. A free task is basically a task without
42// its mandatory part. For instance:
43//
44// s_min s_max e_min e_max
45// v v v v
46// task: =============================
47// ^ ^ ^
48// | free part | Mandatory part |
49//
50// Obviously, the free part of a task that has no mandatory part is equal to the
51// task itself. Also, a free part cannot have a mandatory part by definition. A
52// fixed task thus have no free part.
53//
54// The idea of the algorithm is to use free and mandatory parts separately to
55// have a better estimation of the energy contained in a task interval.
56//
57// If the sum of the energy of all the free parts and mandatory subparts
58// contained in a task interval exceeds the amount of energy available, then the
59// problem is unfeasible. A task thus cannot be scheduled at its minimum start
60// time if this would cause an overload in one of the task intervals.
62 public:
66
67 // This type is neither copyable nor movable.
70
71 bool Propagate() final;
72
74
75 private:
76 // Build the timetable and fills the mandatory_energy_before_start_min_ and
77 // mandatory_energy_before_end_max_.
78 //
79 // TODO(user): Share the profile building code with TimeTablingPerTask ! we do
80 // not really need the mandatory_energy_before_* vectors and can recompute the
81 // profile integral in a window efficiently during TimeTableEdgeFindingPass().
82 void BuildTimeTable();
83
84 // Performs a single pass of the Timetable Edge Finding filtering rule to
85 // updates the start time of the tasks. This same function can be used to
86 // update the end times by calling the SwitchToMirrorProblem method first.
87 bool TimeTableEdgeFindingPass();
88
89 // Fills the reason for the energy in [window_min, window_max].
90 // We exclude the given task_index mandatory energy and uses
91 // tasks_contributing_to_free_energy_.
92 void FillEnergyInWindowReason(IntegerValue window_min,
93 IntegerValue window_max, int task_index);
94
95 IntegerValue CapacityMax() const {
96 return integer_trail_->UpperBound(capacity_);
97 }
98
99 const int num_tasks_;
100 const AffineExpression capacity_;
102 SchedulingDemandHelper* demands_;
103 IntegerTrail* integer_trail_;
104
105 // Start (resp. end) of the compulsory parts used to build the profile.
106 std::vector<TaskTime> scp_;
107 std::vector<TaskTime> ecp_;
108
109 // Sizes and energy of the free parts.
110 std::vector<IntegerValue> size_free_;
111 std::vector<IntegerValue> energy_free_;
112
113 // Energy contained in the time table before the start min (resp. end max)
114 // of each task.
115 std::vector<IntegerValue> mandatory_energy_before_start_min_;
116 std::vector<IntegerValue> mandatory_energy_before_end_max_;
117
118 // List of task that should participate in the reason.
119 std::vector<int> reason_tasks_fully_included_in_window_;
120 std::vector<int> reason_tasks_partially_included_in_window_;
121};
122
123} // namespace sat
124} // namespace operations_research
125
126#endif // OR_TOOLS_SAT_TIMETABLE_EDGEFINDING_H_
IntegerValue UpperBound(IntegerVariable i) const
Definition integer.h:1721
Base class for CP like propagators.
Definition integer.h:1414
void RegisterWith(GenericLiteralWatcher *watcher)
TimeTableEdgeFinding & operator=(const TimeTableEdgeFinding &)=delete
TimeTableEdgeFinding(const TimeTableEdgeFinding &)=delete
This type is neither copyable nor movable.
TimeTableEdgeFinding(AffineExpression capacity, SchedulingConstraintHelper *helper, SchedulingDemandHelper *demands, Model *model)
GRBmodel * model
In SWIG mode, we don't want anything besides these top-level includes.