OR-Tools  8.2
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"
22#include "ortools/sat/model.h"
24
25namespace operations_research {
26namespace 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)|).
38void 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.
45void 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;
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_
void RegisterWith(GenericLiteralWatcher *watcher)
CumulativeEnergyConstraint(std::vector< AffineExpression > energies, AffineExpression capacity, IntegerTrail *integer_trail, SchedulingConstraintHelper *helper)
GRBmodel * model
void AddCumulativeOverloadChecker(const std::vector< AffineExpression > &demands, AffineExpression capacity, SchedulingConstraintHelper *helper, Model *model)
void AddCumulativeEnergyConstraint(std::vector< AffineExpression > energies, AffineExpression capacity, SchedulingConstraintHelper *helper, Model *model)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
int64 capacity