From 04d2b628f58d2d6d92c13af15942b07fbfb9eaea Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Fri, 30 Mar 2018 20:07:24 +0100 Subject: [PATCH] Maps for local entities --- ctx_aut.cc | 2 +- rs.cc | 2 +- symrs.cc | 38 +++++++++++++++++++++++++++++++------- symrs.hh | 8 +++++++- types.hh | 3 +++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/ctx_aut.cc b/ctx_aut.cc index 11e30d8..0710e3c 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -114,7 +114,7 @@ void CtxAut::showTransitions(void) for (const auto &t : transitions) { cout << " * [" << getStateName(t.src_state) << " -> " << getStateName( t.dst_state) - << "]: {" << parent_rctsys->procEntitiesToStr(t.ctx) << "}" << endl; + << "]: { " << parent_rctsys->procEntitiesToStr(t.ctx) << "}" << endl; } } diff --git a/rs.cc b/rs.cc index 99b85d8..5f9bf71 100644 --- a/rs.cc +++ b/rs.cc @@ -183,7 +183,7 @@ std::string RctSys::entitiesToStr(const Entities &entities) std::string RctSys::procEntitiesToStr(const EntitiesForProc &procEntities) { - std::string s = " "; + std::string s = ""; for (auto const &p : procEntities) { s += getProcessName(p.first) + "={" + entitiesToStr(p.second) + "} "; diff --git a/symrs.cc b/symrs.cc index 17b1ebe..98d51d5 100644 --- a/symrs.cc +++ b/symrs.cc @@ -61,11 +61,28 @@ void SymRS::encode(void) VERB("Encoding done"); } +LocalIndicesForProcEntities SymRS::buildLocalEntitiesMap( + const EntitiesForProc &procEnt) +{ + LocalIndicesForProcEntities ent_map; + unsigned int cnt = 0; + + for (const auto &proc_ent : procEnt) { + Process proc_id = proc_ent.first; + + for (const auto &e : proc_ent.second) { + ent_map[proc_id][e] = cnt++; + } + } + + return ent_map; +} + void SymRS::mapProcEntities(void) { - + // // Reactions - + // for (const auto &proc_rcts : rs->proc_reactions) { Process proc_id = proc_rcts.first; @@ -78,13 +95,20 @@ void SymRS::mapProcEntities(void) } } + prod_ent_local_idx = buildLocalEntitiesMap(usedProducts); + + // // Context automaton + // + for (const auto &tr : rs->ctx_aut->transitions) { + for (const auto &proc_ctx : tr.ctx) { + Process proc_id = proc_ctx.first; + SET_ADD(usedCtxEntities[proc_id], proc_ctx.second); + } + } - // for (const ) - // usedCtxEntities - - cout << rs->procEntitiesToStr(usedProducts) << endl; - + ctx_ent_local_idx = buildLocalEntitiesMap(usedCtxEntities); + // cout << rs->procEntitiesToStr(usedCtxEntities) << endl; } BDD SymRS::encEntity_raw(Entity entity, bool succ) const diff --git a/symrs.hh b/symrs.hh index 7cdeb6b..56db27e 100644 --- a/symrs.hh +++ b/symrs.hh @@ -238,6 +238,11 @@ class SymRS EntitiesForProc usedProducts; EntitiesForProc usedCtxEntities; + // Local indices for each entity (per process): + // separete for state/product entities and context + LocalIndicesForProcEntities prod_ent_local_idx; + LocalIndicesForProcEntities ctx_ent_local_idx; + BDD encEntity_raw(Entity entity, bool succ) const; BDD encEntity(Entity entity) const { @@ -296,6 +301,8 @@ class SymRS void encodeInitStatesForCtxAut(void); void encodeInitStatesNoCtxAut(void); void mapStateToAct(void); + LocalIndicesForProcEntities buildLocalEntitiesMap(const EntitiesForProc + &procEnt); void mapProcEntities(void); void encode(void); @@ -307,7 +314,6 @@ class SymRS size_t getCtxAutStateEncodingSize(void); - }; #endif diff --git a/types.hh b/types.hh index cbe98a0..57bea19 100644 --- a/types.hh +++ b/types.hh @@ -39,6 +39,9 @@ typedef std::map StatesByName; typedef std::map EntitiesForProc; +typedef std::map EntiesToLocalIndex; +typedef std::map LocalIndicesForProcEntities; + struct ReactionCond { Entities rctt; Entities inhib;