Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
matrix_utils.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_MATRIX_UTILS_H_
15#define OR_TOOLS_LP_DATA_MATRIX_UTILS_H_
16
19
20namespace operations_research {
21namespace glop {
22
23// Finds the proportional columns of the given matrix: all the pairs of columns
24// such that one is a non-zero scalar multiple of the other. The returned
25// mapping for a given column will either be:
26// - The index of the first column which is proportional with this one.
27// - Or kInvalidCol if this column is not proportional to any other.
28//
29// Because of precision errors, two columns are declared proportional if the
30// multiples (>= 1.0) defined by all the couple of coefficients of the same row
31// are equal up to the given absolute tolerance.
32//
33// The complexity is in most cases O(num entries of the matrix). However,
34// compared to the less efficient algorithm below, it is highly unlikely but
35// possible that some pairs of proportional columns are not detected.
36ColMapping FindProportionalColumns(const SparseMatrix& matrix,
37 Fractional tolerance);
38
39// A simple version of FindProportionalColumns() that compares all the columns
40// pairs one by one. This is slow, but here for reference. The complexity is
41// O(num_cols * num_entries).
43 const SparseMatrix& matrix, Fractional tolerance);
44
45// Returns true iff the two given matrices have exactly the same first num_rows
46// entries on the first num_cols columns. The two given matrices must be ordered
47// by rows (this is DCHECKed, but only for the first one at this point).
48bool AreFirstColumnsAndRowsExactlyEquals(RowIndex num_rows, ColIndex num_cols,
49 const SparseMatrix& matrix_a,
50 const CompactSparseMatrix& matrix_b);
51
52// Returns true iff the rightmost square matrix is an identity matrix.
53bool IsRightMostSquareMatrixIdentity(const SparseMatrix& matrix);
54
55} // namespace glop
56} // namespace operations_research
57
58#endif // OR_TOOLS_LP_DATA_MATRIX_UTILS_H_
StrictITIVector< ColIndex, ColIndex > ColMapping
Row of column indices. Used to represent mappings between columns.
Definition lp_types.h:359
ColMapping FindProportionalColumnsUsingSimpleAlgorithm(const SparseMatrix &matrix, Fractional tolerance)
bool IsRightMostSquareMatrixIdentity(const SparseMatrix &matrix)
Returns true iff the rightmost square matrix is an identity matrix.
bool AreFirstColumnsAndRowsExactlyEquals(RowIndex num_rows, ColIndex num_cols, const SparseMatrix &matrix_a, const CompactSparseMatrix &matrix_b)
ColMapping FindProportionalColumns(const SparseMatrix &matrix, Fractional tolerance)
In SWIG mode, we don't want anything besides these top-level includes.