(C++)  1.0.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
DecisionTree.hh
1 #ifndef GRAIL_DECISION_TREE_H
2 #define GRAIL_DECISION_TREE_H
3 
4 #include "../ISimulatedGameHeuristic.hh"
5 #include "DecisionNode.h"
6 #include <unordered_set>
7 #include <unordered_map>
8 #include <initializer_list>
9 
10 namespace grail
11 {
12  namespace simulation
13  {
14  class ISimulatedGameAction;
15  struct IVectorizer;
16  class Dataset;
17 
18  template <class T>
19  struct IDecisionTreeSerializer;
20 
25  {
26  public:
28  DecisionTree(std::unique_ptr<IVectorizer> vectorizer);
29 
31  void Print();
32 
35 
38 
40  void Construct(Dataset& dataset, int maxDepth = decisionTreeMaxDepth);
41 
43  virtual std::unique_ptr<ISimulatedGameAction> GetAction() const override;
44 
46  virtual bool IsHeuristicSituation(const ISimulatedGameUnit& unit) const final;
47 
49  void SetColumnName(int columnIndex, const std::string& name);
50 
52  void SetColumnNames(const std::initializer_list<std::string>& consecutiveNames);
53 
54  DecisionTree(const DecisionTree& other) = delete;
55 
57  IVectorizer& GetVectorizer() const;
58 
60  void SetVectorizer(std::unique_ptr<IVectorizer> vectorizer);
61  private:
62  void ConstructDefaultColumnNames();
63 
64  std::unique_ptr<DecisionNode<ISimulatedGameAction>> root;
65  std::unique_ptr<IVectorizer> vectorizer;
66  std::unordered_set<int> usedConsiderationIndices;
67  std::unordered_map<int, std::string> columnNames;
68  };
69  }
70 }
71 
72 #endif //GRAIL_DECISION_TREE_H
Definition: Dataset.hh:20
The main class encapsulating the decision tree algorithm.
Definition: DecisionTree.hh:25
void SetVectorizer(std::unique_ptr< IVectorizer > vectorizer)
Moves the vectorizer passed as parameter to the DecisionTree. The DecisionTree uses it to provide act...
Definition: DecisionTree.cpp:79
void Deserialize(IDecisionTreeSerializer< ISimulatedGameAction > &serializer)
Populates the tree based on the given serializer.
Definition: DecisionTree.cpp:31
IVectorizer & GetVectorizer() const
Returns the reference to the currently used vectorizer by the DecisionTree. Do not use this method,...
Definition: DecisionTree.cpp:74
DecisionTree(std::unique_ptr< IVectorizer > vectorizer)
Constructs a new decision tree object. You have to specify a proper vectorizer object that will be us...
Definition: DecisionTree.cpp:13
void SetColumnName(int columnIndex, const std::string &name)
This will make the Print() function output the name instead of Column[columnIndex]....
Definition: DecisionTree.cpp:62
virtual bool IsHeuristicSituation(const ISimulatedGameUnit &unit) const final
Inherited via SimulatedGameHeuristic.
Definition: DecisionTree.cpp:57
void Construct(Dataset &dataset, int maxDepth=decisionTreeMaxDepth)
Runs the decision tree construction algorithm (C45). @dataset contains the training data....
Definition: DecisionTree.cpp:36
void Serialize(IDecisionTreeSerializer< ISimulatedGameAction > &serializer) const
Serializes the content of the tree into the passed serializer object.
Definition: DecisionTree.cpp:26
void SetColumnNames(const std::initializer_list< std::string > &consecutiveNames)
This will make the Print() function output the names instead of Column[columnIndex]....
Definition: DecisionTree.cpp:67
virtual std::unique_ptr< ISimulatedGameAction > GetAction() const override
Inherited via SimulatedGameHeuristic.
Definition: DecisionTree.cpp:48
void Print()
Prints the decision tree in a very diagnostic fashion onto standard output (cout).
Definition: DecisionTree.cpp:20
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:27
Interface that encapsulates an algorithm responsible for action-selection inside SimulatedGame (MCTS)...
Definition: ISimulatedGameHeuristic.hh:19
A base class for an object that is passed to Serialize() and Deserialize() methods of DecisionTree....
Definition: IDecisionTreeSerializer.hh:21
Classes implementing this interface provide training data in the offline learning process.
Definition: IVectorizer.hh:17