Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
indicator_constraint.cc
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
15
16#include <optional>
17#include <sstream>
18#include <string>
19#include <utility>
20
21#include "absl/strings/string_view.h"
26
28
30 const IndicatorConstraintData& data = storage()->constraint_data(id_);
31 // NOTE: The following makes a copy of `data.linear_terms`. This can be made
32 // more efficient if the need arises.
34 *storage_, {.coeffs = data.linear_terms, .offset = 0.0});
35 return data.lower_bound <= std::move(expr) <= data.upper_bound;
36}
37
38std::string IndicatorConstraint::ToString() const {
39 if (!storage()->has_constraint(id_)) {
40 return std::string(kDeletedConstraintDefaultDescription);
41 }
42 const IndicatorConstraintData& data = storage()->constraint_data(id_);
43 std::stringstream str;
44 if (data.indicator.has_value()) {
45 str << Variable(storage_, *data.indicator)
46 << (data.activate_on_zero ? " = 0" : " = 1");
47 } else {
48 str << "[unset indicator variable]";
49 }
50 str << " ⇒ " << ImpliedConstraint();
51 return str.str();
52}
53
54} // namespace operations_research::math_opt
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
constexpr absl::string_view kDeletedConstraintDefaultDescription
Definition model_util.h:30
LinearExpression ToLinearExpression(const ModelStorage &storage, const LinearExpressionData &expr_data)
Definition model_util.cc:25
A LinearExpression with upper and lower bounds.