OR-Tools  8.2
sparse_column.cc
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
15
16#include <algorithm>
17
19
20namespace operations_research {
21namespace glop {
22
23// --------------------------------------------------------
24// RandomAccessSparseColumn
25// --------------------------------------------------------
27 : column_(num_rows, 0.0), changed_(num_rows, false), row_change_() {}
28
30
32 const size_t num_changes = row_change_.size();
33 for (int i = 0; i < num_changes; ++i) {
34 const RowIndex row = row_change_[i];
35 column_[row] = Fractional(0.0);
36 changed_[row] = false;
37 }
38 row_change_.clear();
39}
40
41void RandomAccessSparseColumn::Resize(RowIndex num_rows) {
42 if (num_rows <= column_.size()) {
43 return;
44 }
45 column_.resize(num_rows, 0.0);
46 changed_.resize(num_rows, false);
47}
48
50 const SparseColumn& sparse_column) {
51 Clear();
52 for (const SparseColumn::Entry e : sparse_column) {
53 SetCoefficient(e.row(), e.coefficient());
54 }
55}
56
58 SparseColumn* sparse_column) const {
59 RETURN_IF_NULL(sparse_column);
60
61 sparse_column->Clear();
62 const size_t num_changes = row_change_.size();
63 for (int change_id = 0; change_id < num_changes; ++change_id) {
64 const RowIndex row = row_change_[change_id];
65 const Fractional value = column_[row];
66
67 // TODO(user): Do that only if (value != 0.0) ?
68 sparse_column->SetCoefficient(row, value);
69 }
70
71 DCHECK(sparse_column->CheckNoDuplicates());
72}
73
74} // namespace glop
75} // namespace operations_research
#define DCHECK(condition)
Definition: base/logging.h:884
void PopulateSparseColumn(SparseColumn *sparse_column) const
void PopulateFromSparseColumn(const SparseColumn &sparse_column)
void SetCoefficient(RowIndex row, Fractional value)
void SetCoefficient(Index index, Fractional value)
int64 value
RowIndex row
Definition: markowitz.cc:175
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
#define RETURN_IF_NULL(x)
Definition: return_macros.h:20