Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
symmetry_util.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#ifndef OR_TOOLS_SAT_SYMMETRY_UTIL_H_
15#define OR_TOOLS_SAT_SYMMETRY_UTIL_H_
16
17#include <memory>
18#include <vector>
19
20#include "absl/types/span.h"
22#include "ortools/sat/cp_model.pb.h"
23
24namespace operations_research {
25namespace sat {
26
27// Given the generator for a permutation group of [0, n-1], tries to identify
28// a grouping of the variables in an p x q matrix such that any permutations
29// of the columns of this matrix is in the given group.
30//
31// The name comes from: "Packing and Partitioning Orbitopes", Volker Kaibel,
32// Marc E. Pfetsch, https://arxiv.org/abs/math/0603678 . Here we just detect it,
33// independently of the constraints on the variables in this matrix. We can also
34// detect non-Boolean orbitope.
35//
36// In order to detect orbitope, this basic algorithm requires that the
37// generators of the orbitope must only contain one or more 2-cyle (i.e
38// transpositions). Thus they must be involutions. The list of transpositions in
39// the SparsePermutation must also be listed in a canonical order.
40//
41// TODO(user): Detect more than one orbitope? Note that once detected, the
42// structure can be exploited efficiently, but for now, a more "generic"
43// algorithm based on stabilizator should achieve the same preprocessing power,
44// so I don't know how hard we need to invest in orbitope detection.
45//
46// TODO(user): The heuristic is quite limited for now, but this works on
47// graph20-20-1rand.mps.gz. I suspect the generators provided by the detection
48// code follow our preconditions.
49std::vector<std::vector<int>> BasicOrbitopeExtraction(
50 absl::Span<const std::unique_ptr<SparsePermutation>> generators);
51
52// Returns a vector of size n such that
53// - orbits[i] == -1 iff i is never touched by the generators (singleton orbit).
54// - orbits[i] = orbit_index, where orbits are numbered from 0 to num_orbits - 1
55//
56// TODO(user): We could reuse the internal memory if needed.
57std::vector<int> GetOrbits(
58 int n, absl::Span<const std::unique_ptr<SparsePermutation>> generators);
59
60// Returns the orbits under the given orbitope action.
61// Same results format as in GetOrbits(). Note that here, the orbit index
62// is simply the row index of an element in the orbitope matrix.
63std::vector<int> GetOrbitopeOrbits(int n,
64 absl::Span<const std::vector<int>> orbitope);
65
66// See Chapter 7 of Butler, Gregory, ed. Fundamental algorithms for permutation
67// groups. Berlin, Heidelberg: Springer Berlin Heidelberg, 1991.
69 int point, absl::Span<const std::unique_ptr<SparsePermutation>> generators,
70 std::vector<int>* schrier_vector, std::vector<int>* orbit);
71
72// Given a schreier vector for a given base point and a point in the same orbit
73// of the base point, returns a list of index of the `generators` to apply to
74// get a permutation mapping the base point to get the given point.
75std::vector<int> TracePoint(
76 int point, absl::Span<const int> schrier_vector,
77 absl::Span<const std::unique_ptr<SparsePermutation>> generators);
78
79// Creates a SparsePermutation on [0, n) from its proto representation.
80std::unique_ptr<SparsePermutation> CreateSparsePermutationFromProto(
81 int n, const SparsePermutationProto& proto);
82
83// Given the generators for a permutation group of [0, n-1], update it to
84// a set of generators of the group stabilizing the given element.
85//
86// Note that one can add symmetry breaking constraints by repeatedly doing:
87// 1/ Call GetOrbits() using the current set of generators.
88// 2/ Choose an element x0 in a large orbit (x0, .. xi ..) , and add x0 >= xi
89// for all i.
90// 3/ Update the set of generators to the one stabilizing x0.
91//
92// This is more or less what is described in "Symmetry Breaking Inequalities
93// from the Schreier-Sims Table", Domenico Salvagnin,
94// https://link.springer.com/chapter/10.1007/978-3-319-93031-2_37
95//
96// TODO(user): Implement!
98 int to_stabilize,
99 std::vector<std::unique_ptr<SparsePermutation>>* generators) {}
100
101} // namespace sat
102} // namespace operations_research
103
104#endif // OR_TOOLS_SAT_SYMMETRY_UTIL_H_
std::vector< int > GetOrbitopeOrbits(int n, absl::Span< const std::vector< int > > orbitope)
void GetSchreierVectorAndOrbit(int point, absl::Span< const std::unique_ptr< SparsePermutation > > generators, std::vector< int > *schrier_vector, std::vector< int > *orbit)
std::vector< int > TracePoint(int point, absl::Span< const int > schrier_vector, absl::Span< const std::unique_ptr< SparsePermutation > > generators)
void TransformToGeneratorOfStabilizer(int to_stabilize, std::vector< std::unique_ptr< SparsePermutation > > *generators)
std::vector< int > GetOrbits(int n, absl::Span< const std::unique_ptr< SparsePermutation > > generators)
std::unique_ptr< SparsePermutation > CreateSparsePermutationFromProto(int n, const SparsePermutationProto &proto)
Creates a SparsePermutation on [0, n) from its proto representation.
std::vector< std::vector< int > > BasicOrbitopeExtraction(absl::Span< const std::unique_ptr< SparsePermutation > > generators)
In SWIG mode, we don't want anything besides these top-level includes.