OR-Tools  9.2
solve_parameters_validator.cc
Go to the documentation of this file.
1// Copyright 2010-2021 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include "absl/status/status.h"
17#include "absl/strings/str_cat.h"
18#include "ortools/math_opt/parameters.pb.h"
21
22namespace operations_research {
23namespace math_opt {
24
25absl::Status ValidateSolveParameters(const SolveParametersProto& parameters) {
27 util_time::DecodeGoogleApiProto(parameters.time_limit()).status())
28 << "invalid SolveParameters.time_limit";
29
30 if (parameters.has_threads()) {
31 if (parameters.threads() <= 0) {
32 return absl::InvalidArgumentError(absl::StrCat(
33 "SolveParameters.threads = ", parameters.threads(), " <= 0"));
34 }
35 }
36
37 if (parameters.has_relative_gap_limit()) {
38 if (parameters.relative_gap_limit() < 0) {
39 return absl::InvalidArgumentError(
40 absl::StrCat("SolveParameters.relative_gap_limit = ",
41 parameters.relative_gap_limit(), " < 0"));
42 }
43 }
44
45 if (parameters.has_absolute_gap_limit()) {
46 if (parameters.absolute_gap_limit() < 0) {
47 return absl::InvalidArgumentError(
48 absl::StrCat("SolveParameters.absolute_gap_limit = ",
49 parameters.absolute_gap_limit(), " < 0"));
50 }
51 }
52
53 if (parameters.has_solution_limit() && parameters.solution_limit() <= 0) {
55 << "SolveParameters.solution_limit = " << parameters.solution_limit()
56 << " should be positive.";
57 }
58
59 if (std::isnan(parameters.cutoff_limit())) {
60 return absl::InvalidArgumentError("SolveParameters.cutoff_limit was NaN");
61 }
62 if (std::isnan(parameters.objective_limit())) {
63 return absl::InvalidArgumentError(
64 "SolveParameters.objective_limit was NaN");
65 }
66 if (std::isnan(parameters.best_bound_limit())) {
67 return absl::InvalidArgumentError(
68 "SolveParameters.best_bound_limit was NaN");
69 }
70
71 return absl::OkStatus();
72}
73
74} // namespace math_opt
75} // namespace operations_research
SatParameters parameters
absl::Status ValidateSolveParameters(const SolveParametersProto &parameters)
Collection of objects used to extend the Constraint Solver library.
inline ::absl::StatusOr< absl::Duration > DecodeGoogleApiProto(const google::protobuf::Duration &proto)
Definition: protoutil.h:42
StatusBuilder InvalidArgumentErrorBuilder()
#define RETURN_IF_ERROR(expr)
Definition: status_macros.h:29