From 1ed10a127b0d9580b810c20b21cbe92342345be2 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 7 Apr 2018 14:49:57 +0100 Subject: Add tuned optimisation eval games --- CMakeLists.txt | 10 +++ src/main/evaluation/benchmark.cpp | 14 ++-- src/main/game/global_cache.cpp | 27 +++++--- src/main/input-output/input/sol_preset_types.cpp | 88 ++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65b973d..d5eef74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,16 @@ add_executable(solvitaire-no-pile-symmetry ${main} ${sources}) target_link_libraries(solvitaire-no-pile-symmetry LINK_PUBLIC ${Boost_LIBRARIES}) set_target_properties(solvitaire-no-pile-symmetry PROPERTIES COMPILE_FLAGS -DNO_PILE_SYMMETRY) +# add a separete executable for the 'no suit symmetry' version of the solver +add_executable(solvitaire-no-suit-symmetry ${main} ${sources}) +target_link_libraries(solvitaire-no-suit-symmetry LINK_PUBLIC ${Boost_LIBRARIES}) +set_target_properties(solvitaire-no-suit-symmetry PROPERTIES COMPILE_FLAGS -DNO_SUIT_SYMMETRY) + +# add a separete executable for the 'no symmetry' version of the solver +add_executable(solvitaire-no-symmetry ${main} ${sources}) +target_link_libraries(solvitaire-no-symmetry LINK_PUBLIC ${Boost_LIBRARIES}) +set_target_properties(solvitaire-no-symmetry PROPERTIES COMPILE_FLAGS "-DNO_SUIT_SYMMETRY -DNO_PILE_SYMMETRY") + # add a separete executable for the 'no reduced state' version of the solver add_executable(solvitaire-no-reduced-state ${main} ${sources}) target_link_libraries(solvitaire-no-reduced-state LINK_PUBLIC ${Boost_LIBRARIES}) diff --git a/src/main/evaluation/benchmark.cpp b/src/main/evaluation/benchmark.cpp index 79e2edc..74d34a3 100644 --- a/src/main/evaluation/benchmark.cpp +++ b/src/main/evaluation/benchmark.cpp @@ -10,14 +10,14 @@ #include "../solver/solver.h" using namespace std; -typedef chrono::milliseconds millisec; +typedef chrono::microseconds microsec; void benchmark::run(const sol_rules &rules) { cout << "Seed " - "| Median Solution Time(ms) " + "| Median Solution Time(μs) " "| Median States Searched " - "| Median (Non-Zero) Solution Depth " "| Median Backtracks " + "| Median (Non-Zero) Solution Depth " "| Solvable/Unsolvable "; multiset sol_times; @@ -34,10 +34,10 @@ void benchmark::run(const sol_rules &rules) { auto start = chrono::steady_clock::now(); solver::sol_state result = sol.run(); auto end = chrono::steady_clock::now(); - millisec elapsed_millis = - chrono::duration_cast(end - start); + microsec elapsed_micros = + chrono::duration_cast(end - start); - sol_times.insert(static_cast(elapsed_millis.count())); + sol_times.insert(static_cast(elapsed_micros.count())); states_searched.insert(sol.get_states_searched()); if (sol.get_final_depth() != 0) sol_depths.insert(sol.get_final_depth()); backtracks.insert(sol.get_backtrack_count()); @@ -56,8 +56,8 @@ void benchmark::run(const sol_rules &rules) { cout << "\n" << seed << " | " << *next(begin(sol_times), (sol_times.size())/2) << " | " << *next(begin(states_searched), (states_searched.size())/2) - << " | " << *next(begin(sol_depths), (sol_depths.size())/2) << " | " << *next(begin(backtracks), (backtracks.size())/2) + << " | " << *next(begin(sol_depths), (sol_depths.size())/2) << " | " << total_solvable << "/" << total_unsolvable; } diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp index 29e8d25..44d4bb7 100644 --- a/src/main/game/global_cache.cpp +++ b/src/main/game/global_cache.cpp @@ -87,9 +87,16 @@ void cached_game_state::add_card(card c, const game_state& gs) { // If the game is a 'hole-based' game, or suit-reduction is on, reduces // the cached suit of the card where possible -#ifndef SUIT_REDUCTION_STREAMLINER - if (gs.rules.hole) { + + bool is_suit_symmetry = gs.rules.hole; +#ifdef SUIT_REDUCTION_STREAMLINER + is_suit_symmetry = true; +#endif +#ifdef NO_SUIT_SYMMETRY + is_suit_symmetry = false; #endif + + if (is_suit_symmetry) { switch (gs.rules.build_pol) { case pol::SAME_SUIT: target.emplace_back(c); @@ -101,11 +108,9 @@ void cached_game_state::add_card(card c, const game_state& gs) { target.emplace_back(0, c.get_rank()); break; } -#ifndef SUIT_REDUCTION_STREAMLINER } else { target.emplace_back(c); } -#endif } void cached_game_state::add_card_divider() { @@ -160,10 +165,16 @@ size_t hasher::hash_value(card const& c) const { // If the game is a 'hole-based' game, or suit-reduction is enabled, hash // the reduced suit - uint8_t suit_val; -#ifndef SUIT_REDUCTION_STREAMLINER - if (init_gs.rules.hole) { + bool is_suit_symmetry = init_gs.rules.hole; +#ifdef SUIT_REDUCTION_STREAMLINER + is_suit_symmetry = true; +#endif +#ifdef NO_SUIT_SYMMETRY + is_suit_symmetry = false; #endif + + uint8_t suit_val; + if (is_suit_symmetry) { switch (init_gs.rules.build_pol) { case pol::SAME_SUIT: suit_val = c.get_suit(); @@ -174,11 +185,9 @@ size_t hasher::hash_value(card const& c) const { default: suit_val = 0; } -#ifndef SUIT_REDUCTION_STREAMLINER } else { suit_val = c.get_suit(); } -#endif auto raw_val = static_cast(suit_val * 13 + c.get_rank()); return boost_hasher(raw_val); diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index e4d06a3..4afc86f 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -858,6 +858,94 @@ map sol_preset_types::mp = { } )" + }, + { + "test-game-black-hole", + + R"( + +{ + "tableau piles": { + "count": 7, + "build policy": "no-build" + }, + "max rank": 8, + "hole": true, + "foundations": false +} +)" + }, + { + "test-game-any-suit", + + R"( + +{ + "tableau piles": { + "count": 5, + "build policy": "any-suit" + }, + "max rank": 6 +} +)" + }, + { + "test-game-red-black", + + R"( + +{ + "tableau piles": { + "count": 7, + "build policy": "red-black" + }, + "max rank": 8 +} +)" + }, + { + "test-game-same-suit", + + R"( + +{ + "tableau piles": { + "count": 10, + "build policy": "same-suit" + }, + "max rank": 9 +} +)" + }, + { + "test-game-founds-removable", + + R"( + +{ + "tableau piles": { + "count": 7, + "build policy": "red-black" + }, + "max rank": 8, + "foundations removable": true +} +)" + }, + { + "test-game-diagonal-deal", + + R"( + +{ + "tableau piles": { + "count": 7, + "build policy": "red-black", + "diagonal deal": true + }, + "max rank": 8 +} +)" } }; -- cgit v1.2.1