Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cp_model_symmetries.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_CP_MODEL_SYMMETRIES_H_
15#define OR_TOOLS_SAT_CP_MODEL_SYMMETRIES_H_
16
17#include <memory>
18#include <vector>
19
26
27namespace operations_research {
28namespace sat {
29
30// Returns a list of generators of the symmetry group of the given problem. Each
31// generator is a permutation of the integer range [0, n) where n is the number
32// of variables of the problem. They are permutations of the (index
33// representation of the) problem variables.
34//
35// Note that we ignore the variables that appear in no constraint, instead of
36// outputting the full symmetry group involving them.
37//
38// Note that the time limit is the global one of the solver, this method
39// enforces params.symmetry_detection_deterministic_time_limit() per call on top
40// of it.
41//
42// TODO(user): On SAT problems it is more powerful to detect permutations also
43// involving the negation of the problem variables. So that we could find a
44// symmetry x <-> not(y) for instance.
45//
46// TODO(user): As long as we only exploit symmetry involving only Boolean
47// variables we can make this code more efficient by not detecting symmetries
48// involving integer variable.
50 const SatParameters& params, const CpModelProto& problem,
51 std::vector<std::unique_ptr<SparsePermutation>>* generators,
52 SolverLogger* logger, TimeLimit* solver_time_limit);
53
54// Detects symmetries and fill the symmetry field.
56 CpModelProto* proto, SolverLogger* logger,
57 TimeLimit* solver_time_limit);
58
59// Basic implementation of some symmetry breaking during presolve.
60//
61// Currently this just try to fix variables by detecting symmetries between
62// Booleans in bool_and, at_most_one or exactly_one constraints.
63//
64// TODO(user): A bunch of other presolve transformations break the symmetry even
65// though they probably shouldn't. Like the find big liner overlap for instance.
66// Or when we fix variable but don't propagate to the full orbit. It might not
67// be too much work to:
68// 1/ Compute the symmetry early
69// 2/ Only do transformation that preserve them
70// To investigate. It seems disabling find_big_linear_overlap helps on
71// mas74.pb.gz, or the square??.mps for instance. But it is less good overall.
73
74// This make sure all variables from the same orbit have the same domain.
75// We also remove from the generator cycles on fixed or removed variables.
76//
77// Returns false on UNSAT.
79 PresolveContext* context);
80
81} // namespace sat
82} // namespace operations_research
83
84#endif // OR_TOOLS_SAT_CP_MODEL_SYMMETRIES_H_
bool DetectAndExploitSymmetriesInPresolve(PresolveContext *context)
void FindCpModelSymmetries(const SatParameters &params, const CpModelProto &problem, std::vector< std::unique_ptr< SparsePermutation > > *generators, SolverLogger *logger, TimeLimit *solver_time_limit)
bool FilterOrbitOnUnusedOrFixedVariables(SymmetryProto *symmetry, PresolveContext *context)
void DetectAndAddSymmetryToProto(const SatParameters &params, CpModelProto *proto, SolverLogger *logger, TimeLimit *time_limit)
Detects symmetries and fill the symmetry field.
In SWIG mode, we don't want anything besides these top-level includes.