Fleet  0.0.9
Inference in the LOT
MinimalMCTSNode.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MCTSBase.h"
4 
12 template<typename this_t, typename HYP>
13 class MinimalMCTSNode : public MCTSBase<this_t,HYP> {
15  using Super::Super; // get constructors
16 
17  using data_t = typename HYP::data_t;
18 
19  virtual generator<HYP&> search_one(HYP& current) override {
20  if(DEBUG_MCTS) DEBUG("MinimalMCTSNode SEARCH ONE ", this, "\t["+current.string()+"] ", (unsigned long) this->nvisits);
21 
22  auto c = this->descend_to_childless(current); //sets current and returns the node.
23 
24  while(not current.is_evaluable()) {
25  c->add_children(current);
26 
27  // find the highest prior child
28  auto neigh = current.neighbors();
29  std::vector<double> children_lps(neigh,-infinity);
30  for(int k=0;k<neigh;k++) {
31  children_lps[k] = current.neighbor_prior(k);
32  }
33 
34  auto idx = arg_max_int(neigh, [&](const int i) -> double {return children_lps[i];} ).first;
35  current.expand_to_neighbor(idx);
36  c = &c->children[idx];
37  }
38 
39  c->process_evaluable(current);
40  co_yield current;
41  }
42 };
#define DEBUG_MCTS
Definition: MCTSBase.h:3
Definition: MinimalMCTSNode.h:13
typename HYP::data_t data_t
Definition: MCTSBase.h:46
constexpr double infinity
Definition: Numerics.h:20
Definition: generator.hpp:21
virtual this_t * descend_to_childless(HYP &current)
This goes down the tree to a node with no children (OR evaluable)
Definition: MCTSBase.h:300
Definition: MCTSBase.h:41
void DEBUG(FIRST f, ARGS... args)
Print to std:ccout with debugging info.
Definition: IO.h:73
std::pair< size_t, double > arg_max_int(unsigned int max, const std::function< double(const int)> &f)
Definition: Random.h:395
std::atomic< unsigned int > nvisits
Definition: MCTSBase.h:59