From e41e25b3d869af152c6f4317713cdc682edc16fb Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Wed, 13 Oct 2021 16:39:39 +0200 Subject: [PATCH] tweak the default time limit in solve.cc --- examples/cpp/solve.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/cpp/solve.cc b/examples/cpp/solve.cc index 50cf220a68..dbb50b7a15 100644 --- a/examples/cpp/solve.cc +++ b/examples/cpp/solve.cc @@ -82,9 +82,10 @@ ABSL_FLAG(std::string, params_file, "", "Solver specific parameters file. " "If this flag is set, the --params flag is ignored."); ABSL_FLAG(std::string, params, "", "Solver specific parameters"); -ABSL_FLAG(absl::Duration, time_limit, absl::ZeroDuration(), - "If strictly positive, specifies a limit on the solving time. " - "Otherwise, no time limit will be imposed."); +ABSL_FLAG(absl::Duration, time_limit, absl::InfiniteDuration(), + "It specifies a limit on the solving time. The duration must be must " + "be positive. It default to an infinite duration meaning that no " + "time limit will be imposed."); ABSL_FLAG(std::string, output_csv, "", "If non-empty, write the returned solution in csv format with " "each line formed by a variable name and its value."); @@ -219,7 +220,7 @@ bool Run(MPSolver::OptimizationProblemType type) { } // Time limits. - if (absl::GetFlag(FLAGS_time_limit) > absl::ZeroDuration()) { + if (absl::GetFlag(FLAGS_time_limit) != absl::InfiniteDuration()) { LOG(INFO) << "Setting a time limit of " << absl::GetFlag(FLAGS_time_limit); // Overwrite the request time limit. request_proto.set_solver_time_limit_seconds( @@ -329,6 +330,8 @@ int main(int argc, char** argv) { google::InitGoogleLogging(kUsageStr); absl::ParseCommandLine(argc, argv); QCHECK(!absl::GetFlag(FLAGS_input).empty()) << "--input is required"; + QCHECK_GE(absl::GetFlag(FLAGS_time_limit), absl::ZeroDuration()) + << "--time_limit must be given a positive duration"; operations_research::MPSolver::OptimizationProblemType type; CHECK(operations_research::MPSolver::ParseSolverType(