giacomelli / GeneticSharp

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
MIT License
1.27k stars 332 forks source link

How to set up search steps? #63

Closed wolfcuring closed 5 years ago

wolfcuring commented 5 years ago

Hi giacomelli,

Some times, I want to limit my search space by set up search steps. For example, instead of searching every 0.001 increments of a variable (0.001, 0.002, 0.003....in the range), I want to search every 0.005 increment (so, now I only search 0.005 0.001 in the range).

How Can I set up this in the GeneticSharp? I guess in the FloatingPointChromosome() the Number of Fraction argument can partially implement this.

Thanks in advance !

giacomelli commented 5 years ago

Hi,

this is a really good question!

FlostingPointChromosome use the code bellow to generate genes values:

for (int i = 0; i < geneValues.Length; i++)
{
    geneValues[i] = rnd.GetDouble(minValue[i], maxValue[i]);
}

I guess the best approach you can try is inherits from IRandomization implementation you are using (probably the FastRandomRandomization), then override the double GetDouble(double min, double max) method to guarantee that it wil return only the fraction in the range you want.

wolfcuring commented 5 years ago

Cool, will give it a try !