def test_eq_depth_three_two_children(): node_one = Node('s', Not(Atom('p')), [ Node('s', Atom('p'), [Node('s', Atom('r'), []), Node('s', Atom('f'), [])]) ]) node_two = node_one assert node_one == node_two
def test_semantic_box_p_implies_p(): worlds = [ World('1', {'p': False}), World('2', {'p': True}), World('3', {'p': True}), ] relations = {('1', '2'), ('1', '3')} ks = KripkeStructure(worlds, relations) mpl = Implies(Box(Atom('p')), Atom('p')) assert False == mpl.semantic(ks, '1')
def test_semantic_box_a_true(): worlds = [World('1', {'p': False}), World('2', {'p': True})] relations = {'a': {('1', '2'), ('1', '1')}} ks = KripkeStructure(worlds, relations) mpl = Diamond_a('a', Atom('p')) assert True == mpl.semantic(ks, '1')
def test_semantic_box_a_two_agents(): worlds = [World('1', {'p': False}), World('2', {'p': False})] relations = {'a': {('1', '2')}, 'b': {}} ks = KripkeStructure(worlds, relations) mpl = Diamond_a('b', Atom('p')) assert False == mpl.semantic(ks, '1')
def test_semantic_box_a_empty_relations(): worlds = [World('1', {'p': False}), World('2', {'p': True})] relations = {} ks = KripkeStructure(worlds, relations) mpl = Diamond_a('a', Atom('p')) assert False == mpl.semantic(ks, '1')
def test_semantic_not_q(): worlds = [ World('1', {'q': False}) ] relations = {('1', '2'), ('1', '3')} ks = KripkeStructure(worlds, relations) mpl = Not(Atom('q')) assert True == mpl.semantic(ks, '1')
def test_nodes_not_follow_formula(): worlds = [ World('RWW', { '1:R': True, '2:W': True, '3:W': True }), World('RRW', { '1:R': True, '2:R': True, '3:W': True }) ] relations = {} ks = KripkeStructure(worlds, relations) formula = And(Atom('2:W'), Atom('3:W')) expected_result = ['RRW'] result = ks.nodes_not_follow_formula(formula) assert expected_result == result
def test_semantic_diamond_p_three_worlds_false(): worlds = [ World('1', {'p': False}), World('2', {'p': True}), World('3', {'p': False}), ] relations = {('1', '2'), ('1', '3')} ks = KripkeStructure(worlds, relations) mpl = Diamond(Atom('p')) assert True == mpl.semantic(ks, '1')
def test_not_eq_depth_three_dif_encaps(): node_one = Node('s', Not(Atom('p')), [ Node('s', Atom('p'), [Node('s', Atom('r'), []), Node('s', Atom('f'), [])]) ]) node_two = Node('s', Not(Atom('p')), [Node('s', Atom('p'), [Node('s', Atom('r'), [])])]) assert not node_one == node_two
def update_structure(self, agents): print("Updating kripke structure:") for agent in agents: print(agent, " kb: ", agent.kb) if (agent.alive): for formula in agent.kb: # formula only has to be evaluated once ( prop not evaluated yet? -> False) if (agent.kb[formula][1] == False): if ("v" in formula): formula_list = formula.split("v") f1 = Atom(formula_list[0]) f2 = Atom(formula_list[1]) final_formula = Or(f1, f2) for i in range(len(formula_list) - 2): f = Atom(formula_list[i + 2]) final_formula = Or(final_formula, f) else: f = Atom(formula) # if the formula in the agent's knowledge base is false, negate the formula if (agent.kb[formula][0] == False): f = Not(Atom(formula)) self.ks = self.ks.solve_a(str(agent.unique_id), f) # set formula to True, so that it's not going to be evaluated again in the structure update agent.kb[formula][1] = True
def kill(self, target, room): output = str(self) + " kills " + str(target) + " in room " + str(self.position) + "!" print(output) self.model.print_queue.append(output) # victim agent is now no longer alive; remove him from murderer's target list target.alive = False self.targets.remove(target) # update knowledge of target f = (str(self.unique_id) + str(target.unique_id)) target.kb[f] = [True, True] f = Atom(f) self.model.kripke_model.ks = self.model.kripke_model.ks.solve_a(str(target.unique_id), f) # update knowledge of any observers present for agent in room: if (agent != self and agent != target): # add new knowledge to kb of witness agent.kb[(str(self.unique_id) + str(target.unique_id))] = [True, False]
def test_semantic_diamond_p_one_world_true(): worlds = [World('1', {'p': True})] relations = {} ks = KripkeStructure(worlds, relations) mpl = Diamond(Atom('p')) assert False == mpl.semantic(ks, '1')
def test_box_star_two_agents_box_phi_hold(): ks = KripkeStructure([World('1', {'p': True}), World('2', {'p': True})], {'a1': {('1', '2')}, 'a2': {('1', '2')}}) formula = Box_star(Atom('p')) assert formula.semantic(ks, '1')
from mlsolver.formula import Atom, Box, Or, Box_a, And, Box_star from mlsolver.AcesAndEights import AcesAndEights # Create new Aces and Eights Kripke agentA = AcesAndEights() # The Game is (88, AA, AA) # And(Not(Box_a('1', Atom('1:R'))), Not(Box_a('1', Not(Atom('1:R'))) new_model = agentA.ks.solve(And(And(Atom('2AA'), Atom('3AA')), Atom('188'))) print("Test")
def test_semantic_diamond_p_one_world_reflex_edge_false(): worlds = [World('1', {'p': False})] relations = {('1', '1')} ks = KripkeStructure(worlds, relations) mpl = Diamond(Atom('p')) assert False == mpl.semantic(ks, '1')
def test_node_not_eq_with_cild(): node_one = Node('s', Not(Atom('p')), [Node('s', Atom('p'), [])]) node_two = Node('s', Not(Atom('p')), [Node('s', Atom('q'), [])]) assert not node_one == node_two
def test_semantic_box_p_two_worlds_false(): worlds = [World('1', {'p': False}), World('2', {'p': False})] relations = {('1', '2')} ks = KripkeStructure(worlds, relations) mpl = Box(Atom('p')) assert False == mpl.semantic(ks, '1')
def test_box_star_three_agents_box_phi_not_hold(): ks = KripkeStructure( [World('1', {'p': True}), World('2', {'p': False}), World('3', {'p': True}), World('4', {'p': True})], {'agent_1': {('1', '2'), ('1', '1')}, 'agent_2': {('1', '3'), ('1', '1')}, 'agent_3': {('1', '4'), ('1', '1')}}) formula = Box_star(Atom('p')) assert not formula.semantic(ks, '1')
def test_ks_one_world(): worlds = [World('1', {'p': True})] relations = {} ks = KripkeStructure(worlds, relations) atom = Atom('p') assert True == atom.semantic(ks, '1')
def test_next_and_not_derived(): node = Node('s', And(Atom('p'), Atom('q')), []) next_node = node.__next__() assert next_node is node
def test_semantic_p_and_q(): worlds = [World('1', {'p': True, 'q': True})] relations = {} ks = KripkeStructure(worlds, relations) mpl = And(Atom('p'), Atom('q')) assert True == mpl.semantic(ks, '1')
def test_next_and_is_derived(): node = Node('s', And(Atom('p'), Atom('q')), [Leaf('s', 'p', [Leaf('s', 'q', [], True)], True)]) node.is_derived = True next_node = node.__next__() assert next_node is None
def test_eq_node_none(): node = Node('s', Atom('p'), []) assert node is not None
def test_eq_depth_three_with_and(): node_one = Node('s', And(Atom('p'), Atom('q')), [Node('s', Atom('p'), [Node('s', Atom('q'), [])])]) node_two = node_one assert node_one == node_two
def test_atom_is_false_if_q_not_in_V(): worlds = [World('1', {'p': True})] relations = {} ks = KripkeStructure(worlds, relations) atom = Atom('q') assert False == atom.semantic(ks, '1')
def test_box_star_empty_relations(): ks = KripkeStructure([World('1', {'p': True})], {}) formula = Box_star(Atom('p')) assert formula.semantic(ks, '1')
def test_atom_init(): atom = Atom('p') assert atom.name == 'p'
def test_semantic_box_p_one_world_true(): worlds = [World('1', {'p': True})] relations = {} ks = KripkeStructure(worlds, relations) mpl = Box(Atom('p')) assert True == mpl.semantic(ks, '1')
def test_next_atom_is_derived(): node = Node('s', Atom('p'), []) node.is_derived = True next_node = node.__next__() assert next_node is None
def test_node_is_eq_trivial_case(): node_one = Node('s', Atom('p'), []) node_two = Node('s', Atom('p'), []) assert node_one == node_two