def caw(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying [agents][phi W psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ if len(fsm.fairness_constraints) == 0: return fp(lambda Z : psi | (phi & fsm.pre_nstrat(Z, agents)), BDD.true(fsm.bddEnc.DDmanager)) else: def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre_nstrat(fp(lambda Y : (psi &fair_gamma_states(fsm, agents)) | (Z & f) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager)), agents) return (psi &fair_gamma_states(fsm, agents)) | res return fp(inner, BDD.true(fsm.bddEnc.DDmanager))
def ceu(fsm, agents, phi, psi, strat=None): """ Return the set of states of strat satisfying <agents>[phi U psi] under full observability in strat. If strat is None, strat is considered true. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi strat -- a BDD representing allowed state/inputs pairs, or None """ if len(fsm.fairness_constraints) == 0: return fp(lambda Z : psi | (phi & fsm.pre_strat(Z, agents, strat)), BDD.false(fsm.bddEnc.DDmanager)) else: nfair = nfair_gamma(fsm, agents, strat) def inner(Z): res = psi for f in fsm.fairness_constraints: nf = ~f res = res | fsm.pre_strat(fp(lambda Y : (phi | psi | nfair) & (Z | nf) & (psi | fsm.pre_strat(Y, agents, strat)), BDD.true(fsm.bddEnc.DDmanager)), agents, strat) return (psi | phi | nfair) & res return fp(inner, BDD.false(fsm.bddEnc.DDmanager))
def ceu(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying <agents>[phi U psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ # phi = phi & fsm.bddEnc.statesInputsMask # psi = psi & fsm.bddEnc.statesInputsMask if len(fsm.fairness_constraints) == 0: return fp(lambda Z: psi | (phi & fsm.pre_strat(Z, agents)), BDD.false(fsm.bddEnc.DDmanager)) else: nfair = nfair_gamma_states(fsm, agents) def inner(Z): res = psi for f in fsm.fairness_constraints: nf = ~f # & fsm.bddEnc.statesMask res = res | fsm.pre_strat( fp( lambda Y: (phi | psi | nfair) & (Z | nf) & (psi | fsm.pre_strat(Y, agents)), BDD.true(fsm.bddEnc.DDmanager), ), agents, ) return (psi | phi | nfair) & res return fp(inner, BDD.false(fsm.bddEnc.DDmanager))
def ceu(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying <agents>[phi U psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ #phi = phi & fsm.bddEnc.statesInputsMask #psi = psi & fsm.bddEnc.statesInputsMask if len(fsm.fairness_constraints) == 0: return fp(lambda Z : psi | (phi & fsm.pre_strat(Z, agents)), BDD.false(fsm.bddEnc.DDmanager)) else: nfair = nfair_gamma_states(fsm, agents) def inner(Z): res = psi for f in fsm.fairness_constraints: nf = ~f #& fsm.bddEnc.statesMask res = res | fsm.pre_strat(fp(lambda Y : (phi | psi | nfair) & (Z | nf) & (psi | fsm.pre_strat(Y, agents)), BDD.true(fsm.bddEnc.DDmanager)), agents) return (psi | phi | nfair) & res return fp(inner, BDD.false(fsm.bddEnc.DDmanager))
def caw(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying [agents][phi W psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ if len(fsm.fairness_constraints) == 0: return fp(lambda Z: psi | (phi & fsm.pre_nstrat(Z, agents)), BDD.true(fsm.bddEnc.DDmanager)) else: def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre_nstrat( fp( lambda Y: (psi & fair_gamma_states(fsm, agents)) | (Z & f) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager), ), agents, ) return (psi & fair_gamma_states(fsm, agents)) | res return fp(inner, BDD.true(fsm.bddEnc.DDmanager))
def eg(fsm, phi): """ Return the set of states of fsm satisfying EG phi. fsm -- a MAS representing the system phi -- a BDD representing the set of states of fsm satisfying phi """ # def inner(Z): # res = Z # for f in fsm.fairness_constraints: # res = res & fp(lambda Y : (Z & f) | (phi & fsm.weak_pre(Y)), # BDD.false(fsm.bddEnc.DDmanager)) # return phi & fsm.weak_pre(res) # # r = fp(inner, BDD.true(fsm.bddEnc.DDmanager)) # return r.forsome(fsm.bddEnc.inputsCube) phi = phi.forsome(fsm.bddEnc.inputsCube) & fsm.bddEnc.statesMask if len(fsm.fairness_constraints) == 0: return fp(lambda Z: phi & fsm.pre(Z), BDD.true(fsm.bddEnc.DDmanager)).forsome(fsm.bddEnc.inputsCube) else: def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre(fp(lambda Y: (Z & f) | (phi & fsm.pre(Y)), BDD.false(fsm.bddEnc.DDmanager))) return res return fp(inner, BDD.true(fsm.bddEnc.DDmanager)).forsome(fsm.bddEnc.inputsCube)
def eg(fsm, phi): """ Return the set of states of fsm satisfying EG phi. fsm -- a MAS representing the system phi -- a BDD representing the set of states of fsm satisfying phi """ #def inner(Z): # res = Z # for f in fsm.fairness_constraints: # res = res & fp(lambda Y : (Z & f) | (phi & fsm.weak_pre(Y)), # BDD.false(fsm.bddEnc.DDmanager)) # return phi & fsm.weak_pre(res) # #r = fp(inner, BDD.true(fsm.bddEnc.DDmanager)) #return r.forsome(fsm.bddEnc.inputsCube) phi = phi.forsome(fsm.bddEnc.inputsCube) & fsm.bddEnc.statesMask if len(fsm.fairness_constraints) == 0: return fp(lambda Z : phi & fsm.pre(Z), BDD.true(fsm.bddEnc.DDmanager)).forsome(fsm.bddEnc.inputsCube) else: def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre(fp(lambda Y : (Z & f) | (phi & fsm.pre(Y)), BDD.false(fsm.bddEnc.DDmanager))) return res return (fp(inner, BDD.true(fsm.bddEnc.DDmanager)) .forsome(fsm.bddEnc.inputsCube))
def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre(fp(lambda Y : (Z & f) | (phi & fsm.pre(Y)), BDD.false(fsm.bddEnc.DDmanager))) return res
def nfair_gamma_states(fsm, agents): """ Return the set of states in which agents cann avoid fair paths. fsm -- the model agents -- a list of agents names """ # NFair_Gamma = not([Gamma] G True) = <Gamma> F False agents = frozenset(agents) if agents not in __nfair_gamma_states: if len(fsm.fairness_constraints) == 0: __nfair_gamma_states[agents] = BDD.false(fsm.bddEnc.DDmanager) else: def inner(Z): res = BDD.false(fsm.bddEnc.DDmanager) for f in fsm.fairness_constraints: nf = ~f # & fsm.bddEnc.statesMask res = res | fsm.pre_strat( fp(lambda Y: (Z | nf) & fsm.pre_strat(Y, agents), BDD.true(fsm.bddEnc.DDmanager)), agents ) return res __nfair_gamma_states[agents] = fp(inner, BDD.false(fsm.bddEnc.DDmanager)) return __nfair_gamma_states[agents]
def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre_nstrat( fp(lambda Y: (Z & f) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager)), agents ) return res
def nfair_gamma_states(fsm, agents): """ Return the set of states in which agents cann avoid fair paths. fsm -- the model agents -- a list of agents names """ # NFair_Gamma = not([Gamma] G True) = <Gamma> F False agents = frozenset(agents) if agents not in __nfair_gamma_states: if len(fsm.fairness_constraints) == 0: __nfair_gamma_states[agents] = BDD.false(fsm.bddEnc.DDmanager) else: def inner(Z): res = BDD.false(fsm.bddEnc.DDmanager) for f in fsm.fairness_constraints: nf = ~f #& fsm.bddEnc.statesMask res = res | fsm.pre_strat(fp(lambda Y : (Z | nf) & fsm.pre_strat(Y, agents), BDD.true(fsm.bddEnc.DDmanager)), agents) return res __nfair_gamma_states[agents] = fp(inner, BDD.false(fsm.bddEnc.DDmanager)) return __nfair_gamma_states[agents]
def cew_si(fsm, agents, phi, psi, strat=None): """ Return the set of state/inputs pairs of strat satisfying <agents>[phi W psi] under full observability in strat. If strat is None, strat is considered true. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi strat -- a BDD representing allowed state/inputs pairs, or None """ if not strat: strat = BDD.true(fsm.bddEnc.DDmanager) phi = phi & fsm.bddEnc.statesInputsMask & strat psi = psi & fsm.bddEnc.statesInputsMask & strat nfair = nfair_gamma_si(fsm, agents, strat) return fp( lambda Y: (psi | phi | nfair) & (psi | fsm.pre_strat_si(Y, agents, strat)), BDD.true(fsm.bddEnc.DDmanager))
def nfair_gamma_si(fsm, agents, strat=None): """ Return the set of state/inputs pairs of strat in which agents can avoid a fair path in strat. If strat is None, it is considered true. fsm -- the model agents -- a list of agents names strat -- a BDD representing allowed state/inputs pairs, or None """ if not strat: strat = BDD.true(fsm.bddEnc.DDmanager) if len(fsm.fairness_constraints) == 0: return BDD.false(fsm.bddEnc.DDmanager) else: def inner(Z): res = BDD.false(fsm.bddEnc.DDmanager) for f in fsm.fairness_constraints: nf = ~f & fsm.bddEnc.statesMask & strat res = res | fsm.pre_strat_si( fp(lambda Y: (Z | nf) & fsm.pre_strat_si(Y, agents, strat), BDD.true(fsm.bddEnc.DDmanager)), agents, strat) return res return fp(inner, BDD.false(fsm.bddEnc.DDmanager))
def nfair_gamma_si(fsm, agents, strat=None): """ Return the set of state/inputs pairs of strat in which agents can avoid a fair path in strat. If strat is None, it is considered true. fsm -- the model agents -- a list of agents names strat -- a BDD representing allowed state/inputs pairs, or None """ if not strat: strat = BDD.true(fsm.bddEnc.DDmanager) if len(fsm.fairness_constraints) == 0: return BDD.false(fsm.bddEnc.DDmanager) else: def inner(Z): res = BDD.false(fsm.bddEnc.DDmanager) for f in fsm.fairness_constraints: nf = ~f & fsm.bddEnc.statesMask & strat res = res | fsm.pre_strat_si(fp(lambda Y : (Z | nf) & fsm.pre_strat_si(Y, agents, strat), BDD.true(fsm.bddEnc.DDmanager)), agents, strat) return res return fp(inner, BDD.false(fsm.bddEnc.DDmanager))
def inner(Z): res = BDD.false(fsm.bddEnc.DDmanager) for f in fsm.fairness_constraints: nf = ~f # & fsm.bddEnc.statesMask res = res | fsm.pre_strat( fp(lambda Y: (Z | nf) & fsm.pre_strat(Y, agents), BDD.true(fsm.bddEnc.DDmanager)), agents ) return res
def eg(fsm, phi): """ Return the set of states of fsm satisfying EG phi. fsm -- a MAS representing the system phi -- a BDD representing the set of states of fsm satisfying phi """ return fp(lambda Z: (phi & fsm.pre(Z)), BDD.true(fsm.bddEnc.DDmanager))
def inner(Z): res = BDD.false(fsm.bddEnc.DDmanager) for f in fsm.fairness_constraints: nf = ~f & fsm.bddEnc.statesMask & strat res = res | fsm.pre_strat_si( fp(lambda Y: (Z | nf) & fsm.pre_strat_si(Y, agents, strat), BDD.true(fsm.bddEnc.DDmanager)), agents, strat) return res
def ceg(fsm, agents, phi): """ Return the set of states of fsm satisfying <agents> G phi. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi """ return fp(lambda Z: phi & fsm.pre_strat(Z, agents), BDD.true(fsm.bddEnc.DDmanager))
def eu(fsm, phi, psi): """ Return the set of states of fsm satisfying E[ phi U psi ]. fsm -- a MAS representing the system phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ return fp(lambda Z: (psi | (phi & fsm.pre(Z))), BDD.false(fsm.bddEnc.DDmanager))
def ceu(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying <agents>[phi U psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ return fp(lambda Y: psi | (phi & fsm.pre_strat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager))
def inner(Z): res = psi for f in fsm.fairness_constraints: nf = ~f & fsm.bddEnc.statesMask & strat res = res | fsm.pre_strat_si( fp( lambda Y: (phi | psi | nfair) & (Z | nf) & (psi | fsm.pre_strat_si(Y, agents, strat)), BDD.true(fsm.bddEnc.DDmanager)), agents, strat) return (psi | phi | nfair) & res
def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre_nstrat(fp(lambda Y : (psi &fair_gamma_states(fsm, agents)) | (Z & f) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager)), agents) return (psi &fair_gamma_states(fsm, agents)) | res
def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre_nstrat( fp( lambda Y: (psi & fair_gamma_states(fsm, agents)) | (Z & f) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager), ), agents, ) return (psi & fair_gamma_states(fsm, agents)) | res
def cag(fsm, agents, phi): """ Return the set of states of fsm satisfying [agents] G phi. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi """ if len(fsm.fairness_constraints) == 0: return fp(lambda Z: phi & fsm.pre_nstrat(Z, agents), BDD.true(fsm.bddEnc.DDmanager)) else: def inner(Z): res = phi for f in fsm.fairness_constraints: res = res & fsm.pre_nstrat( fp(lambda Y: (Z & f) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager)), agents ) return res return fp(inner, BDD.true(fsm.bddEnc.DDmanager))
def inner(Z): res = psi for f in fsm.fairness_constraints: nf = ~f res = res | fsm.pre_strat(fp(lambda Y : (phi | psi | nfair) & (Z | nf) & (psi | fsm.pre_strat(Y, agents, strat)), BDD.true(fsm.bddEnc.DDmanager)), agents, strat) return (psi | phi | nfair) & res
def nc(fsm, group, phi): """ Return the set of states of fsm satisfying nC<group> phi fsm -- a MAS representing the system group -- a non-empty list of (str) names of agents of fsm phi -- a BDD representing the set of states of fsm satisfying phi """ # nC<g> p = mu Z. p | nE<g> Z # return fp(lambda Z: (phi | ne(fsm, group, Z)), # BDD.false(fsm.bddEnc.DDmanager)) # nC<g> p = mu Z. nE<g> (p | Z) return fp(lambda Z: ne(fsm, group, (Z | phi)), BDD.false(fsm.bddEnc.DDmanager))
def cau(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying [agents][phi U psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ return fp( lambda Y: (psi & fair_gamma_states(fsm, agents)) | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager), )
def nc(fsm, group, phi): """ Return the set of states of fsm satisfying nC<group> phi fsm -- a MAS representing the system group -- a non-empty list of (str) names of agents of fsm phi -- a BDD representing the set of states of fsm satisfying phi """ # nC<g> p = mu Z. p | nE<g> Z #return fp(lambda Z: (phi | ne(fsm, group, Z)), # BDD.false(fsm.bddEnc.DDmanager)) # nC<g> p = mu Z. nE<g> (p | Z) return fp(lambda Z: ne(fsm, group, (Z | phi)), BDD.false(fsm.bddEnc.DDmanager))
def eu(fsm, phi, psi): """ Return the set of states of fsm satisfying E[ phi U psi ]. fsm -- a MAS representing the system phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ phi = phi.forsome(fsm.bddEnc.inputsCube) & fsm.bddEnc.statesMask psi = psi.forsome(fsm.bddEnc.inputsCube) & fsm.bddEnc.statesMask return fp(lambda X : (psi & fair_states(fsm) & fsm.reachable_states) | (phi & ex(fsm, X)), BDD.false(fsm.bddEnc.DDmanager))
def eu(fsm, phi, psi): """ Return the set of states of fsm satisfying E[ phi U psi ]. fsm -- a MAS representing the system phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ phi = phi.forsome(fsm.bddEnc.inputsCube) & fsm.bddEnc.statesMask psi = psi.forsome(fsm.bddEnc.inputsCube) & fsm.bddEnc.statesMask return fp( lambda X: (psi & fair_states(fsm) & fsm.reachable_states) | (phi & ex(fsm, X)), BDD.false(fsm.bddEnc.DDmanager) )
def cew(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying [agents][phi W psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ # phi = phi & fsm.bddEnc.statesInputsMask # psi = psi & fsm.bddEnc.statesInputsMask nfair = nfair_gamma_states(fsm, agents) return fp(lambda Y: (psi | phi | nfair) & (psi | fsm.pre_strat(Y, agents)), BDD.true(fsm.bddEnc.DDmanager))
def test_tictactoe_cau(self): fsm = self.tictactoe() spec = parseATL("['circlep']['TRUE' U ('winner != circle' & 'run = stop')]")[0] agents = {atom.value for atom in spec.group} phi = evalATL(fsm, spec.left) psi = evalATL(fsm, spec.right) self.assertTrue(check(fsm, spec)) sat = evalATL(fsm, spec) self.assertEqual(sat, fp(lambda Y : psi | (phi & fsm.pre_nstrat(Y, agents)), BDD.false(fsm.bddEnc.DDmanager))) initsat = sat & fsm.init first = fsm.pick_one_state(initsat) explanation = explain_cau(fsm, first, agents, phi, psi) self.check_ceu(fsm, explanation, agents, phi, psi)
def ceg(fsm, agents, phi, strat=None): """ Return the set of states of strat satisfying <agents> G phi under full observability in strat. If strat is None, strat is considered true. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi strat -- a BDD representing allowed state/inputs pairs, or None """ nfair = nfair_gamma(fsm, agents, strat) return fp(lambda Y : (phi | nfair) & fsm.pre_strat(Y, agents, strat), BDD.true(fsm.bddEnc.DDmanager))
def cew(fsm, agents, phi, psi): """ Return the set of states of fsm satisfying [agents][phi W psi]. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi """ #phi = phi & fsm.bddEnc.statesInputsMask #psi = psi & fsm.bddEnc.statesInputsMask nfair = nfair_gamma_states(fsm, agents) return fp(lambda Y : (psi | phi | nfair) & (psi | fsm.pre_strat(Y, agents)), BDD.true(fsm.bddEnc.DDmanager))
def cew_si(fsm, agents, phi, psi, strat=None): """ Return the set of state/inputs pairs of strat satisfying <agents>[phi W psi] under full observability in strat. If strat is None, strat is considered true. fsm -- a MAS representing the system agents -- a list of agents names phi -- a BDD representing the set of states of fsm satisfying phi psi -- a BDD representing the set of states of fsm satisfying psi strat -- a BDD representing allowed state/inputs pairs, or None """ if not strat: strat = BDD.true(fsm.bddEnc.DDmanager) phi = phi & fsm.bddEnc.statesInputsMask & strat psi = psi & fsm.bddEnc.statesInputsMask & strat nfair = nfair_gamma_si(fsm, agents, strat) return fp(lambda Y : (psi | phi | nfair) & (psi | fsm.pre_strat_si(Y, agents, strat)), BDD.true(fsm.bddEnc.DDmanager))