Exemple #1
0
 def eval(self, ind):
     if self.opc == 1:
         ind = bench.rastrigin(ind)
     elif self.opc == 2:
         ind = bench.himmelblau(ind)
     elif self.opc == 3:
         ind = bench.eggholder(ind)
     elif self.opc == 4:
         ind = bench.nqueens(ind)
     elif self.opc == 5:
         ind = bench.tsp(ind)
     
     self.count += 1
     
     return ind
Exemple #2
0
    def eval_pop(self, population):
        for i in range(len(population)):
            if self.opc == 1:
                population[i] = bench.rastrigin(population[i])
            elif self.opc == 2:
                population[i] = bench.himmelblau(population[i])
            elif self.opc == 3:
                population[i] = bench.eggholder(population[i])
            elif self.opc == 4:
                population[i] = bench.nqueens(population[i])
            elif self.opc == 5:
                population[i] = bench.tsp(population[i])

            self.count += 1

        return population
Exemple #3
0
 def test_himmelblau(self):
     self.assertEqual(0, tf.himmelblau(np.array([3]), np.array([2])))
     self.assertAlmostEqual(0, tf.himmelblau(np.array([-2.805118]), np.array([3.131312]))[0])
     self.assertAlmostEqual(0, tf.himmelblau(np.array([-3.779310]), np.array([-3.283186]))[0])
     self.assertAlmostEqual(0, tf.himmelblau(np.array([3.584428]), np.array([-1.848126]))[0])