From fb20d1289ce87234bfae2cb8d784d9edf1d3ff16 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 15 Nov 2017 21:22:40 +0000 Subject: Change history to boost multi-index map --- src/main/solver/solver.cpp | 20 +++++++++----------- src/main/solver/solver.h | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 13 deletions(-) (limited to 'src/main/solver') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index f412d03..a4933b2 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -9,8 +9,6 @@ #include "solver.h" #include "input-output/log_helper.h" -#include "game/game_state.h" -#include using namespace std; using namespace boost; @@ -21,13 +19,13 @@ solver::solver(const game_state gs, const sol_rules& sr) solver::node::node(const node* parent, const game_state& gs) : history(solver::node::gen_history(parent)), state(gs) {} -const vector solver::node::gen_history(const node* parent) { - vector hist; +const solver::node_history solver::node::gen_history(const node* parent) { + node_history hist; if (parent != NULL) { - hist = std::vector(parent->history); - hist.push_back(parent->state); - } else { - hist = vector(); + copy (begin(parent->history.get<0>()), + end(parent->history.get<0>()), + back_inserter(hist.get<0>())); + hist.get<0>().push_back(parent->state); } return hist; } @@ -51,8 +49,8 @@ const optional solver::run() { for (auto it = new_children.rbegin(); it != new_children.rend(); it++) { // If we have seen the state before, ignore it (loop detection)) - if (find(begin(current.history), end(current.history), *it) - != end(current.history)) { + if (current.history.get<1>().find(*it) + != current.history.get<1>().end()) { continue; } @@ -77,7 +75,7 @@ int solver::get_states_searched() const { } std::ostream& operator<< (std::ostream& stream, const solver::node& solution) { - for (auto state : solution.history) { + for (auto state : solution.history.get<0>()) { stream << state << "\n"; } stream << solution.state << "\n"; diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index 91c93d6..73e5e24 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -9,18 +9,30 @@ #include #include +#include +#include +#include +#include #include "game/game_state.h" #include "game/sol_rules.h" class solver { public: + typedef boost::multi_index::multi_index_container< + game_state, + boost::multi_index::indexed_by< + boost::multi_index::sequenced<>, + boost::multi_index::hashed_unique> + > + > node_history; + struct node { node(const node*, const game_state&); - std::vector history; + node_history history; game_state state; - static const std::vector gen_history(const node* parent); + static const node_history gen_history(const node* parent); }; solver(const game_state, const sol_rules&); @@ -33,6 +45,7 @@ public: friend std::ostream& operator<< (std::ostream&, const solver::node&); private: + const node root; const sol_rules rules; node solution; -- cgit v1.2.1 From ddfd79f5ab8bec4949e9a334f62facd67a7d4dfa Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 25 Dec 2017 22:00:42 +0000 Subject: Add necessary features for profiler --- src/main/solver/solver.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/solver') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index a4933b2..02b9c20 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include "solver.h" #include "input-output/log_helper.h" -- cgit v1.2.1