14 #ifndef OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_
15 #define OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_
19 #include <type_traits>
21 #include "absl/container/flat_hash_set.h"
22 #include "absl/status/status.h"
23 #include "absl/strings/string_view.h"
24 #include "absl/log/check.h"
25 #include "ortools/math_opt/callback.pb.h"
26 #include "ortools/math_opt/model.pb.h"
27 #include "ortools/math_opt/model_update.pb.h"
28 #include "ortools/math_opt/result.pb.h"
29 #include "ortools/math_opt/sparse_containers.pb.h"
35 return variables.ids_size();
38 inline int NumConstraints(
const LinearConstraintsProto& linear_constraints) {
39 return linear_constraints.ids_size();
43 return matrix.row_ids_size();
49 return variables.ids().empty() ? std::nullopt
50 : std::make_optional(variables.ids()[0]);
56 const LinearConstraintsProto& linear_constraints) {
57 return linear_constraints.ids().empty()
59 : std::make_optional(linear_constraints.ids()[0]);
91 template <
typename Value>
95 const SparseVectorFilterProto& filter_;
98 int next_filtered_id_index_ = 0;
104 int64_t next_input_id_lower_bound_ = 0;
109 absl::flat_hash_set<CallbackEventProto>
EventSet(
110 const CallbackRegistrationProto& callback_registration);
115 absl::string_view detail = {});
118 absl::string_view detail = {});
121 absl::string_view detail = {});
124 absl::string_view detail = {});
147 absl::string_view solver_name);
158 template <
typename Value>
162 CHECK_GE(
id, next_input_id_lower_bound_)
163 <<
"This function must be called with strictly increasing ids.";
167 next_input_id_lower_bound_ =
id + 1;
174 if (filter_.skip_zero_values() &&
value == 0) {
178 if (!filter_.filter_by_ids()) {
183 while (next_filtered_id_index_ < filter_.filtered_ids_size() &&
184 filter_.filtered_ids(next_filtered_id_index_) <
id) {
185 ++next_filtered_id_index_;
188 if (next_filtered_id_index_ == filter_.filtered_ids_size()) {
195 return id == filter_.filtered_ids(next_filtered_id_index_);
SparseVectorFilterPredicate(const SparseVectorFilterProto &filter)
bool AcceptsAndUpdate(const int64_t id, const Value &value)
TerminationProto FeasibleTermination(const LimitProto limit, const absl::string_view detail)
int NumMatrixNonzeros(const SparseDoubleMatrixProto &matrix)
int NumVariables(const VariablesProto &variables)
std::optional< int64_t > FirstLinearConstraintId(const LinearConstraintsProto &linear_constraints)
absl::Status ModelIsSupported(const ModelProto &model, const SupportedProblemStructures &support_menu, const absl::string_view solver_name)
bool UpdateIsSupported(const ModelUpdateProto &update, const SupportedProblemStructures &support_menu)
TerminationProto TerminateForLimit(const LimitProto limit, const bool feasible, const absl::string_view detail)
TerminationProto NoSolutionFoundTermination(const LimitProto limit, const absl::string_view detail)
int NumConstraints(const LinearConstraintsProto &linear_constraints)
TerminationProto TerminateForReason(const TerminationReasonProto reason, const absl::string_view detail)
absl::flat_hash_set< CallbackEventProto > EventSet(const CallbackRegistrationProto &callback_registration)
void RemoveSparseDoubleVectorZeros(SparseDoubleVectorProto &sparse_vector)
std::optional< int64_t > FirstVariableId(const VariablesProto &variables)
std::function< int64_t(const Model &)> Value(IntegerVariable v)
Collection of objects used to extend the Constraint Solver library.
SupportType integer_variables
SupportType quadratic_constraints
SupportType sos1_constraints
SupportType indicator_constraints
SupportType multi_objectives
SupportType sos2_constraints
SupportType quadratic_objectives