def monitor():
    # data
    dataSet = {
         'a': [(0, 100.0), (1, -1.0), (2, -2.0)],
         'b': [(0, 20.0), (1, 2.0), (2, -10.0)]
    }

    # # stl
    spec = rtamt.STLSpecification(language=rtamt.Language.CPP)
    spec.name = 'STL discrete-time online Python monitor'
    spec.declare_var('a', 'float')
    spec.declare_var('b', 'float')
    spec.spec = 'a + b >= - 2'

    try:
        spec.parse()
    except rtamt.STLParseException as err:
        print('STL Parse Exception: {}'.format(err))
        sys.exit()

    # # eval
    aTraj = dataSet['a']
    bTraj = dataSet['b']
    for i in range(len(dataSet['a'])):
        aData = aTraj[i]
        bData = bTraj[i]
        rob = spec.update(aData[0], [('a', aData[1]), ('b', bData[1])])
        print('time='+str(aData[0])+' rob='+str(rob))
Ejemplo n.º 2
0
    def test_monitor_offline(self):
        # From https://github.com/nickovic/rtamt/blob/master/examples/basic/monitor_offline.py
        dataSet = {
            'a': [(0, 100.0), (1, -1.0), (2, -2.0)],
            'b': [(0, 20.0), (1, 2.0), (2, -10.0)]
        }

        spec = rtamt.STLSpecification(1)
        spec.name = 'HandMadeMonitor'
        spec.declare_var('a', 'float')
        spec.declare_var('b', 'float')
        spec.declare_var('c', 'float')
        spec.spec = 'c = always(a<=2 and b>=1)'
        spec.parse()
        robustness = spec.offline(dataSet)
        self.assertEqual(robustness, -98.0)
Ejemplo n.º 3
0
def monitor():
    # # stl
    spec = rtamt.STLSpecification()
    spec.declare_var('a', 'float')
    spec.declare_var('b', 'float')
    spec.spec = 'eventually[0,1] (a >= b)'

    try:
        spec.parse()
        spec.pastify()
    except rtamt.RTAMTException as err:
        print('RTAMT Exception: {}'.format(err))
        sys.exit()

    rob = spec.update(0, [('a', 100.0), ('b', 20.0)])
    print('time=' + str(0) + ' rob=' + str(rob))

    rob = spec.update(1, [('a', -1.0), ('b', 2.0)])
    print('time=' + str(0) + ' rob=' + str(rob))

    rob = spec.update(2, [('a', -2.0), ('b', -10.0)])
    print('time=' + str(0) + ' rob=' + str(rob))
Ejemplo n.º 4
0
def monitor():
    # data
    dataSet = {
         'time': [0, 1, 2],
         'a': [100.0, -1.0, -2.0],
         'b': [20.0, 2.0, -10.0]
    }

    # # stl
    spec = rtamt.STLSpecification(language=rtamt.Language.PYTHON)
    spec.name = 'STL discrete-time online Python monitor'
    spec.declare_var('a', 'float')
    spec.declare_var('b', 'float')
    spec.spec = 'a + b >= - 2'

    try:
        spec.parse()
    except rtamt.STLParseException as err:
        print('STL Parse Exception: {}'.format(err))
        sys.exit()

    rob = spec.evaluate(dataSet)
    print('Robustness: ' + str(rob))
Ejemplo n.º 5
0
def monitor():
    # data

    dataSet = {
        'time': [0, 1, 2, 3, 4, 5],
        'x': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
        'y': [1.1, 1.2, 1.3, 1.4, 1.5, 1.6]
    }

    # # STANDARD ROBUSTNESS
    spec = rtamt.STLSpecification(language=rtamt.Language.PYTHON,
                                  semantics=rtamt.Semantics.STANDARD)
    spec.name = 'IA-STL discrete-time online Python monitor with STANDARD semantics'
    spec.declare_var('x', 'float')
    spec.declare_var('y', 'float')
    spec.set_var_io_type('x', 'input')
    spec.set_var_io_type('y', 'output')
    spec.spec = '(x>=0.25) and (y>=1.25)'

    try:
        spec.parse()
    except rtamt.STLParseException as err:
        print('STL Parse Exception: {}'.format(err))
        sys.exit()

    rob = spec.evaluate(dataSet)
    print('Standard robustness: ' + str(rob))

    # # OUTPUT ROBUSTNESS
    spec = rtamt.STLSpecification(language=rtamt.Language.PYTHON,
                                  semantics=rtamt.Semantics.OUTPUT_ROBUSTNESS)
    spec.name = 'IA-STL discrete-time online Python monitor with OUTPUT ROBUSTNESS semantics'
    spec.declare_var('x', 'float')
    spec.declare_var('y', 'float')
    spec.set_var_io_type('x', 'input')
    spec.set_var_io_type('y', 'output')
    spec.spec = '(x>=0.25) or (y>=1.25)'

    try:
        spec.parse()
    except rtamt.STLParseException as err:
        print('STL Parse Exception: {}'.format(err))
        sys.exit()

    rob = spec.evaluate(dataSet)
    print('Output robustness: ' + str(rob))

    # # INPUT VACUITY
    spec = rtamt.STLSpecification(language=rtamt.Language.PYTHON,
                                  semantics=rtamt.Semantics.INPUT_VACUITY)
    spec.name = 'IA-STL discrete-time online Python monitor with INPUT VACUITY semantics'
    spec.declare_var('x', 'float')
    spec.declare_var('y', 'float')
    spec.set_var_io_type('x', 'input')
    spec.set_var_io_type('y', 'output')
    spec.spec = '(x>=0.25) or (y>=1.25)'

    try:
        spec.parse()
    except rtamt.STLParseException as err:
        print('STL Parse Exception: {}'.format(err))
        sys.exit()

    rob = spec.evaluate(dataSet)
    print('Input vacuity: ' + str(rob))