def test_af(self): fsm = self.cardgame() # Compute AF step = 2 expr = Mu(Variable("Z"), Or(Atom("step = 2"), Box(Variable("Z")))) for state in fsm.pick_all_states( expr.eval(fsm) & fsm.reachable_states): expl = expr.explain(fsm, state) self.assertEqual(expl.initial.state, state) dot = expl.dot() self.assertIsNotNone(dot) # Follow one path of expl and check that step = 2 is reached e = expl.initial while e is not None: self.assertEqual(e.fsm, fsm) self.assertTrue(e.state <= expr.eval(fsm)) self.assertEqual(e.context, {}) self.assertTrue( len(list(edge for edge in expl.graph.edges if edge[0] == e)) > 0 or len(list(edge for edge in expl.graph.edges if edge[0] == e)) <= 0 and e.formula == Atom("step = 2")) if len(list(edge for edge in expl.graph.edges if edge[0] == e)) > 0: e = next(edge for edge in expl.graph.edges if edge[0] == e)[2] else: e = None
def test_ef(self): fsm = self.cardgame() # Compute EF win expr = Mu(Variable("Z"), Or(Atom("win"), Diamond(Variable("Z")))) for state in fsm.pick_all_states( expr.eval(fsm) & fsm.reachable_states): expl = expr.explain(fsm, state) self.assertEqual(expl.initial.state, state) dot = expl.dot() self.assertIsNotNone(dot) e = expl.initial while e is not None: self.assertEqual(e.fsm, fsm) self.assertTrue(e.state <= expr.eval(fsm)) self.assertEqual(e.context, {}) self.assertTrue( len(list(edge for edge in expl.graph.edges if edge[0] == e)) == 1 or len(list(edge for edge in expl.graph.edges if edge[0] == e)) <= 0 and e.formula == Atom("win")) if len(list(edge for edge in expl.graph.edges if edge[0] == e)) > 0: e = next(edge for edge in expl.graph.edges if edge[0] == e)[2] else: e = None
def test_eval_fp(self): fsm = self.cardgame() s0 = eval_simple_expression(fsm, "step = 0") s1 = eval_simple_expression(fsm, "step = 1") s2 = eval_simple_expression(fsm, "step = 2") pa = eval_simple_expression(fsm, "pcard = Ac") pk = eval_simple_expression(fsm, "pcard = K") pq = eval_simple_expression(fsm, "pcard = Q") da = eval_simple_expression(fsm, "dcard = Ac") dk = eval_simple_expression(fsm, "dcard = K") dq = eval_simple_expression(fsm, "dcard = Q") dda = eval_simple_expression(fsm, "ddcard = Ac") ddk = eval_simple_expression(fsm, "ddcard = K") ddq = eval_simple_expression(fsm, "ddcard = Q") win = eval_simple_expression(fsm, "win") lose = eval_simple_expression(fsm, "lose") true = eval_simple_expression(fsm, "TRUE") false = eval_simple_expression(fsm, "FALSE") # mu Z. win | pre(Z) R = Mu(Variable("Z"), Or(Atom("win"), Diamond(Variable("Z")))) self.assertTrue(s0 <= R.eval(fsm)) # nu Z. ~win & pre(Z) NW = Nu(Variable("Z"), And(Not(Atom("win")), Diamond(Variable("Z")))) self.assertTrue(NW.eval(fsm) <= ~win)
def test_eval_boolean(self): fsm = self.cardgame() s0 = eval_simple_expression(fsm, "step = 0") s1 = eval_simple_expression(fsm, "step = 1") pa = eval_simple_expression(fsm, "pcard = Ac") win = eval_simple_expression(fsm, "win") self.assertEqual(s0 & s1, And(Atom("step = 0"), Atom("step = 1")).eval(fsm)) self.assertEqual(s0 | s1, Or(Atom("step = 0"), Atom("step = 1")).eval(fsm)) self.assertEqual(~win, Not(Atom("win")).eval(fsm))
def Reach(target): return Mu(Variable("W"), Or(target, EX(Variable("W"))))
def EF(target): return Mu(Variable("Z"), Or(target, EX(Variable("Z"))))
def Reach(target): return POI(Mu(Variable("Z"), Or(POI(target), EX(Variable("Z")))))