18 #include "absl/synchronization/mutex.h"
30 : original_problem_(nullptr), clusters_(), mutex_() {}
33 absl::MutexLock mutex_lock(&mutex_);
34 original_problem_ = linear_problem;
43 for (ColIndex
ct(0);
ct < num_ct; ++
ct) {
46 const RowIndex first_row = sparse_constraint.
GetFirstRow();
47 for (EntryIndex e(1); e < sparse_constraint.
num_entries(); ++e) {
49 sparse_constraint.
EntryRow(e).value());
54 std::vector<int> classes;
56 clusters_.resize(num_classes);
57 for (
int i = 0; i < classes.size(); ++i) {
58 clusters_[classes[i]].push_back(ColIndex(i));
60 for (
int i = 0; i < num_classes; ++i) {
61 std::sort(clusters_[i].begin(), clusters_[i].end());
66 absl::MutexLock mutex_lock(&mutex_);
67 return clusters_.size();
71 absl::MutexLock mutex_lock(&mutex_);
72 return *original_problem_;
78 CHECK_LT(problem_index, clusters_.size());
82 absl::MutexLock mutex_lock(&mutex_);
83 const std::vector<ColIndex>& cluster = clusters_[problem_index];
94 for (
int i = 0; i < cluster.size(); ++i) {
95 const ColIndex global_col = cluster[i];
99 global_to_local[global_col] == local_col)
100 <<
"If the mapping is already assigned it has to be the same.";
101 global_to_local[global_col] = local_col;
114 constraints_to_use.
Set(e.row());
118 for (
const RowIndex global_row :
130 const ColIndex local_col = global_to_local[global_col];
137 const std::vector<DenseRow>& assignments)
const {
138 CHECK_EQ(assignments.size(), clusters_.size());
140 absl::MutexLock mutex_lock(&mutex_);
143 for (
int problem = 0; problem < assignments.size(); ++problem) {
144 const DenseRow& local_assignment = assignments[problem];
145 const std::vector<ColIndex>& cluster = clusters_[problem];
146 for (
int i = 0; i < local_assignment.
size(); ++i) {
147 const ColIndex global_col = cluster[i];
148 global_assignment[global_col] = local_assignment[ColIndex(i)];
151 return global_assignment;
157 CHECK_LT(problem_index, clusters_.size());
160 absl::MutexLock mutex_lock(&mutex_);
161 const std::vector<ColIndex>& cluster = clusters_[problem_index];
163 for (
int i = 0; i < cluster.size(); ++i) {
164 const ColIndex global_col = cluster[i];
165 local_assignment[ColIndex(i)] = assignment[global_col];
167 return local_assignment;