Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
init.h
Go to the documentation of this file.
1// Copyright 2010-2024 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
14#ifndef OR_TOOLS_INIT_INIT_H_
15#define OR_TOOLS_INIT_INIT_H_
16
17#include <cstdint>
18#include <string>
19#include <vector>
20
21#include "absl/flags/flag.h"
22#include "absl/flags/usage.h"
23#include "absl/log/globals.h"
24#include "absl/log/initialize.h"
29
30ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
31ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
32ABSL_DECLARE_FLAG(bool, cp_model_dump_submodels);
33ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
34ABSL_DECLARE_FLAG(int, stderrthreshold);
35
36namespace operations_research {
37
41struct CppFlags {
51
56 bool log_prefix = false;
57
70
78
86};
87
93class CppBridge {
94 public:
100 static void InitLogging(const std::string& usage) {
101 absl::SetProgramUsageMessage(usage);
102 absl::InitializeLog();
103 }
104
113 static void ShutdownLogging() {}
114
118 static void SetFlags(const CppFlags& flags) {
119 absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold);
120 absl::EnableLogPrefix(flags.log_prefix);
121 if (!flags.cp_model_dump_prefix.empty()) {
122 absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
123 }
124 absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
125 absl::SetFlag(&FLAGS_cp_model_dump_submodels,
127 absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
128 }
129
138 static bool LoadGurobiSharedLibrary(const std::string& full_library_path) {
139 return LoadGurobiDynamicLibrary({full_library_path}).ok();
140 }
141
145 static void DeleteByteArray(uint8_t* buffer) { delete[] buffer; }
146};
147
149 public:
153 static int MajorNumber() {
154 return ::operations_research::OrToolsMajorVersion();
155 }
156
160 static int MinorNumber() {
161 return ::operations_research::OrToolsMinorVersion();
162 }
163
167 static int PatchNumber() {
168 return ::operations_research::OrToolsPatchVersion();
169 }
170
174 static std::string VersionString() {
175 return ::operations_research::OrToolsVersionString();
176 }
177};
178
179} // namespace operations_research
180
181#endif // OR_TOOLS_INIT_INIT_H_
static void SetFlags(const CppFlags &flags)
Definition init.h:118
static void ShutdownLogging()
Definition init.h:113
static void DeleteByteArray(uint8_t *buffer)
Definition init.h:145
static bool LoadGurobiSharedLibrary(const std::string &full_library_path)
Definition init.h:138
static void InitLogging(const std::string &usage)
Definition init.h:100
static std::string VersionString()
Definition init.h:174
ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix)
In SWIG mode, we don't want anything besides these top-level includes.
absl::Status LoadGurobiDynamicLibrary(std::vector< std::string > potential_paths)
bool log_prefix
Controls if time and source code info are used to prefix logging messages.
Definition init.h:56
int stderrthreshold
Controls the logging level shown on stderr.
Definition init.h:50
std::string cp_model_dump_prefix
Definition init.h:61