RS with context automaton (we embed CA with RS)

This commit is contained in:
Artur Meski
2018-03-03 21:19:13 +00:00
parent f121ce12fd
commit c853e40ad7
10 changed files with 93 additions and 149 deletions

68
rs.cc
View File

@@ -8,6 +8,11 @@
#include "rs.hh"
RctSys::RctSys(void)
{
ctx_aut = nullptr;
}
bool RctSys::hasEntity(std::string name)
{
if (entities_names.find(name) == entities_names.end())
@@ -40,7 +45,7 @@ std::string RctSys::getEntityName(Entity entityID)
}
}
RctSys::Entity RctSys::getEntityID(std::string name)
Entity RctSys::getEntityID(std::string name)
{
if (!hasEntity(name))
{
@@ -166,52 +171,21 @@ void RctSys::printSystem(void)
showInitialStates();
showActionEntities();
showReactions();
}
bool CtxAut::hasState(std::string name)
{
if (states_names.find(name) == states_names.end())
return false;
else
return true;
}
CtxAut::State CtxAut::getStateID(std::string name)
{
if (!hasState(name))
{
FERROR("No such state: " << name);
}
return states_names[name];
}
void CtxAut::addState(std::string name)
{
if (!hasState(name))
{
State new_state_id = states_ids.size();
VERB_L2("Adding state: " << name << " index=" << new_state_id);
states_ids.push_back(name);
states_names[name] = new_state_id;
}
}
void CtxAut::pushContextEntity(RctSys::Entity entity_id)
{
tmpEntities.insert(entity_id);
}
void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
{
VERB_L3("Saving transition");
Transition new_transition;
new_transition.src_state = getStateID(srcStateName);
new_transition.ctx = tmpEntities;
tmpEntities.clear();
new_transition.dst_state = getStateID(dstStateName);
if (ctx_aut != nullptr)
{
ctx_aut->printAutomaton();
}
}
void RctSys::ctxAutEnable(void)
{
assert(ctx_aut == nullptr);
ctx_aut = new CtxAut;
}
void RctSys::ctxAutAddState(std::string stateName)
{
assert(ctx_aut != nullptr);
}