OR-Tools  9.3
sharded_quadratic_program.h
Go to the documentation of this file.
1// Copyright 2010-2021 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 PDLP_SHARDED_QUADRATIC_PROGRAM_H_
15#define PDLP_SHARDED_QUADRATIC_PROGRAM_H_
16
17#include <cstdint>
18#include <memory>
19
20#include "Eigen/Core"
21#include "Eigen/SparseCore"
25
27
28// This class stores:
29// - A QuadraticProgram (QP)
30// - A transposed version of the QP's constraint matrix
31// - A thread pool
32// - Various Sharder objects for doing sharded matrix and vector computations.
34 public:
35 // Requires num_shards >= num_threads >= 1.
36 // Note that the qp is intentionally passed by value.
37 ShardedQuadraticProgram(QuadraticProgram qp, int num_threads, int num_shards);
38
39 // Movable but not copyable.
44
45 const QuadraticProgram& Qp() const { return qp_; }
46
47 // Returns a reference to the transpose of the QP's constraint matrix.
48 const Eigen::SparseMatrix<double, Eigen::ColMajor, int64_t>&
50 return transposed_constraint_matrix_;
51 }
52
53 // Returns a Sharder intended for the columns of the QP's constraint matrix.
55 return constraint_matrix_sharder_;
56 }
57 // Returns a Sharder intended for the rows of the QP's constraint matrix.
59 return transposed_constraint_matrix_sharder_;
60 }
61 // Returns a Sharder intended for primal vectors.
62 const Sharder& PrimalSharder() const { return primal_sharder_; }
63 // Returns a Sharder intended for dual vectors.
64 const Sharder& DualSharder() const { return dual_sharder_; }
65
66 int64_t PrimalSize() const { return qp_.variable_lower_bounds.size(); }
67 int64_t DualSize() const { return qp_.constraint_lower_bounds.size(); }
68
69 // Rescale the QP (including objective, variable bounds, constraint bounds,
70 // constraint matrix, and transposed constraint matrix) based on
71 // col_scaling_vec and row_scaling_vec. That is, rescale the problem so that
72 // each variable is rescaled as variable[i] <- variable[i] /
73 // col_scaling_vec[i], and the j-th constraint is multiplied by
74 // row_scaling_vec[j]. col_scaling_vec and row_scaling_vec must be positive.
75 void RescaleQuadraticProgram(const Eigen::VectorXd& col_scaling_vec,
76 const Eigen::VectorXd& row_scaling_vec);
77
78 private:
80 Eigen::SparseMatrix<double, Eigen::ColMajor, int64_t>
81 transposed_constraint_matrix_;
82 std::unique_ptr<ThreadPool> thread_pool_;
83 Sharder constraint_matrix_sharder_;
84 Sharder transposed_constraint_matrix_sharder_;
85 Sharder primal_sharder_;
86 Sharder dual_sharder_;
87};
88
89} // namespace operations_research::pdlp
90
91#endif // PDLP_SHARDED_QUADRATIC_PROGRAM_H_
ShardedQuadraticProgram & operator=(ShardedQuadraticProgram &&)=default
void RescaleQuadraticProgram(const Eigen::VectorXd &col_scaling_vec, const Eigen::VectorXd &row_scaling_vec)
const Eigen::SparseMatrix< double, Eigen::ColMajor, int64_t > & TransposedConstraintMatrix() const
ShardedQuadraticProgram(QuadraticProgram qp, int num_threads, int num_shards)
ShardedQuadraticProgram(ShardedQuadraticProgram &&)=default
ShardedQuadraticProgram(const ShardedQuadraticProgram &)=delete
ShardedQuadraticProgram & operator=(const ShardedQuadraticProgram &)=delete