Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
lp_decomposer.h
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef OR_TOOLS_LP_DATA_LP_DECOMPOSER_H_
15#define OR_TOOLS_LP_DATA_LP_DECOMPOSER_H_
16
17#include <memory>
18#include <vector>
19
20#include "absl/base/thread_annotations.h"
21#include "absl/synchronization/mutex.h"
22#include "absl/types/span.h"
25
26namespace operations_research {
27namespace glop {
28
29// This class is used to decompose an existing LinearProgram into several
30// independent LinearPrograms. Problems are independent when none of their
31// variables are connected, i.e. appear in the same constraints.
32// Consider for instance the following problem:
33// min: x + 2 y + 3 z + 4 t + 5 u
34// c1: 0 <= x + z <= 1;
35// c2: 0 <= y + t <= 1;
36// c3: 0 <= x + u <= 1;
37// int: x, y, z, t, u
38// Variables x, z and u are connected by constraints c1 and c3.
39// Variables y and t are connected by constraints c2.
40// The problem can be decomposed into two independent problems:
41// min: x + 3 z + 5 u
42// c1: 0 <= x + z <= 1;
43// c3: 0 <= x + u <= 1;
44// int: x, z, u
45// and
46// min: 2 y + 4 t
47// c2: 0 <= y + t <= 1;
48// int: y, t
49//
50// Note that a solution to those two independent problems is a solution to the
51// original problem.
53 public:
55
56 // This type is neither copyable nor movable.
57 LPDecomposer(const LPDecomposer&) = delete;
59
60 // Decomposes the problem into independent problems.
61 // Note that a pointer is kept (no copy) on the linear_problem, so the problem
62 // should not change during the life of the LPDecomposer object.
63 void Decompose(const LinearProgram* linear_problem)
64 ABSL_LOCKS_EXCLUDED(mutex_);
65
66 // Returns the number of independent problems generated by Decompose().
67 int GetNumberOfProblems() const ABSL_LOCKS_EXCLUDED(mutex_);
68
69 // Returns the original problem, i.e. as it was before any decomposition.
70 const LinearProgram& original_problem() const ABSL_LOCKS_EXCLUDED(mutex_);
71
72 // Fills lp with the problem_index^th independent problem generated by
73 // Decompose().
74 // Note that this method runs in O(num-entries-in-generated-problem).
75 void ExtractLocalProblem(int problem_index, LinearProgram* lp)
76 ABSL_LOCKS_EXCLUDED(mutex_);
77
78 // Returns an assignment to the original problem based on the assignments
79 // to the independent problems. Requires Decompose() to have been called.
80 DenseRow AggregateAssignments(absl::Span<const DenseRow> assignments) const
81 ABSL_LOCKS_EXCLUDED(mutex_);
82
83 // Returns an assignment to the given subproblem based on the assignment to
84 // the original problem. Requires Decompose() to have been called.
85 DenseRow ExtractLocalAssignment(int problem_index, const DenseRow& assignment)
86 ABSL_LOCKS_EXCLUDED(mutex_);
87
88 private:
89 const LinearProgram* original_problem_;
90 std::vector<std::vector<ColIndex>> clusters_;
91
92 mutable absl::Mutex mutex_;
93};
94
95} // namespace glop
96} // namespace operations_research
97
98#endif // OR_TOOLS_LP_DATA_LP_DECOMPOSER_H_
const LinearProgram & original_problem() const ABSL_LOCKS_EXCLUDED(mutex_)
Returns the original problem, i.e. as it was before any decomposition.
DenseRow ExtractLocalAssignment(int problem_index, const DenseRow &assignment) ABSL_LOCKS_EXCLUDED(mutex_)
DenseRow AggregateAssignments(absl::Span< const DenseRow > assignments) const ABSL_LOCKS_EXCLUDED(mutex_)
LPDecomposer & operator=(const LPDecomposer &)=delete
int GetNumberOfProblems() const ABSL_LOCKS_EXCLUDED(mutex_)
Returns the number of independent problems generated by Decompose().
void Decompose(const LinearProgram *linear_problem) ABSL_LOCKS_EXCLUDED(mutex_)
LPDecomposer(const LPDecomposer &)=delete
This type is neither copyable nor movable.
void ExtractLocalProblem(int problem_index, LinearProgram *lp) ABSL_LOCKS_EXCLUDED(mutex_)
In SWIG mode, we don't want anything besides these top-level includes.
STL namespace.