17#ifndef OR_TOOLS_MATH_OPT_CPP_MAP_FILTER_H_
18#define OR_TOOLS_MATH_OPT_CPP_MAP_FILTER_H_
20#include <initializer_list>
23#include "absl/algorithm/container.h"
24#include "absl/container/flat_hash_set.h"
25#include "absl/status/status.h"
26#include "absl/status/statusor.h"
32#include "ortools/math_opt/sparse_containers.pb.h"
59template <
typename KeyType>
103 const ModelStorage* expected_storage)
const;
109 SparseVectorFilterProto
Proto()
const;
130absl::StatusOr<MapFilter<QuadraticConstraint>>
132 const SparseVectorFilterProto&
proto);
141template <
typename KeyType>
153template <
typename KeyType>
165template <
typename Collection,
166 typename ValueType =
typename Collection::value_type>
182template <
typename KeyType>
193template <
typename KeyType>
195 const ModelStorage* expected_storage)
const {
196 if (!filtered_keys.has_value()) {
197 return absl::OkStatus();
199 for (
const KeyType& k : filtered_keys.value()) {
204 return absl::OkStatus();
207template <
typename KeyType>
209 SparseVectorFilterProto ret;
210 ret.set_skip_zero_values(skip_zero_values);
211 if (filtered_keys.has_value()) {
212 ret.set_filter_by_ids(
true);
213 auto& filtered_ids = *ret.mutable_filtered_ids();
214 filtered_ids.Reserve(
static_cast<int>(filtered_keys.value().size()));
215 for (
const auto k : filtered_keys.value()) {
216 filtered_ids.Add(k.typed_id().value());
219 absl::c_sort(filtered_ids);
#define RETURN_IF_ERROR(expr)
CpModelProto proto
The output proto.
absl::Status CheckModelStorage(const ModelStorage *const storage, const ModelStorage *const expected_storage)
An object oriented wrapper for quadratic constraints in ModelStorage.
MapFilter< KeyType > MakeSkipAllFilter()
absl::StatusOr< MapFilter< LinearConstraint > > LinearConstraintFilterFromProto(const Model &model, const SparseVectorFilterProto &proto)
MapFilter< ValueType > MakeKeepKeysFilter(const Collection &keys)
absl::StatusOr< MapFilter< QuadraticConstraint > > QuadraticConstraintFilterFromProto(const Model &model, const SparseVectorFilterProto &proto)
MapFilter< KeyType > MakeSkipZerosFilter()
absl::StatusOr< MapFilter< Variable > > VariableFilterFromProto(const Model &model, const SparseVectorFilterProto &proto)
absl::Status CheckModelStorage(const ModelStorage *expected_storage) const
std::optional< absl::flat_hash_set< KeyType > > filtered_keys
SparseVectorFilterProto Proto() const