diff --git a/examples/cpp/binpacking_2d_sat.cc b/examples/cpp/binpacking_2d_sat.cc index 3d1e4e70e5..18a3ee9fd7 100644 --- a/examples/cpp/binpacking_2d_sat.cc +++ b/examples/cpp/binpacking_2d_sat.cc @@ -28,6 +28,7 @@ #include "absl/container/btree_set.h" #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/str_cat.h" #include "absl/types/span.h" #include "google/protobuf/text_format.h" @@ -555,7 +556,7 @@ void LoadAndSolve(const std::string& file_name, int instance) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { LOG(FATAL) << "Please supply a data file with --input="; diff --git a/examples/cpp/constraint_programming_cp.cc b/examples/cpp/constraint_programming_cp.cc index b7f82ce57e..b7541e619c 100644 --- a/examples/cpp/constraint_programming_cp.cc +++ b/examples/cpp/constraint_programming_cp.cc @@ -13,8 +13,12 @@ // Constraint programming example that shows how to use the API. +#include +#include #include +#include "absl/base/log_severity.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -23,12 +27,12 @@ namespace operations_research { void RunConstraintProgrammingExample() { // Instantiate the solver. Solver solver("ConstraintProgrammingExample"); - const int64_t numVals = 3; + const int64_t kNumVals = 3; // Define decision variables. - IntVar* const x = solver.MakeIntVar(0, numVals - 1, "x"); - IntVar* const y = solver.MakeIntVar(0, numVals - 1, "y"); - IntVar* const z = solver.MakeIntVar(0, numVals - 1, "z"); + IntVar* const x = solver.MakeIntVar(0, kNumVals - 1, "x"); + IntVar* const y = solver.MakeIntVar(0, kNumVals - 1, "y"); + IntVar* const z = solver.MakeIntVar(0, kNumVals - 1, "z"); // Define constraints. std::vector xyvars = {x, y}; @@ -57,7 +61,7 @@ void RunConstraintProgrammingExample() { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::RunConstraintProgrammingExample(); return EXIT_SUCCESS; diff --git a/examples/cpp/costas_array_sat.cc b/examples/cpp/costas_array_sat.cc index 3592d41bfd..4f96ec69d0 100644 --- a/examples/cpp/costas_array_sat.cc +++ b/examples/cpp/costas_array_sat.cc @@ -28,7 +28,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/types/span.h" @@ -297,7 +299,7 @@ void CostasBoolSoft(const int dim) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); int min = 1; diff --git a/examples/cpp/golomb_sat.cc b/examples/cpp/golomb_sat.cc index 83e4cb8c38..889dc9dd81 100644 --- a/examples/cpp/golomb_sat.cc +++ b/examples/cpp/golomb_sat.cc @@ -28,7 +28,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/str_format.h" #include "google/protobuf/text_format.h" #include "ortools/base/init_google.h" @@ -120,7 +122,7 @@ void GolombRuler(int size) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_size) != 0) { diff --git a/examples/cpp/integer_programming.cc b/examples/cpp/integer_programming.cc index 2ca6b23c95..14ff990899 100644 --- a/examples/cpp/integer_programming.cc +++ b/examples/cpp/integer_programming.cc @@ -16,7 +16,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "ortools/base/init_google.h" @@ -94,7 +96,7 @@ void RunAllExamples() { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::RunAllExamples(); return EXIT_SUCCESS; diff --git a/examples/cpp/jobshop_sat.cc b/examples/cpp/jobshop_sat.cc index ba7efe71cf..c156d31330 100644 --- a/examples/cpp/jobshop_sat.cc +++ b/examples/cpp/jobshop_sat.cc @@ -18,10 +18,12 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/str_join.h" #include "absl/types/span.h" #include "google/protobuf/text_format.h" @@ -848,7 +850,7 @@ void Solve(const JsspInputProblem& problem) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { diff --git a/examples/cpp/knapsack_2d_sat.cc b/examples/cpp/knapsack_2d_sat.cc index 5a1d8883d2..63ac87b410 100644 --- a/examples/cpp/knapsack_2d_sat.cc +++ b/examples/cpp/knapsack_2d_sat.cc @@ -21,7 +21,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/types/span.h" #include "google/protobuf/text_format.h" #include "ortools/base/commandlineflags.h" @@ -106,7 +108,7 @@ void CheckAndPrint2DSolution( } } -// Load a 2d binpacking problem and solve it as a 2d knapsack problem. +// Load a 2d bin-packing problem and solve it as a 2d knapsack problem. // That is fit the max number of object in one box. void LoadAndSolve(const std::string& file_name, int instance) { packing::BinPacking2dParser parser; @@ -226,7 +228,7 @@ void LoadAndSolve(const std::string& file_name, int instance) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { LOG(FATAL) << "Please supply a data file with --input="; diff --git a/examples/cpp/linear_programming.cc b/examples/cpp/linear_programming.cc index f27e7a387f..45477e883c 100644 --- a/examples/cpp/linear_programming.cc +++ b/examples/cpp/linear_programming.cc @@ -17,7 +17,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "ortools/base/commandlineflags.h" @@ -122,7 +124,7 @@ void RunAllExamples() { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::RunAllExamples(); return EXIT_SUCCESS; diff --git a/examples/cpp/linear_solver_protocol_buffers.cc b/examples/cpp/linear_solver_protocol_buffers.cc index 675f061c1c..47fbad8b1d 100644 --- a/examples/cpp/linear_solver_protocol_buffers.cc +++ b/examples/cpp/linear_solver_protocol_buffers.cc @@ -11,15 +11,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include "ortools/base/init_google.h" #include "ortools/base/logging.h" -#include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" +#include "ortools/linear_solver/solve_mp_model.h" namespace operations_research { -void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { +void BuildLinearProgrammingMaxExample(MPModelRequest::SolverType type) { const double kObjCoef[] = {10.0, 6.0, 4.0}; const std::string kVarName[] = {"x1", "x2", "x3"}; const int numVars = 3; @@ -32,7 +33,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { kConstraintCoef3}; const double kConstraintUb[] = {100.0, 600.0, 300.0}; - const double infinity = MPSolver::infinity(); + const double infinity = std::numeric_limits::infinity(); MPModelProto model_proto; model_proto.set_name("Max_Example"); @@ -62,19 +63,9 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { MPModelRequest model_request; *model_request.mutable_model() = model_proto; -#if defined(USE_GLOP) - if (type == MPSolver::GLOP_LINEAR_PROGRAMMING) { - model_request.set_solver_type(MPModelRequest::GLOP_LINEAR_PROGRAMMING); - } -#endif // USE_GLOP -#if defined(USE_CLP) - if (type == MPSolver::CLP_LINEAR_PROGRAMMING) { - model_request.set_solver_type(MPModelRequest::CLP_LINEAR_PROGRAMMING); - } -#endif // USE_CLP + model_request.set_solver_type(type); - MPSolutionResponse solution_response; - MPSolver::SolveWithProto(model_request, &solution_response); + const MPSolutionResponse solution_response = SolveMPModel(model_request); // The problem has an optimal solution. CHECK_EQ(MPSOLVER_OPTIMAL, solution_response.status()); @@ -89,11 +80,11 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { void RunAllExamples() { #if defined(USE_GLOP) LOG(INFO) << "----- Running Max Example with GLOP -----"; - BuildLinearProgrammingMaxExample(MPSolver::GLOP_LINEAR_PROGRAMMING); + BuildLinearProgrammingMaxExample(MPModelRequest::GLOP_LINEAR_PROGRAMMING); #endif // USE_GLOP #if defined(USE_CLP) LOG(INFO) << "----- Running Max Example with Coin LP -----"; - BuildLinearProgrammingMaxExample(MPSolver::CLP_LINEAR_PROGRAMMING); + BuildLinearProgrammingMaxExample(MPModelRequest::CLP_LINEAR_PROGRAMMING); #endif // USE_CLP } } // namespace operations_research diff --git a/examples/cpp/magic_sequence_sat.cc b/examples/cpp/magic_sequence_sat.cc index 1be92e4c5d..b4ca8fdd1b 100644 --- a/examples/cpp/magic_sequence_sat.cc +++ b/examples/cpp/magic_sequence_sat.cc @@ -22,7 +22,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/str_format.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" @@ -92,7 +94,7 @@ void MagicSequence(int size) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::sat::MagicSequence(absl::GetFlag(FLAGS_size)); diff --git a/examples/cpp/magic_square_sat.cc b/examples/cpp/magic_square_sat.cc index 00fceeb346..7e64960f40 100644 --- a/examples/cpp/magic_square_sat.cc +++ b/examples/cpp/magic_square_sat.cc @@ -14,7 +14,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "ortools/base/init_google.h" @@ -101,7 +103,7 @@ void MagicSquare(int size) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::sat::MagicSquare(absl::GetFlag(FLAGS_size)); diff --git a/examples/cpp/max_flow.cc b/examples/cpp/max_flow.cc index f4b4f18099..d7b12d1dfe 100644 --- a/examples/cpp/max_flow.cc +++ b/examples/cpp/max_flow.cc @@ -14,7 +14,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/graph/generic_max_flow.h" @@ -64,7 +66,7 @@ void SolveMaxFlow() { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::SolveMaxFlow(); return EXIT_SUCCESS; diff --git a/examples/cpp/min_cost_flow.cc b/examples/cpp/min_cost_flow.cc index 92b0cb4a9a..dccc719a46 100644 --- a/examples/cpp/min_cost_flow.cc +++ b/examples/cpp/min_cost_flow.cc @@ -16,7 +16,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" @@ -73,7 +75,7 @@ void SolveMinCostFlow() { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::SolveMinCostFlow(); return EXIT_SUCCESS; diff --git a/examples/cpp/mps_driver.cc b/examples/cpp/mps_driver.cc index 4a4e3c63f3..ea12c6a08c 100644 --- a/examples/cpp/mps_driver.cc +++ b/examples/cpp/mps_driver.cc @@ -28,7 +28,6 @@ #include "ortools/base/file.h" #include "ortools/base/helpers.h" #include "ortools/base/init_google.h" -#include "ortools/base/logging.h" #include "ortools/base/timer.h" #include "ortools/glop/lp_solver.h" #include "ortools/glop/parameters.pb.h" @@ -90,7 +89,7 @@ int main(int argc, char* argv[]) { "The files must be in Mps or linear_solver.proto format and can be " "compressed with gzip.", &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); GlopParameters parameters; ReadGlopParameters(¶meters); diff --git a/examples/cpp/multi_knapsack_sat.cc b/examples/cpp/multi_knapsack_sat.cc index 21b5cb8879..425275e81c 100644 --- a/examples/cpp/multi_knapsack_sat.cc +++ b/examples/cpp/multi_knapsack_sat.cc @@ -23,7 +23,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" @@ -33,7 +35,6 @@ ABSL_FLAG(int, size, 16, "scaling factor of the model"); ABSL_FLAG(std::string, params, "num_workers:8,log_search_progress:true,max_time_in_seconds:10.0", "Sat parameters"); - namespace operations_research { namespace sat { @@ -111,7 +112,7 @@ void MultiKnapsackSat(int scaling, const std::string& params) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::sat::MultiKnapsackSat(absl::GetFlag(FLAGS_size), absl::GetFlag(FLAGS_params)); diff --git a/examples/cpp/network_routing_sat.cc b/examples/cpp/network_routing_sat.cc index a67b0ce048..24ca3c6877 100644 --- a/examples/cpp/network_routing_sat.cc +++ b/examples/cpp/network_routing_sat.cc @@ -33,10 +33,12 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/random/uniform_int_distribution.h" #include "absl/strings/str_format.h" #include "ortools/base/init_google.h" @@ -673,7 +675,7 @@ class NetworkRoutingSolver { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::sat::NetworkRoutingData data; diff --git a/examples/cpp/pdlp_solve.cc b/examples/cpp/pdlp_solve.cc index c2d6246337..97eda90812 100644 --- a/examples/cpp/pdlp_solve.cc +++ b/examples/cpp/pdlp_solve.cc @@ -131,7 +131,7 @@ void Solve(const std::string& input, absl::string_view params_str, } // namespace operations_research::pdlp int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, /*remove_flags=*/true); operations_research::pdlp::Solve( diff --git a/examples/cpp/pdptw.cc b/examples/cpp/pdptw.cc index e0d03294e9..856b3d5885 100644 --- a/examples/cpp/pdptw.cc +++ b/examples/cpp/pdptw.cc @@ -47,8 +47,10 @@ #include #include "absl/algorithm/container.h" +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "google/protobuf/text_format.h" @@ -359,7 +361,7 @@ bool LoadAndSolve(absl::string_view pdp_file, } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); operations_research::routing::RoutingModelParameters model_parameters = operations_research::routing::DefaultRoutingModelParameters(); diff --git a/examples/cpp/shift_minimization_sat.cc b/examples/cpp/shift_minimization_sat.cc index 0e317053eb..97fb194863 100644 --- a/examples/cpp/shift_minimization_sat.cc +++ b/examples/cpp/shift_minimization_sat.cc @@ -32,8 +32,10 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/container/btree_set.h" #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/numbers.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" @@ -305,7 +307,7 @@ void LoadAndSolve(const std::string& file_name) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { diff --git a/examples/cpp/sports_scheduling_sat.cc b/examples/cpp/sports_scheduling_sat.cc index 0b0d523b02..65df956b7b 100644 --- a/examples/cpp/sports_scheduling_sat.cc +++ b/examples/cpp/sports_scheduling_sat.cc @@ -46,6 +46,9 @@ #include #include +#include "absl/base/log_severity.h" +#include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -321,7 +324,7 @@ static const char kUsage[] = "There is no output besides the LOGs of the solver."; int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(kUsage, &argc, &argv, true); CHECK_EQ(0, absl::GetFlag(FLAGS_num_teams) % 2) << "The number of teams must be even"; diff --git a/examples/cpp/strawberry_fields_with_column_generation.cc b/examples/cpp/strawberry_fields_with_column_generation.cc index e0a48c0612..b21f834256 100644 --- a/examples/cpp/strawberry_fields_with_column_generation.cc +++ b/examples/cpp/strawberry_fields_with_column_generation.cc @@ -606,7 +606,7 @@ int main(int argc, char** argv) { usage += " --colgen_max_iterations max columns to generate\n"; usage += " --colgen_complete generate all columns at start\n"; - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(usage.c_str(), &argc, &argv, true); operations_research::MPSolver::OptimizationProblemType solver_type; diff --git a/examples/cpp/uncapacitated_facility_location.cc b/examples/cpp/uncapacitated_facility_location.cc index 68eb3f4cbd..f0b034c776 100644 --- a/examples/cpp/uncapacitated_facility_location.cc +++ b/examples/cpp/uncapacitated_facility_location.cc @@ -28,6 +28,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/flags/usage.h" +#include "absl/log/globals.h" #include "absl/log/initialize.h" #include "absl/random/random.h" #include "ortools/base/logging.h" @@ -239,7 +240,7 @@ int main(int argc, char** argv) { << "Specify a non-null client size."; CHECK_LT(0, absl::GetFlag(FLAGS_fix_cost)) << "Specify a non-null client size."; - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::RunAllExamples(absl::GetFlag(FLAGS_facilities), absl::GetFlag(FLAGS_clients), absl::GetFlag(FLAGS_fix_cost)); diff --git a/examples/cpp/vector_bin_packing_solver.cc b/examples/cpp/vector_bin_packing_solver.cc index 71aaf82412..3aa7a9b3c4 100644 --- a/examples/cpp/vector_bin_packing_solver.cc +++ b/examples/cpp/vector_bin_packing_solver.cc @@ -15,6 +15,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -98,7 +99,7 @@ void ParseAndSolve(const std::string& filename, absl::string_view solver, } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { LOG(FATAL) << "Please supply a data file with --input="; diff --git a/examples/cpp/weighted_tardiness_sat.cc b/examples/cpp/weighted_tardiness_sat.cc index a51681de5e..f5889448a2 100644 --- a/examples/cpp/weighted_tardiness_sat.cc +++ b/examples/cpp/weighted_tardiness_sat.cc @@ -19,6 +19,7 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" @@ -252,7 +253,7 @@ void ParseAndSolve() { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { LOG(FATAL) << "Please supply a data file with --input="; diff --git a/examples/cpp/xpress_use.cc b/examples/cpp/xpress_use.cc index aac79913b3..bddc73d65a 100644 --- a/examples/cpp/xpress_use.cc +++ b/examples/cpp/xpress_use.cc @@ -90,7 +90,7 @@ void useXpressSolver(bool solveAsMip, bool useFactory) { } #define ABSL_MIN_LOG_LEVEL INFO; int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); std::cout << "start\n"; LOG(WARNING) << "start"; diff --git a/examples/tests/lp_test.cc b/examples/tests/lp_test.cc index 37a3133e4d..c15d3a0db3 100644 --- a/examples/tests/lp_test.cc +++ b/examples/tests/lp_test.cc @@ -226,7 +226,7 @@ void RunAllExamples() { int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::RunAllExamples(); return 0; } diff --git a/ortools/base/BUILD.bazel b/ortools/base/BUILD.bazel index 5132337dd3..5a0e40ec54 100644 --- a/ortools/base/BUILD.bazel +++ b/ortools/base/BUILD.bazel @@ -73,7 +73,10 @@ cc_library( "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/flags:parse", "@com_google_absl//absl/flags:usage", + "@com_google_absl//absl/log", + "@com_google_absl//absl/log:check", "@com_google_absl//absl/log:die_if_null", + "@com_google_absl//absl/log:globals", "@com_google_absl//absl/log:initialize", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", diff --git a/ortools/base/logging.cc b/ortools/base/logging.cc index 9afc09e06a..966f380f15 100644 --- a/ortools/base/logging.cc +++ b/ortools/base/logging.cc @@ -34,6 +34,4 @@ void FixFlagsAndEnvironmentForSwig() { absl::EnableLogPrefix(false); } -void KeepAbslSymbols() { absl::SetFlag(&FLAGS_stderrthreshold, 0); } - } // namespace operations_research diff --git a/ortools/base/logging.h b/ortools/base/logging.h index 1452a4b256..7dafabc2e0 100644 --- a/ortools/base/logging.h +++ b/ortools/base/logging.h @@ -14,21 +14,19 @@ #ifndef OR_TOOLS_BASE_LOGGING_H_ #define OR_TOOLS_BASE_LOGGING_H_ -#include "absl/base/log_severity.h" -#include "absl/flags/declare.h" -#include "absl/flags/flag.h" -#include "absl/log/check.h" -#include "absl/log/die_if_null.h" -#include "absl/log/log.h" -#include "absl/log/vlog_is_on.h" -#include "absl/memory/memory.h" -#include "absl/status/status.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" -#include "ortools/base/macros.h" - -// Forward the new flag. -ABSL_DECLARE_FLAG(int, stderrthreshold); +#include "absl/base/log_severity.h" // IWYU pragma: keep +#include "absl/flags/declare.h" // IWYU pragma: keep +#include "absl/flags/flag.h" // IWYU pragma: keep +#include "absl/log/check.h" // IWYU pragma: keep +#include "absl/log/die_if_null.h" // IWYU pragma: keep +#include "absl/log/globals.h" // IWYU pragma: keep +#include "absl/log/log.h" // IWYU pragma: keep +#include "absl/log/vlog_is_on.h" // IWYU pragma: keep +#include "absl/memory/memory.h" // IWYU pragma: keep +#include "absl/status/status.h" // IWYU pragma: keep +#include "absl/strings/str_cat.h" // IWYU pragma: keep +#include "absl/strings/string_view.h" // IWYU pragma: keep +#include "ortools/base/macros.h" // IWYU pragma: keep namespace operations_research { diff --git a/ortools/constraint_solver/samples/cp_is_fun_cp.cc b/ortools/constraint_solver/samples/cp_is_fun_cp.cc index c69f634ab6..f4cd1e63aa 100644 --- a/ortools/constraint_solver/samples/cp_is_fun_cp.cc +++ b/ortools/constraint_solver/samples/cp_is_fun_cp.cc @@ -20,10 +20,14 @@ // This problem has 72 different solutions in base 10. // [START import] #include +#include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/check.h" #include "absl/log/flags.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -147,7 +151,7 @@ void CPIsFunCp() { int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::CPIsFunCp(); return EXIT_SUCCESS; } diff --git a/ortools/constraint_solver/samples/minimal_jobshop_cp.cc b/ortools/constraint_solver/samples/minimal_jobshop_cp.cc index 47591eca79..b6859271ab 100644 --- a/ortools/constraint_solver/samples/minimal_jobshop_cp.cc +++ b/ortools/constraint_solver/samples/minimal_jobshop_cp.cc @@ -12,6 +12,7 @@ // limitations under the License. #include +#include #include #include #include // std::iota @@ -21,8 +22,10 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" #include "absl/log/flags.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -198,7 +201,7 @@ void SolveJobShopExample() { int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::SolveJobShopExample(); return EXIT_SUCCESS; } diff --git a/ortools/constraint_solver/samples/nurses_cp.cc b/ortools/constraint_solver/samples/nurses_cp.cc index 4ab0da3a2b..e3fd33f1e4 100644 --- a/ortools/constraint_solver/samples/nurses_cp.cc +++ b/ortools/constraint_solver/samples/nurses_cp.cc @@ -13,13 +13,16 @@ #include #include +#include #include #include // std::iota #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" #include "absl/log/flags.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -205,7 +208,7 @@ void SolveNursesExample() { int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::SolveNursesExample(); return EXIT_SUCCESS; } diff --git a/ortools/constraint_solver/samples/rabbits_and_pheasants_cp.cc b/ortools/constraint_solver/samples/rabbits_and_pheasants_cp.cc index 49ad19fcbc..e859f63884 100644 --- a/ortools/constraint_solver/samples/rabbits_and_pheasants_cp.cc +++ b/ortools/constraint_solver/samples/rabbits_and_pheasants_cp.cc @@ -13,8 +13,12 @@ // Knowing that we see 20 heads and 56 legs, // how many pheasants and rabbits are we looking at ? +#include + +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" #include "absl/log/flags.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -60,7 +64,7 @@ void RunConstraintProgrammingExample() { int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::RunConstraintProgrammingExample(); return EXIT_SUCCESS; } diff --git a/ortools/constraint_solver/samples/simple_ls_program.cc b/ortools/constraint_solver/samples/simple_ls_program.cc index 2db8dbb0ac..3e4db1ab2a 100644 --- a/ortools/constraint_solver/samples/simple_ls_program.cc +++ b/ortools/constraint_solver/samples/simple_ls_program.cc @@ -15,9 +15,13 @@ // Local Search. It solves the same trivial problem with a Large // Neighborhood Search approach, a Local Search approach, and a Local // Search with Filter approach. +#include +#include #include -#include "absl/log/flags.h" +#include "absl/base/log_severity.h" +#include "absl/log/check.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -199,7 +203,7 @@ void SolveProblem(SolveType solve_type) { int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::SolveProblem(operations_research::LNS); operations_research::SolveProblem(operations_research::LS); operations_research::SolveProblem(operations_research::LS_WITH_FILTER); diff --git a/ortools/graph/solve_flow_model.cc b/ortools/graph/solve_flow_model.cc index deed8253d4..22e5ddc67e 100644 --- a/ortools/graph/solve_flow_model.cc +++ b/ortools/graph/solve_flow_model.cc @@ -30,11 +30,10 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/file.h" #include "ortools/base/filesystem.h" #include "ortools/base/helpers.h" #include "ortools/base/init_google.h" @@ -303,7 +302,7 @@ int main(int argc, char** argv) { "The files must be in Dimacs text format or in binary FlowModelProto " "format.", &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); if (absl::GetFlag(FLAGS_input).empty()) { LOG(FATAL) << "Please specify input pattern via --input=..."; } diff --git a/ortools/init/init.cc b/ortools/init/init.cc index e80ce87a4f..8a9a7718e7 100644 --- a/ortools/init/init.cc +++ b/ortools/init/init.cc @@ -28,7 +28,7 @@ void CppBridge::InitLogging(const std::string& usage) { } void CppBridge::SetFlags(const CppFlags& flags) { - absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); absl::EnableLogPrefix(flags.log_prefix); if (!flags.cp_model_dump_prefix.empty()) { absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix); diff --git a/ortools/linear_solver/samples/basic_example.cc b/ortools/linear_solver/samples/basic_example.cc index 038c7ffb94..6e6ee7968c 100644 --- a/ortools/linear_solver/samples/basic_example.cc +++ b/ortools/linear_solver/samples/basic_example.cc @@ -17,8 +17,8 @@ #include #include -#include "absl/flags/flag.h" -#include "absl/log/flags.h" +#include "absl/base/log_severity.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/init/init.h" @@ -98,7 +98,7 @@ void BasicExample() { int main(int argc, char* argv[]) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::BasicExample(); return EXIT_SUCCESS; } diff --git a/ortools/linear_solver/samples/stigler_diet.cc b/ortools/linear_solver/samples/stigler_diet.cc index 222ac8e30f..145179b1fc 100644 --- a/ortools/linear_solver/samples/stigler_diet.cc +++ b/ortools/linear_solver/samples/stigler_diet.cc @@ -16,13 +16,14 @@ // [START import] #include #include +#include #include #include #include // std::pair #include -#include "absl/flags/flag.h" -#include "absl/log/flags.h" +#include "absl/base/log_severity.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/linear_solver/linear_solver.h" @@ -321,7 +322,7 @@ void StiglerDiet() { int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); operations_research::StiglerDiet(); return EXIT_SUCCESS; } diff --git a/ortools/linear_solver/xpress_interface_test.cc b/ortools/linear_solver/xpress_interface_test.cc index 18c39c66eb..6aad5f5a34 100644 --- a/ortools/linear_solver/xpress_interface_test.cc +++ b/ortools/linear_solver/xpress_interface_test.cc @@ -1414,7 +1414,7 @@ TEST_F(XpressFixtureMIP, CallbackThrowsException) { } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); testing::InitGoogleTest(&argc, argv); auto solver = operations_research::MPSolver::CreateSolver("XPRESS_LP"); if (solver == nullptr) { diff --git a/ortools/packing/vector_bin_packing_main.cc b/ortools/packing/vector_bin_packing_main.cc index 787f3810e1..479135d8ca 100644 --- a/ortools/packing/vector_bin_packing_main.cc +++ b/ortools/packing/vector_bin_packing_main.cc @@ -16,6 +16,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "ortools/base/helpers.h" @@ -94,7 +95,7 @@ void ParseAndSolve(const std::string& filename, absl::string_view solver, } // namespace operations_research int main(int argc, char** argv) { - absl::SetFlag(&FLAGS_stderrthreshold, 0); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); InitGoogle(argv[0], &argc, &argv, true); if (absl::GetFlag(FLAGS_input).empty()) { LOG(FATAL) << "Please supply a data file with --input="; diff --git a/ortools/sat/cp_model_copy.cc b/ortools/sat/cp_model_copy.cc index 087b9aae9f..30da6c9ed1 100644 --- a/ortools/sat/cp_model_copy.cc +++ b/ortools/sat/cp_model_copy.cc @@ -524,6 +524,14 @@ bool ModelCopy::CopyLinear(const ConstraintProto& ct, bool canonicalize) { FillDomainInProto(tight_domain, linear); if (canonicalize) { context_->CanonicalizeLinearConstraint(new_ct); + // We checked if the constraint was trivial above, but canonicalization can + // make it trivial again by simplifying expressions like (x - x). + if (new_ct->linear().vars().empty() && + ReadDomainFromProto(new_ct->linear()).Contains(0)) { + context_->UpdateRuleStats("linear: trivial 0=0"); + context_->working_model->mutable_constraints()->RemoveLast(); + return true; + } } return true; } diff --git a/ortools/util/stats.cc b/ortools/util/stats.cc index d998a43dc5..a8e8073c34 100644 --- a/ortools/util/stats.cc +++ b/ortools/util/stats.cc @@ -15,11 +15,13 @@ #include #include +#include #include #include #include "absl/log/check.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "ortools/base/logging.h" #include "ortools/base/stl_util.h" #include "ortools/base/types.h" @@ -51,8 +53,6 @@ Stat::Stat(absl::string_view name, StatsGroup* group) : name_(name) { std::string Stat::StatString() const { return name_ + ": " + ValueAsString(); } -StatsGroup::~StatsGroup() { gtl::STLDeleteValues(&time_distributions_); } - void StatsGroup::Register(Stat* stat) { stats_.push_back(stat); } void StatsGroup::Reset() { @@ -117,13 +117,14 @@ std::string StatsGroup::StatString() const { return result; } -TimeDistribution* StatsGroup::LookupOrCreateTimeDistribution(std::string name) { - TimeDistribution*& ref = time_distributions_[name]; +TimeDistribution* StatsGroup::LookupOrCreateTimeDistribution( + absl::string_view name) { + std::unique_ptr& ref = time_distributions_[name]; if (ref == nullptr) { - ref = new TimeDistribution(name); - Register(ref); + ref = std::make_unique(name); + Register(ref.get()); } - return ref; + return ref.get(); } DistributionStat::DistributionStat(absl::string_view name) diff --git a/ortools/util/stats.h b/ortools/util/stats.h index 270e900e96..a777012127 100644 --- a/ortools/util/stats.h +++ b/ortools/util/stats.h @@ -69,10 +69,13 @@ #define OR_TOOLS_UTIL_STATS_H_ #include +#include #include +#include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" #include "ortools/base/timer.h" @@ -138,7 +141,7 @@ class StatsGroup { // This type is neither copyable nor movable. StatsGroup(const StatsGroup&) = delete; StatsGroup& operator=(const StatsGroup&) = delete; - ~StatsGroup(); + ~StatsGroup() = default; // Registers a Stat, which will appear in the string returned by StatString(). // The Stat object must live as long as this StatsGroup. @@ -154,9 +157,9 @@ class StatsGroup { void SetPrintOrder(PrintOrder print_order) { print_order_ = print_order; } // Returns and if needed creates and registers a TimeDistribution with the - // given name. Note that this involve a map lookup and his thus slower than - // directly accessing a TimeDistribution variable. - TimeDistribution* LookupOrCreateTimeDistribution(std::string name); + // given name. Note that this involve a hash map lookup and is thus slower + // than directly accessing a TimeDistribution variable. + TimeDistribution* LookupOrCreateTimeDistribution(absl::string_view name); // Calls Reset() on all the statistics registered with this group. void Reset(); @@ -165,7 +168,8 @@ class StatsGroup { std::string name_; PrintOrder print_order_ = SORT_BY_PRIORITY_THEN_VALUE; std::vector stats_; - std::map time_distributions_; + absl::flat_hash_map> + time_distributions_; }; // Base class to track and compute statistics about the distribution of a @@ -376,7 +380,8 @@ class DisabledScopedTimeStats { // per measurement compared to about 20ns (as of 2012-06, on my workstation). class EnabledScopedTimeStats { public: - explicit EnabledScopedTimeStats(StatsGroup* stats, const char* function_name) + explicit EnabledScopedTimeStats(StatsGroup* stats, + absl::string_view function_name) : scoped_time_stat_( stats->LookupOrCreateTimeDistribution(function_name)) {} EnabledScopedTimeStats(const EnabledScopedTimeStats&) = delete; diff --git a/patches/scip-v920.patch b/patches/scip-v920.patch index 628716d38c..22c2d14c1e 100644 --- a/patches/scip-v920.patch +++ b/patches/scip-v920.patch @@ -15,13 +15,13 @@ index a90120188a..2c068e5e30 100644 if ( ival == 0 ) { - (void) google::SetVLOGLevel("*", google::GLOG_INFO); -+ absl::SetFlag(&FLAGS_stderrthreshold, 2); ++ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); lpi->lp_info = false; } else { - (void) google::SetVLOGLevel("*", google::GLOG_ERROR); -+ absl::SetFlag(&FLAGS_stderrthreshold, 0); ++ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kError); lpi->lp_info = true; } break;