Пример #1
0
def synthesize_enumerated_streett(spec, use_cudd=False):
    """Return transducer enumerated as a graph.

    @type spec: `tulip.spec.form.GRSpec`
    @param use_cudd: efficient BDD computations with `dd.cudd`
    @rtype: `networkx.DiGraph`
    """
    aut = _grspec_to_automaton(spec)
    sym.fill_blanks(aut)
    bdd = _init_bdd(use_cudd)
    aut.bdd = bdd
    a = aut.build()
    t0 = time.time()
    z, yij, xijk = gr1.solve_streett_game(a)
    t1 = time.time()
    # unrealizable ?
    if z == a.bdd.false:
        return None
    t = gr1.make_streett_transducer(z, yij, xijk, a)
    t2 = time.time()
    (u,) = t.action['sys']
    care = _int_bounds(t)
    g = enum.relation_to_graph(u, t, care_source=care,
                               care_target=care)
    h = _strategy_to_state_annotated(g, a)
    del u, yij, xijk, care
    t3 = time.time()
    log.info((
        'Winning set computed in {win} sec.\n'
        'Symbolic strategy computed in {sym} sec.\n'
        'Strategy enumerated in {enu} sec.').format(
            win=t1 - t0,
            sym=t2 - t1,
            enu=t3 - t2))
    return h
Пример #2
0
def synthesize_enumerated_streett(spec, use_cudd=False):
    """Return transducer enumerated as a graph.

    @type spec: `tulip.spec.form.GRSpec`
    @param use_cudd: efficient BDD computations with `dd.cudd`
    @rtype: `networkx.DiGraph`
    """
    aut = _grspec_to_automaton(spec)
    sym.fill_blanks(aut)
    bdd = _init_bdd(use_cudd)
    aut.bdd = bdd
    a = aut.build()
    assert a.action['sys'][0] != bdd.false
    t0 = time.time()
    z, yij, xijk = gr1.solve_streett_game(a)
    t1 = time.time()
    # unrealizable ?
    if not gr1.is_realizable(z, a):
        print('WARNING: unrealizable')
        return None
    t = gr1.make_streett_transducer(z, yij, xijk, a)
    t2 = time.time()
    (u, ) = t.action['sys']
    assert u != bdd.false
    g = enum.action_to_steps(t, qinit=spec.qinit)
    h = _strategy_to_state_annotated(g, a)
    del u, yij, xijk
    t3 = time.time()
    log.info(('Winning set computed in {win} sec.\n'
              'Symbolic strategy computed in {sym} sec.\n'
              'Strategy enumerated in {enu} sec.').format(win=t1 - t0,
                                                          sym=t2 - t1,
                                                          enu=t3 - t2))
    return h
Пример #3
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
Пример #4
0
def is_circular(spec, use_cudd=False):
    """Return `True` if trivial winning set non-empty.

    @type spec: `tulip.spec.form.GRSpec`
    @param use_cudd: efficient BDD computations with `dd.cudd`
    @rtype: `bool`
    """
    aut = _grspec_to_automaton(spec)
    sym.fill_blanks(aut)
    bdd = _init_bdd(use_cudd)
    aut.bdd = bdd
    triv, t = gr1.trivial_winning_set(aut)
    return triv != t.bdd.false
Пример #5
0
def is_circular(spec, use_cudd=False):
    """Return `True` if trivial winning set non-empty.

    @type spec: `tulip.spec.form.GRSpec`
    @param use_cudd: efficient BDD computations with `dd.cudd`
    @rtype: `bool`
    """
    aut = _grspec_to_automaton(spec)
    sym.fill_blanks(aut)
    bdd = _init_bdd(use_cudd)
    aut.bdd = bdd
    triv, t = gr1.trivial_winning_set(aut)
    return triv != t.bdd.false
Пример #6
0
def is_realizable(spec, use_cudd=False):
    """Return `True` if, and only if, realizable.

    See `synthesize_enumerated_streett` for more details.
    """
    aut = _grspec_to_automaton(spec)
    sym.fill_blanks(aut)
    bdd = _init_bdd(use_cudd)
    aut.bdd = bdd
    a = aut.build()
    t0 = time.time()
    z, _, _ = gr1.solve_streett_game(a)
    t1 = time.time()
    return gr1.is_realizable(z, a)
Пример #7
0
def synthesize_environment(spec, use_cudd=False):
    """Return transducer enumerated as a graph.

    @type spec: `tulip.spec.form.GRSpec`
    @param use_cudd: efficient BDD computations with `dd.cudd`
    @rtype: `networkx.DiGraph`
    """
    aut = tulip.interfaces.omega._grspec_to_automaton(spec)
    sym.fill_blanks(aut)
    bdd = tulip.interfaces.omega._init_bdd(use_cudd)
    aut.bdd = bdd
    a = aut.build()
    assert a.action['sys'][0] != bdd.false
    z, yij, xijk = gr1.solve_streett_game(a)
    if (not gr1.is_realizable(z, a)) :
        aut_rabin = generate_complement(aut) 
        controller_rabin = synthesize_rabin_controller(aut_rabin)
        h = tulip.interfaces.omega._strategy_to_state_annotated(controller_rabin, a)
        return h;
    else:
        print("Warning: the automata is synthesizable")
Пример #8
0
#    psi |= DSL.response(trig=b[i], react=f[i], owner='sys', aux='aux' + str(i+1))
#print(psi.pretty())


psi.qinit = '\A \E'
psi.moore = False
psi.plus_one = False

#ctrl=synth.synthesize(psi, ignore_sys_init=False, solver='gr1c')

strategy = omega_int.synthesize_enumerated_streett(psi)
use_cudd=False

spec=psi
aut = omega_int._grspec_to_automaton(spec)
sym.fill_blanks(aut)
bdd = omega_int._init_bdd(use_cudd)
aut.bdd = bdd
a = aut.build()
bdd.dump("file_a.pdf")

# what has been generated#
print(aut.init['env'])
print(aut.init['sys'])
print(aut.action['sys'])

print(bdd.false)
# what has been build from it
print(a.init['env'])
print(a.init['sys'])
print(a.action['sys'])