From 2a7c3dc6609a242f92dfdd6769b6d143e34d1342 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Wed, 15 May 2019 13:12:20 +0200
Subject: [PATCH] Fixed action hash

---
 maca_common/include/LimitedStack.hpp  | 8 +++++---
 trainer/src/Trainer.cpp               | 1 -
 transition_machine/include/Config.hpp | 2 +-
 transition_machine/src/Config.cpp     | 2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/maca_common/include/LimitedStack.hpp b/maca_common/include/LimitedStack.hpp
index 06d0860..4640038 100644
--- a/maca_common/include/LimitedStack.hpp
+++ b/maca_common/include/LimitedStack.hpp
@@ -13,11 +13,12 @@
 namespace std
 {
   template<>
-  struct hash< std::pair<std::string, Action> >
+  struct hash< pair<string, Action> >
   {
-    size_t operator()(const std::pair<std::string, Action> &p) const
+    size_t operator()(const pair<std::string, Action> & p) const
     {
-      return 0;
+      static hash<string> h;
+      return h(p.first + p.second.name);
     }
   };
 }
@@ -43,6 +44,7 @@ class LimitedStack
   {
     nbElements = 0;
     lastElementIndex = -1; 
+    present.clear();
   }
 
   void push(T elem)
diff --git a/trainer/src/Trainer.cpp b/trainer/src/Trainer.cpp
index b035da2..fd46e97 100644
--- a/trainer/src/Trainer.cpp
+++ b/trainer/src/Trainer.cpp
@@ -381,7 +381,6 @@ void Trainer::doStepTrain()
     }
     std::string normalClassifierName(buffer);
 
-    auto & errorHistory = trainConfig.getActionsHistory(tm.getCurrentClassifier()->name);
     auto & normalHistory = trainConfig.getActionsHistory(normalClassifierName);
 
     // If a BACK just happened
diff --git a/transition_machine/include/Config.hpp b/transition_machine/include/Config.hpp
index de3dd7a..9aba457 100644
--- a/transition_machine/include/Config.hpp
+++ b/transition_machine/include/Config.hpp
@@ -134,7 +134,7 @@ class Config
 
   private :
 
-  const unsigned int HISTORY_SIZE = 100000000;
+  const unsigned int HISTORY_SIZE = 100000;
   /// @brief The name of the current state of the TransitionMachine.
   std::string currentStateName;
   /// @brief For each state of the TransitionMachine, an history of the Action that have been applied to this Config.
diff --git a/transition_machine/src/Config.cpp b/transition_machine/src/Config.cpp
index f4612e0..64cad5a 100644
--- a/transition_machine/src/Config.cpp
+++ b/transition_machine/src/Config.cpp
@@ -437,7 +437,7 @@ void Config::addToEntropyHistory(float entropy)
 
 std::size_t Config::computeHash()
 {
-  static int window = 3;
+  static int window = 10;
 
   int start = std::max(0, head-window);
   int end = std::min(tapes[0].refSize()-1, head+window);
-- 
GitLab