Grail (C++)  1.1.1
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 <initializer_list>
5 #include <unordered_map>
6 #include <unordered_set>
7 #include "DecisionNode.h"
8 #include "../ISimulatedGameHeuristic.hh"
9 
10 namespace grail
11 {
12  namespace simulation
13  {
14  class ISimulatedGameAction;
15  struct IVectorizer;
16  class Dataset;
17 
18  template <class T>
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 override 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
grail::simulation::DecisionTree::Deserialize
void Deserialize(IDecisionTreeSerializer< ISimulatedGameAction > &serializer)
Populates the tree based on the given serializer.
Definition: DecisionTree.cpp:35
grail::simulation::DecisionTree::Print
void Print()
Prints the decision tree in a very diagnostic fashion onto standard output (cout).
Definition: DecisionTree.cpp:19
grail::simulation::DecisionTree::SetVectorizer
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:88
grail::simulation::Dataset
Definition: Dataset.hh:19
grail::simulation::DecisionTree::GetAction
virtual std::unique_ptr< ISimulatedGameAction > GetAction() const override
Inherited via SimulatedGameHeuristic.
Definition: DecisionTree.cpp:53
grail::simulation::DecisionTree::GetVectorizer
IVectorizer & GetVectorizer() const
Returns the reference to the currently used vectorizer by the DecisionTree. Do not use this method,...
Definition: DecisionTree.cpp:83
grail::simulation::DecisionTree::SetColumnName
void SetColumnName(int columnIndex, const std::string &name)
This will make the Print() function output the name instead of Column[columnIndex]....
Definition: DecisionTree.cpp:69
grail::simulation::DecisionTree
The main class encapsulating the decision tree algorithm.
Definition: DecisionTree.hh:24
grail::simulation::IDecisionTreeSerializer
A base class for an object that is passed to Serialize() and Deserialize() methods of DecisionTree....
Definition: DecisionTree.hh:19
grail::simulation::SimulatedGameHeuristic
Interface that encapsulates an algorithm responsible for action-selection inside SimulatedGame (MCTS)...
Definition: ISimulatedGameHeuristic.hh:18
grail::simulation::DecisionTree::DecisionTree
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
grail::simulation::IVectorizer
Classes implementing this interface provide training data in the offline learning process.
Definition: IVectorizer.hh:15
grail::simulation::DecisionTree::Construct
void Construct(Dataset &dataset, int maxDepth=decisionTreeMaxDepth)
Runs the decision tree construction algorithm (C45). @dataset contains the training data....
Definition: DecisionTree.cpp:41
grail::simulation::DecisionTree::Serialize
void Serialize(IDecisionTreeSerializer< ISimulatedGameAction > &serializer) const
Serializes the content of the tree into the passed serializer object.
Definition: DecisionTree.cpp:27
grail::simulation::DecisionTree::IsHeuristicSituation
virtual bool IsHeuristicSituation(const ISimulatedGameUnit &unit) const override final
Inherited via SimulatedGameHeuristic.
Definition: DecisionTree.cpp:64
grail::simulation::DecisionTree::SetColumnNames
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:74
grail::simulation::ISimulatedGameUnit
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:26