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"
25
26ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
27ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
28ABSL_DECLARE_FLAG(bool, cp_model_dump_lns);
29ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
30
31namespace operations_research {
32
36struct CppFlags {
40 bool logtostderr = false;
41
45 bool log_prefix = false;
46
59
67
75};
76
82class 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_
This class performs various C++ initialization.
Definition: init.h:82
static void InitLogging(const std::string &program_name)
Initialize the C++ logging layer.
Definition: init.h:89
static bool LoadGurobiSharedLibrary(const std::string &full_library_path)
Load the gurobi shared library.
Definition: init.h:123
static void ShutdownLogging()
Shutdown the C++ logging layer.
Definition: init.h:99
static void SetFlags(const CppFlags &flags)
Sets all the C++ flags contained in the CppFlags structure.
Definition: init.h:104
static std::string VersionString()
Returns the string version of OR-Tools.
Definition: init.h:154
static int MinorNumber()
Returns the minor version of OR-Tools.
Definition: init.h:140
static int PatchNumber()
Returns the patch version of OR-Tools.
Definition: init.h:147
static int MajorNumber()
Returns the major version of OR-Tools.
Definition: init.h:133
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:722
Simple structure that holds useful C++ flags to setup from non-C++ languages.
Definition: init.h:36
bool cp_model_dump_lns
DEBUG ONLY: Dump CP-SAT LNS models during solve.
Definition: init.h:66
bool cp_model_dump_response
DEBUG ONLY: Dump the CP-SAT final response found during solve.
Definition: init.h:74
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
bool logtostderr
If true, all logging message will be sent to stderr.
Definition: init.h:40
std::string cp_model_dump_prefix
Prefix filename for all dumped files (models, solutions, lns sub-models).
Definition: init.h:50