20 #include "absl/strings/str_join.h"
29 std::vector<bool> should_be_deleted(
NumCycles(),
false);
30 for (
int i : cycle_indices) {
33 DCHECK(!should_be_deleted[i])
34 <<
"Duplicate index given to RemoveCycles(): " << i;
35 should_be_deleted[i] =
true;
37 int new_cycles_size = 0;
38 int new_cycle_ends_size = 0;
41 const int end = cycle_ends_[i];
42 if (!should_be_deleted[i]) {
44 cycles_[new_cycles_size++] = cycles_[j];
46 cycle_ends_[new_cycle_ends_size++] = new_cycles_size;
50 cycles_.resize(new_cycles_size);
51 cycle_ends_.resize(new_cycle_ends_size);
55 DCHECK_EQ(cycles_.empty(), cycle_ends_.empty());
56 if (!cycles_.empty()) DCHECK_EQ(cycles_.size(), cycle_ends_.back());
57 std::vector<std::vector<int>> cycles;
59 for (
const int end : cycle_ends_) {
62 for (
int i =
start + 1; i <
end; ++i) {
63 if (cycles_[i] < cycles_[min_pos]) min_pos = i;
65 std::vector<int> cycle;
66 for (
int i = min_pos; i <
end; ++i) cycle.push_back(cycles_[i]);
67 for (
int i =
start; i < min_pos; ++i) cycle.push_back(cycles_[i]);
68 cycles.push_back(cycle);
71 std::sort(cycles.begin(), cycles.end());
73 for (
const std::vector<int>& cycle : cycles) {
74 if (!out.empty()) out +=
" ";
76 out += absl::StrJoin(cycle,
" ");
std::string DebugString() const
void RemoveCycles(const std::vector< int > &cycle_indices)
Collection of objects used to extend the Constraint Solver library.
std::optional< int64_t > end