Exemple #1
0
        public void GATest()
        {
            // Target:
            double num = 0.55;

            // Algo
            Func<Genom, double> f = g => Math.Abs(num - g.Genes.Sum());
            var algo = new TournamentSelectionAlgorithm(5);
            var ga = new GA(10, 100, 1, new PointMutationPars(PointMutationType.Uniform, 0.05, 0.1), algo, new FitnessFunctionComparer(f));
            ga.Initialize();

            // Run
            int maxGen = 100;
            for (int i = 0; i < maxGen; i++)
            {
                ga.NextGeneration();
                Debug.WriteLine(f(ga[0]) + " " + f(ga[1]));
            }

            Debug.WriteLine(ga[0]);
        }