OR-Tools  9.6
init.h
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 
14 #ifndef OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
15 #define OR_TOOLS_OPEN_SOURCE_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"
25 #include "ortools/base/logging.h"
26 #include "ortools/base/version.h"
29 
30 ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
31 ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
32 ABSL_DECLARE_FLAG(bool, cp_model_dump_lns);
33 ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
34 ABSL_DECLARE_FLAG(int, stderrthreshold);
35 
36 namespace operations_research {
37 
41 struct CppFlags {
50  int stderrthreshold = 2;
51 
56  bool log_prefix = false;
57 
61  std::string cp_model_dump_prefix;
69  bool cp_model_dump_models = false;
70 
78 
86 };
87 
93 class 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_lns, flags.cp_model_dump_lns);
126  absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
127  }
128 
137  static bool LoadGurobiSharedLibrary(const std::string& full_library_path) {
138  return LoadGurobiDynamicLibrary({full_library_path}).ok();
139  }
140 
144  static void DeleteByteArray(uint8_t* buffer) { delete[] buffer; }
145 };
146 
148  public:
152  static int MajorNumber() {
154  }
155 
159  static int MinorNumber() {
161  }
162 
166  static int PatchNumber() {
168  }
169 
173  static std::string VersionString() {
175  }
176 };
177 
178 } // namespace operations_research
179 
180 #endif // OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
This class performs various C++ initialization.
Definition: init.h:93
static void InitLogging(const std::string &usage)
Initialize the C++ logging layer.
Definition: init.h:100
static bool LoadGurobiSharedLibrary(const std::string &full_library_path)
Load the gurobi shared library.
Definition: init.h:137
static void ShutdownLogging()
Shutdown the C++ logging layer.
Definition: init.h:113
static void SetFlags(const CppFlags &flags)
Sets all the C++ flags contained in the CppFlags structure.
Definition: init.h:118
static void DeleteByteArray(uint8_t *buffer)
Delete a temporary C++ byte array.
Definition: init.h:144
static std::string VersionString()
Returns the string version of OR-Tools.
Definition: init.h:173
static int MinorNumber()
Returns the minor version of OR-Tools.
Definition: init.h:159
static int PatchNumber()
Returns the patch version of OR-Tools.
Definition: init.h:166
static int MajorNumber()
Returns the major version of OR-Tools.
Definition: init.h:152
ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix)
Collection of objects used to extend the Constraint Solver library.
int OrToolsMinorVersion()
Definition: version.cc:24
std::string OrToolsVersionString()
Definition: version.cc:28
int OrToolsMajorVersion()
Definition: version.cc:22
int OrToolsPatchVersion()
Definition: version.cc:26
absl::Status LoadGurobiDynamicLibrary(std::vector< std::string > potential_paths)
Definition: environment.cc:385
Simple structure that holds useful C++ flags to setup from non-C++ languages.
Definition: init.h:41
bool cp_model_dump_lns
DEBUG ONLY: Dump CP-SAT LNS models during solve.
Definition: init.h:77
int stderrthreshold
Controls the logging level shown on stderr.
Definition: init.h:50
bool cp_model_dump_response
DEBUG ONLY: Dump the CP-SAT final response found during solve.
Definition: init.h:85
bool cp_model_dump_models
DEBUG ONLY: Dump CP-SAT models during solve.
Definition: init.h:69
bool log_prefix
Controls if time and source code info are used to prefix logging messages.
Definition: init.h:56
std::string cp_model_dump_prefix
Prefix filename for all dumped files (models, solutions, lns sub-models).
Definition: init.h:61