aboutsummaryrefslogtreecommitdiff
path: root/solvitaire/src/main/solver/solver.h
diff options
context:
space:
mode:
authorTom Harley2019-01-27 15:37:06 +0000
committerTom Harley2019-01-27 15:37:06 +0000
commita996283af7c21baaff0e114d58c34db820902c6f (patch)
tree2fe5b6f7a800d4a7b8a65ee345f8c98aa138e36b /solvitaire/src/main/solver/solver.h
parentSplit code into 3 files (diff)
downloadmetasol-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/solver/solver.h')
-rw-r--r--solvitaire/src/main/solver/solver.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/solvitaire/src/main/solver/solver.h b/solvitaire/src/main/solver/solver.h
new file mode 100644
index 0000000..74c73a8
--- /dev/null
+++ b/solvitaire/src/main/solver/solver.h
@@ -0,0 +1,78 @@
+//
+// Created by thecharlesblake on 10/24/17.
+//
+
+#ifndef SOLVITAIRE_SOLVER_H
+#define SOLVITAIRE_SOLVER_H
+
+#include <string>
+#include <vector>
+#include <atomic>
+#include <chrono>
+
+#include "../game/global_cache.h"
+#include "../game/sol_rules.h"
+#include "../input-output/input/command_line_helper.h"
+
+class solver {
+public:
+ lru_cache cache;
+
+ struct node {
+ node(move);
+ const move mv;
+ std::vector<move> child_moves;
+ boost::optional<lru_cache::item_list::iterator> cache_state; // Optional, as dominance moves aren't cached
+ };
+
+ struct result {
+ enum class type { TIMEOUT, SOLVED, UNSOLVABLE, MEM_LIMIT, TERMINATED };
+
+ type sol_type;
+ uint64_t states_searched;
+ uint64_t unique_states_searched;
+ uint64_t backtracks;
+ uint64_t dominance_moves;
+ uint64_t states_removed_from_cache;
+ lru_cache::item_list::size_type cache_size;
+ lru_cache::item_list::size_type cache_bucket_count;
+ uint64_t max_depth;
+ uint64_t depth;
+ std::chrono::milliseconds time;
+ };
+
+ explicit solver(const game_state&, uint64_t);
+
+ result run(boost::optional<std::chrono::milliseconds> = 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<node> get_frontier() const;
+
+ const game_state init_state;
+
+private:
+ typedef std::chrono::high_resolution_clock clock;
+ typedef std::chrono::milliseconds millisec;
+
+ result::type dfs(boost::optional<clock::time_point> = boost::none);
+
+ bool revert_to_last_node_with_children(boost::optional<lru_cache::item_list::iterator> = boost::none);
+ void set_to_child();
+
+ game_state state;
+ std::vector<node> frontier;
+
+ result res;
+
+ node root;
+ std::vector<node>::iterator current_node;
+};
+
+std::ostream& operator<< (std::ostream&, const solver::result::type&);
+std::ostream& operator<< (std::ostream&, const solver::result&);
+void sigint_handler(int i);
+
+#endif //SOLVITAIRE_SOLVER_H