Esempio n. 1
0
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
Esempio n. 2
0
def test_orthotope_eq():
    fol, prm = setup_aut()
    varmap = prm._varmap
    r = lat.eq(varmap, fol)
    r_ = fol.add_expr('a_x = u_x /\ b_x = v_x /\ ' 'a_y = u_y /\ b_y = v_y')
    assert r == r_, (r, r_)
    d = dict(a_x=1, b_x=2, a_y=0, b_y=3)
    r = fol.let(d, r)
    d = dict(u_x=4, v_x=6, u_y=7, v_y=10)
    r = fol.let(d, r)
    assert r == fol.false
    r = lat.eq(varmap, fol)
    d = dict(a_x=1, b_x=2, a_y=0, b_y=3)
    r = fol.let(d, r)
    d = dict(u_x=1, v_x=2, u_y=0, v_y=3)
    r = fol.let(d, r)
    assert r == fol.true
Esempio n. 3
0
def test_orthotope_eq():
    fol, prm = setup_aut()
    varmap = prm._varmap
    r = lat.eq(varmap, fol)
    r_ = fol.add_expr(
        'a_x = u_x /\ b_x = v_x /\ '
        'a_y = u_y /\ b_y = v_y')
    assert r == r_, (r, r_)
    d = dict(a_x=1, b_x=2, a_y=0, b_y=3)
    r = fol.let(d, r)
    d = dict(u_x=4, v_x=6, u_y=7, v_y=10)
    r = fol.let(d, r)
    assert r == fol.false
    r = lat.eq(varmap, fol)
    d = dict(a_x=1, b_x=2, a_y=0, b_y=3)
    r = fol.let(d, r)
    d = dict(u_x=1, v_x=2, u_y=0, v_y=3)
    r = fol.let(d, r)
    assert r == fol.true
Esempio n. 4
0
def test_cost():
    r = cov._cost(None, '?', '?')
    assert r == float('inf'), r
    fol, prm = setup_aut()
    # assign here to avoid calling `eq` from `setup_aut`
    # to ensure unit testing
    prm.p_eq_q = lat.eq(prm._varmap, fol)
    s = ('1 <= a_x /\ a_x <= 3 /\ b_x = 6 /\ '
         '2 <= a_y /\ a_y <= 5 /\ '
         '0 <= b_y /\ b_y <= 7')
    u = fol.add_expr(s)
    r = cov._cost(u, prm, fol)
    assert r == 96, r
Esempio n. 5
0
def test_cost():
    r = cov._cost(None, '?', '?')
    assert r == float('inf'), r
    fol, prm = setup_aut()
    # assign here to avoid calling `eq` from `setup_aut`
    # to ensure unit testing
    prm.p_eq_q = lat.eq(prm._varmap, fol)
    s = (
        '1 <= a_x /\ a_x <= 3 /\ b_x = 6 /\ '
        '2 <= a_y /\ a_y <= 5 /\ '
        '0 <= b_y /\ b_y <= 7')
    u = fol.add_expr(s)
    r = cov._cost(u, prm, fol)
    assert r == 96, r
Esempio n. 6
0
def test_orthotopes_using_robots_example():
    aut, prm = setup_aut(15, 15)
    p_vars = prm.p_vars
    # this predicate is constructed by `contract_maker`
    # for the robots example in ACC 2016
    f = robots_example(aut)
    prm.p_leq_q = lat.subseteq(prm._varmap, aut)
    prm.p_eq_q = lat.eq(prm._varmap, aut)
    u = lat.prime_implicants(f, prm, aut)
    support = aut.support(u)
    assert support == set(p_vars), (support, p_vars)
    n_primes = aut.count(u)
    k = aut.count(u)
    assert n_primes == k, (n_primes, k)
    log.info('{n} prime implicants'.format(n=n_primes))
    u = lat.essential_orthotopes(f, prm, aut)
    support = aut.support(u)
    assert support == set(p_vars), (support, p_vars)
    n_essential = aut.count(u)
    k = aut.count(u)
    assert n_essential == k, (n_essential, k)
    log.info('{n} essential prime implicants'.format(n=n_essential))
    assert n_essential == 7, n_essential
    # result: all primes are essential in this example
    #
    care = aut.true
    s = cov.dumps_cover(u, f, care, aut)
    log.info(s)
    log.info('BDD has {n} nodes'.format(n=len(aut.bdd)))
    # confirm that essential orthotopes cover exactly `f`
    c = lat.list_expr(u, prm, aut, simple=True)
    s = stx.disj(c)
    log.info(s)
    z = aut.add_expr(s)
    z = aut.exist(['a_x', 'b_x', 'a_y', 'b_y'], z)
    assert aut.support(z) == aut.support(f)
    assert z == f
    if plt is not None:
        _plot_orthotopes_for_robots_example(u, f, prm._px, xvars, aut)
    # pprint.pprint(aut.bdd.statistics())
    # pprint.pprint(aut.bdd.vars)
    log.info('{n} nodes in manager'.format(n=len(aut.bdd)))
Esempio n. 7
0
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