diff options
| author | Tom Harley | 2019-01-27 15:37:06 +0000 |
|---|---|---|
| committer | Tom Harley | 2019-01-27 15:37:06 +0000 |
| commit | a996283af7c21baaff0e114d58c34db820902c6f (patch) | |
| tree | 2fe5b6f7a800d4a7b8a65ee345f8c98aa138e36b /solvitaire/src/main/evaluation/benchmark.cpp | |
| parent | Split code into 3 files (diff) | |
| download | metasol-a996283af7c21baaff0e114d58c34db820902c6f.tar.gz metasol-a996283af7c21baaff0e114d58c34db820902c6f.zip | |
Reorganise repo
All solvitaire content has been shoved into a subdirectory to tidy up the root of the project. This also means solvitaire is treated similarly to other dependencies of the project, and allows other dependencies to be added easily.
There’s also a lot of other work done here, such as usign a thread pool library to manage the running of the voters.
Diffstat (limited to 'solvitaire/src/main/evaluation/benchmark.cpp')
| -rw-r--r-- | solvitaire/src/main/evaluation/benchmark.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/solvitaire/src/main/evaluation/benchmark.cpp b/solvitaire/src/main/evaluation/benchmark.cpp new file mode 100644 index 0000000..f66573c --- /dev/null +++ b/solvitaire/src/main/evaluation/benchmark.cpp @@ -0,0 +1,63 @@ +// +// Created by thecharlesblake on 4/5/18. +// + +#include <climits> +#include <iostream> +#include <numeric> + +#include "benchmark.h" +#include "../game/search-state/game_state.h" +#include "../solver/solver.h" + +using namespace std; +typedef chrono::microseconds microsec; + +void benchmark::run(const sol_rules &rules, uint64_t cache_capacity, game_state::streamliner_options streamliners) { + cout << "Seed " + "| Median/Mean Solution Time(μs) " + "| Median/Mean States Searched " + "| Solvable/Unsolvable"; + + multiset<int> sol_times; + multiset<int> states_searched; + int total_time = 0; + int total_states = 0; + int total_solvable = 0; + int total_unsolvable = 0; + + for(int seed = 1; seed <= 1000; seed++) { + game_state gs(rules, seed, streamliners); + solver sol(gs, cache_capacity); + + auto start = chrono::steady_clock::now(); + solver::result result = sol.run(); + auto end = chrono::steady_clock::now(); + microsec elapsed_micros = + chrono::duration_cast<chrono::microseconds>(end - start); + + sol_times.insert(static_cast<int>(elapsed_micros.count())); + total_time += static_cast<int>(elapsed_micros.count()); + states_searched.insert(result.states_searched); + total_states += result.states_searched; + switch (result.sol_type) { + case solver::result::type::SOLVED: + total_solvable++; + break; + case solver::result::type::UNSOLVABLE: + total_unsolvable++; + break; + default: + assert(false); + break; + } + + cout << "\n" << seed + << " | " << *next(begin(sol_times), (sol_times.size())/2) + << "/" << total_time/sol_times.size() + << " | " << *next(begin(states_searched), (states_searched.size())/2) + << "/" << total_states/sol_times.size() + << " | " << total_solvable + << "/" << total_unsolvable; + } +} |
