Пример #1
0
def and_expr(conjuncts):
    conjuncts = [c for c in conjuncts if c != Bool(True)]

    if len(conjuncts) == 0:
        return Bool(True)

    if len(conjuncts) == 1:
        return conjuncts[0]

    res = conjuncts[0]
    for c in conjuncts[1:]:
        res &= c

    return res
Пример #2
0
def _create_LTL_for_E_formula(
        v_bits:
    SignalsTuple,  # v_bits[0] will correspond to j_bits[0] (left-most bit)
        path_formula: Expr,
        d: Dict[int, SignalsTuple],
        ordered_inputs: Tuple[Signal]) -> Expr:
    # TODO: what if we |v_bits| = 3 but not all bit valuations are used?
    # We create the conjunction:
    # for each j:
    #   G[ v=j -> (Gd_j -> path_formula) ]
    #
    # How to specify v=j?
    # - v should be represented by bits
    # - convert j into binary
    # - conjunct (v[i] == j_bits[i]) for each bit
    #
    # How to specify d_j?
    # - each d_j is represented by bits
    # - d_j actually means (d_j[in1], d_j[in2], ..., d_j[inK])
    # - then d_j is the conjunction "for each inK: d_j[inK]==inK"
    result = Bool(True)
    nof_IDs = len(d)
    for j in range(1, nof_IDs + 1):
        v_eq_j = _make_v_eq_j(j, v_bits)
        d_j_expr = _conjunction([
            (prop2(d[j][idx]) >> prop2(inp)) & (prop2(d[j][idx]) << prop2(inp))
            for idx, inp in enumerate(ordered_inputs)
        ])
        result &= G(v_eq_j >> (G(d_j_expr) >> path_formula))
    return result
Пример #3
0
    def test_ctl2aht(self):
        """ 'Crash' test: no assertions fails """
        rs, r = sig_prop('r')
        cs, c = sig_prop('c')
        gs, g = sig_prop('g')

        formulas = [
            AG(r >> F(g)),
            AG(r >> F(g)) & EGF(~g),
            AG(r >> F(g)) & EFG(g) & AFEG(~g),
            AG(r >> X(g & X(g & EGF(g) & EGF(~g)))),
            # AG(r >> F(g | c) & EGF(g) & EF(c) & EF(~c) & EGF(r)),   # TODO: why those tests are so slow?
            AG(EFG(r & g)),
            # AG(EFG(r & g)) | AFEG(g),
            AG(~r >> F(~g)) & AG(~r >> F(~g)) & EFG(g) & AFEG(~g),
            A(r),
            A(r) & A(~r),
            g,
            Bool(False),
            Bool(True)
        ]

        i = 0
        for f in formulas:
            i += 1
            print('checking: ' + str(f))

            dstFormPropMgr = DstFormulaPropMgr()
            shared_aht = SharedAHT()
            spec = Spec([rs, cs], [gs], f)
            ctl2aht(spec, self.ltl2ba, shared_aht, dstFormPropMgr)

            with tempfile.NamedTemporaryFile(delete=False) as dot_file:
                dot = aht2dot.convert(None, shared_aht, dstFormPropMgr)
                dot_file.write(dot.encode())
                # with open('/tmp/ttmmpp%i.dot'%i, 'w') as output:
                #     output.write(dot)

            os.remove(dot_file.name)
Пример #4
0
rs_array, r_array = [], []
gs_array, g_array = [], []
rm_s, rm = sig_prop('rm')
gm_s, gm = sig_prop('gm')

for i in range(n):
    rs, r = sig_prop('r_' + str(i))
    gs, g = sig_prop('g_' + str(i))
    rs_array.append(rs)
    r_array.append(r)
    gs_array.append(gs)
    g_array.append(g)

#
mut_excl = Bool(True)
for i in range(n):
    mut_excl &= G(g_array[i] >> ~(
        reduce(lambda x, y: x | y, g_array[:i], Bool(False))
        | reduce(lambda x, y: x | y, g_array[i + 1:], Bool(False)) | gm))
mut_excl &= G(gm >> ~reduce(lambda x, y: x | y, g_array))

#
req_is_granted = reduce(lambda x, y: x & y,
                        [G(r_array[i] >> F(g_array[i])) for i in range(n)],
                        Bool(True))
req_is_granted &= G(rm >> F(gm))

#
master_priority = G(
    rm >> X(U(reduce(lambda x, y: x & y, [~g for g in g_array]), gm)))
Пример #5
0
def _conjunction(iterable) -> Expr:
    return reduce(lambda x, y: x & y, iterable, Bool(True))
Пример #6
0
 def visit_bool(self, bool_:Bool):
     return Bool(bool_ == Bool(False))