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

selects a node that minimises a given metric More...

#include <min_function_selector.hpp>

Inheritance diagram for mcts::MinFunctionSelector< Context, Config >:
mcts::ISelectionStrategy< Context, Config > mcts::MinSampleSelector< 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::MinFunctionSelector< Context, Config >

selects a node that minimises a given metric

Template Parameters
Context@README
Config@README

Definition at line 18 of file min_function_selector.hpp.

Member Function Documentation

◆ evaluate()

template<typename Context , typename Config >
virtual double mcts::MinFunctionSelector< 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::MinSampleSelector< Context, Config >.

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

◆ select()

template<typename Context , typename Config >
node_t* mcts::MinFunctionSelector< 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 22 of file min_function_selector.hpp.

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

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