OR-Tools  9.3
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 <cstdint>
18#include <string>
19#include <vector>
20
21#include "absl/flags/flag.h"
26
27ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
28ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
29ABSL_DECLARE_FLAG(bool, cp_model_dump_lns);
30ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
31
32namespace operations_research {
33
37struct CppFlags {
41 bool logtostderr = false;
42
46 bool log_prefix = false;
47
60
68
76};
77
83class CppBridge {
84 public:
90 static void InitLogging(const std::string& program_name) {
91 google::InitGoogleLogging(program_name.c_str());
92 }
93
101
105 static void SetFlags(const CppFlags& flags) {
106 absl::SetFlag(&FLAGS_logtostderr, flags.logtostderr);
107 absl::SetFlag(&FLAGS_log_prefix, flags.log_prefix);
108 if (!flags.cp_model_dump_prefix.empty()) {
109 absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
110 }
111 absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
112 absl::SetFlag(&FLAGS_cp_model_dump_lns, flags.cp_model_dump_lns);
113 absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
114 }
115
124 static bool LoadGurobiSharedLibrary(const std::string& full_library_path) {
125 return LoadGurobiDynamicLibrary({full_library_path}).ok();
126 }
127
131 static void DeleteByteArray(uint8_t* buffer) { delete[] buffer; }
132};
133
135 public:
139 static int MajorNumber() {
141 }
142
146 static int MinorNumber() {
148 }
149
153 static int PatchNumber() {
155 }
156
160 static std::string VersionString() {
162 }
163};
164
165} // namespace operations_research
166
167#endif // OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
This class performs various C++ initialization.
Definition: init.h:83
static void InitLogging(const std::string &program_name)
Initialize the C++ logging layer.
Definition: init.h:90
static bool LoadGurobiSharedLibrary(const std::string &full_library_path)
Load the gurobi shared library.
Definition: init.h:124
static void ShutdownLogging()
Shutdown the C++ logging layer.
Definition: init.h:100
static void SetFlags(const CppFlags &flags)
Sets all the C++ flags contained in the CppFlags structure.
Definition: init.h:105
static void DeleteByteArray(uint8_t *buffer)
Delete a temporary C++ byte array.
Definition: init.h:131
static std::string VersionString()
Returns the string version of OR-Tools.
Definition: init.h:160
static int MinorNumber()
Returns the minor version of OR-Tools.
Definition: init.h:146
static int PatchNumber()
Returns the patch version of OR-Tools.
Definition: init.h:153
static int MajorNumber()
Returns the major version of OR-Tools.
Definition: init.h:139
ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix)
void InitGoogleLogging(const char *argv0)
void ShutdownGoogleLogging()
Collection of objects used to extend the Constraint Solver library.
int OrToolsMinorVersion()
Definition: version.cc:22
std::string OrToolsVersionString()
Definition: version.cc:26
int OrToolsMajorVersion()
Definition: version.cc:20
int OrToolsPatchVersion()
Definition: version.cc:24
absl::Status LoadGurobiDynamicLibrary(std::vector< std::string > potential_paths)
Definition: environment.cc:717
Simple structure that holds useful C++ flags to setup from non-C++ languages.
Definition: init.h:37
bool cp_model_dump_lns
DEBUG ONLY: Dump CP-SAT LNS models during solve.
Definition: init.h:67
bool cp_model_dump_response
DEBUG ONLY: Dump the CP-SAT final response found during solve.
Definition: init.h:75
bool cp_model_dump_models
DEBUG ONLY: Dump CP-SAT models during solve.
Definition: init.h:59
bool log_prefix
Controls is time and source code info are used to prefix logging messages.
Definition: init.h:46
bool logtostderr
If true, all logging message will be sent to stderr.
Definition: init.h:41
std::string cp_model_dump_prefix
Prefix filename for all dumped files (models, solutions, lns sub-models).
Definition: init.h:51