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