Beispiel #1
0
        def mate(x, y):

            x_ = x.terms.copy()
            y_ = y.terms.copy()
            n, m = x_.shape
            nm = n * m

            a = x_.reshape((1, nm)).tolist()[0]
            b = y_.reshape((1, nm)).tolist()[0]
            c = np.array(tools.cxOnePoint(a, b))
            a = creator.pt_individual(c[0, :].reshape((n, m)))
            b = creator.pt_individual(c[1, :].reshape((n, m)))
            return (a, b)
Beispiel #2
0
        def mate(x, y):

            x_ = x.terms.copy()
            y_ = y.terms.copy()
            n, m = x_.shape
            nm = n * m

            a = x_.reshape((1, nm)).tolist()[0]
            b = y_.reshape((1, nm)).tolist()[0]
            c = np.array(tools.cxOnePoint(a, b))
            a = creator.pt_individual(c[0, :].reshape((n, m)))
            b = creator.pt_individual(c[1, :].reshape((n, m)))
            return (a, b)
Beispiel #3
0
        def mutate(p):
            z = np.copy(p.terms)

            rows, cols = z.shape
            for _ in range(self.num_mutations):
                r = np.random.randint(rows)
                c = np.random.randint(cols)
                z[r, c] = np.random.choice(a=self.valid_degrees)

            return (creator.pt_individual(z), )
Beispiel #4
0
        def mutate(p):
            z = np.copy(p.terms)

            rows, cols = z.shape
            for _ in range(self.num_mutations):
                r = np.random.randint(rows)
                c = np.random.randint(cols)
                z[r, c] = np.random.choice(a=self.valid_degrees)

            return (creator.pt_individual(z),)