Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoUctBookBuilder< PLAYER > Class Template Reference
[Automatic Opening Book Construction]

#include <GoUctBookBuilder.h>

Inheritance diagram for GoUctBookBuilder< PLAYER >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class PLAYER>
class GoUctBookBuilder< PLAYER >

Expands a Book using the given player to evaluate game positions.

Supports multithreaded evaluation of children.

Todo:
Copy settings from passed player to other players.

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

GoAutoBookm_book
 Book this builder is expanding.
PLAYER * m_origPlayer
GoAutoBookState m_state
std::set< SgHashCodem_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< Workerm_workers
SgThreadedWorker< SgMove,
float, Worker > * 
m_threadedWorker

Classes

class  Worker
 Copyable worker. More...


Constructor & Destructor Documentation

template<class PLAYER>
GoUctBookBuilder< PLAYER >::GoUctBookBuilder ( const GoBoard brd  ) 

Definition at line 213 of file GoUctBookBuilder.h.

References SgBookBuilder::SetAlpha(), and SgBookBuilder::SetExpandWidth().

template<class PLAYER>
GoUctBookBuilder< PLAYER >::~GoUctBookBuilder (  ) 

Definition at line 227 of file GoUctBookBuilder.h.


Member Function Documentation

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::AfterEvaluateChildren (  )  [protected, virtual]

Reimplemented from SgBookBuilder.

Definition at line 456 of file GoUctBookBuilder.h.

template<class PLAYER>
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().

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::ClearAllVisited (  )  [protected, virtual]

Implements SgBookBuilder.

Definition at line 473 of file GoUctBookBuilder.h.

References GoUctBookBuilder< PLAYER >::m_visited.

template<class PLAYER>
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().

template<class PLAYER>
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().

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::EndIteration (  )  [protected, virtual]

Reimplemented from SgBookBuilder.

Definition at line 467 of file GoUctBookBuilder.h.

template<class PLAYER>
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().

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::EvaluateChildren ( const std::vector< SgMove > &  childrenToDo,
std::vector< std::pair< SgMove, float > > &  scores 
) [protected, virtual]

Implements SgBookBuilder.

Definition at line 445 of file GoUctBookBuilder.h.

References SgDebug().

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::Fini (  )  [protected, virtual]

Reimplemented from SgBookBuilder.

Definition at line 279 of file GoUctBookBuilder.h.

References GoUctBookBuilder< PLAYER >::DestroyWorkers().

template<class PLAYER>
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().

template<class PLAYER>
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().

template<class PLAYER>
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.

template<class PLAYER>
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().

template<class PLAYER>
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.

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::Init (  )  [protected, virtual]

Reimplemented from SgBookBuilder.

Definition at line 273 of file GoUctBookBuilder.h.

References GoUctBookBuilder< PLAYER >::CreateWorkers().

template<class PLAYER>
float GoUctBookBuilder< PLAYER >::InverseEval ( float  eval  )  const [virtual]

Implements SgBookBuilder.

Definition at line 329 of file GoUctBookBuilder.h.

template<class PLAYER>
bool GoUctBookBuilder< PLAYER >::IsLoss ( float  eval  )  const [virtual]

Implements SgBookBuilder.

Definition at line 335 of file GoUctBookBuilder.h.

template<class PLAYER>
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.

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::NumGamesPerEvaluation (  )  const

Number of games to play when evaluation a state.

Definition at line 186 of file GoUctBookBuilder.h.

template<class PLAYER>
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.

template<class PLAYER>
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.

template<class PLAYER>
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().

template<class PLAYER>
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().

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::SetNumGamesPerEvaluation ( std::size_t  num  ) 

See NumGamesPerEvaluation.

Definition at line 193 of file GoUctBookBuilder.h.

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::SetNumGamesPerSort ( std::size_t  num  ) 

See NumGamesForSort().

Definition at line 205 of file GoUctBookBuilder.h.

References GoUctBookBuilder< PLAYER >::m_numGamesPerSort.

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::SetNumThreads ( std::size_t  num  ) 

See NumThreads().

Definition at line 179 of file GoUctBookBuilder.h.

References GoUctBookBuilder< PLAYER >::m_numThreads.

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::SetPlayer ( PLAYER &  player  ) 

Definition at line 310 of file GoUctBookBuilder.h.

References GoUctBookBuilder< PLAYER >::m_origPlayer.

template<class PLAYER>
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().

template<class PLAYER>
void GoUctBookBuilder< PLAYER >::StartIteration ( int  iteration  )  [protected, virtual]

Reimplemented from SgBookBuilder.

Definition at line 461 of file GoUctBookBuilder.h.

References SgDebug().

template<class PLAYER>
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().

template<class PLAYER>
float GoUctBookBuilder< PLAYER >::Value ( const SgBookNode node  )  const [virtual]

Implements SgBookBuilder.

Definition at line 373 of file GoUctBookBuilder.h.

References SgBookNode::m_value.

template<class PLAYER>
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().


Member Data Documentation

template<class PLAYER>
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().

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_internal_nodes [private]

Reimplemented from SgBookBuilder.

Definition at line 152 of file GoUctBookBuilder.h.

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_leaf_nodes [private]

Reimplemented from SgBookBuilder.

Definition at line 154 of file GoUctBookBuilder.h.

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_num_evals [private]

Reimplemented from SgBookBuilder.

Definition at line 144 of file GoUctBookBuilder.h.

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_num_widenings [private]

Reimplemented from SgBookBuilder.

Definition at line 146 of file GoUctBookBuilder.h.

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_numGamesPerEvaluation [private]

Definition at line 140 of file GoUctBookBuilder.h.

Referenced by GoUctBookBuilder< PLAYER >::BeforeEvaluateChildren().

template<class PLAYER>
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().

template<class PLAYER>
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().

template<class PLAYER>
PLAYER* GoUctBookBuilder< PLAYER >::m_origPlayer [private]

Definition at line 131 of file GoUctBookBuilder.h.

Referenced by GoUctBookBuilder< PLAYER >::SetPlayer().

template<class PLAYER>
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().

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_priority_updates [private]

Reimplemented from SgBookBuilder.

Definition at line 150 of file GoUctBookBuilder.h.

template<class PLAYER>
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().

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_terminal_nodes [private]

Reimplemented from SgBookBuilder.

Definition at line 156 of file GoUctBookBuilder.h.

template<class PLAYER>
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().

template<class PLAYER>
std::size_t GoUctBookBuilder< PLAYER >::m_value_updates [private]

Reimplemented from SgBookBuilder.

Definition at line 148 of file GoUctBookBuilder.h.

template<class PLAYER>
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().

template<class PLAYER>
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().


The documentation for this class was generated from the following file:


17 Jun 2010 Doxygen 1.4.7