示例#1
0
    def test_ag(self):
        fsm = self.cardgame()

        # Compute AG step <= 4
        expr = Nu(Variable("Z"), And(Atom("step <= 3"), 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)

            # Inspect all nodes
            found = set()
            pending = {expl.initial}
            while len(pending) > 0:
                e = pending.pop()
                found.add(e)

                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("step <= 3"))

                pending |= {
                    edge[2]
                    for edge in expl.graph.edges if edge[0] == e
                } - found
示例#2
0
    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)
示例#3
0
 def fair(fsm):
     body = EX(Reach(And(Variable("Z"), Variable("fci"))))
     return Nu(
         Variable("Z"),
         BigAnd(body, Variable("fci"), [
             POI(Variable("fc%d" % index))
             for index in range(len(fsm.fairness_constraints))
         ]))
示例#4
0
 def EG(inv):
     return POI(Nu(Variable("Z"), And(POI(inv), EX(Variable("Z")))))
示例#5
0
 def AG(inv):
     return Nu(Variable("Z"), And(inv, AX(Variable("Z"))))