From 8353c4cccf11dbd395e2762ad2676e6f70c5ca12 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Wed, 26 Jun 2019 16:08:53 +0200 Subject: [PATCH] Improved BACK action appliable detection --- transition_machine/include/Config.hpp | 2 +- transition_machine/src/ActionBank.cpp | 31 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/transition_machine/include/Config.hpp b/transition_machine/include/Config.hpp index fcbe0a3..0d43fe1 100644 --- a/transition_machine/include/Config.hpp +++ b/transition_machine/include/Config.hpp @@ -138,7 +138,7 @@ class Config private : - const unsigned int HISTORY_SIZE = 1000; + const unsigned int HISTORY_SIZE = 2000; /// @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/ActionBank.cpp b/transition_machine/src/ActionBank.cpp index 6591710..4dbf8e3 100644 --- a/transition_machine/src/ActionBank.cpp +++ b/transition_machine/src/ActionBank.cpp @@ -564,16 +564,37 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na }; auto appliable = [dist](Config & c, Action::BasicAction) { - std::string classifierName = c.pastActions.top().first; - int stateHistorySize = c.getStateHistory(classifierName).size(); - - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) + if (c.pastActions.size() == 0) return false; + const std::string & classifierName = c.pastActions.top().first; + if (c.hashHistory.contains(c.computeHash())) return false; - if (stateHistorySize <= dist) + unsigned int topIndex = 0; + + static auto undoOneTime = [](Config & c, const std::string & classifierName, unsigned int & topIndex) + { + while (true) + { + topIndex++; + + if (topIndex >= c.pastActions.size()) + return; + + if (c.pastActions.getElem(topIndex).first == classifierName) + return; + } + }; + + undoOneTime(c, classifierName, topIndex); + for (int i = 0; i < dist-1; i++) + undoOneTime(c, classifierName, topIndex); + + undoOneTime(c, classifierName, topIndex); + + if (topIndex >= c.pastActions.size()) return false; return true; -- GitLab