Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
elements.h
Go to the documentation of this file.
1// Copyright 2010-2025 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// IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h"
15// IWYU pragma: friend "ortools/math_opt/cpp/.*"
16// IWYU pragma: friend "ortools/math_opt/elemental/.*"
17
18#ifndef ORTOOLS_MATH_OPT_ELEMENTAL_ELEMENTS_H_
19#define ORTOOLS_MATH_OPT_ELEMENTAL_ELEMENTS_H_
20
21#include <ostream>
22#include <type_traits>
23
24#include "absl/strings/string_view.h"
25#include "ortools/base/array.h"
27
29
37constexpr auto kElements = gtl::to_array(
41constexpr int kNumElements = static_cast<int>(kElements.size());
42constexpr absl::string_view kElementNames[kNumElements] = {
43 "variable", "linear_constraint", "auxiliary_objective",
44 "quadratic_constraint", "indicator_constraint"};
45// Short names, typically to fit more things on a screen when debugging. Not
46// part of the API, can be changed if needed.
47constexpr absl::string_view kShortElementNames[kNumElements] = {
48 "var", "lin_con", "aux_obj", "quad_con", "indic_con"};
49
50absl::string_view ToString(ElementType element_type);
51std::ostream& operator<<(std::ostream& ostr, ElementType element_type);
52
53template <typename Sink>
54void AbslStringify(Sink& sink, ElementType element_type) {
55 sink.Append(ToString(element_type));
56}
57
58template <ElementType element_type>
60
61template <ElementType element_type, typename Container>
63
64template <ElementType element_type>
66
67template <ElementType element_type>
69
70// Traits to detect whether `T` is an `ElementId`.
71template <typename T>
72struct is_element_id : public std::false_type {};
73
74template <ElementType element_type>
75struct is_element_id<ElementId<element_type>> : public std::true_type {};
76
77template <typename T>
78static constexpr inline bool is_element_id_v = is_element_id<T>::value;
79
85
86} // namespace operations_research::math_opt
87
88#endif // ORTOOLS_MATH_OPT_ELEMENTAL_ELEMENTS_H_
constexpr std::array< std::remove_cv_t< T >, N > to_array(T(&ts)[N])
Definition array.h:44
TaggedIdsConstView< element_type, Container > ElementIdsConstView
Definition elements.h:62
ElementId< ElementType::kAuxiliaryObjective > AuxiliaryObjectiveId
Definition elements.h:82
typename TaggedIdsVector< tag >::View TaggedIdsSpan
Definition tagged_id.h:227
static constexpr bool is_element_id_v
Definition elements.h:78
constexpr absl::string_view kShortElementNames[kNumElements]
Definition elements.h:47
ElementId< ElementType::kVariable > VariableId
Definition elements.h:80
void AbslStringify(Sink &sink, const RemoteStreamingSolveMode mode)
ElementId< ElementType::kQuadraticConstraint > QuadraticConstraintId
Definition elements.h:83
std::ostream & operator<<(std::ostream &ostr, const SecondOrderConeConstraint &constraint)
ElementId< ElementType::kLinearConstraint > LinearConstraintId
Definition elements.h:81
absl::string_view ToString(const AttrT attr)
Definition attributes.h:327
TaggedId< element_type > ElementId
Definition elements.h:59
TaggedIdsVector< element_type > ElementIdsVector
Definition elements.h:65
constexpr absl::string_view kElementNames[kNumElements]
Definition elements.h:42
TaggedIdsSpan< element_type > ElementIdsSpan
Definition elements.h:68
ElementId< ElementType::kIndicatorConstraint > IndicatorConstraintId
Definition elements.h:84