OR-Tools  9.1
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"
24 
25 ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
26 ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
27 ABSL_DECLARE_FLAG(bool, cp_model_dump_lns);
28 ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
29 
30 namespace operations_research {
31 
35 struct CppFlags {
39  bool logtostderr = false;
40 
44  bool log_prefix = false;
45 
49  std::string cp_model_dump_prefix;
57  bool cp_model_dump_models = false;
58 
66 
74 };
75 
81 class CppBridge {
82  public:
88  static void InitLogging(const std::string& program_name) {
89  google::InitGoogleLogging(program_name.c_str());
90  }
91 
99 
103  static void SetFlags(const CppFlags& flags) {
104  absl::SetFlag(&FLAGS_logtostderr, flags.logtostderr);
105  absl::SetFlag(&FLAGS_log_prefix, flags.log_prefix);
106  if (!flags.cp_model_dump_prefix.empty()) {
107  absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
108  }
109  absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
110  absl::SetFlag(&FLAGS_cp_model_dump_lns, flags.cp_model_dump_lns);
111  absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
112  }
113 
122  static bool LoadGurobiSharedLibrary(const std::string& full_library_path) {
123  return LoadGurobiDynamicLibrary({full_library_path}).ok();
124  }
125 };
126 
127 } // namespace operations_research
128 
129 #endif // OR_TOOLS_OPEN_SOURCE_INIT_INIT_H_
void InitGoogleLogging(const char *argv0)
absl::Status LoadGurobiDynamicLibrary(std::vector< std::string > potential_paths)
Definition: environment.cc:721
static void ShutdownLogging()
Shutdown the C++ logging layer.
Definition: init.h:98
bool cp_model_dump_lns
DEBUG ONLY: Dump CP-SAT LNS models during solve.
Definition: init.h:65
This class performs various C++ initialization.
Definition: init.h:81
Simple structure that holds useful C++ flags to setup from non-C++ languages.
Definition: init.h:35
bool cp_model_dump_response
DEBUG ONLY: Dump the CP-SAT final response found during solve.
Definition: init.h:73
bool logtostderr
If true, all logging message will be sent to stderr.
Definition: init.h:39
static void SetFlags(const CppFlags &flags)
Sets all the C++ flags contained in the CppFlags structure.
Definition: init.h:103
static void InitLogging(const std::string &program_name)
Initialize the C++ logging layer.
Definition: init.h:88
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:49
ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix)
bool cp_model_dump_models
DEBUG ONLY: Dump CP-SAT models during solve.
Definition: init.h:57
bool log_prefix
Controls is time and source code info are used to prefix logging messages.
Definition: init.h:44
static bool LoadGurobiSharedLibrary(const std::string &full_library_path)
Load the gurobi shared library.
Definition: init.h:122
void ShutdownGoogleLogging()