OR-Tools  8.1
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_
operations_research::glop::SparseRow::ApplyPartialColPermutation
void ApplyPartialColPermutation(const ColumnPermutation &p)
Definition: sparse_row.h:55
operations_research::glop::SparseRow::ApplyColPermutation
void ApplyColPermutation(const ColumnPermutation &p)
Definition: sparse_row.h:52
coefficients
std::vector< double > coefficients
Definition: sat/lp_utils.cc:496
operations_research::glop::SparseRow::GetFirstCol
ColIndex GetFirstCol() const
Definition: sparse_row.h:50
operations_research::glop::SparseVector< ColIndex, SparseRowIterator >::GetFirstIndex
Index GetFirstIndex() const
Definition: sparse_vector.h:279
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::SparseVector< ColIndex, SparseRowIterator >::ApplyIndexPermutation
void ApplyIndexPermutation(const IndexPermutation &index_perm)
Definition: sparse_vector.h:926
operations_research::glop::Fractional
double Fractional
Definition: lp_types.h:77
sparse_vector.h
operations_research::glop::SparseRow::EntryCoefficient
Fractional EntryCoefficient(EntryIndex i) const
Definition: sparse_row.h:49
operations_research::glop::SparseVector
Definition: sparse_vector.h:83
operations_research::glop::RowMajorSparseMatrix
absl::StrongVector< RowIndex, SparseRow > RowMajorSparseMatrix
Definition: sparse_row.h:61
operations_research::glop::SparseRowEntry::col
ColIndex col() const
Definition: sparse_row.h:29
operations_research::glop::SparseVectorEntry< ColIndex >::index
Index index() const
Definition: sparse_vector.h:415
operations_research::glop::SparseVector< ColIndex, SparseRowIterator >::GetIndex
Index GetIndex(EntryIndex i) const
Definition: sparse_vector.h:344
operations_research::glop::SparseRowEntry
Definition: sparse_row.h:26
operations_research::glop::SparseRow::EntryCol
ColIndex EntryCol(EntryIndex i) const
Definition: sparse_row.h:48
operations_research::glop::Permutation< ColIndex >
operations_research::glop::SparseRow::SparseRow
SparseRow()
Definition: sparse_row.h:45
operations_research::glop::SparseVectorEntry
Definition: sparse_vector.h:411
operations_research::glop::SparseRow
Definition: sparse_row.h:43
operations_research::glop::VectorIterator
Definition: lp_types.h:356
absl::StrongVector
Definition: strong_vector.h:76
operations_research::glop::SparseVector< ColIndex, SparseRowIterator >::GetLastIndex
Index GetLastIndex() const
Definition: sparse_vector.h:289
operations_research::glop::SparseRowEntry::SparseRowEntry
SparseRowEntry(const ColIndex *indices, const Fractional *coefficients, EntryIndex i)
Definition: sparse_row.h:32
strong_vector.h
operations_research::glop::SparseVector< ColIndex, SparseRowIterator >::GetCoefficient
Fractional GetCoefficient(EntryIndex i) const
Definition: sparse_vector.h:349
operations_research::glop::SparseRow::GetLastCol
ColIndex GetLastCol() const
Definition: sparse_row.h:51
operations_research::glop::SparseVector< ColIndex, SparseRowIterator >::ApplyPartialIndexPermutation
void ApplyPartialIndexPermutation(const IndexPermutation &index_perm)
Definition: sparse_vector.h:934