Ejemplo n.º 1
0
        public void FindsSimpleSolution()
        {
            var random    = new SystemRandom(42);
            var factory   = new SimpleGenomeFactory(random);
            var selection = new BinaryTournamentSelection(random);

            Environment environment = new SimpleEnvironment();
            Ranking     ranking     = new CrowdingDistanceRanking(1);

            var evolution = new Evolution(100, 0.4, 0.4, factory, selection);
            var genomes   = evolution.Initialize();

            double score = 0;

            for (int i = 0; i < 100; i++)
            {
                // evaluate
                var population = genomes.Select(environment.Evaluate).ToList();

                // rank
                ranking.Rank(population);

                // keep score
                var best = population[0];
                Console.WriteLine(best);
                score = best.GetScore(0);

                // evolve
                genomes = evolution.Evolve(population, random);
            }

            Assert.Greater(score, 30);
        }
Ejemplo n.º 2
0
        public void FindsSimpleSolution()
        {
            var random    = new SystemRandom(42);
            var factory   = new SimpleGenomeFactory(random);
            var selection = new BinaryTournamentSelection(random);

            Environment environment = new SimpleEnvironment();
            Ranking     ranking     = new CrowdingDistanceRanking(1);

            var writer    = File.CreateText("stats.csv");
            var evolution = new ElitistEvolution(100, 20, factory, environment, 1, writer);
            var genomes   = evolution.Initialize();

            double score = 0;

            for (int i = 0; i < 100; i++)
            {
                genomes = evolution.Evolve(genomes, random);
            }

            writer.Close();

            Assert.Greater(score, 30);
        }