OR-Tools
8.1
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
14
#include "
ortools/lp_data/sparse_column.h
"
15
16
#include <algorithm>
17
18
#include "
ortools/lp_data/lp_types.h
"
19
20
namespace
operations_research
{
21
namespace
glop {
22
23
// --------------------------------------------------------
24
// RandomAccessSparseColumn
25
// --------------------------------------------------------
26
RandomAccessSparseColumn::RandomAccessSparseColumn
(RowIndex num_rows)
27
: column_(num_rows, 0.0), changed_(num_rows, false), row_change_() {}
28
29
RandomAccessSparseColumn::~RandomAccessSparseColumn
() {}
30
31
void
RandomAccessSparseColumn::Clear
() {
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
41
void
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
49
void
RandomAccessSparseColumn::PopulateFromSparseColumn
(
50
const
SparseColumn
& sparse_column) {
51
Clear
();
52
for
(
const
SparseColumn::Entry
e : sparse_column) {
53
SetCoefficient
(e.row(), e.coefficient());
54
}
55
}
56
57
void
RandomAccessSparseColumn::PopulateSparseColumn
(
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
operations_research::glop::StrictITIVector::resize
void resize(IntType size)
Definition:
lp_types.h:269
operations_research::glop::SparseVector::Clear
void Clear()
Definition:
sparse_vector.h:479
operations_research::glop::RandomAccessSparseColumn::Clear
void Clear()
Definition:
sparse_column.cc:31
value
int64 value
Definition:
demon_profiler.cc:43
operations_research::glop::SparseVector::CheckNoDuplicates
bool CheckNoDuplicates() const
Definition:
sparse_vector.h:669
operations_research::glop::RandomAccessSparseColumn::Resize
void Resize(RowIndex num_rows)
Definition:
sparse_column.cc:41
operations_research::glop::StrictITIVector::size
IntType size() const
Definition:
lp_types.h:276
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::RandomAccessSparseColumn::SetCoefficient
void SetCoefficient(RowIndex row, Fractional value)
Definition:
sparse_column.h:145
operations_research::glop::SparseColumn
Definition:
sparse_column.h:44
operations_research::glop::RandomAccessSparseColumn::PopulateSparseColumn
void PopulateSparseColumn(SparseColumn *sparse_column) const
Definition:
sparse_column.cc:57
RETURN_IF_NULL
#define RETURN_IF_NULL(x)
Definition:
return_macros.h:20
operations_research::glop::Fractional
double Fractional
Definition:
lp_types.h:77
operations_research::glop::RandomAccessSparseColumn::PopulateFromSparseColumn
void PopulateFromSparseColumn(const SparseColumn &sparse_column)
Definition:
sparse_column.cc:49
DCHECK
#define DCHECK(condition)
Definition:
base/logging.h:884
operations_research::glop::SparseVector::SetCoefficient
void SetCoefficient(Index index, Fractional value)
Definition:
sparse_vector.h:680
operations_research::glop::RandomAccessSparseColumn::~RandomAccessSparseColumn
virtual ~RandomAccessSparseColumn()
Definition:
sparse_column.cc:29
operations_research::glop::SparseVector< RowIndex, SparseColumnIterator >::Entry
typename Iterator::Entry Entry
Definition:
sparse_vector.h:91
operations_research::glop::RandomAccessSparseColumn::RandomAccessSparseColumn
RandomAccessSparseColumn(RowIndex num_rows)
Definition:
sparse_column.cc:26
row
RowIndex row
Definition:
markowitz.cc:175
lp_types.h
sparse_column.h
ortools
lp_data
sparse_column.cc
Generated by
1.8.20