Hi everyone,
to solve a mixed-integer nonlinear programming problem, I use a connection between a and a DE algorithm. In an upper level, the GA optimized integer variables. For each individual, the DE optimizes the continuous variables and should return these back to the GA for evaluation (basically, the DE algorithm is called in the fitness function of the GA). How can I assign the results from the DE algorithm?
I tried to return the DE individual (which is a three dimensional array) with the GA fitness function:
def fitness_function(self, individual_ga):
individual_ga = np.array(individual_ga)
de = DifferentialEvolution(self.case_study, self.algorithm_parameter, individual_ga)
de.main()
de_solution = de.de_best_solution
fitness = de.de_best_solution.fitness.values[0]
return fitness, de_solution
But this causes an error as the weights of the GA can only be applied to a scalar and not to an array:
creator.create('FitnessMin_ga', base.Fitness, weights=(1.0, 1.0))
TypeError: Both weights and assigned values must be a sequence of numbers when assigning to values of <class 'deap.creator.FitnessMin_ga'>. Currently assigning value(s) (5.645781083596651e-07, [[array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([ 872.59078028, 780.62620719, 1163.77954564]), array([ 905.7298519 , 1396.29337976, 1116.99213661]), array([900.14285028, 179.0710267 , 844.54358005]), array([103.68612417, 112.66638002, 989.0349853 ])], [array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0.81329445, 0.26798293, 0.22317012]), array([0.62806097, 0.05827781, 0.11870541]), array([0., 0., 0.])], [array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0., 0., 0.]), array([0.51854742, 0.16720212, 0.03545263]), array([0., 0., 0.])]]) of <class 'tuple'> to a fitness with weights (1.0, 1.0).
Is there another way how I can assign the DE results to the GA individual?
Thanks!
Jan