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 
18 
19 namespace operations_research {
20 namespace glop {
21 
22 // Specialization of SparseVectorEntry and SparseVectorIterator for the
23 // SparseRow class. In addition to index(), it also provides col() for better
24 // readability on the client side.
25 class SparseRowEntry : public SparseVectorEntry<ColIndex> {
26  public:
27  // Returns the row of the current entry.
28  ColIndex col() const { return index(); }
29 
30  protected:
31  SparseRowEntry(const ColIndex* indices, const Fractional* coefficients,
32  EntryIndex i)
33  : SparseVectorEntry<ColIndex>(indices, coefficients, i) {}
34 };
36 
37 // TODO(user): Use this class where appropriate, i.e. when a SparseColumn is
38 // used to store a row vector (by means of RowIndex to ColIndex casting).
39 
40 // A SparseRow is a SparseVector<ColIndex>, with a few methods renamed
41 // to help readability on the client side.
42 class SparseRow : public SparseVector<ColIndex, SparseRowIterator> {
43  public:
45 
46  // Use a separate API to get the column and coefficient of entry #i.
47  ColIndex EntryCol(EntryIndex i) const { return GetIndex(i); }
48  Fractional EntryCoefficient(EntryIndex i) const { return GetCoefficient(i); }
49  ColIndex GetFirstCol() const { return GetFirstIndex(); }
50  ColIndex GetLastCol() const { return GetLastIndex(); }
53  }
56  }
57 };
58 
59 // A matrix stored by rows.
61 
62 } // namespace glop
63 } // namespace operations_research
64 
65 #endif // OR_TOOLS_LP_DATA_SPARSE_ROW_H_
operations_research::glop::SparseRow::ApplyPartialColPermutation
void ApplyPartialColPermutation(const ColumnPermutation &p)
Definition: sparse_row.h:54
operations_research::glop::SparseRow::ApplyColPermutation
void ApplyColPermutation(const ColumnPermutation &p)
Definition: sparse_row.h:51
coefficients
std::vector< double > coefficients
Definition: sat/lp_utils.cc:497
operations_research::glop::SparseRow::GetFirstCol
ColIndex GetFirstCol() const
Definition: sparse_row.h:49
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:48
operations_research::glop::SparseVector
Definition: sparse_vector.h:83
operations_research::glop::RowMajorSparseMatrix
absl::StrongVector< RowIndex, SparseRow > RowMajorSparseMatrix
Definition: sparse_row.h:60
operations_research::glop::SparseRowEntry::col
ColIndex col() const
Definition: sparse_row.h:28
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:25
operations_research::glop::SparseRow::EntryCol
ColIndex EntryCol(EntryIndex i) const
Definition: sparse_row.h:47
operations_research::glop::Permutation< ColIndex >
operations_research::glop::SparseRow::SparseRow
SparseRow()
Definition: sparse_row.h:44
operations_research::glop::SparseVectorEntry
Definition: sparse_vector.h:411
operations_research::glop::SparseRow
Definition: sparse_row.h:42
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:31
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:50
operations_research::glop::SparseVector< ColIndex, SparseRowIterator >::ApplyPartialIndexPermutation
void ApplyPartialIndexPermutation(const IndexPermutation &index_perm)
Definition: sparse_vector.h:934