Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
sparse_row.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_SPARSE_ROW_H_
15#define OR_TOOLS_LP_DATA_SPARSE_ROW_H_
16
19
20namespace operations_research {
21namespace glop {
22
23// Specialization of SparseVectorEntry and SparseVectorIterator for the
24// SparseRow class. In addition to index(), it also provides col() for better
25// readability on the client side.
26class SparseRowEntry : public SparseVectorEntry<ColIndex> {
27 public:
28 // Returns the row of the current entry.
29 ColIndex col() const { return index(); }
30
31 protected:
32 SparseRowEntry(const ColIndex* indices, const Fractional* coefficients,
33 EntryIndex i)
34 : SparseVectorEntry<ColIndex>(indices, coefficients, i) {}
35};
37
38// TODO(user): Use this class where appropriate, i.e. when a SparseColumn is
39// used to store a row vector (by means of RowIndex to ColIndex casting).
40
41// A SparseRow is a SparseVector<ColIndex>, with a few methods renamed
42// to help readability on the client side.
43class SparseRow : public SparseVector<ColIndex, SparseRowIterator> {
44 public:
46
47 // Use a separate API to get the column and coefficient of entry #i.
48 ColIndex EntryCol(EntryIndex i) const { return GetIndex(i); }
49 Fractional EntryCoefficient(EntryIndex i) const { return GetCoefficient(i); }
50 ColIndex GetFirstCol() const { return GetFirstIndex(); }
51 ColIndex GetLastCol() const { return GetLastIndex(); }
58};
59
60// A matrix stored by rows.
62
63} // namespace glop
64} // namespace operations_research
65
66#endif // OR_TOOLS_LP_DATA_SPARSE_ROW_H_
ColIndex col() const
Returns the row of the current entry.
Definition sparse_row.h:29
SparseRowEntry(const ColIndex *indices, const Fractional *coefficients, EntryIndex i)
Definition sparse_row.h:32
Fractional EntryCoefficient(EntryIndex i) const
Definition sparse_row.h:49
void ApplyColPermutation(const ColumnPermutation &p)
Definition sparse_row.h:52
ColIndex EntryCol(EntryIndex i) const
Use a separate API to get the column and coefficient of entry #i.
Definition sparse_row.h:48
void ApplyPartialColPermutation(const ColumnPermutation &p)
Definition sparse_row.h:55
void ApplyPartialIndexPermutation(const IndexPermutation &index_perm)
absl::Span< const double > coefficients
util_intops::StrongVector< RowIndex, SparseRow > RowMajorSparseMatrix
A matrix stored by rows.
Definition sparse_row.h:61
In SWIG mode, we don't want anything besides these top-level includes.