OR-Tools  9.6
indicator/storage.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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_MATH_OPT_CONSTRAINTS_INDICATOR_STORAGE_H_
15 #define OR_TOOLS_MATH_OPT_CONSTRAINTS_INDICATOR_STORAGE_H_
16 
17 #include <limits>
18 #include <optional>
19 #include <string>
20 #include <vector>
21 
22 #include "ortools/math_opt/model.pb.h"
23 #include "ortools/math_opt/model_update.pb.h"
26 
28 
29 // Internal storage representation for a single indicator constraint.
30 //
31 // Implements the interface specified for the `ConstraintData` parameter of
32 // `AtomicConstraintStorage`.
34  using IdType = IndicatorConstraintId;
35  using ProtoType = IndicatorConstraintProto;
36  using UpdatesProtoType = IndicatorConstraintUpdatesProto;
37 
38  // The `in_proto` must be in a valid state; see the inline comments on
39  // `IndicatorConstraintProto` for details.
40  static IndicatorConstraintData FromProto(const ProtoType& in_proto);
41  ProtoType Proto() const;
42  std::vector<VariableId> RelatedVariables() const;
43  void DeleteVariable(VariableId var);
44 
45  double lower_bound = -std::numeric_limits<double>::infinity();
46  double upper_bound = std::numeric_limits<double>::infinity();
48  // The indicator variable may be unset, in which case the constraint is
49  // ignored.
50  std::optional<VariableId> indicator;
51  bool activate_on_zero = false;
52  std::string name;
53 };
54 
55 template <>
56 struct AtomicConstraintTraits<IndicatorConstraintId> {
58 };
59 
60 } // namespace operations_research::math_opt
61 
62 #endif // OR_TOOLS_MATH_OPT_CONSTRAINTS_INDICATOR_STORAGE_H_
IntVar * var
Definition: expr_array.cc:1874
static IndicatorConstraintData FromProto(const ProtoType &in_proto)