Beispiel #1
0
def generate_complement(aut_streett):
    """Return rabin automaton. This function is used to create complement automaton from given streett

    @type aut_streett: `omega.symbolic.symbolic.Automaton`
    @rtype: `omega.symbolic.symbolic.Automaton`
    """
    
    aut_rabin = sym.Automaton()
    aut_rabin.acceptance = 'Rabin(1)'
    
    # Switch variable ownership
    for var, d in aut_streett.vars.items():
        d = d.copy()
        owner =  d['owner']
        owner = 'env' if owner == 'sys' else 'sys'
        d['owner'] = owner
        aut_rabin.vars[var] = d

    aut_rabin.init['env']=aut_streett.init['sys']
    aut_rabin.init['sys']=aut_streett.init['env']
    aut_rabin.action['env'] = aut_streett.action['sys']
    aut_rabin.action['sys'] = aut_streett.action['env']    
    win = ['!({w})'.format(w=w) for w in aut_streett.win['<>[]']]
    aut_rabin.win['[]<>'] = win
    win = ['!({w})'.format(w=w) for w in aut_streett.win['[]<>']]
    aut_rabin.win['<>[]'] = win
    sym.fill_blanks(aut_rabin, rabin=True)
    aut_rabin.qinit = '\E \E'
    
    return aut_rabin
Beispiel #2
0
def ltl_to_automaton(f):
    """Return `Automaton` from LTL formula `f` as `str`.

    Formula `f` must be in the form:

      A -+-> G

    where each of A, G is a conjunction of terms: `B`, `[]C`, `[]<>B`.
    For more details on `B, C`, see `split_gr1`.

    @type f: `str`
    @rtype: `symbolic.Automaton`
    """
    t = parser.parse(f)
    assert t.operator == '-+->'
    env, sys = t.operands
    d = {'assume': split_gr1(env), 'assert': split_gr1(sys)}
    a = symbolic.Automaton()
    a.init['env'] = d['assume']['init']
    a.init['sys'] = d['assert']['init']
    a.action['env'] = d['assume']['[]']
    a.action['sys'] = d['assert']['[]']
    a.win['env'] = d['assume']['[]<>']
    a.win['sys'] = d['assert']['[]<>']
    return a
Beispiel #3
0
def test_symbolic_automaton():
    aut = symbolic.Automaton()
    aut.vars['x'] = dict(type='bool', owner='env')
    aut.vars['y'] = dict(type='int', dom=(3, 17), owner='sys')
    aut.init['env'].append('x')
    aut.action['env'].append("x => ~ x'")
    aut.init['sys'].append('y = 5')
    aut.action['sys'].append("(y < 6) => (y' > 10)")
    # strategy definition
    assert aut.moore is True, aut.moore
    assert aut.plus_one is True, aut.plus_one
    assert aut.qinit == '\A \A', aut.qinit
    # str
    s = str(aut)
    assert s.startswith('Symbolic automaton:'), s[:10]
    assert s.endswith('> 10)\n'), s[-3:]
    # data persistence
    s = aut.dumps()
    d = eval(s)
    assert isinstance(d, dict), d
    keys = set(d)
    keys_ = {
        'vars', 'init', 'action', 'win', 'acceptance', 'moore', 'plus_one',
        'qinit'
    }
    assert keys == keys_, keys
Beispiel #4
0
def test_relation_to_graph():
    a = symbolic.Automaton()
    a.vars['x'] = dict(type='int', dom=(0, 5), owner='sys')
    a.vars['y'] = dict(type='bool', owner='sys')
    aut = a.build()
    u = aut.add_expr("(x = 4) & y & (x' = 0)")
    care_bits = aut.bdd.vars
    g = enum.relation_to_graph(u, aut, care_bits=care_bits)
    assert len(g) == 3, g.nodes()
    keys = ('x', 'y')
    r = {tuple(d[k] for k in keys) for k, d in g.nodes(data=True)}
    r_ = {(4, True), (0, False), (0, True)}
    assert r == r_, r
Beispiel #5
0
def _grspec_to_automaton(g):
    """Return `symbolic.Automaton` from `GRSpec`.

    @type g: `tulip.spec.form.GRSpec`
    @rtype: `omega.symbolic.symbolic.Automaton`
    """
    if omega is None:
        raise ImportError(
            'Failed to import package `omega`.')
    a = sym.Automaton()
    d = dict(g.env_vars)
    d.update(g.sys_vars)
    for k, v in d.iteritems():
        if v in ('boolean', 'bool'):
            r = 'bool'
        elif isinstance(v, list):
            # string var -> integer var
            r = (0, len(v) - 1)
        elif isinstance(v, tuple):
            r = v
        else:
            raise ValueError(
                'unknown variable type: {v}'.format(v=v))
        d[k] = r
    g.str_to_int()
    # reverse mapping by `synth.strategy2mealy`
    a.vars = bv.make_table(d, env_vars=g.env_vars)
    f = g._bool_int.__getitem__
    a.init['env'] = map(f, g.env_init)
    a.init['sys'] = map(f, g.sys_init)
    a.action['env'] = map(f, g.env_safety)
    a.action['sys'] = map(f, g.sys_safety)
    a.win['<>[]'] = [
        '!({s})'.format(s=s)
        for s in map(f, g.env_prog)]
    a.win['[]<>'] = map(f, g.sys_prog)
    a.moore = g.moore
    a.plus_one = g.plus_one
    a.qinit = g.qinit
    return a