예제 #1
0
    def test___init__(self):
        """
        Should initialize a new evolver instance
        """
        f0 = np.asarray([[1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 1, 0, 1, 1], [0, 1, 0, 1, 1]])

        ga = Evolver(f0, eval_one_max)

        # should have evaluated fitness
        self.assertEqual(len(ga.pop.inew), 0)
        best_fit, best_ind = ga.best_fit
        self.assertEqual(best_fit, 5)

        print ga.__str__(extended=True)
예제 #2
0
    def XXX__evolve(self):
        """
        Should evolve population by one generation
        """
        f0 = 3.0 * np.random.rand(10, 3)
        ga = Evolver(f0, eval_one_max)

        print ga.__str__(extended=True)
        ga._evolve()
        print ga.__str__(extended=True)

        # should have evaluated fitness
        self.assertEqual(len(ga.pop.inew), 0)