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

Added the oracle to compute the cost of a transition on a config into the class Transition

parent db30ed5b
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include "Action.hpp" #include "Action.hpp"
#include "Config.hpp"
class Transition class Transition
{ {
...@@ -10,6 +11,11 @@ class Transition ...@@ -10,6 +11,11 @@ class Transition
std::string name; std::string name;
std::vector<Action> sequence; std::vector<Action> sequence;
std::function<int(const Config & config)> cost;
private :
void initWrite(std::string colName, std::string object, std::string index, std::string value);
public : public :
......
...@@ -7,21 +7,49 @@ Transition::Transition(const std::string & name) ...@@ -7,21 +7,49 @@ Transition::Transition(const std::string & name)
std::regex writeRegex("WRITE ([bs])\\.(.+) (.+) (.+)"); std::regex writeRegex("WRITE ([bs])\\.(.+) (.+) (.+)");
std::smatch sm; auto doIfNameMatch = [name](auto & reg, auto init)
{
std::smatch sm;
std::regex_match(name, sm, reg);
if (sm.empty())
return false;
init(sm);
return true;
};
try try
{ {
std::regex_match(name, sm, writeRegex); if (doIfNameMatch(writeRegex, [this](auto sm){initWrite(sm[3], sm[1], sm[2], sm[4]);}))
if (!sm.empty())
{
sequence.emplace_back(Action::addHypothesisRelative(sm[3], Action::str2object(sm[1]), std::stoi(sm[2]), sm[4]));
return; return;
}
throw std::exception(); throw std::invalid_argument("no match");
} catch (std::exception & e) {util::myThrow(fmt::format("Invalid name '{}' ({})", name, e.what()));}
}
void Transition::initWrite(std::string colName, std::string object, std::string index, std::string value)
{
auto objectValue = Action::str2object(object);
int indexValue = std::stoi(index);
sequence.emplace_back(Action::addHypothesisRelative(colName, objectValue, indexValue, value));
cost = [colName, objectValue, indexValue, value](const Config & config)
{
int lineIndex = 0;
if (objectValue == Action::Object::Buffer)
lineIndex = config.getWordIndex() + indexValue;
else
lineIndex = config.getStack(indexValue);
} catch (std::exception &) {util::myThrow(fmt::format("Invalid name '{}'", name));} if (config.getConst(colName, lineIndex, 0) == value)
return 0;
return 1;
};
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment