19 #include "absl/synchronization/mutex.h"
31 : original_problem_(nullptr), clusters_(), mutex_() {}
34 absl::MutexLock mutex_lock(&mutex_);
35 original_problem_ = linear_problem;
44 for (ColIndex
ct(0);
ct < num_ct; ++
ct) {
47 const RowIndex first_row = sparse_constraint.
GetFirstRow();
48 for (EntryIndex e(1); e < sparse_constraint.
num_entries(); ++e) {
50 sparse_constraint.
EntryRow(e).value());
55 std::vector<int> classes;
57 clusters_.resize(num_classes);
58 for (
int i = 0; i < classes.size(); ++i) {
59 clusters_[classes[i]].push_back(ColIndex(i));
61 for (
int i = 0; i < num_classes; ++i) {
62 std::sort(clusters_[i].begin(), clusters_[i].
end());
67 absl::MutexLock mutex_lock(&mutex_);
68 return clusters_.size();
72 absl::MutexLock mutex_lock(&mutex_);
73 return *original_problem_;
78 CHECK_GE(problem_index, 0);
79 CHECK_LT(problem_index, clusters_.size());
83 absl::MutexLock mutex_lock(&mutex_);
84 const std::vector<ColIndex>& cluster = clusters_[problem_index];
95 for (
int i = 0; i < cluster.size(); ++i) {
96 const ColIndex global_col = cluster[i];
98 CHECK_EQ(local_col, ColIndex(i));
100 global_to_local[global_col] == local_col)
101 <<
"If the mapping is already assigned it has to be the same.";
102 global_to_local[global_col] = local_col;
115 constraints_to_use.
Set(e.row());
119 for (
const RowIndex global_row :
131 const ColIndex local_col = global_to_local[global_col];
138 const std::vector<DenseRow>& assignments)
const {
139 CHECK_EQ(assignments.size(), clusters_.size());
141 absl::MutexLock mutex_lock(&mutex_);
144 for (
int problem = 0; problem < assignments.size(); ++problem) {
145 const DenseRow& local_assignment = assignments[problem];
146 const std::vector<ColIndex>& cluster = clusters_[problem];
147 for (
int i = 0; i < local_assignment.
size(); ++i) {
148 const ColIndex global_col = cluster[i];
149 global_assignment[global_col] = local_assignment[ColIndex(i)];
152 return global_assignment;
157 CHECK_GE(problem_index, 0);
158 CHECK_LT(problem_index, clusters_.size());
161 absl::MutexLock mutex_lock(&mutex_);
162 const std::vector<ColIndex>& cluster = clusters_[problem_index];
164 for (
int i = 0; i < cluster.size(); ++i) {
165 const ColIndex global_col = cluster[i];
166 local_assignment[ColIndex(i)] = assignment[global_col];
168 return local_assignment;
int MergePartsOf(int node1, int node2)
int FillEquivalenceClasses(std::vector< int > *node_equivalence_classes)
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
void Set(IntegerType index)
void Decompose(const LinearProgram *linear_problem) ABSL_LOCKS_EXCLUDED(mutex_)
const LinearProgram & original_problem() const ABSL_LOCKS_EXCLUDED(mutex_)
void ExtractLocalProblem(int problem_index, LinearProgram *lp) ABSL_LOCKS_EXCLUDED(mutex_)
DenseRow AggregateAssignments(const std::vector< DenseRow > &assignments) const ABSL_LOCKS_EXCLUDED(mutex_)
DenseRow ExtractLocalAssignment(int problem_index, const DenseRow &assignment) ABSL_LOCKS_EXCLUDED(mutex_)
int GetNumberOfProblems() const ABSL_LOCKS_EXCLUDED(mutex_)
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
std::string GetVariableName(ColIndex col) const
void SetConstraintName(RowIndex row, absl::string_view name)
const SparseMatrix & GetTransposeSparseMatrix() const
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
const SparseMatrix & GetSparseMatrix() const
void SetVariableName(ColIndex col, absl::string_view name)
const DenseRow & variable_lower_bounds() const
const DenseColumn & constraint_lower_bounds() const
const DenseRow & objective_coefficients() const
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
ColIndex CreateNewVariable()
VariableType GetVariableType(ColIndex col) const
void SetVariableType(ColIndex col, VariableType type)
std::string GetConstraintName(RowIndex row) const
const DenseColumn & constraint_upper_bounds() const
void SetObjectiveCoefficient(ColIndex col, Fractional value)
bool IsMaximizationProblem() const
const DenseRow & variable_upper_bounds() const
ColIndex num_variables() const
RowIndex CreateNewConstraint()
void SetMaximizationProblem(bool maximize)
RowIndex num_constraints() const
RowIndex GetFirstRow() const
RowIndex EntryRow(EntryIndex i) const
const SparseColumn & column(ColIndex col) const
typename Iterator::Entry Entry
EntryIndex num_entries() const
constexpr ColIndex kInvalidCol(-1)
ColIndex RowToColIndex(RowIndex row)
Collection of objects used to extend the Constraint Solver library.
std::optional< int64_t > end