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
15
16#include <cstdint>
17#include <utility>
18#include <variant>
19#include <vector>
20
21#include "absl/algorithm/container.h"
22
24
25namespace detail {
26
27std::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
36std::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
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
52std::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
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28