Skip to content
Snippets Groups Projects
Commit 8353c4cc authored by Franck Dary's avatar Franck Dary
Browse files

Improved BACK action appliable detection

parent 0ab11e48
No related branches found
No related tags found
No related merge requests found
...@@ -138,7 +138,7 @@ class Config ...@@ -138,7 +138,7 @@ class Config
private : private :
const unsigned int HISTORY_SIZE = 1000; const unsigned int HISTORY_SIZE = 2000;
/// @brief The name of the current state of the TransitionMachine. /// @brief The name of the current state of the TransitionMachine.
std::string currentStateName; std::string currentStateName;
/// @brief For each state of the TransitionMachine, an history of the Action that have been applied to this Config. /// @brief For each state of the TransitionMachine, an history of the Action that have been applied to this Config.
......
...@@ -564,16 +564,37 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na ...@@ -564,16 +564,37 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
}; };
auto appliable = [dist](Config & c, Action::BasicAction) auto appliable = [dist](Config & c, Action::BasicAction)
{ {
std::string classifierName = c.pastActions.top().first; if (c.pastActions.size() == 0)
int stateHistorySize = c.getStateHistory(classifierName).size();
if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK"))
return false; return false;
const std::string & classifierName = c.pastActions.top().first;
if (c.hashHistory.contains(c.computeHash())) if (c.hashHistory.contains(c.computeHash()))
return false; 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 false;
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment