#include <GoUctBookBuilder.h>
Inheritance diagram for GoUctBookBuilder< PLAYER >:
Supports multithreaded evaluation of children.
Definition at line 30 of file GoUctBookBuilder.h.
Public Member Functions | |
GoUctBookBuilder (const GoBoard &brd) | |
~GoUctBookBuilder () | |
void | SetPlayer (PLAYER &player) |
void | SetState (GoAutoBook &book) |
Sets the state to start work from. | |
float | InverseEval (float eval) const |
bool | IsLoss (float eval) const |
float | Value (const SgBookNode &node) const |
std::size_t | NumThreads () const |
Number of players to use during leaf expansion. | |
void | SetNumThreads (std::size_t num) |
See NumThreads(). | |
std::size_t | NumGamesPerEvaluation () const |
Number of games to play when evaluation a state. | |
void | SetNumGamesPerEvaluation (std::size_t num) |
See NumGamesPerEvaluation. | |
std::size_t | NumGamesPerSort () const |
Number of games to play when sorting children. | |
void | SetNumGamesPerSort (std::size_t num) |
See NumGamesForSort(). | |
void | Expand (int numExpansions) |
void | Refresh () |
void | IncreaseWidth () |
float | ComputePriority (const SgBookNode &parent, const float childValue, const float childPriority) const |
float | Alpha () const |
void | SetAlpha (float alpha) |
bool | UseWidening () const |
void | SetUseWidening (bool flag) |
std::size_t | ExpandWidth () const |
void | SetExpandWidth (std::size_t width) |
std::size_t | ExpandThreshold () const |
void | SetExpandThreshold (std::size_t threshold) |
Protected Member Functions | |
void | PrintMessage (std::string msg) |
void | PlayMove (SgMove move) |
void | UndoMove (SgMove move) |
bool | GetNode (SgBookNode &node) const |
void | WriteNode (const SgBookNode &node) |
void | FlushBook () |
void | EnsureRootExists () |
Creates root node if necessary. | |
bool | GenerateMoves (std::vector< SgMove > &moves, float &value) |
Computes an ordered set of moves to consider. | |
void | GetAllLegalMoves (std::vector< SgMove > &moves) |
void | EvaluateChildren (const std::vector< SgMove > &childrenToDo, std::vector< std::pair< SgMove, float > > &scores) |
void | Init () |
void | StartIteration (int iteration) |
void | EndIteration () |
void | BeforeEvaluateChildren () |
void | AfterEvaluateChildren () |
void | Fini () |
void | ClearAllVisited () |
void | MarkAsVisited () |
bool | HasBeenVisited () |
Protected Attributes | |
float | m_alpha |
bool | m_use_widening |
std::size_t | m_expand_width |
std::size_t | m_expand_threshold |
std::size_t | m_flush_iterations |
Private Member Functions | |
void | CreateWorkers () |
Copies the player and board and creates the threads. | |
void | DestroyWorkers () |
Destroys copied players, boards, and threads. | |
Private Attributes | |
GoAutoBook * | m_book |
Book this builder is expanding. | |
PLAYER * | m_origPlayer |
GoAutoBookState | m_state |
std::set< SgHashCode > | m_visited |
std::size_t | m_numThreads |
See NumberThreads(). | |
std::size_t | m_numGamesPerEvaluation |
std::size_t | m_numGamesPerSort |
std::size_t | m_num_evals |
std::size_t | m_num_widenings |
std::size_t | m_value_updates |
std::size_t | m_priority_updates |
std::size_t | m_internal_nodes |
std::size_t | m_leaf_nodes |
std::size_t | m_terminal_nodes |
std::vector< PLAYER * > | m_players |
Players for each thread. | |
std::vector< Worker > | m_workers |
SgThreadedWorker< SgMove, float, Worker > * | m_threadedWorker |
Classes | |
class | Worker |
Copyable worker. More... |
GoUctBookBuilder< PLAYER >::GoUctBookBuilder | ( | const GoBoard & | brd | ) |
Definition at line 213 of file GoUctBookBuilder.h.
References SgBookBuilder::SetAlpha(), and SgBookBuilder::SetExpandWidth().
GoUctBookBuilder< PLAYER >::~GoUctBookBuilder | ( | ) |
Definition at line 227 of file GoUctBookBuilder.h.
void GoUctBookBuilder< PLAYER >::AfterEvaluateChildren | ( | ) | [protected, virtual] |
void GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 437 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation, GoUctBookBuilder< PLAYER >::m_numThreads, and GoUctBookBuilder< PLAYER >::m_players.
Referenced by GoUctBookBuilder< PLAYER >::EnsureRootExists().
void GoUctBookBuilder< PLAYER >::ClearAllVisited | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 473 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_visited.
void GoUctBookBuilder< PLAYER >::CreateWorkers | ( | ) | [private] |
Copies the player and board and creates the threads.
Definition at line 235 of file GoUctBookBuilder.h.
References GoAutoBookState::Board(), GoUctBookBuilder< PLAYER >::m_numThreads, GoUctBookBuilder< PLAYER >::m_players, GoUctBookBuilder< PLAYER >::m_state, GoUctBookBuilder< PLAYER >::m_threadedWorker, GoUctBookBuilder< PLAYER >::m_workers, GoUctBookBuilder< PLAYER >::PrintMessage(), and SG_UCTMOVESELECT_ESTIMATE.
Referenced by GoUctBookBuilder< PLAYER >::Init().
void GoUctBookBuilder< PLAYER >::DestroyWorkers | ( | ) | [private] |
Destroys copied players, boards, and threads.
Definition at line 262 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numThreads, GoUctBookBuilder< PLAYER >::m_players, GoUctBookBuilder< PLAYER >::m_threadedWorker, GoUctBookBuilder< PLAYER >::m_workers, and GoUctBookBuilder< PLAYER >::PrintMessage().
Referenced by GoUctBookBuilder< PLAYER >::Fini().
void GoUctBookBuilder< PLAYER >::EndIteration | ( | ) | [protected, virtual] |
void GoUctBookBuilder< PLAYER >::EnsureRootExists | ( | ) | [protected, virtual] |
Creates root node if necessary.
Implements SgBookBuilder.
Definition at line 388 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::GetNode(), GoUctBookBuilder< PLAYER >::m_workers, GoUctBookBuilder< PLAYER >::PrintMessage(), SG_NULLMOVE, and GoUctBookBuilder< PLAYER >::WriteNode().
void GoUctBookBuilder< PLAYER >::EvaluateChildren | ( | const std::vector< SgMove > & | childrenToDo, | |
std::vector< std::pair< SgMove, float > > & | scores | |||
) | [protected, virtual] |
void GoUctBookBuilder< PLAYER >::Fini | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 279 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::DestroyWorkers().
void GoUctBookBuilder< PLAYER >::FlushBook | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 366 of file GoUctBookBuilder.h.
References GoAutoBook::Flush(), GoUctBookBuilder< PLAYER >::m_book, and SgDebug().
bool GoUctBookBuilder< PLAYER >::GenerateMoves | ( | std::vector< SgMove > & | moves, | |
float & | value | |||
) | [protected, virtual] |
Computes an ordered set of moves to consider.
Implements SgBookBuilder.
Definition at line 402 of file GoUctBookBuilder.h.
References GoAutoBookState::Board(), SgUctTreeUtil::FindChildWithMove(), GoBoard::IsLegal(), GoUctBookBuilder< PLAYER >::m_numGamesPerSort, GoUctBookBuilder< PLAYER >::m_players, GoUctBookBuilder< PLAYER >::m_state, GoUctBookBuilder< PLAYER >::m_workers, SgUctNode::PosCount(), SgUctTree::Root(), SG_NULLMOVE, SG_UNUSED(), and SgDebug().
void GoUctBookBuilder< PLAYER >::GetAllLegalMoves | ( | std::vector< SgMove > & | moves | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 379 of file GoUctBookBuilder.h.
References GoAutoBookState::Board(), GoBoard::IsLegal(), and GoUctBookBuilder< PLAYER >::m_state.
bool GoUctBookBuilder< PLAYER >::GetNode | ( | SgBookNode & | node | ) | const [protected, virtual] |
Implements SgBookBuilder.
Definition at line 354 of file GoUctBookBuilder.h.
References GoAutoBook::Get(), GoUctBookBuilder< PLAYER >::m_book, and GoUctBookBuilder< PLAYER >::m_state.
Referenced by GoUctBookBuilder< PLAYER >::EnsureRootExists().
bool GoUctBookBuilder< PLAYER >::HasBeenVisited | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 485 of file GoUctBookBuilder.h.
References GoAutoBookState::GetHashCode(), GoUctBookBuilder< PLAYER >::m_state, and GoUctBookBuilder< PLAYER >::m_visited.
void GoUctBookBuilder< PLAYER >::Init | ( | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 273 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::CreateWorkers().
float GoUctBookBuilder< PLAYER >::InverseEval | ( | float | eval | ) | const [virtual] |
bool GoUctBookBuilder< PLAYER >::IsLoss | ( | float | eval | ) | const [virtual] |
void GoUctBookBuilder< PLAYER >::MarkAsVisited | ( | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 479 of file GoUctBookBuilder.h.
References GoAutoBookState::GetHashCode(), GoUctBookBuilder< PLAYER >::m_state, and GoUctBookBuilder< PLAYER >::m_visited.
std::size_t GoUctBookBuilder< PLAYER >::NumGamesPerEvaluation | ( | ) | const |
std::size_t GoUctBookBuilder< PLAYER >::NumGamesPerSort | ( | ) | const |
Number of games to play when sorting children.
Definition at line 199 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerSort.
std::size_t GoUctBookBuilder< PLAYER >::NumThreads | ( | ) | const |
Number of players to use during leaf expansion.
Each player may use a multi-threaded search. Should speed up the expansion of leaf states by a factor of (very close to) NumThreads().
Definition at line 173 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numThreads.
void GoUctBookBuilder< PLAYER >::PlayMove | ( | SgMove | move | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 341 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_state, and GoAutoBookState::Play().
void GoUctBookBuilder< PLAYER >::PrintMessage | ( | std::string | msg | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 323 of file GoUctBookBuilder.h.
References SgDebug().
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), and GoUctBookBuilder< PLAYER >::EnsureRootExists().
void GoUctBookBuilder< PLAYER >::SetNumGamesPerEvaluation | ( | std::size_t | num | ) |
void GoUctBookBuilder< PLAYER >::SetNumGamesPerSort | ( | std::size_t | num | ) |
See NumGamesForSort().
Definition at line 205 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numGamesPerSort.
void GoUctBookBuilder< PLAYER >::SetNumThreads | ( | std::size_t | num | ) |
See NumThreads().
Definition at line 179 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_numThreads.
void GoUctBookBuilder< PLAYER >::SetPlayer | ( | PLAYER & | player | ) |
Definition at line 310 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_origPlayer.
void GoUctBookBuilder< PLAYER >::SetState | ( | GoAutoBook & | book | ) |
Sets the state to start work from.
Definition at line 316 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_book, GoUctBookBuilder< PLAYER >::m_state, and GoAutoBookState::Synchronize().
void GoUctBookBuilder< PLAYER >::StartIteration | ( | int | iteration | ) | [protected, virtual] |
Reimplemented from SgBookBuilder.
Definition at line 461 of file GoUctBookBuilder.h.
References SgDebug().
void GoUctBookBuilder< PLAYER >::UndoMove | ( | SgMove | move | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 347 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_state, SG_UNUSED(), and GoAutoBookState::Undo().
float GoUctBookBuilder< PLAYER >::Value | ( | const SgBookNode & | node | ) | const [virtual] |
Implements SgBookBuilder.
Definition at line 373 of file GoUctBookBuilder.h.
References SgBookNode::m_value.
void GoUctBookBuilder< PLAYER >::WriteNode | ( | const SgBookNode & | node | ) | [protected, virtual] |
Implements SgBookBuilder.
Definition at line 360 of file GoUctBookBuilder.h.
References GoUctBookBuilder< PLAYER >::m_book, GoUctBookBuilder< PLAYER >::m_state, and GoAutoBook::Put().
Referenced by GoUctBookBuilder< PLAYER >::EnsureRootExists().
GoAutoBook* GoUctBookBuilder< PLAYER >::m_book [private] |
Book this builder is expanding.
Definition at line 129 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::FlushBook(), GoUctBookBuilder< PLAYER >::GetNode(), GoUctBookBuilder< PLAYER >::SetState(), and GoUctBookBuilder< PLAYER >::WriteNode().
std::size_t GoUctBookBuilder< PLAYER >::m_internal_nodes [private] |
std::size_t GoUctBookBuilder< PLAYER >::m_leaf_nodes [private] |
std::size_t GoUctBookBuilder< PLAYER >::m_num_evals [private] |
std::size_t GoUctBookBuilder< PLAYER >::m_num_widenings [private] |
std::size_t GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation [private] |
Definition at line 140 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren().
std::size_t GoUctBookBuilder< PLAYER >::m_numGamesPerSort [private] |
Definition at line 142 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::GenerateMoves(), GoUctBookBuilder< PLAYER >::NumGamesPerSort(), and GoUctBookBuilder< PLAYER >::SetNumGamesPerSort().
std::size_t GoUctBookBuilder< PLAYER >::m_numThreads [private] |
See NumberThreads().
Definition at line 138 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), GoUctBookBuilder< PLAYER >::NumThreads(), and GoUctBookBuilder< PLAYER >::SetNumThreads().
PLAYER* GoUctBookBuilder< PLAYER >::m_origPlayer [private] |
Definition at line 131 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::SetPlayer().
std::vector<PLAYER*> GoUctBookBuilder< PLAYER >::m_players [private] |
Players for each thread.
Definition at line 159 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren(), GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), and GoUctBookBuilder< PLAYER >::GenerateMoves().
std::size_t GoUctBookBuilder< PLAYER >::m_priority_updates [private] |
GoAutoBookState GoUctBookBuilder< PLAYER >::m_state [private] |
Definition at line 133 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::GenerateMoves(), GoUctBookBuilder< PLAYER >::GetAllLegalMoves(), GoUctBookBuilder< PLAYER >::GetNode(), GoUctBookBuilder< PLAYER >::HasBeenVisited(), GoUctBookBuilder< PLAYER >::MarkAsVisited(), GoUctBookBuilder< PLAYER >::PlayMove(), GoUctBookBuilder< PLAYER >::SetState(), GoUctBookBuilder< PLAYER >::UndoMove(), and GoUctBookBuilder< PLAYER >::WriteNode().
std::size_t GoUctBookBuilder< PLAYER >::m_terminal_nodes [private] |
SgThreadedWorker<SgMove,float,Worker>* GoUctBookBuilder< PLAYER >::m_threadedWorker [private] |
Definition at line 163 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), and GoUctBookBuilder< PLAYER >::DestroyWorkers().
std::size_t GoUctBookBuilder< PLAYER >::m_value_updates [private] |
std::set<SgHashCode> GoUctBookBuilder< PLAYER >::m_visited [private] |
Definition at line 135 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::ClearAllVisited(), GoUctBookBuilder< PLAYER >::HasBeenVisited(), and GoUctBookBuilder< PLAYER >::MarkAsVisited().
std::vector<Worker> GoUctBookBuilder< PLAYER >::m_workers [private] |
Definition at line 161 of file GoUctBookBuilder.h.
Referenced by GoUctBookBuilder< PLAYER >::CreateWorkers(), GoUctBookBuilder< PLAYER >::DestroyWorkers(), GoUctBookBuilder< PLAYER >::EnsureRootExists(), and GoUctBookBuilder< PLAYER >::GenerateMoves().