def sys3():
    mdp = sys1()
    mdp |= C.circ2mdp(BV.tee(1, {'c': ['c', 'c_next']}))
    coin = (~C.coin((1, 2), name='c')).with_output('c')
    mdp <<= coin

    delay = BV.aig2aigbv(aiger.delay(['c'], [True]))
    delay = C.circ2mdp(delay)

    return mdp >> delay
Пример #2
0
def test_smoke():
    spec = PLTL.atom('a').historically()
    spec = BV.aig2aigbv(spec.aig)
    spec = C.circ2mdp(spec)
    spec <<= C.coin((1, 8), name='c')
    spec >>= C.circ2mdp(BV.sink(1, ['c']))  # HACK

    bdd, manager, order = to_bdd2(spec, horizon=3)

    assert bdd.dag_size == 4

    for i in range(order.total_bits*order.horizon):
        t = order.time_step(i)
        var = manager.var_at_level(i)
        action, t2, _ = TIMED_INPUT_MATCHER.match(var).groups()
        assert t == int(t2)
        decision = action in spec.inputs
        assert decision == order.is_decision(i)
Пример #3
0
def test_smoke2():
    spec, mdp = scenario_reactive()

    spec_circ = BV.aig2aigbv(spec.aig)
    mdp >>= C.circ2mdp(spec_circ)
    output = spec.output

    bdd, manager, order = to_bdd2(mdp, horizon=3, output=output)

    assert bdd.dag_size == 7

    def translate(mapping):
        return mapping

    assert bdd.count(6) == 8

    node = bdd

    assert bdd.bdd.let(translate({
        'a##time_0[0]': True,
        'c##time_0[0]': False,
        'a##time_1[0]': True,
    }), bdd) == bdd.bdd.false

    assert bdd.bdd.let(translate({
        'a##time_0[0]': True,
        'c##time_0[0]': True,
        'a##time_1[0]': False,
    }), bdd) == bdd.bdd.false

    assert node.low == bdd.bdd.false

    assert bdd.bdd.let(translate({
        'a##time_0[0]': True,
        'c##time_0[0]': True,
        'a##time_1[0]': True,
        'c##time_1[0]': True,
        'a##time_2[0]': True,
        'c##time_2[0]': True,
    }), bdd) == bdd.bdd.true

    assert bdd.bdd.let(translate({
        'a##time_0[0]': True,
        'c##time_0[0]': False,
        'a##time_1[0]': False,
        'c##time_1[0]': False,
        'a##time_2[0]': False,
        'c##time_2[0]': False,
    }), bdd) == bdd.bdd.true

    assert bdd.bdd.let(translate({
        'c##time_0[0]': False,
        'a##time_1[0]': True,
    }), bdd) == bdd.bdd.false

    assert bdd.bdd.let(translate({
        'c##time_0[0]': True,
        'a##time_1[0]': False,
    }), bdd) == bdd.bdd.false

    assert bdd.bdd.let(translate({
        'c##time_1[0]': False,
        'a##time_2[0]': True,
    }), bdd) == bdd.bdd.false

    assert bdd.bdd.let(translate({
        'c##time_1[0]': True,
        'a##time_2[0]': False,
    }), bdd) == bdd.bdd.false

    assert bdd.bdd.let(translate({
        'c##time_2[0]': False,
    }), bdd) == bdd

    assert bdd.bdd.let(translate({
        'c##time_2[0]': True,
    }), bdd) == bdd
Пример #4
0
}


def create_sensor(aps):
    sensor = BV.aig2aigbv(A.empty())
    for name, ap in APS.items():
        sensor |= ap.with_output(name).aigbv
    return sensor


SENSOR = create_sensor(APS)
DYN = GW.gridworld(8, start=(8, 8), compressed_inputs=True)

SLIP = BV.atom(1, 'c', signed=False).repeat(2) & BV.atom(2, 'a', signed=False)
SLIP = SLIP.with_output('a').aigbv
DYN2 = C.coin((31, 32), 'c') >> C.circ2mdp(DYN << SLIP)


def encode_state(x, y):
    x, y = [BV.encode_int(8, 1 << (v - 1), signed=False) for v in (x, y)]
    return {'x': tuple(x), 'y': tuple(y)}


def ap_at_state(x, y, in_ascii=False):
    state = encode_state(x, y)
    obs = SENSOR(state)[0]

    if not in_ascii:
        return obs

    for k, code in {'yellow': 3, 'red': 1}.items():
def sys2():
    mdp = sys1()
    mdp <<= C.coin((1, 8), name='c')
    mdp >>= C.circ2mdp(BV.sink(1, ['c']))  # HACK
    return mdp
def sys1():
    return C.circ2mdp(BV.identity_gate(1, 'a'))
Пример #7
0
import aiger_bv as BV
import aiger_coins as C
import aiger_ptltl as LTL

from mce.equiv import equiv_states

X = LTL.atom('x')
Y = LTL.atom('y')
SYS = C.circ2mdp(BV.aig2aigbv((X.once() | Y.once()).aig))


def test_equiv_states_smoke():
    state = SYS._aigbv.latch2init

    for t in range(3):
        assert equiv_states(SYS, 3, t, state1=state, state2=state)

    state1 = SYS.aigbv({'x': (True, ), 'y': (False, )})[1]
    state2 = SYS.aigbv({'x': (False, ), 'y': (True, )})[1]
    assert state1 != state2

    for t in range(3):
        assert equiv_states(SYS, 3, t, state1=state1, state2=state2)