Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
sparse_column.cc
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
15
16#include <algorithm>
17
18#include "absl/log/check.h"
21
22namespace operations_research {
23namespace glop {
24
25// --------------------------------------------------------
26// RandomAccessSparseColumn
27// --------------------------------------------------------
29 : column_(num_rows, 0.0), changed_(num_rows, false), row_change_() {}
31RandomAccessSparseColumn::~RandomAccessSparseColumn() = default;
32
33void RandomAccessSparseColumn::Clear() {
34 const size_t num_changes = row_change_.size();
35 for (int i = 0; i < num_changes; ++i) {
36 const RowIndex row = row_change_[i];
37 column_[row] = Fractional(0.0);
38 changed_[row] = false;
39 }
40 row_change_.clear();
41}
42
43void RandomAccessSparseColumn::Resize(RowIndex num_rows) {
44 if (num_rows <= column_.size()) {
45 return;
46 }
47 column_.resize(num_rows, 0.0);
48 changed_.resize(num_rows, false);
49}
50
51void RandomAccessSparseColumn::PopulateFromSparseColumn(
52 const SparseColumn& sparse_column) {
53 Clear();
54 for (const SparseColumn::Entry e : sparse_column) {
55 SetCoefficient(e.row(), e.coefficient());
56 }
57}
58
59void RandomAccessSparseColumn::PopulateSparseColumn(
60 SparseColumn* sparse_column) const {
61 RETURN_IF_NULL(sparse_column);
62
63 sparse_column->Clear();
64 const size_t num_changes = row_change_.size();
65 for (int change_id = 0; change_id < num_changes; ++change_id) {
66 const RowIndex row = row_change_[change_id];
67 const Fractional value = column_[row];
68
69 // TODO(user): Do that only if (value != 0.0) ?
70 sparse_column->SetCoefficient(row, value);
71 }
72
73 DCHECK(sparse_column->CheckNoDuplicates());
74}
75
76} // namespace glop
77} // namespace operations_research
int64_t value
RowIndex row
Definition markowitz.cc:186
For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is false
problem is infeasible or unbounded (default).
Definition matchers.h:468
In SWIG mode, we don't want anything besides these top-level includes.
#define RETURN_IF_NULL(x)