[CP-SAT] Fix #4373

This commit is contained in:
Laurent Perron
2024-09-27 14:55:35 +02:00
parent 3c7bc49090
commit c4fac77174
11 changed files with 275 additions and 77 deletions

View File

@@ -81,4 +81,30 @@ std::string SparsePermutation::DebugString() const {
return out;
}
int SparsePermutation::Image(int element) const {
for (int c = 0; c < NumCycles(); ++c) {
int cur_element = LastElementInCycle(c);
for (int image : Cycle(c)) {
if (cur_element == element) {
return image;
}
cur_element = image;
}
}
return element;
}
int SparsePermutation::InverseImage(int element) const {
for (int c = 0; c < NumCycles(); ++c) {
int cur_element = LastElementInCycle(c);
for (int image : Cycle(c)) {
if (image == element) {
return cur_element;
}
cur_element = image;
}
}
return element;
}
} // namespace operations_research