libmcts
A Monte Carlo Tree Search Library
uct_selector.hpp
1 #ifndef UCT_SELECTOR_H
2 #define UCT_SELECTOR_H
3 
4 #include <cmath>
5 #include "inode.hpp"
6 #include "max_function_selector.hpp"
7 
8 namespace mcts {
9 
10 // ----------------------------------------------------------------------
16 // ----------------------------------------------------------------------
17 template <typename Context, typename Config>
18 class UCTSelector : public MaxFunctionSelector<Context, Config> {
19 private:
20  typedef typename INode<Context, Config>::node_t node_t;
21 
23  double C;
24 
25 public:
26  // ----------------------------------------------------------------------
34  // ----------------------------------------------------------------------
35  UCTSelector(double _C) : C(_C) {}
36 
37  double evaluate(node_t *node) const {
38  int nb_samples = node->nb_samples();
39  if (nb_samples == 0)
40  return 0;
41 
42  int nb_parent_samples = node->parent()->nb_samples();
43  return node->ev() + C * sqrt(log((double)nb_parent_samples) / nb_samples);
44  }
45 };
46 }
47 
48 #endif
UCTSelector(double _C)
constructs a new selector
selector that selects the childnode, that maximises the ratio between samples and ev of the parent no...
selector selects the child of a node that maximises a given metric.
basic interface for a node in the tree. Every node has to implement this functions.
Definition: inode.hpp:18
virtual node_t * parent() const =0
gets the parent of the current node
virtual int nb_samples() const =0
number of times a selection strategy selected the current node.
double evaluate(node_t *node) const
this function has to be implemented in derived classes that specializes the metric to be used....
virtual double ev() const =0
gets the current expected value.