Google OR-Tools
v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
element_storage.cc
Go to the documentation of this file.
1
// Copyright 2010-2025 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/math_opt/elemental/element_storage.h
"
15
16
#include <cstdint>
17
#include <utility>
18
#include <variant>
19
#include <vector>
20
21
#include "absl/algorithm/container.h"
22
23
namespace
operations_research::math_opt
{
24
25
namespace
detail
{
26
27
std::vector<int64_t>
SparseElementStorage::AllIds
()
const
{
28
std::vector<int64_t> result;
29
result.reserve(elements_.size());
30
for
(
const
auto
& [
id
, unused] : elements_) {
31
result.push_back(
id
);
32
}
33
return
result;
34
}
35
36
std::vector<int64_t>
DenseElementStorage::AllIds
()
const
{
37
std::vector<int64_t> result(elements_.size());
38
absl::c_iota(result, 0);
39
return
result;
40
}
41
42
SparseElementStorage::SparseElementStorage
(
DenseElementStorage
&& dense)
43
: next_id_(dense.
size
()) {
44
elements_.reserve(next_id_);
45
for
(
int
i = 0; i < next_id_; ++i) {
46
elements_.emplace(i, std::move(dense.elements_[i]));
47
}
48
}
49
50
}
// namespace detail
51
52
std::vector<int64_t>
ElementStorage::AllIds
()
const
{
53
return
std::visit([](
const
auto
& impl) {
return
impl.AllIds(); }, impl_);
54
}
55
56
}
// namespace operations_research::math_opt
operations_research::math_opt::ElementStorage::AllIds
std::vector< int64_t > AllIds() const
Definition
element_storage.cc:52
operations_research::math_opt::detail::DenseElementStorage
Definition
element_storage.h:37
operations_research::math_opt::detail::DenseElementStorage::AllIds
std::vector< int64_t > AllIds() const
Definition
element_storage.cc:36
operations_research::math_opt::detail::SparseElementStorage::size
int64_t size() const
Definition
element_storage.h:94
operations_research::math_opt::detail::SparseElementStorage::SparseElementStorage
SparseElementStorage(DenseElementStorage &&dense)
Definition
element_storage.cc:42
operations_research::math_opt::detail::SparseElementStorage::AllIds
std::vector< int64_t > AllIds() const
Definition
element_storage.cc:27
element_storage.h
operations_research::math_opt::detail
Definition
attr_key.h:232
operations_research::math_opt
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition
gurobi_isv.cc:28
ortools
math_opt
elemental
element_storage.cc
Generated by
1.14.0