Beispiel #1
0
def test_get_basis():
    """Test get_basis function for Formula."""
    point = Attribute('point', [Point('x', 'x', 'x', 'x')])
    fake = Attribute('fake', [])
    r_is_on = Relation('R1(h1, h2, h3) <=> is_on(h1, h2, h3)',
                       ['point', 'point', 'point'], 1)
    r_not_same_point = Relation('R2(h1, h2) <=> not_same_point(h1, h2)',
                                ['point', 'point'], 2)
    r_clocks_unequal = Relation('R3(h1, h2) <=> clocks_unequal(h1, h2)',
                                ['point', 'point'], 3)
    r_can_observe = Relation(
        'R4(p, sp_loc, wls, wle) <=> can_observe(p, sp_loc, wls, wle)',
        ['point', 'point', 'point', 'point'], 4)
    r_fake = Relation(
        'R5(p, wl1s, wl1e, wl2s, wl2e) <=> meets(p, wl1s, wl1e, wl2s, wl2e)',
        ['fake', 'point', 'fake', 'fake', 'point'], 5)

    attribute_structure = AttributeStructure(point, fake, r_is_on,
                                             r_not_same_point,
                                             r_clocks_unequal, r_can_observe,
                                             r_fake)

    rs_is_on = RelationSymbol('IS_ON', 3)
    rs_not_same_point = RelationSymbol('NOT_SAME_POINT', 2)
    rs_clocks_unequal = RelationSymbol('CLOCKS_UNEQUAL', 2)
    rs_can_observe = RelationSymbol('CAN_OBSERVE', 4)
    rs_fake = RelationSymbol('FAKE', 5)

    vocabulary = Vocabulary(['P1', 'P2', 'P3', 'P4', 'P5'], [
        rs_is_on, rs_not_same_point, rs_clocks_unequal, rs_can_observe, rs_fake
    ], [])

    profiles = [[rs_is_on, ('point', 1), ('point', 2), ('point', 3)],
                [rs_not_same_point, ('point', 1), ('point', 2)],
                [rs_clocks_unequal, ('point', 1), ('point', 2)],
                [
                    rs_can_observe, ('point', 1), ('point', 2), ('point', 3),
                    ('point', 4)
                ],
                [
                    rs_fake, ('fake', 1), ('point', 2), ('fake', 3),
                    ('fake', 4), ('point', 5)
                ]]

    mapping = {
        rs_is_on: 1,
        rs_not_same_point: 2,
        rs_clocks_unequal: 3,
        rs_can_observe: 4,
        rs_fake: 5
    }

    attribute_interpretation = AttributeInterpretation(vocabulary,
                                                       attribute_structure,
                                                       mapping, profiles)

    objects = ['p1', 'p2', 'p3', 'p4', 'p5']
    attribute_system = AttributeSystem(attribute_structure, objects)
    p = ConstantAssignment(vocabulary, attribute_system, {
        'P1': 'p1',
        'P2': 'p2',
        'P3': 'p3',
        'P4': 'p4',
        'P5': 'p5'
    })

    named_state = NamedState(
        attribute_system, p, {
            ('point', 'p1'): [Point(1.5, 1.5, 1.5, 1.5)],
            ('point', 'p2'): [Point(2.0, 2.0, 2.0, 2.0)],
            ('point', 'p3'): [Point(1.0, 1.0, 1.0, 1.0)],
            ('point', 'p4'): [Point(3.0, 3.0, 3.0, 3.0)],
            ('point', 'p5'): [Point(2.0, 2.0, 2.0, 2.0)]
        })

    f1 = Formula(vocabulary, 'IS_ON', 'P1', 'P3', 'P4')
    f2 = Formula(vocabulary, 'NOT_SAME_POINT', 'P1', 'P2')
    f3 = Formula(vocabulary, 'CLOCKS_UNEQUAL', 'P1', 'P2')
    f4 = Formula(vocabulary, 'CAN_OBSERVE', 'P1', 'P2', 'P3', 'P4')
    f5 = Formula(vocabulary, 'FAKE', 'P1', 'P2', 'P3', 'P4', 'P5')

    VA = VariableAssignment(vocabulary, attribute_system, {}, dummy=True)

    f1_basis = set([('point', 'p1'), ('point', 'p3'), ('point', 'p4')])
    f2_basis = set([('point', 'p1'), ('point', 'p2')])
    f1_f2_f3_basis = set([('point', 'p1'), ('point', 'p2'), ('point', 'p3'),
                          ('point', 'p4')])
    f5_basis = set([('fake', 'p1'), ('fake', 'p4'), ('point', 'p2'),
                    ('point', 'p5'), ('fake', 'p3')])
    f4_f5_basis = set([('fake', 'p1'), ('fake', 'p4'), ('point', 'p2'),
                       ('point', 'p5'), ('fake', 'p3'), ('point', 'p1'),
                       ('point', 'p3'), ('point', 'p4')])

    assert f1_basis == set(
        Formula.get_basis(named_state._p, VA, attribute_interpretation, f1))
    assert f2_basis == set(
        Formula.get_basis(named_state._p, VA, attribute_interpretation, f2))
    assert f1_f2_f3_basis == set(
        Formula.get_basis(named_state._p, VA, attribute_interpretation, f1, f2,
                          f3))
    assert f5_basis == set(
        Formula.get_basis(named_state._p, VA, attribute_interpretation, f5))
    assert f4_f5_basis == set(
        Formula.get_basis(named_state._p, VA, attribute_interpretation, f4,
                          f5))
Beispiel #2
0
def test_get_basis():
    """Test get_basis function for Formula."""
    point = Attribute('point', [Point('x', 'x', 'x', 'x')])
    fake = Attribute('fake', [])
    r_is_on = Relation('R1(h1, h2, h3) <=> is_on(h1, h2, h3)',
                       ['point', 'point', 'point'], 1)
    r_not_same_point = Relation('R2(h1, h2) <=> not_same_point(h1, h2)',
                                ['point', 'point'], 2)
    r_clocks_unequal = Relation('R3(h1, h2) <=> clocks_unequal(h1, h2)',
                                ['point', 'point'], 3)
    r_can_observe = Relation(
        'R4(p, sp_loc, wls, wle) <=> can_observe(p, sp_loc, wls, wle)',
        ['point', 'point', 'point', 'point'], 4)
    r_fake = Relation(
        'R5(p, wl1s, wl1e, wl2s, wl2e) <=> meets(p, wl1s, wl1e, wl2s, wl2e)',
        ['fake', 'point', 'fake', 'fake', 'point'], 5)

    attribute_structure = AttributeStructure(
        point, fake, r_is_on, r_not_same_point, r_clocks_unequal,
        r_can_observe, r_fake)

    rs_is_on = RelationSymbol('IS_ON', 3)
    rs_not_same_point = RelationSymbol('NOT_SAME_POINT', 2)
    rs_clocks_unequal = RelationSymbol('CLOCKS_UNEQUAL', 2)
    rs_can_observe = RelationSymbol('CAN_OBSERVE', 4)
    rs_fake = RelationSymbol('FAKE', 5)

    vocabulary = Vocabulary(['P1', 'P2', 'P3', 'P4', 'P5'],
                            [rs_is_on, rs_not_same_point,
                             rs_clocks_unequal, rs_can_observe, rs_fake],
                            [])

    profiles = [
        [rs_is_on, ('point', 1), ('point', 2), ('point', 3)],
        [rs_not_same_point, ('point', 1), ('point', 2)],
        [rs_clocks_unequal, ('point', 1), ('point', 2)],
        [rs_can_observe,
         ('point', 1), ('point', 2), ('point', 3), ('point', 4)],
        [rs_fake,
         ('fake', 1), ('point', 2), ('fake', 3), ('fake', 4), ('point', 5)]]

    mapping = {rs_is_on: 1, rs_not_same_point: 2, rs_clocks_unequal: 3,
               rs_can_observe: 4, rs_fake: 5}

    attribute_interpretation = AttributeInterpretation(vocabulary,
                                                       attribute_structure,
                                                       mapping,
                                                       profiles)

    objects = ['p1', 'p2', 'p3', 'p4', 'p5']
    attribute_system = AttributeSystem(attribute_structure, objects)
    p = ConstantAssignment(vocabulary, attribute_system,
                           {'P1': 'p1', 'P2': 'p2', 'P3': 'p3', 'P4': 'p4',
                            'P5': 'p5'})

    named_state = NamedState(attribute_system, p, {
                             ('point', 'p1'): [Point(1.5, 1.5, 1.5, 1.5)],
                             ('point', 'p2'): [Point(2.0, 2.0, 2.0, 2.0)],
                             ('point', 'p3'): [Point(1.0, 1.0, 1.0, 1.0)],
                             ('point', 'p4'): [Point(3.0, 3.0, 3.0, 3.0)],
                             ('point', 'p5'): [Point(2.0, 2.0, 2.0, 2.0)]})

    f1 = Formula(vocabulary, 'IS_ON', 'P1', 'P3', 'P4')
    f2 = Formula(vocabulary, 'NOT_SAME_POINT', 'P1', 'P2')
    f3 = Formula(vocabulary, 'CLOCKS_UNEQUAL', 'P1', 'P2')
    f4 = Formula(vocabulary, 'CAN_OBSERVE', 'P1', 'P2', 'P3', 'P4')
    f5 = Formula(vocabulary, 'FAKE', 'P1', 'P2', 'P3', 'P4', 'P5')

    VA = VariableAssignment(vocabulary, attribute_system, {}, dummy=True)

    f1_basis = set([('point', 'p1'), ('point', 'p3'), ('point', 'p4')])
    f2_basis = set([('point', 'p1'), ('point', 'p2')])
    f1_f2_f3_basis = set(
        [('point', 'p1'), ('point', 'p2'), ('point', 'p3'), ('point', 'p4')])
    f5_basis = set(
        [('fake', 'p1'), ('fake', 'p4'), ('point', 'p2'), ('point', 'p5'),
         ('fake', 'p3')])
    f4_f5_basis = set(
        [('fake', 'p1'), ('fake', 'p4'), ('point', 'p2'), ('point', 'p5'),
         ('fake', 'p3'), ('point', 'p1'), ('point', 'p3'), ('point', 'p4')])

    assert f1_basis == set(Formula.get_basis(
        named_state._p, VA, attribute_interpretation, f1))
    assert f2_basis == set(Formula.get_basis(
        named_state._p, VA, attribute_interpretation, f2))
    assert f1_f2_f3_basis == set(Formula.get_basis(
        named_state._p, VA, attribute_interpretation, f1, f2, f3))
    assert f5_basis == set(Formula.get_basis(
        named_state._p, VA, attribute_interpretation, f5))
    assert f4_f5_basis == set(Formula.get_basis(
        named_state._p, VA, attribute_interpretation, f4, f5))