OR-Tools  9.6
glop/parameters_validation.cc
Go to the documentation of this file.
1 // Copyright 2010-2022 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 <string>
17 
18 #include "absl/strings/str_cat.h"
19 #include "ortools/glop/parameters.pb.h"
20 
21 namespace operations_research::glop {
22 
23 #define TEST_FINITE_AND_NON_NEGATIVE(name) \
24  if (!std::isfinite(params.name())) { \
25  return absl::StrCat("parameter '", #name, "' is NaN or not finite"); \
26  } \
27  if (params.name() < 0) { \
28  return absl::StrCat("Parameters '", #name, "' must be non-negative"); \
29  }
30 
31 // We need an integer version of the test as std::isnan can fail to compile
32 // on windows platforms when passed integer values.
33 #define TEST_INTEGER_NON_NEGATIVE(name) \
34  if (params.name() < 0) { \
35  return absl::StrCat("Parameters '", #name, "' must be non-negative"); \
36  }
37 
38 #define TEST_NON_NEGATIVE(name) \
39  if (std::isnan(params.name())) { \
40  return absl::StrCat("parameter '", #name, "' is NaN"); \
41  } \
42  if (params.name() < 0) { \
43  return absl::StrCat("Parameters '", #name, "' must be non-negative"); \
44  }
45 
46 #define TEST_NOT_NAN(name) \
47  if (std::isnan(params.name())) { \
48  return absl::StrCat("parameter '", #name, "' is NaN"); \
49  }
50 
51 std::string ValidateParameters(const GlopParameters& params) {
52  TEST_FINITE_AND_NON_NEGATIVE(degenerate_ministep_factor);
53  TEST_FINITE_AND_NON_NEGATIVE(drop_tolerance);
54  TEST_FINITE_AND_NON_NEGATIVE(dual_feasibility_tolerance);
55  TEST_FINITE_AND_NON_NEGATIVE(dual_small_pivot_threshold);
56  TEST_FINITE_AND_NON_NEGATIVE(dualizer_threshold);
57  TEST_FINITE_AND_NON_NEGATIVE(harris_tolerance_ratio);
58  TEST_FINITE_AND_NON_NEGATIVE(lu_factorization_pivot_threshold);
59  TEST_FINITE_AND_NON_NEGATIVE(markowitz_singularity_threshold);
60  TEST_FINITE_AND_NON_NEGATIVE(max_number_of_reoptimizations);
61  TEST_FINITE_AND_NON_NEGATIVE(minimum_acceptable_pivot);
62  TEST_FINITE_AND_NON_NEGATIVE(preprocessor_zero_tolerance);
63  TEST_FINITE_AND_NON_NEGATIVE(primal_feasibility_tolerance);
64  TEST_FINITE_AND_NON_NEGATIVE(ratio_test_zero_threshold);
65  TEST_FINITE_AND_NON_NEGATIVE(recompute_edges_norm_threshold);
66  TEST_FINITE_AND_NON_NEGATIVE(recompute_reduced_costs_threshold);
67  TEST_FINITE_AND_NON_NEGATIVE(refactorization_threshold);
68  TEST_FINITE_AND_NON_NEGATIVE(relative_cost_perturbation);
69  TEST_FINITE_AND_NON_NEGATIVE(relative_max_cost_perturbation);
70  TEST_FINITE_AND_NON_NEGATIVE(small_pivot_threshold);
71  TEST_FINITE_AND_NON_NEGATIVE(solution_feasibility_tolerance);
72 
73  TEST_NOT_NAN(objective_lower_limit);
74  TEST_NOT_NAN(objective_upper_limit);
75 
76  TEST_NON_NEGATIVE(crossover_bound_snapping_distance);
77  TEST_NON_NEGATIVE(initial_condition_number_threshold);
78  TEST_NON_NEGATIVE(max_deterministic_time);
79  TEST_NON_NEGATIVE(max_time_in_seconds);
80  TEST_NON_NEGATIVE(max_valid_magnitude);
81 
82  TEST_INTEGER_NON_NEGATIVE(basis_refactorization_period);
83  TEST_INTEGER_NON_NEGATIVE(devex_weights_reset_period);
84  TEST_INTEGER_NON_NEGATIVE(num_omp_threads);
85  TEST_INTEGER_NON_NEGATIVE(random_seed);
86 
87  if (params.markowitz_zlatev_parameter() < 1) {
88  return "markowitz_zlatev_parameter must be >= 1";
89  }
90 
91  return "";
92 }
93 
94 #undef TEST_NOT_NAN
95 #undef TEST_INTEGER_NON_NEGATIVE
96 #undef TEST_NON_NEGATIVE
97 #undef TEST_FINITE_AND_NON_NEGATIVE
98 
99 } // namespace operations_research::glop
#define TEST_FINITE_AND_NON_NEGATIVE(name)
#define TEST_INTEGER_NON_NEGATIVE(name)
#define TEST_NON_NEGATIVE(name)
#define TEST_NOT_NAN(name)
std::string ValidateParameters(const GlopParameters &params)