Reactions organised by process
This commit is contained in:
51
rs.cc
51
rs.cc
@@ -9,6 +9,7 @@
|
||||
#include "rs.hh"
|
||||
|
||||
RctSys::RctSys(void)
|
||||
: current_process_defined(false)
|
||||
{
|
||||
ctx_aut = nullptr;
|
||||
}
|
||||
@@ -29,7 +30,7 @@ void RctSys::addEntity(std::string name)
|
||||
|
||||
VERB_L2("Adding entity: " << name << " index=" << new_entity_id);
|
||||
|
||||
entities_ids.push_back(name);
|
||||
entities_ids.push_back(name);
|
||||
entities_names[name] = new_entity_id;
|
||||
}
|
||||
}
|
||||
@@ -57,6 +58,47 @@ Entity RctSys::getEntityID(std::string name)
|
||||
void RctSys::setCurrentProcess(std::string processName)
|
||||
{
|
||||
VERB_LN(2, "Current Process: " << processName);
|
||||
|
||||
if (!hasProcess(processName))
|
||||
{
|
||||
addProcess(processName);
|
||||
}
|
||||
|
||||
current_proc_id = getProcessID(processName);
|
||||
}
|
||||
|
||||
void RctSys::addProcess(std::string processName)
|
||||
{
|
||||
if (!hasProcess(processName))
|
||||
{
|
||||
Process new_proc_id = processes_ids.size();
|
||||
|
||||
VERB_L2("Adding process: " << processName << " index=" << new_proc_id);
|
||||
|
||||
processes_ids.push_back(processName);
|
||||
processes_names[processName] = new_proc_id;
|
||||
|
||||
// reactions for the new process
|
||||
proc_reactions.push_back(Reactions());
|
||||
assert(proc_reactions.size() == new_proc_id+1);
|
||||
}
|
||||
}
|
||||
|
||||
bool RctSys::hasProcess(std::string processName)
|
||||
{
|
||||
if (processes_names.find(processName) == processes_names.end())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
Process RctSys::getProcessID(std::string processName)
|
||||
{
|
||||
if (!hasProcess(processName))
|
||||
{
|
||||
FERROR("No such process: " << processName);
|
||||
}
|
||||
return processes_names[processName];
|
||||
}
|
||||
|
||||
void RctSys::pushReactant(std::string entityName)
|
||||
@@ -78,6 +120,11 @@ void RctSys::pushProduct(std::string entityName)
|
||||
tmpProducts.insert(getEntityID(entityName));
|
||||
}
|
||||
|
||||
void RctSys::addReactionForCurrentProcess(Reaction reaction)
|
||||
{
|
||||
proc_reactions[current_proc_id].push_back(reaction);
|
||||
}
|
||||
|
||||
void RctSys::commitReaction(void)
|
||||
{
|
||||
VERB_L3("Saving reaction");
|
||||
@@ -88,7 +135,7 @@ void RctSys::commitReaction(void)
|
||||
r.inhib = tmpInhibitors;
|
||||
r.prod = tmpProducts;
|
||||
|
||||
reactions.push_back(r);
|
||||
addReactionForCurrentProcess(r);
|
||||
|
||||
tmpReactants.clear();
|
||||
tmpInhibitors.clear();
|
||||
|
||||
43
rs.hh
43
rs.hh
@@ -33,23 +33,24 @@ class RctSys
|
||||
|
||||
public:
|
||||
RctSys(void);
|
||||
void setOptions(Options *opts)
|
||||
{
|
||||
this->opts = opts;
|
||||
}
|
||||
|
||||
void setOptions(Options *opts) { this->opts = opts; }
|
||||
bool hasEntity(std::string entityName);
|
||||
void addEntity(std::string entityName);
|
||||
std::string getEntityName(Entity entityID);
|
||||
|
||||
void setCurrentProcess(std::string processName);
|
||||
void addProcess(std::string processName);
|
||||
bool hasProcess(std::string processName);
|
||||
Process getProcessID(std::string processName);
|
||||
|
||||
void addReactionForCurrentProcess(Reaction reaction);
|
||||
|
||||
void pushReactant(std::string entityName);
|
||||
void pushInhibitor(std::string entityName);
|
||||
void pushProduct(std::string entityName);
|
||||
void commitReaction(void);
|
||||
std::string entityToStr(const Entity entity) {
|
||||
return entities_ids[entity];
|
||||
}
|
||||
std::string entityToStr(const Entity entity) { return entities_ids[entity]; }
|
||||
std::string entitiesToStr(const Entities &entities);
|
||||
void showReactions(void);
|
||||
void pushStateEntity(std::string entityName);
|
||||
@@ -57,18 +58,10 @@ class RctSys
|
||||
void addActionEntity(std::string entityName);
|
||||
void addActionEntity(Entity entity);
|
||||
bool isActionEntity(Entity entity);
|
||||
void resetInitStates(void) {
|
||||
initStates.clear();
|
||||
}
|
||||
unsigned int getEntitiesSize(void) {
|
||||
return entities_ids.size();
|
||||
}
|
||||
unsigned int getReactionsSize(void) {
|
||||
return reactions.size();
|
||||
}
|
||||
unsigned int getActionsSize(void) {
|
||||
return actionEntities.size();
|
||||
}
|
||||
void resetInitStates(void) { initStates.clear(); }
|
||||
unsigned int getEntitiesSize(void) { return entities_ids.size(); }
|
||||
unsigned int getReactionsSize(void) { return reactions.size(); }
|
||||
unsigned int getActionsSize(void) { return actionEntities.size(); }
|
||||
void showInitialStates(void);
|
||||
void showActionEntities(void);
|
||||
void printSystem(void);
|
||||
@@ -83,16 +76,24 @@ class RctSys
|
||||
bool usingContextAutomaton(void) { return ctx_aut != nullptr; }
|
||||
|
||||
private:
|
||||
Reactions reactions;
|
||||
Reactions reactions; // TODO: to be removed later
|
||||
ReactionsForProc proc_reactions;
|
||||
|
||||
EntitiesSets initStates;
|
||||
|
||||
Entities actionEntities;
|
||||
|
||||
CtxAut *ctx_aut;
|
||||
|
||||
EntitiesByIds entities_ids;
|
||||
EntitiesById entities_ids;
|
||||
EntitiesByName entities_names;
|
||||
|
||||
ProcessesById processes_ids;
|
||||
ProcessesByName processes_names;
|
||||
|
||||
Process current_proc_id;
|
||||
bool current_process_defined;
|
||||
|
||||
Entities tmpReactants;
|
||||
Entities tmpInhibitors;
|
||||
Entities tmpProducts;
|
||||
|
||||
8
types.hh
8
types.hh
@@ -22,7 +22,9 @@ struct Reaction {
|
||||
Entities prod;
|
||||
};
|
||||
typedef std::vector<Reaction> Reactions;
|
||||
typedef std::vector<std::string> EntitiesByIds;
|
||||
typedef std::vector<Reactions> ReactionsForProc;
|
||||
|
||||
typedef std::vector<std::string> EntitiesById;
|
||||
typedef std::map<std::string, Entity> EntitiesByName;
|
||||
typedef std::set<Entities> EntitiesSets;
|
||||
|
||||
@@ -30,6 +32,10 @@ typedef unsigned int State;
|
||||
typedef std::vector<std::string> StatesById;
|
||||
typedef std::map<std::string, State> StatesByName;
|
||||
|
||||
typedef unsigned int Process;
|
||||
typedef std::vector<std::string> ProcessesById;
|
||||
typedef std::map<std::string, Process> ProcessesByName;
|
||||
|
||||
struct ReactionCond {
|
||||
Entities rctt;
|
||||
Entities inhib;
|
||||
|
||||
Reference in New Issue
Block a user