libmcts
A Monte Carlo Tree Search Library
Public Member Functions | Protected Attributes | List of all members
mcts::LeafNode< Context, Config > Class Template Reference

implements methods of the inode interface that are used for terminal contexts. all leaf nodes are terminal. More...

#include <leaf_node.hpp>

Inheritance diagram for mcts::LeafNode< Context, Config >:
mcts::INode< Context, Config >

Public Member Functions

 LeafNode (const Context &context, Config *config, node_t *parent)
 
virtual void expand ()
 expand the current context and add all possible derived contexts as children.
 
virtual void accept (visitor_t *visitor)
 accepts a visitor according to the visitor pattern. More...
 
virtual node_tparent () const
 gets the parent of the current node More...
 
virtual int nb_samples () const
 number of times a selection strategy selected the current node. More...
 
virtual Config * config () const
 gets the config object More...
 
virtual const Context context () const
 gets the context associated with the current node More...
 
virtual const vector< node_t * > children () const
 get the children of the current node More...
 
virtual void add_child (node_t *child)
 insert a new node as a child of the current one. More...
 
virtual node_tselect_recusively ()
 recursively selects nodes with a given simulation strategy until an terminal node is reached. More...
 
virtual node_tselect_child ()
 selects a childnode according to a configurable metric More...
 
- Public Member Functions inherited from mcts::INode< Context, Config >
virtual double ev () const =0
 gets the current expected value. More...
 
virtual double std_dev () const =0
 gets the standard deviation. More...
 
virtual double variance () const =0
 gets the variance. More...
 
virtual double simulate () const =0
 applies a simulation strategy to a terminal node. More...
 
virtual void backpropagate (const double &value)=0
 applies a backpropagation strategy to traverse the simulated result back up in the tree. More...
 
virtual unsigned count_recursive () const
 recursively counts number of childen beneth this nodes. counts in the current node. More...
 

Protected Attributes

Context context_
 
Config * config_
 
node_tparent_
 
int nb_samples_
 

Additional Inherited Members

- Public Types inherited from mcts::INode< Context, Config >
typedef INode< Context, Config > node_t
 

Detailed Description

template<typename Context, typename Config>
class mcts::LeafNode< Context, Config >

implements methods of the inode interface that are used for terminal contexts. all leaf nodes are terminal.

Template Parameters
Context@README
Config@README

Definition at line 16 of file leaf_node.hpp.

Member Function Documentation

◆ accept()

template<typename Context , typename Config >
virtual void mcts::LeafNode< Context, Config >::accept ( visitor_t visitor)
inlinevirtual

accepts a visitor according to the visitor pattern.

Parameters
visitorobject

Implements mcts::INode< Context, Config >.

Definition at line 28 of file leaf_node.hpp.

28 { visitor->visit(this); }

◆ add_child()

template<typename Context , typename Config >
virtual void mcts::LeafNode< Context, Config >::add_child ( node_t child)
inlinevirtual

insert a new node as a child of the current one.

Parameters
childpointer to a node

Implements mcts::INode< Context, Config >.

Definition at line 40 of file leaf_node.hpp.

40  {
41  throw std::runtime_error("not supported");
42  }

◆ children()

template<typename Context , typename Config >
virtual const vector<node_t *> mcts::LeafNode< Context, Config >::children ( ) const
inlinevirtual

get the children of the current node

Returns
list of pointers of nodes

Implements mcts::INode< Context, Config >.

Definition at line 38 of file leaf_node.hpp.

38 { return vector<node_t *>(); }

◆ config()

template<typename Context , typename Config >
virtual Config* mcts::LeafNode< Context, Config >::config ( ) const
inlinevirtual

gets the config object

Returns
pointer to config object

Implements mcts::INode< Context, Config >.

Definition at line 34 of file leaf_node.hpp.

34 { return config_; }

◆ context()

template<typename Context , typename Config >
virtual const Context mcts::LeafNode< Context, Config >::context ( ) const
inlinevirtual

gets the context associated with the current node

Returns
a context

Implements mcts::INode< Context, Config >.

Definition at line 36 of file leaf_node.hpp.

36 { return context_; }

◆ nb_samples()

template<typename Context , typename Config >
virtual int mcts::LeafNode< Context, Config >::nb_samples ( ) const
inlinevirtual

number of times a selection strategy selected the current node.

Returns
a selection count

Implements mcts::INode< Context, Config >.

Definition at line 32 of file leaf_node.hpp.

32 { return nb_samples_; }

◆ parent()

template<typename Context , typename Config >
virtual node_t* mcts::LeafNode< Context, Config >::parent ( ) const
inlinevirtual

gets the parent of the current node

Returns
pointer to parent

Implements mcts::INode< Context, Config >.

Definition at line 30 of file leaf_node.hpp.

30 { return parent_; }

◆ select_child()

template<typename Context , typename Config >
virtual node_t* mcts::LeafNode< Context, Config >::select_child ( )
inlinevirtual

selects a childnode according to a configurable metric

Returns
pointer to a child node

Implements mcts::INode< Context, Config >.

Definition at line 46 of file leaf_node.hpp.

46 { return this; }

◆ select_recusively()

template<typename Context , typename Config >
virtual node_t* mcts::LeafNode< Context, Config >::select_recusively ( )
inlinevirtual

recursively selects nodes with a given simulation strategy until an terminal node is reached.

Returns
pointer to a terminal node

Implements mcts::INode< Context, Config >.

Definition at line 44 of file leaf_node.hpp.

44 { return this; }

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