aboutsummaryrefslogtreecommitdiff
path: root/src/main/solver/solver.h
diff options
context:
space:
mode:
authorCharlie Blake2018-07-25 09:49:34 +0100
committerCharlie Blake2018-07-26 10:32:38 +0100
commite1ea0d49c5804921cd4910e891ed263172608d49 (patch)
tree44df2ad6c36873e091a7c3a2892c4edf2c69901a /src/main/solver/solver.h
parentMerge pull request #78 from thecharlesblake/add-canfield (diff)
downloadmetasol-e1ea0d49c5804921cd4910e891ed263172608d49.tar.gz
metasol-e1ea0d49c5804921cd4910e891ed263172608d49.zip

Make timeout operate using single thread

Diffstat (limited to 'src/main/solver/solver.h')
-rw-r--r--src/main/solver/solver.h30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h
index 3aa0d95..75ee603 100644
--- a/src/main/solver/solver.h
+++ b/src/main/solver/solver.h
@@ -14,7 +14,6 @@
class solver {
public:
- enum class sol_state {solved, unsolvable, timed_out};
lru_cache cache;
struct node {
@@ -24,7 +23,10 @@ public:
boost::optional<lru_cache::item_list::iterator> cache_state; // Optional, as dominance moves aren't cached
};
- struct solution_info {
+ struct result {
+ enum class type { TIMEOUT, SOLVED, UNSOLVABLE, MEM_LIMIT };
+
+ type sol_type;
int states_searched;
int unique_states_searched;
int backtracks;
@@ -34,22 +36,22 @@ public:
lru_cache::item_list::size_type cache_bucket_count;
int max_depth;
int depth;
+ std::chrono::milliseconds time;
};
- friend std::ostream& operator<< (std::ostream&, const solution_info&);
explicit solver(const game_state&, uint64_t);
- sol_state run(boost::optional<std::atomic<bool> &> = boost::none);
+ result run(boost::optional<std::chrono::milliseconds> = boost::none);
void print_solution() const;
- int get_states_searched() const;
- int get_unique_states_searched() const;
- int get_cache_size() const;
- int get_states_rem_from_cache() const;
const std::vector<node> get_frontier() const;
- solution_info get_solution_info();
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();
@@ -57,16 +59,14 @@ private:
game_state state;
std::vector<node> frontier;
- int states_searched;
- int unique_states_searched;
- int backtracks;
- int dominance_moves;
- int depth;
- int max_depth;
+ 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&);
+
#endif //SOLVITAIRE_SOLVER_H