fix the rest of the C++ examples

This commit is contained in:
Laurent Perron
2018-11-28 11:32:45 +01:00
committed by Corentin Le Molgat
parent fe0249dd64
commit 798b9e73e2
11 changed files with 38 additions and 49 deletions

View File

@@ -23,8 +23,8 @@
#include <string>
#include <vector>
#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<int>(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;
}

View File

@@ -24,6 +24,7 @@
#include <vector>
#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<FapConstraint>& constraints,
const std::map<int, FapVariable>& variables,
const int maximum_variable_id,
std::unordered_map<int, FapComponent>* components) {
absl::flat_hash_map<int, FapComponent>* components) {
std::vector<int> 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<int, FapVariable>* variables,
std::vector<FapConstraint>* constraints,
std::string* objective, std::vector<int>* frequencies,
std::unordered_map<int, FapComponent>* components) {
absl::flat_hash_map<int, FapComponent>* components) {
CHECK(variables != nullptr);
CHECK(constraints != nullptr);
CHECK(objective != nullptr);

View File

@@ -22,11 +22,11 @@
#include <set>
#include <vector>
#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 {

View File

@@ -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) {
&parameters))
<< FLAGS_params;
}
model.Add(NewSatParameters(parameters));
model.Add(NewSatParameters(parameters));
const CpSolverResponse response = SolveWithModel(cp_model, &model);
if (response.status() == CpSolverStatus::OPTIMAL) {

View File

@@ -14,8 +14,8 @@
#include <string>
#include <vector>
#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;

View File

@@ -32,13 +32,13 @@
#include <utility>
#include <vector>
#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,

View File

@@ -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);

View File

@@ -17,7 +17,7 @@
#include <string>
#include <vector>
#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<std::vector<int>> &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];

View File

@@ -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"

View File

@@ -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()));
}
}

View File

@@ -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 \