Skip to content

Commit c88a5a8

Browse files
author
sicco
committed
added timeout to search mode, set via --searchtimeout parameter
1 parent 4e5ed7d commit c88a5a8

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

source/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ int main(int argc, char *argv[]){
162162
app.add_option("--searchlocal", SEARCH_LOCAL, "Search using the local heuristic from the evaluation function. Default=0.");
163163
app.add_option("--searchglobal", SEARCH_GLOBAL, "Search using the global heuristic from the evaluation function. Default=0.");
164164
app.add_option("--searchpartial", SEARCH_PARTIAL, "Search using the partial heuristic from the evaluation function. Default=0.");
165+
app.add_option("--searchtimeout", SEARCH_TIME_OUT, "Timeout in seconds for the search process. When exceeded, the search will finish the current run and return the best discovered solution. Default=600. Set to -1 to use no timeout.");
165166

166167
app.add_option("--predictreset", PREDICT_RESET, "When predicting and there is no outgoing transition, the model is reset to the root state. This works well when using sliding windows. Default=0.");
167168
app.add_option("--predictremain", PREDICT_REMAIN, "When predicting and there is no outgoing transition, the model is looped back into the current state. Default=0.");

source/parameters.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,5 @@ std::string POSTGRESQL_TBLNAME = "";
169169
bool POSTGRESQL_DROPTBLS = true;
170170

171171
std::string PRINT_MODEL_PREFIX = ""; // TODO: delete this one
172+
173+
int SEARCH_TIME_OUT = 600;

source/parameters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,6 @@ extern int DFA_SIZE_BOUND;
198198
extern int APTA_SIZE_BOUND;
199199
extern bool SAT_RUN_GREEDY;
200200

201+
extern int SEARCH_TIME_OUT;
202+
201203
#endif

source/running_modes/search_mode.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "common.h"
1515

1616
#include <queue>
17+
#include <chrono>
1718

1819
using namespace std;
1920

@@ -160,7 +161,8 @@ void change_refinement_list(state_merger* merger, refinement_list* new_list){
160161
}
161162

162163
int search_mode::run(){
163-
start_size = merger->get_final_apta_size();
164+
auto time_start = std::chrono::high_resolution_clock::now();
165+
start_size = merger->get_final_apta_size();
164166
best_solution = -1;
165167
current_run = new refinement_list();
166168

@@ -177,19 +179,23 @@ int search_mode::run(){
177179
MERGE_SINKS_WITH_CORE = temp_merge_sinks_core;
178180
}
179181

180-
add_to_q(merger);
182+
add_to_q(merger);
181183

182184
cerr << Q.size() << endl;
183185

184-
while(!Q.empty()){
185-
pair<double, refinement_list*> next_refinements = Q.top();
186-
change_refinement_list(merger, next_refinements.second);
187-
Q.pop();
186+
while(!Q.empty()){
187+
pair<double, refinement_list*> next_refinements = Q.top();
188+
change_refinement_list(merger, next_refinements.second);
189+
Q.pop();
188190

189-
cerr << Q.size() << " " << current_refinements->size() << " " << next_refinements.first << endl;
191+
cerr << Q.size() << " " << current_refinements->size() << " " << next_refinements.first << endl;
190192

191193
add_to_q(merger);
192-
}
194+
195+
if (SEARCH_TIME_OUT != -1 && std::chrono::high_resolution_clock::now() - time_start > std::chrono::seconds(SEARCH_TIME_OUT)) {
196+
break;
197+
}
198+
}
193199

194200
return EXIT_SUCCESS;
195201
}

0 commit comments

Comments
 (0)