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;
#define CHECK_LT(val1, val2)
#define CHECK_EQ(val1, val2)
#define CHECK_GE(val1, val2)
int MergePartsOf(int node1, int node2)
int FillEquivalenceClasses(std::vector< int > *node_equivalence_classes)
void Set(IntegerType index)
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
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)
void SetVariableName(ColIndex col, absl::string_view name)
const DenseColumn & constraint_lower_bounds() const
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
ColIndex CreateNewVariable()
VariableType GetVariableType(ColIndex col) const
const DenseRow & variable_upper_bounds() const
void SetVariableType(ColIndex col, VariableType type)
std::string GetConstraintName(RowIndex row) const
const DenseColumn & constraint_upper_bounds() const
const DenseRow & objective_coefficients() const
void SetObjectiveCoefficient(ColIndex col, Fractional value)
bool IsMaximizationProblem() const
ColIndex num_variables() const
const SparseMatrix & GetSparseMatrix() const
RowIndex CreateNewConstraint()
const DenseRow & variable_lower_bounds() const
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
const ColIndex kInvalidCol(-1)
ColIndex RowToColIndex(RowIndex row)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...