From 179c199ece47d2f03e57509a6e3da87fce34c0e5 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 28 Mar 2018 15:35:48 +0100 Subject: [PATCH 01/90] Processes, switching --- rs.cc | 5 +++++ rs.hh | 3 +++ rsin_parser.yy | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/rs.cc b/rs.cc index 9ed9d26..42558f6 100644 --- a/rs.cc +++ b/rs.cc @@ -54,6 +54,11 @@ Entity RctSys::getEntityID(std::string name) return entities_names[name]; } +void RctSys::setCurrentProcess(std::string processName) +{ + VERB_LN(2, "Current Process: " << processName); +} + void RctSys::pushReactant(std::string entityName) { if (!hasEntity(entityName)) diff --git a/rs.hh b/rs.hh index 00bf7fa..1c40459 100644 --- a/rs.hh +++ b/rs.hh @@ -40,6 +40,9 @@ class RctSys bool hasEntity(std::string entityName); void addEntity(std::string entityName); std::string getEntityName(Entity entityID); + + void setCurrentProcess(std::string processName); + void pushReactant(std::string entityName); void pushInhibitor(std::string entityName); void pushProduct(std::string entityName); diff --git a/rsin_parser.yy b/rsin_parser.yy index 1038cec..c947743 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -77,7 +77,7 @@ class rsin_driver; system: | OPTIONS LCB options RCB system - | REACTIONS LCB reactions RCB system + | REACTIONS LCB reactionsets RCB system | INITIALCONTEXTS LCB initstates RCB system | CONTEXTENTITIES LCB actionentities RCB system | CONTEXTAUTOMATON LCB ctxaut RCB system @@ -104,6 +104,20 @@ option: * REACTIONS * ------------------------- */ + +reactionsets: + | processname LCB reactions RCB SEMICOL + ; + +processname: IDENTIFIER { + //driver.getReactionSystem()->ctxAutAddState(*$1); + // + // Set the current process name for which we are saving reactions... + // + driver.getReactionSystem()->setCurrentProcess(*$1); + free($1); + } + reactions: | reactions reaction SEMICOL ; From 99fbed638c1e159e76ed8ac3333f5ad39bb40905 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 28 Mar 2018 18:10:42 +0100 Subject: [PATCH 02/90] Reactions organised by process --- rs.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- rs.hh | 43 ++++++++++++++++++++++--------------------- types.hh | 8 +++++++- 3 files changed, 78 insertions(+), 24 deletions(-) diff --git a/rs.cc b/rs.cc index 42558f6..1f22c00 100644 --- a/rs.cc +++ b/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(); diff --git a/rs.hh b/rs.hh index 1c40459..3b48d63 100644 --- a/rs.hh +++ b/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; diff --git a/types.hh b/types.hh index 23529bf..cfaf789 100644 --- a/types.hh +++ b/types.hh @@ -22,7 +22,9 @@ struct Reaction { Entities prod; }; typedef std::vector Reactions; -typedef std::vector EntitiesByIds; +typedef std::vector ReactionsForProc; + +typedef std::vector EntitiesById; typedef std::map EntitiesByName; typedef std::set EntitiesSets; @@ -30,6 +32,10 @@ typedef unsigned int State; typedef std::vector StatesById; typedef std::map StatesByName; +typedef unsigned int Process; +typedef std::vector ProcessesById; +typedef std::map ProcessesByName; + struct ReactionCond { Entities rctt; Entities inhib; From 753b217721be4cb826b6413846db34bd9a85cc36 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 28 Mar 2018 18:58:59 +0100 Subject: [PATCH 03/90] Printing of reactions --- rs.cc | 30 ++++++++++++++++++++++++------ rs.hh | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/rs.cc b/rs.cc index 1f22c00..5df678a 100644 --- a/rs.cc +++ b/rs.cc @@ -101,6 +101,16 @@ Process RctSys::getProcessID(std::string processName) return processes_names[processName]; } +std::string RctSys::getProcessName(Process processID) +{ + if (processID < processes_ids.size()) + return processes_ids[processID]; + else + { + FERROR("No such process ID: " << processID); + } +} + void RctSys::pushReactant(std::string entityName) { if (!hasEntity(entityName)) @@ -155,12 +165,20 @@ std::string RctSys::entitiesToStr(const Entities &entities) void RctSys::showReactions(void) { cout << "# Reactions:" << endl; - for (auto r = reactions.begin(); r != reactions.end(); ++r) - { - cout << " * (R={" << entitiesToStr(r->rctt) << "}," - << "I={" << entitiesToStr(r->inhib) << "}," - << "P={" << entitiesToStr(r->prod) << "})" << endl; - } + + for (unsigned int proc_id = 0; proc_id < processes_ids.size(); ++proc_id) + { + cout << endl; + cout << " . proc = \"" << getProcessName(proc_id) << "\":" << endl; + for (const auto &r : proc_reactions[proc_id]) + { + cout << " * (R={" << entitiesToStr(r.rctt) << "}," + << "I={" << entitiesToStr(r.inhib) << "}," + << "P={" << entitiesToStr(r.prod) << "})" << endl; + } + + } + cout << endl; } void RctSys::pushStateEntity(std::string entityName) diff --git a/rs.hh b/rs.hh index 3b48d63..350d336 100644 --- a/rs.hh +++ b/rs.hh @@ -43,6 +43,7 @@ class RctSys void addProcess(std::string processName); bool hasProcess(std::string processName); Process getProcessID(std::string processName); + std::string getProcessName(Process processID); void addReactionForCurrentProcess(Reaction reaction); From c90a87875a3a5f6190850b80b286c9a6ecefc789 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 28 Mar 2018 20:46:19 +0100 Subject: [PATCH 04/90] Context automaton with augmented context: parsing --- main.cc | 80 ++++++++++++++++++++++++++++---------------------- main.hh | 6 ++-- rs.cc | 8 +++-- rsin_parser.ll | 1 + rsin_parser.yy | 14 +++++---- types.hh | 11 ++++--- 6 files changed, 71 insertions(+), 49 deletions(-) diff --git a/main.cc b/main.cc index afc90f7..25b3aa8 100644 --- a/main.cc +++ b/main.cc @@ -34,7 +34,7 @@ int main(int argc, char **argv) int c; int option_index = 0; - while ((c = getopt_long(argc, argv, "cbBmpPrsStTvxz", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "cbBmpPrsStTvxzh", long_options, &option_index)) != -1) { switch (c) { case 0: @@ -90,8 +90,12 @@ int main(int argc, char **argv) opts->reorder_reach = true; opts->reorder_trans = true; break; + case 'h': + usage_error = true; + break; default: usage_error = true; + break; } } @@ -108,40 +112,7 @@ int main(int argc, char **argv) if (usage_error) { - cout << endl - << " ------------------------------------" << endl - << " -- Reaction Systems Model Checker --" << endl - << " ------------------------------------" << endl - << endl - << " Version: " << VERSION << endl - << " Contact: " << AUTHOR << endl - << endl -#ifndef PUBLIC_RELEASE - << " ###################################" << endl - << " THIS IS A PRIVATE VERSION OF RSMC " << endl - << " PLEASE, DO NOT DISTRIBUTE " << endl - << " ###################################" << endl - << endl -#endif - << " Usage: " << argv[0] << " [options] " << endl << endl - << " TASKS:" << endl - << " -c -- perform RSCTL model checking" << endl - //<< " -f K -- generate SMT input for the depth K" << endl - << " -P -- print parsed system" << endl - << " -r -- print reactions" << endl - << " -s -- print the set of all the reachable states" << endl - << " -t -- print the set of all the reachable states with their successors" << endl - << endl << " OTHER:" << endl - << " -b -- disable bounded model checking (BMC) heuristic" << endl - << " -x -- use partitioned transition relation (may use less memory)" << endl - << " -z -- use reordering of the BDD variables" << endl - << " -v -- verbose (can be used more than once to increase verbosity)" << endl - << " -p -- show progress (where possible)" << endl - << endl - << " Benchmarking options:" << endl - << " -m -- measure and display time and memory usage" << endl - << " -B -- display an easy to parse summary (enables -m)" << endl - << endl; + print_help(std::string(argv[0])); return 100; } @@ -233,4 +204,43 @@ int main(int argc, char **argv) return 0; } +void print_help(std::string path_str) +{ + cout << endl + << " ------------------------------------" << endl + << " -- Reaction Systems Model Checker --" << endl + << " ------------------------------------" << endl + << endl + << " Version: " << VERSION << endl + << " Contact: " << AUTHOR << endl + << endl +#ifndef PUBLIC_RELEASE + << " ###################################" << endl + << " THIS IS A PRIVATE VERSION OF RSMC " << endl + << " PLEASE, DO NOT DISTRIBUTE " << endl + << " ###################################" << endl + << endl +#endif + << " Usage: " << path_str << " [options] " << endl << endl + << " TASKS:" << endl + << " -c -- perform RSCTL model checking" << endl + //<< " -f K -- generate SMT input for the depth K" << endl + << " -P -- print parsed system" << endl + << " -r -- print reactions" << endl + << " -s -- print the set of all the reachable states" << endl + << " -t -- print the set of all the reachable states with their successors" << endl + << endl << " OTHER:" << endl + << " -b -- disable bounded model checking (BMC) heuristic" << endl + << " -x -- use partitioned transition relation (may use less memory)" << endl + << " -z -- use reordering of the BDD variables" << endl + << " -v -- verbose (can be used more than once to increase verbosity)" << endl + << " -p -- show progress (where possible)" << endl + << endl + << " Benchmarking options:" << endl + << " -m -- measure and display time and memory usage" << endl + << " -B -- display an easy to parse summary (enables -m)" << endl + << endl; +} + /** EOF **/ + diff --git a/main.hh b/main.hh index 5a7b11b..5d95f44 100644 --- a/main.hh +++ b/main.hh @@ -22,9 +22,11 @@ #include "options.hh" #include "memtime.hh" -#define VERSION "1.0alpha" -#define AUTHOR "Artur Męski " +#define VERSION "2.0 ALPHA" +#define AUTHOR "Artur Meski " using std::cout; using std::endl; +void print_help(std::string path_str); + #endif diff --git a/rs.cc b/rs.cc index 5df678a..4b844f4 100644 --- a/rs.cc +++ b/rs.cc @@ -65,6 +65,7 @@ void RctSys::setCurrentProcess(std::string processName) } current_proc_id = getProcessID(processName); + current_process_defined = true; } void RctSys::addProcess(std::string processName) @@ -79,7 +80,7 @@ void RctSys::addProcess(std::string processName) processes_names[processName] = new_proc_id; // reactions for the new process - proc_reactions.push_back(Reactions()); + proc_reactions[new_proc_id] = Reactions(); assert(proc_reactions.size() == new_proc_id+1); } } @@ -132,6 +133,10 @@ void RctSys::pushProduct(std::string entityName) void RctSys::addReactionForCurrentProcess(Reaction reaction) { + if (!current_process_defined) + { + FERROR("Internal error. Current process is not set!"); + } proc_reactions[current_proc_id].push_back(reaction); } @@ -176,7 +181,6 @@ void RctSys::showReactions(void) << "I={" << entitiesToStr(r.inhib) << "}," << "P={" << entitiesToStr(r.prod) << "})" << endl; } - } cout << endl; } diff --git a/rsin_parser.ll b/rsin_parser.ll index ba2cbf8..8ecb732 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -55,6 +55,7 @@ blank [ \t] ")" return token::RRB; "[" return token::LSB; "]" return token::RSB; +"=" return token::EQ; "<" return token::LAB; ">" return token::RAB; ":" return token::COL; diff --git a/rsin_parser.yy b/rsin_parser.yy index c947743..02458e7 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -47,7 +47,7 @@ class rsin_driver; %token OPTIONS USE_CTX_AUT USE_CONCENTRATIONS %token REACTIONS INITIALCONTEXTS CONTEXTENTITIES RSCTLFORM %token CONTEXTAUTOMATON STATES INITSTATE TRANSITIONS -%token LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL COMMA RARR +%token EQ LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL COMMA RARR %token AND OR XOR IMPLIES NOT %token EX EU EF EG AX AU AF AG E A X U F G EMPTY @@ -110,10 +110,6 @@ reactionsets: ; processname: IDENTIFIER { - //driver.getReactionSystem()->ctxAutAddState(*$1); - // - // Set the current process name for which we are saving reactions... - // driver.getReactionSystem()->setCurrentProcess(*$1); free($1); } @@ -231,12 +227,18 @@ auttransitions: | auttrans SEMICOL auttransitions ; -auttrans: LCB contextset RCB COL IDENTIFIER RARR IDENTIFIER { +auttrans: LCB proc_contextset 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); + free($1); + } + ; contextset: ctxentity diff --git a/types.hh b/types.hh index cfaf789..b431fa0 100644 --- a/types.hh +++ b/types.hh @@ -21,8 +21,13 @@ struct Reaction { Entities inhib; Entities prod; }; + +typedef unsigned int Process; +typedef std::vector ProcessesById; +typedef std::map ProcessesByName; + typedef std::vector Reactions; -typedef std::vector ReactionsForProc; +typedef std::map ReactionsForProc; typedef std::vector EntitiesById; typedef std::map EntitiesByName; @@ -32,9 +37,7 @@ typedef unsigned int State; typedef std::vector StatesById; typedef std::map StatesByName; -typedef unsigned int Process; -typedef std::vector ProcessesById; -typedef std::map ProcessesByName; +typedef std::map EntitiesForProc; struct ReactionCond { Entities rctt; From 5f1a759c8fa972996653d1eae6769a891f55bf1a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 28 Mar 2018 21:00:44 +0100 Subject: [PATCH 05/90] Reformatting --- bdd_macro.hh | 8 +- ctx_aut.cc | 117 +++---- ctx_aut.hh | 58 ++-- formrsctl.cc | 519 ++++++++++++++--------------- formrsctl.hh | 417 ++++++++++++----------- macro.hh | 12 +- main.cc | 427 ++++++++++++------------ mc.cc | 873 ++++++++++++++++++++++++------------------------- mc.hh | 24 +- memtime.hh | 43 +-- options.hh | 25 +- rs.cc | 359 ++++++++++---------- rs.hh | 156 +++++---- rsin_driver.cc | 85 +++-- rsin_driver.hh | 48 +-- symrs.cc | 842 +++++++++++++++++++++++------------------------ symrs.hh | 229 ++++++++----- types.hh | 18 +- 18 files changed, 2204 insertions(+), 2056 deletions(-) diff --git a/bdd_macro.hh b/bdd_macro.hh index 43136af..dee04e3 100644 --- a/bdd_macro.hh +++ b/bdd_macro.hh @@ -1,11 +1,11 @@ #ifndef __BDD_MACRO_HH__ #define __BDD_MACRO_HH__ -#define BDD_IFF(p,q) (!(p+q)+(p*q)) -#define BDD_TRUE (cuddMgr->bddOne()) -#define BDD_FALSE (cuddMgr->bddZero()) +#define BDD_IFF(p,q) (!(p+q)+(p*q)) +#define BDD_TRUE (cuddMgr->bddOne()) +#define BDD_FALSE (cuddMgr->bddZero()) -#define BDD_PRINT(t) ((t).PrintMinterm()) +#define BDD_PRINT(t) ((t).PrintMinterm()) #endif diff --git a/ctx_aut.cc b/ctx_aut.cc index a77e21c..1354b53 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -1,108 +1,111 @@ #include "ctx_aut.hh" -CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys) -{ - setOptions(opts); - this->parent_rctsys = parent_rctsys; +CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys) +{ + setOptions(opts); + this->parent_rctsys = parent_rctsys; } bool CtxAut::hasState(std::string name) { - if (states_names.find(name) == states_names.end()) - return false; - else - return true; + if (states_names.find(name) == states_names.end()) { + return false; + } + else { + return true; + } } State CtxAut::getStateID(std::string name) { - if (!hasState(name)) - { - FERROR("No such state: " << name); - } - return states_names[name]; + if (!hasState(name)) { + FERROR("No such state: " << name); + } + + return states_names[name]; } std::string CtxAut::getStateName(State state_id) { - assert(state_id < states_ids.size()); - return states_ids[state_id]; + assert(state_id < states_ids.size()); + return states_ids[state_id]; } void CtxAut::addState(std::string name) { - if (!hasState(name)) - { - State new_state_id = states_ids.size(); + if (!hasState(name)) { + State new_state_id = states_ids.size(); - VERB_L2("Adding state: " << name << " index=" << new_state_id); + VERB_L2("Adding state: " << name << " index=" << new_state_id); - states_ids.push_back(name); - states_names[name] = new_state_id; - - if (!init_state_defined) - { - setInitState(name); - } + states_ids.push_back(name); + states_names[name] = new_state_id; + + if (!init_state_defined) { + setInitState(name); } + } } void CtxAut::setInitState(std::string name) { - VERB_L2("Setting initial CA state: " << name); - State state_id = getStateID(name); - VERB_L2("Got initial CA state ID: index=" << state_id); - init_state_id = state_id; - init_state_defined = true; + VERB_L2("Setting initial CA state: " << name); + State state_id = getStateID(name); + VERB_L2("Got initial CA state ID: index=" << state_id); + init_state_id = state_id; + init_state_defined = true; } State CtxAut::getInitState(void) { - assert(init_state_defined); - return init_state_id; + assert(init_state_defined); + return init_state_id; } void CtxAut::printAutomaton(void) { - showStates(); - showTransitions(); + showStates(); + showTransitions(); } 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; + cout << "# Context Automaton States:" << endl; + cout << " = Init state: " << getStateName(init_state_id) << endl; + + for (const auto &s : states_ids) { + cout << " * " << s << endl; + } } -void CtxAut::pushContextEntity(Entity entity_id) +void CtxAut::pushContextEntity(Entity entity_id) { - tmpEntities.insert(entity_id); + tmpEntities.insert(entity_id); } -void CtxAut::addTransition(std::string srcStateName, std::string dstStateName) +void CtxAut::addTransition(std::string srcStateName, std::string dstStateName) { - VERB_L3("Saving transition"); - - CtxAutTransition new_transition; - - new_transition.src_state = getStateID(srcStateName); - new_transition.ctx = tmpEntities; - tmpEntities.clear(); - new_transition.dst_state = getStateID(dstStateName); - transitions.push_back(new_transition); + VERB_L3("Saving transition"); + + CtxAutTransition new_transition; + + new_transition.src_state = getStateID(srcStateName); + new_transition.ctx = tmpEntities; + tmpEntities.clear(); + new_transition.dst_state = getStateID(dstStateName); + transitions.push_back(new_transition); } 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; - } + 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; + } } /** EOF **/ diff --git a/ctx_aut.hh b/ctx_aut.hh index a2e2f6f..d5c143e 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -28,32 +28,38 @@ class RctSys; class CtxAut { friend class SymRS; - - public: - CtxAut(Options *opts, RctSys *parent_rctsys); - bool hasState(std::string name); - void addState(std::string stateName); - void setInitState(std::string stateName); - State getInitState(void); - State getStateID(std::string name); - std::string getStateName(State state_id); - void printAutomaton(void); - void showStates(void); - void addTransition(std::string srcStateName, std::string dstStateName); - void showTransitions(void); - void pushContextEntity(Entity entity_id); - void setOptions(Options *opts) { this->opts = opts; } - size_t statesCount(void) { return states_ids.size(); } - - private: - RctSys *parent_rctsys; - Options *opts; - StatesById states_ids; - StatesByName states_names; - State init_state_id; - bool init_state_defined; - Entities tmpEntities; - CtxAutTransitions transitions; + + public: + CtxAut(Options *opts, RctSys *parent_rctsys); + bool hasState(std::string name); + void addState(std::string stateName); + void setInitState(std::string stateName); + State getInitState(void); + State getStateID(std::string name); + std::string getStateName(State state_id); + void printAutomaton(void); + void showStates(void); + void addTransition(std::string srcStateName, std::string dstStateName); + void showTransitions(void); + void pushContextEntity(Entity entity_id); + void setOptions(Options *opts) + { + this->opts = opts; + } + size_t statesCount(void) + { + return states_ids.size(); + } + + private: + RctSys *parent_rctsys; + Options *opts; + StatesById states_ids; + StatesByName states_names; + State init_state_id; + bool init_state_defined; + Entities tmpEntities; + CtxAutTransitions transitions; }; #endif /* RS_CTX_AUT_HH */ diff --git a/formrsctl.cc b/formrsctl.cc index 45a9a5d..8f465e0 100644 --- a/formrsctl.cc +++ b/formrsctl.cc @@ -11,313 +11,300 @@ std::string BoolContexts::toStr(void) const { - if (oper == BCTX_PV) - { - return name; + if (oper == BCTX_PV) { + return name; + } + else if (oper == BCTX_TF) { + if (tf) { + return "true"; } - else if (oper == BCTX_TF) - { - if (tf) return "true"; - else return "false"; - } - else if (oper == BCTX_AND) - { - return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; - } - else if (oper == BCTX_OR) - { - return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; - } - else if (oper == BCTX_XOR) - { - return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; - } - else if (oper == BCTX_NOT) - { - return "~" + arg[0]->toStr(); - } - - else - { - return "??"; - assert(0); + else { + return "false"; } + } + else if (oper == BCTX_AND) { + return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; + } + else if (oper == BCTX_OR) { + return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; + } + else if (oper == BCTX_XOR) { + return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; + } + else if (oper == BCTX_NOT) { + return "~" + arg[0]->toStr(); + } + + else { + return "??"; + assert(0); + } } BDD BoolContexts::getBDD(const SymRS *srs) const { - if (oper == BCTX_PV) - { - return srs->encActStrEntity(name); - } - else if (oper == BCTX_TF) - { - if (tf) return srs->getBDDtrue(); - else return srs->getBDDfalse(); - } - else if (oper == BCTX_AND) - { - return arg[0]->getBDD(srs) * arg[1]->getBDD(srs); - } - else if (oper == BCTX_OR) - { - return arg[0]->getBDD(srs) + arg[1]->getBDD(srs); - } - else if (oper == BCTX_XOR) - { - return arg[0]->getBDD(srs) ^ arg[1]->getBDD(srs); - } - else if (oper == BCTX_NOT) - { - return !arg[0]->getBDD(srs); - } - else - { - assert(0); - FERROR("Undefined operator used in Boolean context definition. This should not happen."); - return srs->getBDDfalse(); - } + if (oper == BCTX_PV) { + return srs->encActStrEntity(name); + } + else if (oper == BCTX_TF) { + if (tf) { + return srs->getBDDtrue(); + } + else { + return srs->getBDDfalse(); + } + } + else if (oper == BCTX_AND) { + return arg[0]->getBDD(srs) * arg[1]->getBDD(srs); + } + else if (oper == BCTX_OR) { + return arg[0]->getBDD(srs) + arg[1]->getBDD(srs); + } + else if (oper == BCTX_XOR) { + return arg[0]->getBDD(srs) ^ arg[1]->getBDD(srs); + } + else if (oper == BCTX_NOT) { + return !arg[0]->getBDD(srs); + } + else { + assert(0); + FERROR("Undefined operator used in Boolean context definition. This should not happen."); + return srs->getBDDfalse(); + } } std::string FormRSCTL::toStr(void) const { - if (oper == RSCTL_PV) - { - return name; + if (oper == RSCTL_PV) { + return name; + } + else if (oper == RSCTL_TF) { + if (tf) { + return "true"; } - else if (oper == RSCTL_TF) - { - if (tf) return "true"; - else return "false"; - } - else if (oper == RSCTL_AND) - { - return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_OR) - { - return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_XOR) - { - return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_IMPL) - { - return "(" + arg[0]->toStr() + " IMPLIES " + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_NOT) - { - return "~" + arg[0]->toStr(); - } - else if (oper == RSCTL_EX) - { - return "EX(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_EG) - { - return "EG(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_EU) - { - return "EU(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_EF) - { - return "EF(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_AX) - { - return "AX(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_AG) - { - return "AG(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_AU) - { - return "AU(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_AF) - { - return "AF(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_EX_ACT) - { - return "E" + getActionsStr() + "X(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_EG_ACT) - { - return "E" + getActionsStr() + "G(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_EU_ACT) - { - return "E" + getActionsStr() + "U(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_EF_ACT) - { - return "E" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_AX_ACT) - { - return "A" + getActionsStr() + "X(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_AG_ACT) - { - return "A" + getActionsStr() + "G(" + arg[0]->toStr() + ")"; - } - else if (oper == RSCTL_AU_ACT) - { - return "A" + getActionsStr() + "U(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; - } - else if (oper == RSCTL_AF_ACT) - { - return "A" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; + else { + return "false"; } + } + else if (oper == RSCTL_AND) { + return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; + } + else if (oper == RSCTL_OR) { + return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; + } + else if (oper == RSCTL_XOR) { + return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; + } + else if (oper == RSCTL_IMPL) { + return "(" + arg[0]->toStr() + " IMPLIES " + arg[1]->toStr() + ")"; + } + else if (oper == RSCTL_NOT) { + return "~" + arg[0]->toStr(); + } + else if (oper == RSCTL_EX) { + return "EX(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_EG) { + return "EG(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_EU) { + return "EU(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; + } + else if (oper == RSCTL_EF) { + return "EF(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_AX) { + return "AX(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_AG) { + return "AG(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_AU) { + return "AU(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; + } + else if (oper == RSCTL_AF) { + return "AF(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_EX_ACT) { + return "E" + getActionsStr() + "X(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_EG_ACT) { + return "E" + getActionsStr() + "G(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_EU_ACT) { + return "E" + getActionsStr() + "U(" + arg[0]->toStr() + "," + arg[1]->toStr() + + ")"; + } + else if (oper == RSCTL_EF_ACT) { + return "E" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_AX_ACT) { + return "A" + getActionsStr() + "X(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_AG_ACT) { + return "A" + getActionsStr() + "G(" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTL_AU_ACT) { + return "A" + getActionsStr() + "U(" + arg[0]->toStr() + "," + arg[1]->toStr() + + ")"; + } + else if (oper == RSCTL_AF_ACT) { + return "A" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; + } - else - { - return "??"; - assert(0); - } + else { + return "??"; + assert(0); + } } bool FormRSCTL::hasOper(Oper op) const { - if (oper == op) - return true; - else - { - bool result = false; - if (arg[0] != nullptr) result = arg[0]->hasOper(op); - if (!result && arg[1] != nullptr) result = arg[1]->hasOper(op); - return result; + if (oper == op) { + return true; + } + else { + bool result = false; + + if (arg[0] != nullptr) { + result = arg[0]->hasOper(op); } + + if (!result && arg[1] != nullptr) { + result = arg[1]->hasOper(op); + } + + return result; + } } void FormRSCTL::encodeEntities(const SymRS *srs) { - if (RSCTL_COND_1ARG(oper)) - { - arg[0]->encodeEntities(srs); - } - else if (RSCTL_COND_2ARG(oper)) - { - arg[0]->encodeEntities(srs); - arg[1]->encodeEntities(srs); - } - else if (oper == RSCTL_PV) - { - bdd = new BDD(srs->encEntity(name)); - } + if (RSCTL_COND_1ARG(oper)) { + arg[0]->encodeEntities(srs); + } + else if (RSCTL_COND_2ARG(oper)) { + arg[0]->encodeEntities(srs); + arg[1]->encodeEntities(srs); + } + else if (oper == RSCTL_PV) { + bdd = new BDD(srs->encEntity(name)); + } } bool FormRSCTL::isERSCTL(void) const { - if (oper == RSCTL_PV) - { - return true; + if (oper == RSCTL_PV) { + return true; + } + + if (oper == RSCTL_NOT) { + if (arg[0]->getOper() == RSCTL_PV || arg[0]->getOper() == RSCTL_TF) { + return true; } - - if (oper == RSCTL_NOT) - { - if (arg[0]->getOper() == RSCTL_PV || arg[0]->getOper() == RSCTL_TF) - return true; - else - return false; + else { + return false; } + } - if (RSCTL_COND_IS_UNIVERSAL(oper)) - { - return false; - } - - if (RSCTL_COND_1ARG(oper)) - { - return arg[0]->isERSCTL(); - } - - if (RSCTL_COND_2ARG(oper)) - { - return arg[0]->isERSCTL() && arg[1]->isERSCTL(); - } - - assert(0); - + if (RSCTL_COND_IS_UNIVERSAL(oper)) { return false; + } + + if (RSCTL_COND_1ARG(oper)) { + return arg[0]->isERSCTL(); + } + + if (RSCTL_COND_2ARG(oper)) { + return arg[0]->isERSCTL() && arg[1]->isERSCTL(); + } + + assert(0); + + return false; } std::string FormRSCTL::getActionsStr(void) const { - if (actions != nullptr) - { - std::string r = "[ "; - bool firstact = true; + if (actions != nullptr) { + std::string r = "[ "; + bool firstact = true; - for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); ++act) - { - if (!firstact) r += ","; - else firstact = false; - r += "{"; - bool firstent = true; - for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) - { - if (!firstent) r += ","; - else firstent = false; - r += *ent; - } - r += "}"; - } - r += " ]"; - return r; - } - else if (boolCtx != nullptr) - { - return "< " + boolCtx->toStr() + " >"; - } - else - { - FERROR("Context not specified. This should not happen."); - } + for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); + ++act) { + if (!firstact) { + r += ","; + } + else { + firstact = false; + } + + r += "{"; + bool firstent = true; + + for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) { + if (!firstent) { + r += ","; + } + else { + firstent = false; + } + + r += *ent; + } + + r += "}"; + } + + r += " ]"; + return r; + } + else if (boolCtx != nullptr) { + return "< " + boolCtx->toStr() + " >"; + } + else { + FERROR("Context not specified. This should not happen."); + } } void FormRSCTL::encodeActions(const SymRS *srs) { - if (RSCTL_COND_ACT(oper)) - { - if (actions_bdd != nullptr) forgetActionsBDD(); - actions_bdd = new BDD(srs->getBDDfalse()); - assert(actions != nullptr || boolCtx != nullptr); - assert(!(actions != nullptr && boolCtx != nullptr)); - if (actions != nullptr) - { - for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); ++act) - { - BDD single_action = srs->getBDDtrue(); - for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) - { - single_action *= srs->encActStrEntity(*ent); - } - single_action = srs->compContext(single_action); - *actions_bdd += single_action; - } - } - else if (boolCtx != nullptr) - { - *actions_bdd = boolCtx->getBDD(srs); - } - else - assert(0); + if (RSCTL_COND_ACT(oper)) { + if (actions_bdd != nullptr) { + forgetActionsBDD(); } - if (RSCTL_COND_1ARG(oper)) - { - arg[0]->encodeActions(srs); - } + actions_bdd = new BDD(srs->getBDDfalse()); + assert(actions != nullptr || boolCtx != nullptr); + assert(!(actions != nullptr && boolCtx != nullptr)); - if (RSCTL_COND_2ARG(oper)) - { - arg[0]->encodeActions(srs); - arg[1]->encodeActions(srs); + if (actions != nullptr) { + for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); + ++act) { + BDD single_action = srs->getBDDtrue(); + + for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) { + single_action *= srs->encActStrEntity(*ent); + } + + single_action = srs->compContext(single_action); + *actions_bdd += single_action; + } } + else if (boolCtx != nullptr) { + *actions_bdd = boolCtx->getBDD(srs); + } + else { + assert(0); + } + } + + if (RSCTL_COND_1ARG(oper)) { + arg[0]->encodeActions(srs); + } + + if (RSCTL_COND_2ARG(oper)) { + arg[0]->encodeActions(srs); + arg[1]->encodeActions(srs); + } } diff --git a/formrsctl.hh b/formrsctl.hh index eac1723..14990e7 100644 --- a/formrsctl.hh +++ b/formrsctl.hh @@ -19,7 +19,7 @@ #define RSCTL_PV 0 // propositional variable #define RSCTL_AND 1 #define RSCTL_OR 2 -#define RSCTL_XOR 3 +#define RSCTL_XOR 3 #define RSCTL_NOT 4 #define RSCTL_IMPL 5 #define RSCTL_EG 11 // Existential... @@ -41,12 +41,12 @@ #define RSCTL_TF 50 // true/false /* For Boolean contexts: */ -#define BCTX_PV 60 -#define BCTX_AND 61 -#define BCTX_OR 62 -#define BCTX_XOR 63 -#define BCTX_NOT 64 -#define BCTX_TF 70 +#define BCTX_PV 60 +#define BCTX_AND 61 +#define BCTX_OR 62 +#define BCTX_XOR 63 +#define BCTX_NOT 64 +#define BCTX_TF 70 #define RSCTL_COND_1ARG(a) ((a) == RSCTL_NOT || (a) == RSCTL_EG || (a) == RSCTL_EF || (a) == RSCTL_EX || (a) == RSCTL_AG || (a) == RSCTL_AF || (a) == RSCTL_AX || (a) == RSCTL_EG_ACT || (a) == RSCTL_EF_ACT || (a) == RSCTL_EX_ACT || (a) == RSCTL_AG_ACT || (a) == RSCTL_AF_ACT || (a) == RSCTL_AX_ACT) @@ -71,75 +71,82 @@ typedef vector ActionsVec_f; class BoolContexts { - Oper oper; - BoolContexts *arg[2]; - std::string name; - bool tf; - -public: - - BoolContexts(std::string varName) - { - oper = BCTX_PV; - name = varName; - arg[0] = nullptr; - arg[1] = nullptr; - } - - /** - * @brief Constructor for true/false. - * - * @param val value of the logical constant - */ - BoolContexts(bool val) { - oper = BCTX_TF; - tf = val; - arg[0] = nullptr; - arg[1] = nullptr; - } + Oper oper; + BoolContexts *arg[2]; + std::string name; + bool tf; - /** - * @brief Constructor for one-argument formula. - */ - BoolContexts(Oper op, BoolContexts *form1) { - assert(op == BCTX_NOT); - oper = op; - arg[0] = form1; - arg[1] = nullptr; - } + public: - /** - * @brief Constructor for two-argument formula. - */ - BoolContexts(Oper op, BoolContexts *form1, BoolContexts *form2) { - assert(BCTX_COND_2ARG(op)); - oper = op; - arg[0] = form1; - arg[1] = form2; - } - - ~BoolContexts() { - delete arg[0]; - delete arg[1]; - } - - std::string toStr(void) const; - - BDD getBDD(const SymRS *srs) const; - - Oper getOper(void) const { - assert(BCTX_IS_VALID(oper)); - return oper; - } - BoolContexts *getLeftSF(void) const { - assert(arg[0] != nullptr); - return arg[0]; - } - BoolContexts *getRightSF(void) const { - assert(BCTX_COND_2ARG(oper)); - assert(arg[1] != nullptr); - return arg[1]; - } + BoolContexts(std::string varName) + { + oper = BCTX_PV; + name = varName; + arg[0] = nullptr; + arg[1] = nullptr; + } + + /** + * @brief Constructor for true/false. + * + * @param val value of the logical constant + */ + BoolContexts(bool val) + { + oper = BCTX_TF; + tf = val; + arg[0] = nullptr; + arg[1] = nullptr; + } + + /** + * @brief Constructor for one-argument formula. + */ + BoolContexts(Oper op, BoolContexts *form1) + { + assert(op == BCTX_NOT); + oper = op; + arg[0] = form1; + arg[1] = nullptr; + } + + /** + * @brief Constructor for two-argument formula. + */ + BoolContexts(Oper op, BoolContexts *form1, BoolContexts *form2) + { + assert(BCTX_COND_2ARG(op)); + oper = op; + arg[0] = form1; + arg[1] = form2; + } + + ~BoolContexts() + { + delete arg[0]; + delete arg[1]; + } + + std::string toStr(void) const; + + BDD getBDD(const SymRS *srs) const; + + Oper getOper(void) const + { + assert(BCTX_IS_VALID(oper)); + return oper; + } + BoolContexts *getLeftSF(void) const + { + assert(arg[0] != nullptr); + return arg[0]; + } + BoolContexts *getRightSF(void) const + { + assert(BCTX_COND_2ARG(oper)); + assert(arg[1] != nullptr); + return arg[1]; + } }; class FormRSCTL @@ -151,23 +158,24 @@ class FormRSCTL BDD *bdd; ActionsVec_f *actions; BDD *actions_bdd; - BoolContexts *boolCtx; -public: + BoolContexts *boolCtx; + public: /** * @brief Constructor for propositional variable. * * @param varName variable name used mostly for printing the variable. * @param varBDD the BDD describing the set where the variable holds. */ - FormRSCTL(std::string varName) { - oper = RSCTL_PV; - name = varName; - arg[0] = nullptr; - arg[1] = nullptr; - bdd = nullptr; - actions = nullptr; - actions_bdd = nullptr; - boolCtx = nullptr; + FormRSCTL(std::string varName) + { + oper = RSCTL_PV; + name = varName; + arg[0] = nullptr; + arg[1] = nullptr; + bdd = nullptr; + actions = nullptr; + actions_bdd = nullptr; + boolCtx = nullptr; } /** @@ -175,156 +183,173 @@ public: * * @param val value of the logical constant */ - FormRSCTL(bool val) { - oper = RSCTL_TF; - tf = val; - arg[0] = nullptr; - arg[1] = nullptr; - bdd = nullptr; - actions = nullptr; - actions_bdd = nullptr; - boolCtx = nullptr; + FormRSCTL(bool val) + { + oper = RSCTL_TF; + tf = val; + arg[0] = nullptr; + arg[1] = nullptr; + bdd = nullptr; + actions = nullptr; + actions_bdd = nullptr; + boolCtx = nullptr; } /** * @brief Constructor for two-argument formula. */ - FormRSCTL(Oper op, FormRSCTL *form1, FormRSCTL *form2) { - assert(RSCTL_COND_2ARG(op)); - assert(!RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = form2; - bdd = nullptr; - actions = nullptr; - actions_bdd = nullptr; - boolCtx = nullptr; + FormRSCTL(Oper op, FormRSCTL *form1, FormRSCTL *form2) + { + assert(RSCTL_COND_2ARG(op)); + assert(!RSCTL_COND_ACT(op)); + oper = op; + arg[0] = form1; + arg[1] = form2; + bdd = nullptr; + actions = nullptr; + actions_bdd = nullptr; + boolCtx = nullptr; } /** * @brief Constructor for two-argument formula with action restrictions. */ - FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1, FormRSCTL *form2) { - assert(acts != nullptr); - assert(RSCTL_COND_2ARG(op)); - assert(RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = form2; - bdd = nullptr; - actions = acts; - actions_bdd = nullptr; - boolCtx = nullptr; + FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1, FormRSCTL *form2) + { + assert(acts != nullptr); + assert(RSCTL_COND_2ARG(op)); + assert(RSCTL_COND_ACT(op)); + oper = op; + arg[0] = form1; + arg[1] = form2; + bdd = nullptr; + actions = acts; + actions_bdd = nullptr; + boolCtx = nullptr; } - /** - * @brief Constructor for two-argument formula with Boolean context restrictions. - */ - FormRSCTL(Oper op, BoolContexts *bctx, FormRSCTL *form1, FormRSCTL *form2) { - assert(bctx != nullptr); - assert(RSCTL_COND_2ARG(op)); - assert(RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = form2; - bdd = nullptr; - actions = nullptr; - actions_bdd = nullptr; - boolCtx = bctx; - } + /** + * @brief Constructor for two-argument formula with Boolean context restrictions. + */ + FormRSCTL(Oper op, BoolContexts *bctx, FormRSCTL *form1, FormRSCTL *form2) + { + assert(bctx != nullptr); + assert(RSCTL_COND_2ARG(op)); + assert(RSCTL_COND_ACT(op)); + oper = op; + arg[0] = form1; + arg[1] = form2; + bdd = nullptr; + actions = nullptr; + actions_bdd = nullptr; + boolCtx = bctx; + } /** * @brief Constructor for one-argument formula. */ - FormRSCTL(Oper op, FormRSCTL *form1) { - assert(RSCTL_COND_1ARG(op)); - assert(!RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = nullptr; - bdd = nullptr; - actions = nullptr; - actions_bdd = nullptr; - boolCtx = nullptr; + FormRSCTL(Oper op, FormRSCTL *form1) + { + assert(RSCTL_COND_1ARG(op)); + assert(!RSCTL_COND_ACT(op)); + oper = op; + arg[0] = form1; + arg[1] = nullptr; + bdd = nullptr; + actions = nullptr; + actions_bdd = nullptr; + boolCtx = nullptr; } /** * @brief Constructor for one-argument formula with action restrictions. */ - FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1) { - assert(acts != nullptr); - assert(RSCTL_COND_1ARG(op)); - assert(RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = nullptr; - bdd = nullptr; - actions = acts; - actions_bdd = nullptr; - boolCtx = nullptr; + FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1) + { + assert(acts != nullptr); + assert(RSCTL_COND_1ARG(op)); + assert(RSCTL_COND_ACT(op)); + oper = op; + arg[0] = form1; + arg[1] = nullptr; + bdd = nullptr; + actions = acts; + actions_bdd = nullptr; + boolCtx = nullptr; } - /** - * @brief Constructor for one-argument formula with Boolean context restrictions. - */ - FormRSCTL(Oper op, BoolContexts *bctx, FormRSCTL *form1) { - assert(bctx != nullptr); - assert(RSCTL_COND_1ARG(op)); - assert(RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = nullptr; - bdd = nullptr; - actions = nullptr; - actions_bdd = nullptr; - boolCtx = bctx; - } + /** + * @brief Constructor for one-argument formula with Boolean context restrictions. + */ + FormRSCTL(Oper op, BoolContexts *bctx, FormRSCTL *form1) + { + assert(bctx != nullptr); + assert(RSCTL_COND_1ARG(op)); + assert(RSCTL_COND_ACT(op)); + oper = op; + arg[0] = form1; + arg[1] = nullptr; + bdd = nullptr; + actions = nullptr; + actions_bdd = nullptr; + boolCtx = bctx; + } /** * @brief Destructor. */ - ~FormRSCTL() { - delete arg[0]; - delete arg[1]; - delete bdd; - delete actions; - delete actions_bdd; - delete boolCtx; + ~FormRSCTL() + { + delete arg[0]; + delete arg[1]; + delete bdd; + delete actions; + delete actions_bdd; + delete boolCtx; } std::string toStr(void) const; bool hasOper(Oper op) const; - const BDD *getBDD(void) const { - assert(oper == RSCTL_PV); - assert(bdd != nullptr); - return bdd; + const BDD *getBDD(void) const + { + assert(oper == RSCTL_PV); + assert(bdd != nullptr); + return bdd; } - const BDD *getActionsBDD(void) const { - assert(RSCTL_COND_ACT(oper)); - assert(actions_bdd != nullptr); - return actions_bdd; + const BDD *getActionsBDD(void) const + { + assert(RSCTL_COND_ACT(oper)); + assert(actions_bdd != nullptr); + return actions_bdd; } - Oper getOper(void) const { - assert(RSCTL_IS_VALID(oper)); - return oper; + Oper getOper(void) const + { + assert(RSCTL_IS_VALID(oper)); + return oper; } - FormRSCTL *getLeftSF(void) const { - assert(arg[0] != nullptr); - return arg[0]; + FormRSCTL *getLeftSF(void) const + { + assert(arg[0] != nullptr); + return arg[0]; } - FormRSCTL *getRightSF(void) const { - assert(RSCTL_COND_2ARG(oper)); - assert(arg[1] != nullptr); - return arg[1]; + FormRSCTL *getRightSF(void) const + { + assert(RSCTL_COND_2ARG(oper)); + assert(arg[1] != nullptr); + return arg[1]; } std::string getActionsStr(void) const; - bool getTF(void) const { - assert(oper == RSCTL_TF); - return tf; + bool getTF(void) const + { + assert(oper == RSCTL_TF); + return tf; } void encodeEntities(const SymRS *srs); void encodeActions(const SymRS *srs); - void forgetActionsBDD(void) { - if (actions_bdd != nullptr) delete actions_bdd; + void forgetActionsBDD(void) + { + if (actions_bdd != nullptr) { + delete actions_bdd; + } } bool isERSCTL(void) const; }; diff --git a/macro.hh b/macro.hh index dc44207..27934c8 100644 --- a/macro.hh +++ b/macro.hh @@ -7,8 +7,8 @@ /* Fatal error */ #define FERROR(s) \ { \ - std::cerr << "EE: " << __FILE__ << " (function " << __func__ << "), line " << __LINE__ << ": " << s << std::endl; \ - exit(1); \ + std::cerr << "EE: " << __FILE__ << " (function " << __func__ << "), line " << __LINE__ << ": " << s << std::endl; \ + exit(1); \ } #define WARNING(s) \ { \ @@ -18,25 +18,25 @@ #define VERB(s) \ assert(opts != nullptr); \ if (opts->verbose > 0) { \ - std::cerr << "ii VERBOSE(1): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ + std::cerr << "ii VERBOSE(1): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ } #define VERB_L2(s) \ assert(opts != nullptr); \ if (opts->verbose > 1) { \ - std::cerr << "ii VERBOSE(2): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ + std::cerr << "ii VERBOSE(2): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ } #define VERB_L3(s) \ assert(opts != nullptr); \ if (opts->verbose > 2) { \ - std::cerr << "ii VERBOSE(3): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ + std::cerr << "ii VERBOSE(3): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ } #define VERB_LN(n,s) \ assert(opts != nullptr); \ if (opts->verbose >= (n)) { \ - std::cerr << "ii VERBOSE(" << (n) << "): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ + std::cerr << "ii VERBOSE(" << (n) << "): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ } #endif diff --git a/main.cc b/main.cc index 25b3aa8..bba2658 100644 --- a/main.cc +++ b/main.cc @@ -10,236 +10,249 @@ int main(int argc, char **argv) { - rsin_driver driver; + rsin_driver driver; - Options *opts = new Options; - driver.setOptions(opts); + Options *opts = new Options; + driver.setOptions(opts); - bool show_reactions = false; - bool rstl_model_checking = false; - bool reach_states = false; - bool reach_states_succ = false; - bool bmc = true; - bool benchmarking = false; - bool usage_error = false; - bool print_parsed_sys = false; + bool show_reactions = false; + bool rstl_model_checking = false; + bool reach_states = false; + bool reach_states_succ = false; + bool bmc = true; + bool benchmarking = false; + bool usage_error = false; + bool print_parsed_sys = false; - static struct option long_options[] = - { - {"trace-parsing", no_argument, 0, 0 }, - {"trace-scanning", no_argument, 0, 0 }, - {0, 0, 0, 0 } - }; + static struct option long_options[] = { + {"trace-parsing", no_argument, 0, 0 }, + {"trace-scanning", no_argument, 0, 0 }, + {0, 0, 0, 0 } + }; - int c; - int option_index = 0; + int c; + int option_index = 0; - while ((c = getopt_long(argc, argv, "cbBmpPrsStTvxzh", long_options, &option_index)) != -1) - { - switch (c) { - case 0: - printf("option %s", long_options[option_index].name); - if (optarg) - printf(" with arg %s", optarg); - printf("\n"); + while ((c = getopt_long(argc, argv, "cbBmpPrsStTvxzh", long_options, + &option_index)) != -1) { + switch (c) { + case 0: + printf("option %s", long_options[option_index].name); - if (strcmp(long_options[option_index].name, "trace-parsing")) - driver.trace_parsing = true; - else if (strcmp(long_options[option_index].name, "trace-scanning")) - driver.trace_scanning = true; - - break; - //case 'b': - // printf("-b with %s\n", optarg); - // break; - case 'b': - bmc = false; - break; - case 'p': - opts->show_progress = true; - break; - case 'P': - print_parsed_sys = true; - break; - case 'r': - show_reactions = true; - break; - case 'c': - rstl_model_checking = true; - break; - case 'm': - opts->measure = true; - break; - case 'B': - benchmarking = true; - opts->measure = true; - break; - case 's': - reach_states = true; - break; - case 't': - reach_states_succ = true; - break; - case 'v': - opts->verbose++; - break; - case 'x': - opts->part_tr_rel = true; - break; - case 'z': - opts->reorder_reach = true; - opts->reorder_trans = true; - break; - case 'h': - usage_error = true; - break; - default: - usage_error = true; - break; + if (optarg) { + printf(" with arg %s", optarg); } - } - - std::string inputfile; - if (optind < argc) - { - inputfile = argv[optind]; - } - else - { - cout << "Missing input file" << endl; + + printf("\n"); + + if (strcmp(long_options[option_index].name, "trace-parsing")) { + driver.trace_parsing = true; + } + else if (strcmp(long_options[option_index].name, "trace-scanning")) { + driver.trace_scanning = true; + } + + break; + + //case 'b': + // printf("-b with %s\n", optarg); + // break; + case 'b': + bmc = false; + break; + + case 'p': + opts->show_progress = true; + break; + + case 'P': + print_parsed_sys = true; + break; + + case 'r': + show_reactions = true; + break; + + case 'c': + rstl_model_checking = true; + break; + + case 'm': + opts->measure = true; + break; + + case 'B': + benchmarking = true; + opts->measure = true; + break; + + case 's': + reach_states = true; + break; + + case 't': + reach_states_succ = true; + break; + + case 'v': + opts->verbose++; + break; + + case 'x': + opts->part_tr_rel = true; + break; + + case 'z': + opts->reorder_reach = true; + opts->reorder_trans = true; + break; + + case 'h': usage_error = true; + break; + + default: + usage_error = true; + break; + } + } + + std::string inputfile; + + if (optind < argc) { + inputfile = argv[optind]; + } + else { + cout << "Missing input file" << endl; + usage_error = true; + } + + if (usage_error) { + print_help(std::string(argv[0])); + return 100; + } + + if (!(reach_states || reach_states_succ || rstl_model_checking + || show_reactions || print_parsed_sys)) { + FERROR("No task specified: -c, -P, -r, or -s needs to be used"); + } + + if (opts->verbose > 0) { + cout << "Verbose level: " << opts->verbose << endl; + } + + VERB("Parsing " << inputfile); + + if (driver.parse(inputfile)) { + FERROR("Parse error"); + } + + // + // Here we retrieve the reaction system from the parser + // + // We decide which RS will be used at the parser level. + // This decision depends on whether we use concentrations, + // context automaton, etc. + // + auto rs = *driver.getReactionSystem(); + + rs.setOptions(opts); // these need to be passed to the driver + + if (show_reactions) { + rs.showReactions(); + } + + if (print_parsed_sys) { + rs.printSystem(); + } + + if (reach_states || reach_states_succ || rstl_model_checking) { + SymRS srs(&rs, opts); + + ModelChecker mc(&srs, opts); + + if (reach_states) { + mc.printReach(); } - if (usage_error) - { - print_help(std::string(argv[0])); - return 100; + if (reach_states_succ) { + mc.printReachWithSucc(); } - if (!(reach_states || reach_states_succ || rstl_model_checking || show_reactions || print_parsed_sys)) - { - FERROR("No task specified: -c, -P, -r, or -s needs to be used"); + if (rstl_model_checking) { + if (bmc) { + cout << "Using BDD-based Bounded Model Checking" << endl; + mc.checkRSCTL(driver.getFormRSCTL()); + } + else { + mc.checkRSCTLfull(driver.getFormRSCTL()); + } } + } + + if (opts->measure) { + cout << endl << std::setprecision(4) + << "Encoding time: " << opts->enc_time << " sec" << endl + << "Verification time: " << opts->ver_time << " sec" << endl + << "Encoding memory: " << opts->enc_mem << " MB" << endl + << "Memory (total): " << opts->ver_mem << " MB" << endl + << "TOTAL time: " << opts->enc_time + opts->ver_time << " sec" << endl; + + if (benchmarking) { + cout << std::setprecision(4) + << "STAT; " << opts->enc_time + << " ; " << opts->ver_time + << " ; " << opts->enc_mem + << " ; " << opts->ver_mem + << " ; " << opts->enc_time + opts->ver_time << endl; - if (opts->verbose > 0) - { - cout << "Verbose level: " << opts->verbose << endl; } + } - VERB("Parsing " << inputfile); + delete opts; - if (driver.parse(inputfile)) - { - FERROR("Parse error"); - } - - // - // Here we retrieve the reaction system from the parser - // - // We decide which RS will be used at the parser level. - // This decision depends on whether we use concentrations, - // context automaton, etc. - // - auto rs = *driver.getReactionSystem(); - - rs.setOptions(opts); // these need to be passed to the driver - - if (show_reactions) - rs.showReactions(); - - if (print_parsed_sys) - rs.printSystem(); - - if (reach_states || reach_states_succ || rstl_model_checking) - { - SymRS srs(&rs, opts); - - ModelChecker mc(&srs, opts); - - if (reach_states) - { - mc.printReach(); - } - if (reach_states_succ) - { - mc.printReachWithSucc(); - } - - if (rstl_model_checking) - { - if (bmc) - { - cout << "Using BDD-based Bounded Model Checking" << endl; - mc.checkRSCTL(driver.getFormRSCTL()); - } - else - { - mc.checkRSCTLfull(driver.getFormRSCTL()); - } - } - } - - if (opts->measure) - { - cout << endl << std::setprecision(4) - << "Encoding time: " << opts->enc_time << " sec" << endl - << "Verification time: " << opts->ver_time << " sec" << endl - << "Encoding memory: " << opts->enc_mem << " MB" << endl - << "Memory (total): " << opts->ver_mem << " MB" << endl - << "TOTAL time: " << opts->enc_time + opts->ver_time << " sec" << endl; - if (benchmarking) - { - cout << std::setprecision(4) - << "STAT; " << opts->enc_time - << " ; " << opts->ver_time - << " ; " << opts->enc_mem - << " ; " << opts->ver_mem - << " ; " << opts->enc_time+opts->ver_time << endl; - - } - } - - delete opts; - - return 0; + return 0; } void print_help(std::string path_str) { - cout << endl - << " ------------------------------------" << endl - << " -- Reaction Systems Model Checker --" << endl - << " ------------------------------------" << endl - << endl - << " Version: " << VERSION << endl - << " Contact: " << AUTHOR << endl - << endl + cout << endl + << " ------------------------------------" << endl + << " -- Reaction Systems Model Checker --" << endl + << " ------------------------------------" << endl + << endl + << " Version: " << VERSION << endl + << " Contact: " << AUTHOR << endl + << endl #ifndef PUBLIC_RELEASE - << " ###################################" << endl - << " THIS IS A PRIVATE VERSION OF RSMC " << endl - << " PLEASE, DO NOT DISTRIBUTE " << endl - << " ###################################" << endl - << endl + << " ###################################" << endl + << " THIS IS A PRIVATE VERSION OF RSMC " << endl + << " PLEASE, DO NOT DISTRIBUTE " << endl + << " ###################################" << endl + << endl #endif - << " Usage: " << path_str << " [options] " << endl << endl - << " TASKS:" << endl - << " -c -- perform RSCTL model checking" << endl - //<< " -f K -- generate SMT input for the depth K" << endl - << " -P -- print parsed system" << endl - << " -r -- print reactions" << endl - << " -s -- print the set of all the reachable states" << endl - << " -t -- print the set of all the reachable states with their successors" << endl - << endl << " OTHER:" << endl - << " -b -- disable bounded model checking (BMC) heuristic" << endl - << " -x -- use partitioned transition relation (may use less memory)" << endl - << " -z -- use reordering of the BDD variables" << endl - << " -v -- verbose (can be used more than once to increase verbosity)" << endl - << " -p -- show progress (where possible)" << endl - << endl - << " Benchmarking options:" << endl - << " -m -- measure and display time and memory usage" << endl - << " -B -- display an easy to parse summary (enables -m)" << endl - << endl; + << " Usage: " << path_str << " [options] " << endl << endl + << " TASKS:" << endl + << " -c -- perform RSCTL model checking" << endl + //<< " -f K -- generate SMT input for the depth K" << endl + << " -P -- print parsed system" << endl + << " -r -- print reactions" << endl + << " -s -- print the set of all the reachable states" << endl + << " -t -- print the set of all the reachable states with their successors" + << endl + << endl << " OTHER:" << endl + << " -b -- disable bounded model checking (BMC) heuristic" << endl + << " -x -- use partitioned transition relation (may use less memory)" << + endl + << " -z -- use reordering of the BDD variables" << endl + << " -v -- verbose (can be used more than once to increase verbosity)" << + endl + << " -p -- show progress (where possible)" << endl + << endl + << " Benchmarking options:" << endl + << " -m -- measure and display time and memory usage" << endl + << " -B -- display an easy to parse summary (enables -m)" << endl + << endl; } /** EOF **/ diff --git a/mc.cc b/mc.cc index 2ec8873..80b5f2c 100644 --- a/mc.cc +++ b/mc.cc @@ -1,572 +1,567 @@ #include "mc.hh" ModelChecker::ModelChecker(SymRS *srs, Options *opts) - : using_ctx_aut(false) + : using_ctx_aut(false) { - this->srs = srs; - this->opts = opts; - - cuddMgr = srs->getCuddMgr(); - - initStates = srs->getEncInitStates(); - - totalStateVars = srs->getTotalStateVars(); - - pv = srs->getEncPV(); - pv_succ = srs->getEncPVsucc(); - pv_E = srs->getEncPV_E(); - pv_succ_E = srs->getEncPVsucc_E(); - pv_act_E = srs->getEncPVact_E(); + this->srs = srs; + this->opts = opts; - // - // Transition relations - // - // trp -- partitioned TR - // trm -- monolithic TR - // - // If we use trp, then trm is nullptr (same for trm) - // - trp = srs->getEncPartTrans(); - if (trp == nullptr) - trp_size = 0; - else - trp_size = trp->size(); - trm = srs->getEncMonoTrans(); - - if (srs->usingContextAutomaton()) - { - using_ctx_aut = true; - pv_ca = srs->getEncCtxAutPV(); - pv_ca_succ = srs->getEncCtxAutPVsucc(); - pv_ca_E = srs->getEncCtxAutPV_E(); - pv_ca_succ_E = srs->getEncCtxAutPVsucc_E(); - } - else - { - using_ctx_aut = false; - pv_ca = nullptr; - pv_ca_succ = nullptr; - pv_ca_E = nullptr; - pv_ca_succ_E = nullptr; - } - - // Initialise the set of reachable states - reach = nullptr; + cuddMgr = srs->getCuddMgr(); + + initStates = srs->getEncInitStates(); + + totalStateVars = srs->getTotalStateVars(); + + pv = srs->getEncPV(); + pv_succ = srs->getEncPVsucc(); + pv_E = srs->getEncPV_E(); + pv_succ_E = srs->getEncPVsucc_E(); + pv_act_E = srs->getEncPVact_E(); + + // + // Transition relations + // + // trp -- partitioned TR + // trm -- monolithic TR + // + // If we use trp, then trm is nullptr (same for trm) + // + trp = srs->getEncPartTrans(); + + if (trp == nullptr) { + trp_size = 0; + } + else { + trp_size = trp->size(); + } + + trm = srs->getEncMonoTrans(); + + if (srs->usingContextAutomaton()) { + using_ctx_aut = true; + pv_ca = srs->getEncCtxAutPV(); + pv_ca_succ = srs->getEncCtxAutPVsucc(); + pv_ca_E = srs->getEncCtxAutPV_E(); + pv_ca_succ_E = srs->getEncCtxAutPVsucc_E(); + } + else { + using_ctx_aut = false; + pv_ca = nullptr; + pv_ca_succ = nullptr; + pv_ca_E = nullptr; + pv_ca_succ_E = nullptr; + } + + // Initialise the set of reachable states + reach = nullptr; } inline BDD ModelChecker::getSucc(const BDD &states) { - BDD q = BDD_TRUE; + BDD q = BDD_TRUE; - VERB_L2("Computing successors"); - if (opts->part_tr_rel) - { - for (unsigned int i = 0; i < trp_size; ++i) - { - q *= states * (*trp)[i]; - } + VERB_L2("Computing successors"); + + if (opts->part_tr_rel) { + for (unsigned int i = 0; i < trp_size; ++i) { + q *= states * (*trp)[i]; } - else - { - q *= states * *trm; - } - q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); - q = q.ExistAbstract(*pv_act_E); - - return q; + } + else { + q *= states * *trm; + } + + q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); + q = q.ExistAbstract(*pv_act_E); + + return q; } inline BDD ModelChecker::getPreE(const BDD &states) { - BDD q = BDD_TRUE; - VERB_L2("Computing preE"); - BDD x = states.SwapVariables(*pv, *pv_succ); - if (opts->part_tr_rel) - { - for (unsigned int i = 0; i < trp_size; ++i) - q *= x * (*trp)[i]; + BDD q = BDD_TRUE; + VERB_L2("Computing preE"); + BDD x = states.SwapVariables(*pv, *pv_succ); + + if (opts->part_tr_rel) { + for (unsigned int i = 0; i < trp_size; ++i) { + q *= x * (*trp)[i]; } - else - { - q *= x * *trm; - } - q = q.ExistAbstract(*pv_succ_E); - q = q.ExistAbstract(*pv_act_E); - return q; + } + else { + q *= x * *trm; + } + + q = q.ExistAbstract(*pv_succ_E); + q = q.ExistAbstract(*pv_act_E); + return q; } inline BDD ModelChecker::getPreEctx(const BDD &states, const BDD *contexts) { - BDD q = BDD_TRUE; - VERB_L2("Computing (context-restricted) preE"); - BDD x = states.SwapVariables(*pv, *pv_succ); - if (opts->part_tr_rel) - { - for (unsigned int i = 0; i < trp_size; ++i) - q *= x * (*trp)[i] * *contexts; + BDD q = BDD_TRUE; + VERB_L2("Computing (context-restricted) preE"); + BDD x = states.SwapVariables(*pv, *pv_succ); + + if (opts->part_tr_rel) { + for (unsigned int i = 0; i < trp_size; ++i) { + q *= x * (*trp)[i] * *contexts; } - else - { - q *= x * *trm * *contexts; - } - q = q.ExistAbstract(*pv_succ_E); - q = q.ExistAbstract(*pv_act_E); - return q; + } + else { + q *= x * *trm * *contexts; + } + + q = q.ExistAbstract(*pv_succ_E); + q = q.ExistAbstract(*pv_act_E); + return q; } void ModelChecker::dropCtxAutStatePart(BDD &states) { - states = states.ExistAbstract(*pv_ca_E); + states = states.ExistAbstract(*pv_ca_E); } void ModelChecker::printReach(void) { - VERB_LN(2, "Printing/generating reachable states"); - - if (opts->measure) - opts->ver_time = cpuTime(); + VERB_LN(2, "Printing/generating reachable states"); - assert(initStates != nullptr); - - BDD *reach = new BDD(*initStates); - BDD reach_p = BDD_FALSE; + if (opts->measure) { + opts->ver_time = cpuTime(); + } - unsigned int k = 0; + assert(initStates != nullptr); - while (*reach != reach_p) - { - if (opts->show_progress) - { - cout << "\rIteration " << ++k << flush; - } - reach_p = *reach; - *reach += getSucc(*reach); + BDD *reach = new BDD(*initStates); + BDD reach_p = BDD_FALSE; + + unsigned int k = 0; + + while (*reach != reach_p) { + if (opts->show_progress) { + cout << "\rIteration " << ++k << flush; } - - dropCtxAutStatePart(*reach); - srs->printDecodedRctSysStates(*reach); + reach_p = *reach; + *reach += getSucc(*reach); + } - cleanup(); + dropCtxAutStatePart(*reach); - if (opts->measure) - { - opts->ver_time = cpuTime() - opts->ver_time; - opts->ver_mem = memUsed(); - } + srs->printDecodedRctSysStates(*reach); + + cleanup(); + + if (opts->measure) { + opts->ver_time = cpuTime() - opts->ver_time; + opts->ver_mem = memUsed(); + } } void ModelChecker::printReachWithSucc(void) { - VERB_LN(2, "Printing/generating reachable states (with successors)"); - - BDD *reach = new BDD(*initStates); - BDD reach_p = cuddMgr->bddZero(); + VERB_LN(2, "Printing/generating reachable states (with successors)"); - while (*reach != reach_p) - { - reach_p = *reach; - BDD newStates = getSucc(*reach) - *reach; - *reach += newStates; + BDD *reach = new BDD(*initStates); + BDD reach_p = cuddMgr->bddZero(); - } + while (*reach != reach_p) { + reach_p = *reach; + BDD newStates = getSucc(*reach) - *reach; + *reach += newStates; - BDD unproc = *reach; - while (!unproc.IsZero()) - { - BDD t; - t = unproc.PickOneMinterm(*pv); - cout << "Successors of " << srs->decodedRctSysStateToStr(t) << ":" << endl; - srs->printDecodedRctSysStates(getSucc(t)); - unproc -= t; - } - - cleanup(); + } + + BDD unproc = *reach; + + while (!unproc.IsZero()) { + BDD t; + t = unproc.PickOneMinterm(*pv); + cout << "Successors of " << srs->decodedRctSysStateToStr(t) << ":" << endl; + srs->printDecodedRctSysStates(getSucc(t)); + unproc -= t; + } + + cleanup(); } bool ModelChecker::checkReach(const Entities testState) { - if (opts->measure) - opts->ver_time = cpuTime(); + if (opts->measure) { + opts->ver_time = cpuTime(); + } - BDD st = srs->getEncState(testState); + BDD st = srs->getEncState(testState); - BDD reach = *initStates; - BDD reach_p = cuddMgr->bddZero(); + BDD reach = *initStates; + BDD reach_p = cuddMgr->bddZero(); - while (reach != reach_p) - { - if (reach * st != cuddMgr->bddZero()) - { - cleanup(); - return true; - } - reach_p = reach; - reach += getSucc(reach); + while (reach != reach_p) { + if (reach * st != cuddMgr->bddZero()) { + cleanup(); + return true; } - cleanup(); + reach_p = reach; + reach += getSucc(reach); + } - if (opts->measure) - { - opts->ver_time = cpuTime() - opts->ver_time; - opts->ver_mem = memUsed(); - } + cleanup(); - return false; + if (opts->measure) { + opts->ver_time = cpuTime() - opts->ver_time; + opts->ver_mem = memUsed(); + } + + return false; } BDD ModelChecker::getStatesRSCTL(const FormRSCTL *form) { - assert(reach != nullptr); - Oper oper = form->getOper(); - if (oper == RSCTL_PV) - { - return *form->getBDD() * *reach; - } - else if (oper == RSCTL_TF) - { - if (form->getTF() == true) - return *reach; - else - return cuddMgr->bddZero(); - } - else if (oper == RSCTL_AND) - { - return getStatesRSCTL(form->getLeftSF()) * getStatesRSCTL(form->getRightSF()); - } - else if (oper == RSCTL_OR) - { - return getStatesRSCTL(form->getLeftSF()) + getStatesRSCTL(form->getRightSF()); - } - else if (oper == RSCTL_XOR) - { - return getStatesRSCTL(form->getLeftSF()) ^ getStatesRSCTL(form->getRightSF()); - } - else if (oper == RSCTL_IMPL) - { - return (!getStatesRSCTL(form->getLeftSF()) * *reach) + getStatesRSCTL(form->getRightSF()); - } - else if (oper == RSCTL_NOT) - { - return !getStatesRSCTL(form->getLeftSF()) * *reach; - } - else if (oper == RSCTL_EX) - { - return getPreE(getStatesRSCTL(form->getLeftSF())) * *reach; - } - else if (oper == RSCTL_EG) - { - return statesEG(getStatesRSCTL(form->getLeftSF())); - } - else if (oper == RSCTL_EU) - { - return statesEU( - getStatesRSCTL(form->getLeftSF()), - getStatesRSCTL(form->getRightSF()) - ); - } - else if (oper == RSCTL_EF) - { - return statesEF(getStatesRSCTL(form->getLeftSF())); - } - else if (oper == RSCTL_AX) - { - return !getPreE(!getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; - } - else if (oper == RSCTL_AG) - { - return !statesEF( - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; - } - else if (oper == RSCTL_AU) - { - BDD ng = !getStatesRSCTL(form->getRightSF()) * *reach; - BDD nf = !getStatesRSCTL(form->getLeftSF()) * *reach; + assert(reach != nullptr); + Oper oper = form->getOper(); - BDD x = !statesEU(ng, ng * nf) * *reach; - if (!x.IsZero()) - x = x * !statesEG(ng) * *reach; + if (oper == RSCTL_PV) { + return *form->getBDD() * *reach; + } + else if (oper == RSCTL_TF) { + if (form->getTF() == true) { + return *reach; + } + else { + return cuddMgr->bddZero(); + } + } + else if (oper == RSCTL_AND) { + return getStatesRSCTL(form->getLeftSF()) * getStatesRSCTL(form->getRightSF()); + } + else if (oper == RSCTL_OR) { + return getStatesRSCTL(form->getLeftSF()) + getStatesRSCTL(form->getRightSF()); + } + else if (oper == RSCTL_XOR) { + return getStatesRSCTL(form->getLeftSF()) ^ getStatesRSCTL(form->getRightSF()); + } + else if (oper == RSCTL_IMPL) { + return (!getStatesRSCTL(form->getLeftSF()) * *reach) + getStatesRSCTL( + form->getRightSF()); + } + else if (oper == RSCTL_NOT) { + return !getStatesRSCTL(form->getLeftSF()) * *reach; + } + else if (oper == RSCTL_EX) { + return getPreE(getStatesRSCTL(form->getLeftSF())) * *reach; + } + else if (oper == RSCTL_EG) { + return statesEG(getStatesRSCTL(form->getLeftSF())); + } + else if (oper == RSCTL_EU) { + return statesEU( + getStatesRSCTL(form->getLeftSF()), + getStatesRSCTL(form->getRightSF()) + ); + } + else if (oper == RSCTL_EF) { + return statesEF(getStatesRSCTL(form->getLeftSF())); + } + else if (oper == RSCTL_AX) { + return !getPreE(!getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + } + else if (oper == RSCTL_AG) { + return !statesEF( + !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + } + else if (oper == RSCTL_AU) { + BDD ng = !getStatesRSCTL(form->getRightSF()) * *reach; + BDD nf = !getStatesRSCTL(form->getLeftSF()) * *reach; - return x; - } - else if (oper == RSCTL_AF) - { - return !statesEG( - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; - } - /***** CONTEXT RESTRICTIONS: ******/ - else if (oper == RSCTL_EX_ACT) - { - return getPreEctx(getStatesRSCTL(form->getLeftSF()), form->getActionsBDD()) * *reach; - } - else if (oper == RSCTL_EG_ACT) - { - return statesEGctx(form->getActionsBDD(), getStatesRSCTL(form->getLeftSF())); /***** EG? *****/ - } - else if (oper == RSCTL_EU_ACT) - { - return statesEUctx( - form->getActionsBDD(), - getStatesRSCTL(form->getLeftSF()), - getStatesRSCTL(form->getRightSF()) - ); - } - else if (oper == RSCTL_EF_ACT) - { - return statesEFctx(form->getActionsBDD(), getStatesRSCTL(form->getLeftSF())); - } - else if (oper == RSCTL_AX_ACT) - { - return !getPreEctx(!getStatesRSCTL(form->getLeftSF()) * *reach, form->getActionsBDD()) * *reach; - } - else if (oper == RSCTL_AG_ACT) - { - return !statesEFctx(form->getActionsBDD(), - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; - } - else if (oper == RSCTL_AU_ACT) - { - BDD ng = !getStatesRSCTL(form->getRightSF()) * *reach; - BDD nf = !getStatesRSCTL(form->getLeftSF()) * *reach; + BDD x = !statesEU(ng, ng * nf) * *reach; - BDD x = !statesEUctx(form->getActionsBDD(), ng, ng * nf) * *reach; - if (!x.IsZero()) - x = x * !statesEGctx(form->getActionsBDD(), ng) * *reach; - - return x; - } - else if (oper == RSCTL_AF_ACT) - { - return !statesEGctx(form->getActionsBDD(), - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + if (!x.IsZero()) { + x = x * !statesEG(ng) * *reach; } - assert(0); // Should never happen - return BDD_FALSE; + return x; + } + else if (oper == RSCTL_AF) { + return !statesEG( + !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + } + /***** CONTEXT RESTRICTIONS: ******/ + else if (oper == RSCTL_EX_ACT) { + return getPreEctx(getStatesRSCTL(form->getLeftSF()), + form->getActionsBDD()) * *reach; + } + else if (oper == RSCTL_EG_ACT) { + return statesEGctx(form->getActionsBDD(), + getStatesRSCTL(form->getLeftSF())); /***** EG? *****/ + } + else if (oper == RSCTL_EU_ACT) { + return statesEUctx( + form->getActionsBDD(), + getStatesRSCTL(form->getLeftSF()), + getStatesRSCTL(form->getRightSF()) + ); + } + else if (oper == RSCTL_EF_ACT) { + return statesEFctx(form->getActionsBDD(), getStatesRSCTL(form->getLeftSF())); + } + else if (oper == RSCTL_AX_ACT) { + return !getPreEctx(!getStatesRSCTL(form->getLeftSF()) * *reach, + form->getActionsBDD()) * *reach; + } + else if (oper == RSCTL_AG_ACT) { + return !statesEFctx(form->getActionsBDD(), + !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + } + else if (oper == RSCTL_AU_ACT) { + BDD ng = !getStatesRSCTL(form->getRightSF()) * *reach; + BDD nf = !getStatesRSCTL(form->getLeftSF()) * *reach; + + BDD x = !statesEUctx(form->getActionsBDD(), ng, ng * nf) * *reach; + + if (!x.IsZero()) { + x = x * !statesEGctx(form->getActionsBDD(), ng) * *reach; + } + + return x; + } + else if (oper == RSCTL_AF_ACT) { + return !statesEGctx(form->getActionsBDD(), + !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + } + + assert(0); // Should never happen + return BDD_FALSE; } BDD ModelChecker::statesEG(const BDD &states) { - BDD x = states; - BDD x_p = cuddMgr->bddZero(); - while (x != x_p) - { - x_p = x; - x = x * getPreE(x); - } - return x; + BDD x = states; + BDD x_p = cuddMgr->bddZero(); + + while (x != x_p) { + x_p = x; + x = x * getPreE(x); + } + + return x; } BDD ModelChecker::statesEU(const BDD &statesA, const BDD &statesB) { - BDD x = statesA; - BDD x_p = *reach; - while (x != x_p) - { - x_p = x; - x = x + (statesA * getPreE(x)); - } - return x; + BDD x = statesA; + BDD x_p = *reach; + + while (x != x_p) { + x_p = x; + x = x + (statesA * getPreE(x)); + } + + return x; } BDD ModelChecker::statesEF(const BDD &states) { - BDD x = states; - BDD x_p = *reach; - while (x != x_p) - { - x_p = x; - x = x + (*reach * getPreE(x)); - } - return x; + BDD x = states; + BDD x_p = *reach; + + while (x != x_p) { + x_p = x; + x = x + (*reach * getPreE(x)); + } + + return x; } BDD ModelChecker::statesEGctx(const BDD *contexts, const BDD &states) { - BDD x = states; - BDD x_p = cuddMgr->bddZero(); - while (x != x_p) - { - x_p = x; - x = x * getPreEctx(x, contexts); - } - return x; + BDD x = states; + BDD x_p = cuddMgr->bddZero(); + + while (x != x_p) { + x_p = x; + x = x * getPreEctx(x, contexts); + } + + return x; } -BDD ModelChecker::statesEUctx(const BDD *contexts, const BDD &statesA, const BDD &statesB) +BDD ModelChecker::statesEUctx(const BDD *contexts, const BDD &statesA, + const BDD &statesB) { - BDD x = statesA; - BDD x_p = *reach; - while (x != x_p) - { - x_p = x; - x = x + (statesA * getPreEctx(x, contexts)); - } - return x; + BDD x = statesA; + BDD x_p = *reach; + + while (x != x_p) { + x_p = x; + x = x + (statesA * getPreEctx(x, contexts)); + } + + return x; } BDD ModelChecker::statesEFctx(const BDD *contexts, const BDD &states) { - BDD x = states; - BDD x_p = *reach; - while (x != x_p) - { - x_p = x; - x = x + (*reach * getPreEctx(x, contexts)); - } - return x; + BDD x = states; + BDD x_p = *reach; + + while (x != x_p) { + x_p = x; + x = x + (*reach * getPreEctx(x, contexts)); + } + + return x; } bool ModelChecker::checkRSCTL(FormRSCTL *form) { - if (form->isERSCTL()) - return checkRSCTLbmc(form); - else - return checkRSCTLfull(form); + if (form->isERSCTL()) { + return checkRSCTLbmc(form); + } + else { + return checkRSCTLfull(form); + } } bool ModelChecker::checkRSCTLfull(FormRSCTL *form) { - if (opts->measure) - opts->ver_time = cpuTime(); + if (opts->measure) { + opts->ver_time = cpuTime(); + } - assert(form != nullptr); + assert(form != nullptr); - bool result = false; + bool result = false; - VERB("Model checking for RSCTL formula: " << form->toStr()); + VERB("Model checking for RSCTL formula: " << form->toStr()); - VERB("Processing the formula: encoding entities"); - form->encodeEntities(srs); - VERB("Entities encoded"); + VERB("Processing the formula: encoding entities"); + form->encodeEntities(srs); + VERB("Entities encoded"); - VERB("Processing the formula: encoding actions/contexts"); - form->encodeActions(srs); - VERB("Contexts encoded"); + VERB("Processing the formula: encoding actions/contexts"); + form->encodeActions(srs); + VERB("Contexts encoded"); - assert(reach == nullptr); + assert(reach == nullptr); - reach = new BDD(*initStates); - BDD reach_p = cuddMgr->bddZero(); + reach = new BDD(*initStates); + BDD reach_p = cuddMgr->bddZero(); - VERB("Generating state space"); + VERB("Generating state space"); - unsigned int k = 0; + unsigned int k = 0; - while (*reach != reach_p) - { + while (*reach != reach_p) { - if (opts->show_progress) - { - cout << "\rIteration " << ++k << flush; - } - - if (opts->reorder_reach) - { - VERB_L2("Reordering") - Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); - } - - reach_p = *reach; - *reach += getSucc(*reach); + if (opts->show_progress) { + cout << "\rIteration " << ++k << flush; } - if (opts->show_progress) cout << endl; - - VERB("Checking the formula"); - - //if (*initStates * getStatesRSCTL(form) != cuddMgr->bddZero()) - if (*initStates * getStatesRSCTL(form) == *initStates) - { - result = true; - } - else - { - result = false; + if (opts->reorder_reach) { + VERB_L2("Reordering") + Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); } - cleanup(); + reach_p = *reach; + *reach += getSucc(*reach); + } - cout << "Formula " << form->toStr() << (result ? " holds" : " does not hold") << endl; + if (opts->show_progress) { + cout << endl; + } - if (opts->measure) - { - opts->ver_time = cpuTime() - opts->ver_time; - opts->ver_mem = memUsed(); - } + VERB("Checking the formula"); - return result; + //if (*initStates * getStatesRSCTL(form) != cuddMgr->bddZero()) + if (*initStates * getStatesRSCTL(form) == *initStates) { + result = true; + } + else { + result = false; + } + + cleanup(); + + cout << "Formula " << form->toStr() << (result ? " holds" : " does not hold") + << endl; + + if (opts->measure) { + opts->ver_time = cpuTime() - opts->ver_time; + opts->ver_mem = memUsed(); + } + + return result; } bool ModelChecker::checkRSCTLbmc(FormRSCTL *form) { - if (opts->measure) - opts->ver_time = cpuTime(); + if (opts->measure) { + opts->ver_time = cpuTime(); + } - assert(form != nullptr); + assert(form != nullptr); - if (!form->isERSCTL()) - { - FERROR("Formula " << form->toStr() << " is not syntactically an ERSCTL formula"); + if (!form->isERSCTL()) { + FERROR("Formula " << form->toStr() << + " is not syntactically an ERSCTL formula"); + } + + bool result = false; + + VERB("Bounded model checking for RSCTL formula: " << form->toStr()); + + VERB("Processing the formula: encoding entities"); + form->encodeEntities(srs); + VERB("Entities encoded"); + + VERB("Processing the formula: encoding actions/contexts"); + form->encodeActions(srs); + VERB("Contexts encoded"); + + assert(reach == nullptr); + + reach = new BDD(*initStates); + BDD reach_p = cuddMgr->bddZero(); + + unsigned int k = 0; + + while (*reach != reach_p) { + if (opts->show_progress) { + cout << "\rIteration " << ++k << flush; } - bool result = false; - - VERB("Bounded model checking for RSCTL formula: " << form->toStr()); - - VERB("Processing the formula: encoding entities"); - form->encodeEntities(srs); - VERB("Entities encoded"); - - VERB("Processing the formula: encoding actions/contexts"); - form->encodeActions(srs); - VERB("Contexts encoded"); - - assert(reach == nullptr); - - reach = new BDD(*initStates); - BDD reach_p = cuddMgr->bddZero(); - - unsigned int k = 0; - - while (*reach != reach_p) - { - if (opts->show_progress) - { - cout << "\rIteration " << ++k << flush; - } - - //if (*initStates * getStatesRSCTL(form) != cuddMgr->bddZero()) - if (*initStates * getStatesRSCTL(form) == *initStates) - { - result = true; - break; - } - - reach_p = *reach; - *reach += getSucc(*reach); + //if (*initStates * getStatesRSCTL(form) != cuddMgr->bddZero()) + if (*initStates * getStatesRSCTL(form) == *initStates) { + result = true; + break; } - if (opts->show_progress) cout << endl; + reach_p = *reach; + *reach += getSucc(*reach); + } - cleanup(); + if (opts->show_progress) { + cout << endl; + } - cout << "Formula " << form->toStr() << " " << (result ? "holds" : "does not hold") << endl; + cleanup(); - if (opts->measure) - { - opts->ver_time = cpuTime() - opts->ver_time; - opts->ver_mem = memUsed(); - } + cout << "Formula " << form->toStr() << " " << (result ? "holds" : + "does not hold") << endl; - return result; + if (opts->measure) { + opts->ver_time = cpuTime() - opts->ver_time; + opts->ver_mem = memUsed(); + } + + return result; } void ModelChecker::cleanup(void) { - delete reach; - reach = nullptr; + delete reach; + reach = nullptr; } /** EOF **/ \ No newline at end of file diff --git a/mc.hh b/mc.hh index 20d22fb..f6d7557 100644 --- a/mc.hh +++ b/mc.hh @@ -20,7 +20,7 @@ class ModelChecker SymRS *srs; Options *opts; Cudd *cuddMgr; - BDD *initStates; + BDD *initStates; vector *pv; vector *pv_succ; BDD *pv_E; @@ -29,21 +29,21 @@ class ModelChecker BDD *reach; vector *trp; BDD *trm; - - // Context Automaton - bool using_ctx_aut; - vector *pv_ca; - vector *pv_ca_succ; - BDD *pv_ca_E; - BDD *pv_ca_succ_E; - + + // Context Automaton + bool using_ctx_aut; + vector *pv_ca; + vector *pv_ca_succ; + BDD *pv_ca_E; + BDD *pv_ca_succ_E; + unsigned int trp_size; unsigned int totalStateVars; - + /** * @brief Abstracts away (in-place!) the context automaton states */ - void dropCtxAutStatePart(BDD &states); + void dropCtxAutStatePart(BDD &states); BDD getSucc(const BDD &states); BDD getPreE(const BDD &states); @@ -57,7 +57,7 @@ class ModelChecker BDD statesEFctx(const BDD *contexts, const BDD &states); void cleanup(void); -public: + public: ModelChecker(SymRS *srs, Options *opts); void printReach(void); diff --git a/memtime.hh b/memtime.hh index 1bcef66..fcc4a2f 100644 --- a/memtime.hh +++ b/memtime.hh @@ -29,39 +29,42 @@ typedef long long int64; static inline double cpuTime(void) { - struct rusage ru; - getrusage(RUSAGE_SELF, &ru); - return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; + struct rusage ru; + getrusage(RUSAGE_SELF, &ru); + return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; } static inline int memReadStat(void) { - char name[256]; - pid_t pid = getpid(); - sprintf(name, "/proc/%d/statm", pid); - FILE* in = fopen(name, "rb"); - if (in == nullptr) - { - return 0; + char name[256]; + pid_t pid = getpid(); + sprintf(name, "/proc/%d/statm", pid); + FILE *in = fopen(name, "rb"); + + if (in == nullptr) { + return 0; + } + + int value; + + for (int field = 0; field >= 0; --field) { + if (fscanf(in, "%d", &value) == EOF) { + FERROR("EOF"); } - int value; - for (int field = 0; field >= 0; --field) - { - if (fscanf(in, "%d", &value) == EOF) - FERROR("EOF"); - } - fclose(in); - return value; + } + + fclose(in); + return value; } static inline int64 memUsedInt64() { - return (int64)memReadStat() * (int64)getpagesize(); + return (int64)memReadStat() * (int64)getpagesize(); } static inline double memUsed() { - return memUsedInt64() / 1048576.0; + return memUsedInt64() / 1048576.0; } #endif diff --git a/options.hh b/options.hh index 0f494a0..e33af84 100644 --- a/options.hh +++ b/options.hh @@ -1,9 +1,10 @@ #ifndef RS_OPTIONS_HH #define RS_OPTIONS_HH -class Options { +class Options +{ -public: + public: unsigned int verbose; bool show_progress; bool measure; @@ -18,19 +19,19 @@ public: Options(void) { - verbose = 0; - show_progress = false; - measure = false; + verbose = 0; + show_progress = false; + measure = false; - part_tr_rel = false; + part_tr_rel = false; - reorder_reach = false; - reorder_trans = false; + reorder_reach = false; + reorder_trans = false; - enc_time = 0; - enc_mem = 0; - ver_time = 0; - ver_mem = 0; + enc_time = 0; + enc_mem = 0; + ver_time = 0; + ver_mem = 0; } }; diff --git a/rs.cc b/rs.cc index 4b844f4..684aa4d 100644 --- a/rs.cc +++ b/rs.cc @@ -9,299 +9,320 @@ #include "rs.hh" RctSys::RctSys(void) - : current_process_defined(false) + : current_process_defined(false) { - ctx_aut = nullptr; + ctx_aut = nullptr; } bool RctSys::hasEntity(std::string name) { - if (entities_names.find(name) == entities_names.end()) - return false; - else - return true; + if (entities_names.find(name) == entities_names.end()) { + return false; + } + else { + return true; + } } void RctSys::addEntity(std::string name) { - if (!hasEntity(name)) - { - Entity new_entity_id = entities_ids.size(); + if (!hasEntity(name)) { + Entity new_entity_id = entities_ids.size(); - VERB_L2("Adding entity: " << name << " index=" << new_entity_id); + VERB_L2("Adding entity: " << name << " index=" << new_entity_id); - entities_ids.push_back(name); - entities_names[name] = new_entity_id; - } + entities_ids.push_back(name); + entities_names[name] = new_entity_id; + } } std::string RctSys::getEntityName(Entity entityID) { - if (entityID < entities_ids.size()) - return entities_ids[entityID]; - else - { - FERROR("No such entity ID: " << entityID); - return "??"; - } + if (entityID < entities_ids.size()) { + return entities_ids[entityID]; + } + else { + FERROR("No such entity ID: " << entityID); + return "??"; + } } Entity RctSys::getEntityID(std::string name) { - if (!hasEntity(name)) - { - FERROR("No such entity: " << name); - } - return entities_names[name]; + if (!hasEntity(name)) { + FERROR("No such entity: " << name); + } + + return entities_names[name]; } void RctSys::setCurrentProcess(std::string processName) { - VERB_LN(2, "Current Process: " << processName); - - if (!hasProcess(processName)) - { - addProcess(processName); - } - - current_proc_id = getProcessID(processName); - current_process_defined = true; + VERB_LN(2, "Current Process: " << processName); + + if (!hasProcess(processName)) { + addProcess(processName); + } + + current_proc_id = getProcessID(processName); + current_process_defined = true; } void RctSys::addProcess(std::string processName) { - if (!hasProcess(processName)) - { - Process new_proc_id = processes_ids.size(); + if (!hasProcess(processName)) { + Process new_proc_id = processes_ids.size(); - VERB_L2("Adding process: " << processName << " index=" << new_proc_id); + 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[new_proc_id] = Reactions(); - assert(proc_reactions.size() == new_proc_id+1); - } + processes_ids.push_back(processName); + processes_names[processName] = new_proc_id; + + // reactions for the new process + proc_reactions[new_proc_id] = 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; + 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]; + if (!hasProcess(processName)) { + FERROR("No such process: " << processName); + } + + return processes_names[processName]; } std::string RctSys::getProcessName(Process processID) { - if (processID < processes_ids.size()) - return processes_ids[processID]; - else - { - FERROR("No such process ID: " << processID); - } + if (processID < processes_ids.size()) { + return processes_ids[processID]; + } + else { + FERROR("No such process ID: " << processID); + } } void RctSys::pushReactant(std::string entityName) { - if (!hasEntity(entityName)) - addEntity(entityName); - tmpReactants.insert(getEntityID(entityName)); + if (!hasEntity(entityName)) { + addEntity(entityName); + } + + tmpReactants.insert(getEntityID(entityName)); } void RctSys::pushInhibitor(std::string entityName) { - if (!hasEntity(entityName)) - addEntity(entityName); - tmpInhibitors.insert(getEntityID(entityName)); + if (!hasEntity(entityName)) { + addEntity(entityName); + } + + tmpInhibitors.insert(getEntityID(entityName)); } void RctSys::pushProduct(std::string entityName) { - if (!hasEntity(entityName)) - addEntity(entityName); - tmpProducts.insert(getEntityID(entityName)); + if (!hasEntity(entityName)) { + addEntity(entityName); + } + + tmpProducts.insert(getEntityID(entityName)); } void RctSys::addReactionForCurrentProcess(Reaction reaction) { - if (!current_process_defined) - { - FERROR("Internal error. Current process is not set!"); - } - proc_reactions[current_proc_id].push_back(reaction); + if (!current_process_defined) { + FERROR("Internal error. Current process is not set!"); + } + + proc_reactions[current_proc_id].push_back(reaction); } void RctSys::commitReaction(void) { - VERB_L3("Saving reaction"); + VERB_L3("Saving reaction"); - Reaction r; + Reaction r; - r.rctt = tmpReactants; - r.inhib = tmpInhibitors; - r.prod = tmpProducts; + r.rctt = tmpReactants; + r.inhib = tmpInhibitors; + r.prod = tmpProducts; - addReactionForCurrentProcess(r); + addReactionForCurrentProcess(r); - tmpReactants.clear(); - tmpInhibitors.clear(); - tmpProducts.clear(); + tmpReactants.clear(); + tmpInhibitors.clear(); + tmpProducts.clear(); } std::string RctSys::entitiesToStr(const Entities &entities) { - std::string s = " "; - for (auto a = entities.begin(); a != entities.end(); ++a) - { - s += entityToStr(*a) + " "; - } - return s; + std::string s = " "; + + for (auto a = entities.begin(); a != entities.end(); ++a) { + s += entityToStr(*a) + " "; + } + + return s; } void RctSys::showReactions(void) { - cout << "# Reactions:" << endl; - - for (unsigned int proc_id = 0; proc_id < processes_ids.size(); ++proc_id) - { - cout << endl; - cout << " . proc = \"" << getProcessName(proc_id) << "\":" << endl; - for (const auto &r : proc_reactions[proc_id]) - { - cout << " * (R={" << entitiesToStr(r.rctt) << "}," - << "I={" << entitiesToStr(r.inhib) << "}," - << "P={" << entitiesToStr(r.prod) << "})" << endl; - } - } - cout << endl; + cout << "# Reactions:" << endl; + + for (unsigned int proc_id = 0; proc_id < processes_ids.size(); ++proc_id) { + cout << endl; + cout << " . proc = \"" << getProcessName(proc_id) << "\":" << endl; + + for (const auto &r : proc_reactions[proc_id]) { + cout << " * (R={" << entitiesToStr(r.rctt) << "}," + << "I={" << entitiesToStr(r.inhib) << "}," + << "P={" << entitiesToStr(r.prod) << "})" << endl; + } + } + + cout << endl; } void RctSys::pushStateEntity(std::string entityName) { - if (!hasEntity(entityName)) - { - FERROR("No such entity: " << entityName); - } - tmpState.insert(getEntityID(entityName)); + if (!hasEntity(entityName)) { + FERROR("No such entity: " << entityName); + } + + tmpState.insert(getEntityID(entityName)); } void RctSys::commitInitState(void) { - if (ctx_aut != nullptr) - { - FERROR("Initial RS states must not be used with context automaton"); - } - initStates.insert(tmpState); - tmpState.clear(); + if (ctx_aut != nullptr) { + FERROR("Initial RS states must not be used with context automaton"); + } + + initStates.insert(tmpState); + tmpState.clear(); } void RctSys::addActionEntity(std::string entityName) { - if (!hasEntity(entityName)) - addEntity(entityName); - actionEntities.insert(getEntityID(entityName)); + if (!hasEntity(entityName)) { + addEntity(entityName); + } + + actionEntities.insert(getEntityID(entityName)); } void RctSys::addActionEntity(Entity entity) { - if (!isActionEntity(entity)) - actionEntities.insert(entity); + if (!isActionEntity(entity)) { + actionEntities.insert(entity); + } } bool RctSys::isActionEntity(Entity entity) { - if (actionEntities.count(entity) > 0) - return true; - else - return false; + if (actionEntities.count(entity) > 0) { + return true; + } + else { + return false; + } } void RctSys::showActionEntities(void) { - cout << "# Context entities:"; - for (auto a = actionEntities.begin(); a != actionEntities.end(); ++a) - { - cout << " " << getEntityName(*a); - } - cout << endl; + cout << "# Context entities:"; + + for (auto a = actionEntities.begin(); a != actionEntities.end(); ++a) { + cout << " " << getEntityName(*a); + } + + cout << endl; } void RctSys::showInitialStates(void) { - cout << "# Initial states:" << endl; - for (auto s = initStates.begin(); s != initStates.end(); ++s) - { - cout << " *"; - for (auto a = s->begin(); a != s->end(); ++a) - { - cout << " " << getEntityName(*a); - } - cout << endl; + cout << "# Initial states:" << endl; + + for (auto s = initStates.begin(); s != initStates.end(); ++s) { + cout << " *"; + + for (auto a = s->begin(); a != s->end(); ++a) { + cout << " " << getEntityName(*a); } + + cout << endl; + } } void RctSys::printSystem(void) { - if (!usingContextAutomaton()) - showInitialStates(); - showActionEntities(); - showReactions(); - - if (ctx_aut != nullptr) ctx_aut->printAutomaton(); + if (!usingContextAutomaton()) { + showInitialStates(); + } + + showActionEntities(); + showReactions(); + + if (ctx_aut != nullptr) { + ctx_aut->printAutomaton(); + } } void RctSys::ctxAutEnable(void) { - assert(ctx_aut == nullptr); - if (initStatesDefined()) - { - FERROR("Initial states must not be defined if using context automaton"); - } - ctx_aut = new CtxAut(opts, this); + assert(ctx_aut == nullptr); + + if (initStatesDefined()) { + FERROR("Initial states must not be defined if using context automaton"); + } + + ctx_aut = new CtxAut(opts, this); } void RctSys::ctxAutAddState(std::string stateName) { - assert(ctx_aut != nullptr); - ctx_aut->addState(stateName); + assert(ctx_aut != nullptr); + ctx_aut->addState(stateName); } void RctSys::ctxAutSetInitState(std::string stateName) { - assert(ctx_aut != nullptr); - ctx_aut->setInitState(stateName); + assert(ctx_aut != nullptr); + ctx_aut->setInitState(stateName); } -void RctSys::ctxAutAddTransition(std::string srcStateName, std::string dstStateName) +void RctSys::ctxAutAddTransition(std::string srcStateName, + std::string dstStateName) { - assert(ctx_aut != nullptr); - ctx_aut->addTransition(srcStateName, dstStateName); + assert(ctx_aut != nullptr); + ctx_aut->addTransition(srcStateName, dstStateName); } void RctSys::ctxAutPushNamedContextEntity(std::string entityName) { - assert(ctx_aut != nullptr); - - Entity entity_id = getEntityID(entityName); + assert(ctx_aut != nullptr); - // - // We mark the entity as an action entity - // - // This step is required to ensure the minimal number of - // BDD variables used in the encoding of the context sets - // - addActionEntity(entity_id); - - ctx_aut->pushContextEntity(entity_id); + Entity entity_id = getEntityID(entityName); + + // + // We mark the entity as an action entity + // + // This step is required to ensure the minimal number of + // BDD variables used in the encoding of the context sets + // + addActionEntity(entity_id); + + ctx_aut->pushContextEntity(entity_id); } /** EOF **/ diff --git a/rs.hh b/rs.hh index 350d336..c1f184a 100644 --- a/rs.hh +++ b/rs.hh @@ -28,82 +28,106 @@ class CtxAut; class RctSys { - friend class SymRS; - friend class SymRSstate; + friend class SymRS; + friend class SymRSstate; - public: - RctSys(void); - - 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); - std::string getProcessName(Process processID); - - 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 entitiesToStr(const Entities &entities); - void showReactions(void); - void pushStateEntity(std::string entityName); - void commitInitState(void); - 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 showInitialStates(void); - void showActionEntities(void); - void printSystem(void); + public: + RctSys(void); - void ctxAutEnable(void); - void ctxAutAddState(std::string stateName); - void ctxAutSetInitState(std::string stateName); - void ctxAutAddTransition(std::string srcStateName, std::string dstStateName); - void ctxAutPushNamedContextEntity(std::string entity_name); - - bool initStatesDefined(void) { return initStates.size() != 0; } - bool usingContextAutomaton(void) { return ctx_aut != nullptr; } - - private: - Reactions reactions; // TODO: to be removed later - ReactionsForProc proc_reactions; - - EntitiesSets initStates; + void setOptions(Options *opts) + { + this->opts = opts; + } + bool hasEntity(std::string entityName); + void addEntity(std::string entityName); + std::string getEntityName(Entity entityID); - Entities actionEntities; + void setCurrentProcess(std::string processName); + void addProcess(std::string processName); + bool hasProcess(std::string processName); + Process getProcessID(std::string processName); + std::string getProcessName(Process processID); - CtxAut *ctx_aut; + void addReactionForCurrentProcess(Reaction reaction); - EntitiesById entities_ids; - EntitiesByName entities_names; + 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 entitiesToStr(const Entities &entities); + void showReactions(void); + void pushStateEntity(std::string entityName); + void commitInitState(void); + 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 showInitialStates(void); + void showActionEntities(void); + void printSystem(void); - ProcessesById processes_ids; - ProcessesByName processes_names; - - Process current_proc_id; - bool current_process_defined; + void ctxAutEnable(void); + void ctxAutAddState(std::string stateName); + void ctxAutSetInitState(std::string stateName); + void ctxAutAddTransition(std::string srcStateName, std::string dstStateName); + void ctxAutPushNamedContextEntity(std::string entity_name); - Entities tmpReactants; - Entities tmpInhibitors; - Entities tmpProducts; + bool initStatesDefined(void) + { + return initStates.size() != 0; + } + bool usingContextAutomaton(void) + { + return ctx_aut != nullptr; + } - Entities tmpState; + private: + Reactions reactions; // TODO: to be removed later + ReactionsForProc proc_reactions; - Options *opts; + EntitiesSets initStates; - Entity getEntityID(std::string entityName); + Entities actionEntities; + + CtxAut *ctx_aut; + + 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; + + Entities tmpState; + + Options *opts; + + Entity getEntityID(std::string entityName); }; diff --git a/rsin_driver.cc b/rsin_driver.cc index c78679a..ddc5352 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -2,61 +2,60 @@ #include "rsin_parser.hh" rsin_driver::rsin_driver(void) -: trace_scanning(false), trace_parsing(false) + : trace_scanning(false), trace_parsing(false) { - initialise(); + initialise(); } rsin_driver::rsin_driver(RctSys *rs) -: trace_scanning(false), trace_parsing(false) + : trace_scanning(false), trace_parsing(false) { - initialise(); - this->rs = rs; + initialise(); + this->rs = rs; } void rsin_driver::initialise(void) { - rs = nullptr; - rsctlform = nullptr; - opts = nullptr; - use_ctx_aut = false; - use_concentrations = false; + rs = nullptr; + rsctlform = nullptr; + opts = nullptr; + use_ctx_aut = false; + use_concentrations = false; } rsin_driver::~rsin_driver () { - // placeholder + // placeholder } int rsin_driver::parse(const std::string &f) { - file = f; - scan_begin(); - yy::rsin_parser parser(*this); - parser.set_debug_level(trace_parsing); - int res = parser.parse(); - scan_end(); - return res; + file = f; + scan_begin(); + yy::rsin_parser parser(*this); + parser.set_debug_level(trace_parsing); + int res = parser.parse(); + scan_end(); + return res; } void rsin_driver::error(const yy::location &l, const std::string &m) { - std::cerr << l << ": " << m << std::endl; + std::cerr << l << ": " << m << std::endl; } void rsin_driver::error(const std::string &m) { - std::cerr << m << std::endl; + std::cerr << m << std::endl; } FormRSCTL *rsin_driver::getFormRSCTL(void) { - if (rsctlform == nullptr) - { - FERROR("RSCTL formula was not supplied!"); - } + if (rsctlform == nullptr) { + FERROR("RSCTL formula was not supplied!"); + } - return rsctlform; + return rsctlform; } // @@ -64,40 +63,40 @@ FormRSCTL *rsin_driver::getFormRSCTL(void) // void rsin_driver::ensureOptionsAllowed(void) { - if (rs != nullptr) - { - FERROR("Options cannot be set/modified after the reaction system is initialised") - } + if (rs != nullptr) { + FERROR("Options cannot be set/modified after the reaction system is initialised") + } } void rsin_driver::ensureReactionSystemReady(void) { - if (rs == nullptr) - setupReactionSystem(); + if (rs == nullptr) { + setupReactionSystem(); + } } void rsin_driver::setupReactionSystem(void) { - assert(rs == nullptr); - rs = new RctSys; - - if (use_ctx_aut) VERB("Using RS with CA") - else VERB("Using ordinary RS") + assert(rs == nullptr); + rs = new RctSys; - rs->setOptions(opts); + if (use_ctx_aut) VERB("Using RS with CA") + else VERB("Using ordinary RS") + + rs->setOptions(opts); } RctSys *rsin_driver::getReactionSystem(void) { - ensureReactionSystemReady(); - assert(rs != nullptr); - return rs; + ensureReactionSystemReady(); + assert(rs != nullptr); + return rs; } void rsin_driver::useContextAutomaton(void) { - ensureOptionsAllowed(); - use_ctx_aut = true; - getReactionSystem()->ctxAutEnable(); + ensureOptionsAllowed(); + use_ctx_aut = true; + getReactionSystem()->ctxAutEnable(); } diff --git a/rsin_driver.hh b/rsin_driver.hh index f150146..04a8aa2 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -19,7 +19,7 @@ YY_DECL; // Conducting the whole scanning an parsing of RS class rsin_driver { -public: + public: rsin_driver(void); rsin_driver(RctSys *rs); virtual ~rsin_driver(); @@ -27,10 +27,10 @@ public: //std::map variables; FormRSCTL *rsctlform; Options *opts; - - // options in configuration file: - bool use_ctx_aut; - bool use_concentrations; + + // options in configuration file: + bool use_ctx_aut; + bool use_concentrations; // Handling the scanner void scan_begin(); @@ -41,28 +41,38 @@ public: std::string file; bool trace_parsing; - void setOptions(Options *opts) { this->opts = opts; }; - void addFormRSCTL(FormRSCTL *f) { rsctlform = f; }; + void setOptions(Options *opts) + { + this->opts = opts; + }; + void addFormRSCTL(FormRSCTL *f) + { + rsctlform = f; + }; FormRSCTL *getFormRSCTL(void); - void ensureOptionsAllowed(void); - void useContextAutomaton(void); - void useConcentrations(void) { ensureOptionsAllowed(); use_concentrations = true; }; - - void ensureReactionSystemReady(void); - void setupReactionSystem(void); - - RctSys *getReactionSystem(void); - CtxAut *getCtxAut(void); + void ensureOptionsAllowed(void); + void useContextAutomaton(void); + void useConcentrations(void) + { + ensureOptionsAllowed(); + use_concentrations = true; + }; + + void ensureReactionSystemReady(void); + void setupReactionSystem(void); + + RctSys *getReactionSystem(void); + CtxAut *getCtxAut(void); // Error handling. void error(const yy::location &l, const std::string &m); void error(const std::string &m); - -private: + + private: RctSys *rs; - void initialise(void); + void initialise(void); }; #endif diff --git a/symrs.cc b/symrs.cc index 6440e93..aef6158 100644 --- a/symrs.cc +++ b/symrs.cc @@ -8,593 +8,583 @@ SymRS::SymRS(RctSys *rs, Options *opts) { - this->rs = rs; - this->opts = opts; - totalRctSysStateVars = rs->getEntitiesSize(); - totalReactions = rs->getReactionsSize(); - totalActions = rs->getActionsSize(); - - totalCtxAutStateVars = getCtxAutStateEncodingSize(); - - totalStateVars = totalRctSysStateVars + totalCtxAutStateVars; - - partTrans = nullptr; - monoTrans = nullptr; - - pv_ca = nullptr; - pv_ca_succ = nullptr; - tr_ca = nullptr; + this->rs = rs; + this->opts = opts; + totalRctSysStateVars = rs->getEntitiesSize(); + totalReactions = rs->getReactionsSize(); + totalActions = rs->getActionsSize(); - encode(); + totalCtxAutStateVars = getCtxAutStateEncodingSize(); + + totalStateVars = totalRctSysStateVars + totalCtxAutStateVars; + + partTrans = nullptr; + monoTrans = nullptr; + + pv_ca = nullptr; + pv_ca_succ = nullptr; + tr_ca = nullptr; + + encode(); } BDD SymRS::encEntity_raw(Entity entity, bool succ) const { - BDD r; + BDD r; - if (succ) - r = (*pv_succ)[entity]; - else - r = (*pv)[entity]; + if (succ) { + r = (*pv_succ)[entity]; + } + else { + r = (*pv)[entity]; + } - return r; + return r; } BDD SymRS::encEntitiesConj_raw(const Entities &entities, bool succ) { - BDD r = BDD_TRUE; + BDD r = BDD_TRUE; - for (const auto &entity : entities) - { - if (succ) r *= encEntitySucc(entity); - else r *= encEntity(entity); + for (const auto &entity : entities) { + if (succ) { + r *= encEntitySucc(entity); } + else { + r *= encEntity(entity); + } + } - return r; + return r; } BDD SymRS::encEntitiesDisj_raw(const Entities &entities, bool succ) { - BDD r = BDD_FALSE; + BDD r = BDD_FALSE; - for (const auto &entity : entities) - { - if (succ) r += encEntitySucc(entity); - else r += encEntity(entity); + for (const auto &entity : entities) { + if (succ) { + r += encEntitySucc(entity); } + else { + r += encEntity(entity); + } + } - return r; + return r; } BDD SymRS::encStateActEntitiesConj(const Entities &entities) { - BDD r = BDD_TRUE; + BDD r = BDD_TRUE; - for (const auto &entity : entities) - { - BDD state_act = encEntity(entity); - int actEntity; - - // if entity is also an action entity, we include it in the encoding - if ((actEntity = getMappedStateToActID(entity)) >= 0) - state_act += encActEntity(actEntity); - - r *= state_act; + for (const auto &entity : entities) { + BDD state_act = encEntity(entity); + int actEntity; + + // if entity is also an action entity, we include it in the encoding + if ((actEntity = getMappedStateToActID(entity)) >= 0) { + state_act += encActEntity(actEntity); } - return r; + r *= state_act; + } + + return r; } BDD SymRS::encStateActEntitiesDisj(const Entities &entities) { - BDD r = BDD_FALSE; + BDD r = BDD_FALSE; - for (const auto &entity : entities) - { - BDD state_act = encEntity(entity); - int actEntity; + for (const auto &entity : entities) { + BDD state_act = encEntity(entity); + int actEntity; - // if entity is also an aciton entity, we include it in the encoding - if ((actEntity = getMappedStateToActID(entity)) >= 0) - state_act += encActEntity(actEntity); - - r += state_act; + // if entity is also an aciton entity, we include it in the encoding + if ((actEntity = getMappedStateToActID(entity)) >= 0) { + state_act += encActEntity(actEntity); } - return r; + r += state_act; + } + + return r; } BDD SymRS::encActEntitiesConj(const Entities &entities) { - BDD r = BDD_TRUE; + BDD r = BDD_TRUE; - for (const auto &entity : entities) - { - Entity actEntity = getMappedStateToActID(entity); - r *= encActEntity(actEntity); - } + for (const auto &entity : entities) { + Entity actEntity = getMappedStateToActID(entity); + r *= encActEntity(actEntity); + } - return r; + return r; } BDD SymRS::compState(const BDD &state) const { - BDD s = state; + BDD s = state; - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) - { - if (!(*pv)[i] * state != cuddMgr->bddZero()) - s *= !(*pv)[i]; + for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { + if (!(*pv)[i] * state != cuddMgr->bddZero()) { + s *= !(*pv)[i]; } + } - return s; + return s; } BDD SymRS::compContext(const BDD &context) const { - BDD c = context; + BDD c = context; - for (unsigned int i = 0; i < totalActions; ++i) - { - if (!(*pv_act)[i] * context != cuddMgr->bddZero()) - c *= !(*pv_act)[i]; + for (unsigned int i = 0; i < totalActions; ++i) { + if (!(*pv_act)[i] * context != cuddMgr->bddZero()) { + c *= !(*pv_act)[i]; } + } - return c; + return c; } std::string SymRS::decodedRctSysStateToStr(const BDD &state) { - std::string s = "{ "; - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) - { - if (!(encEntity(i) * state).IsZero()) - { - s += rs->entityToStr(i) + " "; - } + std::string s = "{ "; + + for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { + if (!(encEntity(i) * state).IsZero()) { + s += rs->entityToStr(i) + " "; } - s += "}"; - return s; + } + + s += "}"; + return s; } void SymRS::printDecodedRctSysStates(const BDD &states) { - BDD unproc = states; - while (!unproc.IsZero()) - { - BDD t = unproc.PickOneMinterm(*pv_rs); - cout << decodedRctSysStateToStr(t) << endl; - if (opts->verbose > 9) { - t.PrintMinterm(); - cout << endl; - } - unproc -= t; + BDD unproc = states; + + while (!unproc.IsZero()) { + BDD t = unproc.PickOneMinterm(*pv_rs); + cout << decodedRctSysStateToStr(t) << endl; + + if (opts->verbose > 9) { + t.PrintMinterm(); + cout << endl; } + + unproc -= t; + } } void SymRS::initBDDvars(void) { - VERB("Initialising CUDD"); - - cuddMgr = new Cudd(0,0); + VERB("Initialising CUDD"); - VERB("Preparing BDD variables"); + cuddMgr = new Cudd(0, 0); - // used for bddVar - unsigned int bdd_var_idx = 0; - - // used for pv, pv_succ - unsigned int global_state_idx = 0; + VERB("Preparing BDD variables"); - // Variables for reaction system with CA (if used) - pv = new vector(totalStateVars); - pv_succ = new vector(totalStateVars); - pv_E = new BDD(BDD_TRUE); - pv_succ_E = new BDD(BDD_TRUE); - - // Reaction system (no actions, no CA) - pv_rs = new vector(totalRctSysStateVars); - pv_rs_succ = new vector(totalRctSysStateVars); - pv_rs_E = new BDD(BDD_TRUE); - pv_rs_succ_E = new BDD(BDD_TRUE); + // used for bddVar + unsigned int bdd_var_idx = 0; - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) - { - (*pv_rs)[i] = cuddMgr->bddVar(bdd_var_idx++); - (*pv_rs_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_rs_E *= (*pv_rs)[i]; - *pv_rs_succ_E *= (*pv_rs_succ)[i]; - - (*pv)[global_state_idx] = (*pv_rs)[i]; - (*pv_succ)[global_state_idx] = (*pv_rs_succ)[i]; - ++global_state_idx; - } + // used for pv, pv_succ + unsigned int global_state_idx = 0; - // CA - if (usingContextAutomaton()) - { - VERB("Context automaton variables"); + // Variables for reaction system with CA (if used) + pv = new vector(totalStateVars); + pv_succ = new vector(totalStateVars); + pv_E = new BDD(BDD_TRUE); + pv_succ_E = new BDD(BDD_TRUE); - pv_ca = new vector(totalCtxAutStateVars); - pv_ca_succ = new vector(totalCtxAutStateVars); - pv_ca_E = new BDD(BDD_TRUE); - pv_ca_succ_E = new BDD(BDD_TRUE); + // Reaction system (no actions, no CA) + pv_rs = new vector(totalRctSysStateVars); + pv_rs_succ = new vector(totalRctSysStateVars); + pv_rs_E = new BDD(BDD_TRUE); + pv_rs_succ_E = new BDD(BDD_TRUE); - for (unsigned int i = 0; i < totalCtxAutStateVars; ++i) - { - (*pv_ca)[i] = cuddMgr->bddVar(bdd_var_idx++); - (*pv_ca_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_ca_E *= (*pv_ca)[i]; - *pv_ca_succ_E *= (*pv_ca_succ)[i]; - - (*pv)[global_state_idx] = (*pv_ca)[i]; - (*pv_succ)[global_state_idx] = (*pv_ca_succ)[i]; - ++global_state_idx; - } - } - - // Actions/Contexts - pv_act = new vector(totalActions); - pv_act_E = new BDD(BDD_TRUE); - - for (unsigned int i = 0; i < totalActions; ++i) - { - (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_act_E *= (*pv_act)[i]; + for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { + (*pv_rs)[i] = cuddMgr->bddVar(bdd_var_idx++); + (*pv_rs_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); + *pv_rs_E *= (*pv_rs)[i]; + *pv_rs_succ_E *= (*pv_rs_succ)[i]; + + (*pv)[global_state_idx] = (*pv_rs)[i]; + (*pv_succ)[global_state_idx] = (*pv_rs_succ)[i]; + ++global_state_idx; + } + + // CA + if (usingContextAutomaton()) { + VERB("Context automaton variables"); + + pv_ca = new vector(totalCtxAutStateVars); + pv_ca_succ = new vector(totalCtxAutStateVars); + pv_ca_E = new BDD(BDD_TRUE); + pv_ca_succ_E = new BDD(BDD_TRUE); + + for (unsigned int i = 0; i < totalCtxAutStateVars; ++i) { + (*pv_ca)[i] = cuddMgr->bddVar(bdd_var_idx++); + (*pv_ca_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); + *pv_ca_E *= (*pv_ca)[i]; + *pv_ca_succ_E *= (*pv_ca_succ)[i]; + + (*pv)[global_state_idx] = (*pv_ca)[i]; + (*pv_succ)[global_state_idx] = (*pv_ca_succ)[i]; + ++global_state_idx; } - - // Quantification BDDs - - *pv_E = *pv_rs_E; - *pv_succ_E = *pv_rs_succ_E; - - if (usingContextAutomaton()) - { - *pv_E *= *pv_ca_E; - *pv_succ_E *= *pv_ca_succ_E; - } + } - VERB("All BDD variables ready"); + // Actions/Contexts + pv_act = new vector(totalActions); + pv_act_E = new BDD(BDD_TRUE); + + for (unsigned int i = 0; i < totalActions; ++i) { + (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); + *pv_act_E *= (*pv_act)[i]; + } + + // Quantification BDDs + + *pv_E = *pv_rs_E; + *pv_succ_E = *pv_rs_succ_E; + + if (usingContextAutomaton()) { + *pv_E *= *pv_ca_E; + *pv_succ_E *= *pv_ca_succ_E; + } + + VERB("All BDD variables ready"); } void SymRS::encodeTransitions(void) { - DecompReactions dr; + DecompReactions dr; - VERB("Decomposing reactions"); - for (unsigned int i = 0; i < totalReactions; ++i) - { - ReactionCond cond; - cond.rctt = rs->reactions[i].rctt; - cond.inhib = rs->reactions[i].inhib; - - for (Entities::iterator p = rs->reactions[i].prod.begin(); - p != rs->reactions[i].prod.end(); ++p) - { - dr[*p].push_back(cond); - } + VERB("Decomposing reactions"); + + for (unsigned int i = 0; i < totalReactions; ++i) { + ReactionCond cond; + cond.rctt = rs->reactions[i].rctt; + cond.inhib = rs->reactions[i].inhib; + + for (Entities::iterator p = rs->reactions[i].prod.begin(); + p != rs->reactions[i].prod.end(); ++p) { + dr[*p].push_back(cond); + } + } + + VERB("Encoding reactions"); + + if (opts->part_tr_rel) { + VERB("Using partitioned transition relation encoding"); + partTrans = new vector(totalRctSysStateVars); + } + else { + VERB("Using monolithic transition relation encoding"); + monoTrans = new BDD(BDD_TRUE); + } + + for (unsigned int p = 0; p < totalRctSysStateVars; ++p) { + VERB_L3("Encoding for successor " << p); + + DecompReactions::iterator di; + + if ((di = dr.find(p)) == dr.end()) { + // there is no reaction producing p: + if (opts->part_tr_rel) { + (*partTrans)[p] = !encEntitySucc(p); + } + else { + *monoTrans *= !encEntitySucc(p); + } + } + else { + // di - reactions producing p + + BDD conditions = BDD_FALSE; + + assert(di->second.size() > 0); + + for (unsigned int j = 0; j < di->second.size(); ++j) { + conditions += encStateActEntitiesConj(di->second[j].rctt) * + !encStateActEntitiesDisj(di->second[j].inhib); + } + + if (opts->part_tr_rel) { + (*partTrans)[p] = conditions * encEntitySucc(p); + (*partTrans)[p] += !conditions * !encEntitySucc(p); + } + else { + *monoTrans *= (conditions * encEntitySucc(p)) + (!conditions * !encEntitySucc( + p)); + } } - VERB("Encoding reactions"); - - if (opts->part_tr_rel) - { - VERB("Using partitioned transition relation encoding"); - partTrans = new vector(totalRctSysStateVars); - } - else - { - VERB("Using monolithic transition relation encoding"); - monoTrans = new BDD(BDD_TRUE); + if (opts->reorder_trans) { + VERB_L2("Reordering"); + Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); } - for (unsigned int p = 0; p < totalRctSysStateVars; ++p) - { - VERB_L3("Encoding for successor " << p); + } - DecompReactions::iterator di; + VERB("Reactions ready"); - if ((di = dr.find(p)) == dr.end()) - { - // there is no reaction producing p: - if (opts->part_tr_rel) - (*partTrans)[p] = !encEntitySucc(p); - else - { - *monoTrans *= !encEntitySucc(p); - } - } - else - { - // di - reactions producing p - - BDD conditions = BDD_FALSE; - - assert(di->second.size() > 0); - - for (unsigned int j = 0; j < di->second.size(); ++j) - { - conditions += encStateActEntitiesConj(di->second[j].rctt) * !encStateActEntitiesDisj(di->second[j].inhib); - } - - if (opts->part_tr_rel) - { - (*partTrans)[p] = conditions * encEntitySucc(p); - (*partTrans)[p] += !conditions * !encEntitySucc(p); - } - else - { - *monoTrans *= (conditions * encEntitySucc(p)) + (!conditions * !encEntitySucc(p)); - } - } - if (opts->reorder_trans) - { - VERB_L2("Reordering"); - Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); - } + if (usingContextAutomaton()) { + VERB("Augmenting transition relation encoding with the transition relation for context automaton"); + if (opts->part_tr_rel) { + assert(0); } + else { + assert(tr_ca != nullptr); + *monoTrans *= *tr_ca; + } + } - VERB("Reactions ready"); - - if (usingContextAutomaton()) - { - VERB("Augmenting transition relation encoding with the transition relation for context automaton"); - if (opts->part_tr_rel) - { - assert(0); - } - else - { - assert(tr_ca != nullptr); - *monoTrans *= *tr_ca; - } - } - - VERB("Transition relation encoded") + VERB("Transition relation encoded") } BDD SymRS::getEncState(const Entities &entities) { - assert(0); - //BDD state = compState(encEntitiesConj(rs->initState)); - //for (RctSys::Entities::iterator at = rs->actionEntities.begin(); at != rs->actionEntities.end(); ++at) - //{ - // state = state.ExistAbstract(encEntity(*at)); - //} - return BDD_FALSE; + assert(0); + //BDD state = compState(encEntitiesConj(rs->initState)); + //for (RctSys::Entities::iterator at = rs->actionEntities.begin(); at != rs->actionEntities.end(); ++at) + //{ + // state = state.ExistAbstract(encEntity(*at)); + //} + return BDD_FALSE; } BDD SymRS::encNoContext(void) { - BDD noContextBDD = BDD_TRUE; + BDD noContextBDD = BDD_TRUE; - for (unsigned int i = 0; i < totalActions; ++i) - { - noContextBDD *= !(*pv_act)[i]; - } + for (unsigned int i = 0; i < totalActions; ++i) { + noContextBDD *= !(*pv_act)[i]; + } - return noContextBDD; + return noContextBDD; } void SymRS::encodeInitStates(void) { - if (usingContextAutomaton()) - { - VERB("Encoding initial states (using context automaton)"); - encodeInitStatesForCtxAut(); - } - else - { - VERB("Encoding initial states (for the action entities method -- no CA)"); - encodeInitStatesNoCtxAut(); - } - VERB("Initial states encoded"); + if (usingContextAutomaton()) { + VERB("Encoding initial states (using context automaton)"); + encodeInitStatesForCtxAut(); + } + else { + VERB("Encoding initial states (for the action entities method -- no CA)"); + encodeInitStatesNoCtxAut(); + } + + VERB("Initial states encoded"); } void SymRS::encodeInitStatesForCtxAut(void) { - initStates = new BDD(BDD_TRUE); + initStates = new BDD(BDD_TRUE); - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) - { - *initStates *= !(*pv)[i]; - } + for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { + *initStates *= !(*pv)[i]; + } - *initStates *= getEncCtxAutInitState(); + *initStates *= getEncCtxAutInitState(); } void SymRS::encodeInitStatesNoCtxAut(void) { #ifndef NDEBUG - if (opts->part_tr_rel) - assert(partTrans != nullptr); + + if (opts->part_tr_rel) { + assert(partTrans != nullptr); + } + #endif - initStates = new BDD(BDD_FALSE); - - for (auto state = rs->initStates.begin(); - state != rs->initStates.end(); - ++state) - { - VERB("Encoding a single inital state"); - BDD newInitState = compState(encEntitiesConj(*state)); - BDD q = BDD_TRUE; - if (opts->part_tr_rel) - { - for (unsigned int i = 0; i < partTrans->size(); ++i) - { - q *= newInitState * (*partTrans)[i] * encNoContext(); - } - } - else - { - q *= newInitState * *monoTrans * encNoContext(); - } - - q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); - q = q.ExistAbstract(*pv_act_E); + initStates = new BDD(BDD_FALSE); - *initStates += q; + for (auto state = rs->initStates.begin(); + state != rs->initStates.end(); + ++state) { + VERB("Encoding a single inital state"); + BDD newInitState = compState(encEntitiesConj(*state)); + BDD q = BDD_TRUE; + + if (opts->part_tr_rel) { + for (unsigned int i = 0; i < partTrans->size(); ++i) { + q *= newInitState * (*partTrans)[i] * encNoContext(); + } } + else { + q *= newInitState * *monoTrans * encNoContext(); + } + + q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); + q = q.ExistAbstract(*pv_act_E); + + *initStates += q; + } } void SymRS::mapStateToAct(void) { - VERB("Mapping state variables to action variables"); - unsigned int j = 0; - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) - { - if (rs->isActionEntity(i)) { - stateToAct.push_back(j++); - } - else - { - stateToAct.push_back(-1); - } + VERB("Mapping state variables to action variables"); + unsigned int j = 0; + + for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { + if (rs->isActionEntity(i)) { + stateToAct.push_back(j++); } - const unsigned int verbosity_level = 9; - if (opts->verbose > verbosity_level) - { - for (unsigned int i = 0; i < stateToAct.size(); ++i) - { - cout << "ii VERBOSE(" << verbosity_level << "): stateToAct[" << i << "] = " << stateToAct[i] << endl; - } + else { + stateToAct.push_back(-1); } + } + + const unsigned int verbosity_level = 9; + + if (opts->verbose > verbosity_level) { + for (unsigned int i = 0; i < stateToAct.size(); ++i) { + cout << "ii VERBOSE(" << verbosity_level << "): stateToAct[" << i << "] = " << + stateToAct[i] << endl; + } + } } void SymRS::encode(void) { - VERB("Encoding..."); + VERB("Encoding..."); - if (opts->measure) - { - opts->enc_time = cpuTime(); - opts->enc_mem = memUsed(); - } + if (opts->measure) { + opts->enc_time = cpuTime(); + opts->enc_mem = memUsed(); + } - mapStateToAct(); + mapStateToAct(); - initBDDvars(); - - if (usingContextAutomaton()) - { - encodeCtxAutTrans(); - } - else - { - VERB_LN(3, "Not using context automata, not encoding TR for CA") - } - - encodeTransitions(); - encodeInitStates(); + initBDDvars(); - if (opts->measure) - { - opts->enc_time = cpuTime() - opts->enc_time; - opts->enc_mem = memUsed() - opts->enc_mem; - } + if (usingContextAutomaton()) { + encodeCtxAutTrans(); + } + else { + VERB_LN(3, "Not using context automata, not encoding TR for CA") + } - VERB("Encoding done"); + encodeTransitions(); + encodeInitStates(); + + if (opts->measure) { + opts->enc_time = cpuTime() - opts->enc_time; + opts->enc_mem = memUsed() - opts->enc_mem; + } + + VERB("Encoding done"); } -BDD SymRS::encActStrEntity(std::string name) const +BDD SymRS::encActStrEntity(std::string name) const { - int id = getMappedStateToActID(rs->getEntityID(name)); - if (id < 0) - { - FERROR("Entity \"" << name << "\" not defined as context entity"); - return BDD_FALSE; - } else { - return encActEntity(getMappedStateToActID(rs->getEntityID(name))); - } + int id = getMappedStateToActID(rs->getEntityID(name)); + + if (id < 0) { + FERROR("Entity \"" << name << "\" not defined as context entity"); + return BDD_FALSE; + } + else { + return encActEntity(getMappedStateToActID(rs->getEntityID(name))); + } } size_t SymRS::getCtxAutStateEncodingSize(void) { - if (!usingContextAutomaton()) return 0; - - assert(rs->ctx_aut != nullptr); - - size_t bitCount = 0; - size_t bitCountMaxVal = 1; - size_t numStates = rs->ctx_aut->statesCount(); - while (bitCountMaxVal <= numStates) - { - bitCount++; - bitCountMaxVal *= 2; - } - - VERB_LN(3, "Bits required for CA: " << bitCount); - return bitCount; + if (!usingContextAutomaton()) { + return 0; + } + + assert(rs->ctx_aut != nullptr); + + size_t bitCount = 0; + size_t bitCountMaxVal = 1; + size_t numStates = rs->ctx_aut->statesCount(); + + while (bitCountMaxVal <= numStates) { + bitCount++; + bitCountMaxVal *= 2; + } + + VERB_LN(3, "Bits required for CA: " << bitCount); + return bitCount; } BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const -{ - // select appropriate BDD vector - vector *enc_vec; - if (succ) - enc_vec = pv_ca_succ; - else - enc_vec = pv_ca; +{ + // select appropriate BDD vector + vector *enc_vec; - assert(enc_vec != nullptr); - - BDD r = BDD_TRUE; - State val = state_id; + if (succ) { + enc_vec = pv_ca_succ; + } + else { + enc_vec = pv_ca; + } - for (unsigned int i = 0; i < totalCtxAutStateVars; ++i) - { - if (val != 0) - { - if (val % 2 == 1) - { - r *= (*enc_vec)[i]; - } - else - { - r *= !(*enc_vec)[i]; - } - val /= 2; - } - else - r *= !(*enc_vec)[i]; - } + assert(enc_vec != nullptr); - return r; + BDD r = BDD_TRUE; + State val = state_id; + + for (unsigned int i = 0; i < totalCtxAutStateVars; ++i) { + if (val != 0) { + if (val % 2 == 1) { + r *= (*enc_vec)[i]; + } + else { + r *= !(*enc_vec)[i]; + } + + val /= 2; + } + else { + r *= !(*enc_vec)[i]; + } + } + + return r; } BDD SymRS::getEncCtxAutInitState(void) { - VERB_LN(2, "Encoding context automaton's initial state"); - - State state = rs->ctx_aut->getInitState(); + VERB_LN(2, "Encoding context automaton's initial state"); - return encCtxAutState(state); + State state = rs->ctx_aut->getInitState(); + + return encCtxAutState(state); } void SymRS::encodeCtxAutTrans(void) { - VERB_LN(2, "Encoding context automaton's transition relation"); + VERB_LN(2, "Encoding context automaton's transition relation"); - if (tr_ca != nullptr) - { - VERB_LN(1, "Encoding for context automaton already present, not replacing") - return; - } - - tr_ca = new BDD(BDD_FALSE); + if (tr_ca != nullptr) { + VERB_LN(1, "Encoding for context automaton already present, not replacing") + return; + } - for (auto &t : rs->ctx_aut->transitions) - { - VERB_LN(2, "Encoding CA transition " << rs->ctx_aut->getStateName(t.src_state) - << " -> " << 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)); - - *tr_ca += enc_src * enc_ctx * enc_dst; - } + tr_ca = new BDD(BDD_FALSE); + + for (auto &t : rs->ctx_aut->transitions) { + VERB_LN(2, "Encoding CA transition " << rs->ctx_aut->getStateName(t.src_state) + << " -> " << 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)); + + *tr_ca += enc_src * enc_ctx * enc_dst; + } } /** EOF **/ diff --git a/symrs.hh b/symrs.hh index 376c559..060b819 100644 --- a/symrs.hh +++ b/symrs.hh @@ -36,11 +36,11 @@ class SymRS Cudd *cuddMgr; Options *opts; - // Mapping: entity ID -> action/context entity ID + // Mapping: entity ID -> action/context entity ID StateEntityToAction stateToAct; BDD *initStates; - + vector *pv; vector *pv_succ; BDD *pv_E; @@ -55,12 +55,12 @@ class SymRS BDD *monoTrans; - // Context automaton - vector *pv_ca; - vector *pv_ca_succ; - BDD *pv_ca_E; - BDD *pv_ca_succ_E; - BDD *tr_ca; + // Context automaton + vector *pv_ca; + vector *pv_ca_succ; + BDD *pv_ca_E; + BDD *pv_ca_succ_E; + BDD *tr_ca; vector *pv_act; BDD *pv_act_E; @@ -69,37 +69,44 @@ class SymRS unsigned int totalReactions; unsigned int totalRctSysStateVars; unsigned int totalActions; - unsigned int totalCtxAutStateVars; - + unsigned int totalCtxAutStateVars; + BDD encEntity_raw(Entity entity, bool succ) const; - BDD encEntity(Entity entity) const { - return encEntity_raw(entity, false); + BDD encEntity(Entity entity) const + { + return encEntity_raw(entity, false); } - BDD encActEntity(Entity entity) const { - assert(entity < pv_act->size()); - return (*pv_act)[entity]; + BDD encActEntity(Entity entity) const + { + assert(entity < pv_act->size()); + return (*pv_act)[entity]; } - BDD encEntitySucc(Entity entity) const { - return encEntity_raw(entity, true); + BDD encEntitySucc(Entity entity) const + { + return encEntity_raw(entity, true); } BDD encEntitiesConj_raw(const Entities &entities, bool succ); - BDD encEntitiesConj(const Entities &entities) { - return encEntitiesConj_raw(entities, false); + BDD encEntitiesConj(const Entities &entities) + { + return encEntitiesConj_raw(entities, false); } - BDD encEntitiesConjSucc(const Entities &entities) { - return encEntitiesConj_raw(entities, true); + BDD encEntitiesConjSucc(const Entities &entities) + { + return encEntitiesConj_raw(entities, true); } BDD encEntitiesDisj_raw(const Entities &entities, bool succ); - BDD encEntitiesDisj(const Entities &entities) { - return encEntitiesDisj_raw(entities, false); + BDD encEntitiesDisj(const Entities &entities) + { + return encEntitiesDisj_raw(entities, false); } - BDD encEntitiesDisjSucc(const Entities &entities) { - return encEntitiesDisj_raw(entities, true); + BDD encEntitiesDisjSucc(const Entities &entities) + { + return encEntitiesDisj_raw(entities, true); } BDD encStateActEntitiesConj(const Entities &entities); BDD encStateActEntitiesDisj(const Entities &entities); - BDD encActEntitiesConj(const Entities &entities); + BDD encActEntitiesConj(const Entities &entities); /** * @brief Complements an encoding of a given state by negating all the variables that are not set to true @@ -113,122 +120,186 @@ class SymRS std::string decodedRctSysStateToStr(const BDD &state); void printDecodedRctSysStates(const BDD &states); - BDD encNoContext(void); + BDD encNoContext(void); void initBDDvars(void); void encodeTransitions(void); void encodeTransitions_old(void); void encodeInitStates(void); - void encodeInitStatesForCtxAut(void); - void encodeInitStatesNoCtxAut(void); + void encodeInitStatesForCtxAut(void); + void encodeInitStatesNoCtxAut(void); void mapStateToAct(void); void encode(void); - int getMappedStateToActID(int stateID) const - { - assert(stateID < static_cast(totalRctSysStateVars)); - return stateToAct[stateID]; - } - - size_t getCtxAutStateEncodingSize(void); - -public: - SymRS(RctSys *rs, Options *opts); - - vector *getEncPV(void) { return pv; } - vector *getEncPVsucc(void) { return pv_succ; } - BDD *getEncPV_E(void) { return pv_E; } - BDD *getEncPVsucc_E(void) { return pv_succ_E; } - BDD *getEncPVact_E(void) { return pv_act_E; } - vector *getEncPartTrans(void) { return partTrans; } - BDD *getEncMonoTrans(void) { return monoTrans; } - BDD getEncState(const Entities &entities); - BDD *getEncInitStates(void) { return initStates; } - Cudd *getCuddMgr(void) { return cuddMgr; } - unsigned int getTotalStateVars(void) { return totalStateVars; } - unsigned int getTotalRctSysStateVars(void) { return totalRctSysStateVars; } - BDD encEntity(std::string name) const { - return encEntity(rs->getEntityID(name)); + int getMappedStateToActID(int stateID) const + { + assert(stateID < static_cast(totalRctSysStateVars)); + return stateToAct[stateID]; } - + + size_t getCtxAutStateEncodingSize(void); + + public: + SymRS(RctSys *rs, Options *opts); + + vector *getEncPV(void) + { + return pv; + } + vector *getEncPVsucc(void) + { + return pv_succ; + } + BDD *getEncPV_E(void) + { + return pv_E; + } + BDD *getEncPVsucc_E(void) + { + return pv_succ_E; + } + BDD *getEncPVact_E(void) + { + return pv_act_E; + } + vector *getEncPartTrans(void) + { + return partTrans; + } + BDD *getEncMonoTrans(void) + { + return monoTrans; + } + BDD getEncState(const Entities &entities); + BDD *getEncInitStates(void) + { + return initStates; + } + Cudd *getCuddMgr(void) + { + return cuddMgr; + } + unsigned int getTotalStateVars(void) + { + return totalStateVars; + } + unsigned int getTotalRctSysStateVars(void) + { + return totalRctSysStateVars; + } + BDD encEntity(std::string name) const + { + return encEntity(rs->getEntityID(name)); + } + BDD encActStrEntity(std::string name) const; - BDD getBDDtrue(void) const { return BDD_TRUE; } - BDD getBDDfalse(void) const { return BDD_FALSE; } - + BDD getBDDtrue(void) const + { + return BDD_TRUE; + } + BDD getBDDfalse(void) const + { + return BDD_FALSE; + } + /** * @brief Checks if context automaton is used * * @return True if CA is used */ - bool usingContextAutomaton(void) { return rs->ctx_aut != nullptr; } - + bool usingContextAutomaton(void) + { + return rs->ctx_aut != nullptr; + } + /** * @brief Encodes a context automaton's state * * @return Returns the encoded state */ - BDD encCtxAutState_raw(State state_id, bool succ) const; + BDD encCtxAutState_raw(State state_id, bool succ) const; - /** + /** * @brief Encodes a context automaton's state (as predecessor/non-primed) * * @return Returns the encoded state */ - BDD encCtxAutState(State state_id) const { return encCtxAutState_raw(state_id, false); } - + BDD encCtxAutState(State state_id) const + { + return encCtxAutState_raw(state_id, false); + } + /** * @brief Encodes a context automaton's state (as successor/primed) * * @return Returns the encoded state */ - BDD encCtxAutStateSucc(State state_id) const { return encCtxAutState_raw(state_id, true); } - + BDD encCtxAutStateSucc(State state_id) const + { + return encCtxAutState_raw(state_id, true); + } + /** * @brief Encodes the initial state of context automaton * * @return Returns the encoded state(s) */ - BDD getEncCtxAutInitState(void); - + BDD getEncCtxAutInitState(void); + /** * @brief Getter for context automaton's state variables (predecessor/non-primed) * * @return Returns a vector of BDDs */ - vector *getEncCtxAutPV(void) { return pv_ca; } + vector *getEncCtxAutPV(void) + { + return pv_ca; + } /** * @brief Getter for context automaton's successor (primed) state variables * * @return Returns a vector of BDDs */ - vector *getEncCtxAutPVsucc(void) { return pv_ca_succ; } + vector *getEncCtxAutPVsucc(void) + { + return pv_ca_succ; + } /** * @brief Getter for context automaton's quantification BDD (for non-primed vars) * - * @return Returns a BDD for quantification + * @return Returns a BDD for quantification */ - BDD *getEncCtxAutPV_E(void) { return pv_ca_E; } + BDD *getEncCtxAutPV_E(void) + { + return pv_ca_E; + } /** * @brief Getter for context automaton's quantification BDD (for primed vars) * - * @return Returns a BDD for quantification + * @return Returns a BDD for quantification */ - BDD *getEncCtxAutPVsucc_E(void) { return pv_ca_succ_E; } + BDD *getEncCtxAutPVsucc_E(void) + { + return pv_ca_succ_E; + } /** * @brief Encodes the monolithic transition relation - */ - void encodeCtxAutTrans(void); - + */ + void encodeCtxAutTrans(void); + /** * @brief Getter for context automaton's transition relation * * @return Returns a BDD encoding the transition relation - */ - BDD *getEncCtxAutTrans(void) { return tr_ca; } + */ + BDD *getEncCtxAutTrans(void) + { + return tr_ca; + } }; #endif diff --git a/types.hh b/types.hh index b431fa0..b580b95 100644 --- a/types.hh +++ b/types.hh @@ -17,9 +17,9 @@ typedef unsigned int Entity; typedef std::set Entities; struct Reaction { - Entities rctt; - Entities inhib; - Entities prod; + Entities rctt; + Entities inhib; + Entities prod; }; typedef unsigned int Process; @@ -40,18 +40,18 @@ typedef std::map StatesByName; typedef std::map EntitiesForProc; struct ReactionCond { - Entities rctt; - Entities inhib; + Entities rctt; + Entities inhib; }; typedef std::vector ReactionConds; -typedef std::map DecompReactions; +typedef std::map DecompReactions; typedef std::vector StateEntityToAction; struct CtxAutTransition { - State src_state; - Entities ctx; - State dst_state; + State src_state; + Entities ctx; + State dst_state; }; typedef std::vector CtxAutTransitions; From 38683e1041674291a98a65f00a48c46045ae1fe0 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 28 Mar 2018 21:02:46 +0100 Subject: [PATCH 06/90] Makefile update --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index a75b776..4704169 100644 --- a/Makefile +++ b/Makefile @@ -43,3 +43,8 @@ rsin_parser.lex.cc: rsin_parser.ll flex rsin_parser.ll mv lex.yy.c rsin_parser.lex.cc +style: + astyle --max-code-length=78 --break-closing-brackets --convert-tabs --add-brackets --max-instatement-indent=40 -s2 -C -xG -S -f -p -H -k1 -c --style=kr --align-pointer=name *.cc *.hh + +commit: style + git commit -a From 212321c6cbc5bf3e29d13cf8d59709ff0182951b Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Thu, 29 Mar 2018 17:01:28 +0100 Subject: [PATCH 07/90] Parsing, printing... Context in CA --- ctx_aut.cc | 15 +++++++++++---- ctx_aut.hh | 5 ++--- main.hh | 5 +---- rs.cc | 36 +++++++++++++++++++++++++++--------- rs.hh | 5 ++++- rsin_parser.ll | 22 +++++++++++----------- rsin_parser.yy | 18 ++++++++++++------ symrs.cc | 3 ++- types.hh | 2 +- 9 files changed, 71 insertions(+), 40 deletions(-) diff --git a/ctx_aut.cc b/ctx_aut.cc index 1354b53..9889ef5 100644 --- a/ctx_aut.cc +++ b/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; } } diff --git a/ctx_aut.hh b/ctx_aut.hh index d5c143e..e756dad 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -1,9 +1,6 @@ /* Copyright (c) 2018 Artur Meski - - 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; }; diff --git a/main.hh b/main.hh index 5d95f44..b359869 100644 --- a/main.hh +++ b/main.hh @@ -1,9 +1,6 @@ /* - Copyright (c) 2012, 2013 + Copyright (c) 2012, 2013, 2018 Artur Meski - - Reuse of the code or its part for any purpose - without the author's permission is strictly prohibited. */ #ifndef RS_MAIN_HH diff --git a/rs.cc b/rs.cc index 684aa4d..2e10ffb 100644 --- a/rs.cc +++ b/rs.cc @@ -1,9 +1,6 @@ /* - Copyright (c) 2012-2014 + Copyright (c) 2012-2018 Artur Meski - - 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 **/ diff --git a/rs.hh b/rs.hh index c1f184a..b8b256d 100644 --- a/rs.hh +++ b/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,7 +92,8 @@ 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) { return initStates.size() != 0; diff --git a/rsin_parser.ll b/rsin_parser.ll index 8ecb732..8bf8600 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -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; diff --git a/rsin_parser.yy b/rsin_parser.yy index 02458e7..a702f17 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -106,8 +106,10 @@ option: */ reactionsets: - | processname LCB reactions RCB SEMICOL + | reactionsets process_reactions ; + +process_reactions: processname LCB reactions RCB SEMICOL processname: IDENTIFIER { driver.getReactionSystem()->setCurrentProcess(*$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 ; diff --git a/symrs.cc b/symrs.cc index aef6158..c64e0e1 100644 --- a/symrs.cc +++ b/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; } diff --git a/types.hh b/types.hh index b580b95..cbe98a0 100644 --- a/types.hh +++ b/types.hh @@ -50,7 +50,7 @@ typedef std::vector StateEntityToAction; struct CtxAutTransition { State src_state; - Entities ctx; + EntitiesForProc ctx; State dst_state; }; From bac84bfe9a7489ba4d7bffb055c10f1707632bb2 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Thu, 29 Mar 2018 17:02:55 +0100 Subject: [PATCH 08/90] Formatting --- Makefile | 2 +- ctx_aut.cc | 3 +++ rs.cc | 11 ++++++++--- rs.hh | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4704169..2540cf9 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ cleanly: rm -f *.lex.cc *.lex.o location.hh stack.hh position.hh rsin_parser.cc rsin_parser.hh clean: cleanly - rm -f *.o main *~ makefile.dep tags + rm -f *.o main *.orig *~ makefile.dep tags cleanall: clean diff --git a/ctx_aut.cc b/ctx_aut.cc index 9889ef5..11e30d8 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -73,6 +73,7 @@ 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; } @@ -88,6 +89,7 @@ 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(); } @@ -108,6 +110,7 @@ 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) diff --git a/rs.cc b/rs.cc index 2e10ffb..99b85d8 100644 --- a/rs.cc +++ b/rs.cc @@ -96,6 +96,7 @@ bool RctSys::hasProcess(Process processID) if (processID >= processes_ids.size()) { return false; } + return true; } @@ -104,6 +105,7 @@ Process RctSys::getProcessID(std::string processName) if (!hasProcess(processName)) { FERROR("No such process: " << processName); } + return processes_names[processName]; } @@ -122,6 +124,7 @@ void RctSys::pushReactant(std::string entityName) if (!hasEntity(entityName)) { addEntity(entityName); } + tmpReactants.insert(getEntityID(entityName)); } void RctSys::pushInhibitor(std::string entityName) @@ -129,6 +132,7 @@ void RctSys::pushInhibitor(std::string entityName) if (!hasEntity(entityName)) { addEntity(entityName); } + tmpInhibitors.insert(getEntityID(entityName)); } void RctSys::pushProduct(std::string entityName) @@ -136,6 +140,7 @@ void RctSys::pushProduct(std::string entityName) if (!hasEntity(entityName)) { addEntity(entityName); } + tmpProducts.insert(getEntityID(entityName)); } @@ -179,11 +184,11 @@ std::string RctSys::entitiesToStr(const Entities &entities) std::string RctSys::procEntitiesToStr(const EntitiesForProc &procEntities) { std::string s = " "; - - for (auto const &p : procEntities) - { + + for (auto const &p : procEntities) { s += getProcessName(p.first) + "={" + entitiesToStr(p.second) + "} "; } + return s; } diff --git a/rs.hh b/rs.hh index b8b256d..0247a24 100644 --- a/rs.hh +++ b/rs.hh @@ -93,7 +93,7 @@ class RctSys void ctxAutAddTransition(std::string srcStateName, std::string dstStateName); void ctxAutPushNamedContextEntity(std::string entity_name); void ctxAutSaveCurrentContextSet(std::string processName); - + bool initStatesDefined(void) { return initStates.size() != 0; From e3ed26e4a1d77d181749b08f7c72ceb917cc0fdc Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Fri, 30 Mar 2018 17:51:29 +0100 Subject: [PATCH 09/90] Entities used per process (in reactions) --- macro.hh | 3 + symrs.cc | 102 +++++++++++++++++-------- symrs.hh | 223 +++++++++++++++++++++++++++++-------------------------- 3 files changed, 190 insertions(+), 138 deletions(-) diff --git a/macro.hh b/macro.hh index 27934c8..1e86fac 100644 --- a/macro.hh +++ b/macro.hh @@ -39,4 +39,7 @@ if (opts->verbose >= (n)) { \ std::cerr << "ii VERBOSE(" << (n) << "): " << __FILE__ << " (" << __func__ << ":" << __LINE__ << "): " << s << std::endl; \ } + +#define SET_ADD(set1, set2) (set1).insert((set2).begin(), (set2).end()) + #endif diff --git a/symrs.cc b/symrs.cc index c64e0e1..3044b3a 100644 --- a/symrs.cc +++ b/symrs.cc @@ -28,6 +28,77 @@ SymRS::SymRS(RctSys *rs, Options *opts) encode(); } +void SymRS::encode(void) +{ + VERB("Encoding..."); + + if (opts->measure) { + opts->enc_time = cpuTime(); + opts->enc_mem = memUsed(); + } + + mapStateToAct(); + + mapProcEntities(); + + initBDDvars(); + + if (usingContextAutomaton()) { + encodeCtxAutTrans(); + } + else { + VERB_LN(3, "Not using context automata, not encoding TR for CA") + } + + encodeTransitions(); + encodeInitStates(); + + if (opts->measure) { + opts->enc_time = cpuTime() - opts->enc_time; + opts->enc_mem = memUsed() - opts->enc_mem; + } + + VERB("Encoding done"); +} + +void SymRS::mapProcEntities(void) +{ + + // Reactions + + for (const auto &proc_rcts : rs->proc_reactions) { + Process proc_id = proc_rcts.first; + + for (const auto &rct : proc_rcts.second) { + + // collect entities that can be produced + // locally by the process with proc_id + + SET_ADD(usedEntities[proc_id], rct.prod); + } + } + + // Context automaton + // for () + + printUsedEntitiesPerProc(); + +} + +void SymRS::printUsedEntitiesPerProc(void) +{ + for (const auto &proc_entities : usedEntities) { + std::string proc_name = rs->getProcessName(proc_entities.first); + cout << proc_name << ": "; + + for (const auto &ent : proc_entities.second) { + cout << rs->getEntityName(ent) << " "; + } + + cout << endl; + } +} + BDD SymRS::encEntity_raw(Entity entity, bool succ) const { BDD r; @@ -455,37 +526,6 @@ void SymRS::mapStateToAct(void) } } -void SymRS::encode(void) -{ - VERB("Encoding..."); - - if (opts->measure) { - opts->enc_time = cpuTime(); - opts->enc_mem = memUsed(); - } - - mapStateToAct(); - - initBDDvars(); - - if (usingContextAutomaton()) { - encodeCtxAutTrans(); - } - else { - VERB_LN(3, "Not using context automata, not encoding TR for CA") - } - - encodeTransitions(); - encodeInitStates(); - - if (opts->measure) { - opts->enc_time = cpuTime() - opts->enc_time; - opts->enc_mem = memUsed() - opts->enc_mem; - } - - VERB("Encoding done"); -} - BDD SymRS::encActStrEntity(std::string name) const { int id = getMappedStateToActID(rs->getEntityID(name)); diff --git a/symrs.hh b/symrs.hh index 060b819..63d6fd1 100644 --- a/symrs.hh +++ b/symrs.hh @@ -32,113 +32,6 @@ class SymRS friend class ModelChecker; friend class FormRSCTL; - RctSys *rs; - Cudd *cuddMgr; - Options *opts; - - // Mapping: entity ID -> action/context entity ID - StateEntityToAction stateToAct; - - BDD *initStates; - - vector *pv; - vector *pv_succ; - BDD *pv_E; - BDD *pv_succ_E; - - vector *pv_rs; - vector *pv_rs_succ; - BDD *pv_rs_E; - BDD *pv_rs_succ_E; - - vector *partTrans; - - BDD *monoTrans; - - // Context automaton - vector *pv_ca; - vector *pv_ca_succ; - BDD *pv_ca_E; - BDD *pv_ca_succ_E; - BDD *tr_ca; - - vector *pv_act; - BDD *pv_act_E; - - unsigned int totalStateVars; - unsigned int totalReactions; - unsigned int totalRctSysStateVars; - unsigned int totalActions; - unsigned int totalCtxAutStateVars; - - BDD encEntity_raw(Entity entity, bool succ) const; - BDD encEntity(Entity entity) const - { - return encEntity_raw(entity, false); - } - BDD encActEntity(Entity entity) const - { - assert(entity < pv_act->size()); - return (*pv_act)[entity]; - } - BDD encEntitySucc(Entity entity) const - { - return encEntity_raw(entity, true); - } - BDD encEntitiesConj_raw(const Entities &entities, bool succ); - BDD encEntitiesConj(const Entities &entities) - { - return encEntitiesConj_raw(entities, false); - } - BDD encEntitiesConjSucc(const Entities &entities) - { - return encEntitiesConj_raw(entities, true); - } - BDD encEntitiesDisj_raw(const Entities &entities, bool succ); - BDD encEntitiesDisj(const Entities &entities) - { - return encEntitiesDisj_raw(entities, false); - } - BDD encEntitiesDisjSucc(const Entities &entities) - { - return encEntitiesDisj_raw(entities, true); - } - BDD encStateActEntitiesConj(const Entities &entities); - BDD encStateActEntitiesDisj(const Entities &entities); - - BDD encActEntitiesConj(const Entities &entities); - - /** - * @brief Complements an encoding of a given state by negating all the variables that are not set to true - * - * @return Returns the encoded state - */ - BDD compState(const BDD &state) const; - - BDD compContext(const BDD &context) const; - - std::string decodedRctSysStateToStr(const BDD &state); - void printDecodedRctSysStates(const BDD &states); - - BDD encNoContext(void); - - void initBDDvars(void); - void encodeTransitions(void); - void encodeTransitions_old(void); - void encodeInitStates(void); - void encodeInitStatesForCtxAut(void); - void encodeInitStatesNoCtxAut(void); - void mapStateToAct(void); - void encode(void); - - int getMappedStateToActID(int stateID) const - { - assert(stateID < static_cast(totalRctSysStateVars)); - return stateToAct[stateID]; - } - - size_t getCtxAutStateEncodingSize(void); - public: SymRS(RctSys *rs, Options *opts); @@ -300,6 +193,122 @@ class SymRS { return tr_ca; } + + private: + + RctSys *rs; + Cudd *cuddMgr; + Options *opts; + + // Mapping: entity ID -> action/context entity ID + StateEntityToAction stateToAct; + + BDD *initStates; + + vector *pv; + vector *pv_succ; + BDD *pv_E; + BDD *pv_succ_E; + + vector *pv_rs; + vector *pv_rs_succ; + BDD *pv_rs_E; + BDD *pv_rs_succ_E; + + vector *partTrans; + + BDD *monoTrans; + + // Context automaton + vector *pv_ca; + vector *pv_ca_succ; + BDD *pv_ca_E; + BDD *pv_ca_succ_E; + BDD *tr_ca; + + vector *pv_act; + BDD *pv_act_E; + + unsigned int totalStateVars; + unsigned int totalReactions; + unsigned int totalRctSysStateVars; + unsigned int totalActions; + unsigned int totalCtxAutStateVars; + + EntitiesForProc usedEntities; + + BDD encEntity_raw(Entity entity, bool succ) const; + BDD encEntity(Entity entity) const + { + return encEntity_raw(entity, false); + } + BDD encActEntity(Entity entity) const + { + assert(entity < pv_act->size()); + return (*pv_act)[entity]; + } + BDD encEntitySucc(Entity entity) const + { + return encEntity_raw(entity, true); + } + BDD encEntitiesConj_raw(const Entities &entities, bool succ); + BDD encEntitiesConj(const Entities &entities) + { + return encEntitiesConj_raw(entities, false); + } + BDD encEntitiesConjSucc(const Entities &entities) + { + return encEntitiesConj_raw(entities, true); + } + BDD encEntitiesDisj_raw(const Entities &entities, bool succ); + BDD encEntitiesDisj(const Entities &entities) + { + return encEntitiesDisj_raw(entities, false); + } + BDD encEntitiesDisjSucc(const Entities &entities) + { + return encEntitiesDisj_raw(entities, true); + } + BDD encStateActEntitiesConj(const Entities &entities); + BDD encStateActEntitiesDisj(const Entities &entities); + + BDD encActEntitiesConj(const Entities &entities); + + /** + * @brief Complements an encoding of a given state by negating all the variables that are not set to true + * + * @return Returns the encoded state + */ + BDD compState(const BDD &state) const; + + BDD compContext(const BDD &context) const; + + std::string decodedRctSysStateToStr(const BDD &state); + void printDecodedRctSysStates(const BDD &states); + + BDD encNoContext(void); + + void initBDDvars(void); + void encodeTransitions(void); + void encodeTransitions_old(void); + void encodeInitStates(void); + void encodeInitStatesForCtxAut(void); + void encodeInitStatesNoCtxAut(void); + void mapStateToAct(void); + void mapProcEntities(void); + void encode(void); + + void printUsedEntitiesPerProc(void); + + int getMappedStateToActID(int stateID) const + { + assert(stateID < static_cast(totalRctSysStateVars)); + return stateToAct[stateID]; + } + + size_t getCtxAutStateEncodingSize(void); + + }; #endif From c89e33686255597266837f3989e82dca6b993a2a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Fri, 30 Mar 2018 18:30:08 +0100 Subject: [PATCH 10/90] Printing of entities per proc --- rs.cc | 14 ++++++++++++++ rs.hh | 2 ++ symrs.cc | 19 ++++--------------- symrs.hh | 5 ++--- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/rs.cc b/rs.cc index 99b85d8..4070708 100644 --- a/rs.cc +++ b/rs.cc @@ -119,6 +119,20 @@ std::string RctSys::getProcessName(Process processID) } } +void RctSys::printEntitiesPerProc(const EntitiesForProc &proc_entities) +{ + for (const auto &pe : proc_entities) { + std::string proc_name = getProcessName(pe.first); + cout << proc_name << ": "; + + for (const auto &ent : pe.second) { + cout << getEntityName(ent) << " "; + } + + cout << endl; + } +} + void RctSys::pushReactant(std::string entityName) { if (!hasEntity(entityName)) { diff --git a/rs.hh b/rs.hh index 0247a24..e50efec 100644 --- a/rs.hh +++ b/rs.hh @@ -49,6 +49,8 @@ class RctSys Process getProcessID(std::string processName); std::string getProcessName(Process processID); + void printEntitiesPerProc(const EntitiesForProc &proc_entities); + void addReactionForCurrentProcess(Reaction reaction); void pushReactant(std::string entityName); diff --git a/symrs.cc b/symrs.cc index 3044b3a..1c35d7e 100644 --- a/symrs.cc +++ b/symrs.cc @@ -74,30 +74,19 @@ void SymRS::mapProcEntities(void) // collect entities that can be produced // locally by the process with proc_id - SET_ADD(usedEntities[proc_id], rct.prod); + SET_ADD(usedProducts[proc_id], rct.prod); } } // Context automaton - // for () - printUsedEntitiesPerProc(); + // for (const ) + // usedCtxEntities + rs->printEntitiesPerProc(usedProducts); } -void SymRS::printUsedEntitiesPerProc(void) -{ - for (const auto &proc_entities : usedEntities) { - std::string proc_name = rs->getProcessName(proc_entities.first); - cout << proc_name << ": "; - for (const auto &ent : proc_entities.second) { - cout << rs->getEntityName(ent) << " "; - } - - cout << endl; - } -} BDD SymRS::encEntity_raw(Entity entity, bool succ) const { diff --git a/symrs.hh b/symrs.hh index 63d6fd1..7cdeb6b 100644 --- a/symrs.hh +++ b/symrs.hh @@ -235,7 +235,8 @@ class SymRS unsigned int totalActions; unsigned int totalCtxAutStateVars; - EntitiesForProc usedEntities; + EntitiesForProc usedProducts; + EntitiesForProc usedCtxEntities; BDD encEntity_raw(Entity entity, bool succ) const; BDD encEntity(Entity entity) const @@ -298,8 +299,6 @@ class SymRS void mapProcEntities(void); void encode(void); - void printUsedEntitiesPerProc(void); - int getMappedStateToActID(int stateID) const { assert(stateID < static_cast(totalRctSysStateVars)); From dc241ebf78487995244ad9c8a694e0f2b32c87f1 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Fri, 30 Mar 2018 18:32:34 +0100 Subject: [PATCH 11/90] Cleanup --- rs.cc | 14 -------------- rs.hh | 2 -- symrs.cc | 5 ++--- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/rs.cc b/rs.cc index 4070708..99b85d8 100644 --- a/rs.cc +++ b/rs.cc @@ -119,20 +119,6 @@ std::string RctSys::getProcessName(Process processID) } } -void RctSys::printEntitiesPerProc(const EntitiesForProc &proc_entities) -{ - for (const auto &pe : proc_entities) { - std::string proc_name = getProcessName(pe.first); - cout << proc_name << ": "; - - for (const auto &ent : pe.second) { - cout << getEntityName(ent) << " "; - } - - cout << endl; - } -} - void RctSys::pushReactant(std::string entityName) { if (!hasEntity(entityName)) { diff --git a/rs.hh b/rs.hh index e50efec..0247a24 100644 --- a/rs.hh +++ b/rs.hh @@ -49,8 +49,6 @@ class RctSys Process getProcessID(std::string processName); std::string getProcessName(Process processID); - void printEntitiesPerProc(const EntitiesForProc &proc_entities); - void addReactionForCurrentProcess(Reaction reaction); void pushReactant(std::string entityName); diff --git a/symrs.cc b/symrs.cc index 1c35d7e..17b1ebe 100644 --- a/symrs.cc +++ b/symrs.cc @@ -83,11 +83,10 @@ void SymRS::mapProcEntities(void) // for (const ) // usedCtxEntities - rs->printEntitiesPerProc(usedProducts); + cout << rs->procEntitiesToStr(usedProducts) << endl; + } - - BDD SymRS::encEntity_raw(Entity entity, bool succ) const { BDD r; From 04d2b628f58d2d6d92c13af15942b07fbfb9eaea Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Fri, 30 Mar 2018 20:07:24 +0100 Subject: [PATCH 12/90] 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; From a74bc58a0c9db08489ccea4907d5c0baad87fabc Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 1 Apr 2018 20:59:10 +0100 Subject: [PATCH 13/90] Initialisation of BDD variables --- Makefile | 2 +- rs.hh | 5 + symrs.cc | 282 ++++++++++++++++++++++++++++++++++++++----------------- symrs.hh | 60 +++++++----- types.hh | 3 + 5 files changed, 240 insertions(+), 112 deletions(-) diff --git a/Makefile b/Makefile index 2540cf9..2491bc7 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ rsin_parser.lex.cc: rsin_parser.ll mv lex.yy.c rsin_parser.lex.cc style: - astyle --max-code-length=78 --break-closing-brackets --convert-tabs --add-brackets --max-instatement-indent=40 -s2 -C -xG -S -f -p -H -k1 -c --style=kr --align-pointer=name *.cc *.hh + astyle --max-code-length=130 --break-closing-brackets --convert-tabs --add-brackets --max-instatement-indent=40 -s2 -C -xG -S -f -p -H -k1 -c --style=kr --align-pointer=name *.cc *.hh commit: style git commit -a diff --git a/rs.hh b/rs.hh index 0247a24..233969f 100644 --- a/rs.hh +++ b/rs.hh @@ -103,6 +103,11 @@ class RctSys return ctx_aut != nullptr; } + size_t getNumberOfProcesses(void) + { + return processes_ids.size(); + } + private: Reactions reactions; // TODO: to be removed later ReactionsForProc proc_reactions; diff --git a/symrs.cc b/symrs.cc index 98d51d5..c309fae 100644 --- a/symrs.cc +++ b/symrs.cc @@ -10,13 +10,19 @@ SymRS::SymRS(RctSys *rs, Options *opts) { this->rs = rs; this->opts = opts; - totalRctSysStateVars = rs->getEntitiesSize(); + + mapProcEntities(); + + // TODO: remove + totalActions = 0; + + totalRctSysStateVars = getTotalProductVariables(); totalReactions = rs->getReactionsSize(); - totalActions = rs->getActionsSize(); + totalCtxEntities = getTotalCtxEntitiesVariables(); totalCtxAutStateVars = getCtxAutStateEncodingSize(); - totalStateVars = totalRctSysStateVars + totalCtxAutStateVars; + numberOfProc = rs->getNumberOfProcesses(); partTrans = nullptr; monoTrans = nullptr; @@ -39,8 +45,6 @@ void SymRS::encode(void) mapStateToAct(); - mapProcEntities(); - initBDDvars(); if (usingContextAutomaton()) { @@ -78,6 +82,188 @@ LocalIndicesForProcEntities SymRS::buildLocalEntitiesMap( return ent_map; } +void SymRS::initBDDvars(void) +{ + VERB("Initialising CUDD"); + + cuddMgr = new Cudd(0, 0); + + VERB("Preparing BDD variables"); + + // used for bddVar + unsigned int bdd_var_idx = 0; + + // used for pv, pv_succ + unsigned int global_state_idx = 0; + + // ---------------------------------------------------------- + // Global state + // ---------------------------------------------------------- + // + // Variables for reaction system with CA (if used) + // + + pv = new BDDvec(totalStateVars); + pv_succ = new BDDvec(totalStateVars); + pv_E = new BDD(BDD_TRUE); + pv_succ_E = new BDD(BDD_TRUE); + + // ---------------------------------------------------------- + // Distributed RS + // ---------------------------------------------------------- + + // // Reaction system (no actions, no CA) + // pv_rs = new BDDvec(totalRctSysStateVars); + // pv_rs_succ = new BDDvec(totalRctSysStateVars); + // pv_rs_E = new BDD(BDD_TRUE); + // pv_rs_succ_E = new BDD(BDD_TRUE); + + pv_drs = new vector(numberOfProc); + pv_drs_succ = new vector(numberOfProc); + + pv_drs_flat = new BDDvec(totalRctSysStateVars); + pv_drs_flat_succ = new BDDvec(totalRctSysStateVars); + + pv_drs_flat_E = new BDD(BDD_TRUE); + pv_drs_flat_succ_E = new BDD(BDD_TRUE); + + VERB_LN(3, "DRS processing"); + + unsigned int drs_flat_index = 0; + + for (const auto &proc_ent : usedProducts) { + + auto proc_id = proc_ent.first; + auto entities_count = proc_ent.second.size(); + + // + // The order of entities and their correspondence to the + // correct entities in pv (global) does not matter here. + // + // The correspondence is established in the methods + // returning BDD variables (encoding) of the individual + // enties. + // + // We only need to make sure we have the correct number of + // variables that are going to be used in the encoding. + // + // For efficiency, we do not introduce BDD variables for + // entites that are never produced in a given local component. + // Instead, we only select those that are. We apply the same + // strategy to product entities and context entities. + // + + // First, we need to adjust the sizes of all the nested vectors + (*pv_drs)[proc_id].resize(entities_count); + (*pv_drs_succ)[proc_id].resize(entities_count); + + for (unsigned int i = 0; i < entities_count; ++i) { + + assert(drs_flat_index < totalRctSysStateVars); + assert(global_state_idx < totalStateVars); + assert(proc_id < numberOfProc); + assert(i < rs->getEntitiesSize()); + + // Variables for each individual process/component + (*pv_drs)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); + (*pv_drs_succ)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); + + // The DRS part of the system (flattened): these vars do not include CA + (*pv_drs_flat)[drs_flat_index] = (*pv_drs)[proc_id][i]; + (*pv_drs_flat_succ)[drs_flat_index] = (*pv_drs_succ)[proc_id][i]; + ++drs_flat_index; + + // Variables used for the global states + (*pv)[global_state_idx] = (*pv_drs)[proc_id][i]; + (*pv_succ)[global_state_idx] = (*pv_drs_succ)[proc_id][i]; + ++global_state_idx; + } + } + + // ---------------------------------------------------------- + // Context Automaton + // ---------------------------------------------------------- + + if (usingContextAutomaton()) { + VERB("Context automaton variables"); + + pv_ca = new BDDvec(totalCtxAutStateVars); + pv_ca_succ = new BDDvec(totalCtxAutStateVars); + pv_ca_E = new BDD(BDD_TRUE); + pv_ca_succ_E = new BDD(BDD_TRUE); + + for (unsigned int i = 0; i < totalCtxAutStateVars; ++i) { + (*pv_ca)[i] = cuddMgr->bddVar(bdd_var_idx++); + (*pv_ca_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); + *pv_ca_E *= (*pv_ca)[i]; + *pv_ca_succ_E *= (*pv_ca_succ)[i]; + + (*pv)[global_state_idx] = (*pv_ca)[i]; + (*pv_succ)[global_state_idx] = (*pv_ca_succ)[i]; + ++global_state_idx; + } + } + + // ---------------------------------------------------------- + // Enabledness of processes + // ---------------------------------------------------------- + // + // These variables indicate which process is + // allowed to perform action + // + pv_proc_enab = new BDDvec(numberOfProc); + + for (unsigned int i = 0; i < numberOfProc; ++i) { + (*pv_proc_enab)[i] = cuddMgr->bddVar(bdd_var_idx++); + } + + // Actions/Contexts + pv_act = new BDDvec(totalActions); + pv_act_E = new BDD(BDD_TRUE); + + // TODO + // Actions need also per-process PV and flattened PV + + for (unsigned int i = 0; i < totalActions; ++i) { + (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); + *pv_act_E *= (*pv_act)[i]; + } + + // Quantification BDDs + + *pv_E = *pv_rs_E; + *pv_succ_E = *pv_rs_succ_E; + + if (usingContextAutomaton()) { + *pv_E *= *pv_ca_E; + *pv_succ_E *= *pv_ca_succ_E; + } + + VERB("All BDD variables ready"); +} + +size_t SymRS::getTotalProductVariables(void) +{ + size_t total = 0; + + for (const auto &it : usedProducts) { + total += it.second.size(); + } + + return total; +} + +size_t SymRS::getTotalCtxEntitiesVariables(void) +{ + size_t total = 0; + + for (const auto &it : usedCtxEntities) { + total += it.second.size(); + } + + return total; +} + void SymRS::mapProcEntities(void) { // @@ -256,7 +442,7 @@ void SymRS::printDecodedRctSysStates(const BDD &states) cout << decodedRctSysStateToStr(t) << endl; if (opts->verbose > 9) { - t.PrintMinterm(); + BDD_PRINT(t); cout << endl; } @@ -264,86 +450,6 @@ void SymRS::printDecodedRctSysStates(const BDD &states) } } -void SymRS::initBDDvars(void) -{ - VERB("Initialising CUDD"); - - cuddMgr = new Cudd(0, 0); - - VERB("Preparing BDD variables"); - - // used for bddVar - unsigned int bdd_var_idx = 0; - - // used for pv, pv_succ - unsigned int global_state_idx = 0; - - // Variables for reaction system with CA (if used) - pv = new vector(totalStateVars); - pv_succ = new vector(totalStateVars); - pv_E = new BDD(BDD_TRUE); - pv_succ_E = new BDD(BDD_TRUE); - - // Reaction system (no actions, no CA) - pv_rs = new vector(totalRctSysStateVars); - pv_rs_succ = new vector(totalRctSysStateVars); - pv_rs_E = new BDD(BDD_TRUE); - pv_rs_succ_E = new BDD(BDD_TRUE); - - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { - (*pv_rs)[i] = cuddMgr->bddVar(bdd_var_idx++); - (*pv_rs_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_rs_E *= (*pv_rs)[i]; - *pv_rs_succ_E *= (*pv_rs_succ)[i]; - - (*pv)[global_state_idx] = (*pv_rs)[i]; - (*pv_succ)[global_state_idx] = (*pv_rs_succ)[i]; - ++global_state_idx; - } - - // CA - if (usingContextAutomaton()) { - VERB("Context automaton variables"); - - pv_ca = new vector(totalCtxAutStateVars); - pv_ca_succ = new vector(totalCtxAutStateVars); - pv_ca_E = new BDD(BDD_TRUE); - pv_ca_succ_E = new BDD(BDD_TRUE); - - for (unsigned int i = 0; i < totalCtxAutStateVars; ++i) { - (*pv_ca)[i] = cuddMgr->bddVar(bdd_var_idx++); - (*pv_ca_succ)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_ca_E *= (*pv_ca)[i]; - *pv_ca_succ_E *= (*pv_ca_succ)[i]; - - (*pv)[global_state_idx] = (*pv_ca)[i]; - (*pv_succ)[global_state_idx] = (*pv_ca_succ)[i]; - ++global_state_idx; - } - } - - // Actions/Contexts - pv_act = new vector(totalActions); - pv_act_E = new BDD(BDD_TRUE); - - for (unsigned int i = 0; i < totalActions; ++i) { - (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_act_E *= (*pv_act)[i]; - } - - // Quantification BDDs - - *pv_E = *pv_rs_E; - *pv_succ_E = *pv_rs_succ_E; - - if (usingContextAutomaton()) { - *pv_E *= *pv_ca_E; - *pv_succ_E *= *pv_ca_succ_E; - } - - VERB("All BDD variables ready"); -} - void SymRS::encodeTransitions(void) { DecompReactions dr; @@ -365,7 +471,7 @@ void SymRS::encodeTransitions(void) if (opts->part_tr_rel) { VERB("Using partitioned transition relation encoding"); - partTrans = new vector(totalRctSysStateVars); + partTrans = new BDDvec(totalRctSysStateVars); } else { VERB("Using monolithic transition relation encoding"); @@ -575,7 +681,7 @@ size_t SymRS::getCtxAutStateEncodingSize(void) BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const { // select appropriate BDD vector - vector *enc_vec; + BDDvec *enc_vec; if (succ) { enc_vec = pv_ca_succ; diff --git a/symrs.hh b/symrs.hh index 56db27e..b1385d8 100644 --- a/symrs.hh +++ b/symrs.hh @@ -35,11 +35,11 @@ class SymRS public: SymRS(RctSys *rs, Options *opts); - vector *getEncPV(void) + BDDvec *getEncPV(void) { return pv; } - vector *getEncPVsucc(void) + BDDvec *getEncPVsucc(void) { return pv_succ; } @@ -55,7 +55,7 @@ class SymRS { return pv_act_E; } - vector *getEncPartTrans(void) + BDDvec *getEncPartTrans(void) { return partTrans; } @@ -144,7 +144,7 @@ class SymRS * * @return Returns a vector of BDDs */ - vector *getEncCtxAutPV(void) + BDDvec *getEncCtxAutPV(void) { return pv_ca; } @@ -154,7 +154,7 @@ class SymRS * * @return Returns a vector of BDDs */ - vector *getEncCtxAutPVsucc(void) + BDDvec *getEncCtxAutPVsucc(void) { return pv_ca_succ; } @@ -200,48 +200,62 @@ class SymRS Cudd *cuddMgr; Options *opts; - // Mapping: entity ID -> action/context entity ID - StateEntityToAction stateToAct; + StateEntityToAction + stateToAct; /*!< Mapping: entity ID -> action/context entity ID */ - BDD *initStates; + BDD *initStates; /*!< BDD with initial states encoded */ - vector *pv; - vector *pv_succ; + BDDvec *pv; /*!< PVs for the global state (all the variables, flat) */ + BDDvec *pv_succ; BDD *pv_E; BDD *pv_succ_E; - vector *pv_rs; - vector *pv_rs_succ; + BDDvec *pv_proc_enab; /*!< Variables indicating if a process is enabled */ + + BDDvec *pv_rs; + BDDvec *pv_rs_succ; + BDD *pv_rs_E; BDD *pv_rs_succ_E; - vector *partTrans; + vector *pv_drs; /*!< PVs for the product part of state + (per DRS process) */ + vector *pv_drs_succ; /*!< PVs for the product (successor) + part of state (per DRS process) */ + + BDDvec *pv_drs_flat; /*!< PVs for the DRS product part of state (flat) */ + BDDvec *pv_drs_flat_succ; /*!< PVs for the DRS product (successor) part of state (flat) */ + + BDDvec *partTrans; BDD *monoTrans; // Context automaton - vector *pv_ca; - vector *pv_ca_succ; + BDDvec *pv_ca; + BDDvec *pv_ca_succ; BDD *pv_ca_E; BDD *pv_ca_succ_E; BDD *tr_ca; - vector *pv_act; + BDDvec *pv_act; BDD *pv_act_E; + unsigned int numberOfProc; /*!< The number of DRS processes */ unsigned int totalStateVars; unsigned int totalReactions; - unsigned int totalRctSysStateVars; + unsigned int totalRctSysStateVars; /*!< Total number of different entities produced by reactions */ + unsigned int totalCtxEntities; /*!< Total number of different process-context entities used */ unsigned int totalActions; unsigned int totalCtxAutStateVars; - EntitiesForProc usedProducts; - EntitiesForProc usedCtxEntities; + EntitiesForProc usedProducts; /*!< Entities used in products (per process) */ + EntitiesForProc usedCtxEntities; /*!< Entities used in context sets (per process) */ - // Local indices for each entity (per process): - // separete for state/product entities and context - LocalIndicesForProcEntities prod_ent_local_idx; - LocalIndicesForProcEntities ctx_ent_local_idx; + LocalIndicesForProcEntities prod_ent_local_idx; /*!< Local indices for each entity (per process): product entities */ + LocalIndicesForProcEntities ctx_ent_local_idx; /*!< Local indices for each entity (per process): context entities */ + + size_t getTotalProductVariables(void); + size_t getTotalCtxEntitiesVariables(void); BDD encEntity_raw(Entity entity, bool succ) const; BDD encEntity(Entity entity) const diff --git a/types.hh b/types.hh index 57bea19..8cb55c8 100644 --- a/types.hh +++ b/types.hh @@ -13,6 +13,9 @@ #include #include #include +#include "cudd.hh" + +typedef std::vector BDDvec; typedef unsigned int Entity; typedef std::set Entities; From f73ebdd4bf7289b9f84e3146183d9cedc2df889a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 2 Apr 2018 14:44:44 +0100 Subject: [PATCH 14/90] BDD initialisation --- symrs.cc | 95 ++++++++++++++++++++++++++++++++++++++++++-------------- symrs.hh | 20 ++++++++---- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/symrs.cc b/symrs.cc index c309fae..08c5429 100644 --- a/symrs.cc +++ b/symrs.cc @@ -112,12 +112,6 @@ void SymRS::initBDDvars(void) // Distributed RS // ---------------------------------------------------------- - // // Reaction system (no actions, no CA) - // pv_rs = new BDDvec(totalRctSysStateVars); - // pv_rs_succ = new BDDvec(totalRctSysStateVars); - // pv_rs_E = new BDD(BDD_TRUE); - // pv_rs_succ_E = new BDD(BDD_TRUE); - pv_drs = new vector(numberOfProc); pv_drs_succ = new vector(numberOfProc); @@ -127,7 +121,7 @@ void SymRS::initBDDvars(void) pv_drs_flat_E = new BDD(BDD_TRUE); pv_drs_flat_succ_E = new BDD(BDD_TRUE); - VERB_LN(3, "DRS processing"); + VERB_LN(2, "DRS processing"); unsigned int drs_flat_index = 0; @@ -171,11 +165,18 @@ void SymRS::initBDDvars(void) // The DRS part of the system (flattened): these vars do not include CA (*pv_drs_flat)[drs_flat_index] = (*pv_drs)[proc_id][i]; (*pv_drs_flat_succ)[drs_flat_index] = (*pv_drs_succ)[proc_id][i]; - ++drs_flat_index; + + *pv_drs_flat_E *= (*pv_drs_flat)[drs_flat_index]; + *pv_drs_flat_succ_E *= (*pv_drs_flat_succ)[drs_flat_index]; // Variables used for the global states (*pv)[global_state_idx] = (*pv_drs)[proc_id][i]; (*pv_succ)[global_state_idx] = (*pv_drs_succ)[proc_id][i]; + + *pv_E *= (*pv)[global_state_idx]; + *pv_succ_E *= (*pv_succ)[global_state_idx]; + + ++drs_flat_index; ++global_state_idx; } } @@ -185,7 +186,7 @@ void SymRS::initBDDvars(void) // ---------------------------------------------------------- if (usingContextAutomaton()) { - VERB("Context automaton variables"); + VERB_LN(2, "Context automaton variables"); pv_ca = new BDDvec(totalCtxAutStateVars); pv_ca_succ = new BDDvec(totalCtxAutStateVars); @@ -211,30 +212,71 @@ void SymRS::initBDDvars(void) // These variables indicate which process is // allowed to perform action // + VERB_LN(2, "Variables for process enabledness/activity"); + pv_proc_enab = new BDDvec(numberOfProc); for (unsigned int i = 0; i < numberOfProc; ++i) { (*pv_proc_enab)[i] = cuddMgr->bddVar(bdd_var_idx++); } - // Actions/Contexts - pv_act = new BDDvec(totalActions); - pv_act_E = new BDD(BDD_TRUE); + // ---------------------------------------------------------- + // Context Entities + // ---------------------------------------------------------- - // TODO - // Actions need also per-process PV and flattened PV + // // Actions/Contexts + // pv_act = new BDDvec(totalActions); + // pv_act_E = new BDD(BDD_TRUE); + // + // // TODO + // // Actions need also per-process PV and flattened PV + // + // for (unsigned int i = 0; i < totalActions; ++i) { + // (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); + // *pv_act_E *= (*pv_act)[i]; + // } + + VERB_LN(2, "Variables for context entities"); + + pv_ctx = new BDDvec(totalCtxEntities); + pv_ctx_E = new BDD(BDD_TRUE); + pv_proc_ctx = new vector(numberOfProc); + pv_proc_ctx_E = new BDDvec(numberOfProc); + + unsigned int flat_ctx_index = 0; + + for (const auto &proc_ent : usedCtxEntities) { + + auto proc_id = proc_ent.first; + auto entities_count = proc_ent.second.size(); + + assert(entities_count < rs->getEntitiesSize()); + + // adjust the size of the nested vector before we use an index + (*pv_proc_ctx)[proc_id].resize(entities_count); + + (*pv_proc_ctx_E)[proc_id] = BDD_TRUE; + + for (unsigned int i = 0; i < entities_count; ++i) { + + assert(flat_ctx_index < totalCtxEntities); + assert(proc_id < numberOfProc); + + (*pv_proc_ctx)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); + (*pv_proc_ctx_E)[proc_id] *= (*pv_proc_ctx)[proc_id][i]; + + (*pv_ctx)[flat_ctx_index] = (*pv_proc_ctx)[proc_id][i]; + *pv_ctx_E *= (*pv_ctx)[flat_ctx_index]; + + ++flat_ctx_index; + } - for (unsigned int i = 0; i < totalActions; ++i) { - (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); - *pv_act_E *= (*pv_act)[i]; } - // Quantification BDDs - - *pv_E = *pv_rs_E; - *pv_succ_E = *pv_rs_succ_E; - if (usingContextAutomaton()) { + + VERB_LN(2, "Updating quantification BDDs with context automaton") + *pv_E *= *pv_ca_E; *pv_succ_E *= *pv_ca_succ_E; } @@ -294,7 +336,14 @@ void SymRS::mapProcEntities(void) } ctx_ent_local_idx = buildLocalEntitiesMap(usedCtxEntities); - // cout << rs->procEntitiesToStr(usedCtxEntities) << endl; + + if (opts->verbose > 9) { + cout << "Used product entities:" << endl; + cout << rs->procEntitiesToStr(usedProducts) << endl; + + cout << "Used context entities:" << endl; + cout << rs->procEntitiesToStr(usedCtxEntities) << endl; + } } BDD SymRS::encEntity_raw(Entity entity, bool succ) const diff --git a/symrs.hh b/symrs.hh index b1385d8..673d97b 100644 --- a/symrs.hh +++ b/symrs.hh @@ -212,11 +212,11 @@ class SymRS BDDvec *pv_proc_enab; /*!< Variables indicating if a process is enabled */ - BDDvec *pv_rs; - BDDvec *pv_rs_succ; + BDDvec *pv_rs; // remove + BDDvec *pv_rs_succ; // remove - BDD *pv_rs_E; - BDD *pv_rs_succ_E; + BDD *pv_rs_E; // remove + BDD *pv_rs_succ_E; // remove vector *pv_drs; /*!< PVs for the product part of state (per DRS process) */ @@ -226,6 +226,9 @@ class SymRS BDDvec *pv_drs_flat; /*!< PVs for the DRS product part of state (flat) */ BDDvec *pv_drs_flat_succ; /*!< PVs for the DRS product (successor) part of state (flat) */ + BDD *pv_drs_flat_E; + BDD *pv_drs_flat_succ_E; + BDDvec *partTrans; BDD *monoTrans; @@ -237,6 +240,12 @@ class SymRS BDD *pv_ca_succ_E; BDD *tr_ca; + BDDvec *pv_ctx; + BDD *pv_ctx_E; + vector *pv_proc_ctx; + BDDvec *pv_proc_ctx_E; + + // TODO: remove BDDvec *pv_act; BDD *pv_act_E; @@ -315,8 +324,7 @@ class SymRS void encodeInitStatesForCtxAut(void); void encodeInitStatesNoCtxAut(void); void mapStateToAct(void); - LocalIndicesForProcEntities buildLocalEntitiesMap(const EntitiesForProc - &procEnt); + LocalIndicesForProcEntities buildLocalEntitiesMap(const EntitiesForProc &procEnt); void mapProcEntities(void); void encode(void); From 9a8255a355f57c2b3748884226c6f7627547df9c Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 2 Apr 2018 22:17:47 +0100 Subject: [PATCH 15/90] Encoding DRS transition relation --- formrsctl.cc | 4 +- formrsctl.hh | 5 +- mc.cc | 4 +- rs.hh | 6 +- symrs.cc | 239 +++++++++++++++------------------------------------ symrs.hh | 60 +++++++------ 6 files changed, 113 insertions(+), 205 deletions(-) diff --git a/formrsctl.cc b/formrsctl.cc index 8f465e0..2b97e25 100644 --- a/formrsctl.cc +++ b/formrsctl.cc @@ -76,7 +76,7 @@ BDD BoolContexts::getBDD(const SymRS *srs) const std::string FormRSCTL::toStr(void) const { if (oper == RSCTL_PV) { - return name; + return proc_name + ":" + entity_name; } else if (oper == RSCTL_TF) { if (tf) { @@ -188,7 +188,7 @@ void FormRSCTL::encodeEntities(const SymRS *srs) arg[1]->encodeEntities(srs); } else if (oper == RSCTL_PV) { - bdd = new BDD(srs->encEntity(name)); + bdd = new BDD(srs->encEntity(proc_name, entity_name)); } } diff --git a/formrsctl.hh b/formrsctl.hh index 14990e7..baddbde 100644 --- a/formrsctl.hh +++ b/formrsctl.hh @@ -153,7 +153,8 @@ class FormRSCTL { Oper oper; FormRSCTL *arg[2]; - std::string name; + std::string entity_name; + std::string proc_name; bool tf; BDD *bdd; ActionsVec_f *actions; @@ -169,7 +170,7 @@ class FormRSCTL FormRSCTL(std::string varName) { oper = RSCTL_PV; - name = varName; + entity_name = varName; arg[0] = nullptr; arg[1] = nullptr; bdd = nullptr; diff --git a/mc.cc b/mc.cc index 80b5f2c..00e56c4 100644 --- a/mc.cc +++ b/mc.cc @@ -191,7 +191,9 @@ bool ModelChecker::checkReach(const Entities testState) opts->ver_time = cpuTime(); } - BDD st = srs->getEncState(testState); + // BDD st = srs->getEncState(testState); + BDD st = BDD_FALSE; + assert(0); BDD reach = *initStates; BDD reach_p = cuddMgr->bddZero(); diff --git a/rs.hh b/rs.hh index 233969f..7409336 100644 --- a/rs.hh +++ b/rs.hh @@ -75,10 +75,6 @@ class RctSys { return entities_ids.size(); } - unsigned int getReactionsSize(void) - { - return reactions.size(); - } unsigned int getActionsSize(void) { return actionEntities.size(); @@ -109,7 +105,7 @@ class RctSys } private: - Reactions reactions; // TODO: to be removed later + // Reactions reactions; // TODO: to be removed later ReactionsForProc proc_reactions; EntitiesSets initStates; diff --git a/symrs.cc b/symrs.cc index 08c5429..c81ed72 100644 --- a/symrs.cc +++ b/symrs.cc @@ -13,11 +13,12 @@ SymRS::SymRS(RctSys *rs, Options *opts) mapProcEntities(); + totalEntities = rs->getEntitiesSize(); + // TODO: remove totalActions = 0; totalRctSysStateVars = getTotalProductVariables(); - totalReactions = rs->getReactionsSize(); totalCtxEntities = getTotalCtxEntitiesVariables(); totalCtxAutStateVars = getCtxAutStateEncodingSize(); @@ -43,8 +44,6 @@ void SymRS::encode(void) opts->enc_mem = memUsed(); } - mapStateToAct(); - initBDDvars(); if (usingContextAutomaton()) { @@ -156,7 +155,7 @@ void SymRS::initBDDvars(void) assert(drs_flat_index < totalRctSysStateVars); assert(global_state_idx < totalStateVars); assert(proc_id < numberOfProc); - assert(i < rs->getEntitiesSize()); + assert(i < totalEntities); // Variables for each individual process/component (*pv_drs)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); @@ -250,7 +249,7 @@ void SymRS::initBDDvars(void) auto proc_id = proc_ent.first; auto entities_count = proc_ent.second.size(); - assert(entities_count < rs->getEntitiesSize()); + assert(entities_count < totalEntities); // adjust the size of the nested vector before we use an index (*pv_proc_ctx)[proc_id].resize(entities_count); @@ -346,46 +345,60 @@ void SymRS::mapProcEntities(void) } } -BDD SymRS::encEntity_raw(Entity entity, bool succ) const +BDD SymRS::encEntity_raw(Process proc_id, Entity entity, bool succ) const { BDD r; + assert(proc_id < numberOfProc); + + auto local_entity_id = getLocalProductEntityIndex(proc_id, entity); + if (succ) { - r = (*pv_succ)[entity]; + r = (*pv_drs_succ)[proc_id][local_entity_id]; } else { - r = (*pv)[entity]; + r = (*pv_drs)[proc_id][local_entity_id]; } return r; } -BDD SymRS::encEntitiesConj_raw(const Entities &entities, bool succ) +BDD SymRS::encCtxEntity(Process proc_id, Entity entity) const +{ + assert(entity < totalEntities); + assert(proc_id < numberOfProc); + + auto local_entity_id = getLocalCtxEntityIndex(proc_id, entity); + + return (*pv_proc_ctx)[proc_id][local_entity_id]; +} + +BDD SymRS::encEntitiesConj_raw(Process proc_id, const Entities &entities, bool succ) { BDD r = BDD_TRUE; for (const auto &entity : entities) { if (succ) { - r *= encEntitySucc(entity); + r *= encEntitySucc(proc_id, entity); } else { - r *= encEntity(entity); + r *= encEntity(proc_id, entity); } } return r; } -BDD SymRS::encEntitiesDisj_raw(const Entities &entities, bool succ) +BDD SymRS::encEntitiesDisj_raw(Process proc_id, const Entities &entities, bool succ) { BDD r = BDD_FALSE; for (const auto &entity : entities) { if (succ) { - r += encEntitySucc(entity); + r += encEntitySucc(proc_id, entity); } else { - r += encEntity(entity); + r += encEntity(proc_id, entity); } } @@ -394,8 +407,9 @@ BDD SymRS::encEntitiesDisj_raw(const Entities &entities, bool succ) BDD SymRS::encStateActEntitiesConj(const Entities &entities) { + assert(0); BDD r = BDD_TRUE; - + /* for (const auto &entity : entities) { BDD state_act = encEntity(entity); int actEntity; @@ -407,14 +421,16 @@ BDD SymRS::encStateActEntitiesConj(const Entities &entities) r *= state_act; } + */ return r; } BDD SymRS::encStateActEntitiesDisj(const Entities &entities) { + assert(0); BDD r = BDD_FALSE; - + /* for (const auto &entity : entities) { BDD state_act = encEntity(entity); int actEntity; @@ -426,24 +442,26 @@ BDD SymRS::encStateActEntitiesDisj(const Entities &entities) r += state_act; } - + */ return r; } BDD SymRS::encActEntitiesConj(const Entities &entities) { + assert(0); BDD r = BDD_TRUE; - + /* for (const auto &entity : entities) { Entity actEntity = getMappedStateToActID(entity); r *= encActEntity(actEntity); } - + */ return r; } BDD SymRS::compState(const BDD &state) const { + assert(0); BDD s = state; for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { @@ -457,6 +475,7 @@ BDD SymRS::compState(const BDD &state) const BDD SymRS::compContext(const BDD &context) const { + assert(0); BDD c = context; for (unsigned int i = 0; i < totalActions; ++i) { @@ -470,20 +489,22 @@ BDD SymRS::compContext(const BDD &context) const std::string SymRS::decodedRctSysStateToStr(const BDD &state) { + assert(0); std::string s = "{ "; - + /* for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { if (!(encEntity(i) * state).IsZero()) { s += rs->entityToStr(i) + " "; } } - + */ s += "}"; return s; } void SymRS::printDecodedRctSysStates(const BDD &states) { + assert(0); BDD unproc = states; while (!unproc.IsZero()) { @@ -499,114 +520,51 @@ void SymRS::printDecodedRctSysStates(const BDD &states) } } -void SymRS::encodeTransitions(void) +DecompReactions SymRS::getProductionConditions(Process proc_id) { DecompReactions dr; + for (const auto &rct : rs->proc_reactions[proc_id]) { + ReactionCond cond; + cond.rctt = rct.rctt; + cond.inhib = rct.inhib; + + for (const auto &prod : rct.prod) { + dr[prod].push_back(cond); + } + } + + return dr; +} + +void SymRS::encodeTransitions(void) +{ VERB("Decomposing reactions"); - for (unsigned int i = 0; i < totalReactions; ++i) { - ReactionCond cond; - cond.rctt = rs->reactions[i].rctt; - cond.inhib = rs->reactions[i].inhib; + vector prod_conds(numberOfProc); - for (Entities::iterator p = rs->reactions[i].prod.begin(); - p != rs->reactions[i].prod.end(); ++p) { - dr[*p].push_back(cond); - } + for (auto proc_id = 0; proc_id < numberOfProc; ++proc_id) { + prod_conds[proc_id] = getProductionConditions(proc_id); } VERB("Encoding reactions"); if (opts->part_tr_rel) { VERB("Using partitioned transition relation encoding"); - partTrans = new BDDvec(totalRctSysStateVars); + FERROR("Partitioned transition relation is currently not supported"); } else { VERB("Using monolithic transition relation encoding"); monoTrans = new BDD(BDD_TRUE); } - for (unsigned int p = 0; p < totalRctSysStateVars; ++p) { - VERB_L3("Encoding for successor " << p); - - DecompReactions::iterator di; - - if ((di = dr.find(p)) == dr.end()) { - // there is no reaction producing p: - if (opts->part_tr_rel) { - (*partTrans)[p] = !encEntitySucc(p); - } - else { - *monoTrans *= !encEntitySucc(p); - } - } - else { - // di - reactions producing p - - BDD conditions = BDD_FALSE; - - assert(di->second.size() > 0); - - for (unsigned int j = 0; j < di->second.size(); ++j) { - conditions += encStateActEntitiesConj(di->second[j].rctt) * - !encStateActEntitiesDisj(di->second[j].inhib); - } - - if (opts->part_tr_rel) { - (*partTrans)[p] = conditions * encEntitySucc(p); - (*partTrans)[p] += !conditions * !encEntitySucc(p); - } - else { - *monoTrans *= (conditions * encEntitySucc(p)) + (!conditions * !encEntitySucc( - p)); - } - } - - if (opts->reorder_trans) { - VERB_L2("Reordering"); - Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); - } - - } - - VERB("Reactions ready"); - - if (usingContextAutomaton()) { - VERB("Augmenting transition relation encoding with the transition relation for context automaton"); - - if (opts->part_tr_rel) { - assert(0); - } - else { - assert(tr_ca != nullptr); - *monoTrans *= *tr_ca; - } - } - - VERB("Transition relation encoded") -} - -BDD SymRS::getEncState(const Entities &entities) -{ - assert(0); - //BDD state = compState(encEntitiesConj(rs->initState)); - //for (RctSys::Entities::iterator at = rs->actionEntities.begin(); at != rs->actionEntities.end(); ++at) - //{ - // state = state.ExistAbstract(encEntity(*at)); - //} - return BDD_FALSE; + FERROR("WORK IN PROGRESS"); } BDD SymRS::encNoContext(void) { - BDD noContextBDD = BDD_TRUE; - - for (unsigned int i = 0; i < totalActions; ++i) { - noContextBDD *= !(*pv_act)[i]; - } - - return noContextBDD; + assert(0); + return BDD_FALSE; } void SymRS::encodeInitStates(void) @@ -616,8 +574,7 @@ void SymRS::encodeInitStates(void) encodeInitStatesForCtxAut(); } else { - VERB("Encoding initial states (for the action entities method -- no CA)"); - encodeInitStatesNoCtxAut(); + FERROR("Context automaton required"); } VERB("Initial states encoded"); @@ -634,67 +591,9 @@ void SymRS::encodeInitStatesForCtxAut(void) *initStates *= getEncCtxAutInitState(); } -void SymRS::encodeInitStatesNoCtxAut(void) -{ -#ifndef NDEBUG - - if (opts->part_tr_rel) { - assert(partTrans != nullptr); - } - -#endif - - initStates = new BDD(BDD_FALSE); - - for (auto state = rs->initStates.begin(); - state != rs->initStates.end(); - ++state) { - VERB("Encoding a single inital state"); - BDD newInitState = compState(encEntitiesConj(*state)); - BDD q = BDD_TRUE; - - if (opts->part_tr_rel) { - for (unsigned int i = 0; i < partTrans->size(); ++i) { - q *= newInitState * (*partTrans)[i] * encNoContext(); - } - } - else { - q *= newInitState * *monoTrans * encNoContext(); - } - - q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); - q = q.ExistAbstract(*pv_act_E); - - *initStates += q; - } -} - -void SymRS::mapStateToAct(void) -{ - VERB("Mapping state variables to action variables"); - unsigned int j = 0; - - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { - if (rs->isActionEntity(i)) { - stateToAct.push_back(j++); - } - else { - stateToAct.push_back(-1); - } - } - - const unsigned int verbosity_level = 9; - - if (opts->verbose > verbosity_level) { - for (unsigned int i = 0; i < stateToAct.size(); ++i) { - cout << "ii VERBOSE(" << verbosity_level << "): stateToAct[" << i << "] = " << - stateToAct[i] << endl; - } - } -} - BDD SymRS::encActStrEntity(std::string name) const { + /* int id = getMappedStateToActID(rs->getEntityID(name)); if (id < 0) { @@ -704,6 +603,8 @@ BDD SymRS::encActStrEntity(std::string name) const else { return encActEntity(getMappedStateToActID(rs->getEntityID(name))); } + */ + return BDD_FALSE; } size_t SymRS::getCtxAutStateEncodingSize(void) @@ -788,7 +689,7 @@ 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); - assert(0); // enc_ctx + // assert(0); // enc_ctx BDD enc_ctx = BDD_FALSE; //compContext(encActEntitiesConj(t.ctx)); *tr_ca += enc_src * enc_ctx * enc_dst; diff --git a/symrs.hh b/symrs.hh index 673d97b..d6a0b22 100644 --- a/symrs.hh +++ b/symrs.hh @@ -63,7 +63,6 @@ class SymRS { return monoTrans; } - BDD getEncState(const Entities &entities); BDD *getEncInitStates(void) { return initStates; @@ -80,11 +79,10 @@ class SymRS { return totalRctSysStateVars; } - BDD encEntity(std::string name) const + BDD encEntity(std::string proc_name, std::string entity_name) const { - return encEntity(rs->getEntityID(name)); + return encEntity(rs->getProcessID(proc_name), rs->getEntityID(entity_name)); } - BDD encActStrEntity(std::string name) const; BDD getBDDtrue(void) const { @@ -249,9 +247,9 @@ class SymRS BDDvec *pv_act; BDD *pv_act_E; + unsigned int totalEntities; unsigned int numberOfProc; /*!< The number of DRS processes */ unsigned int totalStateVars; - unsigned int totalReactions; unsigned int totalRctSysStateVars; /*!< Total number of different entities produced by reactions */ unsigned int totalCtxEntities; /*!< Total number of different process-context entities used */ unsigned int totalActions; @@ -266,37 +264,48 @@ class SymRS size_t getTotalProductVariables(void); size_t getTotalCtxEntitiesVariables(void); - BDD encEntity_raw(Entity entity, bool succ) const; - BDD encEntity(Entity entity) const + unsigned int getLocalProductEntityIndex(Process proc_id, Entity entity) const { - return encEntity_raw(entity, false); + return prod_ent_local_idx.at(proc_id).at(entity); } - BDD encActEntity(Entity entity) const + unsigned int getLocalCtxEntityIndex(Process proc_id, Entity entity) const { - assert(entity < pv_act->size()); - return (*pv_act)[entity]; + return ctx_ent_local_idx.at(proc_id).at(entity); } - BDD encEntitySucc(Entity entity) const + + BDD encEntity_raw(Process proc_id, Entity entity, bool succ) const; + BDD encEntity(Process proc_id, Entity entity) const { - return encEntity_raw(entity, true); + return encEntity_raw(proc_id, entity, false); } - BDD encEntitiesConj_raw(const Entities &entities, bool succ); - BDD encEntitiesConj(const Entities &entities) + BDD encEntitySucc(Process proc_id, Entity entity) const { - return encEntitiesConj_raw(entities, false); + return encEntity_raw(proc_id, entity, true); } - BDD encEntitiesConjSucc(const Entities &entities) + + BDD encCtxEntity(Process proc_id, Entity entity) const; + + BDD encEntitiesConj_raw(Process proc_id, const Entities &entities, bool succ); + BDD encEntitiesConj(Process proc_id, const Entities &entities) { - return encEntitiesConj_raw(entities, true); + return encEntitiesConj_raw(proc_id, entities, false); } - BDD encEntitiesDisj_raw(const Entities &entities, bool succ); - BDD encEntitiesDisj(const Entities &entities) + BDD encEntitiesConjSucc(Process proc_id, const Entities &entities) { - return encEntitiesDisj_raw(entities, false); + return encEntitiesConj_raw(proc_id, entities, true); } - BDD encEntitiesDisjSucc(const Entities &entities) + + + // ---- TODO below: + + BDD encEntitiesDisj_raw(Process proc_id, const Entities &entities, bool succ); + BDD encEntitiesDisj(Process proc_id, const Entities &entities) { - return encEntitiesDisj_raw(entities, true); + return encEntitiesDisj_raw(proc_id, entities, false); + } + BDD encEntitiesDisjSucc(Process proc_id, const Entities &entities) + { + return encEntitiesDisj_raw(proc_id, entities, true); } BDD encStateActEntitiesConj(const Entities &entities); BDD encStateActEntitiesDisj(const Entities &entities); @@ -317,13 +326,12 @@ class SymRS BDD encNoContext(void); + DecompReactions getProductionConditions(Process proc_id); + void initBDDvars(void); void encodeTransitions(void); - void encodeTransitions_old(void); void encodeInitStates(void); void encodeInitStatesForCtxAut(void); - void encodeInitStatesNoCtxAut(void); - void mapStateToAct(void); LocalIndicesForProcEntities buildLocalEntitiesMap(const EntitiesForProc &procEnt); void mapProcEntities(void); void encode(void); From 6b485e4e08e1fab8aef8baa57bba25658cc8922b Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 3 Apr 2018 17:19:23 +0100 Subject: [PATCH 16/90] Transition relation for DRS --- symrs.cc | 182 ++++++++++++++++++++++++++++++++++++++++++++----------- symrs.hh | 40 ++++++------ 2 files changed, 164 insertions(+), 58 deletions(-) diff --git a/symrs.cc b/symrs.cc index c81ed72..7eaca85 100644 --- a/symrs.cc +++ b/symrs.cc @@ -68,11 +68,12 @@ 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; + unsigned int cnt = 0; + for (const auto &e : proc_ent.second) { ent_map[proc_id][e] = cnt++; } @@ -345,11 +346,27 @@ void SymRS::mapProcEntities(void) } } +unsigned int SymRS::getLocalProductEntityIndex(Process proc_id, Entity entity) const +{ + assert(productEntityExists(proc_id, entity)); + auto idx = prod_ent_local_idx.at(proc_id).at(entity); + assert(idx < prod_ent_local_idx.at(proc_id).size()); + return idx; +} +unsigned int SymRS::getLocalCtxEntityIndex(Process proc_id, Entity entity) const +{ + assert(ctxEntityExists(proc_id, entity)); + auto idx = ctx_ent_local_idx.at(proc_id).at(entity); + assert(idx < ctx_ent_local_idx.at(proc_id).size()); + return idx; +} + BDD SymRS::encEntity_raw(Process proc_id, Entity entity, bool succ) const { BDD r; assert(proc_id < numberOfProc); + assert(productEntityExists(proc_id, entity)); auto local_entity_id = getLocalProductEntityIndex(proc_id, entity); @@ -367,12 +384,41 @@ BDD SymRS::encCtxEntity(Process proc_id, Entity entity) const { assert(entity < totalEntities); assert(proc_id < numberOfProc); + assert(ctxEntityExists(proc_id, entity)); auto local_entity_id = getLocalCtxEntityIndex(proc_id, entity); return (*pv_proc_ctx)[proc_id][local_entity_id]; } +bool SymRS::productEntityExists(Process proc_id, Entity entity) const +{ + if (prod_ent_local_idx.count(proc_id) == 0) { + return false; + } + else { + if (prod_ent_local_idx.at(proc_id).count(entity) == 1) { + return true; + } + } + + return false; +} + +bool SymRS::ctxEntityExists(Process proc_id, Entity entity) const +{ + if (ctx_ent_local_idx.count(proc_id) == 0) { + return false; + } + else { + if (ctx_ent_local_idx.at(proc_id).count(entity) == 1) { + return true; + } + } + + return false; +} + BDD SymRS::encEntitiesConj_raw(Process proc_id, const Entities &entities, bool succ) { BDD r = BDD_TRUE; @@ -405,44 +451,22 @@ BDD SymRS::encEntitiesDisj_raw(Process proc_id, const Entities &entities, bool s return r; } -BDD SymRS::encStateActEntitiesConj(const Entities &entities) +BDD SymRS::encEntityCondition(Process proc_id, Entity entity_id) { - assert(0); - BDD r = BDD_TRUE; - /* - for (const auto &entity : entities) { - BDD state_act = encEntity(entity); - int actEntity; - - // if entity is also an action entity, we include it in the encoding - if ((actEntity = getMappedStateToActID(entity)) >= 0) { - state_act += encActEntity(actEntity); - } - - r *= state_act; - } - */ - - return r; -} - -BDD SymRS::encStateActEntitiesDisj(const Entities &entities) -{ - assert(0); + // + // Here we encode an entity-based condition which uses + // the entity appearing as a product or a context entity. + // BDD r = BDD_FALSE; - /* - for (const auto &entity : entities) { - BDD state_act = encEntity(entity); - int actEntity; - // if entity is also an aciton entity, we include it in the encoding - if ((actEntity = getMappedStateToActID(entity)) >= 0) { - state_act += encActEntity(actEntity); - } - - r += state_act; + if (productEntityExists(proc_id, entity_id)) { + r += encEntity(proc_id, entity_id); } - */ + + if (ctxEntityExists(proc_id, entity_id)) { + r += encCtxEntity(proc_id, entity_id); + } + return r; } @@ -537,11 +561,72 @@ DecompReactions SymRS::getProductionConditions(Process proc_id) return dr; } +BDD SymRS::encEnabledness(Process proc_id, Entity entity_id) +{ + assert(prod_conds.size() > proc_id); + + BDD enab = BDD_FALSE; + + auto production_conditions = prod_conds[proc_id][entity_id]; + + for (const auto &cond : production_conditions) { + + BDD reactants = BDD_TRUE; + BDD inhibitors = BDD_TRUE; + + for (const auto &reactant : cond.rctt) { + BDD proc_reactants = BDD_FALSE; + + for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { + proc_reactants += encProcEnabled(proc_id) * encEntityCondition(proc_id, reactant); + } // END FOR: prod_id + + reactants *= proc_reactants; + } // END FOR: reactant + + // For inhibitors, we take all the processes first and then we iterate over the inhibitors + for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { + BDD proc_inhibitors = encProcEnabled(proc_id); + + for (const auto &inhibitor : cond.inhib) { + proc_inhibitors *= !encEntityCondition(proc_id, inhibitor); + } + + inhibitors *= proc_inhibitors; + } + + enab += reactants * inhibitors; + + } // END FOR: cond + + return enab; +} + +BDD SymRS::encEntitySameSuccessor(Process proc_id, Entity entity_id) +{ + return BDD_IFF(encEntity(proc_id, entity_id), encEntitySucc(proc_id, entity_id)); +} + +BDD SymRS::encEntityProduction(Process proc_id, Entity entity_id) +{ + BDD enabled = encEnabledness(proc_id, entity_id); + + BDD when_produced = enabled * encEntitySucc(proc_id, entity_id); + BDD when_not_produced = !enabled * !encEntitySucc(proc_id, entity_id); + + BDD proc_enabled = encProcEnabled(proc_id) * (when_produced + when_not_produced); + BDD proc_disabled = !encProcEnabled(proc_id) * encEntitySameSuccessor(proc_id, entity_id); + + BDD result = proc_enabled + proc_disabled; + + return result; +} + void SymRS::encodeTransitions(void) { VERB("Decomposing reactions"); - vector prod_conds(numberOfProc); + prod_conds.resize(numberOfProc); for (auto proc_id = 0; proc_id < numberOfProc; ++proc_id) { prod_conds[proc_id] = getProductionConditions(proc_id); @@ -558,7 +643,30 @@ void SymRS::encodeTransitions(void) monoTrans = new BDD(BDD_TRUE); } - FERROR("WORK IN PROGRESS"); + VERB_LN(3, "Entity production encoding for all the processes and their products"); + + for (const auto &proc_products : usedProducts) { + auto proc_id = proc_products.first; + auto products = proc_products.second; + + for (const auto &prod : products) { + *monoTrans = encEntityProduction(proc_id, prod); + } + } + + VERB("Reactions ready"); + + if (usingContextAutomaton()) { + VERB("Augmenting transition relation encoding with the transition relation for context automaton"); + + if (opts->part_tr_rel) { + FERROR("Partitioned transition relation is currently not supported"); + } + else { + assert(tr_ca != nullptr); + *monoTrans *= *tr_ca; + } + } } BDD SymRS::encNoContext(void) diff --git a/symrs.hh b/symrs.hh index d6a0b22..6807aa7 100644 --- a/symrs.hh +++ b/symrs.hh @@ -198,9 +198,6 @@ class SymRS Cudd *cuddMgr; Options *opts; - StateEntityToAction - stateToAct; /*!< Mapping: entity ID -> action/context entity ID */ - BDD *initStates; /*!< BDD with initial states encoded */ BDDvec *pv; /*!< PVs for the global state (all the variables, flat) */ @@ -227,8 +224,9 @@ class SymRS BDD *pv_drs_flat_E; BDD *pv_drs_flat_succ_E; - BDDvec *partTrans; + vector prod_conds; /*!< Production conditions (per process and per entity) */ + BDDvec *partTrans; BDD *monoTrans; // Context automaton @@ -264,14 +262,8 @@ class SymRS size_t getTotalProductVariables(void); size_t getTotalCtxEntitiesVariables(void); - unsigned int getLocalProductEntityIndex(Process proc_id, Entity entity) const - { - return prod_ent_local_idx.at(proc_id).at(entity); - } - unsigned int getLocalCtxEntityIndex(Process proc_id, Entity entity) const - { - return ctx_ent_local_idx.at(proc_id).at(entity); - } + unsigned int getLocalProductEntityIndex(Process proc_id, Entity entity) const; + unsigned int getLocalCtxEntityIndex(Process proc_id, Entity entity) const; BDD encEntity_raw(Process proc_id, Entity entity, bool succ) const; BDD encEntity(Process proc_id, Entity entity) const @@ -285,6 +277,14 @@ class SymRS BDD encCtxEntity(Process proc_id, Entity entity) const; + bool productEntityExists(Process proc_id, Entity entity) const; + bool ctxEntityExists(Process proc_id, Entity entity) const; + + BDD encProcEnabled(Process proc_id) const + { + return (*pv_proc_enab)[proc_id]; + } + BDD encEntitiesConj_raw(Process proc_id, const Entities &entities, bool succ); BDD encEntitiesConj(Process proc_id, const Entities &entities) { @@ -295,7 +295,6 @@ class SymRS return encEntitiesConj_raw(proc_id, entities, true); } - // ---- TODO below: BDD encEntitiesDisj_raw(Process proc_id, const Entities &entities, bool succ); @@ -307,8 +306,8 @@ class SymRS { return encEntitiesDisj_raw(proc_id, entities, true); } - BDD encStateActEntitiesConj(const Entities &entities); - BDD encStateActEntitiesDisj(const Entities &entities); + + BDD encEntityCondition(Process proc_id, Entity entity_id); BDD encActEntitiesConj(const Entities &entities); @@ -329,6 +328,11 @@ class SymRS DecompReactions getProductionConditions(Process proc_id); void initBDDvars(void); + + BDD encEnabledness(Process proc_id, Entity entity_id); + BDD encEntitySameSuccessor(Process proc_id, Entity entity_id); + BDD encEntityProduction(Process proc_id, Entity entity_id); + void encodeTransitions(void); void encodeInitStates(void); void encodeInitStatesForCtxAut(void); @@ -336,12 +340,6 @@ class SymRS void mapProcEntities(void); void encode(void); - int getMappedStateToActID(int stateID) const - { - assert(stateID < static_cast(totalRctSysStateVars)); - return stateToAct[stateID]; - } - size_t getCtxAutStateEncodingSize(void); }; From 5f578c906677584f4b7b45dcca9a44b65bb44beb Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 3 Apr 2018 17:50:23 +0100 Subject: [PATCH 17/90] Context encoding and complementation --- rs.hh | 2 +- symrs.cc | 42 ++++++++++++++++++++++++++++-------------- symrs.hh | 6 +++--- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/rs.hh b/rs.hh index 7409336..39a89cb 100644 --- a/rs.hh +++ b/rs.hh @@ -105,7 +105,7 @@ class RctSys } private: - // Reactions reactions; // TODO: to be removed later + ReactionsForProc proc_reactions; EntitiesSets initStates; diff --git a/symrs.cc b/symrs.cc index 7eaca85..d99362e 100644 --- a/symrs.cc +++ b/symrs.cc @@ -470,16 +470,24 @@ BDD SymRS::encEntityCondition(Process proc_id, Entity entity_id) return r; } -BDD SymRS::encActEntitiesConj(const Entities &entities) +BDD SymRS::encContext(const EntitiesForProc &proc_entities) { - assert(0); BDD r = BDD_TRUE; - /* - for (const auto &entity : entities) { - Entity actEntity = getMappedStateToActID(entity); - r *= encActEntity(actEntity); + + for (const auto &pe : proc_entities) { + auto proc_id = pe.first; + auto entities = pe.second; + + for (const auto &entity : entities) { + r *= encCtxEntity(proc_id, entity); + } + + // This check is not really requires. Just to be sure... + if (entities.size() > 0) { + r *= encProcEnabled(proc_id); + } } - */ + return r; } @@ -499,12 +507,17 @@ BDD SymRS::compState(const BDD &state) const BDD SymRS::compContext(const BDD &context) const { - assert(0); BDD c = context; - for (unsigned int i = 0; i < totalActions; ++i) { - if (!(*pv_act)[i] * context != cuddMgr->bddZero()) { - c *= !(*pv_act)[i]; + for (const auto &var : *pv_ctx) { + if (!var * context != cuddMgr->bddZero()) { + c *= !var; + } + } + + for (const auto &var : *pv_proc_enab) { + if (!var * context != cuddMgr->bddZero()) { + c *= !var; } } @@ -797,10 +810,11 @@ 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); - // assert(0); // enc_ctx - BDD enc_ctx = BDD_FALSE; //compContext(encActEntitiesConj(t.ctx)); + BDD enc_ctx = compContext(encContext(t.ctx)); - *tr_ca += enc_src * enc_ctx * enc_dst; + BDD new_trans = enc_src * enc_ctx * enc_dst; + + *tr_ca += new_trans; } } diff --git a/symrs.hh b/symrs.hh index 6807aa7..040d476 100644 --- a/symrs.hh +++ b/symrs.hh @@ -236,7 +236,7 @@ class SymRS BDD *pv_ca_succ_E; BDD *tr_ca; - BDDvec *pv_ctx; + BDDvec *pv_ctx; /*!< Flat */ BDD *pv_ctx_E; vector *pv_proc_ctx; BDDvec *pv_proc_ctx_E; @@ -249,7 +249,7 @@ class SymRS unsigned int numberOfProc; /*!< The number of DRS processes */ unsigned int totalStateVars; unsigned int totalRctSysStateVars; /*!< Total number of different entities produced by reactions */ - unsigned int totalCtxEntities; /*!< Total number of different process-context entities used */ + unsigned int totalCtxEntities; /*!< Total number of different (process,context) entities used */ unsigned int totalActions; unsigned int totalCtxAutStateVars; @@ -309,7 +309,7 @@ class SymRS BDD encEntityCondition(Process proc_id, Entity entity_id); - BDD encActEntitiesConj(const Entities &entities); + BDD encContext(const EntitiesForProc &proc_entities); /** * @brief Complements an encoding of a given state by negating all the variables that are not set to true From 95d8123a6ba2752ef8ca4bb813eb950af6954f1f Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 3 Apr 2018 20:05:50 +0100 Subject: [PATCH 18/90] Working DRS with one process --- mc.cc | 20 ++++++++++++++------ mc.hh | 4 +++- symrs.cc | 50 ++++++++++++++++++++++---------------------------- symrs.hh | 17 +++++++---------- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/mc.cc b/mc.cc index 00e56c4..b0a148a 100644 --- a/mc.cc +++ b/mc.cc @@ -16,7 +16,15 @@ ModelChecker::ModelChecker(SymRS *srs, Options *opts) pv_succ = srs->getEncPVsucc(); pv_E = srs->getEncPV_E(); pv_succ_E = srs->getEncPVsucc_E(); - pv_act_E = srs->getEncPVact_E(); + pv_ctx_E = srs->getEncPVctx_E(); + pv_proc_enab_E = srs->getEncPVproc_enab_E(); + + assert(pv != nullptr); + assert(pv_succ != nullptr); + assert(pv_E != nullptr); + assert(pv_succ_E != nullptr); + assert(pv_ctx_E != nullptr); + assert(pv_proc_enab_E != nullptr); // // Transition relations @@ -69,10 +77,12 @@ inline BDD ModelChecker::getSucc(const BDD &states) } else { q *= states * *trm; + BDD_PRINT(q); } q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); - q = q.ExistAbstract(*pv_act_E); + q = q.ExistAbstract(*pv_ctx_E); + q = q.ExistAbstract(*pv_proc_enab_E); return q; } @@ -93,7 +103,7 @@ inline BDD ModelChecker::getPreE(const BDD &states) } q = q.ExistAbstract(*pv_succ_E); - q = q.ExistAbstract(*pv_act_E); + q = q.ExistAbstract(*pv_ctx_E); return q; } @@ -113,7 +123,7 @@ inline BDD ModelChecker::getPreEctx(const BDD &states, const BDD *contexts) } q = q.ExistAbstract(*pv_succ_E); - q = q.ExistAbstract(*pv_act_E); + q = q.ExistAbstract(*pv_ctx_E); return q; } @@ -147,9 +157,7 @@ void ModelChecker::printReach(void) } dropCtxAutStatePart(*reach); - srs->printDecodedRctSysStates(*reach); - cleanup(); if (opts->measure) { diff --git a/mc.hh b/mc.hh index f6d7557..66307c4 100644 --- a/mc.hh +++ b/mc.hh @@ -25,7 +25,7 @@ class ModelChecker vector *pv_succ; BDD *pv_E; BDD *pv_succ_E; - BDD *pv_act_E; + BDD *pv_ctx_E; BDD *reach; vector *trp; BDD *trm; @@ -37,6 +37,8 @@ class ModelChecker BDD *pv_ca_E; BDD *pv_ca_succ_E; + BDD *pv_proc_enab_E; + unsigned int trp_size; unsigned int totalStateVars; diff --git a/symrs.cc b/symrs.cc index d99362e..f2c4cc2 100644 --- a/symrs.cc +++ b/symrs.cc @@ -215,27 +215,18 @@ void SymRS::initBDDvars(void) VERB_LN(2, "Variables for process enabledness/activity"); pv_proc_enab = new BDDvec(numberOfProc); + pv_proc_enab_E = new BDD(BDD_TRUE); for (unsigned int i = 0; i < numberOfProc; ++i) { - (*pv_proc_enab)[i] = cuddMgr->bddVar(bdd_var_idx++); + auto bdd_var = cuddMgr->bddVar(bdd_var_idx++); + (*pv_proc_enab)[i] = bdd_var; + *pv_proc_enab_E *= bdd_var; } // ---------------------------------------------------------- // Context Entities // ---------------------------------------------------------- - // // Actions/Contexts - // pv_act = new BDDvec(totalActions); - // pv_act_E = new BDD(BDD_TRUE); - // - // // TODO - // // Actions need also per-process PV and flattened PV - // - // for (unsigned int i = 0; i < totalActions; ++i) { - // (*pv_act)[i] = cuddMgr->bddVar(bdd_var_idx++); - // *pv_act_E *= (*pv_act)[i]; - // } - VERB_LN(2, "Variables for context entities"); pv_ctx = new BDDvec(totalCtxEntities); @@ -526,26 +517,33 @@ BDD SymRS::compContext(const BDD &context) const std::string SymRS::decodedRctSysStateToStr(const BDD &state) { - assert(0); std::string s = "{ "; - /* - for (unsigned int i = 0; i < totalRctSysStateVars; ++i) { - if (!(encEntity(i) * state).IsZero()) { - s += rs->entityToStr(i) + " "; + + for (const auto &proc_entities : usedProducts) { + + auto proc_id = proc_entities.first; + auto entities = proc_entities.second; + s += rs->getProcessName(proc_id) + "={ "; + + for (const auto &entity : entities) { + if (!(encEntity(proc_id, entity) * state).IsZero()) { + s += rs->entityToStr(entity) + " "; + } } + + s += "} "; } - */ + s += "}"; return s; } void SymRS::printDecodedRctSysStates(const BDD &states) { - assert(0); BDD unproc = states; while (!unproc.IsZero()) { - BDD t = unproc.PickOneMinterm(*pv_rs); + BDD t = unproc.PickOneMinterm(*pv_drs_flat); cout << decodedRctSysStateToStr(t) << endl; if (opts->verbose > 9) { @@ -663,7 +661,9 @@ void SymRS::encodeTransitions(void) auto products = proc_products.second; for (const auto &prod : products) { - *monoTrans = encEntityProduction(proc_id, prod); + *monoTrans *= encEntityProduction(proc_id, prod); + cout << rs->getProcessName(proc_id) << " " << rs->getEntityName(prod) << endl; + BDD_PRINT(encEntityProduction(proc_id, prod)); } } @@ -682,12 +682,6 @@ void SymRS::encodeTransitions(void) } } -BDD SymRS::encNoContext(void) -{ - assert(0); - return BDD_FALSE; -} - void SymRS::encodeInitStates(void) { if (usingContextAutomaton()) { diff --git a/symrs.hh b/symrs.hh index 040d476..71387f4 100644 --- a/symrs.hh +++ b/symrs.hh @@ -51,9 +51,13 @@ class SymRS { return pv_succ_E; } - BDD *getEncPVact_E(void) + BDD *getEncPVctx_E(void) { - return pv_act_E; + return pv_ctx_E; + } + BDD *getEncPVproc_enab_E(void) + { + return pv_proc_enab_E; } BDDvec *getEncPartTrans(void) { @@ -206,12 +210,7 @@ class SymRS BDD *pv_succ_E; BDDvec *pv_proc_enab; /*!< Variables indicating if a process is enabled */ - - BDDvec *pv_rs; // remove - BDDvec *pv_rs_succ; // remove - - BDD *pv_rs_E; // remove - BDD *pv_rs_succ_E; // remove + BDD *pv_proc_enab_E; vector *pv_drs; /*!< PVs for the product part of state (per DRS process) */ @@ -323,8 +322,6 @@ class SymRS std::string decodedRctSysStateToStr(const BDD &state); void printDecodedRctSysStates(const BDD &states); - BDD encNoContext(void); - DecompReactions getProductionConditions(Process proc_id); void initBDDvars(void); From 6e54380f143b13c01655a65498aea72ced20672c Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 3 Apr 2018 20:35:12 +0100 Subject: [PATCH 19/90] It works! --- mc.cc | 1 - symrs.cc | 27 +++++++++++++++++++++++---- symrs.hh | 3 +-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/mc.cc b/mc.cc index b0a148a..0b33196 100644 --- a/mc.cc +++ b/mc.cc @@ -77,7 +77,6 @@ inline BDD ModelChecker::getSucc(const BDD &states) } else { q *= states * *trm; - BDD_PRINT(q); } q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); diff --git a/symrs.cc b/symrs.cc index f2c4cc2..040d8bd 100644 --- a/symrs.cc +++ b/symrs.cc @@ -410,6 +410,15 @@ bool SymRS::ctxEntityExists(Process proc_id, Entity entity) const return false; } +bool SymRS::processUsesEntity(Process proc_id, Entity entity_id) const +{ + if (productEntityExists(proc_id, entity_id) || ctxEntityExists(proc_id, entity_id)) { + return true; + } + + return false; +} + BDD SymRS::encEntitiesConj_raw(Process proc_id, const Entities &entities, bool succ) { BDD r = BDD_TRUE; @@ -458,6 +467,9 @@ BDD SymRS::encEntityCondition(Process proc_id, Entity entity_id) r += encCtxEntity(proc_id, entity_id); } + // pointless call to this function -- we should have prevented it: + assert(r != BDD_FALSE); + return r; } @@ -589,7 +601,9 @@ BDD SymRS::encEnabledness(Process proc_id, Entity entity_id) BDD proc_reactants = BDD_FALSE; for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { - proc_reactants += encProcEnabled(proc_id) * encEntityCondition(proc_id, reactant); + if (processUsesEntity(proc_id, reactant)) { + proc_reactants += encProcEnabled(proc_id) * encEntityCondition(proc_id, reactant); + } } // END FOR: prod_id reactants *= proc_reactants; @@ -597,13 +611,18 @@ BDD SymRS::encEnabledness(Process proc_id, Entity entity_id) // For inhibitors, we take all the processes first and then we iterate over the inhibitors for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { - BDD proc_inhibitors = encProcEnabled(proc_id); + BDD proc_inhibitors = BDD_TRUE; for (const auto &inhibitor : cond.inhib) { - proc_inhibitors *= !encEntityCondition(proc_id, inhibitor); + if (processUsesEntity(proc_id, inhibitor)) { + proc_inhibitors *= !encEntityCondition(proc_id, inhibitor); + } } - inhibitors *= proc_inhibitors; + if (proc_inhibitors != BDD_TRUE) { // just an optimisation + proc_inhibitors += !encProcEnabled(proc_id); + inhibitors *= proc_inhibitors; + } } enab += reactants * inhibitors; diff --git a/symrs.hh b/symrs.hh index 71387f4..600e975 100644 --- a/symrs.hh +++ b/symrs.hh @@ -278,6 +278,7 @@ class SymRS bool productEntityExists(Process proc_id, Entity entity) const; bool ctxEntityExists(Process proc_id, Entity entity) const; + bool processUsesEntity(Process proc_id, Entity entity_id) const; BDD encProcEnabled(Process proc_id) const { @@ -294,8 +295,6 @@ class SymRS return encEntitiesConj_raw(proc_id, entities, true); } - // ---- TODO below: - BDD encEntitiesDisj_raw(Process proc_id, const Entities &entities, bool succ); BDD encEntitiesDisj(Process proc_id, const Entities &entities) { From d8398085aa73b2f6b0d62f1b15d34dc88a0f9e5d Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 3 Apr 2018 20:37:38 +0100 Subject: [PATCH 20/90] Clean-up --- mc.cc | 4 ++++ symrs.cc | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mc.cc b/mc.cc index 0b33196..eda6a2e 100644 --- a/mc.cc +++ b/mc.cc @@ -80,6 +80,10 @@ inline BDD ModelChecker::getSucc(const BDD &states) } q = (q.ExistAbstract(*pv_E)).SwapVariables(*pv_succ, *pv); + + // we should have one BDD for cleaning up + // it should be calculated at the very beginning + q = q.ExistAbstract(*pv_ctx_E); q = q.ExistAbstract(*pv_proc_enab_E); diff --git a/symrs.cc b/symrs.cc index 040d8bd..32889d6 100644 --- a/symrs.cc +++ b/symrs.cc @@ -681,8 +681,6 @@ void SymRS::encodeTransitions(void) for (const auto &prod : products) { *monoTrans *= encEntityProduction(proc_id, prod); - cout << rs->getProcessName(proc_id) << " " << rs->getEntityName(prod) << endl; - BDD_PRINT(encEntityProduction(proc_id, prod)); } } @@ -727,6 +725,7 @@ void SymRS::encodeInitStatesForCtxAut(void) BDD SymRS::encActStrEntity(std::string name) const { + assert(0); // TODO for rsCTL /* int id = getMappedStateToActID(rs->getEntityID(name)); From 30b62c88c6952120ae7ef563a16260b8b2ea01e5 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 14 Apr 2018 22:10:56 +0100 Subject: [PATCH 21/90] rsCTL PVs: process_name.entity_name. --- formrsctl.hh | 7 +++++-- rsin_parser.ll | 1 + rsin_parser.yy | 12 +++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/formrsctl.hh b/formrsctl.hh index baddbde..f83a709 100644 --- a/formrsctl.hh +++ b/formrsctl.hh @@ -74,14 +74,16 @@ class BoolContexts Oper oper; BoolContexts *arg[2]; std::string name; + std::string proc_name; bool tf; public: - BoolContexts(std::string varName) + BoolContexts(std::string procName, std::string varName) { oper = BCTX_PV; name = varName; + proc_name = procName; arg[0] = nullptr; arg[1] = nullptr; } @@ -167,9 +169,10 @@ class FormRSCTL * @param varName variable name used mostly for printing the variable. * @param varBDD the BDD describing the set where the variable holds. */ - FormRSCTL(std::string varName) + FormRSCTL(std::string procName, std::string varName) { oper = RSCTL_PV; + proc_name = procName; entity_name = varName; arg[0] = nullptr; arg[1] = nullptr; diff --git a/rsin_parser.ll b/rsin_parser.ll index 8bf8600..3bd41f0 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -60,6 +60,7 @@ blank [ \t] ">" return token::RAB; ":" return token::COL; ";" return token::SEMICOL; +"." return token::DOT; "," return token::COMMA; "->" return token::RARR; "AND" return token::AND; diff --git a/rsin_parser.yy b/rsin_parser.yy index a702f17..fdf79b2 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -47,7 +47,7 @@ class rsin_driver; %token OPTIONS USE_CTX_AUT USE_CONCENTRATIONS %token REACTIONS INITIALCONTEXTS CONTEXTENTITIES RSCTLFORM %token CONTEXTAUTOMATON STATES INITSTATE TRANSITIONS -%token EQ LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL COMMA RARR +%token EQ LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL DOT COMMA RARR %token AND OR XOR IMPLIES NOT %token EX EU EF EG AX AU AF AG E A X U F G EMPTY @@ -259,9 +259,10 @@ ctxentity: IDENTIFIER { /* formulae */ -bool_contexts: IDENTIFIER { - $$ = new BoolContexts(*$1); +bool_contexts: IDENTIFIER DOT IDENTIFIER { + $$ = new BoolContexts(*$1, *$3); free($1); + free($3); } | NOT bool_contexts { $$ = new BoolContexts(BCTX_NOT, $2); @@ -315,9 +316,10 @@ f_entity: IDENTIFIER { } ; -rsctl_form: IDENTIFIER { - $$ = new FormRSCTL(*$1); +rsctl_form: IDENTIFIER DOT IDENTIFIER { + $$ = new FormRSCTL(*$1, *$3); free($1); + free($3); } | NOT rsctl_form { $$ = new FormRSCTL(RSCTL_NOT, $2); From c4c3af0300232981ddd5a75a1f6f7c8d13d8349a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 15 Apr 2018 12:25:57 +0100 Subject: [PATCH 22/90] Removed action sets in formulae --- formrsctl.cc | 101 +++++++++++++++++++-------------------- formrsctl.hh | 74 ++++++++++++++--------------- rsin_parser.yy | 126 +++++++++++++++++++++++++------------------------ 3 files changed, 152 insertions(+), 149 deletions(-) diff --git a/formrsctl.cc b/formrsctl.cc index 2b97e25..570544b 100644 --- a/formrsctl.cc +++ b/formrsctl.cc @@ -226,40 +226,40 @@ bool FormRSCTL::isERSCTL(void) const std::string FormRSCTL::getActionsStr(void) const { - if (actions != nullptr) { - std::string r = "[ "; - bool firstact = true; - - for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); - ++act) { - if (!firstact) { - r += ","; - } - else { - firstact = false; - } - - r += "{"; - bool firstent = true; - - for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) { - if (!firstent) { - r += ","; - } - else { - firstent = false; - } - - r += *ent; - } - - r += "}"; - } - - r += " ]"; - return r; - } - else if (boolCtx != nullptr) { + // if (actions != nullptr) { + // std::string r = "[ "; + // bool firstact = true; + // + // for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); + // ++act) { + // if (!firstact) { + // r += ","; + // } + // else { + // firstact = false; + // } + // + // r += "{"; + // bool firstent = true; + // + // for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) { + // if (!firstent) { + // r += ","; + // } + // else { + // firstent = false; + // } + // + // r += *ent; + // } + // + // r += "}"; + // } + // + // r += " ]"; + // return r; + // } + if (boolCtx != nullptr) { return "< " + boolCtx->toStr() + " >"; } else { @@ -275,23 +275,24 @@ void FormRSCTL::encodeActions(const SymRS *srs) } actions_bdd = new BDD(srs->getBDDfalse()); - assert(actions != nullptr || boolCtx != nullptr); - assert(!(actions != nullptr && boolCtx != nullptr)); + assert(boolCtx != nullptr); + // assert(actions != nullptr || boolCtx != nullptr); + // assert(!(actions != nullptr && boolCtx != nullptr)); - if (actions != nullptr) { - for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); - ++act) { - BDD single_action = srs->getBDDtrue(); - - for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) { - single_action *= srs->encActStrEntity(*ent); - } - - single_action = srs->compContext(single_action); - *actions_bdd += single_action; - } - } - else if (boolCtx != nullptr) { + // if (actions != nullptr) { + // for (ActionsVec_f::iterator act = actions->begin(); act != actions->end(); + // ++act) { + // BDD single_action = srs->getBDDtrue(); + // + // for (Action_f::iterator ent = act->begin(); ent != act->end(); ++ent) { + // single_action *= srs->encActStrEntity(*ent); + // } + // + // single_action = srs->compContext(single_action); + // *actions_bdd += single_action; + // } + // } + if (boolCtx != nullptr) { *actions_bdd = boolCtx->getBDD(srs); } else { diff --git a/formrsctl.hh b/formrsctl.hh index f83a709..60a9db8 100644 --- a/formrsctl.hh +++ b/formrsctl.hh @@ -65,9 +65,9 @@ using std::endl; typedef unsigned char Oper; -typedef std::string Entity_f; -typedef std::set Action_f; -typedef vector ActionsVec_f; +// typedef std::string Entity_f; +// typedef std::set Action_f; +// typedef vector ActionsVec_f; class BoolContexts { @@ -159,7 +159,7 @@ class FormRSCTL std::string proc_name; bool tf; BDD *bdd; - ActionsVec_f *actions; + // ActionsVec_f *actions; BDD *actions_bdd; BoolContexts *boolCtx; public: @@ -177,7 +177,7 @@ class FormRSCTL arg[0] = nullptr; arg[1] = nullptr; bdd = nullptr; - actions = nullptr; + // actions = nullptr; actions_bdd = nullptr; boolCtx = nullptr; } @@ -194,7 +194,7 @@ class FormRSCTL arg[0] = nullptr; arg[1] = nullptr; bdd = nullptr; - actions = nullptr; + // actions = nullptr; actions_bdd = nullptr; boolCtx = nullptr; } @@ -210,7 +210,7 @@ class FormRSCTL arg[0] = form1; arg[1] = form2; bdd = nullptr; - actions = nullptr; + // actions = nullptr; actions_bdd = nullptr; boolCtx = nullptr; } @@ -218,19 +218,19 @@ class FormRSCTL /** * @brief Constructor for two-argument formula with action restrictions. */ - FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1, FormRSCTL *form2) - { - assert(acts != nullptr); - assert(RSCTL_COND_2ARG(op)); - assert(RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = form2; - bdd = nullptr; - actions = acts; - actions_bdd = nullptr; - boolCtx = nullptr; - } + // FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1, FormRSCTL *form2) + // { + // assert(acts != nullptr); + // assert(RSCTL_COND_2ARG(op)); + // assert(RSCTL_COND_ACT(op)); + // oper = op; + // arg[0] = form1; + // arg[1] = form2; + // bdd = nullptr; + // actions = acts; + // actions_bdd = nullptr; + // boolCtx = nullptr; + // } /** * @brief Constructor for two-argument formula with Boolean context restrictions. @@ -244,7 +244,7 @@ class FormRSCTL arg[0] = form1; arg[1] = form2; bdd = nullptr; - actions = nullptr; + // actions = nullptr; actions_bdd = nullptr; boolCtx = bctx; } @@ -260,7 +260,7 @@ class FormRSCTL arg[0] = form1; arg[1] = nullptr; bdd = nullptr; - actions = nullptr; + // actions = nullptr; actions_bdd = nullptr; boolCtx = nullptr; } @@ -268,19 +268,19 @@ class FormRSCTL /** * @brief Constructor for one-argument formula with action restrictions. */ - FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1) - { - assert(acts != nullptr); - assert(RSCTL_COND_1ARG(op)); - assert(RSCTL_COND_ACT(op)); - oper = op; - arg[0] = form1; - arg[1] = nullptr; - bdd = nullptr; - actions = acts; - actions_bdd = nullptr; - boolCtx = nullptr; - } + // FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1) + // { + // assert(acts != nullptr); + // assert(RSCTL_COND_1ARG(op)); + // assert(RSCTL_COND_ACT(op)); + // oper = op; + // arg[0] = form1; + // arg[1] = nullptr; + // bdd = nullptr; + // // actions = acts; + // actions_bdd = nullptr; + // boolCtx = nullptr; + // } /** * @brief Constructor for one-argument formula with Boolean context restrictions. @@ -294,7 +294,7 @@ class FormRSCTL arg[0] = form1; arg[1] = nullptr; bdd = nullptr; - actions = nullptr; + // actions = nullptr; actions_bdd = nullptr; boolCtx = bctx; } @@ -307,7 +307,7 @@ class FormRSCTL delete arg[0]; delete arg[1]; delete bdd; - delete actions; + // delete actions; delete actions_bdd; delete boolCtx; } diff --git a/rsin_parser.yy b/rsin_parser.yy index fdf79b2..6910086 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -34,9 +34,9 @@ class rsin_driver; int ival; std::string *sval; FormRSCTL *frsctl; - Entity_f *ent; - Action_f *act; - ActionsVec_f *actionsVec; + // Entity_f *ent; + // Action_f *act; + // ActionsVec_f *actionsVec; BoolContexts *fboolctx; }; @@ -61,9 +61,9 @@ class rsin_driver; //%right SRB %type rsctl_form -%type f_entity -%type action -%type actions +// %type f_entity +// %type action +// %type actions %type bool_contexts //%printer { yyoutput << *$$; } "identifier" @@ -281,40 +281,40 @@ bool_contexts: IDENTIFIER DOT IDENTIFIER { } ; -actions: - LCB action RCB { - $$ = new ActionsVec_f; - $$->push_back(*$2); - free($2); - } - | actions COMMA LCB action RCB { - $$ = $1; - $$->push_back(*$4); - free($4); - } - ; +// actions: +// LCB action RCB { +// $$ = new ActionsVec_f; +// $$->push_back(*$2); +// free($2); +// } +// | actions COMMA LCB action RCB { +// $$ = $1; +// $$->push_back(*$4); +// free($4); +// } +// ; -action: - { - $$ = new Action_f; - } - | f_entity { - $$ = new Action_f; - $$->insert(*$1); - free($1); - } - | action COMMA f_entity { - $$ = $1; - $$->insert(*$3); - free($3); - } - ; +// action: +// { +// $$ = new Action_f; +// } +// | f_entity { +// $$ = new Action_f; +// $$->insert(*$1); +// free($1); +// } +// | action COMMA f_entity { +// $$ = $1; +// $$->insert(*$3); +// free($3); +// } +// ; -f_entity: IDENTIFIER { - $$ = new Entity_f(*$1); - free($1); - } - ; +// f_entity: IDENTIFIER { +// $$ = new Entity_f(*$1); +// free($1); +// } +// ; rsctl_form: IDENTIFIER DOT IDENTIFIER { $$ = new FormRSCTL(*$1, *$3); @@ -363,30 +363,32 @@ rsctl_form: IDENTIFIER DOT IDENTIFIER { | AG rsctl_form { $$ = new FormRSCTL(RSCTL_AG, $2); } - | E LSB actions RSB X rsctl_form { - $$ = new FormRSCTL(RSCTL_EX_ACT, $3, $6); - } - | E LSB actions RSB U LRB rsctl_form COMMA rsctl_form RRB { - $$ = new FormRSCTL(RSCTL_EU_ACT, $3, $7, $9); - } - | E LSB actions RSB F rsctl_form { - $$ = new FormRSCTL(RSCTL_EF_ACT, $3, $6); - } - | E LSB actions RSB G rsctl_form { - $$ = new FormRSCTL(RSCTL_EG_ACT, $3, $6); - } - | A LSB actions RSB X rsctl_form { - $$ = new FormRSCTL(RSCTL_AX_ACT, $3, $6); - } - | A LSB actions RSB U LRB rsctl_form COMMA rsctl_form RRB { - $$ = new FormRSCTL(RSCTL_AU_ACT, $3, $7, $9); - } - | A LSB actions RSB F rsctl_form { - $$ = new FormRSCTL(RSCTL_AF_ACT, $3, $6); - } - | A LSB actions RSB G rsctl_form { - $$ = new FormRSCTL(RSCTL_AG_ACT, $3, $6); - } + + // | E LSB actions RSB X rsctl_form { + // $$ = new FormRSCTL(RSCTL_EX_ACT, $3, $6); + // } + // | E LSB actions RSB U LRB rsctl_form COMMA rsctl_form RRB { + // $$ = new FormRSCTL(RSCTL_EU_ACT, $3, $7, $9); + // } + // | E LSB actions RSB F rsctl_form { + // $$ = new FormRSCTL(RSCTL_EF_ACT, $3, $6); + // } + // | E LSB actions RSB G rsctl_form { + // $$ = new FormRSCTL(RSCTL_EG_ACT, $3, $6); + // } + // | A LSB actions RSB X rsctl_form { + // $$ = new FormRSCTL(RSCTL_AX_ACT, $3, $6); + // } + // | A LSB actions RSB U LRB rsctl_form COMMA rsctl_form RRB { + // $$ = new FormRSCTL(RSCTL_AU_ACT, $3, $7, $9); + // } + // | A LSB actions RSB F rsctl_form { + // $$ = new FormRSCTL(RSCTL_AF_ACT, $3, $6); + // } + // | A LSB actions RSB G rsctl_form { + // $$ = new FormRSCTL(RSCTL_AG_ACT, $3, $6); + // } + /* contexts as boolean formulae */ | E LAB bool_contexts RAB X rsctl_form { $$ = new FormRSCTL(RSCTL_EX_ACT, $3, $6); From d34e3954c47011eb34eb33478a246ebb2355a121 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 15 Apr 2018 13:20:07 +0100 Subject: [PATCH 23/90] First working version of rsCTL verification. --- formrsctl.cc | 6 +++--- formrsctl.hh | 4 ++-- mc.cc | 2 ++ symrs.cc | 17 +++-------------- symrs.hh | 2 +- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/formrsctl.cc b/formrsctl.cc index 570544b..f85693a 100644 --- a/formrsctl.cc +++ b/formrsctl.cc @@ -12,7 +12,7 @@ std::string BoolContexts::toStr(void) const { if (oper == BCTX_PV) { - return name; + return proc_name + "." + entity_name; } else if (oper == BCTX_TF) { if (tf) { @@ -44,7 +44,7 @@ std::string BoolContexts::toStr(void) const BDD BoolContexts::getBDD(const SymRS *srs) const { if (oper == BCTX_PV) { - return srs->encActStrEntity(name); + return srs->encActStrEntity(proc_name, entity_name); } else if (oper == BCTX_TF) { if (tf) { @@ -76,7 +76,7 @@ BDD BoolContexts::getBDD(const SymRS *srs) const std::string FormRSCTL::toStr(void) const { if (oper == RSCTL_PV) { - return proc_name + ":" + entity_name; + return proc_name + "." + entity_name; } else if (oper == RSCTL_TF) { if (tf) { diff --git a/formrsctl.hh b/formrsctl.hh index 60a9db8..8f64c97 100644 --- a/formrsctl.hh +++ b/formrsctl.hh @@ -73,7 +73,7 @@ class BoolContexts { Oper oper; BoolContexts *arg[2]; - std::string name; + std::string entity_name; std::string proc_name; bool tf; @@ -82,7 +82,7 @@ class BoolContexts BoolContexts(std::string procName, std::string varName) { oper = BCTX_PV; - name = varName; + entity_name = varName; proc_name = procName; arg[0] = nullptr; arg[1] = nullptr; diff --git a/mc.cc b/mc.cc index eda6a2e..315cdc8 100644 --- a/mc.cc +++ b/mc.cc @@ -107,6 +107,7 @@ inline BDD ModelChecker::getPreE(const BDD &states) q = q.ExistAbstract(*pv_succ_E); q = q.ExistAbstract(*pv_ctx_E); + q = q.ExistAbstract(*pv_proc_enab_E); return q; } @@ -127,6 +128,7 @@ inline BDD ModelChecker::getPreEctx(const BDD &states, const BDD *contexts) q = q.ExistAbstract(*pv_succ_E); q = q.ExistAbstract(*pv_ctx_E); + q = q.ExistAbstract(*pv_proc_enab_E); return q; } diff --git a/symrs.cc b/symrs.cc index 32889d6..1dcaa55 100644 --- a/symrs.cc +++ b/symrs.cc @@ -723,21 +723,10 @@ void SymRS::encodeInitStatesForCtxAut(void) *initStates *= getEncCtxAutInitState(); } -BDD SymRS::encActStrEntity(std::string name) const +BDD SymRS::encActStrEntity(std::string proc_name, std::string entity_name) const { - assert(0); // TODO for rsCTL - /* - int id = getMappedStateToActID(rs->getEntityID(name)); - - if (id < 0) { - FERROR("Entity \"" << name << "\" not defined as context entity"); - return BDD_FALSE; - } - else { - return encActEntity(getMappedStateToActID(rs->getEntityID(name))); - } - */ - return BDD_FALSE; + auto enc_entity = encCtxEntity(rs->getProcessID(proc_name), rs->getEntityID(entity_name)); + return enc_entity; } size_t SymRS::getCtxAutStateEncodingSize(void) diff --git a/symrs.hh b/symrs.hh index 600e975..cf7be42 100644 --- a/symrs.hh +++ b/symrs.hh @@ -87,7 +87,7 @@ class SymRS { return encEntity(rs->getProcessID(proc_name), rs->getEntityID(entity_name)); } - BDD encActStrEntity(std::string name) const; + BDD encActStrEntity(std::string proc_name, std::string entity_name) const; BDD getBDDtrue(void) const { return BDD_TRUE; From 8a9ba95fed556d3cdf73cb94d63f835e6bc2fd05 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 15 Apr 2018 18:47:52 +0100 Subject: [PATCH 24/90] Quantification BDDs for each process; example --- in/hsr_drs.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ symrs.cc | 6 +++++ symrs.hh | 2 ++ 3 files changed, 72 insertions(+) create mode 100644 in/hsr_drs.rs diff --git a/in/hsr_drs.rs b/in/hsr_drs.rs new file mode 100644 index 0000000..f4bcd00 --- /dev/null +++ b/in/hsr_drs.rs @@ -0,0 +1,64 @@ +options { use-context-automaton; } + +reactions { + mainA { + {{hsf},{hsp} -> {hsf3}}; #10 + {{hsf,hsp,mfp},{dI} -> {hsf3}}; #11 + {{hsf3},{hse,hsp} -> {hsf}}; #12 + {{hsf3,hsp,mfp},{hse} -> {hsf}}; #13 + {{hsf3,hse},{hsp} -> {hsf3:hse}}; #14 + {{hsf3,hse,hsp,mfp},{dI} -> {hsf3:hse}}; #15 + {{hse},{hsf3} -> {hse}}; #16 + {{hse,hsf3,hsp},{mfp} -> {hse}}; #17 + {{hsf3:hse},{hsp} -> {hsf3:hse,hsp}}; #18 + {{hsf3:hse,hsp,mfp},{dI} -> {hsf3:hse,hsp}}; #19 + {{hsp,hsf},{mfp} -> {hsp:hsf}}; #20 + {{hsp:hsf,stress},{nostress} -> {hsp,hsf}}; #21 + {{hsp:hsf,nostress},{stress} -> {hsp:hsf}}; #22 + {{hsp,hsf3},{mfp} -> {hsp:hsf}}; #23 + {{hsp,hsf3:hse},{mfp} -> {hsp:hsf,hse}}; + {{prot,stress},{nostress} -> {prot,mfp}}; + {{prot,nostress},{stress} -> {prot}}; + {{hsp,mfp},{dI} -> {hsp:mfp}}; + {{mfp},{hsp} -> {mfp}}; + {{hsp:mfp},{dI} -> {hsp,prot}}; + }; + + dummy { + {{mfp},{hsp} -> {mfp}}; + }; + +} + +context-automaton { + states { s0, s1 } + init-state { s0 } + transitions { + { mainA={hsf,prot,hse,nostress} }: s0 -> s1; + { mainA={hsf,prot,hsp:hsf,stress} }: s0 -> s1; + { mainA={hsp,prot,hsf3:hse,mfp,hsp:mfp,nostress} }: s0 -> s1; + { mainA={stress} }: s1 -> s1; + { mainA={nostress} }: s1 -> s1; + { mainA={stress,nostress} }: s1 -> s1; + } +} + +# P1 +rsctl-property { AG(mainA.hse OR mainA.hsf3:hse IMPLIES AX(mainA.hse OR mainA.hsf3:hse)) } + +# P2 +#rsctl-property { A[{stress},{nostress}]G(~(hse AND hsf3:hse) IMPLIES A[{stress},{nostress}]X(~(hse AND hsf3:hse))) } + +# P3 +#rsctl-property { A[{stress},{nostress}]G(prot IMPLIES A[{stress},{nostress}]X(prot)) } + +# P4 +#rsctl-property { A[{stress},{nostress}]G(mfp IMPLIES A[{stress},{nostress}]X(mfp OR hsp:mfp)) } +#rsctl-property { A< stress XOR nostress >G(mfp IMPLIES A[{stress},{nostress}]X(mfp OR hsp:mfp)) } + +# P5 +#rsctl-property { A[{stress},{nostress}]G( ((hsf XOR hsf3 XOR hsf3:hse XOR hsp:hsf) OR ~(hsf OR hsf3 OR hsf3:hse OR hsp:hsf)) IMPLIES A[{stress},{nostress}]X( (hsf XOR hsf3 XOR hsf3:hse XOR hsp:hsf) OR ~(hsf OR hsf3 OR hsf3:hse OR hsp:hsf) ) ) } + +# P6 +#rsctl-property { A[{nostress}]G(hsp:hsf IMPLIES A[{nostress}]X (hsp:hsf)) } + diff --git a/symrs.cc b/symrs.cc index 1dcaa55..3126496 100644 --- a/symrs.cc +++ b/symrs.cc @@ -118,6 +118,8 @@ void SymRS::initBDDvars(void) pv_drs_flat = new BDDvec(totalRctSysStateVars); pv_drs_flat_succ = new BDDvec(totalRctSysStateVars); + pv_drs_E = new BDDvec(numberOfProc); + pv_drs_flat_E = new BDD(BDD_TRUE); pv_drs_flat_succ_E = new BDD(BDD_TRUE); @@ -151,6 +153,8 @@ void SymRS::initBDDvars(void) (*pv_drs)[proc_id].resize(entities_count); (*pv_drs_succ)[proc_id].resize(entities_count); + (*pv_drs_E)[proc_id] = BDD_TRUE; + for (unsigned int i = 0; i < entities_count; ++i) { assert(drs_flat_index < totalRctSysStateVars); @@ -162,6 +166,8 @@ void SymRS::initBDDvars(void) (*pv_drs)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); (*pv_drs_succ)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); + (*pv_drs_E)[proc_id] *= (*pv_drs)[proc_id][i]; + // The DRS part of the system (flattened): these vars do not include CA (*pv_drs_flat)[drs_flat_index] = (*pv_drs)[proc_id][i]; (*pv_drs_flat_succ)[drs_flat_index] = (*pv_drs_succ)[proc_id][i]; diff --git a/symrs.hh b/symrs.hh index cf7be42..18212b9 100644 --- a/symrs.hh +++ b/symrs.hh @@ -216,6 +216,8 @@ class SymRS (per DRS process) */ vector *pv_drs_succ; /*!< PVs for the product (successor) part of state (per DRS process) */ + + BDDvec *pv_drs_E; /*!< Quantification BDDs for each process */ BDDvec *pv_drs_flat; /*!< PVs for the DRS product part of state (flat) */ BDDvec *pv_drs_flat_succ; /*!< PVs for the DRS product (successor) part of state (flat) */ From 81e9d13ade4a58d34bd24ee1763a627fd168b221 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 15 Apr 2018 19:01:30 +0100 Subject: [PATCH 25/90] Expistemic operators, quantification --- mc.cc | 2 ++ mc.hh | 1 + rsin_parser.ll | 8 ++++++++ rsin_parser.yy | 4 ++-- symrs.cc | 1 + symrs.hh | 6 +++++- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mc.cc b/mc.cc index 315cdc8..e4be58e 100644 --- a/mc.cc +++ b/mc.cc @@ -18,6 +18,7 @@ ModelChecker::ModelChecker(SymRS *srs, Options *opts) pv_succ_E = srs->getEncPVsucc_E(); pv_ctx_E = srs->getEncPVctx_E(); pv_proc_enab_E = srs->getEncPVproc_enab_E(); + pv_drs_E = srs->getEncPVdrs_E(); assert(pv != nullptr); assert(pv_succ != nullptr); @@ -25,6 +26,7 @@ ModelChecker::ModelChecker(SymRS *srs, Options *opts) assert(pv_succ_E != nullptr); assert(pv_ctx_E != nullptr); assert(pv_proc_enab_E != nullptr); + assert(pv_drs_E != nullptr); // // Transition relations diff --git a/mc.hh b/mc.hh index 66307c4..31fe9ae 100644 --- a/mc.hh +++ b/mc.hh @@ -26,6 +26,7 @@ class ModelChecker BDD *pv_E; BDD *pv_succ_E; BDD *pv_ctx_E; + BDDvec *pv_drs_E; BDD *reach; vector *trp; BDD *trm; diff --git a/rsin_parser.ll b/rsin_parser.ll index 3bd41f0..20dba91 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -82,6 +82,14 @@ blank [ \t] "U" return token::U; "F" return token::F; "G" return token::G; +"UK" return token::UK; +"UC" return token::UC; +"UD" return token::UD; +"UE" return token::UE; +"NK" return token::NK; +"NC" return token::NC; +"ND" return token::ND; +"NE" return token::NE; "empty" return token::EMPTY; "#".* ; diff --git a/rsin_parser.yy b/rsin_parser.yy index 6910086..0600a30 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -49,14 +49,14 @@ class rsin_driver; %token CONTEXTAUTOMATON STATES INITSTATE TRANSITIONS %token EQ LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL DOT COMMA RARR %token AND OR XOR IMPLIES NOT -%token EX EU EF EG AX AU AF AG E A X U F G EMPTY +%token EX EU EF EG AX AU AF AG E A X U F G UK UC UD UE NK NC ND NE EMPTY %token END 0 "end of file" %token IDENTIFIER "identifier" %token NUMBER "number" %left AND OR XOR IMPLIES NOT -%left EX EU EF EG AX AU AF AG E A X U F G +%left EX EU EF EG AX AU AF AG E A X U F G UK UC UD UE NK NC ND NE //%right SRB diff --git a/symrs.cc b/symrs.cc index 3126496..71f3fbf 100644 --- a/symrs.cc +++ b/symrs.cc @@ -166,6 +166,7 @@ void SymRS::initBDDvars(void) (*pv_drs)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); (*pv_drs_succ)[proc_id][i] = cuddMgr->bddVar(bdd_var_idx++); + // Quantification (per proc) (*pv_drs_E)[proc_id] *= (*pv_drs)[proc_id][i]; // The DRS part of the system (flattened): these vars do not include CA diff --git a/symrs.hh b/symrs.hh index 18212b9..5133420 100644 --- a/symrs.hh +++ b/symrs.hh @@ -59,6 +59,10 @@ class SymRS { return pv_proc_enab_E; } + BDDvec *getEncPVdrs_E(void) + { + return pv_drs_E; + } BDDvec *getEncPartTrans(void) { return partTrans; @@ -216,7 +220,7 @@ class SymRS (per DRS process) */ vector *pv_drs_succ; /*!< PVs for the product (successor) part of state (per DRS process) */ - + BDDvec *pv_drs_E; /*!< Quantification BDDs for each process */ BDDvec *pv_drs_flat; /*!< PVs for the DRS product part of state (flat) */ From f5e0beb5131aa6acb650cc3a2365e94eb26d9d9d Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 15 Apr 2018 20:00:05 +0100 Subject: [PATCH 26/90] Parsing of K --- formrsctl.hh | 30 +++++++++++++++++++++++------- rsin_parser.ll | 10 ++++------ rsin_parser.yy | 11 +++++++++-- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/formrsctl.hh b/formrsctl.hh index 8f64c97..58b2feb 100644 --- a/formrsctl.hh +++ b/formrsctl.hh @@ -40,16 +40,19 @@ #define RSCTL_AF_ACT 44 #define RSCTL_TF 50 // true/false +#define RSCTL_UK 60 // Epistemic operators +#define RSCTL_NK 61 + /* For Boolean contexts: */ -#define BCTX_PV 60 -#define BCTX_AND 61 -#define BCTX_OR 62 -#define BCTX_XOR 63 -#define BCTX_NOT 64 -#define BCTX_TF 70 +#define BCTX_PV 80 +#define BCTX_AND 81 +#define BCTX_OR 82 +#define BCTX_XOR 83 +#define BCTX_NOT 84 +#define BCTX_TF 90 -#define RSCTL_COND_1ARG(a) ((a) == RSCTL_NOT || (a) == RSCTL_EG || (a) == RSCTL_EF || (a) == RSCTL_EX || (a) == RSCTL_AG || (a) == RSCTL_AF || (a) == RSCTL_AX || (a) == RSCTL_EG_ACT || (a) == RSCTL_EF_ACT || (a) == RSCTL_EX_ACT || (a) == RSCTL_AG_ACT || (a) == RSCTL_AF_ACT || (a) == RSCTL_AX_ACT) +#define RSCTL_COND_1ARG(a) ((a) == RSCTL_NOT || (a) == RSCTL_EG || (a) == RSCTL_EF || (a) == RSCTL_EX || (a) == RSCTL_AG || (a) == RSCTL_AF || (a) == RSCTL_AX || (a) == RSCTL_EG_ACT || (a) == RSCTL_EF_ACT || (a) == RSCTL_EX_ACT || (a) == RSCTL_AG_ACT || (a) == RSCTL_AF_ACT || (a) == RSCTL_AX_ACT || (a) == RSCTL_UK || (a) == RSCTL_NK) #define RSCTL_COND_2ARG(a) ((a) == RSCTL_AND || (a) == RSCTL_OR || (a) == RSCTL_XOR || (a) == RSCTL_IMPL || (a) == RSCTL_EU || (a) == RSCTL_AU || (a) == RSCTL_EU_ACT || (a) == RSCTL_AU_ACT) #define RSCTL_COND_ACT(a) ((a) > 30 && (a) < 45) #define RSCTL_IS_VALID(a) (RSCTL_COND_1ARG(a) || RSCTL_COND_2ARG(a) || (a) == RSCTL_PV || (a) == RSCTL_TF) @@ -68,6 +71,7 @@ typedef unsigned char Oper; // typedef std::string Entity_f; // typedef std::set Action_f; // typedef vector ActionsVec_f; +typedef std::set Agents_f; class BoolContexts { @@ -162,6 +166,7 @@ class FormRSCTL // ActionsVec_f *actions; BDD *actions_bdd; BoolContexts *boolCtx; + Agents_f agents; public: /** * @brief Constructor for propositional variable. @@ -299,6 +304,17 @@ class FormRSCTL boolCtx = bctx; } + FormRSCTL(Oper op, Agents_f agents_set, FormRSCTL *form1) + { + assert(RSCTL_COND_1ARG(op)); + oper = op; + arg[0] = form1; + arg[1] = nullptr; + bdd = nullptr; + actions_bdd = nullptr; + agents = agents_set; + } + /** * @brief Destructor. */ diff --git a/rsin_parser.ll b/rsin_parser.ll index 20dba91..1abe2fc 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -76,16 +76,14 @@ blank [ \t] "AU" return token::AU; "AF" return token::AF; "AG" return token::AG; -"E" return token::E; -"A" return token::A; "X" return token::X; "U" return token::U; "F" return token::F; "G" return token::G; -"UK" return token::UK; -"UC" return token::UC; -"UD" return token::UD; -"UE" return token::UE; +"K" return token::UK; +"C" return token::UC; +"D" return token::UD; +"E" return token::UE; "NK" return token::NK; "NC" return token::NC; "ND" return token::ND; diff --git a/rsin_parser.yy b/rsin_parser.yy index 0600a30..f308f65 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -316,7 +316,8 @@ bool_contexts: IDENTIFIER DOT IDENTIFIER { // } // ; -rsctl_form: IDENTIFIER DOT IDENTIFIER { +rsctl_form: + IDENTIFIER DOT IDENTIFIER { $$ = new FormRSCTL(*$1, *$3); free($1); free($3); @@ -362,6 +363,12 @@ rsctl_form: IDENTIFIER DOT IDENTIFIER { } | AG rsctl_form { $$ = new FormRSCTL(RSCTL_AG, $2); + } + | UK LSB IDENTIFIER RSB LRB rsctl_form RRB { + Agents_f agents; + agents.insert(*$3); + $$ = new FormRSCTL(RSCTL_UK, agents, $6); + free($3); } // | E LSB actions RSB X rsctl_form { @@ -389,7 +396,7 @@ rsctl_form: IDENTIFIER DOT IDENTIFIER { // $$ = new FormRSCTL(RSCTL_AG_ACT, $3, $6); // } - /* contexts as boolean formulae */ + /* contexts as boolean formulae */ | E LAB bool_contexts RAB X rsctl_form { $$ = new FormRSCTL(RSCTL_EX_ACT, $3, $6); } From 09578a075ff2c06d6016e797dbdb503793983bd9 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 21 Apr 2018 19:15:06 +0100 Subject: [PATCH 27/90] Quantification for only the i-th process --- mc.cc | 24 ++++++++++++++++++++++++ mc.hh | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/mc.cc b/mc.cc index e4be58e..d6da428 100644 --- a/mc.cc +++ b/mc.cc @@ -430,6 +430,30 @@ BDD ModelChecker::statesEFctx(const BDD *contexts, const BDD &states) return x; } +BDD ModelChecker::getIthOnly(Process proc_id) +{ + /* if possible, we return the BDD from cache */ + if (ith_only_E.count(proc_id) == 1) { + return ith_only_E[proc_id]; + } + + /* nothing has been found in the cache */ + BDD bdd = BDD_TRUE; + + for (auto i = 0; i < pv_drs_E->size(); ++i) { + + if (i == proc_id) { + continue; + } + + bdd *= (*pv_drs_E)[i]; + } + + ith_only_E[proc_id] = bdd; + + return bdd; +} + bool ModelChecker::checkRSCTL(FormRSCTL *form) { if (form->isERSCTL()) { diff --git a/mc.hh b/mc.hh index 31fe9ae..12497d9 100644 --- a/mc.hh +++ b/mc.hh @@ -31,6 +31,8 @@ class ModelChecker vector *trp; BDD *trm; + std::map ith_only_E; + // Context Automaton bool using_ctx_aut; vector *pv_ca; @@ -58,6 +60,9 @@ class ModelChecker BDD statesEGctx(const BDD *contexts, const BDD &states); BDD statesEUctx(const BDD *contexts, const BDD &statesA, const BDD &statesB); BDD statesEFctx(const BDD *contexts, const BDD &states); + + BDD getIthOnly(Process proc_id); + void cleanup(void); public: From d2a9b5733c18bf5859e5b6c7e2f259c55f38e3a7 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 21 Apr 2018 19:33:32 +0100 Subject: [PATCH 28/90] RSCTL -> RSCTLK --- Makefile | 2 +- formrsctl.cc => formrsctlk.cc | 88 +++++++++++----------- formrsctl.hh => formrsctlk.hh | 134 ++++++++++++++++----------------- main.cc | 6 +- mc.cc | 128 +++++++++++++++---------------- mc.hh | 10 +-- rs.hh | 2 +- rsin_driver.cc | 10 +-- rsin_driver.hh | 10 +-- rsin_parser.ll | 2 +- rsin_parser.yy | 138 +++++++++++++++++----------------- symrs.hh | 2 +- 12 files changed, 266 insertions(+), 266 deletions(-) rename formrsctl.cc => formrsctlk.cc (77%) rename formrsctl.hh => formrsctlk.hh (67%) diff --git a/Makefile b/Makefile index 2491bc7..40d229f 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ CXXFLAGS = -std=c++14 $(CXXFLAGS_SILENT) #CXXFLAGS = -std=c++14 -O3 -DPUBLIC_RELEASE -DNDEBUG #-g LDLIBS = $(CUDD_INCLUDE) -OBJ = rs.o ctx_aut.o symrs.o mc.o rsin_driver.o rsin_parser.o rsin_parser.lex.o formrsctl.o +OBJ = rs.o ctx_aut.o symrs.o mc.o rsin_driver.o rsin_parser.o rsin_parser.lex.o formrsctlk.o all: main diff --git a/formrsctl.cc b/formrsctlk.cc similarity index 77% rename from formrsctl.cc rename to formrsctlk.cc index f85693a..5870709 100644 --- a/formrsctl.cc +++ b/formrsctlk.cc @@ -6,7 +6,7 @@ without the author's permission is strictly prohibited. */ -#include "formrsctl.hh" +#include "formrsctlk.hh" std::string BoolContexts::toStr(void) const @@ -73,12 +73,12 @@ BDD BoolContexts::getBDD(const SymRS *srs) const } } -std::string FormRSCTL::toStr(void) const +std::string FormRSCTLK::toStr(void) const { - if (oper == RSCTL_PV) { + if (oper == RSCTLK_PV) { return proc_name + "." + entity_name; } - else if (oper == RSCTL_TF) { + else if (oper == RSCTLK_TF) { if (tf) { return "true"; } @@ -86,69 +86,69 @@ std::string FormRSCTL::toStr(void) const return "false"; } } - else if (oper == RSCTL_AND) { + else if (oper == RSCTLK_AND) { return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_OR) { + else if (oper == RSCTLK_OR) { return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_XOR) { + else if (oper == RSCTLK_XOR) { return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_IMPL) { + else if (oper == RSCTLK_IMPL) { return "(" + arg[0]->toStr() + " IMPLIES " + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_NOT) { + else if (oper == RSCTLK_NOT) { return "~" + arg[0]->toStr(); } - else if (oper == RSCTL_EX) { + else if (oper == RSCTLK_EX) { return "EX(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_EG) { + else if (oper == RSCTLK_EG) { return "EG(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_EU) { + else if (oper == RSCTLK_EU) { return "EU(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_EF) { + else if (oper == RSCTLK_EF) { return "EF(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_AX) { + else if (oper == RSCTLK_AX) { return "AX(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_AG) { + else if (oper == RSCTLK_AG) { return "AG(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_AU) { + else if (oper == RSCTLK_AU) { return "AU(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_AF) { + else if (oper == RSCTLK_AF) { return "AF(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_EX_ACT) { + else if (oper == RSCTLK_EX_ACT) { return "E" + getActionsStr() + "X(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_EG_ACT) { + else if (oper == RSCTLK_EG_ACT) { return "E" + getActionsStr() + "G(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_EU_ACT) { + else if (oper == RSCTLK_EU_ACT) { return "E" + getActionsStr() + "U(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_EF_ACT) { + else if (oper == RSCTLK_EF_ACT) { return "E" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_AX_ACT) { + else if (oper == RSCTLK_AX_ACT) { return "A" + getActionsStr() + "X(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_AG_ACT) { + else if (oper == RSCTLK_AG_ACT) { return "A" + getActionsStr() + "G(" + arg[0]->toStr() + ")"; } - else if (oper == RSCTL_AU_ACT) { + else if (oper == RSCTLK_AU_ACT) { return "A" + getActionsStr() + "U(" + arg[0]->toStr() + "," + arg[1]->toStr() + ")"; } - else if (oper == RSCTL_AF_ACT) { + else if (oper == RSCTLK_AF_ACT) { return "A" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; } @@ -158,7 +158,7 @@ std::string FormRSCTL::toStr(void) const } } -bool FormRSCTL::hasOper(Oper op) const +bool FormRSCTLK::hasOper(Oper op) const { if (oper == op) { return true; @@ -178,28 +178,28 @@ bool FormRSCTL::hasOper(Oper op) const } } -void FormRSCTL::encodeEntities(const SymRS *srs) +void FormRSCTLK::encodeEntities(const SymRS *srs) { - if (RSCTL_COND_1ARG(oper)) { + if (RSCTLK_COND_1ARG(oper)) { arg[0]->encodeEntities(srs); } - else if (RSCTL_COND_2ARG(oper)) { + else if (RSCTLK_COND_2ARG(oper)) { arg[0]->encodeEntities(srs); arg[1]->encodeEntities(srs); } - else if (oper == RSCTL_PV) { + else if (oper == RSCTLK_PV) { bdd = new BDD(srs->encEntity(proc_name, entity_name)); } } -bool FormRSCTL::isERSCTL(void) const +bool FormRSCTLK::isERSCTLK(void) const { - if (oper == RSCTL_PV) { + if (oper == RSCTLK_PV) { return true; } - if (oper == RSCTL_NOT) { - if (arg[0]->getOper() == RSCTL_PV || arg[0]->getOper() == RSCTL_TF) { + if (oper == RSCTLK_NOT) { + if (arg[0]->getOper() == RSCTLK_PV || arg[0]->getOper() == RSCTLK_TF) { return true; } else { @@ -207,16 +207,16 @@ bool FormRSCTL::isERSCTL(void) const } } - if (RSCTL_COND_IS_UNIVERSAL(oper)) { + if (RSCTLK_COND_IS_UNIVERSAL(oper)) { return false; } - if (RSCTL_COND_1ARG(oper)) { - return arg[0]->isERSCTL(); + if (RSCTLK_COND_1ARG(oper)) { + return arg[0]->isERSCTLK(); } - if (RSCTL_COND_2ARG(oper)) { - return arg[0]->isERSCTL() && arg[1]->isERSCTL(); + if (RSCTLK_COND_2ARG(oper)) { + return arg[0]->isERSCTLK() && arg[1]->isERSCTLK(); } assert(0); @@ -224,7 +224,7 @@ bool FormRSCTL::isERSCTL(void) const return false; } -std::string FormRSCTL::getActionsStr(void) const +std::string FormRSCTLK::getActionsStr(void) const { // if (actions != nullptr) { // std::string r = "[ "; @@ -267,9 +267,9 @@ std::string FormRSCTL::getActionsStr(void) const } } -void FormRSCTL::encodeActions(const SymRS *srs) +void FormRSCTLK::encodeActions(const SymRS *srs) { - if (RSCTL_COND_ACT(oper)) { + if (RSCTLK_COND_ACT(oper)) { if (actions_bdd != nullptr) { forgetActionsBDD(); } @@ -300,11 +300,11 @@ void FormRSCTL::encodeActions(const SymRS *srs) } } - if (RSCTL_COND_1ARG(oper)) { + if (RSCTLK_COND_1ARG(oper)) { arg[0]->encodeActions(srs); } - if (RSCTL_COND_2ARG(oper)) { + if (RSCTLK_COND_2ARG(oper)) { arg[0]->encodeActions(srs); arg[1]->encodeActions(srs); } diff --git a/formrsctl.hh b/formrsctlk.hh similarity index 67% rename from formrsctl.hh rename to formrsctlk.hh index 58b2feb..008e5a1 100644 --- a/formrsctl.hh +++ b/formrsctlk.hh @@ -6,8 +6,8 @@ without the author's permission is strictly prohibited. */ -#ifndef RS_FORMRSCTL_HH -#define RS_FORMRSCTL_HH +#ifndef RS_FORMRSCTLK_HH +#define RS_FORMRSCTLK_HH #include #include @@ -16,32 +16,32 @@ #include "symrs.hh" #include "cudd.hh" -#define RSCTL_PV 0 // propositional variable -#define RSCTL_AND 1 -#define RSCTL_OR 2 -#define RSCTL_XOR 3 -#define RSCTL_NOT 4 -#define RSCTL_IMPL 5 -#define RSCTL_EG 11 // Existential... -#define RSCTL_EU 12 -#define RSCTL_EX 13 -#define RSCTL_EF 14 -#define RSCTL_AG 21 // Universal... -#define RSCTL_AU 22 -#define RSCTL_AX 23 -#define RSCTL_AF 24 -#define RSCTL_EG_ACT 31 // Existential... -#define RSCTL_EU_ACT 32 -#define RSCTL_EX_ACT 33 -#define RSCTL_EF_ACT 34 -#define RSCTL_AG_ACT 41 // Universal... -#define RSCTL_AU_ACT 42 -#define RSCTL_AX_ACT 43 -#define RSCTL_AF_ACT 44 -#define RSCTL_TF 50 // true/false +#define RSCTLK_PV 0 // propositional variable +#define RSCTLK_AND 1 +#define RSCTLK_OR 2 +#define RSCTLK_XOR 3 +#define RSCTLK_NOT 4 +#define RSCTLK_IMPL 5 +#define RSCTLK_EG 11 // Existential... +#define RSCTLK_EU 12 +#define RSCTLK_EX 13 +#define RSCTLK_EF 14 +#define RSCTLK_AG 21 // Universal... +#define RSCTLK_AU 22 +#define RSCTLK_AX 23 +#define RSCTLK_AF 24 +#define RSCTLK_EG_ACT 31 // Existential... +#define RSCTLK_EU_ACT 32 +#define RSCTLK_EX_ACT 33 +#define RSCTLK_EF_ACT 34 +#define RSCTLK_AG_ACT 41 // Universal... +#define RSCTLK_AU_ACT 42 +#define RSCTLK_AX_ACT 43 +#define RSCTLK_AF_ACT 44 +#define RSCTLK_TF 50 // true/false -#define RSCTL_UK 60 // Epistemic operators -#define RSCTL_NK 61 +#define RSCTLK_UK 60 // Epistemic operators +#define RSCTLK_NK 61 /* For Boolean contexts: */ #define BCTX_PV 80 @@ -52,12 +52,12 @@ #define BCTX_TF 90 -#define RSCTL_COND_1ARG(a) ((a) == RSCTL_NOT || (a) == RSCTL_EG || (a) == RSCTL_EF || (a) == RSCTL_EX || (a) == RSCTL_AG || (a) == RSCTL_AF || (a) == RSCTL_AX || (a) == RSCTL_EG_ACT || (a) == RSCTL_EF_ACT || (a) == RSCTL_EX_ACT || (a) == RSCTL_AG_ACT || (a) == RSCTL_AF_ACT || (a) == RSCTL_AX_ACT || (a) == RSCTL_UK || (a) == RSCTL_NK) -#define RSCTL_COND_2ARG(a) ((a) == RSCTL_AND || (a) == RSCTL_OR || (a) == RSCTL_XOR || (a) == RSCTL_IMPL || (a) == RSCTL_EU || (a) == RSCTL_AU || (a) == RSCTL_EU_ACT || (a) == RSCTL_AU_ACT) -#define RSCTL_COND_ACT(a) ((a) > 30 && (a) < 45) -#define RSCTL_IS_VALID(a) (RSCTL_COND_1ARG(a) || RSCTL_COND_2ARG(a) || (a) == RSCTL_PV || (a) == RSCTL_TF) +#define RSCTLK_COND_1ARG(a) ((a) == RSCTLK_NOT || (a) == RSCTLK_EG || (a) == RSCTLK_EF || (a) == RSCTLK_EX || (a) == RSCTLK_AG || (a) == RSCTLK_AF || (a) == RSCTLK_AX || (a) == RSCTLK_EG_ACT || (a) == RSCTLK_EF_ACT || (a) == RSCTLK_EX_ACT || (a) == RSCTLK_AG_ACT || (a) == RSCTLK_AF_ACT || (a) == RSCTLK_AX_ACT || (a) == RSCTLK_UK || (a) == RSCTLK_NK) +#define RSCTLK_COND_2ARG(a) ((a) == RSCTLK_AND || (a) == RSCTLK_OR || (a) == RSCTLK_XOR || (a) == RSCTLK_IMPL || (a) == RSCTLK_EU || (a) == RSCTLK_AU || (a) == RSCTLK_EU_ACT || (a) == RSCTLK_AU_ACT) +#define RSCTLK_COND_ACT(a) ((a) > 30 && (a) < 45) +#define RSCTLK_IS_VALID(a) (RSCTLK_COND_1ARG(a) || RSCTLK_COND_2ARG(a) || (a) == RSCTLK_PV || (a) == RSCTLK_TF) -#define RSCTL_COND_IS_UNIVERSAL(a) (((a) > 20 && (a) < 25) || ((a) > 40 && (a) < 45)) +#define RSCTLK_COND_IS_UNIVERSAL(a) (((a) > 20 && (a) < 25) || ((a) > 40 && (a) < 45)) #define BCTX_COND_1ARG(a) ((a) == BCTX_NOT) #define BCTX_COND_2ARG(a) ((a) == BCTX_AND || (a) == BCTX_OR || (a) == BCTX_XOR) @@ -155,10 +155,10 @@ class BoolContexts } }; -class FormRSCTL +class FormRSCTLK { Oper oper; - FormRSCTL *arg[2]; + FormRSCTLK *arg[2]; std::string entity_name; std::string proc_name; bool tf; @@ -174,9 +174,9 @@ class FormRSCTL * @param varName variable name used mostly for printing the variable. * @param varBDD the BDD describing the set where the variable holds. */ - FormRSCTL(std::string procName, std::string varName) + FormRSCTLK(std::string procName, std::string varName) { - oper = RSCTL_PV; + oper = RSCTLK_PV; proc_name = procName; entity_name = varName; arg[0] = nullptr; @@ -192,9 +192,9 @@ class FormRSCTL * * @param val value of the logical constant */ - FormRSCTL(bool val) + FormRSCTLK(bool val) { - oper = RSCTL_TF; + oper = RSCTLK_TF; tf = val; arg[0] = nullptr; arg[1] = nullptr; @@ -207,10 +207,10 @@ class FormRSCTL /** * @brief Constructor for two-argument formula. */ - FormRSCTL(Oper op, FormRSCTL *form1, FormRSCTL *form2) + FormRSCTLK(Oper op, FormRSCTLK *form1, FormRSCTLK *form2) { - assert(RSCTL_COND_2ARG(op)); - assert(!RSCTL_COND_ACT(op)); + assert(RSCTLK_COND_2ARG(op)); + assert(!RSCTLK_COND_ACT(op)); oper = op; arg[0] = form1; arg[1] = form2; @@ -223,11 +223,11 @@ class FormRSCTL /** * @brief Constructor for two-argument formula with action restrictions. */ - // FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1, FormRSCTL *form2) + // FormRSCTLK(Oper op, ActionsVec_f *acts, FormRSCTLK *form1, FormRSCTLK *form2) // { // assert(acts != nullptr); - // assert(RSCTL_COND_2ARG(op)); - // assert(RSCTL_COND_ACT(op)); + // assert(RSCTLK_COND_2ARG(op)); + // assert(RSCTLK_COND_ACT(op)); // oper = op; // arg[0] = form1; // arg[1] = form2; @@ -240,11 +240,11 @@ class FormRSCTL /** * @brief Constructor for two-argument formula with Boolean context restrictions. */ - FormRSCTL(Oper op, BoolContexts *bctx, FormRSCTL *form1, FormRSCTL *form2) + FormRSCTLK(Oper op, BoolContexts *bctx, FormRSCTLK *form1, FormRSCTLK *form2) { assert(bctx != nullptr); - assert(RSCTL_COND_2ARG(op)); - assert(RSCTL_COND_ACT(op)); + assert(RSCTLK_COND_2ARG(op)); + assert(RSCTLK_COND_ACT(op)); oper = op; arg[0] = form1; arg[1] = form2; @@ -257,10 +257,10 @@ class FormRSCTL /** * @brief Constructor for one-argument formula. */ - FormRSCTL(Oper op, FormRSCTL *form1) + FormRSCTLK(Oper op, FormRSCTLK *form1) { - assert(RSCTL_COND_1ARG(op)); - assert(!RSCTL_COND_ACT(op)); + assert(RSCTLK_COND_1ARG(op)); + assert(!RSCTLK_COND_ACT(op)); oper = op; arg[0] = form1; arg[1] = nullptr; @@ -273,11 +273,11 @@ class FormRSCTL /** * @brief Constructor for one-argument formula with action restrictions. */ - // FormRSCTL(Oper op, ActionsVec_f *acts, FormRSCTL *form1) + // FormRSCTLK(Oper op, ActionsVec_f *acts, FormRSCTLK *form1) // { // assert(acts != nullptr); - // assert(RSCTL_COND_1ARG(op)); - // assert(RSCTL_COND_ACT(op)); + // assert(RSCTLK_COND_1ARG(op)); + // assert(RSCTLK_COND_ACT(op)); // oper = op; // arg[0] = form1; // arg[1] = nullptr; @@ -290,11 +290,11 @@ class FormRSCTL /** * @brief Constructor for one-argument formula with Boolean context restrictions. */ - FormRSCTL(Oper op, BoolContexts *bctx, FormRSCTL *form1) + FormRSCTLK(Oper op, BoolContexts *bctx, FormRSCTLK *form1) { assert(bctx != nullptr); - assert(RSCTL_COND_1ARG(op)); - assert(RSCTL_COND_ACT(op)); + assert(RSCTLK_COND_1ARG(op)); + assert(RSCTLK_COND_ACT(op)); oper = op; arg[0] = form1; arg[1] = nullptr; @@ -304,9 +304,9 @@ class FormRSCTL boolCtx = bctx; } - FormRSCTL(Oper op, Agents_f agents_set, FormRSCTL *form1) + FormRSCTLK(Oper op, Agents_f agents_set, FormRSCTLK *form1) { - assert(RSCTL_COND_1ARG(op)); + assert(RSCTLK_COND_1ARG(op)); oper = op; arg[0] = form1; arg[1] = nullptr; @@ -318,7 +318,7 @@ class FormRSCTL /** * @brief Destructor. */ - ~FormRSCTL() + ~FormRSCTLK() { delete arg[0]; delete arg[1]; @@ -331,36 +331,36 @@ class FormRSCTL bool hasOper(Oper op) const; const BDD *getBDD(void) const { - assert(oper == RSCTL_PV); + assert(oper == RSCTLK_PV); assert(bdd != nullptr); return bdd; } const BDD *getActionsBDD(void) const { - assert(RSCTL_COND_ACT(oper)); + assert(RSCTLK_COND_ACT(oper)); assert(actions_bdd != nullptr); return actions_bdd; } Oper getOper(void) const { - assert(RSCTL_IS_VALID(oper)); + assert(RSCTLK_IS_VALID(oper)); return oper; } - FormRSCTL *getLeftSF(void) const + FormRSCTLK *getLeftSF(void) const { assert(arg[0] != nullptr); return arg[0]; } - FormRSCTL *getRightSF(void) const + FormRSCTLK *getRightSF(void) const { - assert(RSCTL_COND_2ARG(oper)); + assert(RSCTLK_COND_2ARG(oper)); assert(arg[1] != nullptr); return arg[1]; } std::string getActionsStr(void) const; bool getTF(void) const { - assert(oper == RSCTL_TF); + assert(oper == RSCTLK_TF); return tf; } void encodeEntities(const SymRS *srs); @@ -371,7 +371,7 @@ class FormRSCTL delete actions_bdd; } } - bool isERSCTL(void) const; + bool isERSCTLK(void) const; }; #endif diff --git a/main.cc b/main.cc index bba2658..85d3f71 100644 --- a/main.cc +++ b/main.cc @@ -182,10 +182,10 @@ int main(int argc, char **argv) if (rstl_model_checking) { if (bmc) { cout << "Using BDD-based Bounded Model Checking" << endl; - mc.checkRSCTL(driver.getFormRSCTL()); + mc.checkRSCTLK(driver.getFormRSCTLK()); } else { - mc.checkRSCTLfull(driver.getFormRSCTL()); + mc.checkRSCTLKfull(driver.getFormRSCTLK()); } } } @@ -233,7 +233,7 @@ void print_help(std::string path_str) #endif << " Usage: " << path_str << " [options] " << endl << endl << " TASKS:" << endl - << " -c -- perform RSCTL model checking" << endl + << " -c -- perform RSCTLK model checking" << endl //<< " -f K -- generate SMT input for the depth K" << endl << " -P -- print parsed system" << endl << " -r -- print reactions" << endl diff --git a/mc.cc b/mc.cc index d6da428..0ad65f6 100644 --- a/mc.cc +++ b/mc.cc @@ -233,15 +233,15 @@ bool ModelChecker::checkReach(const Entities testState) return false; } -BDD ModelChecker::getStatesRSCTL(const FormRSCTL *form) +BDD ModelChecker::getStatesRSCTLK(const FormRSCTLK *form) { assert(reach != nullptr); Oper oper = form->getOper(); - if (oper == RSCTL_PV) { + if (oper == RSCTLK_PV) { return *form->getBDD() * *reach; } - else if (oper == RSCTL_TF) { + else if (oper == RSCTLK_TF) { if (form->getTF() == true) { return *reach; } @@ -249,47 +249,47 @@ BDD ModelChecker::getStatesRSCTL(const FormRSCTL *form) return cuddMgr->bddZero(); } } - else if (oper == RSCTL_AND) { - return getStatesRSCTL(form->getLeftSF()) * getStatesRSCTL(form->getRightSF()); + else if (oper == RSCTLK_AND) { + return getStatesRSCTLK(form->getLeftSF()) * getStatesRSCTLK(form->getRightSF()); } - else if (oper == RSCTL_OR) { - return getStatesRSCTL(form->getLeftSF()) + getStatesRSCTL(form->getRightSF()); + else if (oper == RSCTLK_OR) { + return getStatesRSCTLK(form->getLeftSF()) + getStatesRSCTLK(form->getRightSF()); } - else if (oper == RSCTL_XOR) { - return getStatesRSCTL(form->getLeftSF()) ^ getStatesRSCTL(form->getRightSF()); + else if (oper == RSCTLK_XOR) { + return getStatesRSCTLK(form->getLeftSF()) ^ getStatesRSCTLK(form->getRightSF()); } - else if (oper == RSCTL_IMPL) { - return (!getStatesRSCTL(form->getLeftSF()) * *reach) + getStatesRSCTL( + else if (oper == RSCTLK_IMPL) { + return (!getStatesRSCTLK(form->getLeftSF()) * *reach) + getStatesRSCTLK( form->getRightSF()); } - else if (oper == RSCTL_NOT) { - return !getStatesRSCTL(form->getLeftSF()) * *reach; + else if (oper == RSCTLK_NOT) { + return !getStatesRSCTLK(form->getLeftSF()) * *reach; } - else if (oper == RSCTL_EX) { - return getPreE(getStatesRSCTL(form->getLeftSF())) * *reach; + else if (oper == RSCTLK_EX) { + return getPreE(getStatesRSCTLK(form->getLeftSF())) * *reach; } - else if (oper == RSCTL_EG) { - return statesEG(getStatesRSCTL(form->getLeftSF())); + else if (oper == RSCTLK_EG) { + return statesEG(getStatesRSCTLK(form->getLeftSF())); } - else if (oper == RSCTL_EU) { + else if (oper == RSCTLK_EU) { return statesEU( - getStatesRSCTL(form->getLeftSF()), - getStatesRSCTL(form->getRightSF()) + getStatesRSCTLK(form->getLeftSF()), + getStatesRSCTLK(form->getRightSF()) ); } - else if (oper == RSCTL_EF) { - return statesEF(getStatesRSCTL(form->getLeftSF())); + else if (oper == RSCTLK_EF) { + return statesEF(getStatesRSCTLK(form->getLeftSF())); } - else if (oper == RSCTL_AX) { - return !getPreE(!getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + else if (oper == RSCTLK_AX) { + return !getPreE(!getStatesRSCTLK(form->getLeftSF()) * *reach) * *reach; } - else if (oper == RSCTL_AG) { + else if (oper == RSCTLK_AG) { return !statesEF( - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + !getStatesRSCTLK(form->getLeftSF()) * *reach) * *reach; } - else if (oper == RSCTL_AU) { - BDD ng = !getStatesRSCTL(form->getRightSF()) * *reach; - BDD nf = !getStatesRSCTL(form->getLeftSF()) * *reach; + else if (oper == RSCTLK_AU) { + BDD ng = !getStatesRSCTLK(form->getRightSF()) * *reach; + BDD nf = !getStatesRSCTLK(form->getLeftSF()) * *reach; BDD x = !statesEU(ng, ng * nf) * *reach; @@ -299,40 +299,40 @@ BDD ModelChecker::getStatesRSCTL(const FormRSCTL *form) return x; } - else if (oper == RSCTL_AF) { + else if (oper == RSCTLK_AF) { return !statesEG( - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + !getStatesRSCTLK(form->getLeftSF()) * *reach) * *reach; } /***** CONTEXT RESTRICTIONS: ******/ - else if (oper == RSCTL_EX_ACT) { - return getPreEctx(getStatesRSCTL(form->getLeftSF()), + else if (oper == RSCTLK_EX_ACT) { + return getPreEctx(getStatesRSCTLK(form->getLeftSF()), form->getActionsBDD()) * *reach; } - else if (oper == RSCTL_EG_ACT) { + else if (oper == RSCTLK_EG_ACT) { return statesEGctx(form->getActionsBDD(), - getStatesRSCTL(form->getLeftSF())); /***** EG? *****/ + getStatesRSCTLK(form->getLeftSF())); /***** EG? *****/ } - else if (oper == RSCTL_EU_ACT) { + else if (oper == RSCTLK_EU_ACT) { return statesEUctx( form->getActionsBDD(), - getStatesRSCTL(form->getLeftSF()), - getStatesRSCTL(form->getRightSF()) + getStatesRSCTLK(form->getLeftSF()), + getStatesRSCTLK(form->getRightSF()) ); } - else if (oper == RSCTL_EF_ACT) { - return statesEFctx(form->getActionsBDD(), getStatesRSCTL(form->getLeftSF())); + else if (oper == RSCTLK_EF_ACT) { + return statesEFctx(form->getActionsBDD(), getStatesRSCTLK(form->getLeftSF())); } - else if (oper == RSCTL_AX_ACT) { - return !getPreEctx(!getStatesRSCTL(form->getLeftSF()) * *reach, + else if (oper == RSCTLK_AX_ACT) { + return !getPreEctx(!getStatesRSCTLK(form->getLeftSF()) * *reach, form->getActionsBDD()) * *reach; } - else if (oper == RSCTL_AG_ACT) { + else if (oper == RSCTLK_AG_ACT) { return !statesEFctx(form->getActionsBDD(), - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + !getStatesRSCTLK(form->getLeftSF()) * *reach) * *reach; } - else if (oper == RSCTL_AU_ACT) { - BDD ng = !getStatesRSCTL(form->getRightSF()) * *reach; - BDD nf = !getStatesRSCTL(form->getLeftSF()) * *reach; + else if (oper == RSCTLK_AU_ACT) { + BDD ng = !getStatesRSCTLK(form->getRightSF()) * *reach; + BDD nf = !getStatesRSCTLK(form->getLeftSF()) * *reach; BDD x = !statesEUctx(form->getActionsBDD(), ng, ng * nf) * *reach; @@ -342,9 +342,9 @@ BDD ModelChecker::getStatesRSCTL(const FormRSCTL *form) return x; } - else if (oper == RSCTL_AF_ACT) { + else if (oper == RSCTLK_AF_ACT) { return !statesEGctx(form->getActionsBDD(), - !getStatesRSCTL(form->getLeftSF()) * *reach) * *reach; + !getStatesRSCTLK(form->getLeftSF()) * *reach) * *reach; } assert(0); // Should never happen @@ -454,17 +454,17 @@ BDD ModelChecker::getIthOnly(Process proc_id) return bdd; } -bool ModelChecker::checkRSCTL(FormRSCTL *form) +bool ModelChecker::checkRSCTLK(FormRSCTLK *form) { - if (form->isERSCTL()) { - return checkRSCTLbmc(form); + if (form->isERSCTLK()) { + return checkRSCTLKbmc(form); } else { - return checkRSCTLfull(form); + return checkRSCTLKfull(form); } } -bool ModelChecker::checkRSCTLfull(FormRSCTL *form) +bool ModelChecker::checkRSCTLKfull(FormRSCTLK *form) { if (opts->measure) { opts->ver_time = cpuTime(); @@ -474,7 +474,7 @@ bool ModelChecker::checkRSCTLfull(FormRSCTL *form) bool result = false; - VERB("Model checking for RSCTL formula: " << form->toStr()); + VERB("Model checking for RSCTLK formula: " << form->toStr()); VERB("Processing the formula: encoding entities"); form->encodeEntities(srs); @@ -514,8 +514,8 @@ bool ModelChecker::checkRSCTLfull(FormRSCTL *form) VERB("Checking the formula"); - //if (*initStates * getStatesRSCTL(form) != cuddMgr->bddZero()) - if (*initStates * getStatesRSCTL(form) == *initStates) { + //if (*initStates * getStatesRSCTLK(form) != cuddMgr->bddZero()) + if (*initStates * getStatesRSCTLK(form) == *initStates) { result = true; } else { @@ -535,7 +535,7 @@ bool ModelChecker::checkRSCTLfull(FormRSCTL *form) return result; } -bool ModelChecker::checkRSCTLbmc(FormRSCTL *form) +bool ModelChecker::checkRSCTLKbmc(FormRSCTLK *form) { if (opts->measure) { opts->ver_time = cpuTime(); @@ -543,14 +543,14 @@ bool ModelChecker::checkRSCTLbmc(FormRSCTL *form) assert(form != nullptr); - if (!form->isERSCTL()) { + if (!form->isERSCTLK()) { FERROR("Formula " << form->toStr() << - " is not syntactically an ERSCTL formula"); + " is not syntactically an ERSCTLK formula"); } bool result = false; - VERB("Bounded model checking for RSCTL formula: " << form->toStr()); + VERB("Bounded model checking for RSCTLK formula: " << form->toStr()); VERB("Processing the formula: encoding entities"); form->encodeEntities(srs); @@ -572,8 +572,8 @@ bool ModelChecker::checkRSCTLbmc(FormRSCTL *form) cout << "\rIteration " << ++k << flush; } - //if (*initStates * getStatesRSCTL(form) != cuddMgr->bddZero()) - if (*initStates * getStatesRSCTL(form) == *initStates) { + //if (*initStates * getStatesRSCTLK(form) != cuddMgr->bddZero()) + if (*initStates * getStatesRSCTLK(form) == *initStates) { result = true; break; } @@ -605,4 +605,4 @@ void ModelChecker::cleanup(void) reach = nullptr; } -/** EOF **/ \ No newline at end of file +/** EOF **/ diff --git a/mc.hh b/mc.hh index 12497d9..9685c47 100644 --- a/mc.hh +++ b/mc.hh @@ -4,7 +4,7 @@ #include "cudd.hh" #include "rs.hh" #include "symrs.hh" -#include "formrsctl.hh" +#include "formrsctlk.hh" #include "macro.hh" #include "bdd_macro.hh" #include "options.hh" @@ -53,7 +53,7 @@ class ModelChecker BDD getSucc(const BDD &states); BDD getPreE(const BDD &states); BDD getPreEctx(const BDD &states, const BDD *contexts); - BDD getStatesRSCTL(const FormRSCTL *form); + BDD getStatesRSCTLK(const FormRSCTLK *form); BDD statesEG(const BDD &states); BDD statesEU(const BDD &statesA, const BDD &statesB); BDD statesEF(const BDD &states); @@ -71,9 +71,9 @@ class ModelChecker void printReach(void); void printReachWithSucc(void); bool checkReach(const Entities testState); - bool checkRSCTL(FormRSCTL *form); - bool checkRSCTLfull(FormRSCTL *form); - bool checkRSCTLbmc(FormRSCTL *form); + bool checkRSCTLK(FormRSCTLK *form); + bool checkRSCTLKfull(FormRSCTLK *form); + bool checkRSCTLKbmc(FormRSCTLK *form); }; #endif diff --git a/rs.hh b/rs.hh index 39a89cb..1ac89b2 100644 --- a/rs.hh +++ b/rs.hh @@ -137,4 +137,4 @@ class RctSys #endif -/** EOF **/ \ No newline at end of file +/** EOF **/ diff --git a/rsin_driver.cc b/rsin_driver.cc index ddc5352..5e6ccf5 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -17,7 +17,7 @@ rsin_driver::rsin_driver(RctSys *rs) void rsin_driver::initialise(void) { rs = nullptr; - rsctlform = nullptr; + rsctlkform = nullptr; opts = nullptr; use_ctx_aut = false; use_concentrations = false; @@ -49,13 +49,13 @@ void rsin_driver::error(const std::string &m) std::cerr << m << std::endl; } -FormRSCTL *rsin_driver::getFormRSCTL(void) +FormRSCTLK *rsin_driver::getFormRSCTLK(void) { - if (rsctlform == nullptr) { - FERROR("RSCTL formula was not supplied!"); + if (rsctlkform == nullptr) { + FERROR("RSCTLK formula was not supplied!"); } - return rsctlform; + return rsctlkform; } // diff --git a/rsin_driver.hh b/rsin_driver.hh index 04a8aa2..5570960 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -4,7 +4,7 @@ #include #include "rsin_parser.hh" #include "rs.hh" -#include "formrsctl.hh" +#include "formrsctlk.hh" #include "options.hh" // Tell Flex the lexer's prototype ... @@ -25,7 +25,7 @@ class rsin_driver virtual ~rsin_driver(); //std::map variables; - FormRSCTL *rsctlform; + FormRSCTLK *rsctlkform; Options *opts; // options in configuration file: @@ -45,11 +45,11 @@ class rsin_driver { this->opts = opts; }; - void addFormRSCTL(FormRSCTL *f) + void addFormRSCTLK(FormRSCTLK *f) { - rsctlform = f; + rsctlkform = f; }; - FormRSCTL *getFormRSCTL(void); + FormRSCTLK *getFormRSCTLK(void); void ensureOptionsAllowed(void); void useContextAutomaton(void); diff --git a/rsin_parser.ll b/rsin_parser.ll index 1abe2fc..a946223 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -48,7 +48,7 @@ blank [ \t] "transitions" return token::TRANSITIONS; "states" return token::STATES; "init-state" return token::INITSTATE; -"rsctl-property" return token::RSCTLFORM; +"rsctlk-property" return token::RSCTLKFORM; "{" return token::LCB; "}" return token::RCB; "(" return token::LRB; diff --git a/rsin_parser.yy b/rsin_parser.yy index f308f65..827eda5 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -6,7 +6,7 @@ %code requires { #include #include -#include "formrsctl.hh" +#include "formrsctlk.hh" using std::set; using std::string; @@ -33,7 +33,7 @@ class rsin_driver; { int ival; std::string *sval; - FormRSCTL *frsctl; + FormRSCTLK *frsctlk; // Entity_f *ent; // Action_f *act; // ActionsVec_f *actionsVec; @@ -45,7 +45,7 @@ class rsin_driver; } %token OPTIONS USE_CTX_AUT USE_CONCENTRATIONS -%token REACTIONS INITIALCONTEXTS CONTEXTENTITIES RSCTLFORM +%token REACTIONS INITIALCONTEXTS CONTEXTENTITIES RSCTLKFORM %token CONTEXTAUTOMATON STATES INITSTATE TRANSITIONS %token EQ LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL DOT COMMA RARR %token AND OR XOR IMPLIES NOT @@ -60,7 +60,7 @@ class rsin_driver; //%right SRB -%type rsctl_form +%type rsctlk_form // %type f_entity // %type action // %type actions @@ -81,8 +81,8 @@ system: | INITIALCONTEXTS LCB initstates RCB system | CONTEXTENTITIES LCB actionentities RCB system | CONTEXTAUTOMATON LCB ctxaut RCB system - | RSCTLFORM LCB rsctl_form RCB system { - driver.addFormRSCTL($3); + | RSCTLKFORM LCB rsctlk_form RCB system { + driver.addFormRSCTLK($3); } ; @@ -316,110 +316,110 @@ bool_contexts: IDENTIFIER DOT IDENTIFIER { // } // ; -rsctl_form: +rsctlk_form: IDENTIFIER DOT IDENTIFIER { - $$ = new FormRSCTL(*$1, *$3); + $$ = new FormRSCTLK(*$1, *$3); free($1); free($3); } - | NOT rsctl_form { - $$ = new FormRSCTL(RSCTL_NOT, $2); + | NOT rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_NOT, $2); } - | LRB rsctl_form RRB { + | LRB rsctlk_form RRB { $$ = $2; } - | rsctl_form AND rsctl_form { - $$ = new FormRSCTL(RSCTL_AND, $1, $3); + | rsctlk_form AND rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AND, $1, $3); } - | rsctl_form OR rsctl_form { - $$ = new FormRSCTL(RSCTL_OR, $1, $3); + | rsctlk_form OR rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_OR, $1, $3); } - | rsctl_form XOR rsctl_form { - $$ = new FormRSCTL(RSCTL_XOR, $1, $3); + | rsctlk_form XOR rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_XOR, $1, $3); } - | rsctl_form IMPLIES rsctl_form { - $$ = new FormRSCTL(RSCTL_IMPL, $1, $3); + | rsctlk_form IMPLIES rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_IMPL, $1, $3); } - | EX rsctl_form { - $$ = new FormRSCTL(RSCTL_EX, $2); + | EX rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_EX, $2); } - | EU LRB rsctl_form COMMA rsctl_form RRB { - $$ = new FormRSCTL(RSCTL_EU, $3, $5); + | EU LRB rsctlk_form COMMA rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_EU, $3, $5); } - | EF rsctl_form { - $$ = new FormRSCTL(RSCTL_EF, $2); + | EF rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_EF, $2); } - | EG rsctl_form { - $$ = new FormRSCTL(RSCTL_EG, $2); + | EG rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_EG, $2); } - | AX rsctl_form { - $$ = new FormRSCTL(RSCTL_AX, $2); + | AX rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AX, $2); } - | AU LRB rsctl_form COMMA rsctl_form RRB { - $$ = new FormRSCTL(RSCTL_AU, $3, $5); + | AU LRB rsctlk_form COMMA rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_AU, $3, $5); } - | AF rsctl_form { - $$ = new FormRSCTL(RSCTL_AF, $2); + | AF rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AF, $2); } - | AG rsctl_form { - $$ = new FormRSCTL(RSCTL_AG, $2); + | AG rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AG, $2); } - | UK LSB IDENTIFIER RSB LRB rsctl_form RRB { + | UK LSB IDENTIFIER RSB LRB rsctlk_form RRB { Agents_f agents; agents.insert(*$3); - $$ = new FormRSCTL(RSCTL_UK, agents, $6); + $$ = new FormRSCTLK(RSCTLK_UK, agents, $6); free($3); } - // | E LSB actions RSB X rsctl_form { - // $$ = new FormRSCTL(RSCTL_EX_ACT, $3, $6); + // | E LSB actions RSB X rsctlk_form { + // $$ = new FormRSCTLK(RSCTLK_EX_ACT, $3, $6); // } - // | E LSB actions RSB U LRB rsctl_form COMMA rsctl_form RRB { - // $$ = new FormRSCTL(RSCTL_EU_ACT, $3, $7, $9); + // | E LSB actions RSB U LRB rsctlk_form COMMA rsctlk_form RRB { + // $$ = new FormRSCTLK(RSCTLK_EU_ACT, $3, $7, $9); // } - // | E LSB actions RSB F rsctl_form { - // $$ = new FormRSCTL(RSCTL_EF_ACT, $3, $6); + // | E LSB actions RSB F rsctlk_form { + // $$ = new FormRSCTLK(RSCTLK_EF_ACT, $3, $6); // } - // | E LSB actions RSB G rsctl_form { - // $$ = new FormRSCTL(RSCTL_EG_ACT, $3, $6); + // | E LSB actions RSB G rsctlk_form { + // $$ = new FormRSCTLK(RSCTLK_EG_ACT, $3, $6); // } - // | A LSB actions RSB X rsctl_form { - // $$ = new FormRSCTL(RSCTL_AX_ACT, $3, $6); + // | A LSB actions RSB X rsctlk_form { + // $$ = new FormRSCTLK(RSCTLK_AX_ACT, $3, $6); // } - // | A LSB actions RSB U LRB rsctl_form COMMA rsctl_form RRB { - // $$ = new FormRSCTL(RSCTL_AU_ACT, $3, $7, $9); + // | A LSB actions RSB U LRB rsctlk_form COMMA rsctlk_form RRB { + // $$ = new FormRSCTLK(RSCTLK_AU_ACT, $3, $7, $9); // } - // | A LSB actions RSB F rsctl_form { - // $$ = new FormRSCTL(RSCTL_AF_ACT, $3, $6); + // | A LSB actions RSB F rsctlk_form { + // $$ = new FormRSCTLK(RSCTLK_AF_ACT, $3, $6); // } - // | A LSB actions RSB G rsctl_form { - // $$ = new FormRSCTL(RSCTL_AG_ACT, $3, $6); + // | A LSB actions RSB G rsctlk_form { + // $$ = new FormRSCTLK(RSCTLK_AG_ACT, $3, $6); // } /* contexts as boolean formulae */ - | E LAB bool_contexts RAB X rsctl_form { - $$ = new FormRSCTL(RSCTL_EX_ACT, $3, $6); + | E LAB bool_contexts RAB X rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_EX_ACT, $3, $6); } - | E LAB bool_contexts RAB U LRB rsctl_form COMMA rsctl_form RRB { - $$ = new FormRSCTL(RSCTL_EU_ACT, $3, $7, $9); + | E LAB bool_contexts RAB U LRB rsctlk_form COMMA rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_EU_ACT, $3, $7, $9); } - | E LAB bool_contexts RAB F rsctl_form { - $$ = new FormRSCTL(RSCTL_EF_ACT, $3, $6); + | E LAB bool_contexts RAB F rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_EF_ACT, $3, $6); } - | E LAB bool_contexts RAB G rsctl_form { - $$ = new FormRSCTL(RSCTL_EG_ACT, $3, $6); + | E LAB bool_contexts RAB G rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_EG_ACT, $3, $6); } - | A LAB bool_contexts RAB X rsctl_form { - $$ = new FormRSCTL(RSCTL_AX_ACT, $3, $6); + | A LAB bool_contexts RAB X rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AX_ACT, $3, $6); } - | A LAB bool_contexts RAB U LRB rsctl_form COMMA rsctl_form RRB { - $$ = new FormRSCTL(RSCTL_AU_ACT, $3, $7, $9); + | A LAB bool_contexts RAB U LRB rsctlk_form COMMA rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_AU_ACT, $3, $7, $9); } - | A LAB bool_contexts RAB F rsctl_form { - $$ = new FormRSCTL(RSCTL_AF_ACT, $3, $6); + | A LAB bool_contexts RAB F rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AF_ACT, $3, $6); } - | A LAB bool_contexts RAB G rsctl_form { - $$ = new FormRSCTL(RSCTL_AG_ACT, $3, $6); + | A LAB bool_contexts RAB G rsctlk_form { + $$ = new FormRSCTLK(RSCTLK_AG_ACT, $3, $6); } ; %% diff --git a/symrs.hh b/symrs.hh index 5133420..cea2470 100644 --- a/symrs.hh +++ b/symrs.hh @@ -30,7 +30,7 @@ using std::map; class SymRS { friend class ModelChecker; - friend class FormRSCTL; + friend class FormRSCTLK; public: SymRS(RctSys *rs, Options *opts); From 3157bb09efdeb3396308b02e33fb4e8d6ba38ad5 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 21 Apr 2018 22:26:42 +0100 Subject: [PATCH 29/90] Support for NK --- formrsctlk.cc | 6 ++++++ formrsctlk.hh | 9 +++++++++ in/hsr_drs.rs | 14 +++++++------- mc.cc | 14 ++++++++++++++ mc.hh | 1 + rsin_parser.ll | 4 +++- rsin_parser.yy | 6 ++++++ 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/formrsctlk.cc b/formrsctlk.cc index 5870709..334fa0d 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -151,6 +151,12 @@ std::string FormRSCTLK::toStr(void) const else if (oper == RSCTLK_AF_ACT) { return "A" + getActionsStr() + "F(" + arg[0]->toStr() + ")"; } + else if (oper == RSCTLK_NK) { + return "NK[" + getSingleAgent() + "](" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTLK_UK) { + return "UK[" + getSingleAgent() + "](" + arg[0]->toStr() + ")"; + } else { return "??"; diff --git a/formrsctlk.hh b/formrsctlk.hh index 008e5a1..b992ff6 100644 --- a/formrsctlk.hh +++ b/formrsctlk.hh @@ -372,6 +372,15 @@ class FormRSCTLK } } bool isERSCTLK(void) const; + Agents_f getAgents(void) const + { + return agents; + } + std::string getSingleAgent(void) const + { + assert(oper == RSCTLK_NK || oper == RSCTLK_UK); + return *(agents.begin()); + } }; #endif diff --git a/in/hsr_drs.rs b/in/hsr_drs.rs index f4bcd00..51c33af 100644 --- a/in/hsr_drs.rs +++ b/in/hsr_drs.rs @@ -44,21 +44,21 @@ context-automaton { } # P1 -rsctl-property { AG(mainA.hse OR mainA.hsf3:hse IMPLIES AX(mainA.hse OR mainA.hsf3:hse)) } +rsctlk-property { AG(mainA.hse OR mainA.hsf3:hse IMPLIES AX(mainA.hse OR NK[mainA]( mainA.hsf3:hse ))) } # P2 -#rsctl-property { A[{stress},{nostress}]G(~(hse AND hsf3:hse) IMPLIES A[{stress},{nostress}]X(~(hse AND hsf3:hse))) } +#rsctlk-property { A[{stress},{nostress}]G(~(hse AND hsf3:hse) IMPLIES A[{stress},{nostress}]X(~(hse AND hsf3:hse))) } # P3 -#rsctl-property { A[{stress},{nostress}]G(prot IMPLIES A[{stress},{nostress}]X(prot)) } +#rsctlk-property { A[{stress},{nostress}]G(prot IMPLIES A[{stress},{nostress}]X(prot)) } # P4 -#rsctl-property { A[{stress},{nostress}]G(mfp IMPLIES A[{stress},{nostress}]X(mfp OR hsp:mfp)) } -#rsctl-property { A< stress XOR nostress >G(mfp IMPLIES A[{stress},{nostress}]X(mfp OR hsp:mfp)) } +#rsctlk-property { A[{stress},{nostress}]G(mfp IMPLIES A[{stress},{nostress}]X(mfp OR hsp:mfp)) } +#rsctlk-property { A< stress XOR nostress >G(mfp IMPLIES A[{stress},{nostress}]X(mfp OR hsp:mfp)) } # P5 -#rsctl-property { A[{stress},{nostress}]G( ((hsf XOR hsf3 XOR hsf3:hse XOR hsp:hsf) OR ~(hsf OR hsf3 OR hsf3:hse OR hsp:hsf)) IMPLIES A[{stress},{nostress}]X( (hsf XOR hsf3 XOR hsf3:hse XOR hsp:hsf) OR ~(hsf OR hsf3 OR hsf3:hse OR hsp:hsf) ) ) } +#rsctlk-property { A[{stress},{nostress}]G( ((hsf XOR hsf3 XOR hsf3:hse XOR hsp:hsf) OR ~(hsf OR hsf3 OR hsf3:hse OR hsp:hsf)) IMPLIES A[{stress},{nostress}]X( (hsf XOR hsf3 XOR hsf3:hse XOR hsp:hsf) OR ~(hsf OR hsf3 OR hsf3:hse OR hsp:hsf) ) ) } # P6 -#rsctl-property { A[{nostress}]G(hsp:hsf IMPLIES A[{nostress}]X (hsp:hsf)) } +#rsctlk-property { A[{nostress}]G(hsp:hsf IMPLIES A[{nostress}]X (hsp:hsf)) } diff --git a/mc.cc b/mc.cc index 0ad65f6..95c82c3 100644 --- a/mc.cc +++ b/mc.cc @@ -346,6 +346,10 @@ BDD ModelChecker::getStatesRSCTLK(const FormRSCTLK *form) return !statesEGctx(form->getActionsBDD(), !getStatesRSCTLK(form->getLeftSF()) * *reach) * *reach; } + else if (oper == RSCTLK_NK) { + auto proc_id = srs->rs->getProcessID(form->getSingleAgent()); + return statesNK(getStatesRSCTLK(form->getLeftSF()) * *reach, proc_id) * *reach; + } assert(0); // Should never happen return BDD_FALSE; @@ -430,6 +434,16 @@ BDD ModelChecker::statesEFctx(const BDD *contexts, const BDD &states) return x; } +BDD ModelChecker::statesNK(const BDD &states, Process proc_id) +{ + // bdd = new BDD((arg[0]->satStates(reach) * reach).ExistAbstract(bddOnlyIth(getAgent())) * reach); + BDD x = states; + + x = x.ExistAbstract(getIthOnly(proc_id)); + + return x; +} + BDD ModelChecker::getIthOnly(Process proc_id) { /* if possible, we return the BDD from cache */ diff --git a/mc.hh b/mc.hh index 9685c47..54b87b9 100644 --- a/mc.hh +++ b/mc.hh @@ -60,6 +60,7 @@ class ModelChecker BDD statesEGctx(const BDD *contexts, const BDD &states); BDD statesEUctx(const BDD *contexts, const BDD &statesA, const BDD &statesB); BDD statesEFctx(const BDD *contexts, const BDD &states); + BDD statesNK(const BDD &states, Process proc_id); BDD getIthOnly(Process proc_id); diff --git a/rsin_parser.ll b/rsin_parser.ll index a946223..3750a72 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -68,6 +68,8 @@ blank [ \t] "XOR" return token::XOR; "IMPLIES" return token::IMPLIES; "~" return token::NOT; +"A" return token::A; +"E" return token::E; "EX" return token::EX; "EU" return token::EU; "EF" return token::EF; @@ -83,7 +85,7 @@ blank [ \t] "K" return token::UK; "C" return token::UC; "D" return token::UD; -"E" return token::UE; +"UE" return token::UE; "NK" return token::NK; "NC" return token::NC; "ND" return token::ND; diff --git a/rsin_parser.yy b/rsin_parser.yy index 827eda5..440cc8a 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -370,6 +370,12 @@ rsctlk_form: $$ = new FormRSCTLK(RSCTLK_UK, agents, $6); free($3); } + | NK LSB IDENTIFIER RSB LRB rsctlk_form RRB { + Agents_f agents; + agents.insert(*$3); + $$ = new FormRSCTLK(RSCTLK_NK, agents, $6); + free($3); + } // | E LSB actions RSB X rsctlk_form { // $$ = new FormRSCTLK(RSCTLK_EX_ACT, $3, $6); From 142846b90cbc7879cf865f28649f9e0dd543d9e1 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 23 Apr 2018 20:15:46 +0100 Subject: [PATCH 30/90] Fixed a bug with missing process enabledness encoding in context; fixed bit count for CA --- ctx_aut.cc | 3 ++- symrs.cc | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ctx_aut.cc b/ctx_aut.cc index 0710e3c..3e2abf9 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -102,7 +102,8 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName) new_transition.src_state = getStateID(srcStateName); new_transition.ctx = tmpProcEntities; - tmpEntities.clear(); + // tmpEntities.clear(); + tmpProcEntities.clear(); new_transition.dst_state = getStateID(dstStateName); transitions.push_back(new_transition); } diff --git a/symrs.cc b/symrs.cc index 71f3fbf..7c35081 100644 --- a/symrs.cc +++ b/symrs.cc @@ -492,10 +492,7 @@ BDD SymRS::encContext(const EntitiesForProc &proc_entities) r *= encCtxEntity(proc_id, entity); } - // This check is not really requires. Just to be sure... - if (entities.size() > 0) { - r *= encProcEnabled(proc_id); - } + r *= encProcEnabled(proc_id); } return r; @@ -591,13 +588,16 @@ DecompReactions SymRS::getProductionConditions(Process proc_id) return dr; } -BDD SymRS::encEnabledness(Process proc_id, Entity entity_id) +BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) { - assert(prod_conds.size() > proc_id); + assert(prod_conds.size() > prod_proc_id); BDD enab = BDD_FALSE; - auto production_conditions = prod_conds[proc_id][entity_id]; + auto production_conditions = prod_conds[prod_proc_id][entity_id]; + + + VERB_LN(5, "| Produce " << rs->getEntityName(entity_id) << " in " << rs->getProcessName(prod_proc_id) << ":"); for (const auto &cond : production_conditions) { @@ -610,6 +610,9 @@ BDD SymRS::encEnabledness(Process proc_id, Entity entity_id) for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { if (processUsesEntity(proc_id, reactant)) { proc_reactants += encProcEnabled(proc_id) * encEntityCondition(proc_id, reactant); + + VERB_LN(5, "| - if process " << rs->getProcessName(proc_id) << " is enabled and has " << rs->getEntityName(reactant)); + } } // END FOR: prod_id @@ -748,7 +751,7 @@ size_t SymRS::getCtxAutStateEncodingSize(void) size_t bitCountMaxVal = 1; size_t numStates = rs->ctx_aut->statesCount(); - while (bitCountMaxVal <= numStates) { + while (bitCountMaxVal < numStates) { bitCount++; bitCountMaxVal *= 2; } From 36b59b5baf8dc3b5f246d378a1a0ad263b0b0177 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 29 Apr 2018 17:16:25 +0100 Subject: [PATCH 31/90] Universal K support --- mc.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mc.cc b/mc.cc index 95c82c3..9300923 100644 --- a/mc.cc +++ b/mc.cc @@ -350,6 +350,10 @@ BDD ModelChecker::getStatesRSCTLK(const FormRSCTLK *form) auto proc_id = srs->rs->getProcessID(form->getSingleAgent()); return statesNK(getStatesRSCTLK(form->getLeftSF()) * *reach, proc_id) * *reach; } + else if (oper == RSCTLK_UK) { + auto proc_id = srs->rs->getProcessID(form->getSingleAgent()); + return *reach - (statesNK(*reach - getStatesRSCTLK(form->getLeftSF()), proc_id) * *reach); + } assert(0); // Should never happen return BDD_FALSE; From 06a28f9e5447b419a44241a8662c7e5a4fce2d75 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 29 Apr 2018 18:54:19 +0100 Subject: [PATCH 32/90] Mutext DRS generator --- formrsctlk.cc | 2 +- in/gen_drs_mutex.py | 82 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 in/gen_drs_mutex.py diff --git a/formrsctlk.cc b/formrsctlk.cc index 334fa0d..044cc38 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -155,7 +155,7 @@ std::string FormRSCTLK::toStr(void) const return "NK[" + getSingleAgent() + "](" + arg[0]->toStr() + ")"; } else if (oper == RSCTLK_UK) { - return "UK[" + getSingleAgent() + "](" + arg[0]->toStr() + ")"; + return "K[" + getSingleAgent() + "](" + arg[0]->toStr() + ")"; } else { diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py new file mode 100755 index 0000000..9a3e4b1 --- /dev/null +++ b/in/gen_drs_mutex.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +from sys import argv,exit + +OPTIONS_STR = """ +options { use-context-automaton; } +""" +CONTROLLER_STR = """ + ct { + {{lock},{release} -> {lock}}; + {{req},{} -> {lock}}; + }; +""" + +PROC_STR = """ + proc{:d} {{ + {{{{out, busy}}, {{}} -> {{req}}}}; + {{{{out}}, {{}} -> {{req}}}}; + {{{{req}}, {{lock}} -> {{in}}}}; + {{{{in}}, {{busy}} -> {{out, release}}}}; + {{{{in, busy}}, {{}} -> {{in}}}}; + {{{{in, lock}}, {{}} -> {{req}}}}; + }}; +""" + +CA_STR = """ +context-automaton {{ + states {{ s0, s1 }} + init-state {{ s0 }} + transitions {{ +{:s} + }} +}} +""" + +PROPERTY_STR = """ +rsctlk-property { AG(proc0.in IMPLIES K[proc0](~proc1.in) ) } +""" + + +################################################################# + +if len(argv) < 2: + print("Usage: {:s} ".format(argv[0])) + exit(100) + +n = int(argv[1]) + +out = "" + +out += OPTIONS_STR +out += "reactions {\n" +out += CONTROLLER_STR +for i in range(n): + out += PROC_STR.format(i) +out += "}\n" + +transitions = "" + +init_trans = 8*" " + "{ ct={} " +for i in range(n): + init_trans += "proc{:d}={{out}} ".format(i) + +init_trans += "}: s0 -> s1;\n" + +transitions += init_trans + +for i in range(n): + transitions += "{:s}{{ ct={{}} proc{:d}={{}} }}: s1 -> s1;\n".format(8*" ", i) + +out += CA_STR.format(transitions) + +out += PROPERTY_STR + +print(out) + + # { ct={} proc1={out} }: s0 -> s1; + # { ct={} proc2={out} }: s0 -> s1; + + # { ct={} proc1={} }: s1 -> s1; + # { ct={} proc2={} }: s1 -> s1; + From 2aadb9df33861270c48fb240d5fc4d92cb10a3a4 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 29 Apr 2018 18:54:56 +0100 Subject: [PATCH 33/90] Cleanup --- in/gen_drs_mutex.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py index 9a3e4b1..852488d 100755 --- a/in/gen_drs_mutex.py +++ b/in/gen_drs_mutex.py @@ -74,9 +74,5 @@ out += PROPERTY_STR print(out) - # { ct={} proc1={out} }: s0 -> s1; - # { ct={} proc2={out} }: s0 -> s1; - - # { ct={} proc1={} }: s1 -> s1; - # { ct={} proc2={} }: s1 -> s1; + From b7c4cd69064b7def01163c3876411fc64d242041 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 29 Apr 2018 19:58:17 +0100 Subject: [PATCH 34/90] Scalable formula --- in/gen_drs_mutex.py | 17 ++++++++++++----- symrs.cc | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py index 852488d..acb8adb 100755 --- a/in/gen_drs_mutex.py +++ b/in/gen_drs_mutex.py @@ -34,17 +34,20 @@ context-automaton {{ """ PROPERTY_STR = """ -rsctlk-property { AG(proc0.in IMPLIES K[proc0](~proc1.in) ) } +rsctlk-property {{ {:s} }} """ ################################################################# if len(argv) < 2: - print("Usage: {:s} ".format(argv[0])) + print("Usage: {:s} ".format(argv[0])) exit(100) n = int(argv[1]) +f = int(argv[2]) + +assert n > 1, "number of proc must be > 1" out = "" @@ -70,9 +73,13 @@ for i in range(n): out += CA_STR.format(transitions) -out += PROPERTY_STR +if f == 1: + subf = "~proc1.in" + for i in range(2, n): + subf += " AND ~proc{:d}.in".format(i) + formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) + +out += PROPERTY_STR.format(formula) print(out) - - diff --git a/symrs.cc b/symrs.cc index 7c35081..75c6a3e 100644 --- a/symrs.cc +++ b/symrs.cc @@ -596,7 +596,6 @@ BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) auto production_conditions = prod_conds[prod_proc_id][entity_id]; - VERB_LN(5, "| Produce " << rs->getEntityName(entity_id) << " in " << rs->getProcessName(prod_proc_id) << ":"); for (const auto &cond : production_conditions) { @@ -639,6 +638,11 @@ BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) } // END FOR: cond + if (opts->reorder_trans) { + VERB_L2("Reordering"); + Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); + } + return enab; } From 1590dacdcbe8c3084e2f3ca3a006ba36288c6ce4 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 29 Apr 2018 19:59:02 +0100 Subject: [PATCH 35/90] Check for incorrect property number --- in/gen_drs_mutex.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py index acb8adb..d9ede51 100755 --- a/in/gen_drs_mutex.py +++ b/in/gen_drs_mutex.py @@ -78,6 +78,8 @@ if f == 1: for i in range(2, n): subf += " AND ~proc{:d}.in".format(i) formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) +else: + assert False, "No such formula" out += PROPERTY_STR.format(formula) From 54ee79b6b30bace2061aeb292266ea3650761e38 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 28 May 2018 18:18:37 +0100 Subject: [PATCH 36/90] Changes to the transition relation --- symrs.cc | 108 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 13 deletions(-) diff --git a/symrs.cc b/symrs.cc index 75c6a3e..1452952 100644 --- a/symrs.cc +++ b/symrs.cc @@ -598,17 +598,32 @@ BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) VERB_LN(5, "| Produce " << rs->getEntityName(entity_id) << " in " << rs->getProcessName(prod_proc_id) << ":"); + // Iterate through production conditions for the entity (entity_id) that + // belongs to the process prod_proc_id which contain: + // - reactants + // - inhibitors + // + // Here we are building an alternative for the enab BDD, + // for all the possible production conditions + // for (const auto &cond : production_conditions) { + // Take all the reactants... (conjuntion) BDD reactants = BDD_TRUE; - BDD inhibitors = BDD_TRUE; for (const auto &reactant : cond.rctt) { + + // Disjunction for all the processes BDD proc_reactants = BDD_FALSE; + if (ctxEntityExists(prod_proc_id, reactant)) { + proc_reactants += encCtxEntity(prod_proc_id, reactant); + } + for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { - if (processUsesEntity(proc_id, reactant)) { - proc_reactants += encProcEnabled(proc_id) * encEntityCondition(proc_id, reactant); + if (productEntityExists(proc_id, reactant)) { + + proc_reactants += encProcEnabled(proc_id) * encEntity(proc_id, reactant); VERB_LN(5, "| - if process " << rs->getProcessName(proc_id) << " is enabled and has " << rs->getEntityName(reactant)); @@ -618,20 +633,27 @@ BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) reactants *= proc_reactants; } // END FOR: reactant - // For inhibitors, we take all the processes first and then we iterate over the inhibitors - for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { + + // Take all the inhibitors... (conjunction) + BDD inhibitors = BDD_TRUE; + + for (const auto &inhibitor : cond.inhib) { + + // Conjunction for all the processes BDD proc_inhibitors = BDD_TRUE; - for (const auto &inhibitor : cond.inhib) { - if (processUsesEntity(proc_id, inhibitor)) { - proc_inhibitors *= !encEntityCondition(proc_id, inhibitor); + if (ctxEntityExists(prod_proc_id, inhibitor)) { + proc_inhibitors *= !encCtxEntity(prod_proc_id, inhibitor); + } + + for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { + if (productEntityExists(proc_id, inhibitor)) { + proc_inhibitors *= !encEntity(proc_id, inhibitor) + !encProcEnabled(proc_id); } } - if (proc_inhibitors != BDD_TRUE) { // just an optimisation - proc_inhibitors += !encProcEnabled(proc_id); - inhibitors *= proc_inhibitors; - } + inhibitors *= proc_inhibitors; + } enab += reactants * inhibitors; @@ -639,13 +661,73 @@ BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) } // END FOR: cond if (opts->reorder_trans) { - VERB_L2("Reordering"); + VERB_L2("Reordering START"); Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); + VERB_L2("Reordering DONE"); } return enab; } +// BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) +// { +// assert(prod_conds.size() > prod_proc_id); + +// BDD enab = BDD_FALSE; + +// auto production_conditions = prod_conds[prod_proc_id][entity_id]; + +// VERB_LN(5, "| Produce " << rs->getEntityName(entity_id) << " in " << rs->getProcessName(prod_proc_id) << ":"); + +// for (const auto &cond : production_conditions) { + +// BDD reactants = BDD_TRUE; +// BDD inhibitors = BDD_TRUE; + +// for (const auto &reactant : cond.rctt) { +// BDD proc_reactants = BDD_FALSE; + +// for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { +// if (processUsesEntity(proc_id, reactant)) { +// proc_reactants += encProcEnabled(proc_id) * encEntityCondition(proc_id, reactant); + +// VERB_LN(5, "| - if process " << rs->getProcessName(proc_id) << " is enabled and has " << rs->getEntityName(reactant)); + +// } +// } // END FOR: prod_id + +// reactants *= proc_reactants; +// } // END FOR: reactant + +// // For inhibitors, we take all the processes first and then we iterate over the inhibitors +// for (unsigned int proc_id = 0; proc_id < numberOfProc; ++proc_id) { +// BDD proc_inhibitors = BDD_TRUE; + +// for (const auto &inhibitor : cond.inhib) { +// if (processUsesEntity(proc_id, inhibitor)) { +// proc_inhibitors *= !encEntityCondition(proc_id, inhibitor); +// } +// } + +// if (proc_inhibitors != BDD_TRUE) { // just an optimisation +// proc_inhibitors += !encProcEnabled(proc_id); +// inhibitors *= proc_inhibitors; +// } +// } + +// enab += reactants * inhibitors; + +// } // END FOR: cond + +// if (opts->reorder_trans) { +// VERB_L2("Reordering"); +// Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); +// } + +// return enab; +// } + + BDD SymRS::encEntitySameSuccessor(Process proc_id, Entity entity_id) { return BDD_IFF(encEntity(proc_id, entity_id), encEntitySucc(proc_id, entity_id)); From 964fb71d02f810913769550e65adccf592b40d4e Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Wed, 20 Jun 2018 17:50:44 +0100 Subject: [PATCH 37/90] Mutex generator (tgc) --- in/gen_drs_mutex.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py index d9ede51..621c40a 100755 --- a/in/gen_drs_mutex.py +++ b/in/gen_drs_mutex.py @@ -7,19 +7,18 @@ options { use-context-automaton; } """ CONTROLLER_STR = """ ct { - {{lock},{release} -> {lock}}; + {{lock},{leave} -> {lock}}; {{req},{} -> {lock}}; }; """ PROC_STR = """ proc{:d} {{ - {{{{out, busy}}, {{}} -> {{req}}}}; - {{{{out}}, {{}} -> {{req}}}}; + {{{{out}}, {{}} -> {{approach}}}}; + {{{{approach}}, {{req}} -> {{req}}}}; {{{{req}}, {{lock}} -> {{in}}}}; - {{{{in}}, {{busy}} -> {{out, release}}}}; - {{{{in, busy}}, {{}} -> {{in}}}}; - {{{{in, lock}}, {{}} -> {{req}}}}; + {{{{in}}, {{}} -> {{out,leave}}}}; + {{{{req}}, {{in}} -> {{req}}}}; }}; """ From 141c25386d916b7d3a5fa0834eb5350ca9a88273 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 17 Jul 2018 19:35:39 +0100 Subject: [PATCH 38/90] ReactICS --- Makefile | 6 +++--- main.cc => reactics.cc | 8 ++++---- main.hh => reactics.hh | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) rename main.cc => reactics.cc (96%) rename main.hh => reactics.hh (81%) diff --git a/Makefile b/Makefile index 40d229f..8317c63 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,13 @@ LDLIBS = $(CUDD_INCLUDE) OBJ = rs.o ctx_aut.o symrs.o mc.o rsin_driver.o rsin_parser.o rsin_parser.lex.o formrsctlk.o -all: main +all: reactics cleanly: rm -f *.lex.cc *.lex.o location.hh stack.hh position.hh rsin_parser.cc rsin_parser.hh clean: cleanly - rm -f *.o main *.orig *~ makefile.dep tags + rm -f *.o reactics *.orig *~ makefile.dep tags cleanall: clean @@ -27,7 +27,7 @@ makefile.dep: *.cc *.hh include makefile.dep -main: main.o $(OBJ) +reactics: reactics.o $(OBJ) rsin_parser.hh: rsin_parser.cc diff --git a/main.cc b/reactics.cc similarity index 96% rename from main.cc rename to reactics.cc index 85d3f71..f8b98b1 100644 --- a/main.cc +++ b/reactics.cc @@ -6,7 +6,7 @@ without the author's permission is strictly prohibited. */ -#include "main.hh" +#include "reactics.hh" int main(int argc, char **argv) { @@ -217,9 +217,9 @@ int main(int argc, char **argv) void print_help(std::string path_str) { cout << endl - << " ------------------------------------" << endl - << " -- Reaction Systems Model Checker --" << endl - << " ------------------------------------" << endl + << " ------------------------------------------------" << endl + << " -- ReactICS -- Reaction Systems Model Checker --" << endl + << " ------------------------------------------------" << endl << endl << " Version: " << VERSION << endl << " Contact: " << AUTHOR << endl diff --git a/main.hh b/reactics.hh similarity index 81% rename from main.hh rename to reactics.hh index b359869..8b6bfc7 100644 --- a/main.hh +++ b/reactics.hh @@ -3,8 +3,8 @@ Artur Meski */ -#ifndef RS_MAIN_HH -#define RS_MAIN_HH +#ifndef REACTICS_HH +#define REACTICS_HH #include #include @@ -20,7 +20,7 @@ #include "memtime.hh" #define VERSION "2.0 ALPHA" -#define AUTHOR "Artur Meski " +#define AUTHOR "Artur Meski " using std::cout; using std::endl; From 2aefa98aef3547c4846d73d3273bff56d24b0bc0 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 17 Jul 2018 20:04:11 +0100 Subject: [PATCH 39/90] Identifier --- rsin_driver.hh | 2 +- rsin_parser.yy | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rsin_driver.hh b/rsin_driver.hh index 5570960..8d0c3c7 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -45,7 +45,7 @@ class rsin_driver { this->opts = opts; }; - void addFormRSCTLK(FormRSCTLK *f) + void addFormRSCTLK(std::string *propertyName, FormRSCTLK *f) { rsctlkform = f; }; diff --git a/rsin_parser.yy b/rsin_parser.yy index 440cc8a..efe08c0 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -32,7 +32,7 @@ class rsin_driver; %union { int ival; - std::string *sval; + std::string sval; FormRSCTLK *frsctlk; // Entity_f *ent; // Action_f *act; @@ -81,8 +81,8 @@ system: | INITIALCONTEXTS LCB initstates RCB system | CONTEXTENTITIES LCB actionentities RCB system | CONTEXTAUTOMATON LCB ctxaut RCB system - | RSCTLKFORM LCB rsctlk_form RCB system { - driver.addFormRSCTLK($3); + | RSCTLKFORM LCB IDENTIFIER COL rsctlk_form RCB system { + driver.addFormRSCTLK($3, $5); } ; From eb2e4e552642336edb653abf054f5f2d4f029a9f Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 17 Jul 2018 20:10:18 +0100 Subject: [PATCH 40/90] Property name --- rsin_driver.hh | 2 +- rsin_parser.yy | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rsin_driver.hh b/rsin_driver.hh index 8d0c3c7..fe930b6 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -45,7 +45,7 @@ class rsin_driver { this->opts = opts; }; - void addFormRSCTLK(std::string *propertyName, FormRSCTLK *f) + void addFormRSCTLK(std::string propertyName, FormRSCTLK *f) { rsctlkform = f; }; diff --git a/rsin_parser.yy b/rsin_parser.yy index efe08c0..81bfb68 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -32,7 +32,7 @@ class rsin_driver; %union { int ival; - std::string sval; + std::string *sval; FormRSCTLK *frsctlk; // Entity_f *ent; // Action_f *act; @@ -82,7 +82,8 @@ system: | CONTEXTENTITIES LCB actionentities RCB system | CONTEXTAUTOMATON LCB ctxaut RCB system | RSCTLKFORM LCB IDENTIFIER COL rsctlk_form RCB system { - driver.addFormRSCTLK($3, $5); + driver.addFormRSCTLK(*$3, $5); + free($3); } ; From b0d69d0aa7d46da0f7287cb789c04e9c069c1874 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 17 Jul 2018 20:26:05 +0100 Subject: [PATCH 41/90] Property selection --- reactics.cc | 8 +++++--- rsin_driver.cc | 14 +++++++++----- rsin_driver.hh | 11 +++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/reactics.cc b/reactics.cc index f8b98b1..ab8371d 100644 --- a/reactics.cc +++ b/reactics.cc @@ -23,6 +23,7 @@ int main(int argc, char **argv) bool benchmarking = false; bool usage_error = false; bool print_parsed_sys = false; + std::string property_name = "default"; static struct option long_options[] = { {"trace-parsing", no_argument, 0, 0 }, @@ -33,7 +34,7 @@ int main(int argc, char **argv) int c; int option_index = 0; - while ((c = getopt_long(argc, argv, "cbBmpPrsStTvxzh", long_options, + while ((c = getopt_long(argc, argv, "c:bBmpPrsStTvxzh", long_options, &option_index)) != -1) { switch (c) { case 0: @@ -75,6 +76,7 @@ int main(int argc, char **argv) case 'c': rstl_model_checking = true; + property_name = optarg; break; case 'm': @@ -182,10 +184,10 @@ int main(int argc, char **argv) if (rstl_model_checking) { if (bmc) { cout << "Using BDD-based Bounded Model Checking" << endl; - mc.checkRSCTLK(driver.getFormRSCTLK()); + mc.checkRSCTLK(driver.getFormRSCTLK(property_name)); } else { - mc.checkRSCTLKfull(driver.getFormRSCTLK()); + mc.checkRSCTLKfull(driver.getFormRSCTLK(property_name)); } } } diff --git a/rsin_driver.cc b/rsin_driver.cc index 5e6ccf5..952fa51 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -17,7 +17,6 @@ rsin_driver::rsin_driver(RctSys *rs) void rsin_driver::initialise(void) { rs = nullptr; - rsctlkform = nullptr; opts = nullptr; use_ctx_aut = false; use_concentrations = false; @@ -49,13 +48,18 @@ void rsin_driver::error(const std::string &m) std::cerr << m << std::endl; } -FormRSCTLK *rsin_driver::getFormRSCTLK(void) +void rsin_driver::addFormRSCTLK(std::string propertyName, FormRSCTLK *f) { - if (rsctlkform == nullptr) { - FERROR("RSCTLK formula was not supplied!"); + properties[propertyName] = f; +}; + +FormRSCTLK *rsin_driver::getFormRSCTLK(std::string propertyName) +{ + if (properties.count(propertyName) == 0) { + FERROR("Property/formula label does not exist: " << propertyName); } - return rsctlkform; + return properties[propertyName]; } // diff --git a/rsin_driver.hh b/rsin_driver.hh index fe930b6..49002b4 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -25,9 +25,10 @@ class rsin_driver virtual ~rsin_driver(); //std::map variables; - FormRSCTLK *rsctlkform; Options *opts; + std::map properties; + // options in configuration file: bool use_ctx_aut; bool use_concentrations; @@ -45,11 +46,9 @@ class rsin_driver { this->opts = opts; }; - void addFormRSCTLK(std::string propertyName, FormRSCTLK *f) - { - rsctlkform = f; - }; - FormRSCTLK *getFormRSCTLK(void); + void addFormRSCTLK(std::string propertyName, FormRSCTLK *f); + + FormRSCTLK *getFormRSCTLK(std::string propertyName); void ensureOptionsAllowed(void); void useContextAutomaton(void); From 36b5e7b741af56381986de047679e601766c7d66 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Tue, 17 Jul 2018 20:31:26 +0100 Subject: [PATCH 42/90] TGC generator --- in/gen_drs_mutex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py index 621c40a..35188c0 100755 --- a/in/gen_drs_mutex.py +++ b/in/gen_drs_mutex.py @@ -33,7 +33,7 @@ context-automaton {{ """ PROPERTY_STR = """ -rsctlk-property {{ {:s} }} +rsctlk-property {{ default : {:s} }} """ From 5edab042669c68f7357ce3b7aa7f4d21f81446ad Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 22 Jul 2018 14:12:14 +0100 Subject: [PATCH 43/90] Benchmarks --- in/gen_drs_mutex.py | 27 +++++++++++++++------------ memtime.hh | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/in/gen_drs_mutex.py b/in/gen_drs_mutex.py index 35188c0..5cf3dd9 100755 --- a/in/gen_drs_mutex.py +++ b/in/gen_drs_mutex.py @@ -33,18 +33,17 @@ context-automaton {{ """ PROPERTY_STR = """ -rsctlk-property {{ default : {:s} }} +rsctlk-property {{ {:s} : {:s} }} """ ################################################################# -if len(argv) < 2: - print("Usage: {:s} ".format(argv[0])) +if len(argv) < 1: + print("Usage: {:s} ".format(argv[0])) exit(100) n = int(argv[1]) -f = int(argv[2]) assert n > 1, "number of proc must be > 1" @@ -72,15 +71,19 @@ for i in range(n): out += CA_STR.format(transitions) -if f == 1: - subf = "~proc1.in" - for i in range(2, n): - subf += " AND ~proc{:d}.in".format(i) - formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) -else: - assert False, "No such formula" +# f1 +formula = "EF( proc0.in )" +for i in range(1, n): + formula += " AND EF( proc{:d}.in )".format(i) +out += PROPERTY_STR.format("f1",formula) -out += PROPERTY_STR.format(formula) +# f2 +subf = "~proc1.in" +for i in range(2, n): + subf += " AND ~proc{:d}.in".format(i) +formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) + +out += PROPERTY_STR.format("f2",formula) print(out) diff --git a/memtime.hh b/memtime.hh index fcc4a2f..d257276 100644 --- a/memtime.hh +++ b/memtime.hh @@ -21,6 +21,9 @@ #include #include +#if defined(__APPLE__) +#include +#endif #include #include #include "macro.hh" @@ -62,9 +65,21 @@ static inline int64 memUsedInt64() return (int64)memReadStat() * (int64)getpagesize(); } +#if defined(__APPLE__) + +static inline double memUsed() { + malloc_statistics_t t; + malloc_zone_statistics(NULL, &t); + return (double)t.max_size_in_use / (1024*1024); } + +#else + static inline double memUsed() { - return memUsedInt64() / 1048576.0; + return memUsedInt64() / (1024*1024); } #endif + +#endif + From f3a6fc6949b0b3f17ca77f1a87036a1996a4ae21 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 22 Jul 2018 14:17:26 +0100 Subject: [PATCH 44/90] Benchmarking script --- drs_benchmark.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 drs_benchmark.sh diff --git a/drs_benchmark.sh b/drs_benchmark.sh new file mode 100755 index 0000000..cd69944 --- /dev/null +++ b/drs_benchmark.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +TMPINPUT="tmp_$RANDOM$RANDOM.rs" + +CMD="./reactics -b -B" + +for i in `seq 2 10`;do + + echo "[i] n=$i; generating input file" + in/gen_drs_mutex.py $i > $TMPINPUT + + for f in `seq 1 2`; do + + echo "[i] Testing formula f$f" + + TMPCMD="$CMD -c f$f $TMPINPUT" + echo "[i] running reactics: $TMPCMD" + + res=$($TMPCMD | grep STAT) + mem=$(echo $res | cut -d';' -f 5) + time=$(echo $res | cut -d';' -f 6) + + echo "[.] Finished. time:$time, mem:$mem" + + echo "$i $time $mem" >> results_f$f.out + + done + + echo + +done + +rm -f $TMPINPUT + +# EOF \ No newline at end of file From 41b609326a7ff4f63ef233cfb6b72ddc53afc421 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 22 Jul 2018 15:08:50 +0100 Subject: [PATCH 45/90] Benchmarks --- drs_benchmark.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index cd69944..42f9bf7 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -4,7 +4,7 @@ TMPINPUT="tmp_$RANDOM$RANDOM.rs" CMD="./reactics -b -B" -for i in `seq 2 10`;do +for i in `seq 2 20`;do echo "[i] n=$i; generating input file" in/gen_drs_mutex.py $i > $TMPINPUT @@ -32,4 +32,4 @@ done rm -f $TMPINPUT -# EOF \ No newline at end of file +# EOF From 482828a04e424e8f98743673afd5497592a3153a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 22 Jul 2018 15:11:52 +0100 Subject: [PATCH 46/90] Benchmarks --- drs_benchmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index 42f9bf7..828587e 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -22,7 +22,7 @@ for i in `seq 2 20`;do echo "[.] Finished. time:$time, mem:$mem" - echo "$i $time $mem" >> results_f$f.out + echo "$i $time $mem" >> bench_drs_mutex_f$f.dat done From 18e840ce17587baf56927401028f1e6f8e8a6c67 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 22 Jul 2018 18:25:19 +0100 Subject: [PATCH 47/90] Partitioned trnasition relation with reordering --- drs_benchmark.sh | 2 +- mc.cc | 14 ++++++----- symrs.cc | 62 ++++++++++++++++++++++++++++++++++++++---------- symrs.hh | 2 ++ 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index 828587e..d944121 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -2,7 +2,7 @@ TMPINPUT="tmp_$RANDOM$RANDOM.rs" -CMD="./reactics -b -B" +CMD="./reactics -z -b -B" for i in `seq 2 20`;do diff --git a/mc.cc b/mc.cc index 9300923..8dcf876 100644 --- a/mc.cc +++ b/mc.cc @@ -73,8 +73,8 @@ inline BDD ModelChecker::getSucc(const BDD &states) VERB_L2("Computing successors"); if (opts->part_tr_rel) { - for (unsigned int i = 0; i < trp_size; ++i) { - q *= states * (*trp)[i]; + for (const auto &trans : *trp) { + q *= states * trans; } } else { @@ -99,8 +99,8 @@ inline BDD ModelChecker::getPreE(const BDD &states) BDD x = states.SwapVariables(*pv, *pv_succ); if (opts->part_tr_rel) { - for (unsigned int i = 0; i < trp_size; ++i) { - q *= x * (*trp)[i]; + for (const auto &trans : *trp) { + q *= x * trans; } } else { @@ -110,6 +110,7 @@ inline BDD ModelChecker::getPreE(const BDD &states) q = q.ExistAbstract(*pv_succ_E); q = q.ExistAbstract(*pv_ctx_E); q = q.ExistAbstract(*pv_proc_enab_E); + return q; } @@ -120,9 +121,10 @@ inline BDD ModelChecker::getPreEctx(const BDD &states, const BDD *contexts) BDD x = states.SwapVariables(*pv, *pv_succ); if (opts->part_tr_rel) { - for (unsigned int i = 0; i < trp_size; ++i) { - q *= x * (*trp)[i] * *contexts; + for (const auto &trans : *trp) { + q *= x * trans; } + q *= *contexts; } else { q *= x * *trm * *contexts; diff --git a/symrs.cc b/symrs.cc index 1452952..0e37d21 100644 --- a/symrs.cc +++ b/symrs.cc @@ -660,11 +660,7 @@ BDD SymRS::encEnabledness(Process prod_proc_id, Entity entity_id) } // END FOR: cond - if (opts->reorder_trans) { - VERB_L2("Reordering START"); - Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); - VERB_L2("Reordering DONE"); - } + reorder(); return enab; } @@ -762,22 +758,51 @@ void SymRS::encodeTransitions(void) if (opts->part_tr_rel) { VERB("Using partitioned transition relation encoding"); - FERROR("Partitioned transition relation is currently not supported"); + + if (usingContextAutomaton()) { + partTrans = new BDDvec(numberOfProc+1); + } + else { + partTrans = new BDDvec(numberOfProc); + } + } else { + VERB("Using monolithic transition relation encoding"); monoTrans = new BDD(BDD_TRUE); + } VERB_LN(3, "Entity production encoding for all the processes and their products"); - for (const auto &proc_products : usedProducts) { - auto proc_id = proc_products.first; - auto products = proc_products.second; + if (opts->part_tr_rel) + { - for (const auto &prod : products) { - *monoTrans *= encEntityProduction(proc_id, prod); + for (const auto &proc_products : usedProducts) { + auto proc_id = proc_products.first; + auto products = proc_products.second; + + (*partTrans)[proc_id] = BDD_TRUE; + + for (const auto &prod : products) { + (*partTrans)[proc_id] *= encEntityProduction(proc_id, prod); + } } + + + } + else { + + for (const auto &proc_products : usedProducts) { + auto proc_id = proc_products.first; + auto products = proc_products.second; + + for (const auto &prod : products) { + *monoTrans *= encEntityProduction(proc_id, prod); + } + } + } VERB("Reactions ready"); @@ -785,8 +810,9 @@ void SymRS::encodeTransitions(void) if (usingContextAutomaton()) { VERB("Augmenting transition relation encoding with the transition relation for context automaton"); - if (opts->part_tr_rel) { - FERROR("Partitioned transition relation is currently not supported"); + if (opts->part_tr_rel) { + auto last_index = numberOfProc; + (*partTrans)[last_index] = *tr_ca; } else { assert(tr_ca != nullptr); @@ -915,4 +941,14 @@ void SymRS::encodeCtxAutTrans(void) } } + +void SymRS::reorder(void) +{ + if (opts->reorder_trans) { + VERB_L2("Reordering START"); + Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); + VERB_L2("Reordering DONE"); + } +} + /** EOF **/ diff --git a/symrs.hh b/symrs.hh index cea2470..4023eb7 100644 --- a/symrs.hh +++ b/symrs.hh @@ -344,6 +344,8 @@ class SymRS size_t getCtxAutStateEncodingSize(void); + void reorder(void); + }; #endif From 07171c6d605118437a2273cd69bf2bc22365d9c4 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 22 Jul 2018 20:20:14 +0100 Subject: [PATCH 48/90] Optimisations --- drs_benchmark.sh | 4 ++-- formrsctlk.hh | 6 +++--- mc.cc | 13 +++++++++++++ mc.hh | 2 ++ symrs.cc | 3 ++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index d944121..05edb14 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -2,9 +2,9 @@ TMPINPUT="tmp_$RANDOM$RANDOM.rs" -CMD="./reactics -z -b -B" +CMD="./reactics -zxbB" -for i in `seq 2 20`;do +for i in `seq 2 9`;do echo "[i] n=$i; generating input file" in/gen_drs_mutex.py $i > $TMPINPUT diff --git a/formrsctlk.hh b/formrsctlk.hh index b992ff6..b9b94c0 100644 --- a/formrsctlk.hh +++ b/formrsctlk.hh @@ -40,8 +40,8 @@ #define RSCTLK_AF_ACT 44 #define RSCTLK_TF 50 // true/false -#define RSCTLK_UK 60 // Epistemic operators -#define RSCTLK_NK 61 +#define RSCTLK_NK 61 // Epistemic operators +#define RSCTLK_UK 71 /* For Boolean contexts: */ #define BCTX_PV 80 @@ -57,7 +57,7 @@ #define RSCTLK_COND_ACT(a) ((a) > 30 && (a) < 45) #define RSCTLK_IS_VALID(a) (RSCTLK_COND_1ARG(a) || RSCTLK_COND_2ARG(a) || (a) == RSCTLK_PV || (a) == RSCTLK_TF) -#define RSCTLK_COND_IS_UNIVERSAL(a) (((a) > 20 && (a) < 25) || ((a) > 40 && (a) < 45)) +#define RSCTLK_COND_IS_UNIVERSAL(a) (((a) > 20 && (a) < 25) || ((a) > 40 && (a) < 45) || ((a) > 70 && (a) < 75)) #define BCTX_COND_1ARG(a) ((a) == BCTX_NOT) #define BCTX_COND_2ARG(a) ((a) == BCTX_AND || (a) == BCTX_OR || (a) == BCTX_XOR) diff --git a/mc.cc b/mc.cc index 8dcf876..4d20649 100644 --- a/mc.cc +++ b/mc.cc @@ -75,6 +75,7 @@ inline BDD ModelChecker::getSucc(const BDD &states) if (opts->part_tr_rel) { for (const auto &trans : *trp) { q *= states * trans; + reorder(); } } else { @@ -101,6 +102,7 @@ inline BDD ModelChecker::getPreE(const BDD &states) if (opts->part_tr_rel) { for (const auto &trans : *trp) { q *= x * trans; + reorder(); } } else { @@ -123,6 +125,7 @@ inline BDD ModelChecker::getPreEctx(const BDD &states, const BDD *contexts) if (opts->part_tr_rel) { for (const auto &trans : *trp) { q *= x * trans; + reorder(); } q *= *contexts; } @@ -619,6 +622,16 @@ bool ModelChecker::checkRSCTLKbmc(FormRSCTLK *form) return result; } +void ModelChecker::reorder(void) +{ + if (opts->reorder_trans) { + VERB_L2("Reordering START"); + // Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 100000); + cuddMgr->ReduceHeap(CUDD_REORDER_GROUP_SIFT); + VERB_L2("Reordering DONE"); + } +} + void ModelChecker::cleanup(void) { delete reach; diff --git a/mc.hh b/mc.hh index 54b87b9..663d3bd 100644 --- a/mc.hh +++ b/mc.hh @@ -66,6 +66,8 @@ class ModelChecker void cleanup(void); + void reorder(void); + public: ModelChecker(SymRS *srs, Options *opts); diff --git a/symrs.cc b/symrs.cc index 0e37d21..1258e90 100644 --- a/symrs.cc +++ b/symrs.cc @@ -946,7 +946,8 @@ void SymRS::reorder(void) { if (opts->reorder_trans) { VERB_L2("Reordering START"); - Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); + // Cudd_ReduceHeap(cuddMgr->getManager(), CUDD_REORDER_SIFT, 10000); + cuddMgr->ReduceHeap(CUDD_REORDER_GROUP_SIFT); VERB_L2("Reordering DONE"); } } From d4ac425963a755456855c3fe0e07ad37e15a4e44 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 22 Sep 2018 20:05:19 +0100 Subject: [PATCH 49/90] state constraints --- stateconstr.cc | 74 +++++++++++++++++++++++++++++++++ stateconstr.hh | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 stateconstr.cc create mode 100644 stateconstr.hh diff --git a/stateconstr.cc b/stateconstr.cc new file mode 100644 index 0000000..b1e47e4 --- /dev/null +++ b/stateconstr.cc @@ -0,0 +1,74 @@ +/* + Copyright (c) 2018 + Artur Meski + + Reuse of the code or its part for any purpose + without the author's permission is strictly prohibited. +*/ + +#include "stateconstr.hh" + +std::string StateConstr::toStr(void) const +{ + if (oper == STC_PV) { + return proc_name + "." + entity_name; + } + else if (oper == STC_TF) { + if (tf) { + return "true"; + } + else { + return "false"; + } + } + else if (oper == STC_AND) { + return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; + } + else if (oper == STC_OR) { + return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; + } + else if (oper == STC_XOR) { + return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; + } + else if (oper == STC_NOT) { + return "~" + arg[0]->toStr(); + } + + else { + return "??"; + assert(0); + } +} + +BDD StateConstr::getBDD(const SymRS *srs) const +{ + if (oper == STC_PV) { + return srs->encActStrEntity(proc_name, entity_name); + } + else if (oper == STC_TF) { + if (tf) { + return srs->getBDDtrue(); + } + else { + return srs->getBDDfalse(); + } + } + else if (oper == STC_AND) { + return arg[0]->getBDD(srs) * arg[1]->getBDD(srs); + } + else if (oper == STC_OR) { + return arg[0]->getBDD(srs) + arg[1]->getBDD(srs); + } + else if (oper == STC_XOR) { + return arg[0]->getBDD(srs) ^ arg[1]->getBDD(srs); + } + else if (oper == STC_NOT) { + return !arg[0]->getBDD(srs); + } + else { + assert(0); + FERROR("Undefined operator used in Boolean context definition. This should not happen."); + return srs->getBDDfalse(); + } +} + diff --git a/stateconstr.hh b/stateconstr.hh new file mode 100644 index 0000000..8fbbc59 --- /dev/null +++ b/stateconstr.hh @@ -0,0 +1,110 @@ +/* + Copyright (c) 2018 + Artur Meski + + Reuse of the code or its part for any purpose + without the author's permission is strictly prohibited. +*/ + +#ifndef STATECONSTR_HH +#define STATECONSTR_HH + +#include "types.hh" + +/* For Boolean contexts: */ +#define STC_PV 80 +#define STC_AND 81 +#define STC_OR 82 +#define STC_XOR 83 +#define STC_NOT 84 +#define STC_TF 90 + +#define STC_COND_1ARG(a) ((a) == STC_NOT) +#define STC_COND_2ARG(a) ((a) == STC_AND || (a) == STC_OR || (a) == STC_XOR) +#define STC_IS_VALID(a) (STC_COND_1ARG(a) || STC_COND_2ARG(a) || (a) == STC_PV || (a) == STC_TF) + +class SymRS; + +class StateConstr +{ + Oper oper; + StateConstr *arg[2]; + std::string entity_name; + std::string proc_name; + bool tf; + + public: + + StateConstr(std::string procName, std::string varName) + { + oper = STC_PV; + entity_name = varName; + proc_name = procName; + arg[0] = nullptr; + arg[1] = nullptr; + } + + /** + * @brief Constructor for true/false. + * + * @param val value of the logical constant + */ + StateConstr(bool val) + { + oper = STC_TF; + tf = val; + arg[0] = nullptr; + arg[1] = nullptr; + } + + /** + * @brief Constructor for one-argument formula. + */ + StateConstr(Oper op, StateConstr *form1) + { + assert(op == STC_NOT); + oper = op; + arg[0] = form1; + arg[1] = nullptr; + } + + /** + * @brief Constructor for two-argument formula. + */ + StateConstr(Oper op, StateConstr *form1, StateConstr *form2) + { + assert(STC_COND_2ARG(op)); + oper = op; + arg[0] = form1; + arg[1] = form2; + } + + ~StateConstr() + { + delete arg[0]; + delete arg[1]; + } + + std::string toStr(void) const; + + BDD getBDD(const SymRS *srs) const; + + Oper getOper(void) const + { + assert(STC_IS_VALID(oper)); + return oper; + } + StateConstr *getLeftSF(void) const + { + assert(arg[0] != nullptr); + return arg[0]; + } + StateConstr *getRightSF(void) const + { + assert(STC_COND_2ARG(oper)); + assert(arg[1] != nullptr); + return arg[1]; + } +}; + +#endif From a36ed9651f7e49853aa98ed024ba34e34b8270d6 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 22 Sep 2018 20:05:35 +0100 Subject: [PATCH 50/90] Includes, clean-up We are trying to avoid including stuff whenever possible. Forward declarations are prefered in most cases, just in case... --- bdd_macro.hh | 2 + ctx_aut.cc | 5 ++- ctx_aut.hh | 10 +++-- formrsctlk.cc | 28 ++++++------- formrsctlk.hh | 107 ++++--------------------------------------------- macro.hh | 2 + memtime.hh | 4 +- rs.cc | 9 ++++- rs.hh | 2 + rsin_driver.cc | 2 + rsin_driver.hh | 5 ++- rsin_parser.yy | 49 ++++++++++++---------- symrs.cc | 14 ++++++- symrs.hh | 15 +++---- types.hh | 2 + 15 files changed, 103 insertions(+), 153 deletions(-) diff --git a/bdd_macro.hh b/bdd_macro.hh index dee04e3..c39bf1e 100644 --- a/bdd_macro.hh +++ b/bdd_macro.hh @@ -1,6 +1,8 @@ #ifndef __BDD_MACRO_HH__ #define __BDD_MACRO_HH__ +#include "cudd.hh" + #define BDD_IFF(p,q) (!(p+q)+(p*q)) #define BDD_TRUE (cuddMgr->bddOne()) #define BDD_FALSE (cuddMgr->bddZero()) diff --git a/ctx_aut.cc b/ctx_aut.cc index 3e2abf9..def9d3c 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -1,5 +1,8 @@ #include "ctx_aut.hh" +#include "rs.hh" +#include "macro.hh" +#include "stateconstr.hh" CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys) { @@ -94,7 +97,7 @@ void CtxAut::saveCurrentContextSet(Process proc_id) tmpEntities.clear(); } -void CtxAut::addTransition(std::string srcStateName, std::string dstStateName) +void CtxAut::addTransition(std::string srcStateName, std::string dstStateName, StateConstr *stateConstr) { VERB_L3("Saving transition"); diff --git a/ctx_aut.hh b/ctx_aut.hh index e756dad..66bb489 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -12,15 +12,17 @@ #include #include #include -#include "rs.hh" +// #include "rs.hh" #include "types.hh" -#include "macro.hh" -#include "options.hh" +// #include "options.hh" +// #include "stateconstr.hh" using std::cout; using std::endl; class RctSys; +class Options; +class StateConstr; class CtxAut { @@ -36,7 +38,7 @@ class CtxAut std::string getStateName(State state_id); void printAutomaton(void); void showStates(void); - void addTransition(std::string srcStateName, std::string dstStateName); + void addTransition(std::string srcStateName, std::string dstStateName, StateConstr *stateConstr); void showTransitions(void); void pushContextEntity(Entity entity_id); void saveCurrentContextSet(Process proc_id); diff --git a/formrsctlk.cc b/formrsctlk.cc index 044cc38..6dc82fa 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -9,12 +9,12 @@ #include "formrsctlk.hh" -std::string BoolContexts::toStr(void) const +std::string StateConstr::toStr(void) const { - if (oper == BCTX_PV) { + if (oper == STC_PV) { return proc_name + "." + entity_name; } - else if (oper == BCTX_TF) { + else if (oper == STC_TF) { if (tf) { return "true"; } @@ -22,16 +22,16 @@ std::string BoolContexts::toStr(void) const return "false"; } } - else if (oper == BCTX_AND) { + else if (oper == STC_AND) { return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; } - else if (oper == BCTX_OR) { + else if (oper == STC_OR) { return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; } - else if (oper == BCTX_XOR) { + else if (oper == STC_XOR) { return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; } - else if (oper == BCTX_NOT) { + else if (oper == STC_NOT) { return "~" + arg[0]->toStr(); } @@ -41,12 +41,12 @@ std::string BoolContexts::toStr(void) const } } -BDD BoolContexts::getBDD(const SymRS *srs) const +BDD StateConstr::getBDD(const SymRS *srs) const { - if (oper == BCTX_PV) { + if (oper == STC_PV) { return srs->encActStrEntity(proc_name, entity_name); } - else if (oper == BCTX_TF) { + else if (oper == STC_TF) { if (tf) { return srs->getBDDtrue(); } @@ -54,16 +54,16 @@ BDD BoolContexts::getBDD(const SymRS *srs) const return srs->getBDDfalse(); } } - else if (oper == BCTX_AND) { + else if (oper == STC_AND) { return arg[0]->getBDD(srs) * arg[1]->getBDD(srs); } - else if (oper == BCTX_OR) { + else if (oper == STC_OR) { return arg[0]->getBDD(srs) + arg[1]->getBDD(srs); } - else if (oper == BCTX_XOR) { + else if (oper == STC_XOR) { return arg[0]->getBDD(srs) ^ arg[1]->getBDD(srs); } - else if (oper == BCTX_NOT) { + else if (oper == STC_NOT) { return !arg[0]->getBDD(srs); } else { diff --git a/formrsctlk.hh b/formrsctlk.hh index b9b94c0..474ea5f 100644 --- a/formrsctlk.hh +++ b/formrsctlk.hh @@ -12,9 +12,11 @@ #include #include #include -#include "rs.hh" +// #include "rs.hh" #include "symrs.hh" #include "cudd.hh" +#include "types.hh" +#include "stateconstr.hh" #define RSCTLK_PV 0 // propositional variable #define RSCTLK_AND 1 @@ -43,15 +45,6 @@ #define RSCTLK_NK 61 // Epistemic operators #define RSCTLK_UK 71 -/* For Boolean contexts: */ -#define BCTX_PV 80 -#define BCTX_AND 81 -#define BCTX_OR 82 -#define BCTX_XOR 83 -#define BCTX_NOT 84 -#define BCTX_TF 90 - - #define RSCTLK_COND_1ARG(a) ((a) == RSCTLK_NOT || (a) == RSCTLK_EG || (a) == RSCTLK_EF || (a) == RSCTLK_EX || (a) == RSCTLK_AG || (a) == RSCTLK_AF || (a) == RSCTLK_AX || (a) == RSCTLK_EG_ACT || (a) == RSCTLK_EF_ACT || (a) == RSCTLK_EX_ACT || (a) == RSCTLK_AG_ACT || (a) == RSCTLK_AF_ACT || (a) == RSCTLK_AX_ACT || (a) == RSCTLK_UK || (a) == RSCTLK_NK) #define RSCTLK_COND_2ARG(a) ((a) == RSCTLK_AND || (a) == RSCTLK_OR || (a) == RSCTLK_XOR || (a) == RSCTLK_IMPL || (a) == RSCTLK_EU || (a) == RSCTLK_AU || (a) == RSCTLK_EU_ACT || (a) == RSCTLK_AU_ACT) #define RSCTLK_COND_ACT(a) ((a) > 30 && (a) < 45) @@ -59,101 +52,15 @@ #define RSCTLK_COND_IS_UNIVERSAL(a) (((a) > 20 && (a) < 25) || ((a) > 40 && (a) < 45) || ((a) > 70 && (a) < 75)) -#define BCTX_COND_1ARG(a) ((a) == BCTX_NOT) -#define BCTX_COND_2ARG(a) ((a) == BCTX_AND || (a) == BCTX_OR || (a) == BCTX_XOR) -#define BCTX_IS_VALID(a) (BCTX_COND_1ARG(a) || BCTX_COND_2ARG(a) || (a) == BCTX_PV || (a) == BCTX_TF) - using std::cout; using std::endl; -typedef unsigned char Oper; - // typedef std::string Entity_f; // typedef std::set Action_f; // typedef vector ActionsVec_f; typedef std::set Agents_f; -class BoolContexts -{ - Oper oper; - BoolContexts *arg[2]; - std::string entity_name; - std::string proc_name; - bool tf; - - public: - - BoolContexts(std::string procName, std::string varName) - { - oper = BCTX_PV; - entity_name = varName; - proc_name = procName; - arg[0] = nullptr; - arg[1] = nullptr; - } - - /** - * @brief Constructor for true/false. - * - * @param val value of the logical constant - */ - BoolContexts(bool val) - { - oper = BCTX_TF; - tf = val; - arg[0] = nullptr; - arg[1] = nullptr; - } - - /** - * @brief Constructor for one-argument formula. - */ - BoolContexts(Oper op, BoolContexts *form1) - { - assert(op == BCTX_NOT); - oper = op; - arg[0] = form1; - arg[1] = nullptr; - } - - /** - * @brief Constructor for two-argument formula. - */ - BoolContexts(Oper op, BoolContexts *form1, BoolContexts *form2) - { - assert(BCTX_COND_2ARG(op)); - oper = op; - arg[0] = form1; - arg[1] = form2; - } - - ~BoolContexts() - { - delete arg[0]; - delete arg[1]; - } - - std::string toStr(void) const; - - BDD getBDD(const SymRS *srs) const; - - Oper getOper(void) const - { - assert(BCTX_IS_VALID(oper)); - return oper; - } - BoolContexts *getLeftSF(void) const - { - assert(arg[0] != nullptr); - return arg[0]; - } - BoolContexts *getRightSF(void) const - { - assert(BCTX_COND_2ARG(oper)); - assert(arg[1] != nullptr); - return arg[1]; - } -}; +class StateConstr; class FormRSCTLK { @@ -165,7 +72,7 @@ class FormRSCTLK BDD *bdd; // ActionsVec_f *actions; BDD *actions_bdd; - BoolContexts *boolCtx; + StateConstr *boolCtx; Agents_f agents; public: /** @@ -240,7 +147,7 @@ class FormRSCTLK /** * @brief Constructor for two-argument formula with Boolean context restrictions. */ - FormRSCTLK(Oper op, BoolContexts *bctx, FormRSCTLK *form1, FormRSCTLK *form2) + FormRSCTLK(Oper op, StateConstr *bctx, FormRSCTLK *form1, FormRSCTLK *form2) { assert(bctx != nullptr); assert(RSCTLK_COND_2ARG(op)); @@ -290,7 +197,7 @@ class FormRSCTLK /** * @brief Constructor for one-argument formula with Boolean context restrictions. */ - FormRSCTLK(Oper op, BoolContexts *bctx, FormRSCTLK *form1) + FormRSCTLK(Oper op, StateConstr *bctx, FormRSCTLK *form1) { assert(bctx != nullptr); assert(RSCTLK_COND_1ARG(op)); diff --git a/macro.hh b/macro.hh index 1e86fac..b4305a7 100644 --- a/macro.hh +++ b/macro.hh @@ -2,6 +2,8 @@ #define __MY_MACROS__ #include +#include + #define LINENUM std::cout << __FILE__ << " (function " << __func__ << "), line " << __LINE__ << std::endl; /* Fatal error */ diff --git a/memtime.hh b/memtime.hh index d257276..af6a286 100644 --- a/memtime.hh +++ b/memtime.hh @@ -28,6 +28,8 @@ #include #include "macro.hh" +using namespace std; + typedef long long int64; static inline double cpuTime(void) @@ -52,7 +54,7 @@ static inline int memReadStat(void) for (int field = 0; field >= 0; --field) { if (fscanf(in, "%d", &value) == EOF) { - FERROR("EOF"); + FERROR("EOF") } } diff --git a/rs.cc b/rs.cc index 5f9bf71..67f734f 100644 --- a/rs.cc +++ b/rs.cc @@ -322,7 +322,14 @@ void RctSys::ctxAutAddTransition(std::string srcStateName, std::string dstStateName) { assert(ctx_aut != nullptr); - ctx_aut->addTransition(srcStateName, dstStateName); + ctx_aut->addTransition(srcStateName, dstStateName, nullptr); +} + +void RctSys::ctxAutAddTransition(std::string srcStateName, + std::string dstStateName, StateConstr *stateConstr) +{ + assert(ctx_aut != nullptr); + ctx_aut->addTransition(srcStateName, dstStateName, stateConstr); } void RctSys::ctxAutPushNamedContextEntity(std::string entityName) diff --git a/rs.hh b/rs.hh index 1ac89b2..66389f2 100644 --- a/rs.hh +++ b/rs.hh @@ -25,6 +25,7 @@ using std::cout; using std::endl; class CtxAut; +class StateConstr; class RctSys { @@ -87,6 +88,7 @@ class RctSys void ctxAutAddState(std::string stateName); void ctxAutSetInitState(std::string stateName); void ctxAutAddTransition(std::string srcStateName, std::string dstStateName); + void ctxAutAddTransition(std::string srcStateName, std::string dstStateName, StateConstr *stateConstr); void ctxAutPushNamedContextEntity(std::string entity_name); void ctxAutSaveCurrentContextSet(std::string processName); diff --git a/rsin_driver.cc b/rsin_driver.cc index 952fa51..66c8403 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -1,6 +1,8 @@ #include "rsin_driver.hh" #include "rsin_parser.hh" +#include "rs.hh" + rsin_driver::rsin_driver(void) : trace_scanning(false), trace_parsing(false) { diff --git a/rsin_driver.hh b/rsin_driver.hh index 49002b4..381c3c4 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -3,7 +3,7 @@ #include #include #include "rsin_parser.hh" -#include "rs.hh" +// #include "rs.hh" #include "formrsctlk.hh" #include "options.hh" @@ -16,6 +16,9 @@ // ... and declare it for the parser's sake. YY_DECL; +class RctSys; +class CtxAut; + // Conducting the whole scanning an parsing of RS class rsin_driver { diff --git a/rsin_parser.yy b/rsin_parser.yy index 81bfb68..c87bbff 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -7,6 +7,8 @@ #include #include #include "formrsctlk.hh" +#include "rs.hh" +// #include "stateconstr.hh" using std::set; using std::string; @@ -37,7 +39,7 @@ class rsin_driver; // Entity_f *ent; // Action_f *act; // ActionsVec_f *actionsVec; - BoolContexts *fboolctx; + StateConstr *fstc; }; %code { @@ -64,7 +66,7 @@ class rsin_driver; // %type f_entity // %type action // %type actions -%type bool_contexts +%type state_constr //%printer { yyoutput << *$$; } "identifier" %destructor { delete $$; } "identifier" @@ -235,6 +237,11 @@ auttrans: LCB proc_ctxsets RCB COL IDENTIFIER RARR IDENTIFIER { free($5); free($7); } + | LCB proc_ctxsets RCB COL IDENTIFIER RARR IDENTIFIER COL state_constr { + driver.getReactionSystem()->ctxAutAddTransition(*$5, *$7, $9); + free($5); + free($7); + } ; proc_ctxsets: @@ -260,25 +267,25 @@ ctxentity: IDENTIFIER { /* formulae */ -bool_contexts: IDENTIFIER DOT IDENTIFIER { - $$ = new BoolContexts(*$1, *$3); +state_constr: IDENTIFIER DOT IDENTIFIER { + $$ = new StateConstr(*$1, *$3); free($1); free($3); } - | NOT bool_contexts { - $$ = new BoolContexts(BCTX_NOT, $2); + | NOT state_constr { + $$ = new StateConstr(STC_NOT, $2); } - | LRB bool_contexts RRB { + | LRB state_constr RRB { $$ = $2; } - | bool_contexts AND bool_contexts { - $$ = new BoolContexts(BCTX_AND, $1, $3); + | state_constr AND state_constr { + $$ = new StateConstr(STC_AND, $1, $3); } - | bool_contexts OR bool_contexts { - $$ = new BoolContexts(BCTX_OR, $1, $3); + | state_constr OR state_constr { + $$ = new StateConstr(STC_OR, $1, $3); } - | bool_contexts XOR bool_contexts { - $$ = new BoolContexts(BCTX_XOR, $1, $3); + | state_constr XOR state_constr { + $$ = new StateConstr(STC_XOR, $1, $3); } ; @@ -404,28 +411,28 @@ rsctlk_form: // } /* contexts as boolean formulae */ - | E LAB bool_contexts RAB X rsctlk_form { + | E LAB state_constr RAB X rsctlk_form { $$ = new FormRSCTLK(RSCTLK_EX_ACT, $3, $6); } - | E LAB bool_contexts RAB U LRB rsctlk_form COMMA rsctlk_form RRB { + | E LAB state_constr RAB U LRB rsctlk_form COMMA rsctlk_form RRB { $$ = new FormRSCTLK(RSCTLK_EU_ACT, $3, $7, $9); } - | E LAB bool_contexts RAB F rsctlk_form { + | E LAB state_constr RAB F rsctlk_form { $$ = new FormRSCTLK(RSCTLK_EF_ACT, $3, $6); } - | E LAB bool_contexts RAB G rsctlk_form { + | E LAB state_constr RAB G rsctlk_form { $$ = new FormRSCTLK(RSCTLK_EG_ACT, $3, $6); } - | A LAB bool_contexts RAB X rsctlk_form { + | A LAB state_constr RAB X rsctlk_form { $$ = new FormRSCTLK(RSCTLK_AX_ACT, $3, $6); } - | A LAB bool_contexts RAB U LRB rsctlk_form COMMA rsctlk_form RRB { + | A LAB state_constr RAB U LRB rsctlk_form COMMA rsctlk_form RRB { $$ = new FormRSCTLK(RSCTLK_AU_ACT, $3, $7, $9); } - | A LAB bool_contexts RAB F rsctlk_form { + | A LAB state_constr RAB F rsctlk_form { $$ = new FormRSCTLK(RSCTLK_AF_ACT, $3, $6); } - | A LAB bool_contexts RAB G rsctlk_form { + | A LAB state_constr RAB G rsctlk_form { $$ = new FormRSCTLK(RSCTLK_AG_ACT, $3, $6); } ; diff --git a/symrs.cc b/symrs.cc index 1258e90..b6cafbf 100644 --- a/symrs.cc +++ b/symrs.cc @@ -4,7 +4,8 @@ */ #include "symrs.hh" - +#include "rs.hh" +#include "bdd_macro.hh" SymRS::SymRS(RctSys *rs, Options *opts) { @@ -35,6 +36,17 @@ SymRS::SymRS(RctSys *rs, Options *opts) encode(); } +bool SymRS::usingContextAutomaton(void) +{ + return rs->ctx_aut != nullptr; +} + + +BDD SymRS::encEntity(std::string proc_name, std::string entity_name) const +{ + return encEntity(rs->getProcessID(proc_name), rs->getEntityID(entity_name)); +} + void SymRS::encode(void) { VERB("Encoding..."); diff --git a/symrs.hh b/symrs.hh index 4023eb7..aa275af 100644 --- a/symrs.hh +++ b/symrs.hh @@ -13,11 +13,12 @@ #include #include #include +#include #include "cudd.hh" #include "types.hh" #include "macro.hh" #include "bdd_macro.hh" -#include "rs.hh" +// #include "rs.hh" #include "options.hh" #include "memtime.hh" @@ -27,6 +28,8 @@ using std::endl; using std::vector; using std::map; +class RctSys; + class SymRS { friend class ModelChecker; @@ -87,10 +90,7 @@ class SymRS { return totalRctSysStateVars; } - BDD encEntity(std::string proc_name, std::string entity_name) const - { - return encEntity(rs->getProcessID(proc_name), rs->getEntityID(entity_name)); - } + BDD encEntity(std::string proc_name, std::string entity_name) const; BDD encActStrEntity(std::string proc_name, std::string entity_name) const; BDD getBDDtrue(void) const { @@ -106,10 +106,7 @@ class SymRS * * @return True if CA is used */ - bool usingContextAutomaton(void) - { - return rs->ctx_aut != nullptr; - } + bool usingContextAutomaton(void); /** * @brief Encodes a context automaton's state diff --git a/types.hh b/types.hh index 8cb55c8..f0a5054 100644 --- a/types.hh +++ b/types.hh @@ -15,6 +15,8 @@ #include #include "cudd.hh" +typedef unsigned char Oper; + typedef std::vector BDDvec; typedef unsigned int Entity; From 206996a7008b3d5b3b7da5c59cfd4308a41cc3b5 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 22 Sep 2018 22:55:00 +0100 Subject: [PATCH 51/90] Building of stateconstr.o; prelim. methods for ctx and state BDD enc. --- Makefile | 8 +++---- formrsctlk.cc | 65 -------------------------------------------------- stateconstr.cc | 13 ++++++++-- stateconstr.hh | 8 +++++-- 4 files changed, 21 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index 8317c63..0e28206 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ CUDD_INCLUDE=cudd/lib/libcudd.a INCLUDES=-Icudd/include CPPFLAGS_SILENT = $(INCLUDES) CPPFLAGS = -Wall $(CPPFLAGS_SILENT) #-Werror -#CPPFLAGS = -Wall $(INCLUDES) -DNDEBUG +#CPPFLAGS = -Wall $(INCLUDES) -DNDEBUG CXXFLAGS_SILENT = -O3 -g CXXFLAGS = -std=c++14 $(CXXFLAGS_SILENT) #CXXFLAGS = -std=c++14 -O3 -DPUBLIC_RELEASE -DNDEBUG #-g -LDLIBS = $(CUDD_INCLUDE) +LDLIBS = $(CUDD_INCLUDE) -OBJ = rs.o ctx_aut.o symrs.o mc.o rsin_driver.o rsin_parser.o rsin_parser.lex.o formrsctlk.o +OBJ = rs.o ctx_aut.o symrs.o mc.o rsin_driver.o rsin_parser.o rsin_parser.lex.o formrsctlk.o stateconstr.o all: reactics @@ -44,7 +44,7 @@ rsin_parser.lex.cc: rsin_parser.ll mv lex.yy.c rsin_parser.lex.cc style: - astyle --max-code-length=130 --break-closing-brackets --convert-tabs --add-brackets --max-instatement-indent=40 -s2 -C -xG -S -f -p -H -k1 -c --style=kr --align-pointer=name *.cc *.hh + astyle --max-code-length=130 --break-closing-brackets --convert-tabs --add-brackets --max-instatement-indent=40 -s2 -C -xG -S -f -p -H -k1 -c --style=kr --align-pointer=name *.cc *.hh commit: style git commit -a diff --git a/formrsctlk.cc b/formrsctlk.cc index 6dc82fa..f2f3acc 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -8,71 +8,6 @@ #include "formrsctlk.hh" - -std::string StateConstr::toStr(void) const -{ - if (oper == STC_PV) { - return proc_name + "." + entity_name; - } - else if (oper == STC_TF) { - if (tf) { - return "true"; - } - else { - return "false"; - } - } - else if (oper == STC_AND) { - return "(" + arg[0]->toStr() + " AND " + arg[1]->toStr() + ")"; - } - else if (oper == STC_OR) { - return "(" + arg[0]->toStr() + " OR " + arg[1]->toStr() + ")"; - } - else if (oper == STC_XOR) { - return "(" + arg[0]->toStr() + " XOR " + arg[1]->toStr() + ")"; - } - else if (oper == STC_NOT) { - return "~" + arg[0]->toStr(); - } - - else { - return "??"; - assert(0); - } -} - -BDD StateConstr::getBDD(const SymRS *srs) const -{ - if (oper == STC_PV) { - return srs->encActStrEntity(proc_name, entity_name); - } - else if (oper == STC_TF) { - if (tf) { - return srs->getBDDtrue(); - } - else { - return srs->getBDDfalse(); - } - } - else if (oper == STC_AND) { - return arg[0]->getBDD(srs) * arg[1]->getBDD(srs); - } - else if (oper == STC_OR) { - return arg[0]->getBDD(srs) + arg[1]->getBDD(srs); - } - else if (oper == STC_XOR) { - return arg[0]->getBDD(srs) ^ arg[1]->getBDD(srs); - } - else if (oper == STC_NOT) { - return !arg[0]->getBDD(srs); - } - else { - assert(0); - FERROR("Undefined operator used in Boolean context definition. This should not happen."); - return srs->getBDDfalse(); - } -} - std::string FormRSCTLK::toStr(void) const { if (oper == RSCTLK_PV) { diff --git a/stateconstr.cc b/stateconstr.cc index b1e47e4..9290ac6 100644 --- a/stateconstr.cc +++ b/stateconstr.cc @@ -7,6 +7,10 @@ */ #include "stateconstr.hh" +#include "types.hh" +#include "cudd.hh" +#include "bdd_macro.hh" +#include "symrs.hh" std::string StateConstr::toStr(void) const { @@ -40,7 +44,13 @@ std::string StateConstr::toStr(void) const } } -BDD StateConstr::getBDD(const SymRS *srs) const +BDD StateConstr::getBDDforState(const SymRS *srs) const +{ + assert(0); + // return BDD_FALSE; +} + +BDD StateConstr::getBDDforContext(const SymRS *srs) const { if (oper == STC_PV) { return srs->encActStrEntity(proc_name, entity_name); @@ -71,4 +81,3 @@ BDD StateConstr::getBDD(const SymRS *srs) const return srs->getBDDfalse(); } } - diff --git a/stateconstr.hh b/stateconstr.hh index 8fbbc59..9b60f2d 100644 --- a/stateconstr.hh +++ b/stateconstr.hh @@ -11,7 +11,7 @@ #include "types.hh" -/* For Boolean contexts: */ +/* For state constraints: */ #define STC_PV 80 #define STC_AND 81 #define STC_OR 82 @@ -87,7 +87,11 @@ class StateConstr std::string toStr(void) const; - BDD getBDD(const SymRS *srs) const; + BDD getBDD(const SymRS *srs) const { + return getBDDforContext(srs); + } + BDD getBDDforContext(const SymRS *srs) const; + BDD getBDDforState(const SymRS *srs) const; Oper getOper(void) const { From ac97db8ead1afc82297c0f1de957b9e4da0ddbc6 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 23 Sep 2018 13:12:33 +0100 Subject: [PATCH 52/90] Printing of the state constraints in the context automaton --- ctx_aut.cc | 7 ++++++- types.hh | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ctx_aut.cc b/ctx_aut.cc index def9d3c..d095f9f 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -107,6 +107,7 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName, S new_transition.ctx = tmpProcEntities; // tmpEntities.clear(); tmpProcEntities.clear(); + new_transition.state_constr = stateConstr; new_transition.dst_state = getStateID(dstStateName); transitions.push_back(new_transition); } @@ -118,7 +119,11 @@ 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) << "}"; + if (t.state_constr != nullptr) { + cout << " " << t.state_constr->toStr(); + } + cout << endl; } } diff --git a/types.hh b/types.hh index f0a5054..b49eb62 100644 --- a/types.hh +++ b/types.hh @@ -56,9 +56,11 @@ typedef std::vector ReactionConds; typedef std::map DecompReactions; typedef std::vector StateEntityToAction; +class StateConstr; struct CtxAutTransition { State src_state; EntitiesForProc ctx; + StateConstr *state_constr; State dst_state; }; From 469ca7e46ba406741fcb0d18784b4bc2ea395fc4 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 7 Oct 2018 21:45:28 +0100 Subject: [PATCH 53/90] Added encoding of the DRS state constraints to the context automaton --- formrsctlk.cc | 2 +- stateconstr.cc | 23 +++++++++++++++-------- stateconstr.hh | 4 +--- symrs.cc | 7 ++++--- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/formrsctlk.cc b/formrsctlk.cc index f2f3acc..6921548 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -234,7 +234,7 @@ void FormRSCTLK::encodeActions(const SymRS *srs) // } // } if (boolCtx != nullptr) { - *actions_bdd = boolCtx->getBDD(srs); + *actions_bdd = boolCtx->getBDDforContext(srs); } else { assert(0); diff --git a/stateconstr.cc b/stateconstr.cc index 9290ac6..a0d1170 100644 --- a/stateconstr.cc +++ b/stateconstr.cc @@ -46,14 +46,21 @@ std::string StateConstr::toStr(void) const BDD StateConstr::getBDDforState(const SymRS *srs) const { - assert(0); - // return BDD_FALSE; + return getBDD(srs, false); } BDD StateConstr::getBDDforContext(const SymRS *srs) const +{ + return getBDD(srs, true); +} + +BDD StateConstr::getBDD(const SymRS *srs, bool encode_context) const { if (oper == STC_PV) { - return srs->encActStrEntity(proc_name, entity_name); + if (encode_context) + return srs->encActStrEntity(proc_name, entity_name); + else + return srs->encEntity(proc_name, entity_name); } else if (oper == STC_TF) { if (tf) { @@ -64,20 +71,20 @@ BDD StateConstr::getBDDforContext(const SymRS *srs) const } } else if (oper == STC_AND) { - return arg[0]->getBDD(srs) * arg[1]->getBDD(srs); + return arg[0]->getBDD(srs, encode_context) * arg[1]->getBDD(srs, encode_context); } else if (oper == STC_OR) { - return arg[0]->getBDD(srs) + arg[1]->getBDD(srs); + return arg[0]->getBDD(srs, encode_context) + arg[1]->getBDD(srs, encode_context); } else if (oper == STC_XOR) { - return arg[0]->getBDD(srs) ^ arg[1]->getBDD(srs); + return arg[0]->getBDD(srs, encode_context) ^ arg[1]->getBDD(srs, encode_context); } else if (oper == STC_NOT) { - return !arg[0]->getBDD(srs); + return !arg[0]->getBDD(srs, encode_context); } else { assert(0); - FERROR("Undefined operator used in Boolean context definition. This should not happen."); + FERROR("Undefined operator used in Boolean state/context definition. This should not happen."); return srs->getBDDfalse(); } } diff --git a/stateconstr.hh b/stateconstr.hh index 9b60f2d..482f94c 100644 --- a/stateconstr.hh +++ b/stateconstr.hh @@ -87,9 +87,7 @@ class StateConstr std::string toStr(void) const; - BDD getBDD(const SymRS *srs) const { - return getBDDforContext(srs); - } + BDD getBDD(const SymRS *srs, bool encode_context) const; BDD getBDDforContext(const SymRS *srs) const; BDD getBDDforState(const SymRS *srs) const; diff --git a/symrs.cc b/symrs.cc index b6cafbf..2f2c9aa 100644 --- a/symrs.cc +++ b/symrs.cc @@ -5,6 +5,7 @@ #include "symrs.hh" #include "rs.hh" +#include "stateconstr.hh" #include "bdd_macro.hh" SymRS::SymRS(RctSys *rs, Options *opts) @@ -822,7 +823,7 @@ void SymRS::encodeTransitions(void) if (usingContextAutomaton()) { VERB("Augmenting transition relation encoding with the transition relation for context automaton"); - if (opts->part_tr_rel) { + if (opts->part_tr_rel) { auto last_index = numberOfProc; (*partTrans)[last_index] = *tr_ca; } @@ -946,8 +947,8 @@ void SymRS::encodeCtxAutTrans(void) BDD enc_src = encCtxAutState(t.src_state); BDD enc_dst = encCtxAutStateSucc(t.dst_state); BDD enc_ctx = compContext(encContext(t.ctx)); - - BDD new_trans = enc_src * enc_ctx * enc_dst; + BDD enc_drs_state = t.state_constr->getBDDforState(this); + BDD new_trans = enc_src * enc_drs_state * enc_ctx * enc_dst; *tr_ca += new_trans; } From 9dc03f8abc3738f45164a3d31be262fab45cd275 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 7 Oct 2018 21:56:48 +0100 Subject: [PATCH 54/90] Fixed nullptr deref when there is no state constraint --- symrs.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/symrs.cc b/symrs.cc index 2f2c9aa..a17e661 100644 --- a/symrs.cc +++ b/symrs.cc @@ -947,7 +947,10 @@ void SymRS::encodeCtxAutTrans(void) BDD enc_src = encCtxAutState(t.src_state); BDD enc_dst = encCtxAutStateSucc(t.dst_state); BDD enc_ctx = compContext(encContext(t.ctx)); - BDD enc_drs_state = t.state_constr->getBDDforState(this); + BDD enc_drs_state = BDD_TRUE; + if (t.state_constr != nullptr) { + enc_drs_state = t.state_constr->getBDDforState(this); + } BDD new_trans = enc_src * enc_drs_state * enc_ctx * enc_dst; *tr_ca += new_trans; From 96b02781360637ee26c1e1119655c81af1cde510 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 8 Oct 2018 21:01:39 +0100 Subject: [PATCH 55/90] Progressive eca construction --- ctx_aut.cc | 37 +++++++++++++++++++++++++++++++++++++ ctx_aut.hh | 1 + stateconstr.cc | 22 ++++++++++++++++++++++ stateconstr.hh | 3 +++ symrs.cc | 6 ++++++ 5 files changed, 69 insertions(+) diff --git a/ctx_aut.cc b/ctx_aut.cc index d095f9f..b581690 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -127,4 +127,41 @@ void CtxAut::showTransitions(void) } } +void CtxAut::makeProgressive(void) +{ + std::string special_loc = "T"; + while (hasState(special_loc)) + { + special_loc += "T"; + } + addState(special_loc); + + std::map constrs; + for (State s = 0; s < states_ids.size(); ++s) + { + if (constrs.count(s) == 0) { + constrs[s] = new StateConstr(false); + } + } + + for (const auto &t : transitions) { + State curr_st = t.src_state; + if (t.state_constr != nullptr) + { + constrs[curr_st] = new StateConstr( + STC_OR, constrs[curr_st], t.state_constr); + } + } + + for (const auto &s : states_ids) + { + StateConstr *state_constr = nullptr; + if (!constrs[getStateID(s)]->isFalse()) { + state_constr = new StateConstr(STC_NOT, constrs[getStateID(s)]); + } + addTransition(s, special_loc, state_constr); + } + +} + /** EOF **/ diff --git a/ctx_aut.hh b/ctx_aut.hh index 66bb489..c413632 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -40,6 +40,7 @@ class CtxAut void showStates(void); void addTransition(std::string srcStateName, std::string dstStateName, StateConstr *stateConstr); void showTransitions(void); + void makeProgressive(void); void pushContextEntity(Entity entity_id); void saveCurrentContextSet(Process proc_id); void setOptions(Options *opts) diff --git a/stateconstr.cc b/stateconstr.cc index a0d1170..6aef1b8 100644 --- a/stateconstr.cc +++ b/stateconstr.cc @@ -88,3 +88,25 @@ BDD StateConstr::getBDD(const SymRS *srs, bool encode_context) const return srs->getBDDfalse(); } } + +bool StateConstr::isFalse(void) const +{ + if (oper == STC_TF && tf == false) + return true; + + if (oper == STC_NOT && arg[0]->oper == STC_TF && arg[0]->tf == true) + return true; + + return false; +} + +bool StateConstr::isTrue(void) const +{ + if (oper == STC_TF && tf == true) + return true; + + if (oper == STC_NOT && arg[0]->oper == STC_TF && arg[0]->tf == false) + return true; + + return false; +} diff --git a/stateconstr.hh b/stateconstr.hh index 482f94c..21b42ae 100644 --- a/stateconstr.hh +++ b/stateconstr.hh @@ -107,6 +107,9 @@ class StateConstr assert(arg[1] != nullptr); return arg[1]; } + + bool isFalse(void) const; + bool isTrue(void) const; }; #endif diff --git a/symrs.cc b/symrs.cc index a17e661..d05808c 100644 --- a/symrs.cc +++ b/symrs.cc @@ -34,6 +34,12 @@ SymRS::SymRS(RctSys *rs, Options *opts) pv_ca_succ = nullptr; tr_ca = nullptr; + // TODO: this should be triggered by the parser and it should depend + // on an option in the input file + rs->ctx_aut->makeProgressive(); + + rs->printSystem(); + encode(); } From e4ab5999aa5874733fb3c60dd1ba993e865a3814 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 13 Oct 2018 21:00:06 +0100 Subject: [PATCH 56/90] Make Progressive as option --- rs.cc | 11 +++++++++ rs.hh | 4 +++ rsin_driver.cc | 15 +++++++++++ rsin_driver.hh | 4 +-- rsin_parser.ll | 2 +- rsin_parser.yy | 67 +++++++++++++++++++++++++++----------------------- symrs.cc | 4 --- 7 files changed, 69 insertions(+), 38 deletions(-) diff --git a/rs.cc b/rs.cc index 67f734f..b3220e4 100644 --- a/rs.cc +++ b/rs.cc @@ -9,6 +9,7 @@ RctSys::RctSys(void) : current_process_defined(false) { ctx_aut = nullptr; + gen_ctxaut_progressive_closure = false; } bool RctSys::hasEntity(std::string name) @@ -306,6 +307,11 @@ void RctSys::ctxAutEnable(void) ctx_aut = new CtxAut(opts, this); } +void RctSys::ctxAutEnableProgressiveClosure(void) +{ + gen_ctxaut_progressive_closure = true; +} + void RctSys::ctxAutAddState(std::string stateName) { assert(ctx_aut != nullptr); @@ -355,4 +361,9 @@ void RctSys::ctxAutSaveCurrentContextSet(std::string processName) ctx_aut->saveCurrentContextSet(processID); } +void RctSys::ctxAutFinalise(void) +{ + ctx_aut->makeProgressive(); +} + /** EOF **/ diff --git a/rs.hh b/rs.hh index 66389f2..e872da3 100644 --- a/rs.hh +++ b/rs.hh @@ -85,12 +85,14 @@ class RctSys void printSystem(void); void ctxAutEnable(void); + void ctxAutEnableProgressiveClosure(void); void ctxAutAddState(std::string stateName); void ctxAutSetInitState(std::string stateName); void ctxAutAddTransition(std::string srcStateName, std::string dstStateName); void ctxAutAddTransition(std::string srcStateName, std::string dstStateName, StateConstr *stateConstr); void ctxAutPushNamedContextEntity(std::string entity_name); void ctxAutSaveCurrentContextSet(std::string processName); + void ctxAutFinalise(void); bool initStatesDefined(void) { @@ -116,6 +118,8 @@ class RctSys CtxAut *ctx_aut; + bool gen_ctxaut_progressive_closure; + EntitiesById entities_ids; EntitiesByName entities_names; diff --git a/rsin_driver.cc b/rsin_driver.cc index 66c8403..4cb70b8 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -22,6 +22,7 @@ void rsin_driver::initialise(void) opts = nullptr; use_ctx_aut = false; use_concentrations = false; + use_progressive = false; } rsin_driver::~rsin_driver () @@ -106,3 +107,17 @@ void rsin_driver::useContextAutomaton(void) getReactionSystem()->ctxAutEnable(); } +void rsin_driver::makeProgressive(void) +{ + use_progressive = true; + if (use_ctx_aut) + { + getReactionSystem()->ctxAutEnableProgressiveClosure(); + } + else + { + FERROR("Context automaton not enabled"); + } +} + +// EOF diff --git a/rsin_driver.hh b/rsin_driver.hh index 381c3c4..a0c0c8a 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -35,6 +35,7 @@ class rsin_driver // options in configuration file: bool use_ctx_aut; bool use_concentrations; + bool use_progressive; // Handling the scanner void scan_begin(); @@ -60,7 +61,7 @@ class rsin_driver ensureOptionsAllowed(); use_concentrations = true; }; - + void makeProgressive(void); void ensureReactionSystemReady(void); void setupReactionSystem(void); @@ -78,4 +79,3 @@ class rsin_driver }; #endif - diff --git a/rsin_parser.ll b/rsin_parser.ll index 3750a72..668a117 100644 --- a/rsin_parser.ll +++ b/rsin_parser.ll @@ -41,6 +41,7 @@ blank [ \t] "options" return token::OPTIONS; "use-context-automaton" return token::USE_CTX_AUT; "use-concentrations" return token::USE_CONCENTRATIONS; +"make-progressive" return token::MAKE_PROGRESSIVE; "reactions" return token::REACTIONS; "initial-contexts" return token::INITIALCONTEXTS; "context-entities" return token::CONTEXTENTITIES; @@ -128,4 +129,3 @@ rsin_driver::scan_end() { fclose(yyin); } - diff --git a/rsin_parser.yy b/rsin_parser.yy index c87bbff..3d1f688 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -46,7 +46,7 @@ class rsin_driver; #include "rsin_driver.hh" } -%token OPTIONS USE_CTX_AUT USE_CONCENTRATIONS +%token OPTIONS USE_CTX_AUT USE_CONCENTRATIONS MAKE_PROGRESSIVE %token REACTIONS INITIALCONTEXTS CONTEXTENTITIES RSCTLKFORM %token CONTEXTAUTOMATON STATES INITSTATE TRANSITIONS %token EQ LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL DOT COMMA RARR @@ -77,34 +77,40 @@ class rsin_driver; %start system; -system: +system: | OPTIONS LCB options RCB system - | REACTIONS LCB reactionsets RCB system - | INITIALCONTEXTS LCB initstates RCB system - | CONTEXTENTITIES LCB actionentities RCB system + | REACTIONS LCB reactionsets RCB system + | INITIALCONTEXTS LCB initstates RCB system + | CONTEXTENTITIES LCB actionentities RCB system | CONTEXTAUTOMATON LCB ctxaut RCB system - | RSCTLKFORM LCB IDENTIFIER COL rsctlk_form RCB system { - driver.addFormRSCTLK(*$3, $5); - free($3); - } - ; + { + driver.getReactionSystem()->ctxAutFinalise(); + } + | RSCTLKFORM LCB IDENTIFIER COL rsctlk_form RCB system { + driver.addFormRSCTLK(*$3, $5); + free($3); + } + ; options: | options option SEMICOL ; option: - | USE_CTX_AUT { - driver.useContextAutomaton(); + | USE_CTX_AUT { + driver.useContextAutomaton(); } | USE_CONCENTRATIONS { driver.useConcentrations(); } + | MAKE_PROGRESSIVE { + driver.makeProgressive(); + } ; -/* +/* * ------------------------- - * REACTIONS + * REACTIONS * ------------------------- */ @@ -113,11 +119,11 @@ reactionsets: ; process_reactions: processname LCB reactions RCB SEMICOL - + processname: IDENTIFIER { driver.getReactionSystem()->setCurrentProcess(*$1); free($1); - } + } reactions: | reactions reaction SEMICOL @@ -146,7 +152,7 @@ reactant: IDENTIFIER { inhibitors: inhibitor - | inhibitors COMMA inhibitor + | inhibitors COMMA inhibitor ; inhibitor: @@ -180,7 +186,7 @@ initstates: initstate: | entity - | initstate COMMA entity + | initstate COMMA entity ; entity: IDENTIFIER { @@ -191,7 +197,7 @@ entity: IDENTIFIER { /*******************************************/ -actionentities: +actionentities: | actentity | actionentities COMMA actentity ; @@ -201,7 +207,7 @@ actentity: IDENTIFIER { free($1); } ; - + /*******************************************/ ctxaut: @@ -226,11 +232,11 @@ autinitstate: IDENTIFIER { free($1); } ; - + auttransitions: | auttrans | auttrans SEMICOL auttransitions - ; + ; auttrans: LCB proc_ctxsets RCB COL IDENTIFIER RARR IDENTIFIER { driver.getReactionSystem()->ctxAutAddTransition(*$5, *$7); @@ -243,22 +249,22 @@ auttrans: LCB proc_ctxsets RCB COL IDENTIFIER RARR IDENTIFIER { free($7); } ; - + proc_ctxsets: | proc_ctxsets single_proc_ctxset ; - + single_proc_ctxset: IDENTIFIER EQ LCB contextset RCB { driver.getReactionSystem()->ctxAutSaveCurrentContextSet(*$1); free($1); } ; - + contextset: | ctxentity | contextset COMMA ctxentity ; - + ctxentity: IDENTIFIER { driver.getReactionSystem()->ctxAutPushNamedContextEntity(*$1); free($1); @@ -266,7 +272,7 @@ ctxentity: IDENTIFIER { ; /* formulae */ - + state_constr: IDENTIFIER DOT IDENTIFIER { $$ = new StateConstr(*$1, *$3); free($1); @@ -324,7 +330,7 @@ state_constr: IDENTIFIER DOT IDENTIFIER { // } // ; -rsctlk_form: +rsctlk_form: IDENTIFIER DOT IDENTIFIER { $$ = new FormRSCTLK(*$1, *$3); free($1); @@ -371,7 +377,7 @@ rsctlk_form: } | AG rsctlk_form { $$ = new FormRSCTLK(RSCTLK_AG, $2); - } + } | UK LSB IDENTIFIER RSB LRB rsctlk_form RRB { Agents_f agents; agents.insert(*$3); @@ -411,7 +417,7 @@ rsctlk_form: // } /* contexts as boolean formulae */ - | E LAB state_constr RAB X rsctlk_form { + | E LAB state_constr RAB X rsctlk_form { $$ = new FormRSCTLK(RSCTLK_EX_ACT, $3, $6); } | E LAB state_constr RAB U LRB rsctlk_form COMMA rsctlk_form RRB { @@ -443,4 +449,3 @@ yy::rsin_parser::error(const yy::rsin_parser::location_type &l, const std::strin { driver.error(l, m); } - diff --git a/symrs.cc b/symrs.cc index d05808c..235bd1f 100644 --- a/symrs.cc +++ b/symrs.cc @@ -34,12 +34,8 @@ SymRS::SymRS(RctSys *rs, Options *opts) pv_ca_succ = nullptr; tr_ca = nullptr; - // TODO: this should be triggered by the parser and it should depend - // on an option in the input file rs->ctx_aut->makeProgressive(); - rs->printSystem(); - encode(); } From e098bcb42b56fd1ac59d60a3ef363acaf774c673 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 13 Oct 2018 21:03:27 +0100 Subject: [PATCH 57/90] use_ -> make_ --- rsin_driver.cc | 4 ++-- rsin_driver.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rsin_driver.cc b/rsin_driver.cc index 4cb70b8..374f9b7 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -22,7 +22,7 @@ void rsin_driver::initialise(void) opts = nullptr; use_ctx_aut = false; use_concentrations = false; - use_progressive = false; + make_progressive = false; } rsin_driver::~rsin_driver () @@ -109,7 +109,7 @@ void rsin_driver::useContextAutomaton(void) void rsin_driver::makeProgressive(void) { - use_progressive = true; + make_progressive = true; if (use_ctx_aut) { getReactionSystem()->ctxAutEnableProgressiveClosure(); diff --git a/rsin_driver.hh b/rsin_driver.hh index a0c0c8a..7661ff9 100644 --- a/rsin_driver.hh +++ b/rsin_driver.hh @@ -35,7 +35,7 @@ class rsin_driver // options in configuration file: bool use_ctx_aut; bool use_concentrations; - bool use_progressive; + bool make_progressive; // Handling the scanner void scan_begin(); From a976813c4866aece57ae5df7811548231bec7410 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 13 Oct 2018 22:04:58 +0100 Subject: [PATCH 58/90] TGC --- in/tgc.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 in/tgc.rs diff --git a/in/tgc.rs b/in/tgc.rs new file mode 100644 index 0000000..924e331 --- /dev/null +++ b/in/tgc.rs @@ -0,0 +1,48 @@ + +options { use-context-automaton; } +reactions { + + proc0 { + {{out}, {} -> {approach}}; + {{approach}, {req} -> {req}}; + {{allowed}, {} -> {in}}; + {{in}, {} -> {out,leave}}; + {{req}, {in} -> {req}}; + }; + + proc1 { + {{out}, {} -> {approach}}; + {{approach}, {req} -> {req}}; + {{allowed}, {} -> {in}}; + {{in}, {} -> {out,leave}}; + {{req}, {in} -> {req}}; + }; + + proc2 { + {{out}, {} -> {approach}}; + {{approach}, {req} -> {req}}; + {{allowed}, {} -> {in}}; + {{in}, {} -> {out,leave}}; + {{req}, {in} -> {req}}; + }; +} + +context-automaton { + states { init, green, red } + init-state { init } + transitions { + { proc0={out} proc1={out} proc2={out} }: init -> green; + { proc0={} proc1={} proc2={} }: green -> green : ~proc0.req AND ~proc1.req AND ~proc2.req; + { proc0={allowed} }: green -> red : proc0.req; + { proc1={allowed} }: green -> red : proc1.req; + { proc2={allowed} }: green -> red : proc2.req; + { proc0={} }: red -> green : proc0.leave; + { proc1={} }: red -> green : proc1.leave; + { proc2={} }: red -> green : proc2.leave; + { proc0={} proc1={} proc2={} } : red -> red : ~proc0.leave AND ~proc1.leave AND ~proc2.leave; + } +} + +rsctlk-property { f1 : EF( proc0.in ) AND EF( proc1.in ) AND EF( proc2.in ) } + +rsctlk-property { f2 : AG( proc0.in IMPLIES K[proc0](~proc1.in AND ~proc2.in) ) } From 24f783c6a809f8cfd3513fdd87df5577bb7d3b2f Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 14 Oct 2018 16:14:44 +0100 Subject: [PATCH 59/90] TGC generator (with controller as context automaton) --- in/gen_tgc_sc.py | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 in/gen_tgc_sc.py diff --git a/in/gen_tgc_sc.py b/in/gen_tgc_sc.py new file mode 100755 index 0000000..c7120de --- /dev/null +++ b/in/gen_tgc_sc.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python + +from sys import argv,exit + +OPTIONS_STR = """ +options { use-context-automaton; } +""" + +PROC_STR = """ + proc{:d} {{ + {{{{out}}, {{}} -> {{approach}}}}; + {{{{approach}}, {{req}} -> {{req}}}}; + {{{{allowed}}, {{}} -> {{in}}}}; + {{{{in}}, {{}} -> {{out,leave}}}}; + {{{{req}}, {{in}} -> {{req}}}}; + }}; +""" + +CA_STR = """ +context-automaton {{ + states {{ init, green, red }} + init-state {{ init }} + transitions {{ +{:s} + }} +}} +""" + +PROPERTY_STR = """ +rsctlk-property {{ {:s} : {:s} }} +""" + + +################################################################# + +if len(argv) < 1: + print("Usage: {:s} ".format(argv[0])) + exit(100) + +n = int(argv[1]) + +assert n > 1, "number of proc must be > 1" + +out = "" + +out += OPTIONS_STR +out += "reactions {\n" +for i in range(n): + out += PROC_STR.format(i) +out += "}\n" + +transitions = "" + +init_trans = 8*" " + "{ " +for i in range(n): + init_trans += "proc{:d}={{out}} ".format(i) + +init_trans += "}: init -> green;\n" + +transitions += init_trans + +green_no_change_trans = 8*" " + "{ " +for i in range(n): + green_no_change_trans += "proc{:d}={{}} ".format(i) +green_no_change_trans += "}: green -> green : ~proc0.req" +for i in range(1, n): + green_no_change_trans += " AND ~proc{:d}.req".format(i) +green_no_change_trans += ";\n" + +transitions += green_no_change_trans + +for i in range(n): + transitions += "{:s}{{ proc{:d}={{allowed}} }}: green -> red : proc{:d}.req;\n".format(8*" ", i, i) + +for i in range(n): + transitions += "{:s}{{ proc{:d}={{}} }}: red -> green : proc{:d}.leave;\n".format(8*" ", i, i) + +red_no_change_trans = 8*" " + "{ " +for i in range(n): + red_no_change_trans += "proc{:d}={{}} ".format(i) +red_no_change_trans += "}: red -> red : ~proc0.leave" +for i in range(1, n): + red_no_change_trans += " AND ~proc{:d}.leave".format(i) +red_no_change_trans += ";\n" + +transitions += red_no_change_trans + +out += CA_STR.format(transitions) + +# f1 +formula = "EF( proc0.in )" +for i in range(1, n): + formula += " AND EF( proc{:d}.in )".format(i) +out += PROPERTY_STR.format("f1",formula) + +# f2 +subf = "~proc1.in" +for i in range(2, n): + subf += " AND ~proc{:d}.in".format(i) +formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) + +out += PROPERTY_STR.format("f2",formula) + +print(out) From b3d58504b462d294b49de9cd1c5ca279c3862044 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 14 Oct 2018 16:15:34 +0100 Subject: [PATCH 60/90] TGC generator (with controller as context automaton) --- in/gen_tgc_sc.py | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 in/gen_tgc_sc.py diff --git a/in/gen_tgc_sc.py b/in/gen_tgc_sc.py new file mode 100755 index 0000000..c7120de --- /dev/null +++ b/in/gen_tgc_sc.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python + +from sys import argv,exit + +OPTIONS_STR = """ +options { use-context-automaton; } +""" + +PROC_STR = """ + proc{:d} {{ + {{{{out}}, {{}} -> {{approach}}}}; + {{{{approach}}, {{req}} -> {{req}}}}; + {{{{allowed}}, {{}} -> {{in}}}}; + {{{{in}}, {{}} -> {{out,leave}}}}; + {{{{req}}, {{in}} -> {{req}}}}; + }}; +""" + +CA_STR = """ +context-automaton {{ + states {{ init, green, red }} + init-state {{ init }} + transitions {{ +{:s} + }} +}} +""" + +PROPERTY_STR = """ +rsctlk-property {{ {:s} : {:s} }} +""" + + +################################################################# + +if len(argv) < 1: + print("Usage: {:s} ".format(argv[0])) + exit(100) + +n = int(argv[1]) + +assert n > 1, "number of proc must be > 1" + +out = "" + +out += OPTIONS_STR +out += "reactions {\n" +for i in range(n): + out += PROC_STR.format(i) +out += "}\n" + +transitions = "" + +init_trans = 8*" " + "{ " +for i in range(n): + init_trans += "proc{:d}={{out}} ".format(i) + +init_trans += "}: init -> green;\n" + +transitions += init_trans + +green_no_change_trans = 8*" " + "{ " +for i in range(n): + green_no_change_trans += "proc{:d}={{}} ".format(i) +green_no_change_trans += "}: green -> green : ~proc0.req" +for i in range(1, n): + green_no_change_trans += " AND ~proc{:d}.req".format(i) +green_no_change_trans += ";\n" + +transitions += green_no_change_trans + +for i in range(n): + transitions += "{:s}{{ proc{:d}={{allowed}} }}: green -> red : proc{:d}.req;\n".format(8*" ", i, i) + +for i in range(n): + transitions += "{:s}{{ proc{:d}={{}} }}: red -> green : proc{:d}.leave;\n".format(8*" ", i, i) + +red_no_change_trans = 8*" " + "{ " +for i in range(n): + red_no_change_trans += "proc{:d}={{}} ".format(i) +red_no_change_trans += "}: red -> red : ~proc0.leave" +for i in range(1, n): + red_no_change_trans += " AND ~proc{:d}.leave".format(i) +red_no_change_trans += ";\n" + +transitions += red_no_change_trans + +out += CA_STR.format(transitions) + +# f1 +formula = "EF( proc0.in )" +for i in range(1, n): + formula += " AND EF( proc{:d}.in )".format(i) +out += PROPERTY_STR.format("f1",formula) + +# f2 +subf = "~proc1.in" +for i in range(2, n): + subf += " AND ~proc{:d}.in".format(i) +formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) + +out += PROPERTY_STR.format("f2",formula) + +print(out) From 7b15c50803603f60f5c14a14964f999c461ff6e6 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 14 Oct 2018 16:20:23 +0100 Subject: [PATCH 61/90] Scripts --- in/{ => scripts}/bench_bc.sh | 0 in/{ => scripts}/bench_mutex.sh | 0 in/{ => scripts}/bench_pipe.sh | 0 in/{ => scripts}/benchmark.sh | 0 in/{ => scripts}/benchmark_abs1.sh | 0 in/{ => scripts}/benchmark_abs1_PT.sh | 0 in/{ => scripts}/benchmark_bc.sh | 0 in/{ => scripts}/benchmark_mutex.sh | 0 in/{ => scripts}/benchmark_mutex_PT.sh | 0 in/{ => scripts}/gen_abstract1.py | 0 in/{ => scripts}/gen_bc.py | 0 in/{ => scripts}/gen_drs_mutex.py | 0 in/{ => scripts}/gen_mutex.py | 0 in/{ => scripts}/gen_tgc_sc.py | 0 in/{ => scripts}/get_results.sh | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename in/{ => scripts}/bench_bc.sh (100%) rename in/{ => scripts}/bench_mutex.sh (100%) rename in/{ => scripts}/bench_pipe.sh (100%) rename in/{ => scripts}/benchmark.sh (100%) rename in/{ => scripts}/benchmark_abs1.sh (100%) rename in/{ => scripts}/benchmark_abs1_PT.sh (100%) rename in/{ => scripts}/benchmark_bc.sh (100%) rename in/{ => scripts}/benchmark_mutex.sh (100%) rename in/{ => scripts}/benchmark_mutex_PT.sh (100%) rename in/{ => scripts}/gen_abstract1.py (100%) rename in/{ => scripts}/gen_bc.py (100%) rename in/{ => scripts}/gen_drs_mutex.py (100%) rename in/{ => scripts}/gen_mutex.py (100%) rename in/{ => scripts}/gen_tgc_sc.py (100%) rename in/{ => scripts}/get_results.sh (100%) diff --git a/in/bench_bc.sh b/in/scripts/bench_bc.sh similarity index 100% rename from in/bench_bc.sh rename to in/scripts/bench_bc.sh diff --git a/in/bench_mutex.sh b/in/scripts/bench_mutex.sh similarity index 100% rename from in/bench_mutex.sh rename to in/scripts/bench_mutex.sh diff --git a/in/bench_pipe.sh b/in/scripts/bench_pipe.sh similarity index 100% rename from in/bench_pipe.sh rename to in/scripts/bench_pipe.sh diff --git a/in/benchmark.sh b/in/scripts/benchmark.sh similarity index 100% rename from in/benchmark.sh rename to in/scripts/benchmark.sh diff --git a/in/benchmark_abs1.sh b/in/scripts/benchmark_abs1.sh similarity index 100% rename from in/benchmark_abs1.sh rename to in/scripts/benchmark_abs1.sh diff --git a/in/benchmark_abs1_PT.sh b/in/scripts/benchmark_abs1_PT.sh similarity index 100% rename from in/benchmark_abs1_PT.sh rename to in/scripts/benchmark_abs1_PT.sh diff --git a/in/benchmark_bc.sh b/in/scripts/benchmark_bc.sh similarity index 100% rename from in/benchmark_bc.sh rename to in/scripts/benchmark_bc.sh diff --git a/in/benchmark_mutex.sh b/in/scripts/benchmark_mutex.sh similarity index 100% rename from in/benchmark_mutex.sh rename to in/scripts/benchmark_mutex.sh diff --git a/in/benchmark_mutex_PT.sh b/in/scripts/benchmark_mutex_PT.sh similarity index 100% rename from in/benchmark_mutex_PT.sh rename to in/scripts/benchmark_mutex_PT.sh diff --git a/in/gen_abstract1.py b/in/scripts/gen_abstract1.py similarity index 100% rename from in/gen_abstract1.py rename to in/scripts/gen_abstract1.py diff --git a/in/gen_bc.py b/in/scripts/gen_bc.py similarity index 100% rename from in/gen_bc.py rename to in/scripts/gen_bc.py diff --git a/in/gen_drs_mutex.py b/in/scripts/gen_drs_mutex.py similarity index 100% rename from in/gen_drs_mutex.py rename to in/scripts/gen_drs_mutex.py diff --git a/in/gen_mutex.py b/in/scripts/gen_mutex.py similarity index 100% rename from in/gen_mutex.py rename to in/scripts/gen_mutex.py diff --git a/in/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py similarity index 100% rename from in/gen_tgc_sc.py rename to in/scripts/gen_tgc_sc.py diff --git a/in/get_results.sh b/in/scripts/get_results.sh similarity index 100% rename from in/get_results.sh rename to in/scripts/get_results.sh From 76a64505831d428a604187efcc42aee943ec4b96 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 14 Oct 2018 16:23:36 +0100 Subject: [PATCH 62/90] perms --- in/scripts/gen_abstract1.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 in/scripts/gen_abstract1.py diff --git a/in/scripts/gen_abstract1.py b/in/scripts/gen_abstract1.py old mode 100644 new mode 100755 From e0603b3c9deafb21c943c86e18c2f83008fbad30 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 14 Oct 2018 16:38:02 +0100 Subject: [PATCH 63/90] Merge branch 'distrib_rs' of bitbucket.org:rsmodecking/rsmc into distrib_rs --- drs_benchmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index 05edb14..0ae9a41 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -7,7 +7,7 @@ CMD="./reactics -zxbB" for i in `seq 2 9`;do echo "[i] n=$i; generating input file" - in/gen_drs_mutex.py $i > $TMPINPUT + in/gen_tgc_sc.py $i > $TMPINPUT for f in `seq 1 2`; do From cd95f86fe54857199eb0603d560e980cfb5811c2 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 14 Oct 2018 16:39:44 +0100 Subject: [PATCH 64/90] scr --- drs_benchmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index 0ae9a41..fd30f9e 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -7,7 +7,7 @@ CMD="./reactics -zxbB" for i in `seq 2 9`;do echo "[i] n=$i; generating input file" - in/gen_tgc_sc.py $i > $TMPINPUT + in/scripts/gen_tgc_sc.py $i > $TMPINPUT for f in `seq 1 2`; do From 134646308e058a1c069cf2d30a551da7d76ea3e2 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 20 Oct 2018 16:36:32 +0100 Subject: [PATCH 65/90] Updated script --- in/scripts/gen_tgc_sc.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index c7120de..a49911a 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -54,36 +54,28 @@ transitions = "" init_trans = 8*" " + "{ " for i in range(n): init_trans += "proc{:d}={{out}} ".format(i) - init_trans += "}: init -> green;\n" - transitions += init_trans -green_no_change_trans = 8*" " + "{ " -for i in range(n): - green_no_change_trans += "proc{:d}={{}} ".format(i) -green_no_change_trans += "}: green -> green : ~proc0.req" -for i in range(1, n): - green_no_change_trans += " AND ~proc{:d}.req".format(i) -green_no_change_trans += ";\n" - -transitions += green_no_change_trans - for i in range(n): transitions += "{:s}{{ proc{:d}={{allowed}} }}: green -> red : proc{:d}.req;\n".format(8*" ", i, i) +no_req_cond = "~proc0.req" +for i in range(1, n): + no_req_cond += " AND ~proc{:d}.req".format(i) + +for i in range(n): + transitions += "{:s}{{ proc{:d}={{}} }}: green -> green : {:s};\n".format(8*" ", i, no_req_cond) + for i in range(n): transitions += "{:s}{{ proc{:d}={{}} }}: red -> green : proc{:d}.leave;\n".format(8*" ", i, i) -red_no_change_trans = 8*" " + "{ " -for i in range(n): - red_no_change_trans += "proc{:d}={{}} ".format(i) -red_no_change_trans += "}: red -> red : ~proc0.leave" +no_leave_cond = "~proc0.leave" for i in range(1, n): - red_no_change_trans += " AND ~proc{:d}.leave".format(i) -red_no_change_trans += ";\n" + no_leave_cond += " AND ~proc{:d}.leave".format(i) -transitions += red_no_change_trans +for i in range(n): + transitions += "{:s}{{ proc{:d}={{}} }}: red -> red : {:s};\n".format(8*" ", i, no_leave_cond) out += CA_STR.format(transitions) From b0f24e26db0b30cfc9301f039468b6575e42e4b5 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 20 Oct 2018 21:26:01 +0100 Subject: [PATCH 66/90] Reordering, verbosity --- symrs.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/symrs.cc b/symrs.cc index 235bd1f..ebf8ec3 100644 --- a/symrs.cc +++ b/symrs.cc @@ -34,8 +34,6 @@ SymRS::SymRS(RctSys *rs, Options *opts) pv_ca_succ = nullptr; tr_ca = nullptr; - rs->ctx_aut->makeProgressive(); - encode(); } @@ -925,7 +923,7 @@ BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const BDD SymRS::getEncCtxAutInitState(void) { - VERB_LN(2, "Encoding context automaton's initial state"); + VERB_LN(1, "Encoding context automaton's initial state"); State state = rs->ctx_aut->getInitState(); @@ -934,7 +932,7 @@ BDD SymRS::getEncCtxAutInitState(void) void SymRS::encodeCtxAutTrans(void) { - VERB_LN(2, "Encoding context automaton's transition relation"); + VERB_LN(1, "Encoding context automaton's transition relation"); if (tr_ca != nullptr) { VERB_LN(1, "Encoding for context automaton already present, not replacing") @@ -956,6 +954,8 @@ void SymRS::encodeCtxAutTrans(void) BDD new_trans = enc_src * enc_drs_state * enc_ctx * enc_dst; *tr_ca += new_trans; + + reorder(); } } From 5a728f96ac939127ce513379f58c2c361087784b Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 20 Oct 2018 21:26:12 +0100 Subject: [PATCH 67/90] Progressiveness --- in/scripts/gen_tgc_sc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index a49911a..d132103 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -3,7 +3,7 @@ from sys import argv,exit OPTIONS_STR = """ -options { use-context-automaton; } +options { use-context-automaton; make-progressive; } """ PROC_STR = """ From 75007f04dd575b0f3f7e86b3192f5abe25fb11d7 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 20 Oct 2018 21:26:40 +0100 Subject: [PATCH 68/90] assertion for made_progressive --- ctx_aut.cc | 6 ++++++ ctx_aut.hh | 1 + 2 files changed, 7 insertions(+) diff --git a/ctx_aut.cc b/ctx_aut.cc index b581690..bd597bb 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -8,6 +8,7 @@ CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys) { setOptions(opts); this->parent_rctsys = parent_rctsys; + made_progressive = false; } bool CtxAut::hasState(std::string name) @@ -129,6 +130,9 @@ void CtxAut::showTransitions(void) void CtxAut::makeProgressive(void) { + VERB_LN(2, "Calculating progressive closure of CA"); + assert(!made_progressive); + std::string special_loc = "T"; while (hasState(special_loc)) { @@ -162,6 +166,8 @@ void CtxAut::makeProgressive(void) addTransition(s, special_loc, state_constr); } + made_progressive = true; + } /** EOF **/ diff --git a/ctx_aut.hh b/ctx_aut.hh index c413632..c80d475 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -62,6 +62,7 @@ class CtxAut EntitiesForProc tmpProcEntities; Entities tmpEntities; CtxAutTransitions transitions; + bool made_progressive; }; #endif /* RS_CTX_AUT_HH */ From 2088994fa73df3cc0ac8a10cdbb8eedafb042f1f Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 20 Oct 2018 22:41:45 +0100 Subject: [PATCH 69/90] Benchmarking script --- drs_benchmark.sh | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index fd30f9e..433e3f8 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -2,32 +2,45 @@ TMPINPUT="tmp_$RANDOM$RANDOM.rs" -CMD="./reactics -zxbB" +CMD="./reactics -bB" -for i in `seq 2 9`;do +for opt in "" "z" "x" "zx";do - echo "[i] n=$i; generating input file" - in/scripts/gen_tgc_sc.py $i > $TMPINPUT + for i in `seq 2 10`;do - for f in `seq 1 2`; do + echo "[i] n=$i; generating input file" + in/scripts/gen_tgc_sc.py $i > $TMPINPUT - echo "[i] Testing formula f$f" + for f in `seq 1 2`; do - TMPCMD="$CMD -c f$f $TMPINPUT" - echo "[i] running reactics: $TMPCMD" + echo "[i] Testing formula f$f" - res=$($TMPCMD | grep STAT) - mem=$(echo $res | cut -d';' -f 5) - time=$(echo $res | cut -d';' -f 6) + if [[ "$opt" = "" ]];then + opt_str="NoOpt" + CMDOPT="" + else + opt_str="$opt" + CMDOPT="-$opt" + fi - echo "[.] Finished. time:$time, mem:$mem" + TMPCMD="$CMD $CMDOPT -c f$f $TMPINPUT" + echo "[i] running reactics: $TMPCMD" - echo "$i $time $mem" >> bench_drs_mutex_f$f.dat + res=$($TMPCMD | grep STAT) + mem=$(echo $res | cut -d';' -f 5) + time=$(echo $res | cut -d';' -f 6) - done + echo "[.] Finished. time:$time, mem:$mem" + + + echo "$i $time $mem" >> bench_drs_tgc_${opt_str}_f$f.dat + + done + + echo + + done - echo - done rm -f $TMPINPUT From 3faf00544580f6a2890b4aafc228b294546b885a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 22 Oct 2018 20:28:23 +0100 Subject: [PATCH 70/90] Script for TGC --- in/scripts/gen_tgc_sc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index d132103..7736d8c 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -93,4 +93,11 @@ formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) out += PROPERTY_STR.format("f2",formula) +# f3 +formula = "EF( proc0.approach" +for i in range(1, n): + formula += " AND proc{:d}.approach".format(i) +formula += " )" +out += PROPERTY_STR.format("f3",formula) + print(out) From eef037fd97dfb0022ad16c389ec8d4a7747d3d1d Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 22 Oct 2018 20:31:31 +0100 Subject: [PATCH 71/90] Reordering --- symrs.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/symrs.cc b/symrs.cc index ebf8ec3..53a261a 100644 --- a/symrs.cc +++ b/symrs.cc @@ -830,6 +830,7 @@ void SymRS::encodeTransitions(void) else { assert(tr_ca != nullptr); *monoTrans *= *tr_ca; + reorder(); } } } From 66f9e36c5dbedbc2c851203a887ba2f7f7bdb6ea Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 22 Oct 2018 20:54:09 +0100 Subject: [PATCH 72/90] Script --- drs_benchmark.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index 433e3f8..87760d6 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -2,16 +2,25 @@ TMPINPUT="tmp_$RANDOM$RANDOM.rs" -CMD="./reactics -bB" +CMD="./reactics -B" -for opt in "" "z" "x" "zx";do +timelimit="$((30*60))" # 30 minutes - for i in `seq 2 10`;do +for opt in "z" "zb" "x" "xz" "xzb" "xb" "" "b";do - echo "[i] n=$i; generating input file" - in/scripts/gen_tgc_sc.py $i > $TMPINPUT + for f in `seq 1 3`; do - for f in `seq 1 2`; do + done=0 + + for i in `seq 2 20`;do + + if [[ $done -eq 1 ]];then + echo "Skipping f=$f i=$i for $opt" + continue + fi + + echo "[i] n=$i; generating input file" + in/scripts/gen_tgc_sc.py $i > $TMPINPUT echo "[i] Testing formula f$f" @@ -26,13 +35,15 @@ for opt in "" "z" "x" "zx";do TMPCMD="$CMD $CMDOPT -c f$f $TMPINPUT" echo "[i] running reactics: $TMPCMD" - res=$($TMPCMD | grep STAT) + res=$(timeout $timelimit $TMPCMD | grep STAT) + if [[ $? -ne 0 ]];then + done=1 + fi mem=$(echo $res | cut -d';' -f 5) time=$(echo $res | cut -d';' -f 6) echo "[.] Finished. time:$time, mem:$mem" - echo "$i $time $mem" >> bench_drs_tgc_${opt_str}_f$f.dat done From ff0031244ea65d96e0a7ef377a0dc3472f25b6ec Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Mon, 5 Nov 2018 13:25:57 +0000 Subject: [PATCH 73/90] script --- in/scripts/gen_tgc_sc.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index 7736d8c..c60637b 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -81,16 +81,12 @@ out += CA_STR.format(transitions) # f1 formula = "EF( proc0.in )" -for i in range(1, n): - formula += " AND EF( proc{:d}.in )".format(i) out += PROPERTY_STR.format("f1",formula) # f2 -subf = "~proc1.in" -for i in range(2, n): - subf += " AND ~proc{:d}.in".format(i) -formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) - +formula = "EF( proc0.in )" +for i in range(1, n): + formula += " AND EF( proc{:d}.in )".format(i) out += PROPERTY_STR.format("f2",formula) # f3 @@ -100,4 +96,13 @@ for i in range(1, n): formula += " )" out += PROPERTY_STR.format("f3",formula) +# f4 +subf = "~proc1.in" +for i in range(2, n): + subf += " AND ~proc{:d}.in".format(i) +formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) + +out += PROPERTY_STR.format("f4",formula) + print(out) + From 34f7b503c1a3b1964cb4ae371bce1df2fee97cfa Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 24 Nov 2018 12:58:26 +0000 Subject: [PATCH 74/90] Common Knowledge operators support --- formrsctlk.cc | 11 +++++++++++ formrsctlk.hh | 7 ++++++- mc.cc | 29 +++++++++++++++++++++++++++++ mc.hh | 3 ++- rsin_parser.yy | 37 ++++++++++++++++++++++++++++--------- types.hh | 1 + 6 files changed, 77 insertions(+), 11 deletions(-) diff --git a/formrsctlk.cc b/formrsctlk.cc index 6921548..9260769 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -7,6 +7,7 @@ */ #include "formrsctlk.hh" +#include "rs.hh" std::string FormRSCTLK::toStr(void) const { @@ -250,3 +251,13 @@ void FormRSCTLK::encodeActions(const SymRS *srs) arg[1]->encodeActions(srs); } } + +ProcSet FormRSCTLK::getAgentsAsProcSet(RctSys *rs) const +{ + ProcSet processes; + for (auto &a : agents) + { + processes.insert(rs->getProcessID(a)); + } + return processes; +} diff --git a/formrsctlk.hh b/formrsctlk.hh index 474ea5f..add62c7 100644 --- a/formrsctlk.hh +++ b/formrsctlk.hh @@ -43,9 +43,13 @@ #define RSCTLK_TF 50 // true/false #define RSCTLK_NK 61 // Epistemic operators +#define RSCTLK_NE 62 +#define RSCTLK_NC 63 #define RSCTLK_UK 71 +#define RSCTLK_UE 72 +#define RSCTLK_UC 73 -#define RSCTLK_COND_1ARG(a) ((a) == RSCTLK_NOT || (a) == RSCTLK_EG || (a) == RSCTLK_EF || (a) == RSCTLK_EX || (a) == RSCTLK_AG || (a) == RSCTLK_AF || (a) == RSCTLK_AX || (a) == RSCTLK_EG_ACT || (a) == RSCTLK_EF_ACT || (a) == RSCTLK_EX_ACT || (a) == RSCTLK_AG_ACT || (a) == RSCTLK_AF_ACT || (a) == RSCTLK_AX_ACT || (a) == RSCTLK_UK || (a) == RSCTLK_NK) +#define RSCTLK_COND_1ARG(a) ((a) == RSCTLK_NOT || (a) == RSCTLK_EG || (a) == RSCTLK_EF || (a) == RSCTLK_EX || (a) == RSCTLK_AG || (a) == RSCTLK_AF || (a) == RSCTLK_AX || (a) == RSCTLK_EG_ACT || (a) == RSCTLK_EF_ACT || (a) == RSCTLK_EX_ACT || (a) == RSCTLK_AG_ACT || (a) == RSCTLK_AF_ACT || (a) == RSCTLK_AX_ACT || (a) == RSCTLK_UK || (a) == RSCTLK_NK || (a) == RSCTLK_UE || (a) == RSCTLK_NE || (a) == RSCTLK_UC || (a) == RSCTLK_NC) #define RSCTLK_COND_2ARG(a) ((a) == RSCTLK_AND || (a) == RSCTLK_OR || (a) == RSCTLK_XOR || (a) == RSCTLK_IMPL || (a) == RSCTLK_EU || (a) == RSCTLK_AU || (a) == RSCTLK_EU_ACT || (a) == RSCTLK_AU_ACT) #define RSCTLK_COND_ACT(a) ((a) > 30 && (a) < 45) #define RSCTLK_IS_VALID(a) (RSCTLK_COND_1ARG(a) || RSCTLK_COND_2ARG(a) || (a) == RSCTLK_PV || (a) == RSCTLK_TF) @@ -288,6 +292,7 @@ class FormRSCTLK assert(oper == RSCTLK_NK || oper == RSCTLK_UK); return *(agents.begin()); } + ProcSet getAgentsAsProcSet(RctSys *rs) const; }; #endif diff --git a/mc.cc b/mc.cc index 4d20649..1f443cf 100644 --- a/mc.cc +++ b/mc.cc @@ -359,6 +359,16 @@ BDD ModelChecker::getStatesRSCTLK(const FormRSCTLK *form) auto proc_id = srs->rs->getProcessID(form->getSingleAgent()); return *reach - (statesNK(*reach - getStatesRSCTLK(form->getLeftSF()), proc_id) * *reach); } + else if (oper == RSCTLK_NC) + { + auto proc_set = form->getAgentsAsProcSet(srs->rs); + return statesNC(getStatesRSCTLK(form->getLeftSF()) * *reach, proc_set) * *reach; + } + else if (oper == RSCTLK_UC) + { + auto proc_set = form->getAgentsAsProcSet(srs->rs); + return *reach - (statesNC(*reach - getStatesRSCTLK(form->getLeftSF()), proc_set) * *reach); + } assert(0); // Should never happen return BDD_FALSE; @@ -453,6 +463,25 @@ BDD ModelChecker::statesNK(const BDD &states, Process proc_id) return x; } +BDD ModelChecker::statesNC(const BDD &states, ProcSet processes) +{ + BDD x = BDD_FALSE; + BDD x_p = *reach; + + while (x != x_p) + { + x_p = x; + BDD t = BDD_FALSE; + for (auto const &proc_id : processes) + { + t += x.ExistAbstract(getIthOnly(proc_id)); + } + x = t; + } + + return x; +} + BDD ModelChecker::getIthOnly(Process proc_id) { /* if possible, we return the BDD from cache */ diff --git a/mc.hh b/mc.hh index 663d3bd..1274f61 100644 --- a/mc.hh +++ b/mc.hh @@ -61,13 +61,14 @@ class ModelChecker BDD statesEUctx(const BDD *contexts, const BDD &statesA, const BDD &statesB); BDD statesEFctx(const BDD *contexts, const BDD &states); BDD statesNK(const BDD &states, Process proc_id); + BDD statesNC(const BDD &states, ProcSet processes); BDD getIthOnly(Process proc_id); void cleanup(void); void reorder(void); - + public: ModelChecker(SymRS *srs, Options *opts); diff --git a/rsin_parser.yy b/rsin_parser.yy index 3d1f688..ebece8b 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -39,7 +39,8 @@ class rsin_driver; // Entity_f *ent; // Action_f *act; // ActionsVec_f *actionsVec; - StateConstr *fstc; + StateConstr *fstc; + Agents_f *agents; }; %code { @@ -67,6 +68,7 @@ class rsin_driver; // %type action // %type actions %type state_constr +%type agents; //%printer { yyoutput << *$$; } "identifier" %destructor { delete $$; } "identifier" @@ -330,6 +332,19 @@ state_constr: IDENTIFIER DOT IDENTIFIER { // } // ; +agents: + IDENTIFIER { + Agents_f *ag = new Agents_f; + ag->insert(*$1); + free($1); + $$ = ag; + } + | agents COMMA IDENTIFIER { + $1->insert(*$3); + free($3); + $$ = $1; + } + rsctlk_form: IDENTIFIER DOT IDENTIFIER { $$ = new FormRSCTLK(*$1, *$3); @@ -378,16 +393,20 @@ rsctlk_form: | AG rsctlk_form { $$ = new FormRSCTLK(RSCTLK_AG, $2); } - | UK LSB IDENTIFIER RSB LRB rsctlk_form RRB { - Agents_f agents; - agents.insert(*$3); - $$ = new FormRSCTLK(RSCTLK_UK, agents, $6); + | UK LSB agents RSB LRB rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_UK, *$3, $6); free($3); } - | NK LSB IDENTIFIER RSB LRB rsctlk_form RRB { - Agents_f agents; - agents.insert(*$3); - $$ = new FormRSCTLK(RSCTLK_NK, agents, $6); + | NK LSB agents RSB LRB rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_NK, *$3, $6); + free($3); + } + | UE LSB agents RSB LRB rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_UE, *$3, $6); + free($3); + } + | NE LSB agents RSB LRB rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_NE, *$3, $6); free($3); } diff --git a/types.hh b/types.hh index b49eb62..9d69bf7 100644 --- a/types.hh +++ b/types.hh @@ -30,6 +30,7 @@ struct Reaction { typedef unsigned int Process; typedef std::vector ProcessesById; typedef std::map ProcessesByName; +typedef std::set ProcSet; typedef std::vector Reactions; typedef std::map ReactionsForProc; From c72eb7ac4a60ea9bf4f0f0b49db9d25d39c4e4c2 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 24 Nov 2018 14:23:40 +0000 Subject: [PATCH 75/90] Everybody knows --- mc.cc | 20 ++++++++++++++++++++ mc.hh | 1 + rsin_parser.yy | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/mc.cc b/mc.cc index 1f443cf..c4a3173 100644 --- a/mc.cc +++ b/mc.cc @@ -359,6 +359,14 @@ BDD ModelChecker::getStatesRSCTLK(const FormRSCTLK *form) auto proc_id = srs->rs->getProcessID(form->getSingleAgent()); return *reach - (statesNK(*reach - getStatesRSCTLK(form->getLeftSF()), proc_id) * *reach); } + else if (oper == RSCTLK_NE) { + auto proc_set = form->getAgentsAsProcSet(srs->rs); + return statesNE(getStatesRSCTLK(form->getLeftSF()) * *reach, proc_set) * *reach; + } + else if (oper == RSCTLK_UE) { + auto proc_set = form->getAgentsAsProcSet(srs->rs); + return *reach - (statesNE(*reach - getStatesRSCTLK(form->getLeftSF()), proc_set) * *reach); + } else if (oper == RSCTLK_NC) { auto proc_set = form->getAgentsAsProcSet(srs->rs); @@ -463,6 +471,18 @@ BDD ModelChecker::statesNK(const BDD &states, Process proc_id) return x; } +BDD ModelChecker::statesNE(const BDD &states, ProcSet processes) +{ + BDD x = BDD_FALSE; + + for (auto const &proc_id : processes) + { + x += states.ExistAbstract(getIthOnly(proc_id)); + } + + return x; +} + BDD ModelChecker::statesNC(const BDD &states, ProcSet processes) { BDD x = BDD_FALSE; diff --git a/mc.hh b/mc.hh index 1274f61..a331bb0 100644 --- a/mc.hh +++ b/mc.hh @@ -61,6 +61,7 @@ class ModelChecker BDD statesEUctx(const BDD *contexts, const BDD &statesA, const BDD &statesB); BDD statesEFctx(const BDD *contexts, const BDD &states); BDD statesNK(const BDD &states, Process proc_id); + BDD statesNE(const BDD &states, ProcSet processes); BDD statesNC(const BDD &states, ProcSet processes); BDD getIthOnly(Process proc_id); diff --git a/rsin_parser.yy b/rsin_parser.yy index ebece8b..9cead08 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -409,6 +409,14 @@ rsctlk_form: $$ = new FormRSCTLK(RSCTLK_NE, *$3, $6); free($3); } + | UC LSB agents RSB LRB rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_UC, *$3, $6); + free($3); + } + | NC LSB agents RSB LRB rsctlk_form RRB { + $$ = new FormRSCTLK(RSCTLK_NC, *$3, $6); + free($3); + } // | E LSB actions RSB X rsctlk_form { // $$ = new FormRSCTLK(RSCTLK_EX_ACT, $3, $6); From 85e1e1d16b3a7bb7efe07f9f9b34702268a2e861 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 24 Nov 2018 17:02:26 +0000 Subject: [PATCH 76/90] C, E printing, etc. --- formrsctlk.cc | 22 ++++++++++++++++++++++ formrsctlk.hh | 1 + 2 files changed, 23 insertions(+) diff --git a/formrsctlk.cc b/formrsctlk.cc index 9260769..a760321 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -93,6 +93,13 @@ std::string FormRSCTLK::toStr(void) const else if (oper == RSCTLK_UK) { return "K[" + getSingleAgent() + "](" + arg[0]->toStr() + ")"; } + else if (oper == RSCTLK_NC) { + return "NC[" + getAgentsStr() + "](" + arg[0]->toStr() + ")"; + } + else if (oper == RSCTLK_UC) { + return "C[" + getAgentsStr() + "](" + arg[0]->toStr() + ")"; + } + else { return "??"; @@ -252,6 +259,21 @@ void FormRSCTLK::encodeActions(const SymRS *srs) } } +std::string FormRSCTLK::getAgentsStr(void) const +{ + std::string r = ""; + bool first = true; + for (const auto &a : agents) + { + if (first) + first = false; + else + r += " "; + r += a; + } + return r; +} + ProcSet FormRSCTLK::getAgentsAsProcSet(RctSys *rs) const { ProcSet processes; diff --git a/formrsctlk.hh b/formrsctlk.hh index add62c7..95ee49a 100644 --- a/formrsctlk.hh +++ b/formrsctlk.hh @@ -292,6 +292,7 @@ class FormRSCTLK assert(oper == RSCTLK_NK || oper == RSCTLK_UK); return *(agents.begin()); } + std::string getAgentsStr(void) const; ProcSet getAgentsAsProcSet(RctSys *rs) const; }; From 3db8fe103755e94d464cea8afd770316d4198600 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 24 Nov 2018 20:29:50 +0000 Subject: [PATCH 77/90] ASM --- in/scripts/gen_asm.py | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 in/scripts/gen_asm.py diff --git a/in/scripts/gen_asm.py b/in/scripts/gen_asm.py new file mode 100755 index 0000000..56dc0f6 --- /dev/null +++ b/in/scripts/gen_asm.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +from sys import argv,exit + +OPTIONS_STR = """ +options { use-context-automaton; make-progressive; } +""" + +PROC_STR = """ + proc{:d} {{ + {{{{a}}, {{s}} -> {{y}}}}; + {{{{y}}, {{s}} -> {{y}}}}; + {{{{a}}, {{s}} -> {{b}}}}; + {{{{b}}, {{s}} -> {{c}}}}; + {{{{c}}, {{s}} -> {{d}}}}; + {{{{d,y}}, {{s}} -> {{dy}}}}; + }}; +""" + +FINAL_PROC = """ + procFinal { + {{done}, {s} -> {done}}; + }; +""" + +CA_STR = """ +context-automaton {{ + states {{ init, act }} + init-state {{ init }} + transitions {{ +{:s} + }} +}} +""" + +PROPERTY_STR = """ +rsctlk-property {{ {:s} : {:s} }} +""" + + +################################################################# + +if len(argv) < 1: + print("Usage: {:s} ".format(argv[0])) + exit(100) + +n = int(argv[1]) + +assert n > 1, "number of proc must be > 1" + +out = "" + +out += OPTIONS_STR +out += "reactions {\n" +for i in range(1, n+1): + out += PROC_STR.format(i) + +out += FINAL_PROC +out += "}\n" + +transitions = "" + +init_trans = 8*" " + "{ proc1={a} }: init -> act;\n" +transitions += init_trans + +for i in range(1, n+1): + transitions += "{:s}{{ proc{:d}={{}} }}: act -> act;\n".format(8*" ", i, i) + +for i in range(2, n+1): + transitions += "{:s}{{ proc{:d}={{a}} }}: act -> act : proc{:d}.dy;\n".format(8*" ", i, i-1) + +final_cond = "proc1.dy" +for i in range(1, n+1): + final_cond += " AND proc{:d}.dy".format(i) + +transitions += "{:s}{{ procFinal={{done}} }}: act -> act : {:s};\n".format(8*" ", final_cond) + +out += CA_STR.format(transitions) + +# f1 +formula = "EF( procFinal.done )" +out += PROPERTY_STR.format("f1",formula) + +# f2 +formula = "EF( ~procFinal.done )" +out += PROPERTY_STR.format("f2",formula) + +print(out) + From 252af97897a61e5b3a1820853f694dca41a06240 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 25 Nov 2018 14:47:21 +0000 Subject: [PATCH 78/90] Benchmarking --- drs_benchmark.sh | 71 ++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index 87760d6..a925c62 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -5,51 +5,62 @@ TMPINPUT="tmp_$RANDOM$RANDOM.rs" CMD="./reactics -B" timelimit="$((30*60))" # 30 minutes +timelimit="$((5*60))" # 5 minutes -for opt in "z" "zb" "x" "xz" "xzb" "xb" "" "b";do +form_tgc_sc="`seq 1 3`" +form_asm="`seq 1 2`" - for f in `seq 1 3`; do +for benchmark in "tgc_sc" "asm"; do - done=0 + eval formulae=\$form_${benchmark} - for i in `seq 2 20`;do + for opt in "z" "zb" "x" "xz" "xzb" "xb" "" "b";do - if [[ $done -eq 1 ]];then - echo "Skipping f=$f i=$i for $opt" - continue - fi + for f in $formulae; do - echo "[i] n=$i; generating input file" - in/scripts/gen_tgc_sc.py $i > $TMPINPUT + done=0 - echo "[i] Testing formula f$f" + for i in `seq 2 20`;do - if [[ "$opt" = "" ]];then - opt_str="NoOpt" - CMDOPT="" - else - opt_str="$opt" - CMDOPT="-$opt" - fi + if [[ $done -eq 1 ]];then + echo "Skipping f=$f i=$i for $opt" + continue + fi - TMPCMD="$CMD $CMDOPT -c f$f $TMPINPUT" - echo "[i] running reactics: $TMPCMD" + echo "[i] n=$i; generating input file (${benchmark})" + in/scripts/gen_${benchmark}.py $i > $TMPINPUT - res=$(timeout $timelimit $TMPCMD | grep STAT) - if [[ $? -ne 0 ]];then - done=1 - fi - mem=$(echo $res | cut -d';' -f 5) - time=$(echo $res | cut -d';' -f 6) + echo "[i] Testing formula f$f" - echo "[.] Finished. time:$time, mem:$mem" + if [[ "$opt" = "" ]];then + opt_str="NoOpt" + CMDOPT="" + else + opt_str="$opt" + CMDOPT="-$opt" + fi - echo "$i $time $mem" >> bench_drs_tgc_${opt_str}_f$f.dat + TMPCMD="$CMD $CMDOPT -c f$f $TMPINPUT" + echo "[i] running reactics: $TMPCMD" + res=$(timeout $timelimit $TMPCMD | grep STAT) + if [[ $? -ne 0 ]];then + done=1 + continue + fi + mem=$(echo $res | cut -d';' -f 5) + time=$(echo $res | cut -d';' -f 6) + + echo "[.] Finished. time:$time, mem:$mem" + + echo "$i $time $mem" >> bench_drs_${benchmark}_${opt_str}_f$f.dat + + done + + echo + done - echo - done done From 1f132d4692b0538fd4d8a056db7af89849ba6254 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 25 Nov 2018 15:11:56 +0000 Subject: [PATCH 79/90] Formula --- in/scripts/gen_tgc_sc.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index c60637b..d0b18d8 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -101,8 +101,17 @@ subf = "~proc1.in" for i in range(2, n): subf += " AND ~proc{:d}.in".format(i) formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) - out += PROPERTY_STR.format("f4",formula) +# f5 +subf = "~proc1.in" +for i in range(2, n): + subf += " AND ~proc{:d}.in".format(i) +all_agents = "proc0" +for i in range(1, n): + all_agents += ",proc{:d}".format(i) +formula = "AG( proc0.in IMPLIES C[{:s}]({:s}) )".format(all_agents,subf) +out += PROPERTY_STR.format("f5",formula) + print(out) From c8e02156b9b3fb38b38ce181e372752280afb512 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 2 Dec 2018 19:30:02 +0000 Subject: [PATCH 80/90] Progressiveness --- rs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rs.cc b/rs.cc index b3220e4..63f8938 100644 --- a/rs.cc +++ b/rs.cc @@ -363,7 +363,7 @@ void RctSys::ctxAutSaveCurrentContextSet(std::string processName) void RctSys::ctxAutFinalise(void) { - ctx_aut->makeProgressive(); + // EMPTY } /** EOF **/ From 215015df57daa59b86bfcfd57c4aceadf7da2f86 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 2 Dec 2018 20:22:57 +0000 Subject: [PATCH 81/90] Prog --- ctx_aut.cc | 15 ++++++++++++--- ctx_aut.hh | 1 + rs.cc | 3 ++- stateconstr.cc | 6 +++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ctx_aut.cc b/ctx_aut.cc index bd597bb..d806449 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -139,15 +139,22 @@ void CtxAut::makeProgressive(void) special_loc += "T"; } addState(special_loc); + State special_loc_id = getLastStateID(); std::map constrs; for (State s = 0; s < states_ids.size(); ++s) { + if (s == special_loc_id) { + continue; + } + if (constrs.count(s) == 0) { - constrs[s] = new StateConstr(false); + constrs[s] = new StateConstr(true); } } + constrs[special_loc_id] = new StateConstr(true); + for (const auto &t : transitions) { State curr_st = t.src_state; if (t.state_constr != nullptr) @@ -160,11 +167,13 @@ void CtxAut::makeProgressive(void) for (const auto &s : states_ids) { StateConstr *state_constr = nullptr; - if (!constrs[getStateID(s)]->isFalse()) { + if (!constrs[getStateID(s)]->isTrue()) { state_constr = new StateConstr(STC_NOT, constrs[getStateID(s)]); + addTransition(s, special_loc, state_constr); } - addTransition(s, special_loc, state_constr); + } + addTransition(special_loc, special_loc, nullptr); made_progressive = true; diff --git a/ctx_aut.hh b/ctx_aut.hh index c80d475..f56b92f 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -35,6 +35,7 @@ class CtxAut void setInitState(std::string stateName); State getInitState(void); State getStateID(std::string name); + State getLastStateID(void) { return states_ids.size(); } std::string getStateName(State state_id); void printAutomaton(void); void showStates(void); diff --git a/rs.cc b/rs.cc index 63f8938..3b6ef7f 100644 --- a/rs.cc +++ b/rs.cc @@ -363,7 +363,8 @@ void RctSys::ctxAutSaveCurrentContextSet(std::string processName) void RctSys::ctxAutFinalise(void) { - // EMPTY + if (gen_ctxaut_progressive_closure) + ctx_aut->makeProgressive(); } /** EOF **/ diff --git a/stateconstr.cc b/stateconstr.cc index 6aef1b8..734ddb4 100644 --- a/stateconstr.cc +++ b/stateconstr.cc @@ -94,9 +94,9 @@ bool StateConstr::isFalse(void) const if (oper == STC_TF && tf == false) return true; - if (oper == STC_NOT && arg[0]->oper == STC_TF && arg[0]->tf == true) + if (oper == STC_NOT && arg[0]->isTrue()) return true; - + return false; } @@ -105,7 +105,7 @@ bool StateConstr::isTrue(void) const if (oper == STC_TF && tf == true) return true; - if (oper == STC_NOT && arg[0]->oper == STC_TF && arg[0]->tf == false) + if (oper == STC_NOT && arg[0]->isFalse()) return true; return false; From 9ac04da320d2b7aab80feaebec271e64721d8414 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 2 Dec 2018 20:49:18 +0000 Subject: [PATCH 82/90] asm, epistemic properties --- in/scripts/gen_asm.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/in/scripts/gen_asm.py b/in/scripts/gen_asm.py index 56dc0f6..7ba76ef 100755 --- a/in/scripts/gen_asm.py +++ b/in/scripts/gen_asm.py @@ -64,13 +64,13 @@ init_trans = 8*" " + "{ proc1={a} }: init -> act;\n" transitions += init_trans for i in range(1, n+1): - transitions += "{:s}{{ proc{:d}={{}} }}: act -> act;\n".format(8*" ", i, i) + transitions += "{:s}{{ proc{:d}={{}} }}: act -> act : ~proc{:d}.dy;\n".format(8*" ", i, i, i) for i in range(2, n+1): transitions += "{:s}{{ proc{:d}={{a}} }}: act -> act : proc{:d}.dy;\n".format(8*" ", i, i-1) final_cond = "proc1.dy" -for i in range(1, n+1): +for i in range(2, n+1): final_cond += " AND proc{:d}.dy".format(i) transitions += "{:s}{{ procFinal={{done}} }}: act -> act : {:s};\n".format(8*" ", final_cond) @@ -82,8 +82,12 @@ formula = "EF( procFinal.done )" out += PROPERTY_STR.format("f1",formula) # f2 -formula = "EF( ~procFinal.done )" +formula = "AG( proc{:d}.d IMPLIES K[proc{:d}]( proc{:d}.y ) )".format(n, n, n-1) out += PROPERTY_STR.format("f2",formula) +# x1 +formula = "EF( ~procFinal.done )" +out += PROPERTY_STR.format("x1",formula) + print(out) From a4eaa190d705a2c54eb8e1ae898fdd0df4d03256 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sun, 2 Dec 2018 20:59:29 +0000 Subject: [PATCH 83/90] Results --- reactics.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/reactics.cc b/reactics.cc index ab8371d..b5af3ad 100644 --- a/reactics.cc +++ b/reactics.cc @@ -158,6 +158,8 @@ int main(int argc, char **argv) // auto rs = *driver.getReactionSystem(); + bool result = true; + rs.setOptions(opts); // these need to be passed to the driver if (show_reactions) { @@ -184,10 +186,10 @@ int main(int argc, char **argv) if (rstl_model_checking) { if (bmc) { cout << "Using BDD-based Bounded Model Checking" << endl; - mc.checkRSCTLK(driver.getFormRSCTLK(property_name)); + result = mc.checkRSCTLK(driver.getFormRSCTLK(property_name)); } else { - mc.checkRSCTLKfull(driver.getFormRSCTLK(property_name)); + result = mc.checkRSCTLKfull(driver.getFormRSCTLK(property_name)); } } } @@ -213,7 +215,14 @@ int main(int argc, char **argv) delete opts; - return 0; + int ret_val; + + if (result) + ret_val = 0; + else + ret_val = 1; + + return ret_val; } void print_help(std::string path_str) @@ -258,4 +267,3 @@ void print_help(std::string path_str) } /** EOF **/ - From 8226919c0ef4f64903b381607a294e06ff9dc2ff Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 8 Dec 2018 21:53:32 +0000 Subject: [PATCH 84/90] Form --- in/scripts/gen_tgc_sc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index d0b18d8..81957c4 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -84,9 +84,9 @@ formula = "EF( proc0.in )" out += PROPERTY_STR.format("f1",formula) # f2 -formula = "EF( proc0.in )" +formula = "EF( EX( proc0.in ) )" for i in range(1, n): - formula += " AND EF( proc{:d}.in )".format(i) + formula += " AND EF( EX( proc{:d}.in ) )".format(i, i) out += PROPERTY_STR.format("f2",formula) # f3 From 877e9d095489e5f52613a1f8462dc8f655b7d05a Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 8 Dec 2018 21:58:39 +0000 Subject: [PATCH 85/90] Benchmarks --- drs_benchmark.sh | 2 +- in/scripts/gen_tgc_sc.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drs_benchmark.sh b/drs_benchmark.sh index a925c62..b7ad43d 100755 --- a/drs_benchmark.sh +++ b/drs_benchmark.sh @@ -7,7 +7,7 @@ CMD="./reactics -B" timelimit="$((30*60))" # 30 minutes timelimit="$((5*60))" # 5 minutes -form_tgc_sc="`seq 1 3`" +form_tgc_sc="`seq 1 4`" form_asm="`seq 1 2`" for benchmark in "tgc_sc" "asm"; do diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index 81957c4..23878f4 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -79,31 +79,31 @@ for i in range(n): out += CA_STR.format(transitions) -# f1 -formula = "EF( proc0.in )" -out += PROPERTY_STR.format("f1",formula) +## f1 +#formula = "EF( proc0.in )" +#out += PROPERTY_STR.format("f1",formula) -# f2 +# f1 formula = "EF( EX( proc0.in ) )" for i in range(1, n): formula += " AND EF( EX( proc{:d}.in ) )".format(i, i) -out += PROPERTY_STR.format("f2",formula) +out += PROPERTY_STR.format("f1",formula) -# f3 +# f2 formula = "EF( proc0.approach" for i in range(1, n): formula += " AND proc{:d}.approach".format(i) formula += " )" -out += PROPERTY_STR.format("f3",formula) +out += PROPERTY_STR.format("f2",formula) -# f4 +# f3 subf = "~proc1.in" for i in range(2, n): subf += " AND ~proc{:d}.in".format(i) formula = "AG( proc0.in IMPLIES K[proc0]({:s}) )".format(subf) -out += PROPERTY_STR.format("f4",formula) +out += PROPERTY_STR.format("f3",formula) -# f5 +# f4 subf = "~proc1.in" for i in range(2, n): subf += " AND ~proc{:d}.in".format(i) @@ -111,7 +111,7 @@ all_agents = "proc0" for i in range(1, n): all_agents += ",proc{:d}".format(i) formula = "AG( proc0.in IMPLIES C[{:s}]({:s}) )".format(all_agents,subf) -out += PROPERTY_STR.format("f5",formula) +out += PROPERTY_STR.format("f4",formula) print(out) From e0535de4716296503a1a9942399bf26a6668cf7c Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 29 Dec 2018 13:48:56 +0000 Subject: [PATCH 86/90] Version --- Makefile | 3 ++- reactics.cc | 12 ++++++------ reactics.hh | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 0e28206..4235476 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ CPPFLAGS = -Wall $(CPPFLAGS_SILENT) #-Werror #CPPFLAGS = -Wall $(INCLUDES) -DNDEBUG CXXFLAGS_SILENT = -O3 -g CXXFLAGS = -std=c++14 $(CXXFLAGS_SILENT) -#CXXFLAGS = -std=c++14 -O3 -DPUBLIC_RELEASE -DNDEBUG #-g +CXXFLAGS = -std=c++14 -O3 -DPUBLIC_RELEASE -DNDEBUG #-g +CXXFLAGS = -std=c++14 -O3 -DPUBLIC_RELEASE #-g LDLIBS = $(CUDD_INCLUDE) OBJ = rs.o ctx_aut.o symrs.o mc.o rsin_driver.o rsin_parser.o rsin_parser.lex.o formrsctlk.o stateconstr.o diff --git a/reactics.cc b/reactics.cc index b5af3ad..99731ba 100644 --- a/reactics.cc +++ b/reactics.cc @@ -21,7 +21,7 @@ int main(int argc, char **argv) bool reach_states_succ = false; bool bmc = true; bool benchmarking = false; - bool usage_error = false; + bool dump_help_message = false; bool print_parsed_sys = false; std::string property_name = "default"; @@ -110,11 +110,11 @@ int main(int argc, char **argv) break; case 'h': - usage_error = true; + dump_help_message = true; break; default: - usage_error = true; + dump_help_message = true; break; } } @@ -124,12 +124,12 @@ int main(int argc, char **argv) if (optind < argc) { inputfile = argv[optind]; } - else { + else if (!dump_help_message) { cout << "Missing input file" << endl; - usage_error = true; + dump_help_message = true; } - if (usage_error) { + if (dump_help_message) { print_help(std::string(argv[0])); return 100; } diff --git a/reactics.hh b/reactics.hh index 8b6bfc7..c1e0d7c 100644 --- a/reactics.hh +++ b/reactics.hh @@ -19,8 +19,9 @@ #include "options.hh" #include "memtime.hh" -#define VERSION "2.0 ALPHA" -#define AUTHOR "Artur Meski " +#define VERSION "2.0" +//#define AUTHOR "Artur Meski " +#define AUTHOR "Artur Meski " using std::cout; using std::endl; From 37ef85beaafc5fbe8efcc299a447cad88917cf4d Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 29 Dec 2018 13:50:28 +0000 Subject: [PATCH 87/90] Space --- reactics.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reactics.cc b/reactics.cc index 99731ba..b4745fc 100644 --- a/reactics.cc +++ b/reactics.cc @@ -242,7 +242,7 @@ void print_help(std::string path_str) << " ###################################" << endl << endl #endif - << " Usage: " << path_str << " [options] " << endl << endl + << " Usage: " << path_str << " [options] " << endl << endl << " TASKS:" << endl << " -c -- perform RSCTLK model checking" << endl //<< " -f K -- generate SMT input for the depth K" << endl From 53504d6514716836c1901e476adb4f6373e42e2c Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 29 Dec 2018 15:01:57 +0000 Subject: [PATCH 88/90] Parser semicols --- rsin_parser.yy | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rsin_parser.yy b/rsin_parser.yy index 9cead08..0f1ad96 100644 --- a/rsin_parser.yy +++ b/rsin_parser.yy @@ -80,15 +80,15 @@ class rsin_driver; %start system; system: - | OPTIONS LCB options RCB system - | REACTIONS LCB reactionsets RCB system - | INITIALCONTEXTS LCB initstates RCB system - | CONTEXTENTITIES LCB actionentities RCB system - | CONTEXTAUTOMATON LCB ctxaut RCB system + | OPTIONS LCB options RCB SEMICOL system + | REACTIONS LCB reactionsets RCB SEMICOL system + | INITIALCONTEXTS LCB initstates RCB SEMICOL system + | CONTEXTENTITIES LCB actionentities RCB SEMICOL system + | CONTEXTAUTOMATON LCB ctxaut RCB SEMICOL system { driver.getReactionSystem()->ctxAutFinalise(); } - | RSCTLKFORM LCB IDENTIFIER COL rsctlk_form RCB system { + | RSCTLKFORM LCB IDENTIFIER COL rsctlk_form RCB SEMICOL system { driver.addFormRSCTLK(*$3, $5); free($3); } @@ -213,9 +213,9 @@ actentity: IDENTIFIER { /*******************************************/ ctxaut: - | STATES LCB autstates RCB ctxaut - | INITSTATE LCB autinitstate RCB ctxaut - | TRANSITIONS LCB auttransitions RCB ctxaut + | STATES LCB autstates RCB SEMICOL ctxaut + | INITSTATE LCB autinitstate RCB SEMICOL ctxaut + | TRANSITIONS LCB auttransitions RCB SEMICOL ctxaut ; autstate: IDENTIFIER { From e4f5b7271e7a99b487f0c6e69bf374e5b7ebb395 Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 29 Dec 2018 22:07:26 +0000 Subject: [PATCH 89/90] Formatting --- ctx_aut.cc | 32 ++++++++++++++++++-------------- ctx_aut.hh | 5 ++++- formrsctlk.cc | 17 +++++++++++------ in/scripts/gen_tgc_sc.py | 14 +++++++------- mc.cc | 18 ++++++++---------- memtime.hh | 12 +++++++----- reactics.cc | 32 +++++++++++++++++--------------- rs.cc | 3 ++- rsin_driver.cc | 7 +++---- stateconstr.cc | 18 ++++++++++++------ symrs.cc | 7 ++++--- 11 files changed, 93 insertions(+), 72 deletions(-) diff --git a/ctx_aut.cc b/ctx_aut.cc index d806449..edc0f8a 100644 --- a/ctx_aut.cc +++ b/ctx_aut.cc @@ -121,9 +121,11 @@ void CtxAut::showTransitions(void) cout << " * [" << getStateName(t.src_state) << " -> " << getStateName( t.dst_state) << "]: { " << parent_rctsys->procEntitiesToStr(t.ctx) << "}"; + if (t.state_constr != nullptr) { cout << " " << t.state_constr->toStr(); } + cout << endl; } } @@ -134,16 +136,17 @@ void CtxAut::makeProgressive(void) assert(!made_progressive); std::string special_loc = "T"; - while (hasState(special_loc)) - { + + while (hasState(special_loc)) { special_loc += "T"; } + addState(special_loc); State special_loc_id = getLastStateID(); std::map constrs; - for (State s = 0; s < states_ids.size(); ++s) - { + + for (State s = 0; s < states_ids.size(); ++s) { if (s == special_loc_id) { continue; } @@ -157,22 +160,23 @@ void CtxAut::makeProgressive(void) for (const auto &t : transitions) { State curr_st = t.src_state; - if (t.state_constr != nullptr) - { + + if (t.state_constr != nullptr) { constrs[curr_st] = new StateConstr( - STC_OR, constrs[curr_st], t.state_constr); + STC_OR, constrs[curr_st], t.state_constr); } } - for (const auto &s : states_ids) - { - StateConstr *state_constr = nullptr; - if (!constrs[getStateID(s)]->isTrue()) { - state_constr = new StateConstr(STC_NOT, constrs[getStateID(s)]); - addTransition(s, special_loc, state_constr); - } + for (const auto &s : states_ids) { + StateConstr *state_constr = nullptr; + + if (!constrs[getStateID(s)]->isTrue()) { + state_constr = new StateConstr(STC_NOT, constrs[getStateID(s)]); + addTransition(s, special_loc, state_constr); + } } + addTransition(special_loc, special_loc, nullptr); made_progressive = true; diff --git a/ctx_aut.hh b/ctx_aut.hh index f56b92f..164d4c7 100644 --- a/ctx_aut.hh +++ b/ctx_aut.hh @@ -35,7 +35,10 @@ class CtxAut void setInitState(std::string stateName); State getInitState(void); State getStateID(std::string name); - State getLastStateID(void) { return states_ids.size(); } + State getLastStateID(void) + { + return states_ids.size(); + } std::string getStateName(State state_id); void printAutomaton(void); void showStates(void); diff --git a/formrsctlk.cc b/formrsctlk.cc index a760321..fd56f3a 100644 --- a/formrsctlk.cc +++ b/formrsctlk.cc @@ -263,23 +263,28 @@ std::string FormRSCTLK::getAgentsStr(void) const { std::string r = ""; bool first = true; - for (const auto &a : agents) - { - if (first) + + for (const auto &a : agents) { + if (first) { first = false; - else + } + else { r += " "; + } + r += a; } + return r; } ProcSet FormRSCTLK::getAgentsAsProcSet(RctSys *rs) const { ProcSet processes; - for (auto &a : agents) - { + + for (auto &a : agents) { processes.insert(rs->getProcessID(a)); } + return processes; } diff --git a/in/scripts/gen_tgc_sc.py b/in/scripts/gen_tgc_sc.py index 23878f4..d4bfcf0 100755 --- a/in/scripts/gen_tgc_sc.py +++ b/in/scripts/gen_tgc_sc.py @@ -3,7 +3,7 @@ from sys import argv,exit OPTIONS_STR = """ -options { use-context-automaton; make-progressive; } +options { use-context-automaton; make-progressive; }; """ PROC_STR = """ @@ -18,16 +18,16 @@ PROC_STR = """ CA_STR = """ context-automaton {{ - states {{ init, green, red }} - init-state {{ init }} + states {{ init, green, red }}; + init-state {{ init }}; transitions {{ {:s} - }} -}} + }}; +}}; """ PROPERTY_STR = """ -rsctlk-property {{ {:s} : {:s} }} +rsctlk-property {{ {:s} : {:s} }}; """ @@ -47,7 +47,7 @@ out += OPTIONS_STR out += "reactions {\n" for i in range(n): out += PROC_STR.format(i) -out += "}\n" +out += "};\n" transitions = "" diff --git a/mc.cc b/mc.cc index c4a3173..76f1128 100644 --- a/mc.cc +++ b/mc.cc @@ -127,6 +127,7 @@ inline BDD ModelChecker::getPreEctx(const BDD &states, const BDD *contexts) q *= x * trans; reorder(); } + q *= *contexts; } else { @@ -367,13 +368,11 @@ BDD ModelChecker::getStatesRSCTLK(const FormRSCTLK *form) auto proc_set = form->getAgentsAsProcSet(srs->rs); return *reach - (statesNE(*reach - getStatesRSCTLK(form->getLeftSF()), proc_set) * *reach); } - else if (oper == RSCTLK_NC) - { + else if (oper == RSCTLK_NC) { auto proc_set = form->getAgentsAsProcSet(srs->rs); return statesNC(getStatesRSCTLK(form->getLeftSF()) * *reach, proc_set) * *reach; } - else if (oper == RSCTLK_UC) - { + else if (oper == RSCTLK_UC) { auto proc_set = form->getAgentsAsProcSet(srs->rs); return *reach - (statesNC(*reach - getStatesRSCTLK(form->getLeftSF()), proc_set) * *reach); } @@ -475,8 +474,7 @@ BDD ModelChecker::statesNE(const BDD &states, ProcSet processes) { BDD x = BDD_FALSE; - for (auto const &proc_id : processes) - { + for (auto const &proc_id : processes) { x += states.ExistAbstract(getIthOnly(proc_id)); } @@ -488,14 +486,14 @@ BDD ModelChecker::statesNC(const BDD &states, ProcSet processes) BDD x = BDD_FALSE; BDD x_p = *reach; - while (x != x_p) - { + while (x != x_p) { x_p = x; BDD t = BDD_FALSE; - for (auto const &proc_id : processes) - { + + for (auto const &proc_id : processes) { t += x.ExistAbstract(getIthOnly(proc_id)); } + x = t; } diff --git a/memtime.hh b/memtime.hh index af6a286..086fd6c 100644 --- a/memtime.hh +++ b/memtime.hh @@ -69,16 +69,18 @@ static inline int64 memUsedInt64() #if defined(__APPLE__) -static inline double memUsed() { - malloc_statistics_t t; - malloc_zone_statistics(NULL, &t); - return (double)t.max_size_in_use / (1024*1024); } +static inline double memUsed() +{ + malloc_statistics_t t; + malloc_zone_statistics(NULL, &t); + return (double)t.max_size_in_use / (1024 * 1024); +} #else static inline double memUsed() { - return memUsedInt64() / (1024*1024); + return memUsedInt64() / (1024 * 1024); } #endif diff --git a/reactics.cc b/reactics.cc index b4745fc..06aeab4 100644 --- a/reactics.cc +++ b/reactics.cc @@ -124,7 +124,7 @@ int main(int argc, char **argv) if (optind < argc) { inputfile = argv[optind]; } - else if (!dump_help_message) { + else if (!dump_help_message) { cout << "Missing input file" << endl; dump_help_message = true; } @@ -217,10 +217,12 @@ int main(int argc, char **argv) int ret_val; - if (result) + if (result) { ret_val = 0; - else + } + else { ret_val = 1; + } return ret_val; } @@ -244,25 +246,25 @@ void print_help(std::string path_str) #endif << " Usage: " << path_str << " [options] " << endl << endl << " TASKS:" << endl - << " -c -- perform RSCTLK model checking" << endl + << " -c form -- perform RSCTLK model checking (form: formula identifier)" << endl //<< " -f K -- generate SMT input for the depth K" << endl - << " -P -- print parsed system" << endl - << " -r -- print reactions" << endl - << " -s -- print the set of all the reachable states" << endl - << " -t -- print the set of all the reachable states with their successors" + << " -P -- print parsed system" << endl + << " -r -- print reactions" << endl + << " -s -- print all the reachable states" << endl + << " -t -- print all the reachable states with their successors" << endl << endl << " OTHER:" << endl - << " -b -- disable bounded model checking (BMC) heuristic" << endl - << " -x -- use partitioned transition relation (may use less memory)" << + << " -b -- disable bounded model checking (BMC) heuristic" << endl + << " -x -- use partitioned transition relation" << endl - << " -z -- use reordering of the BDD variables" << endl - << " -v -- verbose (can be used more than once to increase verbosity)" << + << " -z -- use reordering of the BDD variables" << endl + << " -v -- verbose (use more than once to increase verbosity)" << endl - << " -p -- show progress (where possible)" << endl + << " -p -- show progress (where possible)" << endl << endl << " Benchmarking options:" << endl - << " -m -- measure and display time and memory usage" << endl - << " -B -- display an easy to parse summary (enables -m)" << endl + << " -m -- measure and display time and memory usage" << endl + << " -B -- display an easy to parse summary (enables -m)" << endl << endl; } diff --git a/rs.cc b/rs.cc index 3b6ef7f..f04c578 100644 --- a/rs.cc +++ b/rs.cc @@ -363,8 +363,9 @@ void RctSys::ctxAutSaveCurrentContextSet(std::string processName) void RctSys::ctxAutFinalise(void) { - if (gen_ctxaut_progressive_closure) + if (gen_ctxaut_progressive_closure) { ctx_aut->makeProgressive(); + } } /** EOF **/ diff --git a/rsin_driver.cc b/rsin_driver.cc index 374f9b7..0c50b29 100644 --- a/rsin_driver.cc +++ b/rsin_driver.cc @@ -110,12 +110,11 @@ void rsin_driver::useContextAutomaton(void) void rsin_driver::makeProgressive(void) { make_progressive = true; - if (use_ctx_aut) - { + + if (use_ctx_aut) { getReactionSystem()->ctxAutEnableProgressiveClosure(); } - else - { + else { FERROR("Context automaton not enabled"); } } diff --git a/stateconstr.cc b/stateconstr.cc index 734ddb4..8bb6f27 100644 --- a/stateconstr.cc +++ b/stateconstr.cc @@ -57,10 +57,12 @@ BDD StateConstr::getBDDforContext(const SymRS *srs) const BDD StateConstr::getBDD(const SymRS *srs, bool encode_context) const { if (oper == STC_PV) { - if (encode_context) + if (encode_context) { return srs->encActStrEntity(proc_name, entity_name); - else + } + else { return srs->encEntity(proc_name, entity_name); + } } else if (oper == STC_TF) { if (tf) { @@ -91,22 +93,26 @@ BDD StateConstr::getBDD(const SymRS *srs, bool encode_context) const bool StateConstr::isFalse(void) const { - if (oper == STC_TF && tf == false) + if (oper == STC_TF && tf == false) { return true; + } - if (oper == STC_NOT && arg[0]->isTrue()) + if (oper == STC_NOT && arg[0]->isTrue()) { return true; + } return false; } bool StateConstr::isTrue(void) const { - if (oper == STC_TF && tf == true) + if (oper == STC_TF && tf == true) { return true; + } - if (oper == STC_NOT && arg[0]->isFalse()) + if (oper == STC_NOT && arg[0]->isFalse()) { return true; + } return false; } diff --git a/symrs.cc b/symrs.cc index 53a261a..62f60a6 100644 --- a/symrs.cc +++ b/symrs.cc @@ -773,7 +773,7 @@ void SymRS::encodeTransitions(void) VERB("Using partitioned transition relation encoding"); if (usingContextAutomaton()) { - partTrans = new BDDvec(numberOfProc+1); + partTrans = new BDDvec(numberOfProc + 1); } else { partTrans = new BDDvec(numberOfProc); @@ -789,8 +789,7 @@ void SymRS::encodeTransitions(void) VERB_LN(3, "Entity production encoding for all the processes and their products"); - if (opts->part_tr_rel) - { + if (opts->part_tr_rel) { for (const auto &proc_products : usedProducts) { auto proc_id = proc_products.first; @@ -949,9 +948,11 @@ void SymRS::encodeCtxAutTrans(void) BDD enc_dst = encCtxAutStateSucc(t.dst_state); BDD enc_ctx = compContext(encContext(t.ctx)); BDD enc_drs_state = BDD_TRUE; + if (t.state_constr != nullptr) { enc_drs_state = t.state_constr->getBDDforState(this); } + BDD new_trans = enc_src * enc_drs_state * enc_ctx * enc_dst; *tr_ca += new_trans; From b70c09a2d127436a9f46d781cbf262bf9ab3cdbb Mon Sep 17 00:00:00 2001 From: Artur Meski Date: Sat, 29 Dec 2018 22:41:15 +0000 Subject: [PATCH 90/90] Shorter verbose message --- symrs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symrs.cc b/symrs.cc index 62f60a6..c7476c6 100644 --- a/symrs.cc +++ b/symrs.cc @@ -820,7 +820,7 @@ void SymRS::encodeTransitions(void) VERB("Reactions ready"); if (usingContextAutomaton()) { - VERB("Augmenting transition relation encoding with the transition relation for context automaton"); + VERB("Augmenting transitions with transitions for context automaton"); if (opts->part_tr_rel) { auto last_index = numberOfProc;