# Minimum Number of Variables for Effective use of the Genetic Algorithm

From my understanding of the genetic algorithm the population consists of individuals, where each individual is a potential solution made up of "genes", and each gene is a variable. So for a cost function that takes in 3 variables the individuals will have 3 genes.

The optimization happens by selection (picking the fittests from the population), crossover (swapping genes between pairs in the population), and mutation (randomly changing certain genes).

Because of this it seems to me that the genetic algorithm is best suited to high dimensionality optimisation problems, i.e ones with lots of variables, so that there are more genes that can be swapped and mutated.

Is this true? and what is a good number of genes for use in the genetic algorithm?

Thanks!

• I see a genetic algorithm as a search over a parameter space. So even with a single (semi-)continuous parameter you could use a genetic algorithm as a continuous number can be represent as 24 bits (float) or 53 bits (double), which gives you plenty of genes to work with. – Maarten Buis May 23 '14 at 9:57
• @MaartenBuis : My solutions need to be all positive integers, but I have Matlab 2011a so I do not have the creation, crossover, and mutation functions for integer programing. I have instead just put round(x) at the start of my cost function, which rounds all of the variables. Although not a common solution, I thought this could work as it is sort of like having "fuzzy" variables, that are then fully defined once they are put into the cost function. The min and max constraints are 1 and 50 for all 3 variables. What are your thoughts on this? Will it give a good optimization? – Blue7 May 23 '14 at 10:33
• I can't speak to matlab in particular, but a common way of representing integer parameters in a GA is to encode them in binary (or often better, gray-coded binary) representation. So if I have two parameters p1 and p2, where p1 is between 0 and 10 and I need two decimal places of precision, and p2 is between 50 and 100 with one place of precision, I could encode this as a single binary string with just enough bits (in this case, 10 bits for p1 and 9 bits for p2, so 19 bits in total). – deong May 23 '14 at 10:39