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
14
#include "
ortools/math_opt/core/invalid_indicators.h
"
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"
26
#include "
ortools/base/status_builder.h
"
27
28
namespace
operations_research::math_opt
{
29
30
absl::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;
36
i < std::min(
kMaxNonBinaryIndicatorVariables
,
invalid_indicators
.size());
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,
", "
);
47
if
(
invalid_indicators
.size() >
kMaxNonBinaryIndicatorVariables
) {
48
builder <<
", ..."
;
49
}
50
return
builder;
51
}
52
53
void
InvalidIndicators::Sort
() {
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
invalid_indicators.h
operations_research::math_opt
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition
gurobi_isv.cc:28
operations_research::math_opt::kMaxNonBinaryIndicatorVariables
constexpr std::size_t kMaxNonBinaryIndicatorVariables
The maximum number of non-binary indicator variables to report.
Definition
invalid_indicators.h:25
util::InvalidArgumentErrorBuilder
StatusBuilder InvalidArgumentErrorBuilder()
Definition
status_builder.h:107
status_builder.h
operations_research::math_opt::InvalidIndicators::VariableAndConstraint
Definition
invalid_indicators.h:32
operations_research::math_opt::InvalidIndicators::VariableAndConstraint::constraint
int64_t constraint
Definition
invalid_indicators.h:34
operations_research::math_opt::InvalidIndicators::VariableAndConstraint::variable
int64_t variable
Definition
invalid_indicators.h:33
operations_research::math_opt::InvalidIndicators::invalid_indicators
std::vector< VariableAndConstraint > invalid_indicators
Definition
invalid_indicators.h:47
operations_research::math_opt::InvalidIndicators::Sort
void Sort()
Sort the elements lexicographically by (constraint ID, variable ID).
Definition
invalid_indicators.cc:53
operations_research::math_opt::InvalidIndicators::ToStatus
absl::Status ToStatus() const
Definition
invalid_indicators.cc:30
ortools
math_opt
core
invalid_indicators.cc
Generated by
1.12.0