Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgUctNode Class Reference
[Monte Carlo tree search]

#include <SgUctTree.h>

List of all members.


Detailed Description

Node used in SgUctTree.

All data members are declared as volatile to avoid that the compiler re-orders writes, which can break assumptions made by SgUctSearch in lock-free mode (see Lock-free mode in SgUctSearch). For example, the search relies on the fact that m_firstChild is valid, if m_nuChildren is greater zero or that the mean value of the move and RAVE value statistics is valid if the corresponding count is greater zero.

Definition at line 113 of file SgUctTree.h.

Public Member Functions

 SgUctNode (const SgMoveInfo &info)
 Initializes node with given move, value and count.
void AddGameResult (float eval)
 Add game result.
void AddGameResults (float eval, std::size_t count)
 Adds a game result count times.
void MergeResults (const SgUctNode &node)
 Add other nodes results to this node's.
void RemoveGameResult (float eval)
 Removes a game result.
void RemoveGameResults (float eval, std::size_t count)
 Removes a game result count times.
std::size_t PosCount () const
 Number of times this node was visited.
std::size_t MoveCount () const
 Number of times the move leading to this position was chosen.
const SgUctNodeFirstChild () const
 Get first child.
bool HasChildren () const
 Does the node have at least one child?
float Mean () const
 Average game result.
bool HasMean () const
 True, if mean value is defined (move count not zero).
int NuChildren () const
 Get number of children.
void SetFirstChild (const SgUctNode *child)
 See FirstChild().
void SetNuChildren (int nuChildren)
 See NuChildren().
void IncPosCount ()
 Increment the position count.
void DecPosCount ()
 Decrement the position count.
void SetPosCount (std::size_t value)
void InitializeValue (float value, std::size_t count)
 Initialize value with prior knowledge.
void CopyDataFrom (const SgUctNode &node)
 Copy data from other node.
SgMove Move () const
 Get move.
float RaveCount () const
 Get RAVE count.
float RaveValue () const
 Get RAVE mean value.
bool HasRaveValue () const
void AddRaveValue (float value, float weight)
 Add a game result value to the RAVE value.
void RemoveRaveValue (float value)
 Removes a rave result.
void RemoveRaveValue (float value, float weight)
void InitializeRaveValue (float value, float count)
 Initialize RAVE value with prior knowledge.
std::size_t KnowledgeCount () const
 Returns the last time knowledge was computed.
void SetKnowledgeCount (std::size_t count)
 Set that knowledge has been computed at count.
bool IsProven () const
 Returns true if node is a proven node.
bool IsProvenWin () const
bool IsProvenLoss () const
SgProvenNodeType ProvenNodeType () const
void SetProvenNodeType (SgProvenNodeType type)

Private Attributes

SgStatisticsBase< volatile
float, volatile std::size_t > 
m_statistics
const SgUctNode *volatile m_firstChild
volatile int m_nuChildren
volatile SgMove m_move
SgStatisticsBase< volatile
float, volatile float > 
m_raveValue
 RAVE statistics.
volatile std::size_t m_posCount
volatile std::size_t m_knowledgeCount
volatile SgProvenNodeType m_provenType


Constructor & Destructor Documentation

SgUctNode::SgUctNode ( const SgMoveInfo info  ) 

Initializes node with given move, value and count.

Definition at line 271 of file SgUctTree.h.


Member Function Documentation

void SgUctNode::AddGameResult ( float  eval  ) 

Add game result.

Parameters:
eval The game result (e.g. score or 0/1 for win loss)

Definition at line 283 of file SgUctTree.h.

References m_statistics.

void SgUctNode::AddGameResults ( float  eval,
std::size_t  count 
)

Adds a game result count times.

Definition at line 288 of file SgUctTree.h.

References m_statistics.

void SgUctNode::AddRaveValue ( float  value,
float  weight 
)

Add a game result value to the RAVE value.

See also:
SgUctSearch::Rave().

Definition at line 311 of file SgUctTree.h.

References m_raveValue.

void SgUctNode::CopyDataFrom ( const SgUctNode node  ) 

Copy data from other node.

Copies all data, apart from the children information (first child and number of children).

Definition at line 326 of file SgUctTree.h.

References m_knowledgeCount, m_move, m_posCount, m_provenType, m_raveValue, and m_statistics.

Referenced by SgUctTree::ApplyFilter(), and SgUctTree::CopySubtree().

void SgUctNode::DecPosCount (  ) 

Decrement the position count.

See PosCount()

Definition at line 362 of file SgUctTree.h.

References m_posCount.

const SgUctNode * SgUctNode::FirstChild (  )  const

Get first child.

Note:
This information is an implementation detail of how SgUctTree manages nodes. Use SgUctChildIterator to access children nodes.

Definition at line 336 of file SgUctTree.h.

References HasChildren(), m_firstChild, and SG_ASSERT.

Referenced by SgUctChildIterator::SgUctChildIterator().

bool SgUctNode::HasChildren (  )  const

Does the node have at least one child?

Definition at line 342 of file SgUctTree.h.

References m_nuChildren.

Referenced by SgUctTree::ApplyFilter(), SgUctTree::CreateChildren(), SgUctSearch::FindBestChild(), SgUctSearch::FindBestSequence(), SgUctTreeUtil::FindChildWithMove(), FirstChild(), SgUctTreeIterator::operator++(), SgUctSearch::PlayInTree(), SgUctSearch::PrintSearchProgress(), SgUctSearch::SelectChild(), and SgUctChildIterator::SgUctChildIterator().

bool SgUctNode::HasMean (  )  const

True, if mean value is defined (move count not zero).

Definition at line 347 of file SgUctTree.h.

References m_statistics.

Referenced by SgUctSearch::CheckEarlyAbort(), SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().

bool SgUctNode::HasRaveValue (  )  const

Definition at line 352 of file SgUctTree.h.

References m_raveValue.

Referenced by SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().

void SgUctNode::IncPosCount (  ) 

Increment the position count.

See PosCount()

Definition at line 357 of file SgUctTree.h.

References m_posCount.

void SgUctNode::InitializeRaveValue ( float  value,
float  count 
)

Initialize RAVE value with prior knowledge.

Definition at line 372 of file SgUctTree.h.

References m_raveValue.

void SgUctNode::InitializeValue ( float  value,
std::size_t  count 
)

Initialize value with prior knowledge.

Definition at line 367 of file SgUctTree.h.

References m_statistics.

bool SgUctNode::IsProven (  )  const

Returns true if node is a proven node.

Definition at line 439 of file SgUctTree.h.

References m_provenType, and SG_NOT_PROVEN.

Referenced by SgUctSearch::PlayInTree().

bool SgUctNode::IsProvenLoss (  )  const

Definition at line 449 of file SgUctTree.h.

References m_provenType, and SG_PROVEN_LOSS.

bool SgUctNode::IsProvenWin (  )  const

Definition at line 444 of file SgUctTree.h.

References m_provenType, and SG_PROVEN_WIN.

std::size_t SgUctNode::KnowledgeCount (  )  const

Returns the last time knowledge was computed.

Definition at line 429 of file SgUctTree.h.

References m_knowledgeCount.

Referenced by SgUctSearch::NeedToComputeKnowledge(), and SgUctSearch::PlayInTree().

float SgUctNode::Mean (  )  const

Average game result.

Requires: HasMean()

Definition at line 377 of file SgUctTree.h.

References m_statistics.

Referenced by SgUctSearch::CheckEarlyAbort(), SgUctSearch::GetValueEstimate(), SgUctSearch::GetValueEstimateRave(), SgUctSearch::PrintSearchProgress(), and SgUctSearch::Search().

void SgUctNode::MergeResults ( const SgUctNode node  ) 

Add other nodes results to this node's.

Definition at line 293 of file SgUctTree.h.

References m_raveValue, and m_statistics.

SgMove SgUctNode::Move (  )  const

Get move.

Requires: Node has a move (is not root node)

Definition at line 382 of file SgUctTree.h.

References m_move, SG_ASSERT, and SG_NULLMOVE.

Referenced by SgUctSearch::CheckCountAbort(), SgUctSearch::FindBestSequence(), SgUctSearch::PlayInTree(), and SgUctSearch::PrintSearchProgress().

std::size_t SgUctNode::MoveCount (  )  const

Number of times the move leading to this position was chosen.

This count will be different from PosCount(), if prior knowledge initialization is used.

Definition at line 388 of file SgUctTree.h.

References m_statistics.

Referenced by SgUctSearch::CheckCountAbort(), SgUctSearch::CheckEarlyAbort(), SgUctSearch::GamesPlayed(), SgUctSearch::GetBound(), SgUctSearch::GetValueEstimate(), SgUctSearch::GetValueEstimateRave(), SgUctSearch::NeedToComputeKnowledge(), SgUctSearch::PlayInTree(), SgUctSearch::PrintSearchProgress(), SgUctSearch::Search(), SgUctSearch::StartSearch(), and SgUctSearch::WriteStatistics().

int SgUctNode::NuChildren (  )  const

Get number of children.

Note:
This information is an implementation detail of how SgUctTree manages nodes. Use SgUctChildIterator to access children nodes.

Definition at line 393 of file SgUctTree.h.

References m_nuChildren.

Referenced by SgUctTree::ApplyFilter(), SgUctTree::MergeChildren(), SgUctChildIterator::SgUctChildIterator(), and SgUctSearch::StartSearch().

std::size_t SgUctNode::PosCount (  )  const

Number of times this node was visited.

This corresponds to the sum of MoveCount() of all children. It can be different from MoveCount() of this position, if prior knowledge initialization of the children is used.

Definition at line 398 of file SgUctTree.h.

References m_posCount.

Referenced by SgUctTree::AddGameResults(), SgUctSearch::GetBound(), SgUctTree::RemoveGameResults(), and SgUctSearch::SelectChild().

SgProvenNodeType SgUctNode::ProvenNodeType (  )  const

Definition at line 454 of file SgUctTree.h.

References m_provenType.

float SgUctNode::RaveCount (  )  const

Get RAVE count.

See also:
SgUctSearch::Rave().

Definition at line 403 of file SgUctTree.h.

References m_raveValue.

Referenced by SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().

float SgUctNode::RaveValue (  )  const

Get RAVE mean value.

Requires: HasRaveValue()

See also:
SgUctSearch::Rave().

Definition at line 408 of file SgUctTree.h.

References m_raveValue.

Referenced by SgUctSearch::GetValueEstimate(), and SgUctSearch::GetValueEstimateRave().

void SgUctNode::RemoveGameResult ( float  eval  ) 

Removes a game result.

Parameters:
eval The game result (e.g. score or 0/1 for win loss)

Definition at line 301 of file SgUctTree.h.

References m_statistics.

void SgUctNode::RemoveGameResults ( float  eval,
std::size_t  count 
)

Removes a game result count times.

Definition at line 306 of file SgUctTree.h.

References m_statistics.

void SgUctNode::RemoveRaveValue ( float  value,
float  weight 
)

Definition at line 321 of file SgUctTree.h.

References m_raveValue.

void SgUctNode::RemoveRaveValue ( float  value  ) 

Removes a rave result.

Definition at line 316 of file SgUctTree.h.

References m_raveValue.

void SgUctNode::SetFirstChild ( const SgUctNode child  ) 

See FirstChild().

Definition at line 413 of file SgUctTree.h.

References m_firstChild.

Referenced by SgUctTree::ApplyFilter(), SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), and SgUctTree::MergeChildren().

void SgUctNode::SetKnowledgeCount ( std::size_t  count  ) 

Set that knowledge has been computed at count.

Definition at line 434 of file SgUctTree.h.

References m_knowledgeCount.

void SgUctNode::SetNuChildren ( int  nuChildren  ) 

See NuChildren().

Definition at line 418 of file SgUctTree.h.

References m_nuChildren, and SG_ASSERT.

Referenced by SgUctTree::ApplyFilter(), SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), and SgUctTree::MergeChildren().

void SgUctNode::SetPosCount ( std::size_t  value  ) 

Definition at line 424 of file SgUctTree.h.

References m_posCount.

Referenced by SgUctTree::CopySubtree(), SgUctTree::CreateChildren(), and SgUctTree::MergeChildren().

void SgUctNode::SetProvenNodeType ( SgProvenNodeType  type  ) 

Definition at line 459 of file SgUctTree.h.

References m_provenType.

Referenced by SgUctSearch::PlayInTree().


Member Data Documentation

const SgUctNode* volatile SgUctNode::m_firstChild [private]

Definition at line 252 of file SgUctTree.h.

Referenced by FirstChild(), and SetFirstChild().

volatile std::size_t SgUctNode::m_knowledgeCount [private]

Definition at line 266 of file SgUctTree.h.

Referenced by CopyDataFrom(), KnowledgeCount(), and SetKnowledgeCount().

volatile SgMove SgUctNode::m_move [private]

Definition at line 256 of file SgUctTree.h.

Referenced by CopyDataFrom(), and Move().

volatile int SgUctNode::m_nuChildren [private]

Definition at line 254 of file SgUctTree.h.

Referenced by HasChildren(), NuChildren(), and SetNuChildren().

volatile std::size_t SgUctNode::m_posCount [private]

Definition at line 264 of file SgUctTree.h.

Referenced by CopyDataFrom(), DecPosCount(), IncPosCount(), PosCount(), and SetPosCount().

volatile SgProvenNodeType SgUctNode::m_provenType [private]

Definition at line 268 of file SgUctTree.h.

Referenced by CopyDataFrom(), IsProven(), IsProvenLoss(), IsProvenWin(), ProvenNodeType(), and SetProvenNodeType().

SgStatisticsBase<volatile float,volatile float> SgUctNode::m_raveValue [private]

RAVE statistics.

Uses double for count to allow adding fractional values if RAVE updates are weighted.

Definition at line 262 of file SgUctTree.h.

Referenced by AddRaveValue(), CopyDataFrom(), HasRaveValue(), InitializeRaveValue(), MergeResults(), RaveCount(), RaveValue(), and RemoveRaveValue().

SgStatisticsBase<volatile float,volatile std::size_t> SgUctNode::m_statistics [private]

Definition at line 250 of file SgUctTree.h.

Referenced by AddGameResult(), AddGameResults(), CopyDataFrom(), HasMean(), InitializeValue(), Mean(), MergeResults(), MoveCount(), RemoveGameResult(), and RemoveGameResults().


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


17 Jun 2010 Doxygen 1.4.7