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/evaluation/solvability_calc.cpp | 63 ++------------------------------ src/main/evaluation/solvability_calc.h | 2 - src/main/main.cpp | 16 +++++--- src/main/solver/solver.cpp | 63 ++++++++++++++++++++++++++++++++ src/main/solver/solver.h | 4 ++ 5 files changed, 81 insertions(+), 67 deletions(-) (limited to 'src/main') diff --git a/src/main/evaluation/solvability_calc.cpp b/src/main/evaluation/solvability_calc.cpp index c981644..85a8f34 100644 --- a/src/main/evaluation/solvability_calc.cpp +++ b/src/main/evaluation/solvability_calc.cpp @@ -29,47 +29,6 @@ solvability_calc::solvability_calc(const sol_rules& r, uint64_t cache_capacity_) // PRINTING METHODS // ////////////////////// -void solvability_calc::print_header(long t) const { - cout << "Calculating solvability percentage...\n\n" - "Lower Bound" - ", Upper Bound" - ", Solvable" - ", Unsolvable" - ", Timed-out" - ", Memory Limited, "; - if (stream_opt == cmd_sos::SMART) { - cout << "| (Streamliner Results:) " - "Attempted Seed" - ", Outcome" - ", Time Taken(ms)" - ", States Searched" - ", Unique States Searched" - ", Backtracks" - ", Dominance Moves" - ", States Removed From Cache" - ", Final States In Cache" - ", Final Buckets In Cache" - ", Maximum Search Depth" - ", Final Search Depth" - "| (Non-Streamliner Results:) "; - } - cout << "Attempted Seed" - ", Outcome" - ", Time Taken(ms)" - ", States Searched" - ", Unique States Searched" - ", Backtracks" - ", Dominance Moves" - ", States Removed From Cache" - ", Final States In Cache" - ", Final Buckets In Cache" - ", Maximum Search Depth" - ", Final Search Depth" - ", Seeds In Progress ..." - "\n--- Timeout = " << t << " milliseconds ---\n"; - cout << fixed << setprecision(3); -} - void solvability_calc::print_general_info(const seed_results& seed_res) { pair interval = binomial_ci::wilson( seed_res.solvable, @@ -88,22 +47,8 @@ void solvability_calc::print_seed_info(seed_result seed_res) { int seed = seed_res.first; auto& res = seed_res.second; - cout << ", " << seed - << ", " << res.sol_type - << ", " << res.time.count() - << ", " << res.states_searched - << ", " << res.unique_states_searched - << ", " << res.backtracks - << ", " << res.dominance_moves - << ", " << res.states_removed_from_cache - << ", " << res.cache_size - << ", " << res.cache_bucket_count - << ", " << res.max_depth - << ", " << res.depth; -} - -void solvability_calc::print_null_seed_info() { - cout << ", , , , , , , , , , , , "; + cout << ", " << seed; + solver::print_result_csv(res); } void solvability_calc::print_seeds_in_prog(std::set& seeds_in_progress) { @@ -135,7 +80,7 @@ void solvability_calc::calculate_solvability_percentage(uint64_t timeout_, int s seed_res.timed_out = resume[2]; timeout = millisec(timeout_); - print_header(timeout.count()); + solver::print_header(timeout.count(), stream_opt_); seed_count = seed_count_; stream_opt = stream_opt_; @@ -186,7 +131,7 @@ void solvability_calc::solver_thread(solvability_calc* sc, uint core) { if (sc->stream_opt == cmd_sos::SMART) { print_seed_info(*stream_res); if (no_stream_res) print_seed_info(*no_stream_res); - else print_null_seed_info(); + else solver::print_null_seed_info(); } else { print_seed_info(*no_stream_res); } diff --git a/src/main/evaluation/solvability_calc.h b/src/main/evaluation/solvability_calc.h index cbc3394..25eb844 100644 --- a/src/main/evaluation/solvability_calc.h +++ b/src/main/evaluation/solvability_calc.h @@ -34,10 +34,8 @@ private: }; // Printing methods - void print_header(long) const; static void print_general_info(const seed_results&); static void print_seed_info(seed_result); - static void print_null_seed_info(); static void print_seeds_in_prog(std::set&); // Solving methods 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; } diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index abe55f5..3aaceb8 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -9,11 +9,13 @@ #include #include #include +#include #include "solver.h" #include "../game/move.h" #include "../input-output/output/log_helper.h" #include "../input-output/output/state_printer.h" +#include "../input-output/input/command_line_helper.h" using std::atomic; using std::vector; @@ -24,6 +26,8 @@ using std::max; using std::begin; using std::end; using boost::optional; +using std::fixed; +using std::setprecision; solver::solver(const game_state& gs, uint64_t cache_capacity) : cache(lru_cache(gs, cache_capacity)) @@ -240,6 +244,65 @@ std::ostream& operator<< (std::ostream& out, const solver::result& r) { << "Time Taken (milliseconds): " << r.time.count() << "\n"; } +void solver::print_header(long t, command_line_helper::streamliner_opt stream_opt) { + cout << "Calculating solvability percentage...\n\n" + "Lower Bound" + ", Upper Bound" + ", Solvable" + ", Unsolvable" + ", Timed-out" + ", Memory Limited, "; + if (stream_opt == command_line_helper::streamliner_opt::SMART) { + cout << "| (Streamliner Results:) " + "Attempted Seed" + ", Outcome" + ", Time Taken(ms)" + ", States Searched" + ", Unique States Searched" + ", Backtracks" + ", Dominance Moves" + ", States Removed From Cache" + ", Final States In Cache" + ", Final Buckets In Cache" + ", Maximum Search Depth" + ", Final Search Depth" + "| (Non-Streamliner Results:) "; + } + cout << "Attempted Seed" + ", Outcome" + ", Time Taken(ms)" + ", States Searched" + ", Unique States Searched" + ", Backtracks" + ", Dominance Moves" + ", States Removed From Cache" + ", Final States In Cache" + ", Final Buckets In Cache" + ", Maximum Search Depth" + ", Final Search Depth" + ", Seeds In Progress ..." + "\n--- Timeout = " << t << " milliseconds ---\n"; + cout << fixed << setprecision(3); +} + +void solver::print_result_csv(solver::result res) { + cout << ", " << res.sol_type + << ", " << res.time.count() + << ", " << res.states_searched + << ", " << res.unique_states_searched + << ", " << res.backtracks + << ", " << res.dominance_moves + << ", " << res.states_removed_from_cache + << ", " << res.cache_size + << ", " << res.cache_bucket_count + << ", " << res.max_depth + << ", " << res.depth; +} + +void solver::print_null_seed_info() { + cout << ", , , , , , , , , , , , "; +} + const vector solver::get_frontier() const { return frontier; } diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index 4035d6a..90796f7 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -12,6 +12,7 @@ #include "../game/global_cache.h" #include "../game/sol_rules.h" +#include "../input-output/input/command_line_helper.h" class solver { public: @@ -45,6 +46,9 @@ public: result run(boost::optional = boost::none); void print_solution() const; + static void print_header(long, command_line_helper::streamliner_opt); + static void print_result_csv(solver::result); + static void print_null_seed_info(); const std::vector get_frontier() const; private: -- cgit v1.2.1