From c96c8240343dab8906fe4605372c49b951b97c0f Mon Sep 17 00:00:00 2001 From: Mizux Seiha Date: Tue, 25 Feb 2025 16:03:40 +0100 Subject: [PATCH] backport examples from main --- examples/cpp/binpacking_2d_sat.cc | 4 ++- examples/cpp/constraint_programming_cp.cc | 14 +++++++---- examples/cpp/costas_array_sat.cc | 4 ++- examples/cpp/fap_parser.cc | 5 ++-- examples/cpp/fap_parser.h | 3 ++- examples/cpp/golomb_sat.cc | 9 +++++-- examples/cpp/integer_programming.cc | 6 +++-- examples/cpp/jobshop_sat.cc | 4 ++- examples/cpp/knapsack_2d_sat.cc | 16 ++++++------ examples/cpp/linear_programming.cc | 5 ++-- .../cpp/linear_solver_protocol_buffers.cc | 25 ++++++------------- examples/cpp/magic_sequence_sat.cc | 6 +++-- examples/cpp/magic_square_sat.cc | 8 +++--- examples/cpp/max_flow.cc | 6 +++-- examples/cpp/min_cost_flow.cc | 6 +++-- examples/cpp/mps_driver.cc | 16 +++++++----- examples/cpp/multi_knapsack_sat.cc | 6 ++--- examples/cpp/network_routing_sat.cc | 8 +++++- examples/cpp/nqueens.cc | 1 + examples/cpp/pdlp_solve.cc | 5 ++-- examples/cpp/pdptw.cc | 24 ++++++++++-------- examples/cpp/shift_minimization_sat.cc | 10 +++++--- examples/cpp/sports_scheduling_sat.cc | 10 +++++--- ...trawberry_fields_with_column_generation.cc | 5 ++-- .../cpp/uncapacitated_facility_location.cc | 8 +++++- examples/cpp/vector_bin_packing_solver.cc | 3 ++- examples/cpp/weighted_tardiness_sat.cc | 5 +++- examples/cpp/xpress_use.cc | 2 +- 28 files changed, 137 insertions(+), 87 deletions(-) diff --git a/examples/cpp/binpacking_2d_sat.cc b/examples/cpp/binpacking_2d_sat.cc index 3d1e4e70e5..c7b82751ac 100644 --- a/examples/cpp/binpacking_2d_sat.cc +++ b/examples/cpp/binpacking_2d_sat.cc @@ -24,10 +24,12 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/container/btree_map.h" #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 +557,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/fap_parser.cc b/examples/cpp/fap_parser.cc index 5c6028f544..4eb1a8f423 100644 --- a/examples/cpp/fap_parser.cc +++ b/examples/cpp/fap_parser.cc @@ -20,19 +20,20 @@ #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" #include "ortools/base/helpers.h" #include "ortools/base/map_util.h" namespace operations_research { namespace { -int strtoint32(const std::string& word) { +int strtoint32(absl::string_view word) { int result; CHECK(absl::SimpleAtoi(word, &result)); return result; } } // namespace -void ParseFileByLines(const std::string& filename, +void ParseFileByLines(absl::string_view filename, std::vector* lines) { CHECK(lines != nullptr); std::string result; diff --git a/examples/cpp/fap_parser.h b/examples/cpp/fap_parser.h index b094c1da97..f25f234013 100644 --- a/examples/cpp/fap_parser.h +++ b/examples/cpp/fap_parser.h @@ -24,12 +24,13 @@ #include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" +#include "absl/strings/string_view.h" namespace operations_research { // Takes a filename and a buffer and fills the lines buffer // with the lines of the file corresponding to the filename. -void ParseFileByLines(const std::string& filename, +void ParseFileByLines(absl::string_view filename, std::vector* lines); // The FapVariable struct represents a radio link of the diff --git a/examples/cpp/golomb_sat.cc b/examples/cpp/golomb_sat.cc index 83e4cb8c38..1847e10d58 100644 --- a/examples/cpp/golomb_sat.cc +++ b/examples/cpp/golomb_sat.cc @@ -26,16 +26,21 @@ #include #include +#include +#include #include +#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 "google/protobuf/text_format.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" -#include "ortools/base/types.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" +#include "ortools/util/sorted_interval_list.h" ABSL_FLAG(bool, print, false, "If true, print the minimal solution."); ABSL_FLAG( @@ -120,7 +125,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..c8a4ce812a 100644 --- a/examples/cpp/integer_programming.cc +++ b/examples/cpp/integer_programming.cc @@ -13,10 +13,12 @@ // Integer programming example that shows how to use the API. +#include #include #include -#include "absl/flags/flag.h" +#include "absl/base/log_severity.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..d29fa110e3 100644 --- a/examples/cpp/knapsack_2d_sat.cc +++ b/examples/cpp/knapsack_2d_sat.cc @@ -12,25 +12,27 @@ // limitations under the License. // This file solves a 2D Bin Packing problem as a 2D Knapsack problem. -// It loads the size of the mainrectangle, all available items (rectangles too), -// and tries to fit as many rectangles as possible in the main rectangle. +// It loads the size of the main rectangle, all available items (rectangles +// too), and tries to fit as many rectangles as possible in the main rectangle. -#include #include -#include +#include #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" +#include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/types/span.h" #include "google/protobuf/text_format.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/packing/binpacking_2d_parser.h" #include "ortools/packing/multiple_dimensions_bin_packing.pb.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/cp_model_solver.h" +#include "ortools/util/sorted_interval_list.h" ABSL_FLAG(std::string, input, "", "Input file."); ABSL_FLAG(int, instance, -1, "Instance number if the file."); @@ -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..ab4d923d4b 100644 --- a/examples/cpp/linear_programming.cc +++ b/examples/cpp/linear_programming.cc @@ -17,7 +17,8 @@ #include #include -#include "absl/flags/flag.h" +#include "absl/base/log_severity.h" +#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "ortools/base/commandlineflags.h" @@ -122,7 +123,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..092db422c2 100644 --- a/examples/cpp/magic_sequence_sat.cc +++ b/examples/cpp/magic_sequence_sat.cc @@ -22,11 +22,13 @@ #include #include +#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 "ortools/base/init_google.h" #include "ortools/base/logging.h" -#include "ortools/base/types.h" #include "ortools/sat/cp_model.h" ABSL_FLAG(int, size, 50, "Size of the problem."); @@ -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..41b8cc315d 100644 --- a/examples/cpp/magic_square_sat.cc +++ b/examples/cpp/magic_square_sat.cc @@ -11,17 +11,19 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" -#include "absl/strings/str_cat.h" +#include "absl/log/globals.h" #include "absl/strings/str_format.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" -#include "ortools/base/types.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" +#include "ortools/util/sorted_interval_list.h" ABSL_FLAG(int, size, 7, "Size of the magic square"); ABSL_FLAG(std::string, params, "", "Sat parameters"); @@ -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..f3c60bd707 100644 --- a/examples/cpp/max_flow.cc +++ b/examples/cpp/max_flow.cc @@ -11,10 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include -#include "absl/flags/flag.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/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..fabecde571 100644 --- a/examples/cpp/min_cost_flow.cc +++ b/examples/cpp/min_cost_flow.cc @@ -13,10 +13,12 @@ #include "ortools/graph/min_cost_flow.h" +#include #include #include -#include "absl/flags/flag.h" +#include "absl/base/log_severity.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..5f3279e9c0 100644 --- a/examples/cpp/mps_driver.cc +++ b/examples/cpp/mps_driver.cc @@ -16,23 +16,27 @@ #include +#include #include #include +#include "absl/base/log_severity.h" +#include "absl/flags/flag.h" +#include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/status/status.h" #include "absl/strings/match.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/message.h" +#include "absl/strings/str_format.h" #include "google/protobuf/text_format.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/file.h" #include "ortools/base/helpers.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" +#include "ortools/base/options.h" #include "ortools/base/timer.h" #include "ortools/glop/lp_solver.h" #include "ortools/glop/parameters.pb.h" -#include "ortools/lp_data/lp_print_utils.h" +#include "ortools/lp_data/lp_data.h" +#include "ortools/lp_data/lp_types.h" #include "ortools/lp_data/mps_reader.h" #include "ortools/lp_data/proto_utils.h" #include "ortools/util/file_util.h" @@ -90,7 +94,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..2bc12a69b8 100644 --- a/examples/cpp/multi_knapsack_sat.cc +++ b/examples/cpp/multi_knapsack_sat.cc @@ -23,8 +23,9 @@ #include #include +#include "absl/base/log_severity.h" #include "absl/flags/flag.h" -#include "ortools/base/commandlineflags.h" +#include "absl/log/globals.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/sat/cp_model.h" @@ -33,7 +34,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 +111,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..c28d7c36f0 100644 --- a/examples/cpp/network_routing_sat.cc +++ b/examples/cpp/network_routing_sat.cc @@ -28,23 +28,29 @@ #include #include #include +#include #include #include #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/check.h" +#include "absl/log/globals.h" #include "absl/random/uniform_int_distribution.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/graph/graph.h" #include "ortools/graph/shortest_paths.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" +#include "ortools/util/sorted_interval_list.h" #include "ortools/util/time_limit.h" // ----- Data Generator ----- @@ -673,7 +679,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/nqueens.cc b/examples/cpp/nqueens.cc index 88b184d8f7..ff2a0ae1d0 100644 --- a/examples/cpp/nqueens.cc +++ b/examples/cpp/nqueens.cc @@ -39,6 +39,7 @@ ABSL_FLAG( int, size, 0, "Size of the problem. If equal to 0, will test several increasing sizes."); ABSL_FLAG(bool, use_symmetry, false, "Use Symmetry Breaking methods"); +ABSL_DECLARE_FLAG(bool, cp_disable_solve); static const int kNumSolutions[] = { 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, 2279184}; diff --git a/examples/cpp/pdlp_solve.cc b/examples/cpp/pdlp_solve.cc index c2d6246337..7be8500736 100644 --- a/examples/cpp/pdlp_solve.cc +++ b/examples/cpp/pdlp_solve.cc @@ -21,9 +21,10 @@ #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 "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -131,7 +132,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 20526962f0..9d832a62d6 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" @@ -151,14 +153,14 @@ void SetupModel(const routing::LiLimParser& parser, search_parameters->set_log_cost_scaling_factor(1.0 / scaling_factor); const int vehicle_cost = model->RegisterTransitCallback( [&parser, &manager, scaling_factor](int64_t i, int64_t j) { - return MathUtil::FastInt64Round( + return MathUtil::Round( scaling_factor * parser.GetDistance(manager.IndexToNode(i).value(), manager.IndexToNode(j).value())); }); model->SetArcCostEvaluatorOfAllVehicles(vehicle_cost); model->SetFixedCostOfAllVehicles( - MathUtil::FastInt64Round(kFixedCost * scaling_factor)); + MathUtil::Round(kFixedCost * scaling_factor)); RoutingTransitCallback2 demand_evaluator = [&parser, &manager](int64_t from_index, int64_t /*to_index*/) { return parser.demands()[manager.IndexToNode(from_index).value()]; @@ -169,7 +171,7 @@ void SetupModel(const routing::LiLimParser& parser, RoutingTransitCallback2 time_evaluator = [&parser, &manager, scaling_factor]( int64_t from_index, int64_t to_index) { - int64_t value = MathUtil::FastInt64Round( + int64_t value = MathUtil::Round( scaling_factor * parser.GetTravelTime(manager.IndexToNode(from_index).value(), manager.IndexToNode(to_index).value())); @@ -198,8 +200,8 @@ void SetupModel(const routing::LiLimParser& parser, IntVar* const cumul = time_dimension.CumulVar(index); const routing::SimpleTimeWindow& window = parser.time_windows()[node]; - cumul->SetMin(MathUtil::FastInt64Round(scaling_factor * window.start)); - cumul->SetMax(MathUtil::FastInt64Round(scaling_factor * window.end)); + cumul->SetMin(MathUtil::Round(scaling_factor * window.start)); + cumul->SetMax(MathUtil::Round(scaling_factor * window.end)); } if (search_parameters->local_search_metaheuristic() == @@ -234,7 +236,7 @@ void SetupModel(const routing::LiLimParser& parser, ++order) { std::vector orders(1, manager.NodeToIndex(order)); model->AddDisjunction(orders, - MathUtil::FastInt64Round(scaling_factor * kPenalty)); + MathUtil::Round(scaling_factor * kPenalty)); } } @@ -262,8 +264,8 @@ std::string VerboseOutput(const RoutingModel& model, const IntVar* arrival = time_dimension.CumulVar(index); absl::StrAppendFormat( &output, "Time(%d..%d) ", - MathUtil::FastInt64Round(assignment.Min(arrival) * scaling_factor), - MathUtil::FastInt64Round(assignment.Max(arrival) * scaling_factor)); + MathUtil::Round(assignment.Min(arrival) * scaling_factor), + MathUtil::Round(assignment.Max(arrival) * scaling_factor)); const IntVar* load = load_dimension.CumulVar(index); absl::StrAppendFormat(&output, "Load(%d..%d) ", assignment.Min(load), assignment.Max(load)); @@ -280,8 +282,8 @@ std::string VerboseOutput(const RoutingModel& model, const IntVar* arrival = time_dimension.CumulVar(index); absl::StrAppendFormat( &output, "Time(%d..%d) ", - MathUtil::FastInt64Round(assignment.Min(arrival) * scaling_factor), - MathUtil::FastInt64Round(assignment.Max(arrival) * scaling_factor)); + MathUtil::Round(assignment.Min(arrival) * scaling_factor), + MathUtil::Round(assignment.Max(arrival) * scaling_factor)); const IntVar* load = load_dimension.CumulVar(index); absl::StrAppendFormat(&output, "Load(%d..%d) ", assignment.Min(load), assignment.Max(load)); @@ -356,7 +358,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::RoutingModelParameters model_parameters = operations_research::DefaultRoutingModelParameters(); diff --git a/examples/cpp/shift_minimization_sat.cc b/examples/cpp/shift_minimization_sat.cc index 0e317053eb..f069e3967d 100644 --- a/examples/cpp/shift_minimization_sat.cc +++ b/examples/cpp/shift_minimization_sat.cc @@ -27,22 +27,24 @@ // performing all the jobs. #include -#include -#include +#include #include #include +#include "absl/base/log_severity.h" #include "absl/container/btree_set.h" #include "absl/flags/flag.h" +#include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/numbers.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" #include "ortools/util/filelineiter.h" +#include "ortools/util/sorted_interval_list.h" ABSL_FLAG(std::string, input, "", "Input file."); ABSL_FLAG(std::string, params, "", "Sat parameters in text proto format."); @@ -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..44e933116e 100644 --- a/examples/cpp/sports_scheduling_sat.cc +++ b/examples/cpp/sports_scheduling_sat.cc @@ -43,18 +43,22 @@ // We also introduces a variable at_home[d][i] which is true if team i // plays any opponent at home on day d. +#include #include #include +#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_cat.h" #include "absl/strings/str_format.h" -#include "absl/strings/str_join.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/model.h" +#include "ortools/util/sorted_interval_list.h" // Problem main flags. ABSL_FLAG(int, num_teams, 10, "Number of teams in the problem."); @@ -321,7 +325,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..4e9a995320 100644 --- a/examples/cpp/strawberry_fields_with_column_generation.cc +++ b/examples/cpp/strawberry_fields_with_column_generation.cc @@ -57,14 +57,13 @@ #include #include #include -#include #include #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/strings/str_format.h" #include "absl/types/span.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/init_google.h" #include "ortools/base/logging.h" #include "ortools/linear_solver/linear_solver.h" @@ -606,7 +605,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..9864faa0a3 100644 --- a/examples/cpp/uncapacitated_facility_location.cc +++ b/examples/cpp/uncapacitated_facility_location.cc @@ -20,14 +20,20 @@ // sake of simplicity, facilities and demands are randomly located. Distances // are assumed to be in meters and times in seconds. +#include +#include +#include #include +#include #include #include #include +#include "absl/base/log_severity.h" #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 +245,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..fef2d176f6 100644 --- a/examples/cpp/weighted_tardiness_sat.cc +++ b/examples/cpp/weighted_tardiness_sat.cc @@ -13,12 +13,15 @@ #include #include +#include #include #include #include +#include "absl/base/log_severity.h" #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 +255,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";