Esempio n. 1
0
def test_not_eq_depth_three_one_child():
    node_one = Node('s', Not(Atom('p')),
                    [Node('s', Atom('p'), [Node('s', Atom('r'), [])])])

    node_two = Node('s', Not(Atom('p')),
                    [Node('s', Atom('p'), [Node('s', Atom('f'), [])])])
    assert not node_one == node_two
Esempio n. 2
0
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')
Esempio n. 3
0
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
Esempio n. 4
0
 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
Esempio n. 5
0
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
Esempio n. 6
0
    def __init__(self):
        worlds = [
            World('RWW', {
                '1:R': True,
                '2:W': True,
                '3:W': True
            }),
            World('RRW', {
                '1:R': True,
                '2:R': True,
                '3:W': True
            }),
            World('RRR', {
                '1:R': True,
                '2:R': True,
                '3:R': True
            }),
            World('WRR', {
                '1:W': True,
                '2:R': True,
                '3:R': True
            }),
            World('WWR', {
                '1:W': True,
                '2:W': True,
                '3:R': True
            }),
            World('RWR', {
                '1:R': True,
                '2:W': True,
                '3:R': True
            }),
            World('WRW', {
                '1:W': True,
                '2:R': True,
                '3:W': True
            }),
            World('WWW', {
                '1:W': True,
                '2:W': True,
                '3:W': True
            }),
        ]

        relations = {
            '1': {('RWW', 'WWW'), ('RRW', 'WRW'), ('RWR', 'WWR'),
                  ('WRR', 'RRR')},
            '2': {('RWR', 'RRR'), ('RWW', 'RRW'), ('WRR', 'WWR'),
                  ('WWW', 'WRW')},
            '3': {('WWR', 'WWW'), ('RRR', 'RRW'), ('RWW', 'RWR'),
                  ('WRW', 'WRR')}
        }

        relations.update(add_reflexive_edges(worlds, relations))
        relations.update(add_symmetric_edges(relations))

        self.ks = KripkeStructure(worlds, relations)

        # Wise man ONE does not know whether he wears a red hat or not
        self.knowledge_base.append(
            And(Not(Box_a('1', Atom('1:R'))), Not(Box_a('1',
                                                        Not(Atom('1:R'))))))

        # This announcement implies that either second or third wise man wears a red hat.
        self.knowledge_base.append(Box_star(Or(Atom('2:R'), Atom('3:R'))))

        # Wise man TWO does not know whether he wears a red hat or not
        self.knowledge_base.append(
            And(Not(Box_a('2', Atom('2:R'))), Not(Box_a('2',
                                                        Not(Atom('2:R'))))))

        # This announcement implies that third men has be the one, who wears a red hat
        self.knowledge_base.append(Box_a('3', Atom('3:R')))