14#ifndef OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_
15#define OR_TOOLS_MATH_OPT_CORE_MATH_OPT_PROTO_UTILS_H_
20#include "absl/base/attributes.h"
21#include "absl/container/flat_hash_set.h"
22#include "absl/log/check.h"
23#include "absl/status/status.h"
24#include "absl/strings/string_view.h"
25#include "ortools/math_opt/callback.pb.h"
26#include "ortools/math_opt/infeasible_subsystem.pb.h"
27#include "ortools/math_opt/model.pb.h"
28#include "ortools/math_opt/model_parameters.pb.h"
29#include "ortools/math_opt/model_update.pb.h"
30#include "ortools/math_opt/result.pb.h"
31#include "ortools/math_opt/solution.pb.h"
32#include "ortools/math_opt/sparse_containers.pb.h"
50 return variables.ids_size();
54 return linear_constraints.ids_size();
58 return matrix.row_ids_size();
64 return variables.ids().empty() ? std::nullopt
65 : std::make_optional(variables.ids()[0]);
71 const LinearConstraintsProto& linear_constraints) {
72 return linear_constraints.ids().empty()
74 : std::make_optional(linear_constraints.ids()[0]);
106 template <
typename Value>
110 const SparseVectorFilterProto& filter_;
113 int next_filtered_id_index_ = 0;
119 int64_t next_input_id_lower_bound_ = 0;
128 const SparseDoubleVectorProto&
input,
129 const SparseVectorFilterProto& filter);
140void ApplyAllFilters(
const ModelSolveParametersProto& model_solve_params,
144absl::flat_hash_set<CallbackEventProto>
EventSet(
145 const CallbackRegistrationProto& callback_registration);
162 "Use TerminateForReason(bool, TerminationReasonProto, absl::string_view) "
181 TerminationReasonProto reason,
182 absl::string_view
detail = {});
192 double dual_objective,
193 absl::string_view
detail = {});
213 FeasibilityStatusProto dual_feasibility_status =
214 FEASIBILITY_STATUS_UNDETERMINED,
215 absl::string_view
detail = {});
228 FeasibilityStatusProto dual_feasibility_status =
229 FEASIBILITY_STATUS_UNDETERMINED,
230 absl::string_view
detail = {});
236 absl::string_view
detail = {});
253 bool is_maximize, LimitProto limit,
254 std::optional<double> optional_dual_objective = std::nullopt,
255 absl::string_view
detail = {});
276 bool is_maximize, LimitProto limit,
double finite_primal_objective,
277 std::optional<double> optional_dual_objective = std::nullopt,
278 absl::string_view
detail = {});
286 bool is_maximize, LimitProto limit,
287 std::optional<double> optional_finite_primal_objective,
288 std::optional<double> optional_dual_objective = std::nullopt,
289 absl::string_view
detail = {});
308 double primal_objective,
309 double dual_objective,
310 bool claim_dual_feasible_solution_exists,
311 absl::string_view
detail = {});
315 absl::string_view
detail = {});
339 absl::string_view solver_name);
347 SolveResultProto& solve_result_proto);
353template <
typename Value>
355 const Value&
value) {
357 CHECK_GE(
id, next_input_id_lower_bound_)
358 <<
"This function must be called with strictly increasing ids.";
362 next_input_id_lower_bound_ =
id + 1;
369 if (filter_.skip_zero_values() &&
value == 0) {
373 if (!filter_.filter_by_ids()) {
378 while (next_filtered_id_index_ < filter_.filtered_ids_size() &&
379 filter_.filtered_ids(next_filtered_id_index_) <
id) {
380 ++next_filtered_id_index_;
383 if (next_filtered_id_index_ == filter_.filtered_ids_size()) {
390 return id == filter_.filtered_ids(next_filtered_id_index_);
SparseVectorFilterPredicate(const SparseVectorFilterProto &filter)
bool AcceptsAndUpdate(int64_t id, const Value &value)
An object oriented wrapper for quadratic constraints in ModelStorage.
TerminationProto TerminateForReason(const TerminationReasonProto reason, const absl::string_view detail)
absl::Status ModelIsSupported(const ModelProto &model, const SupportedProblemStructures &support_menu, const absl::string_view solver_name)
TerminationProto FeasibleTermination(const LimitProto limit, const absl::string_view detail)
void UpgradeSolveResultProtoForStatsMigration(SolveResultProto &solve_result_proto)
std::optional< int64_t > FirstLinearConstraintId(const LinearConstraintsProto &linear_constraints)
TerminationProto TerminateForLimit(const LimitProto limit, const bool feasible, const absl::string_view detail)
int NumMatrixNonzeros(const SparseDoubleMatrixProto &matrix)
int NumVariables(const VariablesProto &variables)
absl::flat_hash_set< CallbackEventProto > EventSet(const CallbackRegistrationProto &callback_registration)
Returns the callback_registration.request_registration as a set of enums.
TerminationProto OptimalTerminationProto(const double finite_primal_objective, const double dual_objective, const absl::string_view detail)
TerminationProto LimitTerminationProto(const bool is_maximize, const LimitProto limit, const std::optional< double > optional_finite_primal_objective, const std::optional< double > optional_dual_objective, const absl::string_view detail)
TerminationProto InfeasibleOrUnboundedTerminationProto(bool is_maximize, const FeasibilityStatusProto dual_feasibility_status, const absl::string_view detail)
bool UpdateIsSupported(const ModelUpdateProto &update, const SupportedProblemStructures &support_menu)
ProblemStatusProto GetProblemStatus(const SolveResultProto &solve_result)
TerminationProto FeasibleTerminationProto(const bool is_maximize, const LimitProto limit, const double primal_objective, const std::optional< double > optional_dual_objective, const absl::string_view detail)
ObjectiveBoundsProto GetObjectiveBounds(const SolveResultProto &solve_result)
TerminationProto NoSolutionFoundTerminationProto(const bool is_maximize, const LimitProto limit, const std::optional< double > optional_dual_objective, const absl::string_view detail)
TerminationProto CutoffTerminationProto(bool is_maximize, const absl::string_view detail)
Calls NoSolutionFoundTerminationProto() with LIMIT_CUTOFF LIMIT.
TerminationProto NoSolutionFoundTermination(const LimitProto limit, const absl::string_view detail)
int NumConstraints(const LinearConstraintsProto &linear_constraints)
std::optional< int64_t > FirstVariableId(const VariablesProto &variables)
TerminationProto InfeasibleTerminationProto(bool is_maximize, const FeasibilityStatusProto dual_feasibility_status, const absl::string_view detail)
SparseDoubleVectorProto FilterSparseVector(const SparseDoubleVectorProto &input, const SparseVectorFilterProto &filter)
ABSL_DEPRECATED("Use TerminateForReason(bool, TerminationReasonProto, absl::string_view) " "instead") TerminationProto TerminateForReason(TerminationReasonProto reason
TerminationProto UnboundedTerminationProto(const bool is_maximize, const absl::string_view detail)
void RemoveSparseDoubleVectorZeros(SparseDoubleVectorProto &sparse_vector)
void ApplyAllFilters(const ModelSolveParametersProto &model_solve_params, SolutionProto &solution)
ObjectiveBoundsProto MakeTrivialBounds(const bool is_maximize)
static int input(yyscan_t yyscanner)
SupportType second_order_cone_constraints
SupportType sos2_constraints
SupportType quadratic_objectives
SupportType multi_objectives
SupportType integer_variables
SupportType sos1_constraints
SupportType quadratic_constraints
SupportType indicator_constraints