OR-Tools  8.1
cumulative_energy.h
Go to the documentation of this file.
1 // Copyright 2010-2018 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_ENERGY_H_
15 #define OR_TOOLS_SAT_CUMULATIVE_ENERGY_H_
16 
17 #include <functional>
18 #include <vector>
19 
20 #include "ortools/sat/integer.h"
21 #include "ortools/sat/intervals.h"
22 #include "ortools/sat/model.h"
23 #include "ortools/sat/theta_tree.h"
24 
25 namespace operations_research {
26 namespace sat {
27 
28 // Enforces the existence of a preemptive schedule where every task is executed
29 // inside its interval, using energy units of the resource during execution.
30 //
31 // All energy expression are assumed to take a non-negative value;
32 // if the energy of a task is 0, the task can run anywhere.
33 // The schedule never uses more than capacity units of energy at a given time.
34 //
35 // This is mathematically equivalent to making a model with energy(task)
36 // different tasks with demand and size 1, but is much more efficient,
37 // since it uses O(|tasks|) variables instead of O(sum_{task} |energy(task)|).
38 void AddCumulativeEnergyConstraint(std::vector<AffineExpression> energies,
39  AffineExpression capacity,
40  SchedulingConstraintHelper* helper,
41  Model* model);
42 
43 // Creates a CumulativeEnergyConstraint where the energy of each interval is
44 // the product of the demands times its size.
45 void AddCumulativeOverloadChecker(const std::vector<AffineExpression>& demands,
46  AffineExpression capacity,
47  SchedulingConstraintHelper* helper,
48  Model* model);
49 
51  public:
52  CumulativeEnergyConstraint(std::vector<AffineExpression> energies,
54  IntegerTrail* integer_trail,
56  bool Propagate() final;
57  void RegisterWith(GenericLiteralWatcher* watcher);
58 
59  private:
60  const std::vector<AffineExpression> energies_;
61  const AffineExpression capacity_;
62  IntegerTrail* integer_trail_;
65 
66  // Task characteristics.
67  std::vector<int> task_to_start_event_;
68 
69  // Start event characteristics, by nondecreasing start time.
70  std::vector<TaskTime> start_event_task_time_;
71  std::vector<bool> start_event_is_present_;
72 };
73 
74 } // namespace sat
75 } // namespace operations_research
76 
77 #endif // OR_TOOLS_SAT_CUMULATIVE_ENERGY_H_
operations_research::sat::AffineExpression
Definition: integer.h:205
operations_research::sat::IntegerTrail
Definition: integer.h:533
operations_research::sat::AddCumulativeOverloadChecker
void AddCumulativeOverloadChecker(const std::vector< AffineExpression > &demands, AffineExpression capacity, SchedulingConstraintHelper *helper, Model *model)
Definition: cumulative_energy.cc:40
operations_research::sat::PropagatorInterface
Definition: integer.h:1043
model.h
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::sat::CumulativeEnergyConstraint::CumulativeEnergyConstraint
CumulativeEnergyConstraint(std::vector< AffineExpression > energies, AffineExpression capacity, IntegerTrail *integer_trail, SchedulingConstraintHelper *helper)
Definition: cumulative_energy.cc:86
operations_research::sat::CumulativeEnergyConstraint
Definition: cumulative_energy.h:50
operations_research::sat::GenericLiteralWatcher
Definition: integer.h:1091
operations_research::sat::AddCumulativeEnergyConstraint
void AddCumulativeEnergyConstraint(std::vector< AffineExpression > energies, AffineExpression capacity, SchedulingConstraintHelper *helper, Model *model)
Definition: cumulative_energy.cc:27
operations_research::sat::SchedulingConstraintHelper
Definition: intervals.h:172
intervals.h
operations_research::sat::CumulativeEnergyConstraint::RegisterWith
void RegisterWith(GenericLiteralWatcher *watcher)
Definition: cumulative_energy.cc:99
operations_research::sat::CumulativeEnergyConstraint::Propagate
bool Propagate() final
Definition: cumulative_energy.cc:105
theta_tree.h
model
GRBmodel * model
Definition: gurobi_interface.cc:269
capacity
int64 capacity
Definition: routing_flow.cc:129
operations_research::sat::ThetaLambdaTree< IntegerValue >
integer.h