コード例 #1
0
def test_format_nx():
    g = nx.DiGraph()
    sorted_vars = ['x', 'y', 'w']
    g.add_node(0, x=5, y=3)
    g.add_node(1, w=True)
    g.add_edge(1, 0)
    h, umap = enum._format_nx(g, sorted_vars)
    assert len(h) == len(g), (h.nodes(), g.nodes())
    assert len(h) == len(umap), (h.nodes(), umap)
    ux = r' (x=5) ∧ (y=3) \l'
    uy = r' (w=True) \l'
    assert h.has_edge(uy, ux), h.edges()
コード例 #2
0
def test_format_nx():
    g = nx.DiGraph()
    sorted_vars = ['x', 'y', 'w']
    g.add_node(0, x=5, y=3)
    g.add_node(1, w=True)
    g.add_edge(1, 0)
    h, umap = enum._format_nx(g, sorted_vars)
    assert len(h) == len(g), (h.nodes(), g.nodes())
    assert len(h) == len(umap), (h.nodes(), umap)
    ux = r' (x=5) ∧ (y=3) \l'
    uy = r' (w=True) \l'
    assert h.has_edge(uy, ux), h.edges()
コード例 #3
0
ファイル: symbolic.py プロジェクト: tichakornw/omega
def semi_symbolic():
    """Example using a semi-enumerated state machine.

    Instructive variants:

    - `formula = "x'"`
    - `self_loops = True`
    - `aut.moore = False`
    """
    g = TransitionSystem()
    g.owner = 'sys'
    g.vars = dict(x='bool')
    g.env_vars.add('x')
    nx.add_path(g, range(11))
    g.add_edge(10, 10)
    g.add_edge(10, 0, formula="x")
    # symbolic
    aut = logicizer.graph_to_logic(g,
                                   'nd',
                                   ignore_initial=True,
                                   self_loops=False)
    aut.init['env'] = 'nd = 1'
    aut.win['<>[]'] = aut.bdds_from(' ~ x')
    aut.win['[]<>'] = aut.bdds_from('nd = 0')
    aut.qinit = '\A \A'
    aut.moore = True
    aut.plus_one = True
    print(aut)
    # compile to BDD
    z, yij, xijk = gr1.solve_streett_game(aut)
    gr1.make_streett_transducer(z, yij, xijk, aut)
    # print t.bdd.to_expr(t.action['sys'][0])
    r = aut.action['sys']
    # aut.bdd.dump('bdd.pdf', roots=[r])
    g = enumerate_controller(aut)
    h, _ = sym_enum._format_nx(g)
    pd = nx.drawing.nx_pydot.to_pydot(h)
    pd.write_pdf('game_states.pdf')
    print('Enumerated strategy has {n} nodes.'.format(n=len(g)))
    print(('Winning set:', aut.bdd.to_expr(z)))
    print('{n} BDD nodes in total'.format(n=len(aut.bdd)))
コード例 #4
0
ファイル: symbolic.py プロジェクト: johnyf/omega
def semi_symbolic():
    """Example using a semi-enumerated state machine.

    Instructive variants:

    - `formula = "x'"`
    - `self_loops = True`
    - `aut.moore = False`
    """
    g = TransitionSystem()
    g.owner = 'sys'
    g.vars = dict(x='bool')
    g.env_vars.add('x')
    g.add_path(range(11))
    g.add_edge(10, 10)
    g.add_edge(10, 0, formula="x")
    # symbolic
    aut = logicizer.graph_to_logic(
        g, 'nd', ignore_initial=True, self_loops=False)
    aut.init['env'] = 'nd = 1'
    aut.win['<>[]'] = aut.bdds_from(' ~ x')
    aut.win['[]<>'] = aut.bdds_from('nd = 0')
    aut.qinit = '\A \A'
    aut.moore = True
    aut.plus_one = True
    print(aut)
    # compile to BDD
    z, yij, xijk = gr1.solve_streett_game(aut)
    gr1.make_streett_transducer(z, yij, xijk, aut)
    # print t.bdd.to_expr(t.action['sys'][0])
    r = aut.action['sys']
    # aut.bdd.dump('bdd.pdf', roots=[r])
    g = enumerate_controller(aut)
    h, _ = sym_enum._format_nx(g)
    pd = nx.drawing.nx_pydot.to_pydot(h)
    pd.write_pdf('game_states.pdf')
    print('Enumerated strategy has {n} nodes.'.format(
        n=len(g)))
    print(('Winning set:', aut.bdd.to_expr(z)))
    print('{n} BDD nodes in total'.format(
        n=len(aut.bdd)))
コード例 #5
0
'''

aut.define(specs)
aut.init.update(env='envInit', sys='sysInit')
aut.action.update(env='envNext', sys='sysNext')

# aut.win['<>[]'] = aut.bdds_from('(sysX1 = 0 /\ sysY1 = 0)','(sysX1 = 2 /\ sysY1 = 0)', '(sysX1 = 0 /\ sysY1 = 2)')
# aut.win['[]<>'] = aut.bdds_from('(sysX1 = 0 /\ sysY1 = 0)','(sysX1 = 2 /\ sysY1 = 0)', '(sysX1 = 0 /\ sysY1 = 2)')

aut.win['<>[]'] = aut.bdds_from('TRUE')
aut.win['[]<>'] = aut.bdds_from('pos1 = 1', 'pos1 = 2')

aut.qinit = '\E \A'
aut.moore = True
aut.plus_one = True

# g = enum.action_to_steps(aut, 'env', 'sys', qinit=aut.qinit)
# h, _ = sym_enum._format_nx(g)
# pd = nx.drawing.nx_pydot.to_pydot(h)
# pd.write_pdf('outputs/single_gridworld_game_states_omega.pdf')

z, yij, xijk = gr1.solve_streett_game(aut)
gr1.make_streett_transducer(z, yij, xijk, aut)
aut.varlist['sys'].append('_goal')
aut.prime_varlists()
# enumerate
g = enum.action_to_steps(aut, 'env', 'impl', qinit=aut.qinit)
h, _ = sym_enum._format_nx(g)
pd = nx.drawing.nx_pydot.to_pydot(h)
pd.write_pdf('single_gridworld_game_states_omega.pdf')
コード例 #6
0
def dump_graph_as_figure(g):
    """Create a PDF file showing the graph `g`."""
    h, _ = sym_enum._format_nx(g)
    pd = nx.drawing.nx_pydot.to_pydot(h)
    pd.write_pdf('game_states.pdf')
コード例 #7
0
ファイル: gr1_synthesis_intro.py プロジェクト: johnyf/omega
def dump_graph_as_figure(g):
    """Create a PDF file showing the graph `g`."""
    h, _ = sym_enum._format_nx(g)
    pd = nx.drawing.nx_pydot.to_pydot(h)
    pd.write_pdf('game_states.pdf')