Esempio n. 1
0
    def test_split(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")

        ngamma_cube = (fsm.bddEnc.inputsCube -
                       fsm.inputs_cube_for_agents({"player"}))

        strats = split(fsm, fsm.protocol({"player"}), {"player"})

        self.assertEqual(len(strats), 8)
Esempio n. 2
0
    def test_split(self):
        fsm = self.little()

        aa = eval_simple_expression(fsm, "a.a = 1")
        ap = eval_simple_expression(fsm, "a.p = 1")
        ba = eval_simple_expression(fsm, "b.a = 1")
        bq = eval_simple_expression(fsm, "b.q = 1")
        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        gamma_inputs = [
            var for agent in {"a"} for var in fsm.agents_inputvars[agent]
        ]
        gamma_cube = fsm.bddEnc.cube_for_inputs_vars(gamma_inputs)
        ngamma_cube = fsm.bddEnc.inputsCube - gamma_cube

        strats = split(fsm, fsm.protocol({"a"}), {"a"})

        commstrat = (((~ap & bq & ~aa) |
                      (~ap & ~bq & ~aa)).forsome(ngamma_cube)
                     & fsm.protocol({"a"}))
        firststrat = (((ap & bq & aa) | (ap & ~bq & aa)).forsome(ngamma_cube)
                      & fsm.protocol({"a"}))
        secstrat = (((ap & bq & ~aa) | (ap & ~bq & ~aa)).forsome(ngamma_cube)
                    & fsm.protocol({"a"}))

        self.assertTrue((commstrat | firststrat) in strats)
        self.assertTrue((commstrat | secstrat) in strats)

        self.assertSetEqual({commstrat | firststrat, commstrat | secstrat},
                            strats)
Esempio n. 3
0
 def test_split(self):
     fsm = self.little()
     
     aa = eval_simple_expression(fsm, "a.a = 1")
     ap = eval_simple_expression(fsm, "a.p = 1")
     ba = eval_simple_expression(fsm, "b.a = 1")
     bq = eval_simple_expression(fsm, "b.q = 1")
     true = eval_simple_expression(fsm, "TRUE")
     false = eval_simple_expression(fsm, "FALSE")
     
     gamma_inputs = [var
                     for agent in {"a"}
                     for var in fsm.agents_inputvars[agent]]
     gamma_cube = fsm.bddEnc.cube_for_inputs_vars(gamma_inputs)
     ngamma_cube = fsm.bddEnc.inputsCube - gamma_cube
     
     strats = split(fsm, fsm.protocol({"a"}), {"a"})
         
     commstrat = (((~ap & bq & ~aa) | (~ap & ~bq & ~aa)).forsome(ngamma_cube) &
                  fsm.protocol({"a"}))
     firststrat = (((ap & bq & aa) | (ap & ~bq & aa)).forsome(ngamma_cube) &
                   fsm.protocol({"a"}))
     secstrat = (((ap & bq & ~aa) | (ap & ~bq & ~aa)).forsome(ngamma_cube) &
                 fsm.protocol({"a"}))
     
     self.assertTrue((commstrat | firststrat) in strats)
     self.assertTrue((commstrat | secstrat) in strats)
     
     self.assertSetEqual({commstrat | firststrat, commstrat | secstrat},
                         strats)
Esempio n. 4
0
    def test_split(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")

        ngamma_cube = fsm.bddEnc.inputsCube - fsm.inputs_cube_for_agents({"player"})

        strats = split(fsm, fsm.protocol({"player"}), {"player"})

        self.assertEqual(len(strats), 8)
Esempio n. 5
0
    def test_split_cardgame3(self):
        fsm = self.cardgame3()
        agents = {'player'}

        strats = set()
        nbstrats = 0
        for strat in split(fsm, fsm.protocol(agents), agents):
            nbstrats += 1
            self.assertTrue(strat not in strats)
            strats.add(strat)
        self.assertEqual(nbstrats, 8)
        self.assertEqual(len(strats), nbstrats)
Esempio n. 6
0
    def test_nfair_gamma_si_trans2_fair(self):
        fsm = self.trans2_fair()

        #print("nfair_[transmitter] SI without strategies")
        #self.show_si(fsm, nfair_gamma_si(fsm, {'transmitter'}) &
        #                  fsm.protocol({'transmitter','sender'}))

        #print("nfair_[sender] SI without strategies")
        #self.show_si(fsm, nfair_gamma_si(fsm, {'sender'}))

        strats = split(fsm, fsm.protocol({'transmitter'}), {'transmitter'})
        strat = strats.pop()
Esempio n. 7
0
    def test_nfair_gamma_si_trans2_fair(self):
        fsm = self.trans2_fair()

        # print("nfair_[transmitter] SI without strategies")
        # self.show_si(fsm, nfair_gamma_si(fsm, {'transmitter'}) &
        #                  fsm.protocol({'transmitter','sender'}))

        # print("nfair_[sender] SI without strategies")
        # self.show_si(fsm, nfair_gamma_si(fsm, {'sender'}))

        strats = split(fsm, fsm.protocol({"transmitter"}), {"transmitter"})
        strat = strats.pop()
Esempio n. 8
0
 def test_split_cardgame3(self):
     fsm = self.cardgame3()
     agents = {'player'}
     
     strats = set()
     nbstrats = 0
     for strat in split(fsm, fsm.protocol(agents), agents):
         nbstrats += 1
         self.assertTrue(strat not in strats)
         strats.add(strat)
     self.assertEqual(nbstrats, 8)
     self.assertEqual(len(strats), nbstrats)
     
Esempio n. 9
0
    def test_nfair_gamma_si(self):
        fsm = self.cardgame_post_fair()

        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")

        pan = eval_simple_expression(fsm, "player.action = none")
        pak = eval_simple_expression(fsm, "player.action = keep")
        pas = eval_simple_expression(fsm, "player.action = swap")

        dan = eval_simple_expression(fsm, "dealer.action = none")

        win = eval_simple_expression(fsm, "win")
        lose = eval_simple_expression(fsm, "lose")

        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        agents = {'dealer'}
        strats = split(fsm, fsm.protocol(agents), agents)
        strat = strats.pop()
        nf = ~fsm.fairness_constraints[0] & fsm.bddEnc.statesInputsMask

        self.assertEqual(
            nf
            & fsm.pre_strat_si(BDD.true(fsm.bddEnc.DDmanager), agents, strat),
            nf
            & fsm.pre_strat_si(BDD.true(fsm.bddEnc.DDmanager), agents, strat)
            & fsm.bddEnc.statesInputsMask)

        nfp = nfair_gamma_si(fsm, {'player'})
        nfd = nfair_gamma_si(fsm, {'dealer'})

        self.assertTrue(nfp.is_false())
        self.assertTrue(fsm.protocol({'dealer'}) <= nfd)
Esempio n. 10
0
    def test_nfair_gamma(self):
        fsm = self.transmission_post_fair()

        transmit = eval_simple_expression(fsm, "transmitter.action = transmit")
        false = BDD.false(fsm.bddEnc.DDmanager)

        self.assertTrue(fsm.reachable_states <= nfair_gamma(fsm, {"transmitter"}))

        self.assertEqual(false, nfair_gamma(fsm, {"sender"}))

        strats = split(fsm, fsm.protocol({"transmitter"}), {"transmitter"})
        for strat in strats:
            if (strat & transmit).isnot_false():
                self.assertTrue(nfair_gamma(fsm, {"transmitter"}, strat).is_false())
            else:
                self.assertTrue(fsm.reachable_states <= nfair_gamma(fsm, {"transmitter"}, strat))
Esempio n. 11
0
    def test_nfair_gamma_si(self):
        fsm = self.cardgame_post_fair()

        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")

        pan = eval_simple_expression(fsm, "player.action = none")
        pak = eval_simple_expression(fsm, "player.action = keep")
        pas = eval_simple_expression(fsm, "player.action = swap")

        dan = eval_simple_expression(fsm, "dealer.action = none")

        win = eval_simple_expression(fsm, "win")
        lose = eval_simple_expression(fsm, "lose")

        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        agents = {"dealer"}
        strats = split(fsm, fsm.protocol(agents), agents)
        strat = strats.pop()
        nf = ~fsm.fairness_constraints[0] & fsm.bddEnc.statesInputsMask

        self.assertEqual(
            nf & fsm.pre_strat_si(BDD.true(fsm.bddEnc.DDmanager), agents, strat),
            nf & fsm.pre_strat_si(BDD.true(fsm.bddEnc.DDmanager), agents, strat) & fsm.bddEnc.statesInputsMask,
        )

        nfp = nfair_gamma_si(fsm, {"player"})
        nfd = nfair_gamma_si(fsm, {"dealer"})

        self.assertTrue(nfp.is_false())
        self.assertTrue(fsm.protocol({"dealer"}) <= nfd)
Esempio n. 12
0
    def test_nfair_gamma(self):
        fsm = self.transmission_post_fair()

        transmit = eval_simple_expression(fsm, "transmitter.action = transmit")
        false = BDD.false(fsm.bddEnc.DDmanager)

        self.assertTrue(
            fsm.reachable_states <= nfair_gamma(fsm, {'transmitter'}))

        self.assertEqual(false, nfair_gamma(fsm, {'sender'}))

        strats = split(fsm, fsm.protocol({'transmitter'}), {'transmitter'})
        for strat in strats:
            if (strat & transmit).isnot_false():
                self.assertTrue(
                    nfair_gamma(fsm, {'transmitter'}, strat).is_false())
            else:
                self.assertTrue(fsm.reachable_states <= nfair_gamma(
                    fsm, {'transmitter'}, strat))
Esempio n. 13
0
    def test_nfair_gamma_cardgame_post_fair(self):
        fsm = self.cardgame_post_fair()

        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")

        pan = eval_simple_expression(fsm, "player.action = none")
        pak = eval_simple_expression(fsm, "player.action = keep")
        pas = eval_simple_expression(fsm, "player.action = swap")

        dan = eval_simple_expression(fsm, "dealer.action = none")

        win = eval_simple_expression(fsm, "win")
        lose = eval_simple_expression(fsm, "lose")

        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        self.assertEqual(false, nfair_gamma(fsm, {'player'}))

        self.assertTrue(
            fsm.reachable_states
            & fsm.bddEnc.statesInputsMask <= nfair_gamma(fsm, {'dealer'}))

        strats = split(fsm, fsm.protocol({'dealer'}), {'dealer'})
        for strat in strats:
            self.assertTrue(fsm.reachable_states & fsm.bddEnc.statesInputsMask
                            <= nfair_gamma(fsm, {'dealer'}, strat))
Esempio n. 14
0
    def test_nfair_gamma_cardgame_post_fair(self):
        fsm = self.cardgame_post_fair()

        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")

        pan = eval_simple_expression(fsm, "player.action = none")
        pak = eval_simple_expression(fsm, "player.action = keep")
        pas = eval_simple_expression(fsm, "player.action = swap")

        dan = eval_simple_expression(fsm, "dealer.action = none")

        win = eval_simple_expression(fsm, "win")
        lose = eval_simple_expression(fsm, "lose")

        true = eval_simple_expression(fsm, "TRUE")
        false = eval_simple_expression(fsm, "FALSE")

        self.assertEqual(false, nfair_gamma(fsm, {"player"}))

        self.assertTrue(fsm.reachable_states & fsm.bddEnc.statesInputsMask <= nfair_gamma(fsm, {"dealer"}))

        strats = split(fsm, fsm.protocol({"dealer"}), {"dealer"})
        for strat in strats:
            self.assertTrue(fsm.reachable_states & fsm.bddEnc.statesInputsMask <= nfair_gamma(fsm, {"dealer"}, strat))