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();
35 inline int NumConstraints(
const LinearConstraintsProto& linear_constraints) {
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;
90 absl::flat_hash_set<CallbackEventProto>
EventSet(
91 const CallbackRegistrationProto& callback_registration);
97 template <
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_);
140 #endif // OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_ #define CHECK_GE(val1, val2)
bool AcceptsAndUpdate(const int64_t id, const Value &value)
SparseVectorFilterPredicate(const SparseVectorFilterProto &filter)
int NumMatrixNonzeros(const SparseDoubleMatrixProto &matrix)
int NumVariables(const VariablesProto &variables)
std::function< int64_t(const Model &)> Value(IntegerVariable v)
int NumConstraints(const LinearConstraintsProto &linear_constraints)
absl::flat_hash_set< CallbackEventProto > EventSet(const CallbackRegistrationProto &callback_registration)
void RemoveSparseDoubleVectorZeros(SparseDoubleVectorProto &sparse_vector)
Collection of objects used to extend the Constraint Solver library.