From c269c0a0319a83f9e719bc85e6c83934aa89e293 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Mon, 28 Jun 2021 11:35:12 +0200
Subject: [PATCH] Corrected bug that made BACK transitions unusable

---
 Config.py     |  2 +-
 Transition.py | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Config.py b/Config.py
index eee07f2..051e6bc 100644
--- a/Config.py
+++ b/Config.py
@@ -87,7 +87,7 @@ class Config :
     print("state :", self.state, file=output)
     print("stack :",[self.getAsFeature(ind, "ID") for ind in self.stack], file=output)
     print("history :",[str(trans) for trans in self.history[-10:]], file=output)
-    print("historyPop :",[(str(c[0]),"dat:"+str(c[1]),"mvt:"+str(c[2]),"reward:"+str(c[3])) for c in self.historyPop[-10:]], file=output)
+    print("historyPop :",[(str(c[0]),"dat:"+str(c[1]),"mvt:"+str(c[2]),"reward:"+str(c[3]),"state:"+str(c[4])) for c in self.historyPop[-10:]], file=output)
     toPrint = []
     for lineIndex in range(self.wordIndex-left, self.wordIndex+right) :
       if lineIndex not in range(len(self.lines)) :
diff --git a/Transition.py b/Transition.py
index 2c6eadf..e2cba77 100644
--- a/Transition.py
+++ b/Transition.py
@@ -46,7 +46,7 @@ class Transition :
       exit(1)
     config.history.append(self)
     if "BACK" not in self.name :
-      config.historyPop.append((self,data,None))
+      config.historyPop.append((self,data,None, None, config.state))
 
   def appliable(self, config) :
     if self.name == "RIGHT" :
@@ -173,7 +173,7 @@ def scoreOracleReduce(config, ml) :
 ################################################################################
 def applyBack(config, strategy, size) :
   for i in range(size) :
-    trans, data, movement, _ = config.historyPop.pop()
+    trans, data, movement, _, state = config.historyPop.pop()
     config.moveWordIndex(-movement)
     if trans.name == "RIGHT" :
       applyBackRight(config, data, trans.size)
@@ -188,6 +188,7 @@ def applyBack(config, strategy, size) :
     else :
       print("ERROR : trying to apply BACK to '%s'"%trans.name, file=sys.stderr)
       exit(1)
+    config.state = state
 ################################################################################
 
 ################################################################################
@@ -290,8 +291,9 @@ def applyTransition(strat, config, transition, reward) :
   moved = config.moveWordIndex(movement)
   movement = movement if moved else 0
   if len(config.historyPop) > 0 and "BACK" not in transition.name :
-    config.historyPop[-1] = (config.historyPop[-1][0], config.historyPop[-1][1], movement, reward)
-  config.state = newState
+    config.historyPop[-1] = (config.historyPop[-1][0], config.historyPop[-1][1], movement, reward, config.historyPop[-1][4])
+  if "BACK" not in transition.name :
+    config.state = newState
   return moved
 ################################################################################
 
-- 
GitLab