File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212// limitations under the License.
1313
1414using System ;
15+ using Google . OrTools . Init ;
1516using Google . OrTools . LinearSolver ;
1617
1718public class CsIntegerProgramming
@@ -100,7 +101,11 @@ private static void RunIntegerProgrammingExampleNaturalApi(String solverType)
100101
101102 static void Main ( )
102103 {
103- Google . OrTools . Init . Init . InitCppLogging ( "csintegerprogramming.cs" , true , false ) ;
104+ CppBridge . InitLogging ( "csintegerprogramming.cs" ) ;
105+ CppFlags flags = new CppFlags ( ) ;
106+ flags . logtostderr = true ;
107+ flags . log_prefix = false ;
108+ CppBridge . SetFlags ( flags ) ;
104109
105110 Console . WriteLine ( "---- Integer programming example with GLPK ----" ) ;
106111 RunIntegerProgrammingExample ( "GLPK" ) ;
Original file line number Diff line number Diff line change @@ -116,7 +116,9 @@ def main():
116116
117117
118118if __name__ == '__main__' :
119- init .Init .InitCppLogging ('integer_programming.py' ,
120- / * logtostderr = * / True ,
121- / * log_prefix = * / False );
119+ init .CppBridge .InitLogging ('integer_programming.py' )
120+ cpp_flags = init .CppFlags ()
121+ cpp_flags .logtostderr = True
122+ cpp_flags .log_prefix = False
123+ init .CppBridge .SetFlags (cpp_flags )
122124 main ()
Original file line number Diff line number Diff line change 1010
1111%unignore operations_research;
1212
13- %unignore operations_research::Init;
14- %unignore operations_research::Init::InitCppLogging;
15- %unignore operations_research::Init::LoadGurobiSharedLibrary;
13+ // Expose the flags structure.
14+ %unignore operations_research::CppFlags;
15+ %unignore operations_research::CppFlags::logtostderr;
16+ %unignore operations_research::CppFlags::log_prefix;
17+
18+ // Expose the static methods of the bridge class.
19+ %unignore operations_research::CppBridge;
20+ %unignore operations_research::CppBridge::InitLogging;
21+ %unignore operations_research::CppBridge::SetFlags;
22+ %unignore operations_research::CppBridge::LoadGurobiSharedLibrary;
1623
1724%include " ortools/init/init.h"
1825
Original file line number Diff line number Diff line change 88
99namespace operations_research {
1010
11+ struct CppFlags {
12+ bool logtostderr = false ;
13+ bool log_prefix = false ;
14+ };
15+
1116// This class performs various C++ initialization.
1217// It is meant to be used once at the start of a program.
13- class Init {
18+ class CppBridge {
1419 public:
1520 // Initialize the C++ logging layer.
16- // If logtostderr is false, all C++ logging will be ignored.
17- // If true, all logging will the displayed on stderr.
18- static void InitCppLogging (const std::string& program_name, bool logtostderr,
19- bool log_prefix) {
20- absl::SetFlag (&FLAGS_logtostderr, logtostderr);
21- absl::SetFlag (&FLAGS_log_prefix, log_prefix);
21+ static void InitLogging (const std::string& program_name) {
2222 google::InitGoogleLogging (program_name.c_str ());
2323 }
24+
25+ // Sets all the C++ flags contained in the CppFlags structure.
26+ static void SetFlags (const CppFlags& flags) {
27+ absl::SetFlag (&FLAGS_logtostderr, flags.logtostderr );
28+ absl::SetFlag (&FLAGS_log_prefix, flags.log_prefix );
29+ }
2430
2531 // Load the gurobi shared library.
2632 // This is necessary if the library is installed in a non canonical
Original file line number Diff line number Diff line change 1010
1111%unignore operations_research;
1212
13- %unignore operations_research::Init;
14- %rename (initCppLogging) operations_research::Init::InitCppLogging;
15- %rename (logGurobiSharedLibrary) operations_research::Init::LoadGurobiSharedLibrary;
13+ // Expose the flags structure.
14+ %unignore operations_research::CppFlags;
15+ %unignore operations_research::CppFlags::logtostderr;
16+ %unignore operations_research::CppFlags::log_prefix;
17+
18+ // Expose the static methods of the bridge class.
19+ %unignore operations_research::CppBridge;
20+ %rename (initLogging) operations_research::CppBridge::InitLogging;
21+ %rename (setFlags) operations_research::CppBridge::SetFlags;
22+ %rename (logGurobiSharedLibrary) operations_research::CppBridge::LoadGurobiSharedLibrary;
1623
1724%include " ortools/init/init.h"
1825
Original file line number Diff line number Diff line change 1010
1111%unignore operations_research;
1212
13- %unignore operations_research::Init;
14- %unignore operations_research::Init::InitCppLogging;
15- %unignore operations_research::Init::LoadGurobiSharedLibrary;
13+ // Expose the flags structure.
14+ %unignore operations_research::CppFlags;
15+ %unignore operations_research::CppFlags::logtostderr;
16+ %unignore operations_research::CppFlags::log_prefix;
17+
18+ // Expose the static methods of the bridge class.
19+ %unignore operations_research::CppBridge;
20+ %unignore operations_research::CppBridge::InitLogging;
21+ %unignore operations_research::CppBridge::SetFlags;
22+ %unignore operations_research::CppBridge::LoadGurobiSharedLibrary;
1623
1724%include " ortools/init/init.h"
1825
You can’t perform that action at this time.
0 commit comments