diff --git a/transition_machine/include/Config.hpp b/transition_machine/include/Config.hpp index fcbe0a3d6317bc208f6bc2fb866173728cf988c3..0d43fe15a2032f3987aa4df269bba3737c7b0d4f 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 6591710ab6bd308118dea4870be11b50d8ec5666..4dbf8e350aa6599abde0eb3a97522f9ee31484b5 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;