Exemple #1
0
    def point_test():
        """Do test with Point object and its parser."""
        from vivid.classes.point import Point
        point = Attribute('point', [Point('x', 'x', 'x', 'x')])
        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)

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

        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)

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

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

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

        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'})

        world = 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)]})

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

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

        assumption_base = AssumptionBase(f2, f3, f4)
        context = Context(assumption_base, world)

        # Whenever we can observe a Point, we're either at that point or on
        # same worldline so IS_ON should hold
        assert context.entails_formula(f1, attribute_interpretation)
        # We always entail our own formulae
        assert context.entails_formula(f2, attribute_interpretation)
        assert context.entails_formula(f3, attribute_interpretation)
        assert context.entails_formula(f4, attribute_interpretation)
Exemple #2
0
    def point_test():
        """Do test with Point object and its parser."""
        from vivid.classes.point import Point
        point = Attribute('point', [Point('x', 'x', 'x', 'x')])
        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)

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

        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)

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

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

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

        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'
        })

        world = 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)]
            })

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

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

        assumption_base = AssumptionBase(f2, f3, f4)
        context = Context(assumption_base, world)

        # Whenever we can observe a Point, we're either at that point or on
        # same worldline so IS_ON should hold
        assert context.entails_formula(f1, attribute_interpretation)
        # We always entail our own formulae
        assert context.entails_formula(f2, attribute_interpretation)
        assert context.entails_formula(f3, attribute_interpretation)
        assert context.entails_formula(f4, attribute_interpretation)
Exemple #3
0
    def standard_test():
        """Do test with standard parser."""
        hour = Attribute('hour', [Interval(0, 23)])
        minute = Attribute('minute', [Interval(0, 59)])
        r_pm = Relation('R1(h1) <=> h1 > 11', ['hour'], 1)
        r_am = Relation('R2(h1) <=> h1 <= 11', ['hour'], 2)
        r_ahead = Relation(
            'R3(h1,m1,hhh2,mm2) <=> h1 > hhh2 or (h1 = hhh2 and m1 > mm2)',
            ['hour', 'minute', 'hour', 'minute'], 3)
        r_behind = Relation(
            'R4(h1,m1,h2,m2) <=> h1 <= h2 or (h1 = h2 and m1 < m2)',
            ['hour', 'minute', 'hour', 'minute'], 4)
        attribute_structure = AttributeStructure(
            hour, minute, r_ahead, r_behind, r_pm, r_am)

        rs_ahead = RelationSymbol('Ahead', 4)
        rs_behind = RelationSymbol('Behind', 4)
        rs_pm = RelationSymbol('PM', 1)
        rs_am = RelationSymbol('AM', 1)
        vocabulary = Vocabulary(
            ['C1', 'C2'], [rs_ahead, rs_behind, rs_pm, rs_am], ['V1', 'V2'])

        objects = ['s1', 's2']
        attribute_system = AttributeSystem(attribute_structure, objects)
        p = ConstantAssignment(
            vocabulary, attribute_system, {'C1': 's1', 'C2': 's2'})

        profiles = [
            [rs_pm, ('hour', 1)],
            [rs_am, ('hour', 1)],
            [rs_behind, ('hour', 1), ('minute', 1), ('hour', 2), ('minute', 2)],
            [rs_ahead, ('hour', 1), ('minute', 1), ('hour', 2), ('minute', 2)]]

        attribute_interpretation = AttributeInterpretation(
            vocabulary, attribute_structure,
            {rs_pm: 1, rs_am: 2, rs_ahead: 3, rs_behind: 4}, profiles)

        f1 = Formula(vocabulary, 'Ahead', 'C1', 'C2')
        f2 = Formula(vocabulary, 'Behind', 'C2', 'C1')
        f3 = Formula(vocabulary, 'PM', 'C1')
        f4 = Formula(vocabulary, 'AM', 'C2')
        assumption_base = AssumptionBase(f1, f3, f4)
        named_state = NamedState(attribute_system, p, {
                                 ("hour", "s1"): [Interval(15, 17)],
                                 ("hour", "s2"): [11],
                                 ("minute", "s1"): [23],
                                 ("minute", "s2"): [23]})

        context = Context(assumption_base, named_state)

        assert context.entails_formula(f1, attribute_interpretation)
        assert context.entails_formula(f2, attribute_interpretation)
        assert context.entails_formula(f3, attribute_interpretation)
        assert context.entails_formula(f4, attribute_interpretation)

        vocabulary = Vocabulary(
            ['C1'], [rs_ahead, rs_behind, rs_pm, rs_am], ['V1', 'V2'])

        objects = ['s1', 's2']
        attribute_system = AttributeSystem(attribute_structure, objects)
        p = ConstantAssignment(
            vocabulary, attribute_system, {'C1': 's1'})

        profiles = [
            [rs_pm, ('hour', 1)],
            [rs_am, ('hour', 1)],
            [rs_behind, ('hour', 1), ('minute', 1), ('hour', 2), ('minute', 2)],
            [rs_ahead, ('hour', 1), ('minute', 1), ('hour', 2), ('minute', 2)]]

        attribute_interpretation = AttributeInterpretation(
            vocabulary, attribute_structure,
            {rs_pm: 1, rs_am: 2, rs_ahead: 3, rs_behind: 4}, profiles)

        f1 = Formula(vocabulary, 'Ahead', 'C1', 'V1')
        f2 = Formula(vocabulary, 'PM', 'C1')
        f3 = Formula(vocabulary, 'AM', 'V1')
        f4 = Formula(vocabulary, 'AM', 'V2')
        f5 = Formula(vocabulary, 'Behind', 'V1', 'C1')
        assumption_base = AssumptionBase(f1)
        named_state = NamedState(attribute_system, p, {
                                 ("hour", "s1"): [Interval(15, 17)],
                                 ("hour", "s2"): [11],
                                 ("minute", "s1"): [23],
                                 ("minute", "s2"): [23]})

        context = Context(assumption_base, named_state)
        assert context.entails_formula(f1, attribute_interpretation)
        assert context.entails_formula(f2, attribute_interpretation)
        assert context.entails_formula(f3, attribute_interpretation)
        # assert not here as it does not hold for every variable assignment;
        # e.g. the following configuration is valid but its truth value is unknown:
        # profile: [('hour', 'V1')]
        #           CA{'C1': 's1'}
        #           VA{'V2': 's2'}, which means all terms are not defined
        assert not context.entails_formula(f4, attribute_interpretation)
        assert context.entails_formula(f5, attribute_interpretation)
Exemple #4
0
    def standard_test():
        """Do test with standard parser."""
        hour = Attribute('hour', [Interval(0, 23)])
        minute = Attribute('minute', [Interval(0, 59)])
        r_pm = Relation('R1(h1) <=> h1 > 11', ['hour'], 1)
        r_am = Relation('R2(h1) <=> h1 <= 11', ['hour'], 2)
        r_ahead = Relation(
            'R3(h1,m1,hhh2,mm2) <=> h1 > hhh2 or (h1 = hhh2 and m1 > mm2)',
            ['hour', 'minute', 'hour', 'minute'], 3)
        r_behind = Relation(
            'R4(h1,m1,h2,m2) <=> h1 <= h2 or (h1 = h2 and m1 < m2)',
            ['hour', 'minute', 'hour', 'minute'], 4)
        attribute_structure = AttributeStructure(hour, minute, r_ahead,
                                                 r_behind, r_pm, r_am)

        rs_ahead = RelationSymbol('Ahead', 4)
        rs_behind = RelationSymbol('Behind', 4)
        rs_pm = RelationSymbol('PM', 1)
        rs_am = RelationSymbol('AM', 1)
        vocabulary = Vocabulary(['C1', 'C2'],
                                [rs_ahead, rs_behind, rs_pm, rs_am],
                                ['V1', 'V2'])

        objects = ['s1', 's2']
        attribute_system = AttributeSystem(attribute_structure, objects)
        p = ConstantAssignment(vocabulary, attribute_system, {
            'C1': 's1',
            'C2': 's2'
        })

        profiles = [[rs_pm, ('hour', 1)], [rs_am, ('hour', 1)],
                    [
                        rs_behind, ('hour', 1), ('minute', 1), ('hour', 2),
                        ('minute', 2)
                    ],
                    [
                        rs_ahead, ('hour', 1), ('minute', 1), ('hour', 2),
                        ('minute', 2)
                    ]]

        attribute_interpretation = AttributeInterpretation(
            vocabulary, attribute_structure, {
                rs_pm: 1,
                rs_am: 2,
                rs_ahead: 3,
                rs_behind: 4
            }, profiles)

        f1 = Formula(vocabulary, 'Ahead', 'C1', 'C2')
        f2 = Formula(vocabulary, 'Behind', 'C2', 'C1')
        f3 = Formula(vocabulary, 'PM', 'C1')
        f4 = Formula(vocabulary, 'AM', 'C2')
        assumption_base = AssumptionBase(f1, f3, f4)
        named_state = NamedState(
            attribute_system, p, {
                ("hour", "s1"): [Interval(15, 17)],
                ("hour", "s2"): [11],
                ("minute", "s1"): [23],
                ("minute", "s2"): [23]
            })

        context = Context(assumption_base, named_state)

        assert context.entails_formula(f1, attribute_interpretation)
        assert context.entails_formula(f2, attribute_interpretation)
        assert context.entails_formula(f3, attribute_interpretation)
        assert context.entails_formula(f4, attribute_interpretation)

        vocabulary = Vocabulary(['C1'], [rs_ahead, rs_behind, rs_pm, rs_am],
                                ['V1', 'V2'])

        objects = ['s1', 's2']
        attribute_system = AttributeSystem(attribute_structure, objects)
        p = ConstantAssignment(vocabulary, attribute_system, {'C1': 's1'})

        profiles = [[rs_pm, ('hour', 1)], [rs_am, ('hour', 1)],
                    [
                        rs_behind, ('hour', 1), ('minute', 1), ('hour', 2),
                        ('minute', 2)
                    ],
                    [
                        rs_ahead, ('hour', 1), ('minute', 1), ('hour', 2),
                        ('minute', 2)
                    ]]

        attribute_interpretation = AttributeInterpretation(
            vocabulary, attribute_structure, {
                rs_pm: 1,
                rs_am: 2,
                rs_ahead: 3,
                rs_behind: 4
            }, profiles)

        f1 = Formula(vocabulary, 'Ahead', 'C1', 'V1')
        f2 = Formula(vocabulary, 'PM', 'C1')
        f3 = Formula(vocabulary, 'AM', 'V1')
        f4 = Formula(vocabulary, 'AM', 'V2')
        f5 = Formula(vocabulary, 'Behind', 'V1', 'C1')
        assumption_base = AssumptionBase(f1)
        named_state = NamedState(
            attribute_system, p, {
                ("hour", "s1"): [Interval(15, 17)],
                ("hour", "s2"): [11],
                ("minute", "s1"): [23],
                ("minute", "s2"): [23]
            })

        context = Context(assumption_base, named_state)
        assert context.entails_formula(f1, attribute_interpretation)
        assert context.entails_formula(f2, attribute_interpretation)
        assert context.entails_formula(f3, attribute_interpretation)
        # assert not here as it does not hold for every variable assignment;
        # e.g. the following configuration is valid but its truth value is unknown:
        # profile: [('hour', 'V1')]
        #           CA{'C1': 's1'}
        #           VA{'V2': 's2'}, which means all terms are not defined
        assert not context.entails_formula(f4, attribute_interpretation)
        assert context.entails_formula(f5, attribute_interpretation)