예제 #1
0
    def counters(self):
        # Build model
        class main(Module):
            v1 = Var(Boolean())
            v2 = Var(Boolean())

            act1 = IVar(Scalar(("skip", "inc")))
            act2 = IVar(Scalar(("skip", "inc")))

            TRANS = [v1.next() == (act1 == "skip").ite(v1, ~v1)]
            TRANS += [v2.next() == (act2 == "skip").ite(v2, ~v2)]

        # Define agents
        a1 = Agent("a1", {main.v1}, {main.act1})
        a2 = Agent("a2", {main.v2}, {main.act2})
        g = Group("g", a1, a2)

        # Load model
        glob.load(main)

        # Get MAS
        mas = glob.mas({a1, a2, g})

        self.assertIsNotNone(mas)
        return mas
예제 #2
0
    def coins(self):
        # Build model
        class main(Module):
            c1 = Var(Scalar(('none', 'head', 'tail')))
            c2 = Var(Scalar(('none', 'head', 'tail')))
            result = Var(Scalar(('none', 'win', 'lose')))

            act1 = IVar(Scalar(("different", "equal")))
            act2 = IVar(Scalar(("different", "equal")))

            INIT = [(c1 == 'none') & (c2 == 'none') & (result == 'none')]

            TRANS = []

            TRANS += [
                ((c1 == 'none') &
                 (c2 == 'none')).implies(c1.next().in_(Set(('head', 'tail')))
                                         & c2.next().in_(Set(('head', 'tail')))
                                         & (result.next() == result))
            ]
            TRANS += [
                ((c1 != 'none') & (c2 != 'none') & (result == 'none')).implies(
                    (c1.next() == c1) & (c2.next() == c2)
                    & (result.next() == ((
                        (c1 == c2) & (act1 == 'equal') & (act2 == 'equal')) | (
                            (c1 != c2) & (act1 == 'different') &
                            (act2 == 'different'))).ite('win', 'lose')))
            ]
            TRANS += [(result != 'none').implies((result.next() == result)
                                                 & (c1.next() == c1)
                                                 & (c2.next() == c2))]

        # Define agents
        a1 = Agent("a1", {main.c1}, {main.act1})
        a2 = Agent("a2", {main.c2}, {main.act2})
        g = Group("g", a1, a2)

        # Load model
        glob.load(main)

        # Get MAS
        mas = glob.mas({a1, a2, g})

        self.assertIsNotNone(mas)
        return mas