14#ifndef OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_
15#define OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_
22#include "absl/container/flat_hash_set.h"
23#include "ortools/math_opt/callback.pb.h"
24#include "ortools/math_opt/model.pb.h"
25#include "ortools/math_opt/model_update.pb.h"
26#include "ortools/math_opt/sparse_containers.pb.h"
32 return variables.ids_size();
36 return linear_constraints.ids_size();
40 return matrix.row_ids_size();
72 template <
typename Value>
76 const SparseVectorFilterProto& filter_;
79 int next_filtered_id_index_ = 0;
85 int next_input_id_lower_bound_ = 0;
90absl::flat_hash_set<CallbackEventProto>
EventSet(
91 const CallbackRegistrationProto& callback_registration);
97template <
typename Value>
101 CHECK_GE(
id, next_input_id_lower_bound_)
102 <<
"This function must be called with strictly increasing ids.";
106 next_input_id_lower_bound_ =
id + 1;
113 if (filter_.skip_zero_values() &&
value == 0) {
117 if (!filter_.filter_by_ids()) {
122 while (next_filtered_id_index_ < filter_.filtered_ids_size() &&
123 filter_.filtered_ids(next_filtered_id_index_) <
id) {
124 ++next_filtered_id_index_;
127 if (next_filtered_id_index_ == filter_.filtered_ids_size()) {
134 return id == filter_.filtered_ids(next_filtered_id_index_);
#define CHECK_GE(val1, val2)
SparseVectorFilterPredicate(const SparseVectorFilterProto &filter)
bool AcceptsAndUpdate(const int64_t id, const Value &value)
int NumMatrixNonzeros(const SparseDoubleMatrixProto &matrix)
int NumVariables(const VariablesProto &variables)
int NumConstraints(const LinearConstraintsProto &linear_constraints)
absl::flat_hash_set< CallbackEventProto > EventSet(const CallbackRegistrationProto &callback_registration)
void RemoveSparseDoubleVectorZeros(SparseDoubleVectorProto &sparse_vector)
std::function< int64_t(const Model &)> Value(IntegerVariable v)
Collection of objects used to extend the Constraint Solver library.