def synthesize_enumerated_streett(spec): """Return transducer enumerated as a graph. @type spec: `tulip.spec.form.GRSpec` @rtype: `networkx.DiGraph` """ aut = _grspec_to_automaton(spec) assert aut.action['sys'] != aut.false t0 = time.time() z, yij, xijk = gr1.solve_streett_game(aut) t1 = time.time() # unrealizable ? if not gr1.is_realizable(z, aut): print('WARNING: unrealizable') return None gr1.make_streett_transducer(z, yij, xijk, aut) t2 = time.time() g = enum.action_to_steps(aut, 'env', 'impl', qinit=aut.qinit) h = _strategy_to_state_annotated(g, aut) del z, 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
def test_streett_trivial_loop(): a = trl.default_streett_automaton() a.declare_variables(x='bool') a.varlist['sys'] = ['x'] # solve assert len(a.win['<>[]']) == 1 assert len(a.win['[]<>']) == 1 z, yij, xijk = gr1.solve_streett_game(a) assert z == a.bdd.true, z # transducer gr1.make_streett_transducer(z, yij, xijk, a) # vars assert '_goal' in a.vars, a.vars vt = a.vars['_goal']['type'] assert vt == 'int', vt dom = a.vars['_goal']['dom'] assert dom == (0, 0), dom assert 'x' in a.vars, a.vars # init init = a.init['impl_env'] init_ = a.add_expr('_goal = 0') assert init == init_, a.bdd.to_expr(init) # action action = a.action['impl'] s = "(_goal = 0) /\ (_goal' = 0)" action_ = a.add_expr(s) assert action == action_, a.bdd.to_expr(action)
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
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
def test_streett_deadend(): aut = trl.default_streett_automaton() aut.declare_variables(x=(0, 10)) aut.varlist['sys'] = ['x'] aut.action['sys'] = aut.add_expr("(x = 0) /\ (x' = 5)") z, _, _ = gr1.solve_streett_game(aut) win_set = z assert win_set == aut.bdd.false, win_set
def is_realizable(spec): """Return `True` if, and only if, realizable. See `synthesize_enumerated_streett` for more details. """ aut = _grspec_to_automaton(spec) t0 = time.time() z, _, _ = gr1.solve_streett_game(aut) t1 = time.time() return gr1.is_realizable(z, aut)
def test_streett_with_liveness_assumption(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool', y=(0, 2)) aut.varlist = dict(env=['x'], sys=['y']) aut.init['env'] = aut.add_expr('y < 2') aut.action['sys'] = aut.add_expr( """ /\ ( ((y = 0) /\ ~ x) => (y' = 0) ) /\ ((y = 0) => (y' < 2)) /\ ((y = 1) => (y' = 0)) /\ ((y = 2) => FALSE) /\ y \in 0..2 """) aut.win['<>[]'] = [aut.add_expr(' ~ x')] aut.win['[]<>'] = [aut.add_expr('y = 1')] # solve z, yij, xijk = gr1.solve_streett_game(aut) z_ = aut.add_expr('y < 2') e = aut.bdd.to_expr(z) e_ = aut.bdd.to_expr(z_) assert z == z_, (e, e_) # transducer gr1.make_streett_transducer(z, yij, xijk, aut) assert action_refined(aut) init = aut.init['impl_env'] assert init == aut.add_expr('(y < 2) /\ (_goal = 0)'), aut.bdd.to_expr(init) action = aut.action['impl'] s = ( "( (y = 0) => ite(x, (y' = 1), (y' = 0)) ) /\ " "( (y = 1) => (y' = 0) ) /\ " "( (_goal = 0) /\ (_goal' = 0) ) /\ " "( (y /= 2) /\ (y /= 3) )") action_ = aut.add_expr(s) sat = list(aut.bdd.pick_iter(action)) sys_action = aut.action['sys'] sys_action = gr1._copy_bdd(sys_action, aut.bdd, aut.bdd) u = aut.apply('=>', action, sys_action) assert u == aut.bdd.true, u assert action == action_, (action, action_, pprint.pprint(sat)) # # test complement b = trl.default_rabin_automaton() b.acceptance = 'Rabin(1)' b.declare_variables(x='bool', y=(0, 2)) b.varlist = dict(env=['y'], sys=['x']) b.action['env'] = gr1._copy_bdd(aut.action['sys'], aut.bdd, b.bdd) b.win['<>[]'] = [b.add_expr('y /= 1')] b.win['[]<>'] = [b.add_expr('x')] zk, yki, xkijr = gr1.solve_rabin_game(b) rabin_win_set = zk[-1] bdd = b.bdd streett_win_set = gr1._copy_bdd(z, aut.bdd, bdd) assert rabin_win_set == bdd.apply('not', streett_win_set) with assert_raises(AssertionError): gr1.make_rabin_transducer(zk, yki, xkijr, b)
def synthesize_some_controller(aut): """Return a controller that implements the spec. If no controller exists, then raise an `Exception`. The returned controller is represented as a `networkx` graph. """ z, yij, xijk = gr1.solve_streett_game(aut) gr1.make_streett_transducer(z, yij, xijk, aut) g = enum.action_to_steps( aut, env='env', sys='impl', qinit=aut.qinit) return g
def test_streett_with_liveness_assumption(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool', y=(0, 2)) aut.varlist = dict(env=['x'], sys=['y']) aut.init['env'] = aut.add_expr('y < 2') aut.action['sys'] = aut.add_expr(""" /\ ( ((y = 0) /\ ~ x) => (y' = 0) ) /\ ((y = 0) => (y' < 2)) /\ ((y = 1) => (y' = 0)) /\ ((y = 2) => FALSE) /\ y \in 0..2 """) aut.win['<>[]'] = [aut.add_expr(' ~ x')] aut.win['[]<>'] = [aut.add_expr('y = 1')] # solve z, yij, xijk = gr1.solve_streett_game(aut) z_ = aut.add_expr('y < 2') e = aut.bdd.to_expr(z) e_ = aut.bdd.to_expr(z_) assert z == z_, (e, e_) # transducer gr1.make_streett_transducer(z, yij, xijk, aut) assert action_refined(aut) init = aut.init['impl_env'] assert init == aut.add_expr('(y < 2) /\ (_goal = 0)'), aut.bdd.to_expr( init) action = aut.action['impl'] s = ("( (y = 0) => ite(x, (y' = 1), (y' = 0)) ) /\ " "( (y = 1) => (y' = 0) ) /\ " "( (_goal = 0) /\ (_goal' = 0) ) /\ " "( (y /= 2) /\ (y /= 3) )") action_ = aut.add_expr(s) sat = list(aut.bdd.pick_iter(action)) sys_action = aut.action['sys'] sys_action = gr1._copy_bdd(sys_action, aut.bdd, aut.bdd) u = aut.apply('=>', action, sys_action) assert u == aut.bdd.true, u assert action == action_, (action, action_, pprint.pprint(sat)) # # test complement b = trl.default_rabin_automaton() b.acceptance = 'Rabin(1)' b.declare_variables(x='bool', y=(0, 2)) b.varlist = dict(env=['y'], sys=['x']) b.action['env'] = gr1._copy_bdd(aut.action['sys'], aut.bdd, b.bdd) b.win['<>[]'] = [b.add_expr('y /= 1')] b.win['[]<>'] = [b.add_expr('x')] zk, yki, xkijr = gr1.solve_rabin_game(b) rabin_win_set = zk[-1] bdd = b.bdd streett_win_set = gr1._copy_bdd(z, aut.bdd, bdd) assert rabin_win_set == bdd.apply('not', streett_win_set) with assert_raises(AssertionError): gr1.make_rabin_transducer(zk, yki, xkijr, b)
def test_streett_always_x(): # always x aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist['sys'] = ['x'] aut.moore = False aut.action['sys'] = aut.add_expr("x' ") # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.true, z # transducer gr1.make_streett_transducer(z, yij, xijk, aut) # init init = aut.init['impl_env'] init_ = aut.add_expr('_goal = 0') assert init == init_, aut.bdd.to_expr(init) # action action = aut.action['impl'] s = ( "(_goal = 0) /\ (_goal' = 0) /\ " "x' ") action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action) # # always ~ x aut.init['env'] = aut.add_expr(' ~ x') aut.action['sys'] = aut.add_expr(' ~ x') # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.add_expr(' ~ x'), aut.bdd.to_expr(z) # tranducer gr1.make_streett_transducer(z, yij, xijk, aut) assert action_refined(aut) init = aut.init['impl_env'] init_ = aut.add_expr('(_goal = 0) /\ ~ x') assert init == init_, aut.bdd.to_expr(init) action = aut.action['impl'] s = "(_goal = 0) /\ (_goal' = 0) /\ ~ x /\ ~ x'" action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action)
def synthesize_some_controller(aut): """Return a controller that implements the spec. If no controller exists, then raise an `Exception`. The returned controller is represented as a `networkx` graph. """ z, yij, xijk = gr1.solve_streett_game(aut) gr1.make_streett_transducer(z, yij, xijk, aut) aut.init['env'] = aut.init['impl_env'] aut.init['sys'] = aut.init['impl_sys'] aut.action['sys'] = aut.action['impl'] g = enum.action_to_steps(aut, qinit=aut.qinit) return g
def test_streett_always_x(): # always x aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist['sys'] = ['x'] aut.moore = False aut.action['sys'] = aut.add_expr("x' ") # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.true, z # transducer gr1.make_streett_transducer(z, yij, xijk, aut) # init init = aut.init['impl_env'] init_ = aut.add_expr('_goal = 0') assert init == init_, aut.bdd.to_expr(init) # action action = aut.action['impl'] s = ("(_goal = 0) /\ (_goal' = 0) /\ " "x' ") action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action) # # always ~ x aut.init['env'] = aut.add_expr(' ~ x') aut.action['sys'] = aut.add_expr(' ~ x') # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.add_expr(' ~ x'), aut.bdd.to_expr(z) # tranducer gr1.make_streett_transducer(z, yij, xijk, aut) assert action_refined(aut) init = aut.init['impl_env'] init_ = aut.add_expr('(_goal = 0) /\ ~ x') assert init == init_, aut.bdd.to_expr(init) action = aut.action['impl'] s = "(_goal = 0) /\ (_goal' = 0) /\ ~ x /\ ~ x'" action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action)
def test_streett_with_safety_assumption(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist['env'] = ['x'] aut.moore = False aut.plus_one = False aut.action['env'] = aut.add_expr('x') aut.action['sys'] = aut.add_expr('x') # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.true, z # transducer gr1.make_streett_transducer(z, yij, xijk, aut) init = aut.init['impl_env'] assert init == aut.add_expr('_goal = 0'), aut.bdd.to_expr(init) action = aut.action['impl'] action_ = aut.add_expr("x => ((_goal = 0) /\ (_goal' = 0))") assert action == action_, aut.bdd.to_expr(action) # # negate action to make unrealizable aut.action['sys'] = aut.add_expr(' ~ x') # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.add_expr(' ~ x'), aut.bdd.to_expr(z) # transducer with assert_raises(AssertionError): gr1.make_streett_transducer(z, yij, xijk, aut) # Moore case aut.moore = True aut.plus_one = False aut.action['env'] = aut.add_expr('x') aut.action['sys'] = aut.add_expr('x') # solve z_moore, yij, xijk = gr1.solve_streett_game(aut) assert z_moore != z, 'should differ due to plus_one' gr1.make_streett_transducer(z_moore, yij, xijk, aut) init = aut.init['impl_env'] assert init == aut.add_expr('_goal = 0'), aut.bdd.to_expr(init)
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)
def test_streett_qinit_exist_forall(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool', y=(0, 5)) aut.varlist = dict(env=['x'], sys=['y']) aut.moore = True aut.qinit = '\E \A' aut.init['env'] = aut.add_expr('x') aut.init['sys'] = aut.add_expr('(x => (y = 4)) /\ y \in 0..5') aut.action['sys'] = aut.add_expr('y \in 0..5') # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.add_expr('y \in 0..5'), aut.bdd.to_expr(z) # transducer gr1.make_streett_transducer(z, yij, xijk, aut) u = aut.init['impl_env'] u_ = aut.add_expr('x /\ (y = 4) /\ (_goal = 0)') assert u == u_, aut.bdd.to_expr(u)
def test_streett_2_goals(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist = dict(env=list(), sys=['x']) aut.win['[]<>'] = [aut.add_expr('x'), aut.add_expr(' ~ x')] # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.bdd.true, aut.bdd.to_expr(z) # transducer gr1.make_streett_transducer(z, yij, xijk, aut) assert action_refined(aut) action = aut.action['impl'] # print_fol_bdd(action, aut.bdd, aut.vars) # enumeration.dump_relation(action, aut) s = ("((x /\ (_goal = 0)) => (_goal' = 1)) /\ " "(( ~ x /\ (_goal = 1)) => (_goal' = 0)) /\ " "(( ~ x /\ (_goal = 0)) => (x' /\ (_goal' = 0))) /\ " "((x /\ (_goal = 1)) => ( ~ x' /\ (_goal' = 1)))") action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action)
def test_streett_counter(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist['sys'] = ['x'] aut.action['sys'] = aut.add_expr("x => ~ x' ") aut.win['[]<>'] = [aut.add_expr('x')] # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.true, z # transducer gr1.make_streett_transducer(z, yij, xijk, aut) init = aut.init['impl_env'] init_ = aut.add_expr('_goal = 0') assert init == init_, aut.bdd.to_expr(init) action = aut.action['impl'] assert action_refined(aut) # regression s = ("(_goal = 0) /\ (_goal' = 0) /\ " "(x <=> ~ x')") action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action)
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)))
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)))
def test_streett_2_goals(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist = dict(env=list(), sys=['x']) aut.win['[]<>'] = [aut.add_expr('x'), aut.add_expr(' ~ x')] # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.bdd.true, aut.bdd.to_expr(z) # transducer gr1.make_streett_transducer(z, yij, xijk, aut) assert action_refined(aut) action = aut.action['impl'] # print_fol_bdd(action, aut.bdd, aut.vars) # enumeration.dump_relation(action, aut) s = ( "((x /\ (_goal = 0)) => (_goal' = 1)) /\ " "(( ~ x /\ (_goal = 1)) => (_goal' = 0)) /\ " "(( ~ x /\ (_goal = 0)) => (x' /\ (_goal' = 0))) /\ " "((x /\ (_goal = 1)) => ( ~ x' /\ (_goal' = 1)))") action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action)
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")
def test_streett_counter(): aut = trl.default_streett_automaton() aut.declare_variables(x='bool') aut.varlist['sys'] = ['x'] aut.action['sys'] = aut.add_expr("x => ~ x' ") aut.win['[]<>'] = [aut.add_expr('x')] # solve z, yij, xijk = gr1.solve_streett_game(aut) assert z == aut.true, z # transducer gr1.make_streett_transducer(z, yij, xijk, aut) init = aut.init['impl_env'] init_ = aut.add_expr('_goal = 0') assert init == init_, aut.bdd.to_expr(init) action = aut.action['impl'] assert action_refined(aut) # regression s = ( "(_goal = 0) /\ (_goal' = 0) /\ " "(x <=> ~ x')") action_ = aut.add_expr(s) assert action == action_, aut.bdd.to_expr(action)
def synthesize_some_controller(env, sys, aut): """Return a controller that implements the spec. If no controller exists, then raise an `Exception`. The returned controller is represented as a `networkx` graph. """ aut.prime_varlists() # vars aut.varlist['env'] = aut.varlist[env] + aut.varlist['scheduler'] aut.varlist['sys'] = aut.varlist[sys] # init aut.init['env'] = aut.init[env] aut.init['sys'] = aut.init[sys] # actions aut.action['env'] = aut.action[env] aut.action['sys'] = aut.action[sys] # win aut.win['[]<>'] = aut.win[sys]['[]<>'] aut.win['<>[]'] = aut.win[sys]['<>[]'] z, yij, xijk = gr1.solve_streett_game(aut) gr1.make_streett_transducer(z, yij, xijk, aut) aut.varlist[sys].append('_goal') aut.prime_varlists()
''' 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')
(* type invariant *) /\ foo \in 1..15 /\ foo' \in 1..15 ''' aut.action['sys'] = ''' (* type invariant *) /\ (bar \in -15..-1) /\ (bar' \in -15..-1) (* inversion with one-step delay *) /\ (bar' + foo <= 0) /\ (bar' < -2) ''' aut.win['<>[]'] = aut.bdds_from(' ~ (foo = 3) ') aut.win['[]<>'] = aut.bdds_from(' bar = - 3 ') aut.plus_one = True # strictly causal stepwise implication aut.moore = True # implementation reads current state; not x' aut.qinit = '\E \A' # disjoint-state throughout fixpoint_iterates = gr1.solve_streett_game(aut) gr1.make_streett_transducer(*fixpoint_iterates, aut) synthesized_action = aut.action['impl'] care = aut.type_hint_for(["foo", "bar", "foo'", "bar'", "_goal", "_goal'"]) care = aut.to_bdd(care) # restrict the environment to values of interest u = synthesized_action & care expr = aut.to_expr(u, care=care, show_dom=True) print(expr)
def forall(*arg): *vrs, u = arg return aut.forall(vrs, u) sys_init_synth = exist('x', sys_init) | ~exist('x', 'y', env_init) sys_init_synth &= sys_init | ~env_init sys_next_synth = (exist("x'", sys_next) & forall("x'", sys_next | ~env_next)) aut.moore = True # a synthesis option that describes the implementation aut.plus_one = True # a specification formula option, affects # init form and # the steady state (win set via the controllable step operator) aut.qinit = '\E \A' # whether state is disjoint or initially shared: # a synthesis option that describes the kind of implementation # initial conditions aut.init['env'] = env_init aut.init['sys'] = sys_init_synth # actions aut.action['env'] = env_next aut.action['sys'] = sys_next_synth # liveness requirements aut.win['<>[]'] = [~env_live] aut.win['[]<>'] = [sys_live] fx_iterates = gr1.solve_streett_game(aut) gr1.make_streett_transducer(*fx_iterates, aut)
return aut.forall(vrs, u) sys_init_synth = exist('x', sys_init) | ~ exist('x', 'y', env_init) sys_init_synth &= sys_init | ~ env_init sys_next_synth = ( exist("x'", sys_next) & forall("x'", sys_next | ~ env_next)) aut.moore = True # a synthesis option that describes the implementation aut.plus_one = True # a specification formula option, affects # init form and # the steady state (win set via the controllable step operator) aut.qinit = '\E \A' # whether state is disjoint or initially shared: # a synthesis option that describes the kind of implementation # initial conditions aut.init['env'] = env_init aut.init['sys'] = sys_init_synth # actions aut.action['env'] = env_next aut.action['sys'] = sys_next_synth # liveness requirements aut.win['<>[]'] = [~ env_live] aut.win['[]<>'] = [sys_live] fx_iterates = gr1.solve_streett_game(aut) gr1.make_streett_transducer(*fx_iterates, aut)
/\ foo \in 1..15 /\ foo' \in 1..15 ''' aut.action['sys'] = ''' (* type invariant *) /\ (bar \in -15..-1) /\ (bar' \in -15..-1) (* inversion with one-step delay *) /\ (bar' + foo <= 0) /\ (bar' < -2) ''' aut.win['<>[]'] = aut.bdds_from(' ~ (foo = 3) ') aut.win['[]<>'] = aut.bdds_from(' bar = - 3 ') aut.plus_one = True # strictly causal stepwise implication aut.moore = True # implementation reads current state; not x' aut.qinit = '\E \A' # disjoint-state throughout fixpoint_iterates = gr1.solve_streett_game(aut) gr1.make_streett_transducer(*fixpoint_iterates, aut) synthesized_action = aut.action['impl'] care = aut.type_hint_for([ "foo", "bar", "foo'", "bar'", "_goal", "_goal'"]) care = aut.to_bdd(care) # restrict the environment to values of interest u = synthesized_action & care expr = aut.to_expr(u, care=care, show_dom=True) print(expr)