OR-Tools  8.2
gscip_parameters.cc
Go to the documentation of this file.
1// Copyright 2010-2018 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
17
18namespace operations_research {
19
20// NOTE(user): the open source build for proto is less accepting of
21// absl::string_view than internally, so we do more conversions than would
22// appear necessary.
23namespace {
24constexpr absl::string_view kLimitsTime = "limits/time";
25constexpr absl::string_view kParallelMaxNThreads = "parallel/maxnthreads";
26constexpr absl::string_view kDisplayVerbLevel = "display/verblevel";
27constexpr absl::string_view kRandomSeedParam = "randomization/randomseedshift";
28} // namespace
29
30void GScipSetTimeLimit(absl::Duration time_limit, GScipParameters* parameters) {
31 if (time_limit < absl::Seconds(1e20) && time_limit > absl::Duration()) {
32 (*parameters->mutable_real_params())[std::string(kLimitsTime)] =
33 absl::ToDoubleSeconds(time_limit);
34 } else {
35 parameters->mutable_real_params()->erase(std::string(kLimitsTime));
36 }
37}
38
39absl::Duration GScipTimeLimit(const GScipParameters& parameters) {
40 if (parameters.real_params().contains(std::string(kLimitsTime))) {
41 const double scip_limit =
42 parameters.real_params().at(std::string(kLimitsTime));
43 if (scip_limit >= 1e20) {
44 return absl::InfiniteDuration();
45 } else if (scip_limit <= 0.0) {
46 return absl::Duration();
47 } else {
48 return absl::Seconds(scip_limit);
49 }
50 }
51 return absl::InfiniteDuration();
52}
53
54bool GScipTimeLimitSet(const GScipParameters& parameters) {
55 return parameters.real_params().contains(std::string(kLimitsTime));
56}
57
58void GScipSetMaxNumThreads(int num_threads, GScipParameters* parameters) {
59 CHECK_GE(num_threads, 1);
60 (*parameters->mutable_int_params())[std::string(kParallelMaxNThreads)] =
61 num_threads;
62}
63
64int GScipMaxNumThreads(const GScipParameters& parameters) {
65 if (parameters.int_params().contains(std::string(kParallelMaxNThreads))) {
66 return parameters.int_params().at(std::string(kParallelMaxNThreads));
67 }
68 return 1;
69}
70
71bool GScipMaxNumThreadsSet(const GScipParameters& parameters) {
72 return parameters.int_params().contains(std::string(kParallelMaxNThreads));
73}
74
75void GScipSetLogLevel(GScipParameters* parameters, int log_level) {
76 CHECK_GE(log_level, 0);
77 CHECK_LE(log_level, 5);
78 (*parameters->mutable_int_params())[std::string(kDisplayVerbLevel)] =
79 log_level;
80}
81
82int GScipLogLevel(const GScipParameters& parameters) {
83 return parameters.int_params().contains(std::string(kDisplayVerbLevel))
84 ? parameters.int_params().at(std::string(kDisplayVerbLevel))
85 : 4;
86}
87bool GScipLogLevelSet(const GScipParameters& parameters) {
88 return parameters.int_params().contains(std::string(kDisplayVerbLevel));
89}
90
91void GScipSetOutputEnabled(GScipParameters* parameters, bool output_enabled) {
92 if (output_enabled) {
93 parameters->mutable_int_params()->erase(std::string(kDisplayVerbLevel));
94 } else {
95 (*parameters->mutable_int_params())[std::string(kDisplayVerbLevel)] = 0;
96 }
97}
98bool GScipOutputEnabled(const GScipParameters& parameters) {
99 return !parameters.int_params().contains(std::string(kDisplayVerbLevel)) ||
100 (parameters.int_params().at(std::string(kDisplayVerbLevel)) > 0);
101}
102
103bool GScipOutputEnabledSet(const GScipParameters& parameters) {
105}
106
107void GScipSetRandomSeed(GScipParameters* parameters, int random_seed) {
108 random_seed = std::max(0, random_seed);
109 (*parameters->mutable_int_params())[std::string(kRandomSeedParam)] =
110 random_seed;
111}
112
113int GScipRandomSeed(const GScipParameters& parameters) {
115 return parameters.int_params().at(std::string(kRandomSeedParam));
116 }
117 return -1; // Unset value.
118}
119
120bool GScipRandomSeedSet(const GScipParameters& parameters) {
121 return parameters.int_params().contains(std::string(kRandomSeedParam));
122}
123} // namespace operations_research
int64 max
Definition: alldiff_cst.cc:139
#define CHECK_GE(val1, val2)
Definition: base/logging.h:701
#define CHECK_LE(val1, val2)
Definition: base/logging.h:699
SatParameters parameters
SharedTimeLimit * time_limit
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
int GScipLogLevel(const GScipParameters &parameters)
void GScipSetTimeLimit(absl::Duration time_limit, GScipParameters *parameters)
bool GScipLogLevelSet(const GScipParameters &parameters)
int GScipMaxNumThreads(const GScipParameters &parameters)
void GScipSetRandomSeed(GScipParameters *parameters, int random_seed)
bool GScipOutputEnabledSet(const GScipParameters &parameters)
void GScipSetOutputEnabled(GScipParameters *parameters, bool output_enabled)
bool GScipMaxNumThreadsSet(const GScipParameters &parameters)
bool GScipOutputEnabled(const GScipParameters &parameters)
void GScipSetMaxNumThreads(int num_threads, GScipParameters *parameters)
int GScipRandomSeed(const GScipParameters &parameters)
void GScipSetLogLevel(GScipParameters *parameters, int log_level)
bool GScipRandomSeedSet(const GScipParameters &parameters)
bool GScipTimeLimitSet(const GScipParameters &parameters)
absl::Duration GScipTimeLimit(const GScipParameters &parameters)