Using The Code / A Simple Sample



static void Main(string[] args)

{

    DoubleGenome.DefaultLength = 4;

    DoubleGenome.DefaultFitnessFunction = new DoubleGenomeFitnessFunction_Max();

    DoubleGenome.DefaultMutateRate = 0.05;

 

    GeneticAlgorithm<DoubleGenome> pro = new GeneticAlgorithm<DoubleGenome>();

    pro.CrossoverRate = 0.8;

    pro.PopulationSize = 100;

    pro.GenerationSize = 2000;

    pro.Elitism = true;


    pro.Compute();

 

    DoubleGenome g = pro.GetBestGenome();

    for (int i = 0; i < g.Value.Length; i++)

    {

        Console.WriteLine(g.Value[i]);

    }

}


To solve your problem with this "Generic Genetic Algorithm",
You should first describe your problem by writing your own genome class derived from the abstract class "Genome", implementing abstract methods such as "Crossover", "Mutate", "ComputeFitness", etc.

Sample Project Download:
https://files.cnblogs.com/Dah/Adrian.Algorithm.Genetic.rar

Feel free to leave your comment or suggestion. :)
Posted on 2007-02-11 16:24  Adrian H.  阅读(761)  评论(0编辑  收藏  举报