Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
invalid_indicators.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 <algorithm>
17#include <cstdint>
18#include <string>
19#include <tuple>
20#include <vector>
21
22#include "absl/algorithm/container.h"
23#include "absl/status/status.h"
24#include "absl/strings/str_cat.h"
25#include "absl/strings/str_join.h"
27
29
30absl::Status InvalidIndicators::ToStatus() const {
31 if (invalid_indicators.empty()) {
32 return absl::OkStatus();
33 }
34 std::vector<std::string> printed_pairs;
35 for (int i = 0;
37 ++i) {
38 printed_pairs.push_back(absl::StrCat("(", invalid_indicators[i].constraint,
39 ", ", invalid_indicators[i].variable,
40 ")"));
41 }
42 auto builder = util::InvalidArgumentErrorBuilder();
43 builder
44 << "the following (indicator constraint ID, indicator variable ID) pairs "
45 "are invalid as the indicator variable is not binary: "
46 << absl::StrJoin(printed_pairs, ", ");
48 builder << ", ...";
49 }
50 return builder;
51}
52
54 absl::c_sort(invalid_indicators, [](const VariableAndConstraint& lhs,
55 const VariableAndConstraint& rhs) {
56 return std::forward_as_tuple(lhs.constraint, lhs.variable) <
57 std::forward_as_tuple(rhs.constraint, rhs.variable);
58 });
59}
60
61} // namespace operations_research::math_opt
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
constexpr std::size_t kMaxNonBinaryIndicatorVariables
The maximum number of non-binary indicator variables to report.
StatusBuilder InvalidArgumentErrorBuilder()
std::vector< VariableAndConstraint > invalid_indicators
void Sort()
Sort the elements lexicographically by (constraint ID, variable ID).