Beispiel #1
0
    def box2bvs(self, box, innerapprox=False, tol=.0000001):
        left, right = box

        eps = self.binwidth
        abs_tol = eps * tol

        # assert left <= right

        left = self.pt2index(left - abs_tol)
        right = self.pt2index(right + abs_tol)
        if innerapprox:
            # Inner approximations move in the box
            if left == right or left == right - 1:
                return []

            if self.periodic and left == self.bins - 1 and right == 0:
                return []
            else:
                left = (left + 1) % self.bins
                right = (right - 1) % self.bins

        left_bv = int2bv(left, self.num_bits)
        right_bv = int2bv(right, self.num_bits)

        if self.periodic and left > right:
            zero_bv = int2bv(0, self.num_bits)
            max_bv = int2bv(self.bins - 1, self.num_bits)
            return itertools.chain(bv_interval(zero_bv, right_bv),
                                   bv_interval(left_bv, max_bv))
        else:
            return bv_interval(left_bv, right_bv)
Beispiel #2
0
 def abs_space(self, mgr, name: str):
     """Return the predicate of the fixed cover abstract space."""
     left_bv = int2bv(0, self.num_bits)
     right_bv = int2bv(self.bins - 1, self.num_bits)
     bvs = bv_interval(left_bv, right_bv)
     boxbdd = mgr.false
     for i in map(lambda x: bv2pred(mgr, name, x), bvs):
         boxbdd |= i
     return boxbdd
Beispiel #3
0
    def pt2bv(self, point: float, nbits: int, tol=0.0):
        """
        Continuous point to a bitvector

        Parameters
        ----------
        point : float
            Continuous point
        nbits : int
            Number of bits to encode

        Returns
        -------
        Tuple of bools:
            Left-most element is most significant bit. Encoding is the standard binary encoding or gray code.

        """
        assert isinstance(nbits, int)

        if self.periodic:
            point = self._wrap(point)

        index = self.pt2index(point, nbits, alignleft=True)

        if self.periodic:
            index = bintogray(index)

        return int2bv(index, nbits)
Beispiel #4
0
    def abs_space(self, mgr, name: str):
        """
        Return the predicate of the discrete set abstract space.

        Parameters
        ----------
        mgr: bdd
            manager
        name: str
            BDD variable name, e.g. "x" for names "x_1", "x_2", etc.

        """
        left_bv = int2bv(0, self.num_bits)
        right_bv = int2bv(self.num_vals - 1, self.num_bits)
        bvs = bv_interval(left_bv, right_bv)
        boxbdd = mgr.false
        for i in map(lambda x: bv2pred(mgr, name, x), bvs):
            boxbdd |= i
        return boxbdd
Beispiel #5
0
    def conc_iter(self, nbits: int):
        """
        Generator for iterating over the space with fixed precision

        Yields
        ------
        Tuple:
            (left, right) box of floats
        """
        i = 0
        while (i < 2**nbits):
            yield self.bv2conc(int2bv(i, nbits))
            i += 1
Beispiel #6
0
    def conc2pred(self, mgr, name: str, concrete):
        """
        Translate from a concrete value to a the associated predicate.

        Parameters
        ----------
        mgr (dd mgr):
        name:
        concrete:

        Returns
        -------
        bdd:

        """
        assert concrete >= 0 and concrete < self.num_vals
        bv = int2bv(concrete, self.num_bits)
        return bv2pred(mgr, name, bv)
Beispiel #7
0
    def conc2pred(self, mgr, name: str, concrete, snap=True):
        """
        Translate from a concrete value to a the associated predicate.

        Parameters
        ----------
        mgr (dd mgr):
        name:
        concrete:
        snap:

        Returns
        -------
        bdd:

        """
        bv = int2bv(self.pt2index(concrete, snap), self.num_bits)
        return bv2pred(mgr, name, bv)
Beispiel #8
0
 def pt2bv(self, point: float, tol=0.0):
     """
     Map a point to bitvector corresponding to the bin that contains it.
     """
     index = self.pt2index(point, tol)
     return int2bv(index, self.num_bits)
Beispiel #9
0
 def pt2bv(self, point) -> BitVector:
     assert point < self.num_vals
     return int2bv(point, self.num_bits)