Пример #1
0
        public static void ProperTestRun()
        {
            EvolutionaryAlgorithm neat = new Neat();

            neat.InitializePopulation();
            bool solvedit = false;

            for (int i = 0; i < EAParameters.MaximumRuns; i++)
            {
                Console.WriteLine("generation:" + i);
                neat.EvaluatePopulation(i);
                if (neat.IsDeadRun())
                {
                    Console.WriteLine("death");
                    break;
                }
                if (neat.SolvedIt())
                {
                    Console.WriteLine("obtained maximum fitness");
                    solvedit = true;
                    break;
                }
                neat.NextGeneration();
            }
            Console.WriteLine("best individual in existence:");
            var best = ((Neat)neat).bestAchieved;

            Console.WriteLine("individualID: {0} generation:{1}", best.individualID, ((Neat)neat).generationOfBest);
            Console.WriteLine("\tFitness:{0}", best.Fitness);
            Console.WriteLine("\tstats:");
            Console.WriteLine("\t\tnodes:{0}", best.genome.nodeGenes.Count);
            Console.Write("\t\tConnections:{0}", best.genome.connectionGenes.Count);
            int count = 0;

            foreach (var gene in best.genome.connectionGenes)
            {
                if (gene.isEnabled)
                {
                    count++;
                }
            }
            Console.WriteLine(" enabled:{0}", count);
            Console.WriteLine("biggest individual in existence:");
            var biggest = ((Neat)neat).biggestAchieved;

            Console.WriteLine("individualID: {0} generation:{1}", biggest.individualID, ((Neat)neat).generationOfBiggest);
            Console.WriteLine("\tFitness:{0}", biggest.Fitness);
            Console.WriteLine("\tstats:");
            Console.WriteLine("\t\tnodes:{0}", biggest.genome.nodeGenes.Count);
            Console.Write("\t\tConnections:{0}", biggest.genome.connectionGenes.Count);
            count = 0;
            foreach (var gene in biggest.genome.connectionGenes)
            {
                if (gene.isEnabled)
                {
                    count++;
                }
            }
            Console.WriteLine(" enabled:{0}", count);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("so what the best do?");
            Console.WriteLine("wanted_gotten rule-results:");
            foreach (var rule in LambdaExperiment.ruleSet)
            {
                Console.WriteLine("rule:{0} _ best:{1}", rule.Result, best.network.GetNextState(rule));
                ((CPPNetwork)(best.network)).ResetNetwork();
            }
            Console.WriteLine();
            Console.WriteLine("so what the biggest do?");
            Console.WriteLine("wanted_gotten rule-results:");
            foreach (var rule in LambdaExperiment.ruleSet)
            {
                Console.WriteLine("rule:{0} _ best:{1}", rule.Result, best.network.GetNextState(rule));
                ((CPPNetwork)(biggest.network)).ResetNetwork();
            }
            Console.WriteLine();


            if (solvedit)
            {
                Console.WriteLine("your perfect genome is ready for you in {0}", @"C:/genes");
            }
        }