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

selector selects the child of a node that maximises a given metric. More...

#include <max_function_selector.hpp>

Inheritance diagram for mcts::MaxFunctionSelector< Context, Config >:
mcts::ISelectionStrategy< Context, Config > mcts::MaxValueSelector< Context, Config > mcts::UCTSelector< Context, Config >

Public Member Functions

node_tselect (node_t *node)
 select a child of node More...
 
virtual double evaluate (node_t *node) const =0
 this function has to be implemented in derived classes that specializes the metric to be used. every child is evaluated against this method. More...
 

Additional Inherited Members

- Public Types inherited from mcts::ISelectionStrategy< Context, Config >
typedef ISelectionStrategy< Context, Config > sstrategy_t
 

Detailed Description

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

selector selects the child of a node that maximises a given metric.

Template Parameters
Context@README
Config@README

Definition at line 20 of file max_function_selector.hpp.

Member Function Documentation

◆ evaluate()

template<typename Context , typename Config >
virtual double mcts::MaxFunctionSelector< Context, Config >::evaluate ( node_t node) const
pure virtual

this function has to be implemented in derived classes that specializes the metric to be used. every child is evaluated against this method.

Parameters
nodeto evaluate
Returns
number representing some metric.

Implemented in mcts::UCTSelector< Context, Config >, and mcts::MaxValueSelector< Context, Config >.

Referenced by mcts::MaxFunctionSelector< Context, Config >::select().

◆ select()

template<typename Context , typename Config >
node_t* mcts::MaxFunctionSelector< Context, Config >::select ( node_t node)
inlinevirtual

select a child of node

Parameters
nodeto select child from
Returns
pointer to childnode of node

Implements mcts::ISelectionStrategy< Context, Config >.

Definition at line 24 of file max_function_selector.hpp.

24  {
25  node_t *max_node = NULL;
26  vector<node_t *> children = node->children();
27  vector<double> values(children.size());
28 
29  for (unsigned i = 0; i < children.size(); ++i){
30  values[i] = evaluate(children[i]);
31  }
32 
33  size_t max_index =
34  std::max_element(values.begin(), values.end()) - values.begin();
35  max_node = children[max_index];
36 
37  if (max_node == NULL) {
38  throw std::logic_error("MaxFunctionSelector failed to select a node.");
39  }
40  return max_node;
41  }
virtual double evaluate(node_t *node) const =0
this function has to be implemented in derived classes that specializes the metric to be used....
virtual const vector< node_t * > children() const =0
get the children of the current node

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