29 const std::vector<std::unique_ptr<SparsePermutation>>& generators) {
32 std::vector<std::vector<int>> num_cycles_to_2cyclers;
33 for (
int g = 0; g < generators.size(); ++g) {
34 const std::unique_ptr<SparsePermutation>& perm = generators[g];
35 bool contain_only_2cycles =
true;
36 const int num_cycles = perm->NumCycles();
37 for (
int i = 0; i < num_cycles; ++i) {
38 if (perm->Cycle(i).size() != 2) {
39 contain_only_2cycles =
false;
43 if (!contain_only_2cycles)
continue;
44 if (num_cycles >= num_cycles_to_2cyclers.size()) {
45 num_cycles_to_2cyclers.resize(num_cycles + 1);
47 num_cycles_to_2cyclers[num_cycles].push_back(g);
56 for (
int i = 0; i < num_cycles_to_2cyclers.size(); ++i) {
57 if (num_cycles_to_2cyclers[i].size() > 1) {
58 const int num_perms = num_cycles_to_2cyclers[i].size() + 1;
59 VLOG(1) <<
"Potential orbitope: " << i <<
" x " << num_perms;
60 const int64_t score =
std::min(i, num_perms);
61 if (score > best_score) {
68 std::vector<std::vector<int>> orbitope;
69 if (best == -1)
return orbitope;
72 std::vector<bool> in_matrix;
75 orbitope.resize(best);
76 for (
const int g : num_cycles_to_2cyclers[best]) {
78 if (orbitope[0].empty()) {
79 const std::unique_ptr<SparsePermutation>& perm = generators[g];
80 const int num_cycles = perm->NumCycles();
81 for (
int i = 0; i < num_cycles; ++i) {
82 for (
const int x : perm->Cycle(i)) {
83 orbitope[i].push_back(x);
84 if (x >= in_matrix.size()) in_matrix.resize(x + 1,
false);
99 std::vector<int> grow;
100 int matching_column_index = -1;
101 const std::unique_ptr<SparsePermutation>& perm = generators[g];
102 const int num_cycles = perm->NumCycles();
103 for (
int i = 0; i < num_cycles; ++i) {
105 std::vector<int> tmp;
106 for (
const int x : perm->Cycle(i)) tmp.push_back(x);
107 const int a = tmp[0];
108 const int b = tmp[1];
112 int num_matches_a = 0;
113 int num_matches_b = 0;
114 int last_match_index = -1;
115 for (
int j = 0; j < orbitope[i].size(); ++j) {
116 if (orbitope[i][j] ==
a) {
118 last_match_index = j;
119 }
else if (orbitope[i][j] ==
b) {
121 last_match_index = j;
124 if (last_match_index == -1)
break;
125 if (matching_column_index == -1) {
126 matching_column_index = last_match_index;
128 if (matching_column_index != last_match_index)
break;
129 if (num_matches_a == 0 && num_matches_b == 1) {
130 if (
a >= in_matrix.size() || !in_matrix[
a]) grow.push_back(
a);
131 }
else if (num_matches_a == 1 && num_matches_b == 0) {
132 if (
b >= in_matrix.size() || !in_matrix[
b]) grow.push_back(
b);
139 if (grow.size() == num_cycles) {
140 for (
int i = 0; i < orbitope.size(); ++i) {
141 orbitope[i].push_back(grow[i]);
142 if (grow[i] >= in_matrix.size()) in_matrix.resize(grow[i] + 1,
false);
143 in_matrix[grow[i]] =
true;
152 int n,
const std::vector<std::unique_ptr<SparsePermutation>>& generators) {
155 for (
const std::unique_ptr<SparsePermutation>& perm : generators) {
156 const int num_cycles = perm->NumCycles();
157 for (
int i = 0; i < num_cycles; ++i) {
161 for (
const int x : perm->Cycle(i)) {
173 std::vector<int> orbits(n, -1);
174 for (
int i = 0; i < n; ++i) {
177 if (orbits[root] == -1) orbits[root] = num_parts++;
178 orbits[i] = orbits[root];
184 int n,
const std::vector<std::vector<int>>& orbitope) {
185 std::vector<int> orbits(n, -1);
186 for (
int i = 0; i < orbitope.size(); ++i) {
187 for (
int j = 0; j < orbitope[i].size(); ++j) {
188 CHECK_EQ(orbits[orbitope[i][j]], -1);
189 orbits[orbitope[i][j]] = i;
#define CHECK_EQ(val1, val2)
#define VLOG(verboselevel)
int NumNodesInSamePartAs(int node)
void Reset(int num_nodes)
int MergePartsOf(int node1, int node2)
int GetRootAndCompressPath(int node)
std::vector< int > GetOrbitopeOrbits(int n, const std::vector< std::vector< int > > &orbitope)
std::vector< int > GetOrbits(int n, const std::vector< std::unique_ptr< SparsePermutation > > &generators)
std::vector< std::vector< int > > BasicOrbitopeExtraction(const std::vector< std::unique_ptr< SparsePermutation > > &generators)
Collection of objects used to extend the Constraint Solver library.