diff --git a/examples/cpp/dobble_ls.cc b/examples/cpp/dobble_ls.cc index b8545938cd..e0e8eeabc3 100644 --- a/examples/cpp/dobble_ls.cc +++ b/examples/cpp/dobble_ls.cc @@ -32,11 +32,11 @@ #include #include +#include "absl/random/random.h" #include "absl/strings/str_format.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/map_util.h" -#include "ortools/base/random.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/bitset.h" @@ -383,13 +383,16 @@ class SwapSymbolsOnCardPairs : public DobbleOperator { protected: bool MakeOneNeighbor() override { - const int num_swaps = rand_.Uniform(max_num_swaps_ - 1) + 2; + const int num_swaps = + absl::Uniform(rand_, 0, max_num_swaps_ - 1) + 2; for (int i = 0; i < num_swaps; ++i) { - const int card_1 = rand_.Uniform(num_cards_); - const int symbol_index_1 = rand_.Uniform(num_symbols_per_card_); + const int card_1 = absl::Uniform(rand_, 0, num_cards_); + const int symbol_index_1 = + absl::Uniform(rand_, 0, num_symbols_per_card_); const int symbol_1 = symbols_per_card_[card_1][symbol_index_1]; - const int card_2 = rand_.Uniform(num_cards_); - const int symbol_index_2 = rand_.Uniform(num_symbols_per_card_); + const int card_2 = absl::Uniform(rand_, 0, num_cards_); + const int symbol_index_2 = + absl::Uniform(rand_, 0, num_symbols_per_card_); const int symbol_2 = symbols_per_card_[card_2][symbol_index_2]; SwapTwoSymbolsOnCards(card_1, symbol_1, card_2, symbol_2); } @@ -399,7 +402,7 @@ class SwapSymbolsOnCardPairs : public DobbleOperator { void InitNeighborhoodSearch() override {} private: - ACMRandom rand_; + std::mt19937 rand_; const int max_num_swaps_; }; diff --git a/examples/cpp/multi_knapsack_sat.cc b/examples/cpp/multi_knapsack_sat.cc index 15404da72a..9b4661f5a2 100644 --- a/examples/cpp/multi_knapsack_sat.cc +++ b/examples/cpp/multi_knapsack_sat.cc @@ -24,7 +24,6 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/sat/cp_model.h" -#include "ortools/sat/sat_parameters.pb.h" DEFINE_int32(size, 16, "scaling factor of the model"); DEFINE_string(params, "", "Sat parameters"); @@ -63,6 +62,7 @@ void MultiKnapsackSat(int scaling, const std::string& params) { } // Fill up scaled values, weights, volumes; + std::vector values(num_items); std::vector weights(num_items); std::vector volumes(num_items); for (int i = 0; i < num_items; ++i) { @@ -97,11 +97,8 @@ void MultiKnapsackSat(int scaling, const std::string& params) { builder.Maximize(LinearExpr::Sum(bin_weights)); // And solve. - SatParameters sat_parameters; - sat_parameters.set_log_search_progress(true); - sat_parameters.MergeFromString(params); const CpSolverResponse response = - SolveWithParameters(builder.Build(), sat_parameters); + SolveWithParameters(builder.Build(), params); LOG(INFO) << CpSolverResponseStats(response); } @@ -109,7 +106,6 @@ void MultiKnapsackSat(int scaling, const std::string& params) { } // namespace operations_research int main(int argc, char** argv) { - google::InitGoogleLogging(argv[0]); absl::SetFlag(&FLAGS_logtostderr, true); gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::sat::MultiKnapsackSat(FLAGS_size, FLAGS_params); diff --git a/examples/cpp/sat_cnf_reader.h b/examples/cpp/sat_cnf_reader.h index 131254d985..78460acddc 100644 --- a/examples/cpp/sat_cnf_reader.h +++ b/examples/cpp/sat_cnf_reader.h @@ -195,8 +195,8 @@ class SatCnfReader { int64 StringPieceAtoi(absl::string_view input) { int64 value; // Hack: data() is not null terminated, but we do know that it points - // inside a std::string where numbers are separated by " " and since - // SimpleAtoi will stop at the first invalid char, this works. + // inside a string where numbers are separated by " " and since SimpleAtoi + // will stop at the first invalid char, this works. CHECK(absl::SimpleAtoi(input, &value)); return value; } diff --git a/examples/cpp/solve.cc b/examples/cpp/solve.cc index 91fb4941a5..4ade6a5e56 100644 --- a/examples/cpp/solve.cc +++ b/examples/cpp/solve.cc @@ -147,10 +147,11 @@ bool Run() { CHECK(solver.SetSolverSpecificParametersAsString(FLAGS_params)) << "Wrong --params format."; } - printf("%-12s: %s\n", "Solver", - MPModelRequest::SolverType_Name( - static_cast(solver.ProblemType())) - .c_str()); + absl::PrintF( + "%-12s: %s\n", "Solver", + MPModelRequest::SolverType_Name( + static_cast(solver.ProblemType())) + .c_str()); // Load the proto into the solver. std::string error_message; @@ -176,8 +177,8 @@ bool Run() { LOG(ERROR) << MPSolverResponseStatus_Name(status) << ": " << error_message; return false; } - printf("%-12s: %d x %d\n", "Dimension", solver.NumConstraints(), - solver.NumVariables()); + absl::PrintF("%-12s: %d x %d\n", "Dimension", solver.NumConstraints(), + solver.NumVariables()); // Solve. MPSolverParameters param; @@ -229,20 +230,20 @@ bool Run() { /*log_errors=*/true); } - printf("%-12s: %s\n", "Status", - MPSolverResponseStatus_Name( - static_cast(solve_status)) - .c_str()); - printf("%-12s: %15.15e\n", "Objective", - has_solution ? solver.Objective().Value() : 0.0); - printf("%-12s: %15.15e\n", "BestBound", - has_solution ? solver.Objective().BestBound() : 0.0); + absl::PrintF("%-12s: %s\n", "Status", + MPSolverResponseStatus_Name( + static_cast(solve_status)) + .c_str()); + absl::PrintF("%-12s: %15.15e\n", "Objective", + has_solution ? solver.Objective().Value() : 0.0); + absl::PrintF("%-12s: %15.15e\n", "BestBound", + has_solution ? solver.Objective().BestBound() : 0.0); absl::PrintF("%-12s: %d\n", "Iterations", solver.iterations()); // NOTE(user): nodes() for non-MIP solvers crashes in debug mode by design. if (solver.IsMIP()) { absl::PrintF("%-12s: %d\n", "Nodes", solver.nodes()); } - printf("%-12s: %-6.4g\n", "Time", absl::ToDoubleSeconds(solving_time)); + absl::PrintF("%-12s: %-6.4g\n", "Time", absl::ToDoubleSeconds(solving_time)); return true; } diff --git a/examples/cpp/strawberry_fields_with_column_generation.cc b/examples/cpp/strawberry_fields_with_column_generation.cc index 024f58cc5a..6b70415c20 100644 --- a/examples/cpp/strawberry_fields_with_column_generation.cc +++ b/examples/cpp/strawberry_fields_with_column_generation.cc @@ -296,7 +296,7 @@ struct BoxLessThan { class CoveringProblem { public: - // Grid is a row-major std::string of length width*height with '@' for an + // Grid is a row-major string of length width*height with '@' for an // occupied cell (strawberry) and '.' for an empty cell. Solver is // not owned. CoveringProblem(MPSolver* const solver, const Instance& instance)