backport examples from main

This commit is contained in:
Mizux Seiha
2025-02-25 16:03:40 +01:00
parent bdfbbc6809
commit c96c824034
28 changed files with 137 additions and 87 deletions

View File

@@ -24,10 +24,12 @@
#include <utility>
#include <vector>
#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=";

View File

@@ -13,8 +13,12 @@
// Constraint programming example that shows how to use the API.
#include <cstdint>
#include <cstdlib>
#include <vector>
#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<IntVar*> 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;

View File

@@ -28,7 +28,9 @@
#include <utility>
#include <vector>
#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;

View File

@@ -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<std::string>* lines) {
CHECK(lines != nullptr);
std::string result;

View File

@@ -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<std::string>* lines);
// The FapVariable struct represents a radio link of the

View File

@@ -26,16 +26,21 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#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) {

View File

@@ -13,10 +13,12 @@
// Integer programming example that shows how to use the API.
#include <cstdlib>
#include <string>
#include <vector>
#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;

View File

@@ -18,10 +18,12 @@
#include <string>
#include <vector>
#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()) {

View File

@@ -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 <algorithm>
#include <cstdint>
#include <limits>
#include <cstdlib>
#include <string>
#include <vector>
#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=";

View File

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

View File

@@ -11,15 +11,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits>
#include <string>
#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<double>::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

View File

@@ -22,11 +22,13 @@
#include <string>
#include <vector>
#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));

View File

@@ -11,17 +11,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstdlib>
#include <string>
#include <vector>
#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));

View File

@@ -11,10 +11,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstdlib>
#include <utility>
#include <vector>
#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;

View File

@@ -13,10 +13,12 @@
#include "ortools/graph/min_cost_flow.h"
#include <cstdlib>
#include <utility>
#include <vector>
#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;

View File

@@ -16,23 +16,27 @@
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <vector>
#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(&parameters);

View File

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

View File

@@ -28,23 +28,29 @@
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <random>
#include <string>
#include <utility>
#include <vector>
#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;

View File

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

View File

@@ -21,9 +21,10 @@
#include <optional>
#include <string>
#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(

View File

@@ -47,8 +47,10 @@
#include <vector>
#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<int64_t>(
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<int64_t>(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<int64_t>(
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<int64_t>& 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<int64_t>(scaling_factor * window.start));
cumul->SetMax(MathUtil::Round<int64_t>(scaling_factor * window.end));
}
if (search_parameters->local_search_metaheuristic() ==
@@ -234,7 +236,7 @@ void SetupModel(const routing::LiLimParser& parser,
++order) {
std::vector<int64_t> orders(1, manager.NodeToIndex(order));
model->AddDisjunction(orders,
MathUtil::FastInt64Round(scaling_factor * kPenalty));
MathUtil::Round<int64_t>(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<int64_t>(assignment.Min(arrival) * scaling_factor),
MathUtil::Round<int64_t>(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<int64_t>(assignment.Min(arrival) * scaling_factor),
MathUtil::Round<int64_t>(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();

View File

@@ -27,22 +27,24 @@
// performing all the jobs.
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <string>
#include <vector>
#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()) {

View File

@@ -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 <cstdlib>
#include <string>
#include <vector>
#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";

View File

@@ -57,14 +57,13 @@
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#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 <n> 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;

View File

@@ -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 <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#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));

View File

@@ -15,6 +15,7 @@
#include <string>
#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=";

View File

@@ -13,12 +13,15 @@
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <numeric>
#include <string>
#include <vector>
#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=";

View File

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