14#ifndef ORTOOLS_MATH_OPT_STORAGE_SPARSE_COEFFICIENT_MAP_H_
15#define ORTOOLS_MATH_OPT_STORAGE_SPARSE_COEFFICIENT_MAP_H_
19#include "absl/container/flat_hash_map.h"
20#include "absl/meta/type_traits.h"
38 absl::flat_hash_map<VariableId, double>
terms);
46 const absl::flat_hash_map<VariableId, double>&
terms()
const {
58 absl::flat_hash_map<VariableId, double> terms_;
66 absl::flat_hash_map<VariableId, double> terms)
68 absl::erase_if(terms_, [](
const auto& term) {
return term.second == 0.0; });
72 const auto it = terms_.find(
id);
73 if (it == terms_.end()) {
81 return terms_.erase(
id) > 0;
83 const auto [iterator, inserted] = terms_.try_emplace(
id, coeff);
87 if (iterator->second != coeff) {
88 iterator->second = coeff;
SparseCoefficientMap()=default
bool set(VariableId id, double coeff)
SparseDoubleVectorProto Proto() const
const absl::flat_hash_map< VariableId, double > & terms() const
double get(VariableId id) const
void erase(VariableId id)
ElementId< ElementType::kVariable > VariableId