OR-Tools  9.2
init.h
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 
14 #ifndef OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
15 #define OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
16 
17 #include <string>
18 #include <vector>
19 
20 #include "absl/flags/flag.h"
21 #include "ortools/base/logging.h"
22 #include "ortools/base/version.h"
25 
26 ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
27 ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
28 ABSL_DECLARE_FLAG(bool, cp_model_dump_lns);
29 ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
30 
31 namespace operations_research {
32 
36 struct CppFlags {
40  bool logtostderr = false;
41 
45  bool log_prefix = false;
46 
50  std::string cp_model_dump_prefix;
58  bool cp_model_dump_models = false;
59 
67 
75 };
76 
82 class CppBridge {
83  public:
89  static void InitLogging(const std::string& program_name) {
90  google::InitGoogleLogging(program_name.c_str());
91  }
92 
100 
104  static void SetFlags(const CppFlags& flags) {
105  absl::SetFlag(&FLAGS_logtostderr, flags.logtostderr);
106  absl::SetFlag(&FLAGS_log_prefix, flags.log_prefix);
107  if (!flags.cp_model_dump_prefix.empty()) {
108  absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
109  }
110  absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
111  absl::SetFlag(&FLAGS_cp_model_dump_lns, flags.cp_model_dump_lns);
112  absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
113  }
114 
123  static bool LoadGurobiSharedLibrary(const std::string& full_library_path) {
124  return LoadGurobiDynamicLibrary({full_library_path}).ok();
125  }
126 };
127 
129  public:
133  static int MajorNumber() {
135  }
136 
140  static int MinorNumber() {
142  }
143 
147  static int PatchNumber() {
149  }
150 
154  static std::string VersionString() {
156  }
157 };
158 
159 } // namespace operations_research
160 
161 #endif // OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
void InitGoogleLogging(const char *argv0)
std::string OrToolsVersionString()
Definition: version.cc:26
int OrToolsPatchVersion()
Definition: version.cc:24
int OrToolsMinorVersion()
Definition: version.cc:22
absl::Status LoadGurobiDynamicLibrary(std::vector< std::string > potential_paths)
Definition: environment.cc:722
static void ShutdownLogging()
Shutdown the C++ logging layer.
Definition: init.h:99
bool cp_model_dump_lns
DEBUG ONLY: Dump CP-SAT LNS models during solve.
Definition: init.h:66
static int MinorNumber()
Returns the minor version of OR-Tools.
Definition: init.h:140
static int MajorNumber()
Returns the major version of OR-Tools.
Definition: init.h:133
This class performs various C++ initialization.
Definition: init.h:82
Simple structure that holds useful C++ flags to setup from non-C++ languages.
Definition: init.h:36
bool cp_model_dump_response
DEBUG ONLY: Dump the CP-SAT final response found during solve.
Definition: init.h:74
bool logtostderr
If true, all logging message will be sent to stderr.
Definition: init.h:40
static void SetFlags(const CppFlags &flags)
Sets all the C++ flags contained in the CppFlags structure.
Definition: init.h:104
static void InitLogging(const std::string &program_name)
Initialize the C++ logging layer.
Definition: init.h:89
static int PatchNumber()
Returns the patch version of OR-Tools.
Definition: init.h:147
Collection of objects used to extend the Constraint Solver library.
std::string cp_model_dump_prefix
Prefix filename for all dumped files (models, solutions, lns sub-models).
Definition: init.h:50
ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix)
int OrToolsMajorVersion()
Definition: version.cc:20
bool cp_model_dump_models
DEBUG ONLY: Dump CP-SAT models during solve.
Definition: init.h:58
bool log_prefix
Controls is time and source code info are used to prefix logging messages.
Definition: init.h:45
static bool LoadGurobiSharedLibrary(const std::string &full_library_path)
Load the gurobi shared library.
Definition: init.h:123
static std::string VersionString()
Returns the string version of OR-Tools.
Definition: init.h:154
void ShutdownGoogleLogging()