Ejemplo n.º 1
0
    def permute(self, k=None):
        '''
        permute the blocks with less than k transpositions

        k : number of transpositions

        return: True number of transpositions

        '''
        if k == None:
            p = np.random.permutation(N_ROW * N_COL)
        else:
            p = []
            for _ in range(k):
                a = 0
                b = 0
                while (a == b):
                    a = np.random.randint(0, N_ROW * N_COL - 1)
                    b = np.random.randint(0, N_ROW * N_COL - 1)
                p.append((a, b))
        p = Permutation(p, size=N_ROW * N_COL)

        self.cut_img = self.cut_img.reshape(N_ROW * N_COL, HEIGHT_BLOCK,
                                            WIDTH_BLOCK)
        original = self.cut_img.copy()

        for k in range(N_ROW * N_COL):
            self.cut_img[k] = original[p(k)]

        self.cut_img = self.cut_img.reshape(N_ROW, N_COL, HEIGHT_BLOCK,
                                            WIDTH_BLOCK)

        return len(p.transpositions())