18#include "absl/status/status.h"
19#include "google/protobuf/repeated_field.h"
24#include "ortools/math_opt/model_parameters.pb.h"
25#include "ortools/math_opt/sparse_containers.pb.h"
34absl::Status ValidateSolutionHint(
const SolutionHintProto& solution_hint,
35 const ModelSummary& model_summary) {
37 MakeView(solution_hint.variable_values()),
38 {.allow_positive_infinity = false, .allow_negative_infinity = false}))
39 <<
"Invalid solution_hint.variable_values";
41 solution_hint.variable_values().ids(), model_summary.variables,
42 "solution_hint.variable_values ids",
"model variable ids"));
45 MakeView(solution_hint.dual_values()),
46 {.allow_positive_infinity = false, .allow_negative_infinity = false}))
47 <<
"Invalid solution_hint.dual_values";
49 solution_hint.dual_values().ids(), model_summary.linear_constraints,
50 "solution_hint.dual_values ids",
"model linear constraint ids"));
52 return absl::OkStatus();
55absl::Status ValidateBranchingPriorities(
56 const SparseInt32VectorProto& branching_priorities,
57 const ModelSummary& model_summary) {
58 const auto vector_view =
MakeView(branching_priorities);
60 <<
"Invalid branching_priorities";
62 model_summary.variables,
63 "branching_priorities ids",
"model IDs"));
65 return absl::OkStatus();
68absl::Status ValidateObjectiveParameters(
70 if (
parameters.objective_degradation_absolute_tolerance() < 0) {
72 <<
"ObjectiveParametersProto.objective_degradation_absolute_"
74 <<
parameters.objective_degradation_absolute_tolerance() <<
" < 0";
77 if (
parameters.objective_degradation_relative_tolerance() < 0) {
79 <<
"ObjectiveParametersProto.objective_degradation_relative_"
81 <<
parameters.objective_degradation_relative_tolerance() <<
" < 0";
83 return absl::OkStatus();
86absl::Status ValidateLazyLinearConstraints(
87 const google::protobuf::RepeatedField<int64_t>& lazy_linear_constraint_ids,
88 const ModelSummary& model_summary) {
92 lazy_linear_constraint_ids, model_summary.linear_constraints,
93 "lazy_linear_constraint ids",
"model linear constraint IDs"));
94 return absl::OkStatus();
103 CheckIdsSubset(v.filtered_ids(), valid_ids,
"filtered_ids",
"model IDs"));
104 if (!v.filter_by_ids() && !v.filtered_ids().empty()) {
105 return absl::InvalidArgumentError(
106 "Invalid SparseVectorFilterProto.filter_by_id* specification. To "
108 "IDs you must set SparseVectorFilterProto.filter_by_ids to 'true'.");
111 return absl::OkStatus();
119 <<
"invalid variable_values_filter";
122 <<
"invalid reduced_costs_filter";
125 <<
"invalid dual_values_filter";
130 for (
const SolutionHintProto& solution_hint :
parameters.solution_hints()) {
136 ValidateObjectiveParameters(
parameters.primary_objective_parameters()))
137 <<
"invalid primary_objective_parameters";
138 for (
const auto& [objective, params] :
139 parameters.auxiliary_objective_parameters()) {
142 <<
"Entry in auxiliary_objective_parameters for unknown "
147 <<
"invalid auxiliary_objective_parameters entry for objective: "
151 parameters.lazy_linear_constraint_ids(), model_summary))
152 <<
"invalid lazy_linear_constraint_ids";
153 return absl::OkStatus();
#define RETURN_IF_ERROR(expr)
bool HasId(int64_t id) const
SparseVectorView< T > MakeView(absl::Span< const int64_t > ids, const Collection &values)
absl::Status CheckIdsAndValues(const SparseVectorView< T > &vector_view, absl::string_view value_name="values")
absl::Status CheckIdsSubset(absl::Span< const int64_t > ids, const IdNameBiMap &universe, std::optional< int64_t > upper_bound)
absl::Status ValidateBasis(const BasisProto &basis, const ModelSummary &model_summary, const bool check_dual_feasibility)
absl::Status ValidateSparseVectorFilter(const SparseVectorFilterProto &v, const IdNameBiMap &valid_ids)
absl::Status ValidateModelSolveParameters(const ModelSolveParametersProto ¶meters, const ModelSummary &model_summary)
absl::Status CheckIdsRangeAndStrictlyIncreasing(absl::Span< const int64_t > ids)
In SWIG mode, we don't want anything besides these top-level includes.
StatusBuilder InvalidArgumentErrorBuilder()
IdNameBiMap linear_constraints
IdNameBiMap auxiliary_objectives