From e1ea0d49c5804921cd4910e891ed263172608d49 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Wed, 25 Jul 2018 09:49:34 +0100 Subject: Make timeout operate using single thread --- src/main/main.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 5c8708e..e8f287b 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -123,15 +123,14 @@ void solve_input_files(const vector input_files, const sol_rules& rules, void solve_game(const game_state& gs, command_line_helper& clh) { solver solv(gs, clh.get_cache_capacity()); - bool solution = solv.run() == solver::sol_state::solved; - - if (solution) { - if (!clh.get_classify()) solv.print_solution(); - cout << "Solved\n"; - } else { - if (!clh.get_classify()) cout << "Deal:\n" << gs << "\n"; - cout << "No Possible Solution\n"; - } + solver::result result = solv.run(); - cout << solv.get_solution_info(); + if (!clh.get_classify()) { + if (result.sol_type == solver::result::type::SOLVED) { + solv.print_solution(); + } else { + cout << "Deal:\n" << gs << "\n"; + } + } + cout << result; } -- cgit v1.2.1 From 4c1a4d02f0a5a4d6daf31744ee8012ff78011196 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Wed, 25 Jul 2018 14:28:05 +0100 Subject: Add timeout to individual games --- src/main/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index e8f287b..ef7131b 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -18,6 +18,8 @@ using namespace boost; namespace po = boost::program_options; +typedef std::chrono::milliseconds millisec; + const optional gen_rules(command_line_helper&); void solve_random_game(int, const sol_rules&, command_line_helper&); void solve_input_files(vector, const sol_rules&, command_line_helper&); @@ -123,7 +125,7 @@ void solve_input_files(const vector input_files, const sol_rules& rules, void solve_game(const game_state& gs, command_line_helper& clh) { solver solv(gs, clh.get_cache_capacity()); - solver::result result = solv.run(); + solver::result result = solv.run(millisec(clh.get_timeout())); if (!clh.get_classify()) { if (result.sol_type == solver::result::type::SOLVED) { -- cgit v1.2.1 From 0c5edfac929ae8e68090af1ef5a4031e9f02f2c2 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Wed, 25 Jul 2018 15:00:18 +0100 Subject: Add csv output to single deal and init sol script --- src/main/main.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index ef7131b..55feedf 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -23,7 +23,7 @@ typedef std::chrono::milliseconds millisec; const optional gen_rules(command_line_helper&); void solve_random_game(int, const sol_rules&, command_line_helper&); void solve_input_files(vector, const sol_rules&, command_line_helper&); -void solve_game(const game_state&, command_line_helper&); +void solve_game(const game_state&, command_line_helper&, int); // Decides what to do given supplied command-line options int main(int argc, const char* argv[]) { @@ -97,7 +97,7 @@ void solve_random_game(int seed, const sol_rules& rules, command_line_helper& cl LOG_INFO ("Attempting to solve with seed: " << seed << "..."); game_state::streamliner_options stream_opts = clh.get_streamliners_game_state(); game_state gs(rules, seed, stream_opts); - solve_game(gs, clh); + solve_game(gs, clh, seed); } void solve_input_files(const vector input_files, const sol_rules& rules, command_line_helper& clh) { @@ -112,7 +112,7 @@ void solve_input_files(const vector input_files, const sol_rules& rules, game_state gs(rules, in_doc, stream_opts); LOG_INFO ("Attempting to solve " << input_file << "..."); - solve_game(gs, clh); + solve_game(gs, clh, -1); } catch (const runtime_error& error) { string errmsg = "Error parsing deal file: "; @@ -122,17 +122,21 @@ void solve_input_files(const vector input_files, const sol_rules& rules, } } -void solve_game(const game_state& gs, command_line_helper& clh) { +void solve_game(const game_state& gs, command_line_helper& clh, int seed) { solver solv(gs, clh.get_cache_capacity()); solver::result result = solv.run(millisec(clh.get_timeout())); - if (!clh.get_classify()) { + if (clh.get_classify()) { + cout << seed; + solver::print_result_csv(result); + cout << "\n"; + } else { if (result.sol_type == solver::result::type::SOLVED) { solv.print_solution(); } else { cout << "Deal:\n" << gs << "\n"; } + cout << result; } - cout << result; } -- cgit v1.2.1 From 3a95f6d9a3be80795c095256b47c51be241df87e Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Wed, 25 Jul 2018 17:39:27 +0100 Subject: Update gen results script to work with changes --- src/main/main.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 55feedf..57540d6 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -125,13 +125,36 @@ void solve_input_files(const vector input_files, const sol_rules& rules, void solve_game(const game_state& gs, command_line_helper& clh, int seed) { solver solv(gs, clh.get_cache_capacity()); - solver::result result = solv.run(millisec(clh.get_timeout())); + solver::result result, streamliner_result; + bool smart = clh.get_streamliners() == command_line_helper::streamliner_opt::SMART; + bool run_again = false; + + if (smart) { + result = solv.run(millisec(clh.get_timeout() / 10)); + run_again = result.sol_type != solver::result::type::SOLVED; + if (run_again) + streamliner_result = solv.run(millisec(clh.get_timeout())); + } else { + result = solv.run(millisec(clh.get_timeout())); + } if (clh.get_classify()) { cout << seed; solver::print_result_csv(result); + if (smart) { + if (run_again) { + solver::print_result_csv(streamliner_result); + } else { + solver::print_null_seed_info(); + } + } cout << "\n"; } else { + if (run_again) { + cout << "Unsolvable using streamliner. Running again...\n"; + result = streamliner_result; + } + if (result.sol_type == solver::result::type::SOLVED) { solv.print_solution(); } else { -- cgit v1.2.1