Common Knowledge operators support
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
29
mc.cc
29
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 */
|
||||
|
||||
1
mc.hh
1
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 statesNC(const BDD &states, ProcSet processes);
|
||||
|
||||
BDD getIthOnly(Process proc_id);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ class rsin_driver;
|
||||
// Action_f *act;
|
||||
// ActionsVec_f *actionsVec;
|
||||
StateConstr *fstc;
|
||||
Agents_f *agents;
|
||||
};
|
||||
|
||||
%code {
|
||||
@@ -67,6 +68,7 @@ class rsin_driver;
|
||||
// %type <act> action
|
||||
// %type <actionsVec> actions
|
||||
%type <fstc> state_constr
|
||||
%type <agents> 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);
|
||||
}
|
||||
|
||||
|
||||
1
types.hh
1
types.hh
@@ -30,6 +30,7 @@ struct Reaction {
|
||||
typedef unsigned int Process;
|
||||
typedef std::vector<std::string> ProcessesById;
|
||||
typedef std::map<std::string, Process> ProcessesByName;
|
||||
typedef std::set<Process> ProcSet;
|
||||
|
||||
typedef std::vector<Reaction> Reactions;
|
||||
typedef std::map<Process, Reactions> ReactionsForProc;
|
||||
|
||||
Reference in New Issue
Block a user