14#ifndef OR_TOOLS_MATH_OPT_ELEMENTAL_SYMMETRY_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_SYMMETRY_H_
22#include "absl/log/check.h"
23#include "absl/strings/str_format.h"
24#include "absl/strings/string_view.h"
30 static constexpr absl::string_view
GetName() {
return "NoSymmetry"; };
33 static constexpr bool Validate(std::array<int64_t, n>&) {
39 static constexpr void Enforce(std::array<int64_t, n>&) {
43 template <
typename ElementTypeT,
size_t n>
52template <
int i,
int j>
54 static_assert(0 <= i && i < j);
57 return absl::StrFormat(
"ElementSymmetry<%i, %i>", i, j);
61 static constexpr bool Validate(std::array<int64_t, n>& ids) {
62 static_assert(n > 1,
"one-dimensional keys cannot have symmetries");
64 return ids[i] <= ids[j];
68 static constexpr void Enforce(std::array<int64_t, n>& ids) {
69 static_assert(n > 1,
"one-dimensional keys cannot have symmetries");
70 if (ids[i] > ids[j]) {
71 std::swap(ids[i], ids[j]);
75 template <
typename ElementTypeT,
size_t n>
77 const std::array<ElementTypeT, n>& element_types) {
78 static_assert(n > 1,
"one-dimensional keys cannot have symmetries");
80 CHECK_EQ(element_types[i], element_types[j])
81 <<
"symmetric elements must be of the same type";
An object oriented wrapper for quadratic constraints in ModelStorage.
static constexpr void Enforce(std::array< int64_t, n > &ids)
static std::string GetName()
static constexpr bool Validate(std::array< int64_t, n > &ids)
static constexpr void CheckElementTypes(const std::array< ElementTypeT, n > &element_types)
A tag for no symmetry between two elements.
static constexpr void Enforce(std::array< int64_t, n > &)
static constexpr bool Validate(std::array< int64_t, n > &)
static constexpr void CheckElementTypes(const std::array< ElementTypeT, n > &)
static constexpr absl::string_view GetName()