Skip to content

Commit 36c44ad

Browse files
committed
Implemented time-limit-per-query
1 parent 8a7df6e commit 36c44ad

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

src/api/MainSolver.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ MainSolver::~MainSolver() = default;
8989

9090
void MainSolver::initialize() {
9191
timeLimitImplPtr = std::make_unique<TimeLimitImpl>(*this);
92+
timeLimitPerQueryImplPtr = std::make_unique<TimeLimitImpl>(*this);
9293

9394
frames.push();
9495
frameTerms.push(logic.getTerm_true());
@@ -383,6 +384,11 @@ sstat MainSolver::check() {
383384
timeLimitImplPtr->setLimitIfNotRunning(std::chrono::milliseconds{option.getValue().numval});
384385
}
385386

387+
if (auto option = config.getOption(SMTConfig::o_time_limit_per_query); not option.isEmpty()) {
388+
assert(option.getValue().type == O_NUM);
389+
timeLimitPerQueryImplPtr->setLimit(std::chrono::milliseconds{option.getValue().numval});
390+
}
391+
386392
sstat rval = simplifyFormulas();
387393

388394
if (config.dump_query()) printCurrentAssertionsAsQuery();

src/api/MainSolver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ class MainSolver {
331331

332332
class TimeLimitImpl;
333333
std::unique_ptr<TimeLimitImpl> timeLimitImplPtr;
334+
std::unique_ptr<TimeLimitImpl> timeLimitPerQueryImplPtr;
334335
};
335336

336337
bool MainSolver::trackPartitions() const {

src/bin/opensmt.cc

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace opensmt {
5252

5353
using namespace std::string_literals;
5454

55+
template <typename...>
56+
constexpr bool falseTp = false;
57+
5558
namespace {
5659
bool pipeExecution = false;
5760
}
@@ -244,11 +247,27 @@ void printHelp()
244247
" --minimal-unsat-cores produced unsat cores must be irreducible\n"
245248
" --print-cores-full produced unsat cores are agnostic to the smt2 attribute ':named'\n"
246249
" --produce-interpolants [-i] enables interpolant computation\n"
247-
" --time-limit [-t] <ms> sets wall-clock time limit in milliseconds\n"
250+
" --time-limit [-t] <ms> sets wall-clock time limit in milliseconds since first query\n"
251+
" --time-limit-per-query <ms> sets wall-clock time limit in milliseconds per each query\n"
248252
" --pipe [-p] for execution within a pipe\n";
249253
std::cerr << help_string;
250254
}
251255

256+
template <typename IntT>
257+
IntT parseInt(std::string const & msg) try {
258+
if constexpr (std::is_same_v<IntT, int>) {
259+
return std::stoi(optarg);
260+
} else if constexpr (std::is_same_v<IntT, long>) {
261+
return std::stol(optarg);
262+
} else if constexpr (std::is_same_v<IntT, long long>) {
263+
return std::stoll(optarg);
264+
} else {
265+
static_assert(falseTp<IntT>);
266+
}
267+
} catch (std::logic_error const & e) {
268+
throw std::invalid_argument{msg + e.what()};
269+
}
270+
252271
SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
253272
{
254273
enum class LongOpt {
@@ -258,6 +277,7 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
258277
getUcore,
259278
minUcore,
260279
fullUcore,
280+
timeLimitPerQuery,
261281
};
262282

263283
SMTConfig res;
@@ -278,6 +298,7 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
278298
{"print-cores-full", no_argument, &selectedLongOpt, to_underlying(LongOpt::fullUcore)},
279299
{"produce-interpolants", no_argument, nullptr, 'i'},
280300
{"time-limit", required_argument, nullptr, 't'},
301+
{"time-limit-per-query", required_argument, &selectedLongOpt, to_underlying(LongOpt::timeLimitPerQuery)},
281302
{"pipe", no_argument, nullptr, 'p'},
282303
{0, 0, 0, 0}
283304
};
@@ -310,6 +331,10 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
310331
case LongOpt::fullUcore:
311332
res.setOption(SMTConfig::o_print_cores_full, SMTOption(true), msg);
312333
break;
334+
case LongOpt::timeLimitPerQuery:
335+
auto timeLimit = parseInt<int64_t>("Invalid argument of time-limit-per-query: ");
336+
ok &= res.setOption(SMTConfig::o_time_limit_per_query, SMTOption{timeLimit}, msg);
337+
break;
313338
}
314339
break;
315340
case 'h':
@@ -334,13 +359,7 @@ SMTConfig parseCMDLineArgs( int argc, char * argv[ ] )
334359
res.setOption(SMTConfig::o_produce_inter, SMTOption{true}, msg);
335360
break;
336361
case 't': {
337-
int64_t timeLimit;
338-
try {
339-
timeLimit = std::stoll(optarg);
340-
} catch (std::logic_error const & e) {
341-
throw std::invalid_argument{"Invalid argument of time-limit: "s + e.what()};
342-
}
343-
362+
auto timeLimit = parseInt<int64_t>("Invalid argument of time-limit: ");
344363
ok &= res.setOption(SMTConfig::o_time_limit, SMTOption{timeLimit}, msg);
345364
break;
346365
}

src/options/SMTConfig.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ namespace opensmt {
415415
{ msg = s_err_unknown_units; return false; }
416416
}
417417

418-
if (strcmp(name, o_time_limit) == 0) {
418+
if (strcmp(name, o_time_limit) == 0 || strcmp(name, o_time_limit_per_query) == 0) {
419419
if (value.getValue().type != O_NUM) { msg = s_err_not_num; return false; }
420420
if (value.getValue().numval <= 0) { msg = s_err_not_positive; return false; }
421421
}
@@ -535,6 +535,7 @@ namespace opensmt {
535535
const char* SMTConfig::o_global_declarations = ":global-declarations";
536536
const char* SMTConfig::o_sat_split_mode = ":split-mode";
537537
const char* SMTConfig::o_time_limit = ":time-limit";
538+
const char* SMTConfig::o_time_limit_per_query = ":time-limit-per-query";
538539

539540
char* SMTConfig::server_host=NULL;
540541
uint16_t SMTConfig::server_port = 0;

src/options/SMTConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ namespace opensmt {
329329

330330
// Wall-clock time limit for the solver in miliseconds
331331
static const char* o_time_limit;
332+
static const char* o_time_limit_per_query;
332333
private:
333334

334335
static const char* s_err_not_str;

0 commit comments

Comments
 (0)