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

mainclass to interact with the library. it holds the root of the searchtree. More...

#include <mcts.hpp>

Public Member Functions

 MCTS (const Context &context, Config *config)
 creates a new empty mcts object. only a root node exists. More...
 
void iterate ()
 executes one interation step. Each iteration consists of the following actions: More...
 
ResultType result ()
 gets the current result node. The node is selected according to a metric defined in a selection strategy. The result is returned to a template container that accepts a node_t* object as constructor. More...
 
const node_troot () const
 gets the root of the node. More...
 
unsigned nb_nodes ()
 gets the number of nodes the tree is currently holding. More...
 
unsigned nb_iterations ()
 gets the number of performed iterations. the counter is increased each time the function iterate() is called. More...
 

Detailed Description

template<typename Context, typename Config, typename WrapNode, typename ResultType>
class mcts::MCTS< Context, Config, WrapNode, ResultType >

mainclass to interact with the library. it holds the root of the searchtree.

Template Parameters
Context@README
Config@README
WrapNodetype derived from inner node class
ResultTypetype of resulttype

Definition at line 19 of file mcts.hpp.

Constructor & Destructor Documentation

◆ MCTS()

template<typename Context , typename Config , typename WrapNode , typename ResultType >
mcts::MCTS< Context, Config, WrapNode, ResultType >::MCTS ( const Context &  context,
Config *  config 
)
inline

creates a new empty mcts object. only a root node exists.

Parameters
contextbase context from which all possible states stem
configa pointer to a config object that stores user defined data and some required functions

Definition at line 31 of file mcts.hpp.

32  : tree(new root_node_t(context, config)), iteration_cnt(0) {}

Member Function Documentation

◆ iterate()

template<typename Context , typename Config , typename WrapNode , typename ResultType >
void mcts::MCTS< Context, Config, WrapNode, ResultType >::iterate ( )
inline

executes one interation step. Each iteration consists of the following actions:

  • select a terminal node
  • simulate that node to get it's ev
  • backpropagate that value back in the tree
  • increase the iteration counter The iteration step expands undexpanded nodes if necessary.

Definition at line 45 of file mcts.hpp.

45  {
46  node_t *selected_leaf = tree->select_recusively();
47  double value = selected_leaf->simulate();
48  selected_leaf->backpropagate(value);
49  ++iteration_cnt;
50  }
virtual double simulate() const =0
applies a simulation strategy to a terminal node.
virtual node_t * select_recusively()=0
recursively selects nodes with a given simulation strategy until an terminal node is reached.

◆ nb_iterations()

template<typename Context , typename Config , typename WrapNode , typename ResultType >
unsigned mcts::MCTS< Context, Config, WrapNode, ResultType >::nb_iterations ( )
inline

gets the number of performed iterations. the counter is increased each time the function iterate() is called.

Returns
number of iterations

Definition at line 84 of file mcts.hpp.

84 { return iteration_cnt; }

◆ nb_nodes()

template<typename Context , typename Config , typename WrapNode , typename ResultType >
unsigned mcts::MCTS< Context, Config, WrapNode, ResultType >::nb_nodes ( )
inline

gets the number of nodes the tree is currently holding.

Returns
number of nodes

Definition at line 76 of file mcts.hpp.

76 { return tree->count_recursive(); }
virtual unsigned count_recursive() const
recursively counts number of childen beneth this nodes. counts in the current node.
Definition: inode.hpp:139

◆ result()

template<typename Context , typename Config , typename WrapNode , typename ResultType >
ResultType mcts::MCTS< Context, Config, WrapNode, ResultType >::result ( )
inline

gets the current result node. The node is selected according to a metric defined in a selection strategy. The result is returned to a template container that accepts a node_t* object as constructor.

Returns
a resultobject

Definition at line 60 of file mcts.hpp.

60  {
61  return ResultType(tree->config()->move_selector()->select(tree));
62  }
virtual Config * config() const =0
gets the config object

◆ root()

template<typename Context , typename Config , typename WrapNode , typename ResultType >
const node_t* mcts::MCTS< Context, Config, WrapNode, ResultType >::root ( ) const
inline

gets the root of the node.

Returns
pointer to root node.

Definition at line 69 of file mcts.hpp.

69 { return tree; }

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