OR-Tools
8.1
matrix_utils.h
Go to the documentation of this file.
1
// Copyright 2010-2018 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
17
#include "
ortools/lp_data/lp_types.h
"
18
#include "
ortools/lp_data/sparse.h
"
19
20
namespace
operations_research
{
21
namespace
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.
36
ColMapping
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).
42
ColMapping
FindProportionalColumnsUsingSimpleAlgorithm
(
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).
48
bool
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.
53
bool
IsRightMostSquareMatrixIdentity
(
const
SparseMatrix& matrix);
54
55
}
// namespace glop
56
}
// namespace operations_research
57
58
#endif // OR_TOOLS_LP_DATA_MATRIX_UTILS_H_
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition:
dense_doubly_linked_list.h:21
operations_research::glop::Fractional
double Fractional
Definition:
lp_types.h:77
operations_research::glop::ColMapping
StrictITIVector< ColIndex, ColIndex > ColMapping
Definition:
lp_types.h:305
operations_research::glop::FindProportionalColumns
ColMapping FindProportionalColumns(const SparseMatrix &matrix, Fractional tolerance)
Definition:
matrix_utils.cc:115
operations_research::glop::AreFirstColumnsAndRowsExactlyEquals
bool AreFirstColumnsAndRowsExactlyEquals(RowIndex num_rows, ColIndex num_cols, const SparseMatrix &matrix_a, const CompactSparseMatrix &matrix_b)
Definition:
matrix_utils.cc:190
operations_research::glop::FindProportionalColumnsUsingSimpleAlgorithm
ColMapping FindProportionalColumnsUsingSimpleAlgorithm(const SparseMatrix &matrix, Fractional tolerance)
Definition:
matrix_utils.cc:171
lp_types.h
sparse.h
operations_research::glop::IsRightMostSquareMatrixIdentity
bool IsRightMostSquareMatrixIdentity(const SparseMatrix &matrix)
Definition:
matrix_utils.cc:231
ortools
lp_data
matrix_utils.h
Generated by
1.8.20