Tuesday, August 10, 2010

Genetic Algorithm with F# - Population

When I design the population, I suddenly feel that maybe I do not need a type (or class). What is a population? It is a set of chromosomes. Population's property is the aggregation of some chromosome properties. It is like a human society. The individual is a physical identity; however, the society is only something in our mind, it is not a physical identity. I'd like to try to break the Object Oriented design this time to try something new. I have free-floating functions everywhere, which I do not need to tie them to a population or a chromosome. When I need them, I can readily grab a function and set of chromosomes. My gut feels that the population class is a barrier. Maybe I am wrong, but it does not hurt if I try.


let Population randomF populationSize chromosomeSize =  
    [for i in 1..populationSize do yield (new ChromosomeType(f=randomF,size=chromosomeSize))]

the randomF is a function to generate the initial loci in each value on the chromosome.

No comments: