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'], [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'] attribute_system = AttributeSystem(attribute_structure, objects) p = ConstantAssignment(vocabulary, attribute_system, {'P1': 'p1', 'P2': 'p2', 'P3': 'p3', 'P4': 'p4'}) 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)]}) 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, named_state) # A context always entails its own named state assert context.entails_named_state( named_state, attribute_interpretation) named_state = NamedState(attribute_system, p, { ('point', 'p1'): [Point(1.5, 1.5, 1.5, 1.5), Point(2.5, 2.5, 2.5, 2.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)]}) # A context entails named states that when the worlds of the context # extend the named state assert context.entails_named_state( named_state, attribute_interpretation) named_state = NamedState(attribute_system, p, { ('point', 'p1'): [Point(1.5, 1.5, 1.5, 1.5), Point(2.5, 2.5, 2.5, 2.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)]}) context = Context(assumption_base, named_state) named_state = NamedState(attribute_system, p, { ('point', 'p1'): [Point(4.25, 1.3, 5.4, 7.5)], ('point', 'p2'): [Point(2.0, 2.4, 2.0, 2.0)], ('point', 'p3'): [Point(1.0, 1.0, 5.0, 1.0)], ('point', 'p4'): [Point(3.0, 3.0, 3.0, 8.0)]}) # A context does not entail a named state when the worlds of the # context do not extend the named state assert not context.entails_named_state( named_state, attribute_interpretation) assumption_base = AssumptionBase( Formula(vocabulary, 'NOT_SAME_POINT', 'P1', 'P1')) context = Context(assumption_base, named_state) named_state = NamedState(attribute_system, p, { ('point', 'p1'): [Point(8.5, 1.4, 2.1, 3.6)], ('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)]}) # A context trivially entails a named state when no world of the # context satisfies the context assert context.entails_named_state( named_state, attribute_interpretation)
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'], [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'] attribute_system = AttributeSystem(attribute_structure, objects) p = ConstantAssignment(vocabulary, attribute_system, { 'P1': 'p1', 'P2': 'p2', 'P3': 'p3', 'P4': 'p4' }) 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)] }) 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, named_state) # A context always entails its own named state assert context.entails_named_state(named_state, attribute_interpretation) named_state = NamedState( attribute_system, p, { ('point', 'p1'): [Point(1.5, 1.5, 1.5, 1.5), Point(2.5, 2.5, 2.5, 2.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)] }) # A context entails named states that when the worlds of the context # extend the named state assert context.entails_named_state(named_state, attribute_interpretation) named_state = NamedState( attribute_system, p, { ('point', 'p1'): [Point(1.5, 1.5, 1.5, 1.5), Point(2.5, 2.5, 2.5, 2.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)] }) context = Context(assumption_base, named_state) named_state = NamedState( attribute_system, p, { ('point', 'p1'): [Point(4.25, 1.3, 5.4, 7.5)], ('point', 'p2'): [Point(2.0, 2.4, 2.0, 2.0)], ('point', 'p3'): [Point(1.0, 1.0, 5.0, 1.0)], ('point', 'p4'): [Point(3.0, 3.0, 3.0, 8.0)] }) # A context does not entail a named state when the worlds of the # context do not extend the named state assert not context.entails_named_state(named_state, attribute_interpretation) assumption_base = AssumptionBase( Formula(vocabulary, 'NOT_SAME_POINT', 'P1', 'P1')) context = Context(assumption_base, named_state) named_state = NamedState( attribute_system, p, { ('point', 'p1'): [Point(8.5, 1.4, 2.1, 3.6)], ('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)] }) # A context trivially entails a named state when no world of the # context satisfies the context assert context.entails_named_state(named_state, attribute_interpretation)
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"): [Interval(6, 9)], ("minute", "s1"): [23], ("minute", "s2"): [23]}) context = Context(assumption_base, named_state) # A context always entails its own named state assert context.entails_named_state( named_state, attribute_interpretation) named_state = NamedState(attribute_system, p, { ("hour", "s1"): [Interval(15, 17)], ("hour", "s2"): [Interval(4, 11)], ("minute", "s1"): [23], ("minute", "s2"): [23]}) # A context entails named states that when the worlds of the context # extend the named state assert context.entails_named_state( named_state, attribute_interpretation) f1 = Formula(vocabulary, 'PM', 'C1') assumption_base = AssumptionBase(f1) named_state = NamedState(attribute_system, p, { ("hour", "s1"): [Interval(15, 17)], ("hour", "s2"): [Interval(6, 9)], ("minute", "s1"): [23], ("minute", "s2"): [23]}) context = Context(assumption_base, named_state) named_state = NamedState(attribute_system, p, { ("hour", "s1"): [23], ("hour", "s2"): [13], ("minute", "s1"): [23], ("minute", "s2"): [23]}) # A context does not entail a named state when the worlds of the # context do not extend the named state assert not context.entails_named_state( named_state, attribute_interpretation) f1 = Formula(vocabulary, 'PM', 'C1') assumption_base = AssumptionBase(f1) named_state = NamedState(attribute_system, p, { ("hour", "s1"): [Interval(6, 9)], ("hour", "s2"): [Interval(15, 17)], ("minute", "s1"): [23], ("minute", "s2"): [23]}) context = Context(assumption_base, named_state) named_state = NamedState(attribute_system, p, { ("hour", "s1"): [23], ("hour", "s2"): [13], ("minute", "s1"): [23], ("minute", "s2"): [23]}) # A context trivially entails a named state when no world of the # context satisfies the context assert context.entails_named_state( named_state, attribute_interpretation)
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"): [Interval(6, 9)], ("minute", "s1"): [23], ("minute", "s2"): [23] }) context = Context(assumption_base, named_state) # A context always entails its own named state assert context.entails_named_state(named_state, attribute_interpretation) named_state = NamedState( attribute_system, p, { ("hour", "s1"): [Interval(15, 17)], ("hour", "s2"): [Interval(4, 11)], ("minute", "s1"): [23], ("minute", "s2"): [23] }) # A context entails named states that when the worlds of the context # extend the named state assert context.entails_named_state(named_state, attribute_interpretation) f1 = Formula(vocabulary, 'PM', 'C1') assumption_base = AssumptionBase(f1) named_state = NamedState( attribute_system, p, { ("hour", "s1"): [Interval(15, 17)], ("hour", "s2"): [Interval(6, 9)], ("minute", "s1"): [23], ("minute", "s2"): [23] }) context = Context(assumption_base, named_state) named_state = NamedState( attribute_system, p, { ("hour", "s1"): [23], ("hour", "s2"): [13], ("minute", "s1"): [23], ("minute", "s2"): [23] }) # A context does not entail a named state when the worlds of the # context do not extend the named state assert not context.entails_named_state(named_state, attribute_interpretation) f1 = Formula(vocabulary, 'PM', 'C1') assumption_base = AssumptionBase(f1) named_state = NamedState( attribute_system, p, { ("hour", "s1"): [Interval(6, 9)], ("hour", "s2"): [Interval(15, 17)], ("minute", "s1"): [23], ("minute", "s2"): [23] }) context = Context(assumption_base, named_state) named_state = NamedState( attribute_system, p, { ("hour", "s1"): [23], ("hour", "s2"): [13], ("minute", "s1"): [23], ("minute", "s2"): [23] }) # A context trivially entails a named state when no world of the # context satisfies the context assert context.entails_named_state(named_state, attribute_interpretation)