當前位置: 首頁>>代碼示例>>Python>>正文


Python expression.Be類代碼示例

本文整理匯總了Python中pynusmv.be.expression.Be的典型用法代碼示例。如果您正苦於以下問題:Python Be類的具體用法?Python Be怎麽用?Python Be使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Be類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_globally_no_loop

 def test_globally_no_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("G (a <-> !b)")
         
         #  bound 0
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 0)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----
         #  bound 0
         offset  = 1
         ref_expr= Be.false(fsm.encoding.manager)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         #  bound 1
         offset  = 1
         ref_expr= Be.false(fsm.encoding.manager)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:27,代碼來源:testBmcLTLspecAtOffset.py

示例2: test_false

 def test_false(self):
     with self.assertRaises(Exception):
         Be.false(None)
     expr = Be.false(self._manager)
     self.assertFalse(expr.is_true())
     self.assertTrue(expr.is_false())
     self.assertTrue(expr.is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:7,代碼來源:testBe.py

示例3: bounded_semantics

    def bounded_semantics(self, fsm, k, fairness=True):
        """
        Returns a boolean expression corresponding to the bounded semantics of
        the formula denoted by `self` on a path of length k. This combines both
        the semantics in case of a loopy path and the case of a non-loopy path.

        .. note::
            This function takes the same approach as NuSMV and does not enforce
            the absence of loop when using the more restrictive semantic_no_loop.

        :param fsm: the FSM representing the model. It is used to gain access
            to the encoder (-> shift variables) and to obtain the list of
            fairness constraints.
        :param k: the last time that exists in the universe of this expression
        :param fairness: a flag indicating whether or not the fairness constraints
            should be taken into account while generating the formula.
        :return: a boolean expression translating the bounded semantics of this
            formula.
        """
        enc = fsm.encoding
        noloop = self.semantic_no_loop(enc, 0, k)

        w_loop = Be.false(enc.manager)
        for l in range(k):  # [0; k-1]
            fairness_cond = fairness_constraint(fsm, k, l) if fairness else Be.true(enc.manager)

            w_loop |= loop_condition(enc, k, l) & fairness_cond & self.semantic_with_loop(enc, 0, k, l)

        return noloop | w_loop
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:29,代碼來源:ast.py

示例4: test_constant_with_loop

 def test_constant_with_loop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         expr = ast.Constant("TRUE")
         self.assertEqual(Be.true(self.mgr), expr.semantic_with_loop(self.enc, 0, 5, 2))
         
         expr = ast.Constant("FALSE")
         self.assertEqual(Be.false(self.mgr), expr.semantic_with_loop(self.enc, 0, 5, 2))
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:7,代碼來源:testSemantics.py

示例5: test_bounded_semantics_without_loop

 def test_bounded_semantics_without_loop(self):
     # parse the ltl property
     spec = Node.from_ptr(parse_ltl_spec("G ( y <= 7 )"))
     
     # it must raise exception when the bound is not feasible
     with self.assertRaises(ValueError):
         ltlspec.bounded_semantics_without_loop(self.fsm, spec, bound=-1)
     
     # verify that the generated expression corresponds to what is announced
     no_loop = ltlspec.bounded_semantics_without_loop(self.fsm, spec, 10)
     
     # globally w/o loop is false (this is just a test)
     self.assertEqual(no_loop, Be.false(self.fsm.encoding.manager)) 
     
     # an other more complex generation
     spec = Node.from_ptr(parse_ltl_spec("F (y <= 7)"))
     no_loop = ltlspec.bounded_semantics_without_loop(self.fsm, spec, 10)
     
     #
     # The generated expression is [[f]]^{0}_{k} so (! L_{k}) is not taken 
     # care of. And actually, NuSMV does not generate that part of the 
     # formula: it only enforce the loop condition when the semantics with 
     # loop is used 
     # 
     handcrafted = Be.false(self.fsm.encoding.manager)
     y_le_seven  = Wff(parse_ltl_spec("y <= 7")).to_boolean_wff().to_be(self.fsm.encoding)
     for time_x in reversed(range(11)): # 11 because range 'eats' up the last step
         handcrafted |= self.fsm.encoding.shift_to_time(y_le_seven, time_x)
     
     #### debuging info #####
     #print("noloop  = {}".format(no_loop.to_cnf()))
     #print("hancraft= {}".format(handcrafted.to_cnf()))
     #print(self.fsm.encoding)
     self.assertEqual(no_loop, handcrafted)
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:34,代碼來源:testBmcLTLspec.py

示例6: test_add_

    def test_add_(self):
        # using the algebraic notation
        true = Be.true(self._manager)
        false = Be.false(self._manager)

        self.assertTrue((true + false).is_true())
        self.assertFalse((true + false).is_false())
        self.assertTrue((true + false).is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:8,代碼來源:testBe.py

示例7: test_and

    def test_and(self):
        # using the function
        true = Be.true(self._manager)
        false = Be.false(self._manager)

        self.assertFalse(true.and_(false).is_true())
        self.assertTrue(true.and_(false).is_false())
        self.assertTrue(true.and_(false).is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:8,代碼來源:testBe.py

示例8: test__and_

    def test__and_(self):
        # using the keyword
        true = Be.true(self._manager)
        false = Be.false(self._manager)

        self.assertFalse((true and false).is_true())
        self.assertTrue((true and false).is_false())
        self.assertTrue((true and false).is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:8,代碼來源:testBe.py

示例9: test_sub_

    def test_sub_(self):
        # and not
        true = Be.true(self._manager)
        false = Be.false(self._manager)

        self.assertTrue((true - false).is_true())
        self.assertFalse((true - false).is_false())
        self.assertTrue((true - false).is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:8,代碼來源:testBe.py

示例10: bounded_semantics_at_offset

def bounded_semantics_at_offset(fsm, formula, bound, offset, fairness=True):
    """
    Generates the Be [[formula]]_{bound} corresponding to the bounded semantic 
    of `formula` but encodes it with an `offset` long shift in the timeline of the encoder.

    .. note:: 

        This function plays the same role as `bounded_semantics_all_loops` but allows to 
        position the time blocks at some place we like in the encoder timeline. This is mostly
        helpful if you want to devise verification methods that need to have multiple parallel
        verifications. (ie. diagnosability).

        Note however, that the two implementations are different.

    .. warning::

        So far, the only supported temporal operators are F, G, U, R, X

    :param fsm: the BeFsm for which the property will be verified. Actually, it is only used to 
        provide the encoder used to assign the variables to some time blocks. The api was kept 
        this ways to keep uniformity with its non-offsetted counterpart.
    :param formula: the property for which to generate a verification problem
        represented in a 'node' format (subclass of :see::class:`pynusmv.node.Node`)
        which corresponds to the format obtained from the ast. (remark: if you
        need to manipulate [ie negate] the formula before passing it, it is
        perfectly valid to pass a node decorated by `Wff.decorate`).
    :param bound: the logical time bound to the problem. (Leave out the offset for this param: if you
        intend to have a problem with at most 10 steps, say bound=10)
    :param offset: the time offset in the encoding block where the sem of this formula will be 
        generated.
    :param fairness: a flag indicating whether or not to take the fairness 
        constraint into account.
    :return: a Be corresponding to the semantics of `formula` for a problem with a maximum of `bound` 
        steps encoded to start at time `offset` in the `fsm` encoding timeline.
    """
    if bound< 0:
        raise ValueError("Bound must be a positive integer")
    if offset<0:
        raise ValueError("The offset must be a positive integer")
    
    enc = fsm.encoding
    straight = bounded_semantics_without_loop_at_offset(fsm, formula, 0, bound, offset)
    k_loop   = Be.false(enc.manager)
    for i in range(bound): 
        fairness_cond = utils.fairness_constraint(fsm, offset+bound, offset+i) \
                                 if fairness \
                                 else Be.true(enc.manager)
        k_loop |= ( utils.loop_condition(enc, offset+bound, offset+i) \
                  & fairness_cond \
                  & bounded_semantics_with_loop_at_offset(fsm, formula, 0, bound, i, offset))
    
    # this is just the sem of the formula
    return straight | k_loop    
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:53,代碼來源:ltlspec.py

示例11: test__mul_

    def test__mul_(self):
        # using algebraic notation
        true = Be.true(self._manager)
        false = Be.false(self._manager)

        self.assertFalse((true * false).is_true())
        self.assertTrue((true * false).is_false())
        self.assertTrue((true * false).is_constant())

        self.assertFalse((true & false).is_true())
        self.assertTrue((true & false).is_false())
        self.assertTrue((true & false).is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:12,代碼來源:testBe.py

示例12: test_imply

    def test_imply(self):
        true = Be.true(self._manager)
        false = Be.false(self._manager)

        # antecedent always true
        self.assertFalse(true.imply(false).is_true())
        self.assertTrue(true.imply(false).is_false())
        self.assertTrue(true.imply(false).is_constant())

        # antecedent always false
        self.assertTrue(false.imply(true).is_true())
        self.assertFalse(false.imply(true).is_false())
        self.assertTrue(false.imply(true).is_constant())
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:13,代碼來源:testBe.py

示例13: test_reset

 def test_reset(self):
     """
     Verifies that resetting the cache provokes no error
     -> verifies only the absence of runtime errors since it is who RBC does 
        the heavy lifting, not the manager
     """
     mgr = BeRbcManager.with_capacity(10)
     # test it doesn't hurt to call this method even though nothing is to
     # be done.
     mgr.reset()
     # conversion to CNF populates the hashes which are being reset so 
     # using this manager to perform cnf conversion makes sense if we want
     # to test the reset works when it actually does something.
     (Be.true(mgr) and Be.false(mgr)).to_cnf(Polarity.POSITIVE)
     mgr.reset()
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:15,代碼來源:testBeManager.py

示例14: test_next_no_loop

 def test_next_no_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("X (a <-> !b)")
         
         #  bound 0
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 0)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----
         #  bound 0
         offset  = 1
         ref_expr= Be.false(fsm.encoding.manager)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         #  bound 1
         offset  = 1
         ref_expr= Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         ref_expr= fsm.encoding.shift_to_time(ref_expr, offset+1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:28,代碼來源:testBmcLTLspecAtOffset.py

示例15: loop_condition

def loop_condition(enc, k, l):
    """
    This function generates a Be expression representing the loop condition
    which is necessary to determine that k->l is a backloop.

    Formally, the returned constraint is denoted _{l}L_{k}

    Because the transition relation is encoded in Nusmv as formula (and not as
    a relation per-se), we determine the existence of a backloop between
    l < k and forall var, var(i) == var(k)

    That is to say: if it is possible to encounter two times the same state
    (same state being all variables have the same value in both states) we know
    there is a backloop on the path

    .. note::
        An other implementation of this function (w/ the same semantics) exists
        in :mod:`pynusmv.bmc.utils`. This version is merely re-implemented to
        1. show that it can be easily done
        2. stick closely to the definition given in the paper by Biere et al.
            (see other note)


    :param fsm: the fsm on which the condition will be evaluated
    :param k: the highest time
    :param l: the time where the loop is assumed to start
    :return: a Be expression representing the loop condition that verifies that
        k-l is a loop path.
    """
    cond = Be.true(enc.manager)
    for v in enc.curr_variables:  # for all untimed variable
        vl = v.at_time[l].boolean_expression
        vk = v.at_time[k].boolean_expression
        cond = cond & (vl.iff(vk))
    return cond
開發者ID:xgillard,項目名稱:pynusmv,代碼行數:35,代碼來源:ast.py


注:本文中的pynusmv.be.expression.Be類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。