Loading README.md +3 −3 Changes for README.md: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ Runs MuddyChildren, CherrylsBirthday, DrinkingLogicians, SallyAndAnne and Flip Coin with tests on multiple formulas. ```bash python3 -OB scripts/toy_examples.py python3 -B scripts/toy_examples.py ``` ### pySMCPDEL_tests.py Loading @@ -72,7 +72,7 @@ model checking give the same result on random PDEL formulas. ```bash python3 -OB scripts/pySMCPDEL_tests.py 5 python3 -B scripts/pySMCPDEL_tests.py 5 ``` ### hanabi_smc.py Loading Loading @@ -102,7 +102,7 @@ python3 -OB scripts/hanabi_smc.py 10 -a 2 -ch 2 -p -s -pu 100 -mc 100 Runs some unit tests on Hanabi ```bash python3 -OB scripts/hanabi_smc_tests.py python3 -B scripts/hanabi_smc_tests.py ``` ### hanabi_launcher.py Loading readme.md −207 File deleted. Show changes scripts/pytests_main.py +1 −1 Changes for scripts/pytests_main.py: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ if __name__ == '__main__': print_time = True manager_liste = [ADDManager] particular_test = "test_marginalisation_in_fonction_hard_example2"#"test_not" #"test_substract" particular_test = None # "test_marginalisation_in_fonction_hard_example2"#"test_not" #"test_substract" for manager in manager_liste: Loading scripts/toy_examples.py +44 −89 Changes for scripts/toy_examples.py: 44 added lines, 89 removed lines. Original line number Diff line number Diff line Loading @@ -54,6 +54,8 @@ def assert_and_show_announces(announce_list, structure, formula, string): res = current.modelCheck(formula) if res: print(Color.get(f"(F, {structure.pointed} ⊨ {string} ", Color.CGREEN)) else: print(Color.get(f"(F, {structure.pointed} ⊨ {string} ", Color.CRED)) assert res def give_op(S5, a, phi): Loading @@ -66,7 +68,7 @@ def give_op_w(S5, a, phi): if S5: return Kw(a, phi) else: return Box_a(a, phi) return Boxw(a, phi) def check(structure, formulas, results_pr, results_box, normalize, add=""): Loading Loading @@ -206,17 +208,11 @@ def semi_private_announcement(S5: bool): # Before announcement assert_and_show(ks, Not(give_op_w(S5,"1", Atom("p")))) assert_and_show(ks, Not(give_op_w(S5,"2", Atom("p")))) #assert ks.modelCheck(Not(give_op_w(S5,"1", Atom("p")))) #assert ks.modelCheck(Not(give_op_w(S5,"2", Atom("p")))) # After announcement add = "[! p]_{2} " assert_and_show(ann, give_op_w(S5, "2", Atom("p")), add=add) assert_and_show(ann, Not(give_op_w(S5, "1", Atom("p"))), add=add) assert_and_show(ann, give_op(S5,"1", give_op_w(S5,"2", Atom("p"))), add=add) #assert ann.modelCheck(give_op_w(S5,"2", Atom("p"))) #assert ann.modelCheck(Not(give_op_w(S5,"1", Atom("p")))) #assert ann.modelCheck(give_op(S5,"1", give_op_w(S5,"2", Atom("p")))) @timing def fully_private_annoucement(s5): Loading Loading @@ -312,76 +308,6 @@ def SallyAndAnne(): @timing def SallyAndAnneSpying(): """ version of 'sally_and_anne()' with Sally spying. """ A, S = "Anne", "Sally" V = ["p", "t"] p, t = map(Atom, V) strq = "q" q = Atom(strq) qp = Atom(prime(strq)) sp = "spying" spying = Atom(sp) spyingp = Atom(prime(sp)) order = generate_order(V, 6, getAfterSymbol()) order += generate_order([strq, sp], 6, get_id_symbol()) manager = ADDManager.create(order=order) obs = {A: Top(), S: Top()} init = BeliefStructure(V, And(p, Not(t)), {a: manager.from_formula(Top(), vars=V+prime(V)) for a in [A, S]}, ["p"], manager) top = FormulaPrecondition(Top(), manager, V) put_marble_basket = BeliefTransformer(V, [], top, obs, [], manager, v_=["t"], theta_={"t":Top()}, name="Put in basket") sally_leaves = BeliefTransformer(V, [], top, obs, [], manager, v_=["p"], theta_={"p":Bot()}, name="Sally leaves") sally_spies = BeliefTransformer(V, [sp], FormulaPrecondition(Top(), manager, V+[sp]), {A: Or(And(spying, Not(spyingp)), And(Not(spying), Not(spying))), S: Top()}, [sp],manager, name="Sally spies") res = init.apply(put_marble_basket) res = res.apply(sally_leaves) res = res.apply(sally_spies) # anne_put_the marble in the box but observed_by_sally put_marble_box = BeliefTransformer(res.vocabulary, [strq], FormulaPrecondition(Top(), manager, res.vocabulary + [strq]), {S: Equiv(q, qp), A: Equiv(q, qp)}, [strq], manager, v_=["t"], theta_={"t": And(Implies(Not(q), t), Implies(q, Bot()))}, name="Put in box") res = res.apply(put_marble_box) sally_comes_back = BeliefTransformer(V, [], top, obs, [], manager, v_=["p"], theta_={"p": Top()}, name="Sally comes back") res = res.apply(sally_comes_back) for f in [ Not(Box_a(S, Not(Atom("t")))), Box_a(A, Not(Atom("t"))), Or(Box_a(S, Atom("t")), Box_a(S, Not(Atom("t")))), Or(Box_a(A, Atom("t")), Box_a(A, Not(Atom("t")))), Box_a(A, Not(Box_a(S, Atom("t")))), Box_a(S, Box_a(A, Not(Box_a(S, Atom("t"))))) ]: assert_and_show(res, f) # assert res.modelCheck(f) Loading Loading @@ -441,6 +367,7 @@ def CherrylsBirthday(s5): " == ['16', 'jl']", Color.CGREEN)) """ @timing def DrinkingLogicians(s5): Loading @@ -459,14 +386,46 @@ def DrinkingLogicians(s5): if not s5: ks = KnowledgeStructure.to_KD45(ks) assert ks.modelCheck(Not(give_op(s5,"a", Not(bigand)))) print(ks) # assert ks.modelCheck(Not(give_op(s5, "a", Not(bigand)))) #big_and = '1' & '2' & '3' #TRUE? [! Not(give_op_w(S5,'a', bigand))][! Not(give_op_w(S5,'b', bigand))] give_op_w(S5,'c', bigand) #assert announce(announce(ks, Not(give_op_w(S5,"a", bigand))), Not(give_op_w(S5,"b", bigand))).modelCheck(give_op_w(S5,"c", bigand)) assert_and_show_announces([Not(give_op_w(s5,"a", bigand)), Not(give_op_w(s5,"b", bigand))], ks, give_op_w(s5,"c", bigand), f_1 = Not(give_op_w(s5, "a", bigand)) f_2 = Not(give_op_w(s5, "b", bigand)) f_3 = give_op_w(s5, "c", bigand) print(f_1) print(f_2) print(f_3) res = announce(announce(ks, f_1), f_2).modelCheck(f_3) print("res", res) assert_and_show_announces([f_1, f_2], ks, f_3, f"[! Not(give_op_w(S5,'a', {bigand}))][! Not(give_op_w(S5,'b', {bigand}))] give_op_w(S5,'c', {bigand})") """ @timing def DrinkingLogicians(s5): # Want a drink ? agents = ["a", "b", "c"] V = ["1", "2", "3"] Law = Top() Obs = {agents[i]: [v] for i, v in enumerate(V)} bigand = MAnd(*map(Atom, V)) order = generate_order(V, 1, getAfterSymbol()) manager = ADDManager.create(order) ks = KnowledgeStructure(V, Law, Obs, V, manager) if not s5: ks = KnowledgeStructure.to_KD45(ks) assert ks.modelCheck(Not(give_op_w(s5, 'a', bigand))) #big_and = '1' & '2' & '3' #TRUE? [! Not(Kw('a', bigand))][! Not(Kw('b', bigand))] Kw('c', bigand) assert announce(announce(ks, Not(give_op_w(s5,'a', bigand))), Not(give_op_w(s5,'b', bigand))).modelCheck(give_op_w(s5,'c', bigand)) @timing Loading Loading @@ -665,16 +624,14 @@ def run(): ks = ProbaStructure(V, Law, Obs, Pi, ["p"], manager=manager, isnormalized=False, pi_in_theta=False) ks.pi["1"].print() formulas = [] formulas.append(Box_a("1", Atom("p"))) formulas.append(Box_a("1", Not(Atom("p")))) formulas.append(Pr("1", Atom("p"), ">=", 0.49)) formulas.append(Pr("1", Atom("p"), ">=", 0.51)) for f in formulas: print(f, ks.modelCheck(f)) resultats = [False, False, True, False] for i, f in enumerate(formulas): assert ks.modelCheck(f) == resultats[i] with BlockPrint(BLOCK_PRINT, showtime=True) as blocktime: Loading @@ -698,8 +655,6 @@ def run(): fully_private_annoucement(False) print(Color.get(f">SallyAndAnne", Color.CBOLD)) SallyAndAnne() print(Color.get(f">SallyAndAnneSpying", Color.CBOLD)) SallyAndAnneSpying() ### This is ProbaStructure tests, for PDEL print(Color.get(f">FlipCoin", Color.CBOLD)) Loading src/model/SMCPDEL/pySMCDEL.py +13 −12 Changes for src/model/SMCPDEL/pySMCDEL.py: 13 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -750,9 +750,11 @@ class Structure(metaclass=ABCMeta): :return: """ assert isinstance(ks, Structure) translation = ks.translation(phi) new_law = translation.apply("x", ks.state_law) res = cls( ks.vocabulary, ks.translation(phi).apply("x", ks.state_law), new_law, ks.omega, ks.pointed, ks.manager ) return res Loading Loading @@ -1273,7 +1275,7 @@ class BeliefStructure(Structure): """ assert isinstance(phi, Formula), f"Phi need to be a Formula, not a {type(phi).__name__}." # print("In Translation Belief", phi) #print("In Translation Belief", phi) if cache is None: cache = {} Loading @@ -1282,22 +1284,21 @@ class BeliefStructure(Structure): if isinstance(form, Box_a): #print("Box_a", show) toforget = [prime(x) for x in self.vocabulary] # prime of v to_prime = {x: prime(x) for x in self.vocabulary} rec = self.translation(form.inner).rename(to_prime) traduction_prime = self.translation(form.inner).rename(to_prime) if show: print("Rec") rec.print(limit=10) print("Theta") self.state_law.print(limit=10, trueAtoms=True) lawprime = self.state_law.rename(to_prime) implies = impliesADD(self.omega[form.agent], rec, cache=cache) lawprime_and_omega = self.omega[form.agent].apply("and", lawprime, cache=cache) if show: print("Implies") implies.print(limit=10, trueAtoms=False) implies = impliesADD(lawprime_and_omega, traduction_prime, cache=cache) forget = implies.UForget(toforget) return forget return impliesADD(self.state_law.rename(to_prime), implies, cache=cache).UForget(toforget) else: Loading Loading
README.md +3 −3 Changes for README.md: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ Runs MuddyChildren, CherrylsBirthday, DrinkingLogicians, SallyAndAnne and Flip Coin with tests on multiple formulas. ```bash python3 -OB scripts/toy_examples.py python3 -B scripts/toy_examples.py ``` ### pySMCPDEL_tests.py Loading @@ -72,7 +72,7 @@ model checking give the same result on random PDEL formulas. ```bash python3 -OB scripts/pySMCPDEL_tests.py 5 python3 -B scripts/pySMCPDEL_tests.py 5 ``` ### hanabi_smc.py Loading Loading @@ -102,7 +102,7 @@ python3 -OB scripts/hanabi_smc.py 10 -a 2 -ch 2 -p -s -pu 100 -mc 100 Runs some unit tests on Hanabi ```bash python3 -OB scripts/hanabi_smc_tests.py python3 -B scripts/hanabi_smc_tests.py ``` ### hanabi_launcher.py Loading
scripts/pytests_main.py +1 −1 Changes for scripts/pytests_main.py: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ if __name__ == '__main__': print_time = True manager_liste = [ADDManager] particular_test = "test_marginalisation_in_fonction_hard_example2"#"test_not" #"test_substract" particular_test = None # "test_marginalisation_in_fonction_hard_example2"#"test_not" #"test_substract" for manager in manager_liste: Loading
scripts/toy_examples.py +44 −89 Changes for scripts/toy_examples.py: 44 added lines, 89 removed lines. Original line number Diff line number Diff line Loading @@ -54,6 +54,8 @@ def assert_and_show_announces(announce_list, structure, formula, string): res = current.modelCheck(formula) if res: print(Color.get(f"(F, {structure.pointed} ⊨ {string} ", Color.CGREEN)) else: print(Color.get(f"(F, {structure.pointed} ⊨ {string} ", Color.CRED)) assert res def give_op(S5, a, phi): Loading @@ -66,7 +68,7 @@ def give_op_w(S5, a, phi): if S5: return Kw(a, phi) else: return Box_a(a, phi) return Boxw(a, phi) def check(structure, formulas, results_pr, results_box, normalize, add=""): Loading Loading @@ -206,17 +208,11 @@ def semi_private_announcement(S5: bool): # Before announcement assert_and_show(ks, Not(give_op_w(S5,"1", Atom("p")))) assert_and_show(ks, Not(give_op_w(S5,"2", Atom("p")))) #assert ks.modelCheck(Not(give_op_w(S5,"1", Atom("p")))) #assert ks.modelCheck(Not(give_op_w(S5,"2", Atom("p")))) # After announcement add = "[! p]_{2} " assert_and_show(ann, give_op_w(S5, "2", Atom("p")), add=add) assert_and_show(ann, Not(give_op_w(S5, "1", Atom("p"))), add=add) assert_and_show(ann, give_op(S5,"1", give_op_w(S5,"2", Atom("p"))), add=add) #assert ann.modelCheck(give_op_w(S5,"2", Atom("p"))) #assert ann.modelCheck(Not(give_op_w(S5,"1", Atom("p")))) #assert ann.modelCheck(give_op(S5,"1", give_op_w(S5,"2", Atom("p")))) @timing def fully_private_annoucement(s5): Loading Loading @@ -312,76 +308,6 @@ def SallyAndAnne(): @timing def SallyAndAnneSpying(): """ version of 'sally_and_anne()' with Sally spying. """ A, S = "Anne", "Sally" V = ["p", "t"] p, t = map(Atom, V) strq = "q" q = Atom(strq) qp = Atom(prime(strq)) sp = "spying" spying = Atom(sp) spyingp = Atom(prime(sp)) order = generate_order(V, 6, getAfterSymbol()) order += generate_order([strq, sp], 6, get_id_symbol()) manager = ADDManager.create(order=order) obs = {A: Top(), S: Top()} init = BeliefStructure(V, And(p, Not(t)), {a: manager.from_formula(Top(), vars=V+prime(V)) for a in [A, S]}, ["p"], manager) top = FormulaPrecondition(Top(), manager, V) put_marble_basket = BeliefTransformer(V, [], top, obs, [], manager, v_=["t"], theta_={"t":Top()}, name="Put in basket") sally_leaves = BeliefTransformer(V, [], top, obs, [], manager, v_=["p"], theta_={"p":Bot()}, name="Sally leaves") sally_spies = BeliefTransformer(V, [sp], FormulaPrecondition(Top(), manager, V+[sp]), {A: Or(And(spying, Not(spyingp)), And(Not(spying), Not(spying))), S: Top()}, [sp],manager, name="Sally spies") res = init.apply(put_marble_basket) res = res.apply(sally_leaves) res = res.apply(sally_spies) # anne_put_the marble in the box but observed_by_sally put_marble_box = BeliefTransformer(res.vocabulary, [strq], FormulaPrecondition(Top(), manager, res.vocabulary + [strq]), {S: Equiv(q, qp), A: Equiv(q, qp)}, [strq], manager, v_=["t"], theta_={"t": And(Implies(Not(q), t), Implies(q, Bot()))}, name="Put in box") res = res.apply(put_marble_box) sally_comes_back = BeliefTransformer(V, [], top, obs, [], manager, v_=["p"], theta_={"p": Top()}, name="Sally comes back") res = res.apply(sally_comes_back) for f in [ Not(Box_a(S, Not(Atom("t")))), Box_a(A, Not(Atom("t"))), Or(Box_a(S, Atom("t")), Box_a(S, Not(Atom("t")))), Or(Box_a(A, Atom("t")), Box_a(A, Not(Atom("t")))), Box_a(A, Not(Box_a(S, Atom("t")))), Box_a(S, Box_a(A, Not(Box_a(S, Atom("t"))))) ]: assert_and_show(res, f) # assert res.modelCheck(f) Loading Loading @@ -441,6 +367,7 @@ def CherrylsBirthday(s5): " == ['16', 'jl']", Color.CGREEN)) """ @timing def DrinkingLogicians(s5): Loading @@ -459,14 +386,46 @@ def DrinkingLogicians(s5): if not s5: ks = KnowledgeStructure.to_KD45(ks) assert ks.modelCheck(Not(give_op(s5,"a", Not(bigand)))) print(ks) # assert ks.modelCheck(Not(give_op(s5, "a", Not(bigand)))) #big_and = '1' & '2' & '3' #TRUE? [! Not(give_op_w(S5,'a', bigand))][! Not(give_op_w(S5,'b', bigand))] give_op_w(S5,'c', bigand) #assert announce(announce(ks, Not(give_op_w(S5,"a", bigand))), Not(give_op_w(S5,"b", bigand))).modelCheck(give_op_w(S5,"c", bigand)) assert_and_show_announces([Not(give_op_w(s5,"a", bigand)), Not(give_op_w(s5,"b", bigand))], ks, give_op_w(s5,"c", bigand), f_1 = Not(give_op_w(s5, "a", bigand)) f_2 = Not(give_op_w(s5, "b", bigand)) f_3 = give_op_w(s5, "c", bigand) print(f_1) print(f_2) print(f_3) res = announce(announce(ks, f_1), f_2).modelCheck(f_3) print("res", res) assert_and_show_announces([f_1, f_2], ks, f_3, f"[! Not(give_op_w(S5,'a', {bigand}))][! Not(give_op_w(S5,'b', {bigand}))] give_op_w(S5,'c', {bigand})") """ @timing def DrinkingLogicians(s5): # Want a drink ? agents = ["a", "b", "c"] V = ["1", "2", "3"] Law = Top() Obs = {agents[i]: [v] for i, v in enumerate(V)} bigand = MAnd(*map(Atom, V)) order = generate_order(V, 1, getAfterSymbol()) manager = ADDManager.create(order) ks = KnowledgeStructure(V, Law, Obs, V, manager) if not s5: ks = KnowledgeStructure.to_KD45(ks) assert ks.modelCheck(Not(give_op_w(s5, 'a', bigand))) #big_and = '1' & '2' & '3' #TRUE? [! Not(Kw('a', bigand))][! Not(Kw('b', bigand))] Kw('c', bigand) assert announce(announce(ks, Not(give_op_w(s5,'a', bigand))), Not(give_op_w(s5,'b', bigand))).modelCheck(give_op_w(s5,'c', bigand)) @timing Loading Loading @@ -665,16 +624,14 @@ def run(): ks = ProbaStructure(V, Law, Obs, Pi, ["p"], manager=manager, isnormalized=False, pi_in_theta=False) ks.pi["1"].print() formulas = [] formulas.append(Box_a("1", Atom("p"))) formulas.append(Box_a("1", Not(Atom("p")))) formulas.append(Pr("1", Atom("p"), ">=", 0.49)) formulas.append(Pr("1", Atom("p"), ">=", 0.51)) for f in formulas: print(f, ks.modelCheck(f)) resultats = [False, False, True, False] for i, f in enumerate(formulas): assert ks.modelCheck(f) == resultats[i] with BlockPrint(BLOCK_PRINT, showtime=True) as blocktime: Loading @@ -698,8 +655,6 @@ def run(): fully_private_annoucement(False) print(Color.get(f">SallyAndAnne", Color.CBOLD)) SallyAndAnne() print(Color.get(f">SallyAndAnneSpying", Color.CBOLD)) SallyAndAnneSpying() ### This is ProbaStructure tests, for PDEL print(Color.get(f">FlipCoin", Color.CBOLD)) Loading
src/model/SMCPDEL/pySMCDEL.py +13 −12 Changes for src/model/SMCPDEL/pySMCDEL.py: 13 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -750,9 +750,11 @@ class Structure(metaclass=ABCMeta): :return: """ assert isinstance(ks, Structure) translation = ks.translation(phi) new_law = translation.apply("x", ks.state_law) res = cls( ks.vocabulary, ks.translation(phi).apply("x", ks.state_law), new_law, ks.omega, ks.pointed, ks.manager ) return res Loading Loading @@ -1273,7 +1275,7 @@ class BeliefStructure(Structure): """ assert isinstance(phi, Formula), f"Phi need to be a Formula, not a {type(phi).__name__}." # print("In Translation Belief", phi) #print("In Translation Belief", phi) if cache is None: cache = {} Loading @@ -1282,22 +1284,21 @@ class BeliefStructure(Structure): if isinstance(form, Box_a): #print("Box_a", show) toforget = [prime(x) for x in self.vocabulary] # prime of v to_prime = {x: prime(x) for x in self.vocabulary} rec = self.translation(form.inner).rename(to_prime) traduction_prime = self.translation(form.inner).rename(to_prime) if show: print("Rec") rec.print(limit=10) print("Theta") self.state_law.print(limit=10, trueAtoms=True) lawprime = self.state_law.rename(to_prime) implies = impliesADD(self.omega[form.agent], rec, cache=cache) lawprime_and_omega = self.omega[form.agent].apply("and", lawprime, cache=cache) if show: print("Implies") implies.print(limit=10, trueAtoms=False) implies = impliesADD(lawprime_and_omega, traduction_prime, cache=cache) forget = implies.UForget(toforget) return forget return impliesADD(self.state_law.rename(to_prime), implies, cache=cache).UForget(toforget) else: Loading