16#include "absl/status/status.h"
17#include "absl/strings/str_cat.h"
21#include "ortools/math_opt/result.pb.h"
29absl::Status CheckNotPrimalDualInfeasible(
const ProblemStatusProto&
status) {
30 if (
status.primal_or_dual_infeasible()) {
32 <<
"expected primal_or_dual_infeasible = false";
34 return absl::OkStatus();
39absl::Status ValidateTerminationReasonConsistency(
42 case TERMINATION_REASON_OPTIMAL: {
44 FEASIBILITY_STATUS_FEASIBLE));
46 FEASIBILITY_STATUS_FEASIBLE));
50 return absl::OkStatus();
52 case TERMINATION_REASON_INFEASIBLE: {
54 FEASIBILITY_STATUS_INFEASIBLE));
55 return absl::OkStatus();
57 case TERMINATION_REASON_UNBOUNDED: {
59 FEASIBILITY_STATUS_FEASIBLE));
61 FEASIBILITY_STATUS_INFEASIBLE));
62 return absl::OkStatus();
64 case TERMINATION_REASON_INFEASIBLE_OR_UNBOUNDED:
66 FEASIBILITY_STATUS_UNDETERMINED));
68 termination.problem_status(), FEASIBILITY_STATUS_INFEASIBLE,
77 return absl::OkStatus();
78 case TERMINATION_REASON_IMPRECISE:
80 FEASIBILITY_STATUS_UNDETERMINED));
82 FEASIBILITY_STATUS_UNDETERMINED));
84 CheckNotPrimalDualInfeasible(
termination.problem_status()));
86 return absl::OkStatus();
87 case TERMINATION_REASON_FEASIBLE: {
89 FEASIBILITY_STATUS_FEASIBLE));
91 FEASIBILITY_STATUS_INFEASIBLE));
97 return absl::OkStatus();
99 case TERMINATION_REASON_NO_SOLUTION_FOUND: {
102 FEASIBILITY_STATUS_INFEASIBLE));
105 return absl::OkStatus();
107 case TERMINATION_REASON_NUMERICAL_ERROR:
108 case TERMINATION_REASON_OTHER_ERROR: {
110 FEASIBILITY_STATUS_UNDETERMINED));
112 FEASIBILITY_STATUS_UNDETERMINED));
114 CheckNotPrimalDualInfeasible(
termination.problem_status()));
116 return absl::OkStatus();
119 <<
" not implemented";
122 return absl::OkStatus();
128 const bool is_maximize) {
129 if (
termination.reason() == TERMINATION_REASON_UNSPECIFIED) {
130 return absl::InvalidArgumentError(
"termination reason must be specified");
132 if (
termination.reason() == TERMINATION_REASON_FEASIBLE ||
133 termination.reason() == TERMINATION_REASON_NO_SOLUTION_FOUND) {
135 return absl::InvalidArgumentError(
137 ", limit must be specified"));
140 termination.reason() == TERMINATION_REASON_FEASIBLE) {
141 return absl::InvalidArgumentError(
142 "For LIMIT_CUTOFF expected no solutions");
146 return absl::InvalidArgumentError(
148 ", limit should be unspecified, but was set to: ",
159 return absl::OkStatus();
#define RETURN_IF_ERROR(expr)
TerminationReason termination
absl::Status CheckDualStatusIsNot(const ProblemStatusProto &status, const FeasibilityStatusProto forbidden_status)
Assumes ValidateProblemStatus(status) is ok.
absl::Status CheckPrimalStatusIs(const ProblemStatusProto &status, const FeasibilityStatusProto required_status)
Assumes ValidateProblemStatus(status) is ok.
absl::Status ValidateProblemStatus(const ProblemStatusProto &status)
absl::Status CheckDualStatusIs(const ProblemStatusProto &status, const FeasibilityStatusProto required_status, const bool primal_or_dual_infeasible_also_ok)
Assumes ValidateProblemStatus(status) is ok.
absl::Status CheckFinitePrimalBound(const ObjectiveBoundsProto &bounds)
absl::Status ValidateObjectiveBounds(const ObjectiveBoundsProto &bounds)
absl::Status ValidateTermination(const TerminationProto &termination, const bool is_maximize)
Checks all messages are valid and compatible.
absl::Status ValidateBoundStatusConsistency(const ObjectiveBoundsProto &objective_bounds, const ProblemStatusProto &status, bool is_maximize)
absl::Status CheckPrimalStatusIsNot(const ProblemStatusProto &status, const FeasibilityStatusProto forbidden_status)
Assumes ValidateProblemStatus(status) is ok.
In SWIG mode, we don't want anything besides these top-level includes.
std::string ProtoEnumToString(ProtoEnumType enum_value)
StatusBuilder InvalidArgumentErrorBuilder()