OR-Tools  8.2
sparse_row.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_SPARSE_ROW_H_
15 #define OR_TOOLS_LP_DATA_SPARSE_ROW_H_
16 
19 
20 namespace operations_research {
21 namespace 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.
26 class 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.
43 class 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(); }
54  }
57  }
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_
Definition: sparse_row.h:26
SparseRowEntry(const ColIndex *indices, const Fractional *coefficients, EntryIndex i)
Definition: sparse_row.h:32
ColIndex col() const
Definition: sparse_row.h:29
void ApplyColPermutation(const ColumnPermutation &p)
Definition: sparse_row.h:52
void ApplyPartialColPermutation(const ColumnPermutation &p)
Definition: sparse_row.h:55
Fractional EntryCoefficient(EntryIndex i) const
Definition: sparse_row.h:49
ColIndex EntryCol(EntryIndex i) const
Definition: sparse_row.h:48
Index index() const
void ApplyPartialIndexPermutation(const IndexPermutation &index_perm)
absl::StrongVector< RowIndex, SparseRow > RowMajorSparseMatrix
Definition: sparse_row.h:61
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
std::vector< double > coefficients