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

implements most methods of the inode interface. some methods have to be implemented problem dependend. Inner nodes are all nonterminal nodes. More...

#include <inner_node.hpp>

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

Public Member Functions

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

Public Attributes

IBackpropagationStrategybackprop_strat_
 strategy that is used for propagating values back in the tree.
 

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::InnerNode< Context, Config >

implements most methods of the inode interface. some methods have to be implemented problem dependend. Inner nodes are all nonterminal nodes.

Template Parameters
Context@README
Config@README

Definition at line 19 of file inner_node.hpp.

Member Function Documentation

◆ accept()

template<typename Context , typename Config >
virtual void mcts::InnerNode< 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 44 of file inner_node.hpp.

44 { visitor->visit(this); }

◆ add_child()

template<typename Context , typename Config >
virtual void mcts::InnerNode< 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 48 of file inner_node.hpp.

48 { children_.push_back(child); }

◆ backpropagate()

template<typename Context , typename Config >
virtual void mcts::InnerNode< Context, Config >::backpropagate ( const double &  value)
inlinevirtual

applies a backpropagation strategy to traverse the simulated result back up in the tree.

Parameters
value

Implements mcts::INode< Context, Config >.

Definition at line 76 of file inner_node.hpp.

76  {
78  parent_->backpropagate(value);
79  }
virtual void backpropagate(const double &value)=0
applies a backpropagation strategy to traverse the simulated result back up in the tree.
virtual void on_backpropagate(const double &value)=0
saves an value according to some metric.
IBackpropagationStrategy * backprop_strat_
strategy that is used for propagating values back in the tree.
Definition: inner_node.hpp:33

◆ children()

template<typename Context , typename Config >
virtual const vector<node_t *> mcts::InnerNode< 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 46 of file inner_node.hpp.

46 { return children_; }

◆ config()

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

gets the config object

Returns
pointer to config object

Implements mcts::INode< Context, Config >.

Definition at line 50 of file inner_node.hpp.

50 { return config_; }

◆ context()

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

gets the context associated with the current node

Returns
a context

Implements mcts::INode< Context, Config >.

Definition at line 52 of file inner_node.hpp.

52 { return context_; }

◆ ev()

template<typename Context , typename Config >
virtual double mcts::InnerNode< Context, Config >::ev ( ) const
inlinevirtual

gets the current expected value.

Returns
ev

Implements mcts::INode< Context, Config >.

Definition at line 68 of file inner_node.hpp.

68 { return backprop_strat_->ev(); }
virtual double ev() const =0
gets the current expected value
IBackpropagationStrategy * backprop_strat_
strategy that is used for propagating values back in the tree.
Definition: inner_node.hpp:33

◆ nb_samples()

template<typename Context , typename Config >
virtual int mcts::InnerNode< 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 74 of file inner_node.hpp.

74 { return backprop_strat_->nb_samples(); }
IBackpropagationStrategy * backprop_strat_
strategy that is used for propagating values back in the tree.
Definition: inner_node.hpp:33
virtual int nb_samples() const =0
gets the number of samples that are saved in the strat.

◆ parent()

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

gets the parent of the current node

Returns
pointer to parent

Implements mcts::INode< Context, Config >.

Definition at line 54 of file inner_node.hpp.

54 { return parent_; }

◆ select_child()

template<typename Context , typename Config >
virtual node_t* mcts::InnerNode< Context, Config >::select_child ( )
pure virtual

selects a childnode according to a configurable metric

Returns
pointer to a child node

Implements mcts::INode< Context, Config >.

Referenced by mcts::InnerNode< Context, Config >::select_recusively().

◆ select_recusively()

template<typename Context , typename Config >
virtual node_t* mcts::InnerNode< 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 56 of file inner_node.hpp.

56  {
57  if (children_.size() == 0)
58  expand();
59  node_t *selec = select_child();
60  node_t *selectedChild = selec->select_recusively();
61  return selectedChild;
62  }
virtual void expand()=0
expand the current context and add all possible derived contexts as children.
virtual node_t * select_child()=0
selects a childnode according to a configurable metric
virtual node_t * select_recusively()=0
recursively selects nodes with a given simulation strategy until an terminal node is reached.

◆ simulate()

template<typename Context , typename Config >
virtual double mcts::InnerNode< Context, Config >::simulate ( ) const
inlinevirtual

applies a simulation strategy to a terminal node.

Returns
the expected value of the evaluated context.

Implements mcts::INode< Context, Config >.

Definition at line 64 of file inner_node.hpp.

64  {
65  throw std::runtime_error("not supported.");
66  }

◆ std_dev()

template<typename Context , typename Config >
virtual double mcts::InnerNode< Context, Config >::std_dev ( ) const
inlinevirtual

gets the standard deviation.

Returns
std_dev

Implements mcts::INode< Context, Config >.

Definition at line 70 of file inner_node.hpp.

70 { return backprop_strat_->std_deviation(); }
virtual double std_deviation() const =0
gets the current standard deviation
IBackpropagationStrategy * backprop_strat_
strategy that is used for propagating values back in the tree.
Definition: inner_node.hpp:33

◆ variance()

template<typename Context , typename Config >
virtual double mcts::InnerNode< Context, Config >::variance ( ) const
inlinevirtual

gets the variance.

Returns
variance of node

Implements mcts::INode< Context, Config >.

Definition at line 72 of file inner_node.hpp.

72 { return backprop_strat_->variance(); }
virtual double variance() const =0
gets the current variance
IBackpropagationStrategy * backprop_strat_
strategy that is used for propagating values back in the tree.
Definition: inner_node.hpp:33

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