From 798b9e73e21c7d979eef8cf4602210d342b0d402 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Wed, 28 Nov 2018 11:32:45 +0100 Subject: [PATCH] fix the rest of the C++ examples --- examples/cpp/fap_model_printer.h | 32 +++++++++++++------------- examples/cpp/fap_parser.h | 5 ++-- examples/cpp/fap_utilities.h | 2 +- examples/cpp/golomb_sat.cc | 5 ++-- examples/cpp/magic_square_sat.cc | 14 +++++------ examples/cpp/network_routing_sat.cc | 4 ++-- examples/cpp/sat_runner.cc | 2 +- examples/cpp/slitherlink_sat.cc | 4 ++-- examples/cpp/sports_scheduling_sat.cc | 2 +- examples/cpp/weighted_tardiness_sat.cc | 3 ++- makefiles/Makefile.cpp.mk | 14 +---------- 11 files changed, 38 insertions(+), 49 deletions(-) diff --git a/examples/cpp/fap_model_printer.h b/examples/cpp/fap_model_printer.h index b7eb997312..7528da83cd 100644 --- a/examples/cpp/fap_model_printer.h +++ b/examples/cpp/fap_model_printer.h @@ -23,8 +23,8 @@ #include #include +#include "absl/strings/str_format.h" #include "examples/cpp/fap_parser.h" -#include "ortools/base/stringprintf.h" namespace operations_research { @@ -65,7 +65,7 @@ void FapModelPrinter::PrintFapVariables() { for (const auto& it : variables_) { std::string domain = "{"; for (const int value : it.second.domain) { - StringAppendF(&domain, "%d ", value); + absl::StrAppendFormat(&domain, "%d ", value); } domain.append("}"); @@ -74,13 +74,13 @@ void FapModelPrinter::PrintFapVariables() { hard = " hard"; } - LOG(INFO) << "Variable " << StringPrintf("%3d: ", it.first) - << StringPrintf("(degree: %2d) ", it.second.degree) - << StringPrintf("%3d", it.second.domain_index) - << StringPrintf("%3d", it.second.initial_position) - << StringPrintf("%3d", it.second.mobility_index) - << StringPrintf("%8d", it.second.mobility_cost) - << StringPrintf(" (%2d) ", it.second.domain_size) << domain + LOG(INFO) << "Variable " << absl::StrFormat("%3d: ", it.first) + << absl::StrFormat("(degree: %2d) ", it.second.degree) + << absl::StrFormat("%3d", it.second.domain_index) + << absl::StrFormat("%3d", it.second.initial_position) + << absl::StrFormat("%3d", it.second.mobility_index) + << absl::StrFormat("%8d", it.second.mobility_cost) + << absl::StrFormat(" (%2d) ", it.second.domain_size) << domain << hard; } } @@ -93,11 +93,11 @@ void FapModelPrinter::PrintFapConstraints() { hard = " hard"; } - LOG(INFO) << StringPrintf("%3d ", ct.variable1) - << StringPrintf("%3d ", ct.variable2) << ct.type << " " - << ct.operation << " " << StringPrintf("%3d", ct.value) - << StringPrintf("%3d", ct.weight_index) - << StringPrintf("%8d", ct.weight_cost) << hard; + LOG(INFO) << absl::StrFormat("%3d ", ct.variable1) + << absl::StrFormat("%3d ", ct.variable2) << ct.type << " " + << ct.operation << " " << absl::StrFormat("%3d", ct.value) + << absl::StrFormat("%3d", ct.weight_index) + << absl::StrFormat("%8d", ct.weight_cost) << hard; } } @@ -106,10 +106,10 @@ void FapModelPrinter::PrintFapObjective() { } void FapModelPrinter::PrintFapValues() { - LOG(INFO) << StringPrintf("Values(%d): ", static_cast(values_.size())); + LOG(INFO) << absl::StrFormat("Values(%d): ", values_.size()); std::string domain = " "; for (const int value : values_) { - StringAppendF(&domain, "%d ", value); + absl::StrAppendFormat(&domain, "%d ", value); } LOG(INFO) << domain; } diff --git a/examples/cpp/fap_parser.h b/examples/cpp/fap_parser.h index c6c9ffc16c..b449e4a13e 100644 --- a/examples/cpp/fap_parser.h +++ b/examples/cpp/fap_parser.h @@ -24,6 +24,7 @@ #include #include "absl/container/flat_hash_map.h" #include "absl/strings/str_split.h" +#include "ortools/base/file.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/base/strtoint.h" @@ -419,7 +420,7 @@ void ParametersParser::Parse() { void FindComponents(const std::vector& constraints, const std::map& variables, const int maximum_variable_id, - std::unordered_map* components) { + absl::flat_hash_map* components) { std::vector in_component(maximum_variable_id + 1, -1); int constraint_index = 0; for (const FapConstraint& constraint : constraints) { @@ -529,7 +530,7 @@ void ParseInstance(const std::string& data_directory, bool find_components, std::map* variables, std::vector* constraints, std::string* objective, std::vector* frequencies, - std::unordered_map* components) { + absl::flat_hash_map* components) { CHECK(variables != nullptr); CHECK(constraints != nullptr); CHECK(objective != nullptr); diff --git a/examples/cpp/fap_utilities.h b/examples/cpp/fap_utilities.h index fd68e59d01..a8195340ab 100644 --- a/examples/cpp/fap_utilities.h +++ b/examples/cpp/fap_utilities.h @@ -22,11 +22,11 @@ #include #include +#include "absl/strings/str_format.h" #include "examples/cpp/fap_parser.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/stringprintf.h" namespace operations_research { diff --git a/examples/cpp/golomb_sat.cc b/examples/cpp/golomb_sat.cc index 278575a80d..3300421757 100644 --- a/examples/cpp/golomb_sat.cc +++ b/examples/cpp/golomb_sat.cc @@ -30,7 +30,6 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" @@ -81,7 +80,7 @@ void GolombRuler(int size) { // Search strategy. cp_model.AddDecisionStrategy(ticks, DecisionStrategyProto::CHOOSE_FIRST, - DecisionStrategyProto::SELECT_MIN_VALUE); + DecisionStrategyProto::SELECT_MIN_VALUE); Model model; SatParameters parameters; @@ -92,7 +91,7 @@ void GolombRuler(int size) { ¶meters)) << FLAGS_params; } - model.Add(NewSatParameters(parameters)); + model.Add(NewSatParameters(parameters)); const CpSolverResponse response = SolveWithModel(cp_model, &model); if (response.status() == CpSolverStatus::OPTIMAL) { diff --git a/examples/cpp/magic_square_sat.cc b/examples/cpp/magic_square_sat.cc index f083d225c5..9f7c109ee3 100644 --- a/examples/cpp/magic_square_sat.cc +++ b/examples/cpp/magic_square_sat.cc @@ -14,8 +14,8 @@ #include #include +#include "absl/strings/str_format.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" @@ -68,7 +68,7 @@ void MagicSquare(int size) { // Sum on diagonals. builder.AddEquality(LinearExpr::Sum(diag1), sum); builder.AddEquality(LinearExpr::Sum(diag2), sum); - + Model model; model.Add(NewSatParameters(FLAGS_params)); @@ -78,22 +78,22 @@ void MagicSquare(int size) { for (int n = 0; n < size; ++n) { std::string output; for (int m = 0; m < size; ++m) { - StringAppendF(&output, "%3lld ", - SolutionIntegerValue(response, square[n][m])); + absl::StrAppendFormat(&output, "%3d ", + SolutionIntegerValue(response, square[n][m])); } LOG(INFO) << output; - } + } } else { LOG(INFO) << "No solution found!"; } - LOG(INFO) << CpSolverResponseStats(response); + LOG(INFO) << CpSolverResponseStats(response); } } // namespace sat } // namespace sat int main(int argc, char **argv) { - base::SetFlag(&FLAGS_logtostderr, true); + absl::SetFlag(&FLAGS_logtostderr, true); gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::sat::MagicSquare(FLAGS_size); return EXIT_SUCCESS; diff --git a/examples/cpp/network_routing_sat.cc b/examples/cpp/network_routing_sat.cc index 5c64d7f678..b49a3e8954 100644 --- a/examples/cpp/network_routing_sat.cc +++ b/examples/cpp/network_routing_sat.cc @@ -32,13 +32,13 @@ #include #include +#include "absl/strings/str_format.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/base/random.h" -#include "ortools/base/stringprintf.h" #include "ortools/graph/shortestpaths.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" @@ -282,7 +282,7 @@ class NetworkRoutingDataBuilder { NetworkRoutingData *const data) { const int size = num_backbones + num_clients; - const std::string name = StringPrintf( + const std::string name = absl::StrFormat( "mp_c%i_b%i_d%i.t%i-%i.cd%i-%i.bd%i-%i.mc%i.fc%i.s%i", num_clients, num_backbones, num_demands, traffic_min, traffic_max, min_client_degree, max_client_degree, min_backbone_degree, max_backbone_degree, diff --git a/examples/cpp/sat_runner.cc b/examples/cpp/sat_runner.cc index 12bd5f46c7..efa0365152 100644 --- a/examples/cpp/sat_runner.cc +++ b/examples/cpp/sat_runner.cc @@ -442,7 +442,7 @@ int main(int argc, char** argv) { // By default, we want to show how the solver progress. Note that this needs // to be set before InitGoogle() which has the nice side-effect of allowing // the user to override it. - absl::SetFlag(&FLAGS_vmodule, "*cp_model*=1"); + // absl::SetFlag(&FLAGS_vmodule, "*cp_model*=1"); gflags::SetUsageMessage(kUsage); gflags::ParseCommandLineFlags(&argc, &argv, true); absl::SetFlag(&FLAGS_alsologtostderr, true); diff --git a/examples/cpp/slitherlink_sat.cc b/examples/cpp/slitherlink_sat.cc index ca4aec1a99..8b1df8fc20 100644 --- a/examples/cpp/slitherlink_sat.cc +++ b/examples/cpp/slitherlink_sat.cc @@ -17,7 +17,7 @@ #include #include -#include "ortools/base/stringprintf.h" +#include "absl/strings/str_format.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/model.h" @@ -63,7 +63,7 @@ void PrintSolution(const std::vector> &data, const int sum = data[i][j]; first_line += h_arc ? " -----" : " "; second_line += v_arc ? "|" : " "; - second_line += sum == -1 ? " " : StringPrintf(" %d ", sum).c_str(); + second_line += sum == -1 ? " " : absl::StrFormat(" %d ", sum).c_str(); third_line += v_arc ? "| " : " "; } const bool termination = v_arcs[num_columns][i]; diff --git a/examples/cpp/sports_scheduling_sat.cc b/examples/cpp/sports_scheduling_sat.cc index 807dac9a7b..7958a2b545 100644 --- a/examples/cpp/sports_scheduling_sat.cc +++ b/examples/cpp/sports_scheduling_sat.cc @@ -41,9 +41,9 @@ // This aggregated variable will be useful to state constraints of the model // and to do search on it. +#include "absl/strings/str_cat.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/sat/cp_model.h" diff --git a/examples/cpp/weighted_tardiness_sat.cc b/examples/cpp/weighted_tardiness_sat.cc index eac49a2ef6..6e8c1c566b 100644 --- a/examples/cpp/weighted_tardiness_sat.cc +++ b/examples/cpp/weighted_tardiness_sat.cc @@ -217,7 +217,8 @@ void ParseAndSolve() { for (const std::string& line : FileLines(FLAGS_input)) { entries = absl::StrSplit(line, ' ', absl::SkipEmpty()); for (const std::string& entry : entries) { - numbers.push_back(atoi32(entry)); + numbers.push_back(0); + CHECK(absl::SimpleAtoi(entry, &numbers.back())); } } diff --git a/makefiles/Makefile.cpp.mk b/makefiles/Makefile.cpp.mk index a8a5bbd0f8..12d92eea26 100755 --- a/makefiles/Makefile.cpp.mk +++ b/makefiles/Makefile.cpp.mk @@ -422,19 +422,7 @@ test_cc_contrib: ; .PHONY: test_cc_cpp # Build and Run all C++ Examples (located in ortools/examples/cpp) test_cc_cpp: \ - rcc_costas_array_sat \ - rcc_cvrp_disjoint_tw \ - rcc_cvrptw \ - rcc_cvrptw_with_breaks \ - rcc_cvrptw_with_refueling \ - rcc_cvrptw_with_resources \ - rcc_cvrptw_with_stop_times_and_resources \ - rcc_dobble_ls \ - rcc_flow_api \ - rcc_linear_assignment_api \ - rcc_linear_solver_protocol_buffers \ - rcc_magic_square_sat \ - rcc_mps_driver \ +# rcc_mps_driver \ rcc_nqueens \ rcc_random_tsp \ rcc_slitherlink_sat \