Transition relation encoding
This commit is contained in:
@@ -102,7 +102,7 @@ void CtxAut::showTransitions(void)
|
|||||||
{
|
{
|
||||||
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName(t.dst_state)
|
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName(t.dst_state)
|
||||||
<< "]: {" << parent_rctsys->entitiesToStr(t.ctx) << "}" << endl;
|
<< "]: {" << parent_rctsys->entitiesToStr(t.ctx) << "}" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** EOF **/
|
/** EOF **/
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class RctSys;
|
|||||||
|
|
||||||
class CtxAut
|
class CtxAut
|
||||||
{
|
{
|
||||||
|
friend class SymRS;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CtxAut(Options *opts, RctSys *parent_rctsys);
|
CtxAut(Options *opts, RctSys *parent_rctsys);
|
||||||
bool hasState(std::string name);
|
bool hasState(std::string name);
|
||||||
|
|||||||
6
macro.hh
6
macro.hh
@@ -33,4 +33,10 @@ 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; \
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
103
symrs.cc
103
symrs.cc
@@ -5,6 +5,25 @@
|
|||||||
|
|
||||||
#include "symrs.hh"
|
#include "symrs.hh"
|
||||||
|
|
||||||
|
|
||||||
|
SymRS::SymRS(RctSys *rs, Options *opts)
|
||||||
|
{
|
||||||
|
this->rs = rs;
|
||||||
|
this->opts = opts;
|
||||||
|
totalStateVars = rs->getEntitiesSize();
|
||||||
|
totalReactions = rs->getReactionsSize();
|
||||||
|
totalActions = rs->getActionsSize();
|
||||||
|
totalCtxAutStateVars = getCtxAutStateEncodingSize();
|
||||||
|
|
||||||
|
partTrans = nullptr;
|
||||||
|
monoTrans = nullptr;
|
||||||
|
|
||||||
|
pv_ca = nullptr;
|
||||||
|
pv_ca_succ = nullptr;
|
||||||
|
|
||||||
|
encode();
|
||||||
|
}
|
||||||
|
|
||||||
BDD SymRS::encEntity_raw(Entity entity, bool succ) const
|
BDD SymRS::encEntity_raw(Entity entity, bool succ) const
|
||||||
{
|
{
|
||||||
BDD r;
|
BDD r;
|
||||||
@@ -21,10 +40,10 @@ BDD SymRS::encEntitiesConj_raw(const Entities &entities, bool succ)
|
|||||||
{
|
{
|
||||||
BDD r = BDD_TRUE;
|
BDD r = BDD_TRUE;
|
||||||
|
|
||||||
for (auto entity = entities.begin(); entity != entities.end(); ++entity)
|
for (const auto &entity : entities)
|
||||||
{
|
{
|
||||||
if (succ) r *= encEntitySucc(*entity);
|
if (succ) r *= encEntitySucc(entity);
|
||||||
else r *= encEntity(*entity);
|
else r *= encEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@@ -34,10 +53,10 @@ BDD SymRS::encEntitiesDisj_raw(const Entities &entities, bool succ)
|
|||||||
{
|
{
|
||||||
BDD r = BDD_FALSE;
|
BDD r = BDD_FALSE;
|
||||||
|
|
||||||
for (auto entity = entities.begin(); entity != entities.end(); ++entity)
|
for (const auto &entity : entities)
|
||||||
{
|
{
|
||||||
if (succ) r += encEntitySucc(*entity);
|
if (succ) r += encEntitySucc(entity);
|
||||||
else r += encEntity(*entity);
|
else r += encEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@@ -47,13 +66,13 @@ BDD SymRS::encStateActEntitiesConj(const Entities &entities)
|
|||||||
{
|
{
|
||||||
BDD r = BDD_TRUE;
|
BDD r = BDD_TRUE;
|
||||||
|
|
||||||
for (auto entity = entities.begin(); entity != entities.end(); ++entity)
|
for (const auto &entity : entities)
|
||||||
{
|
{
|
||||||
BDD state_act = encEntity(*entity);
|
BDD state_act = encEntity(entity);
|
||||||
int actEntity;
|
int actEntity;
|
||||||
|
|
||||||
// if entity is also an action entity, we include it in the encoding
|
// if entity is also an action entity, we include it in the encoding
|
||||||
if ((actEntity = getMappedStateToActID(*entity)) >= 0)
|
if ((actEntity = getMappedStateToActID(entity)) >= 0)
|
||||||
state_act += encActEntity(actEntity);
|
state_act += encActEntity(actEntity);
|
||||||
|
|
||||||
r *= state_act;
|
r *= state_act;
|
||||||
@@ -66,13 +85,13 @@ BDD SymRS::encStateActEntitiesDisj(const Entities &entities)
|
|||||||
{
|
{
|
||||||
BDD r = BDD_FALSE;
|
BDD r = BDD_FALSE;
|
||||||
|
|
||||||
for (auto entity = entities.begin(); entity != entities.end(); ++entity)
|
for (const auto &entity : entities)
|
||||||
{
|
{
|
||||||
BDD state_act = encEntity(*entity);
|
BDD state_act = encEntity(entity);
|
||||||
int actEntity;
|
int actEntity;
|
||||||
|
|
||||||
// if entity is also an aciton entity, we include it in the encoding
|
// if entity is also an aciton entity, we include it in the encoding
|
||||||
if ((actEntity = getMappedStateToActID(*entity)) >= 0)
|
if ((actEntity = getMappedStateToActID(entity)) >= 0)
|
||||||
state_act += encActEntity(actEntity);
|
state_act += encActEntity(actEntity);
|
||||||
|
|
||||||
r += state_act;
|
r += state_act;
|
||||||
@@ -81,6 +100,19 @@ BDD SymRS::encStateActEntitiesDisj(const Entities &entities)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BDD SymRS::encActEntitiesConj(const Entities &entities)
|
||||||
|
{
|
||||||
|
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
|
BDD SymRS::compState(const BDD &state) const
|
||||||
{
|
{
|
||||||
BDD s = state;
|
BDD s = state;
|
||||||
@@ -413,7 +445,7 @@ size_t SymRS::getCtxAutStateEncodingSize(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const
|
BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const
|
||||||
{
|
{
|
||||||
// select appropriate BDD vector
|
// select appropriate BDD vector
|
||||||
vector<BDD> *enc_vec;
|
vector<BDD> *enc_vec;
|
||||||
if (succ)
|
if (succ)
|
||||||
@@ -421,7 +453,9 @@ BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const
|
|||||||
else
|
else
|
||||||
enc_vec = pv_ca;
|
enc_vec = pv_ca;
|
||||||
|
|
||||||
BDD r;
|
assert(enc_vec != nullptr);
|
||||||
|
|
||||||
|
BDD r = BDD_TRUE;
|
||||||
State val = state_id;
|
State val = state_id;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < totalCtxAutStateVars; ++i)
|
for (unsigned int i = 0; i < totalCtxAutStateVars; ++i)
|
||||||
@@ -429,9 +463,13 @@ BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const
|
|||||||
if (val != 0)
|
if (val != 0)
|
||||||
{
|
{
|
||||||
if (val % 2 == 1)
|
if (val % 2 == 1)
|
||||||
r *= (*enc_vec)[i];
|
{
|
||||||
|
r *= (*enc_vec)[i];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
r *= !(*enc_vec)[i];
|
{
|
||||||
|
r *= !(*enc_vec)[i];
|
||||||
|
}
|
||||||
val /= 2;
|
val /= 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -443,22 +481,31 @@ BDD SymRS::encCtxAutState_raw(State state_id, bool succ) const
|
|||||||
|
|
||||||
BDD *SymRS::getEncCtxAutInitState(void)
|
BDD *SymRS::getEncCtxAutInitState(void)
|
||||||
{
|
{
|
||||||
return new BDD(BDD_TRUE);
|
VERB_LN(2, "Encoding context automaton's initial state");
|
||||||
}
|
|
||||||
|
State state = rs->ctx_aut->getInitState();
|
||||||
vector<BDD> *SymRS::getEncCtxAutPV(void)
|
|
||||||
{
|
BDD *r = new BDD(encCtxAutState(state));
|
||||||
return new vector<BDD>();
|
|
||||||
}
|
return r;
|
||||||
|
|
||||||
vector<BDD> *SymRS::getEncCtxAutPVsucc(void)
|
|
||||||
{
|
|
||||||
return new vector<BDD>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BDD *SymRS::getEncCtxAutTrans(void)
|
BDD *SymRS::getEncCtxAutTrans(void)
|
||||||
{
|
{
|
||||||
return new BDD(BDD_TRUE);
|
VERB_LN(2, "Encoding context automaton's transition relation");
|
||||||
|
|
||||||
|
BDD *r = new BDD(BDD_FALSE);
|
||||||
|
|
||||||
|
for (auto &t : rs->ctx_aut->transitions)
|
||||||
|
{
|
||||||
|
BDD enc_src = encCtxAutState(t.src_state);
|
||||||
|
BDD enc_dst = encCtxAutStateSucc(t.dst_state);
|
||||||
|
BDD enc_ctx = encActEntitiesConj(t.ctx);
|
||||||
|
|
||||||
|
*r += enc_src * enc_ctx * enc_dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** EOF **/
|
/** EOF **/
|
||||||
|
|||||||
22
symrs.hh
22
symrs.hh
@@ -94,6 +94,8 @@ class SymRS
|
|||||||
BDD encStateActEntitiesConj(const Entities &entities);
|
BDD encStateActEntitiesConj(const Entities &entities);
|
||||||
BDD encStateActEntitiesDisj(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
|
* @brief Complements an encoding of a given state by negating all the variables that are not set to true
|
||||||
*
|
*
|
||||||
@@ -120,20 +122,8 @@ class SymRS
|
|||||||
size_t getCtxAutStateEncodingSize(void);
|
size_t getCtxAutStateEncodingSize(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SymRS(RctSys *rs, Options *opts)
|
SymRS(RctSys *rs, Options *opts);
|
||||||
{
|
|
||||||
this->rs = rs;
|
|
||||||
this->opts = opts;
|
|
||||||
totalStateVars = rs->getEntitiesSize();
|
|
||||||
totalReactions = rs->getReactionsSize();
|
|
||||||
totalActions = rs->getActionsSize();
|
|
||||||
totalCtxAutStateVars = getCtxAutStateEncodingSize();
|
|
||||||
|
|
||||||
partTrans = nullptr;
|
|
||||||
monoTrans = nullptr;
|
|
||||||
|
|
||||||
encode();
|
|
||||||
}
|
|
||||||
vector<BDD> *getEncPV(void) { return pv; }
|
vector<BDD> *getEncPV(void) { return pv; }
|
||||||
vector<BDD> *getEncPVsucc(void) { return pv_succ; }
|
vector<BDD> *getEncPVsucc(void) { return pv_succ; }
|
||||||
BDD *getEncPV_E(void) { return pv_E; }
|
BDD *getEncPV_E(void) { return pv_E; }
|
||||||
@@ -193,14 +183,14 @@ public:
|
|||||||
*
|
*
|
||||||
* @return Returns a vector of BDDs
|
* @return Returns a vector of BDDs
|
||||||
*/
|
*/
|
||||||
vector<BDD> *getEncCtxAutPV(void);
|
vector<BDD> *getEncCtxAutPV(void) { return pv_ca; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Getter for context automaton's successor (primed) state variables
|
* @brief Getter for context automaton's successor (primed) state variables
|
||||||
*
|
*
|
||||||
* @return Returns a vector of BDDs
|
* @return Returns a vector of BDDs
|
||||||
*/
|
*/
|
||||||
vector<BDD> *getEncCtxAutPVsucc(void);
|
vector<BDD> *getEncCtxAutPVsucc(void) { return pv_ca_succ; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Encodes the monolithic transition relation
|
* @brief Encodes the monolithic transition relation
|
||||||
|
|||||||
Reference in New Issue
Block a user