OR-Tools  9.6
enum_sets.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 <ostream>
17 #include <string>
18 #include <tuple>
19 #include <vector>
20 
21 #include "absl/strings/str_cat.h"
22 #include "gtest/gtest.h"
23 #include "ortools/math_opt/result.pb.h"
24 #include "ortools/math_opt/solution.pb.h"
26 
27 namespace operations_research {
28 namespace math_opt {
29 
30 // portable.
31 std::vector<FeasibilityStatusProto> AllFeasibilityStatuses() {
32  std::vector<FeasibilityStatusProto> values;
33  for (int f = FeasibilityStatusProto_MIN; f <= FeasibilityStatusProto_MAX;
34  ++f) {
35  if (FeasibilityStatusProto_IsValid(f) &&
36  f != FEASIBILITY_STATUS_UNSPECIFIED) {
37  values.push_back(static_cast<FeasibilityStatusProto>(f));
38  }
39  }
40  return values;
41 }
42 
43 std::vector<SolutionStatusProto> AllSolutionStatuses() {
44  std::vector<SolutionStatusProto> values;
45  for (int f = SolutionStatusProto_MIN; f <= SolutionStatusProto_MAX; ++f) {
46  if (SolutionStatusProto_IsValid(f) && f != SOLUTION_STATUS_UNSPECIFIED) {
47  values.push_back(static_cast<SolutionStatusProto>(f));
48  }
49  }
50  return values;
51 }
52 
53 void PrintTo(const SolutionStatusProto& proto, std::ostream* os) {
54  *os << ProtoEnumToString(proto);
55 }
56 
57 void PrintTo(const FeasibilityStatusProto& proto, std::ostream* os) {
58  *os << ProtoEnumToString(proto);
59 }
60 
61 void PrintTo(const std::tuple<SolutionStatusProto, SolutionStatusProto>& proto,
62  std::ostream* os) {
63  *os << ProtoEnumToString(std::get<0>(proto)) << "_"
64  << ProtoEnumToString(std::get<1>(proto));
65 }
66 
67 void PrintTo(
68  const std::tuple<FeasibilityStatusProto, FeasibilityStatusProto>& proto,
69  std::ostream* os) {
70  *os << ProtoEnumToString(std::get<0>(proto)) << "_"
71  << ProtoEnumToString(std::get<1>(proto));
72 }
73 
74 void PrintTo(
75  const std::tuple<SolutionStatusProto, FeasibilityStatusProto>& proto,
76  std::ostream* os) {
77  *os << ProtoEnumToString(std::get<0>(proto)) << "_"
78  << ProtoEnumToString(std::get<1>(proto));
79 }
80 
81 } // namespace math_opt
82 } // namespace operations_research
CpModelProto proto
void PrintTo(const Termination &termination, std::ostream *os)
Definition: matchers.cc:83
std::vector< FeasibilityStatusProto > AllFeasibilityStatuses()
Definition: enum_sets.cc:31
std::vector< SolutionStatusProto > AllSolutionStatuses()
Definition: enum_sets.cc:43
Collection of objects used to extend the Constraint Solver library.
std::string ProtoEnumToString(ProtoEnumType enum_value)