Exemplo n.º 1
0
def test_synthesis_moore():
    sp = grspec_2()
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    # g.save('moore.pdf')
    assert g is not None
    n = len(g)
    assert n == 26, n
Exemplo n.º 2
0
def test_synthesis_mealy_all_init():
    sp = grspec_3()
    h = omega_int.synthesize_enumerated_streett(sp)
    assert h is None, 'should be unrealizable'
    sp.env_init = ['y = x']
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    # g.save('moore.pdf')
    assert g is not None
    n = len(g)
    assert n == 6, n
Exemplo n.º 3
0
def test_synthesis_fol():
    sp = grspec_1()
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    assert g is not None
    assert len(g.inputs) == 1, g.inputs
    assert 'x' in g.inputs, g.inputs
    dom = g.inputs['x']
    dom_ = set(xrange(5))
    assert dom == dom_, (dom, dom_)
    assert len(g.outputs) == 1, g.outputs
    assert 'y' in g.outputs, g.outputs
    dom = g.outputs['y']
    dom_ = set(xrange(5))
    assert dom == dom_, (dom, dom_)
Exemplo n.º 4
0
def test_synthesis_fol():
    sp = grspec_1()
    h = omega_int.synthesize_enumerated_streett(sp)
    assert h is not None
    g = synth.strategy2mealy(h, sp)
    assert g is not None
    assert len(g.inputs) == 1, g.inputs
    assert 'x' in g.inputs, g.inputs
    dom = g.inputs['x']
    dom_ = set(range(5))
    assert dom == dom_, (dom, dom_)
    assert len(g.outputs) == 1, g.outputs
    assert 'y' in g.outputs, g.outputs
    dom = g.outputs['y']
    dom_ = set(range(5))
    assert dom == dom_, (dom, dom_)
Exemplo n.º 5
0
def test_synthesis_bool():
    sp = grspec_0()
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    # fname = 'mealy.pdf'
    # g.save(fname)
    # pd = nx.drawing.nx_pydot.to_pydot(g)
    # pd.write_pdf(fname)
    assert g is not None
    assert len(g.inputs) == 1, g.inputs
    assert 'x' in g.inputs, g.inputs
    dom = g.inputs['x']
    dom_ = {False, True}
    assert dom == dom_, (dom, dom_)
    assert len(g.outputs) == 1, g.outputs
    assert 'y' in g.outputs, g.outputs
    dom = g.outputs['y']
    dom_ = {False, True}
    assert dom == dom_, (dom, dom_)
    assert len(g) == 5, [g.nodes(data=True), g.edges(data=True)]
Exemplo n.º 6
0
def test_synthesis_bool():
    sp = grspec_0()
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    # fname = 'mealy.pdf'
    # g.save(fname)
    # pd = nx.drawing.nx_pydot.to_pydot(g)
    # pd.write_pdf(fname)
    assert g is not None
    assert len(g.inputs) == 1, g.inputs
    assert 'x' in g.inputs, g.inputs
    dom = g.inputs['x']
    dom_ = {False, True}
    assert dom == dom_, (dom, dom_)
    assert len(g.outputs) == 1, g.outputs
    assert 'y' in g.outputs, g.outputs
    dom = g.outputs['y']
    dom_ = {False, True}
    assert dom == dom_, (dom, dom_)
    assert len(g) == 5, [
        g.nodes(data=True), g.edges(data=True)]
Exemplo n.º 7
0
def test_synthesis_strings():
    sp = grspec_2()
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    assert g is not None
    # outputs
    assert len(g.outputs) == 1, g.outputs
    assert 'y' in g.outputs, g.outputs
    dom = g.outputs['y']
    dom_ = {'a', 'b'}
    assert dom == dom_, (dom, dom_)
    # check simulation
    n = len(g)
    assert n == 4, n
    u = 'Sinit'
    u, r = g.reaction(u, dict(x=0))
    assert r == dict(y='a'), r
    u, r = g.reaction(u, dict(x=2))
    assert r == dict(y='b'), r
    u, r = g.reaction(u, dict(x=1))
    assert r == dict(y='b'), r
    u, r = g.reaction(u, dict(x=0))
    assert r == dict(y='a'), r
Exemplo n.º 8
0
def test_synthesis_strings():
    sp = grspec_4()
    h = omega_int.synthesize_enumerated_streett(sp)
    g = synth.strategy2mealy(h, sp)
    assert g is not None
    # outputs
    assert len(g.outputs) == 1, g.outputs
    assert 'y' in g.outputs, g.outputs
    dom = g.outputs['y']
    dom_ = {'a', 'b'}
    assert dom == dom_, (dom, dom_)
    # check simulation
    n = len(g)
    assert n == 4, n
    u = 'Sinit'
    u, r = g.reaction(u, dict(x=0))
    assert r == dict(y='a'), r
    u, r = g.reaction(u, dict(x=2))
    assert r == dict(y='b'), r
    u, r = g.reaction(u, dict(x=1))
    assert r == dict(y='b'), r
    u, r = g.reaction(u, dict(x=0))
    assert r == dict(y='a'), r
Exemplo n.º 9
0
# Also force to use cudd.
ignore_env_init = False
ignore_sys_init = False
specs = synth._spec_plus_sys(specs, None, None, ignore_env_init,
                             ignore_sys_init)
realizable = synth.omega_int.is_realizable(specs, use_cudd=False)
print(realizable)

strategy = synth.omega_int.synthesize_enumerated_streett(specs, use_cudd=False)

# This is the shorthand way to create a Mealy machine of the strategy, but
# this way creates falsifiable initial transitions.
ctrl = synth._trim_strategy(strategy, specs, rm_deadends=True)
assert ctrl is not None, 'unrealizable'

full_mealy = synth.strategy2mealy(strategy, specs)
full_mealy.save('two_players_all_transitions.pdf')

# Use custom code to create Mealy machine. The initial transitions will only be
# created to states that fullfill both env_init and sys_init.
mealy = utils.strategy2mealy(strategy, specs)
mealy.remove_deadends()
mealy.save('two_players_strict_init.pdf')

# Showing how to construct a valid strategy by falsifying assumptions.
# Add a specification which puts player two in an impossible situation.
# Player one will force player two into a situation where one stick is left.
# However, player two cannot do anything. (S)he has to select sticks, but this
# conflicts with this new specification.
env_safe |= {'(sticks > 0 && player_turn = 2) -> player_2_picks < sticks'}
Exemplo n.º 10
0
def get_counterstrategy(specs) :
    counterstrategy = synthesize_environment(specs);
    ctrl = synth.strategy2mealy(counterstrategy, specs);
    return ctrl;