OR-Tools  9.6
inverted_bounds.cc
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 
15 
16 #include <cstdint>
17 #include <string>
18 #include <string_view>
19 #include <vector>
20 
21 #include "absl/status/status.h"
22 #include "absl/strings/str_join.h"
23 #include "absl/types/span.h"
25 
27 
28 absl::Status InvertedBounds::ToStatus() const {
29  if (empty()) {
30  return absl::OkStatus();
31  }
32 
33  auto builder = util::InvalidArgumentErrorBuilder();
34  const auto format_bounds_ids = [&builder](const std::string_view name,
35  const std::vector<int64_t>& ids) {
36  if (ids.empty()) {
37  return;
38  }
39 
40  builder << name << " with ids "
41  << absl::StrJoin(absl::MakeSpan(ids).subspan(0, kMaxInvertedBounds),
42  ",");
43  if (ids.size() > kMaxInvertedBounds) {
44  builder << "...";
45  }
46  };
47 
48  format_bounds_ids("variables", variables);
49  if (!variables.empty() && !linear_constraints.empty()) {
50  builder << " and ";
51  }
52  format_bounds_ids("linear constraints", linear_constraints);
53  builder << " have lower_bound > upper_bound";
54 
55  return builder;
56 }
57 
58 } // namespace operations_research::math_opt
const std::string name
constexpr std::size_t kMaxInvertedBounds
StatusBuilder InvalidArgumentErrorBuilder()