1

Assume that I want to optimize the following function:

Minimize y = x1 * x2 - x3

-5 <= x1 <= 5   # float
0 <= x2 <= 1    # float with precision 0.01
0 <= x3 <= 5    # integer can have values : [0, 1, 2, 3, 4, 5]

x2 can have decimal values with precision 0.01 like : [0, 0.01, 0.02, ...., 0.99, 1].

I have a problem in defining individuals and register in toolbox in Deap library. Please let me know if you have any idea.

Also, what kind of crossover and mutation operators you recommend for this kind of problem?

Mohammad
  • 775
  • 1
  • 14
  • 37

1 Answers1

0

One tricky way would be to cast the desired type inside the fitness function.

For example, if you simply encode your chromosome as a list of floats i.e. [1.7, 0.41, 3.1], then

def fitness_func(chromosome):
    x1, x2, x3 = chromosome[0], chromosome[1], chromosome[2]
    x3 = int(chromosome[2])
    # continue fitness logic

This way you can adjust your chromosome on-the-fly the evolution. You can also add more logic to account for other special requirements like the precision or the bounds that you mentioned. Hope this helps.

Mauricio Maroto
  • 119
  • 1
  • 2
  • 11