Parsing, printing... Context in CA
This commit is contained in:
15
ctx_aut.cc
15
ctx_aut.cc
@@ -73,7 +73,6 @@ void CtxAut::showStates(void)
|
|||||||
{
|
{
|
||||||
cout << "# Context Automaton States:" << endl;
|
cout << "# Context Automaton States:" << endl;
|
||||||
cout << " = Init state: " << getStateName(init_state_id) << endl;
|
cout << " = Init state: " << getStateName(init_state_id) << endl;
|
||||||
|
|
||||||
for (const auto &s : states_ids) {
|
for (const auto &s : states_ids) {
|
||||||
cout << " * " << s << endl;
|
cout << " * " << s << endl;
|
||||||
}
|
}
|
||||||
@@ -84,6 +83,15 @@ void CtxAut::pushContextEntity(Entity entity_id)
|
|||||||
tmpEntities.insert(entity_id);
|
tmpEntities.insert(entity_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CtxAut::saveCurrentContextSet(Process proc_id)
|
||||||
|
{
|
||||||
|
if (!parent_rctsys->hasProcess(proc_id)) {
|
||||||
|
FERROR("No such process: ID=" << proc_id);
|
||||||
|
}
|
||||||
|
tmpProcEntities[proc_id] = tmpEntities;
|
||||||
|
tmpEntities.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
||||||
{
|
{
|
||||||
VERB_L3("Saving transition");
|
VERB_L3("Saving transition");
|
||||||
@@ -91,7 +99,7 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
|||||||
CtxAutTransition new_transition;
|
CtxAutTransition new_transition;
|
||||||
|
|
||||||
new_transition.src_state = getStateID(srcStateName);
|
new_transition.src_state = getStateID(srcStateName);
|
||||||
new_transition.ctx = tmpEntities;
|
new_transition.ctx = tmpProcEntities;
|
||||||
tmpEntities.clear();
|
tmpEntities.clear();
|
||||||
new_transition.dst_state = getStateID(dstStateName);
|
new_transition.dst_state = getStateID(dstStateName);
|
||||||
transitions.push_back(new_transition);
|
transitions.push_back(new_transition);
|
||||||
@@ -100,11 +108,10 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
|||||||
void CtxAut::showTransitions(void)
|
void CtxAut::showTransitions(void)
|
||||||
{
|
{
|
||||||
cout << "# Context Automaton Transitions:" << endl;
|
cout << "# Context Automaton Transitions:" << endl;
|
||||||
|
|
||||||
for (const auto &t : transitions) {
|
for (const auto &t : transitions) {
|
||||||
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName(
|
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName(
|
||||||
t.dst_state)
|
t.dst_state)
|
||||||
<< "]: {" << parent_rctsys->entitiesToStr(t.ctx) << "}" << endl;
|
<< "]: {" << parent_rctsys->procEntitiesToStr(t.ctx) << "}" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2018
|
Copyright (c) 2018
|
||||||
Artur Meski <meski@ipipan.waw.pl>
|
Artur Meski <meski@ipipan.waw.pl>
|
||||||
|
|
||||||
Reuse of the code or its part for any purpose
|
|
||||||
without the author's permission is strictly prohibited.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RS_CTX_AUT_HH
|
#ifndef RS_CTX_AUT_HH
|
||||||
@@ -42,6 +39,7 @@ class CtxAut
|
|||||||
void addTransition(std::string srcStateName, std::string dstStateName);
|
void addTransition(std::string srcStateName, std::string dstStateName);
|
||||||
void showTransitions(void);
|
void showTransitions(void);
|
||||||
void pushContextEntity(Entity entity_id);
|
void pushContextEntity(Entity entity_id);
|
||||||
|
void saveCurrentContextSet(Process proc_id);
|
||||||
void setOptions(Options *opts)
|
void setOptions(Options *opts)
|
||||||
{
|
{
|
||||||
this->opts = opts;
|
this->opts = opts;
|
||||||
@@ -58,6 +56,7 @@ class CtxAut
|
|||||||
StatesByName states_names;
|
StatesByName states_names;
|
||||||
State init_state_id;
|
State init_state_id;
|
||||||
bool init_state_defined;
|
bool init_state_defined;
|
||||||
|
EntitiesForProc tmpProcEntities;
|
||||||
Entities tmpEntities;
|
Entities tmpEntities;
|
||||||
CtxAutTransitions transitions;
|
CtxAutTransitions transitions;
|
||||||
};
|
};
|
||||||
|
|||||||
5
main.hh
5
main.hh
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2012, 2013
|
Copyright (c) 2012, 2013, 2018
|
||||||
Artur Meski <meski@ipipan.waw.pl>
|
Artur Meski <meski@ipipan.waw.pl>
|
||||||
|
|
||||||
Reuse of the code or its part for any purpose
|
|
||||||
without the author's permission is strictly prohibited.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RS_MAIN_HH
|
#ifndef RS_MAIN_HH
|
||||||
|
|||||||
36
rs.cc
36
rs.cc
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2012-2014
|
Copyright (c) 2012-2018
|
||||||
Artur Meski <meski@ipipan.waw.pl>
|
Artur Meski <meski@ipipan.waw.pl>
|
||||||
|
|
||||||
Reuse of the code or its part for any purpose
|
|
||||||
without the author's permission is strictly prohibited.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rs.hh"
|
#include "rs.hh"
|
||||||
@@ -94,18 +91,25 @@ bool RctSys::hasProcess(std::string processName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RctSys::hasProcess(Process processID)
|
||||||
|
{
|
||||||
|
if (processID >= processes_ids.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Process RctSys::getProcessID(std::string processName)
|
Process RctSys::getProcessID(std::string processName)
|
||||||
{
|
{
|
||||||
if (!hasProcess(processName)) {
|
if (!hasProcess(processName)) {
|
||||||
FERROR("No such process: " << processName);
|
FERROR("No such process: " << processName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return processes_names[processName];
|
return processes_names[processName];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RctSys::getProcessName(Process processID)
|
std::string RctSys::getProcessName(Process processID)
|
||||||
{
|
{
|
||||||
if (processID < processes_ids.size()) {
|
if (hasProcess(processID)) {
|
||||||
return processes_ids[processID];
|
return processes_ids[processID];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -118,7 +122,6 @@ void RctSys::pushReactant(std::string entityName)
|
|||||||
if (!hasEntity(entityName)) {
|
if (!hasEntity(entityName)) {
|
||||||
addEntity(entityName);
|
addEntity(entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpReactants.insert(getEntityID(entityName));
|
tmpReactants.insert(getEntityID(entityName));
|
||||||
}
|
}
|
||||||
void RctSys::pushInhibitor(std::string entityName)
|
void RctSys::pushInhibitor(std::string entityName)
|
||||||
@@ -126,7 +129,6 @@ void RctSys::pushInhibitor(std::string entityName)
|
|||||||
if (!hasEntity(entityName)) {
|
if (!hasEntity(entityName)) {
|
||||||
addEntity(entityName);
|
addEntity(entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpInhibitors.insert(getEntityID(entityName));
|
tmpInhibitors.insert(getEntityID(entityName));
|
||||||
}
|
}
|
||||||
void RctSys::pushProduct(std::string entityName)
|
void RctSys::pushProduct(std::string entityName)
|
||||||
@@ -134,7 +136,6 @@ void RctSys::pushProduct(std::string entityName)
|
|||||||
if (!hasEntity(entityName)) {
|
if (!hasEntity(entityName)) {
|
||||||
addEntity(entityName);
|
addEntity(entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpProducts.insert(getEntityID(entityName));
|
tmpProducts.insert(getEntityID(entityName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +176,17 @@ std::string RctSys::entitiesToStr(const Entities &entities)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RctSys::procEntitiesToStr(const EntitiesForProc &procEntities)
|
||||||
|
{
|
||||||
|
std::string s = " ";
|
||||||
|
|
||||||
|
for (auto const &p : procEntities)
|
||||||
|
{
|
||||||
|
s += getProcessName(p.first) + "={" + entitiesToStr(p.second) + "} ";
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void RctSys::showReactions(void)
|
void RctSys::showReactions(void)
|
||||||
{
|
{
|
||||||
cout << "# Reactions:" << endl;
|
cout << "# Reactions:" << endl;
|
||||||
@@ -325,4 +337,10 @@ void RctSys::ctxAutPushNamedContextEntity(std::string entityName)
|
|||||||
ctx_aut->pushContextEntity(entity_id);
|
ctx_aut->pushContextEntity(entity_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RctSys::ctxAutSaveCurrentContextSet(std::string processName)
|
||||||
|
{
|
||||||
|
Process processID = getProcessID(processName);
|
||||||
|
ctx_aut->saveCurrentContextSet(processID);
|
||||||
|
}
|
||||||
|
|
||||||
/** EOF **/
|
/** EOF **/
|
||||||
|
|||||||
3
rs.hh
3
rs.hh
@@ -44,6 +44,7 @@ class RctSys
|
|||||||
|
|
||||||
void setCurrentProcess(std::string processName);
|
void setCurrentProcess(std::string processName);
|
||||||
void addProcess(std::string processName);
|
void addProcess(std::string processName);
|
||||||
|
bool hasProcess(Process processID);
|
||||||
bool hasProcess(std::string processName);
|
bool hasProcess(std::string processName);
|
||||||
Process getProcessID(std::string processName);
|
Process getProcessID(std::string processName);
|
||||||
std::string getProcessName(Process processID);
|
std::string getProcessName(Process processID);
|
||||||
@@ -59,6 +60,7 @@ class RctSys
|
|||||||
return entities_ids[entity];
|
return entities_ids[entity];
|
||||||
}
|
}
|
||||||
std::string entitiesToStr(const Entities &entities);
|
std::string entitiesToStr(const Entities &entities);
|
||||||
|
std::string procEntitiesToStr(const EntitiesForProc &procEntities);
|
||||||
void showReactions(void);
|
void showReactions(void);
|
||||||
void pushStateEntity(std::string entityName);
|
void pushStateEntity(std::string entityName);
|
||||||
void commitInitState(void);
|
void commitInitState(void);
|
||||||
@@ -90,6 +92,7 @@ class RctSys
|
|||||||
void ctxAutSetInitState(std::string stateName);
|
void ctxAutSetInitState(std::string stateName);
|
||||||
void ctxAutAddTransition(std::string srcStateName, std::string dstStateName);
|
void ctxAutAddTransition(std::string srcStateName, std::string dstStateName);
|
||||||
void ctxAutPushNamedContextEntity(std::string entity_name);
|
void ctxAutPushNamedContextEntity(std::string entity_name);
|
||||||
|
void ctxAutSaveCurrentContextSet(std::string processName);
|
||||||
|
|
||||||
bool initStatesDefined(void)
|
bool initStatesDefined(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,9 +106,11 @@ option:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
reactionsets:
|
reactionsets:
|
||||||
| processname LCB reactions RCB SEMICOL
|
| reactionsets process_reactions
|
||||||
;
|
;
|
||||||
|
|
||||||
|
process_reactions: processname LCB reactions RCB SEMICOL
|
||||||
|
|
||||||
processname: IDENTIFIER {
|
processname: IDENTIFIER {
|
||||||
driver.getReactionSystem()->setCurrentProcess(*$1);
|
driver.getReactionSystem()->setCurrentProcess(*$1);
|
||||||
free($1);
|
free($1);
|
||||||
@@ -227,21 +229,25 @@ auttransitions:
|
|||||||
| auttrans SEMICOL auttransitions
|
| auttrans SEMICOL auttransitions
|
||||||
;
|
;
|
||||||
|
|
||||||
auttrans: LCB proc_contextset RCB COL IDENTIFIER RARR IDENTIFIER {
|
auttrans: LCB proc_ctxsets RCB COL IDENTIFIER RARR IDENTIFIER {
|
||||||
driver.getReactionSystem()->ctxAutAddTransition(*$5, *$7);
|
driver.getReactionSystem()->ctxAutAddTransition(*$5, *$7);
|
||||||
free($5);
|
free($5);
|
||||||
free($7);
|
free($7);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
proc_contextset: IDENTIFIER EQ LCB contextset RCB {
|
proc_ctxsets:
|
||||||
driver.getReactionSystem()->setCurrentProcess(*$1);
|
| proc_ctxsets single_proc_ctxset
|
||||||
|
;
|
||||||
|
|
||||||
|
single_proc_ctxset: IDENTIFIER EQ LCB contextset RCB {
|
||||||
|
driver.getReactionSystem()->ctxAutSaveCurrentContextSet(*$1);
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
contextset:
|
contextset:
|
||||||
ctxentity
|
| ctxentity
|
||||||
| contextset COMMA ctxentity
|
| contextset COMMA ctxentity
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
3
symrs.cc
3
symrs.cc
@@ -581,7 +581,8 @@ void SymRS::encodeCtxAutTrans(void)
|
|||||||
<< " -> " << rs->ctx_aut->getStateName(t.dst_state));
|
<< " -> " << rs->ctx_aut->getStateName(t.dst_state));
|
||||||
BDD enc_src = encCtxAutState(t.src_state);
|
BDD enc_src = encCtxAutState(t.src_state);
|
||||||
BDD enc_dst = encCtxAutStateSucc(t.dst_state);
|
BDD enc_dst = encCtxAutStateSucc(t.dst_state);
|
||||||
BDD enc_ctx = compContext(encActEntitiesConj(t.ctx));
|
assert(0); // enc_ctx
|
||||||
|
BDD enc_ctx = BDD_FALSE; //compContext(encActEntitiesConj(t.ctx));
|
||||||
|
|
||||||
*tr_ca += enc_src * enc_ctx * enc_dst;
|
*tr_ca += enc_src * enc_ctx * enc_dst;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user