def create_rps_game(n=1, eps=0): assert n >= 1 k = n - 1 delta = 60 / (6 * n) # TODO context = { 'xRock': create_rock(k=k, p1=True, delta=delta, eps=eps), 'xScissors': create_scissors(k=k, p1=True, delta=delta, eps=eps), 'xPaper': create_paper(k=k, p1=True, delta=delta, eps=eps), 'yRock': create_rock(k=k, p1=False, delta=delta), 'yScissors': create_scissors(k=k, p1=False, delta=delta), 'yPaper': create_paper(k=k, p1=False, delta=delta), } context = fn.walk_keys(stl.parse, context) context.update(CONTEXT) spec = G.Specs( obj=stl.parse('G(Rules)', H=H).inline_context(context), learned=stl.TOP, init=stl.parse("Init").inline_context(context), ) return G.Game(specs=spec, model=MODEL)
def create_game(n=2, eps=0): assert n >= 1 k = n - 1 delta = 2 * 60 / n + 1e-2 # add padding to make last interval closed. # TODO p1_moves = gen_moves(k, p1=True, delta=delta, eps=eps) p2_moves = gen_moves(k, p1=False, delta=delta) def create_rule(i): return parse(f'(yMove{(i + 1) % n}) -> (~(xMove{i}))') context = {parse(f'xMove{i}'): move for i, move in enumerate(p1_moves)} context.update( {parse(f'yMove{i}'): move for i, move in enumerate(p2_moves)}) context.update({ parse("Init"): parse('(x = 0) & (y = 0)'), parse('Rules'): stl.andf(*map(create_rule, range(n))), }) spec = G.Specs( obj=parse('G(Rules)').inline_context(context), learned=stl.TOP, init=parse("Init").inline_context(context), ) return G.Game(specs=spec, model=MODEL)
from magnum import game as G import numpy as np # Setup the Model H = 8 model = G.Model( dt=0.1, vars=G.Vars(state=("x1", "x2"), input=("u", ), env=("w1", "w2")), dyn=G.Dynamics( A=np.array([[0, 1], [-1, -2]]), B=np.array([[20], [0]]), C=np.array([[1, 0], [0, 1]]))) # Setup the specification context = { stl.parse("Init"): stl.parse("(x1 = 4.2) & (x2 = 0)"), stl.parse("Sys"): stl.parse("F[0, 3]((x1 >= 5) & (x1 <= 6))", H=1), } spec = G.Specs( obj=stl.parse("Sys").inline_context(context), init=stl.parse("Init").inline_context(context), learned=stl.TOP, ) g = G.Game(specs=spec, model=model)
import stl from magnum import game as G import numpy as np # Setup the Model H = 3 model = G.Model(dt=1, vars=G.Vars(state=("x", ), input=("u", ), env=()), dyn=G.Dynamics(A=np.array([[0]]), B=np.array([[10]]), C=np.array([[]]))) # Setup the specification context = { stl.parse("Init"): stl.parse("x = 3"), stl.parse("ReachFive"): stl.parse("(F(x > 5)) & (G((x > 5) -> (F[0,2](x < 3))))", H=H), } spec = G.Specs( obj=stl.parse("ReachFive").inline_context(context), init=stl.parse("Init").inline_context(context), learned=stl.TOP, ) feasible_example = G.Game(specs=spec, model=model)