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
Esempio n. 2
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
    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
Esempio n. 4
0
 def test_check_mas_uniform_choice_ok(self):
     class agent(md.Module):
         v = md.Var(md.Boolean())
         a = md.IVar(md.Boolean())
         INIT = v
         TRANS = (v.next() == a)
     class main(md.Module):
         a1 = md.Var(agent())
         a2 = md.Var(agent())
     
     agents = {Agent("a1", {main.a1.v}, {main.a1.a}),
               Agent("a2", {main.a2.v}, {main.a2.a})}
     
     glob.load(agent, main)
     mas = glob.mas(agents=agents)
     self.assertIsNotNone(mas)
     self.assertTrue(mas.check_uniform_choice().is_false())
Esempio n. 5
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
Esempio n. 6
0
    def test_check_mas_uniform_choice_ok(self):
        class agent(md.Module):
            v = md.Var(md.Boolean())
            a = md.IVar(md.Boolean())
            INIT = v
            TRANS = (v.next() == a)

        class main(md.Module):
            a1 = md.Var(agent())
            a2 = md.Var(agent())

        agents = {
            Agent("a1", {main.a1.v}, {main.a1.a}),
            Agent("a2", {main.a2.v}, {main.a2.a})
        }

        glob.load(agent, main)
        mas = glob.mas(agents=agents)
        self.assertIsNotNone(mas)
        self.assertTrue(mas.check_uniform_choice().is_false())
Esempio n. 7
0
 def test_check_mas_free_choice_ko(self):
     class agent(md.Module):
         v = md.Var(md.Boolean())
         a = md.IVar(md.Boolean())
         INIT = v
         TRANS = (v.next() == a)
     class main(md.Module):
         a1 = md.Var(agent())
         a2 = md.Var(agent())
         TRANS = a2.a.implies(a1.a)
     
     agents = {Agent("a1", {main.a1.v, main.a2.v}, {main.a1.a}),
               Agent("a2", {main.a1.v, main.a2.v}, {main.a2.a})}
     
     glob.load(agent, main)
     mas = glob.mas(agents=agents)
     self.assertIsNotNone(mas)
     
     free_choice = mas.check_free_choice()
     self.assertTrue(free_choice.isnot_false())
Esempio n. 8
0
    def test_check_mas_free_choice_ko(self):
        class agent(md.Module):
            v = md.Var(md.Boolean())
            a = md.IVar(md.Boolean())
            INIT = v
            TRANS = (v.next() == a)

        class main(md.Module):
            a1 = md.Var(agent())
            a2 = md.Var(agent())
            TRANS = a2.a.implies(a1.a)

        agents = {
            Agent("a1", {main.a1.v, main.a2.v}, {main.a1.a}),
            Agent("a2", {main.a1.v, main.a2.v}, {main.a2.a})
        }

        glob.load(agent, main)
        mas = glob.mas(agents=agents)
        self.assertIsNotNone(mas)

        free_choice = mas.check_free_choice()
        self.assertTrue(free_choice.isnot_false())