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 << " = Init state: " << getStateName(init_state_id) << endl;
|
||||
|
||||
for (const auto &s : states_ids) {
|
||||
cout << " * " << s << endl;
|
||||
}
|
||||
@@ -84,6 +83,15 @@ void CtxAut::pushContextEntity(Entity 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)
|
||||
{
|
||||
VERB_L3("Saving transition");
|
||||
@@ -91,7 +99,7 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
||||
CtxAutTransition new_transition;
|
||||
|
||||
new_transition.src_state = getStateID(srcStateName);
|
||||
new_transition.ctx = tmpEntities;
|
||||
new_transition.ctx = tmpProcEntities;
|
||||
tmpEntities.clear();
|
||||
new_transition.dst_state = getStateID(dstStateName);
|
||||
transitions.push_back(new_transition);
|
||||
@@ -100,11 +108,10 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
||||
void CtxAut::showTransitions(void)
|
||||
{
|
||||
cout << "# Context Automaton Transitions:" << endl;
|
||||
|
||||
for (const auto &t : transitions) {
|
||||
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName(
|
||||
t.dst_state)
|
||||
<< "]: {" << parent_rctsys->entitiesToStr(t.ctx) << "}" << endl;
|
||||
<< "]: {" << parent_rctsys->procEntitiesToStr(t.ctx) << "}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2018
|
||||
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
|
||||
@@ -42,6 +39,7 @@ class CtxAut
|
||||
void addTransition(std::string srcStateName, std::string dstStateName);
|
||||
void showTransitions(void);
|
||||
void pushContextEntity(Entity entity_id);
|
||||
void saveCurrentContextSet(Process proc_id);
|
||||
void setOptions(Options *opts)
|
||||
{
|
||||
this->opts = opts;
|
||||
@@ -58,6 +56,7 @@ class CtxAut
|
||||
StatesByName states_names;
|
||||
State init_state_id;
|
||||
bool init_state_defined;
|
||||
EntitiesForProc tmpProcEntities;
|
||||
Entities tmpEntities;
|
||||
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>
|
||||
|
||||
Reuse of the code or its part for any purpose
|
||||
without the author's permission is strictly prohibited.
|
||||
*/
|
||||
|
||||
#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>
|
||||
|
||||
Reuse of the code or its part for any purpose
|
||||
without the author's permission is strictly prohibited.
|
||||
*/
|
||||
|
||||
#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)
|
||||
{
|
||||
if (!hasProcess(processName)) {
|
||||
FERROR("No such process: " << processName);
|
||||
}
|
||||
|
||||
return processes_names[processName];
|
||||
}
|
||||
|
||||
std::string RctSys::getProcessName(Process processID)
|
||||
{
|
||||
if (processID < processes_ids.size()) {
|
||||
if (hasProcess(processID)) {
|
||||
return processes_ids[processID];
|
||||
}
|
||||
else {
|
||||
@@ -118,7 +122,6 @@ void RctSys::pushReactant(std::string entityName)
|
||||
if (!hasEntity(entityName)) {
|
||||
addEntity(entityName);
|
||||
}
|
||||
|
||||
tmpReactants.insert(getEntityID(entityName));
|
||||
}
|
||||
void RctSys::pushInhibitor(std::string entityName)
|
||||
@@ -126,7 +129,6 @@ void RctSys::pushInhibitor(std::string entityName)
|
||||
if (!hasEntity(entityName)) {
|
||||
addEntity(entityName);
|
||||
}
|
||||
|
||||
tmpInhibitors.insert(getEntityID(entityName));
|
||||
}
|
||||
void RctSys::pushProduct(std::string entityName)
|
||||
@@ -134,7 +136,6 @@ void RctSys::pushProduct(std::string entityName)
|
||||
if (!hasEntity(entityName)) {
|
||||
addEntity(entityName);
|
||||
}
|
||||
|
||||
tmpProducts.insert(getEntityID(entityName));
|
||||
}
|
||||
|
||||
@@ -175,6 +176,17 @@ std::string RctSys::entitiesToStr(const Entities &entities)
|
||||
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)
|
||||
{
|
||||
cout << "# Reactions:" << endl;
|
||||
@@ -325,4 +337,10 @@ void RctSys::ctxAutPushNamedContextEntity(std::string entityName)
|
||||
ctx_aut->pushContextEntity(entity_id);
|
||||
}
|
||||
|
||||
void RctSys::ctxAutSaveCurrentContextSet(std::string processName)
|
||||
{
|
||||
Process processID = getProcessID(processName);
|
||||
ctx_aut->saveCurrentContextSet(processID);
|
||||
}
|
||||
|
||||
/** EOF **/
|
||||
|
||||
3
rs.hh
3
rs.hh
@@ -44,6 +44,7 @@ class RctSys
|
||||
|
||||
void setCurrentProcess(std::string processName);
|
||||
void addProcess(std::string processName);
|
||||
bool hasProcess(Process processID);
|
||||
bool hasProcess(std::string processName);
|
||||
Process getProcessID(std::string processName);
|
||||
std::string getProcessName(Process processID);
|
||||
@@ -59,6 +60,7 @@ class RctSys
|
||||
return entities_ids[entity];
|
||||
}
|
||||
std::string entitiesToStr(const Entities &entities);
|
||||
std::string procEntitiesToStr(const EntitiesForProc &procEntities);
|
||||
void showReactions(void);
|
||||
void pushStateEntity(std::string entityName);
|
||||
void commitInitState(void);
|
||||
@@ -90,6 +92,7 @@ class RctSys
|
||||
void ctxAutSetInitState(std::string stateName);
|
||||
void ctxAutAddTransition(std::string srcStateName, std::string dstStateName);
|
||||
void ctxAutPushNamedContextEntity(std::string entity_name);
|
||||
void ctxAutSaveCurrentContextSet(std::string processName);
|
||||
|
||||
bool initStatesDefined(void)
|
||||
{
|
||||
|
||||
@@ -38,16 +38,16 @@ blank [ \t]
|
||||
typedef yy::rsin_parser::token token;
|
||||
%}
|
||||
|
||||
"options" return token::OPTIONS;
|
||||
"options" return token::OPTIONS;
|
||||
"use-context-automaton" return token::USE_CTX_AUT;
|
||||
"use-concentrations" return token::USE_CONCENTRATIONS;
|
||||
"use-concentrations" return token::USE_CONCENTRATIONS;
|
||||
"reactions" return token::REACTIONS;
|
||||
"initial-contexts" return token::INITIALCONTEXTS;
|
||||
"context-entities" return token::CONTEXTENTITIES;
|
||||
"context-automaton" return token::CONTEXTAUTOMATON;
|
||||
"transitions" return token::TRANSITIONS;
|
||||
"states" return token::STATES;
|
||||
"init-state" return token::INITSTATE;
|
||||
"context-automaton" return token::CONTEXTAUTOMATON;
|
||||
"transitions" return token::TRANSITIONS;
|
||||
"states" return token::STATES;
|
||||
"init-state" return token::INITSTATE;
|
||||
"rsctl-property" return token::RSCTLFORM;
|
||||
"{" return token::LCB;
|
||||
"}" return token::RCB;
|
||||
@@ -55,16 +55,16 @@ blank [ \t]
|
||||
")" return token::RRB;
|
||||
"[" return token::LSB;
|
||||
"]" return token::RSB;
|
||||
"=" return token::EQ;
|
||||
"<" return token::LAB;
|
||||
">" return token::RAB;
|
||||
":" return token::COL;
|
||||
"=" return token::EQ;
|
||||
"<" return token::LAB;
|
||||
">" return token::RAB;
|
||||
":" return token::COL;
|
||||
";" return token::SEMICOL;
|
||||
"," return token::COMMA;
|
||||
"->" return token::RARR;
|
||||
"AND" return token::AND;
|
||||
"OR" return token::OR;
|
||||
"XOR" return token::XOR;
|
||||
"XOR" return token::XOR;
|
||||
"IMPLIES" return token::IMPLIES;
|
||||
"~" return token::NOT;
|
||||
"EX" return token::EX;
|
||||
|
||||
@@ -106,9 +106,11 @@ option:
|
||||
*/
|
||||
|
||||
reactionsets:
|
||||
| processname LCB reactions RCB SEMICOL
|
||||
| reactionsets process_reactions
|
||||
;
|
||||
|
||||
process_reactions: processname LCB reactions RCB SEMICOL
|
||||
|
||||
processname: IDENTIFIER {
|
||||
driver.getReactionSystem()->setCurrentProcess(*$1);
|
||||
free($1);
|
||||
@@ -227,21 +229,25 @@ 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);
|
||||
free($5);
|
||||
free($7);
|
||||
}
|
||||
;
|
||||
|
||||
proc_contextset: IDENTIFIER EQ LCB contextset RCB {
|
||||
driver.getReactionSystem()->setCurrentProcess(*$1);
|
||||
proc_ctxsets:
|
||||
| proc_ctxsets single_proc_ctxset
|
||||
;
|
||||
|
||||
single_proc_ctxset: IDENTIFIER EQ LCB contextset RCB {
|
||||
driver.getReactionSystem()->ctxAutSaveCurrentContextSet(*$1);
|
||||
free($1);
|
||||
}
|
||||
;
|
||||
|
||||
contextset:
|
||||
ctxentity
|
||||
| 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));
|
||||
BDD enc_src = encCtxAutState(t.src_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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user