def setup_aut(xmax=15, ymax=15): fol = _fol.Context() fol.bdd.configure(reordering=True) # CAUTION: remember that type hints (safety) # needs to be added as care set fol.declare(x=(0, xmax), y=(0, ymax)) x_vars = ['x', 'y'] p_table = lat._parameter_table( x_vars, fol.vars, a_name='a', b_name='b') q_table = lat._parameter_table( x_vars, fol.vars, a_name='u', b_name='v') fol.declare(**p_table) fol.declare(**q_table) px = lat._map_vars_to_parameters( x_vars, a_name='a', b_name='b') qx = lat._map_vars_to_parameters( x_vars, a_name='u', b_name='v') varmap = lat.parameter_varmap(px, qx) p_to_q = lat._renaming_between_parameters(px, qx) prm = lat.Parameters() prm.x_vars = x_vars prm.p_vars = set(p_table) prm.q_vars = set(q_table) prm.p_to_q = p_to_q prm._px = px prm._qx = qx prm._varmap = varmap return fol, prm
def setup_orthotope_vars(): fol = _fol.Context() fol.declare( x=(0, 5), y=(2, 14), px=(0, 5), qx=(0, 5), py=(2, 14), qy=(2, 14), ax=(0, 5), bx=(0, 5), ay=(2, 14), by=(2, 14), ) xvars = ['x', 'y'] px = dict(x=dict(a='px', b='qx'), y=dict(a='py', b='qy')) qx = dict(x=dict(a='ax', b='bx'), y=dict(a='ay', b='by')) prm = lat.Parameters() prm.x_vars = xvars prm._px = px prm._qx = qx prm.p_to_q = dict(px='ax', py='ay', qx='bx', qy='by') prm.p_vars = set(prm.p_to_q) prm.q_vars = set(prm.p_to_q.values()) varmap = lat.parameter_varmap(px, qx) prm.p_leq_q = lat.subseteq(varmap, fol) prm.p_eq_q = lat.eq(varmap, fol) return fol, prm
def test_scaling_equality(): aut = _fol.Context() x_vars = dict(x=(0, 10), y=(0, 15), z=(0, 15)) aut.declare(**x_vars) params = dict(pa='a', pb='b', qa='u', qb='v') p_dom = lat._parameter_table(x_vars, aut.vars, a_name=params['pa'], b_name=params['pb']) q_dom = lat._parameter_table(x_vars, aut.vars, a_name=params['qa'], b_name=params['qb']) aut.declare(**p_dom) aut.declare(**q_dom) px = lat._map_vars_to_parameters(x_vars, a_name=params['pa'], b_name=params['pb']) qx = lat._map_vars_to_parameters(x_vars, a_name=params['qa'], b_name=params['qb']) p_to_q = lat._renaming_between_parameters(px, qx) x_as_x = {xj: dict(a=xj, b=xj) for xj in px} varmap = lat.parameter_varmap(px, x_as_x) log.info('Number of variables: {n}'.format(n=len(varmap))) u = lat.subseteq(varmap, aut) # s = ('( ' '(z = 1 /\ y <= 0) \/ ' '(x = 0 /\ z = 1) \/ ' '(y >= 1 /\ x <= 0) \/ ' '(y >= 1 /\ z <= 0) \/ ' '(x >= 1 /\ z <= 0) \/ ' '(x >= 1 /\ y <= 0) ' ') ') f = aut.add_expr(s) prm = lat.Parameters() prm._px = px lat.embed_as_implicants(f, prm, aut)
def setup_orthotope_vars(): fol = _fol.Context() fol.declare( x=(0, 5), y=(2, 14), px=(0, 5), qx=(0, 5), py=(2, 14), qy=(2, 14), ax=(0, 5), bx=(0, 5), ay=(2, 14), by=(2, 14),) xvars = ['x', 'y'] px = dict(x=dict(a='px', b='qx'), y=dict(a='py', b='qy')) qx = dict(x=dict(a='ax', b='bx'), y=dict(a='ay', b='by')) prm = lat.Parameters() prm.x_vars = xvars prm._px = px prm._qx = qx prm.p_to_q = dict(px='ax', py='ay', qx='bx', qy='by') prm.p_vars = set(prm.p_to_q) prm.q_vars = set(prm.p_to_q.values()) varmap = lat.parameter_varmap(px, qx) prm.p_leq_q = lat.subseteq(varmap, fol) prm.p_eq_q = lat.eq(varmap, fol) return fol, prm
def test_scaling_equality(): aut = _fol.Context() x_vars = dict(x=(0, 10), y=(0, 15), z=(0, 15)) aut.declare(**x_vars) params = dict(pa='a', pb='b', qa='u', qb='v') p_dom = lat._parameter_table( x_vars, aut.vars, a_name=params['pa'], b_name=params['pb']) q_dom = lat._parameter_table( x_vars, aut.vars, a_name=params['qa'], b_name=params['qb']) aut.declare(**p_dom) aut.declare(**q_dom) px = lat._map_vars_to_parameters( x_vars, a_name=params['pa'], b_name=params['pb']) qx = lat._map_vars_to_parameters( x_vars, a_name=params['qa'], b_name=params['qb']) p_to_q = lat._renaming_between_parameters(px, qx) x_as_x = {xj: dict(a=xj, b=xj) for xj in px} varmap = lat.parameter_varmap(px, x_as_x) log.info('Number of variables: {n}'.format(n=len(varmap))) u = lat.subseteq(varmap, aut) # s = ( '( ' '(z = 1 /\ y <= 0) \/ ' '(x = 0 /\ z = 1) \/ ' '(y >= 1 /\ x <= 0) \/ ' '(y >= 1 /\ z <= 0) \/ ' '(x >= 1 /\ z <= 0) \/ ' '(x >= 1 /\ y <= 0) ' ') ') f = aut.add_expr(s) prm = lat.Parameters() prm._px = px lat.embed_as_implicants(f, prm, aut)
def test_parameter_varmap(): px, qx = dummy_parameters() d = lat.parameter_varmap(px, qx) d_ = {('a_x', 'b_x'): ('u_x', 'v_x'), ('a_y', 'b_y'): ('u_y', 'v_y')} assert d == d_, (d, d_)