Esempio n. 1
0
    def test_pickle_population(self):
        ind1 = creator.IndList([1.0, 2.0, 3.0])
        ind1.fitness.values = (1.0, )
        ind2 = creator.IndList([4.0, 5.0, 6.0])
        ind2.fitness.values = (2.0, )
        ind3 = creator.IndList([7.0, 8.0, 9.0])
        ind3.fitness.values = (3.0, )

        pop = [ind1, ind2, ind3]

        pop_s = pickle.dumps(pop)
        pop_l = pickle.loads(pop_s)

        self.assertEqual(
            pop[0], pop_l[0],
            "Unpickled individual list != pickled individual list")
        self.assertEqual(
            pop[0].fitness, pop_l[0].fitness,
            "Unpickled individual fitness != pickled individual fitness")
        self.assertEqual(
            pop[1], pop_l[1],
            "Unpickled individual list != pickled individual list")
        self.assertEqual(
            pop[1].fitness, pop_l[1].fitness,
            "Unpickled individual fitness != pickled individual fitness")
        self.assertEqual(
            pop[2], pop_l[2],
            "Unpickled individual list != pickled individual list")
        self.assertEqual(
            pop[2].fitness, pop_l[2].fitness,
            "Unpickled individual fitness != pickled individual fitness")
 def test_pickle_ind_list(self):
     ind = creator.IndList([1.0, 2.0, 3.0])
     ind.fitness.values = (4.0,)
     ind_s = pickle.dumps(ind)
     ind_l = pickle.loads(ind_s)
     self.assertEqual(ind, ind_l, "Unpickled individual list != pickled individual list")
     self.assertEqual(ind.fitness, ind_l.fitness, "Unpickled individual fitness != pickled individual fitness")