コード例 #1
0
        private static IEnumerable <AdvancedObject <string> > StepByStepApproach()
        {
            Console.WriteLine("Please feel free to enter my goal text:\n`");
            _goalObject = Console.ReadLine();

            var generation = AdvancedObjectFactory
                             .GenerateAdvancedObjects <BoxedAdvancedString, string>(_rand, POPULATION_COUNT,
                                                                                    ((string)_goalObject).Length).Cast <AdvancedObject <string> >().ToList();

            var stringApproach = ApproachFactory.GenApproach <BoxedStringApproach, string>();

            for (var i = 0; i < GENERATIONS - 1; i++)
            {
                generation = stringApproach.DoSteps(generation.GetTopN(PREDATORS), _rand, MUTATIONRATE,
                                                    (string)_goalObject,
                                                    GENERATIONS);

                generation.ForEach(x => x.CalculateScore((string)_goalObject));

                var currentBest = generation.GetTopN(1)[0];

                Console.WriteLine($"Top@Generation[{i}]:\t{currentBest.MObject}");
            }

            return(stringApproach.DoSteps(generation.GetTopN(PREDATORS), _rand, MUTATIONRATE, (string)_goalObject,
                                          GENERATIONS));
        }
コード例 #2
0
        private static List <AdvancedObject <int> > intApproach()
        {
            Console.WriteLine("Please feel free to enter my number:\n`");
            _goalObject = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

            var generation = AdvancedObjectFactory.GenerateAdvancedObjects <BoxedInteger, int>(_rand, POPULATION_COUNT)
                             .ToList();

            var intApproach = new BoxedIntApproach();

            return(intApproach.DoSteps(generation.GetTopN(PREDATORS), _rand, MUTATIONRATE, (int)_goalObject,
                                       GENERATIONS));
        }
コード例 #3
0
        private static List <AdvancedObject <string> > stringApproach()
        {
            Console.WriteLine("Please feel free to enter my goal text:\n`");
            _goalObject = Console.ReadLine();

            var generation = AdvancedObjectFactory
                             .GenerateAdvancedObjects <BoxedAdvancedString, string>(_rand, POPULATION_COUNT,
                                                                                    ((string)_goalObject).Length).ToList();

            var stringApproach = new BoxedStringApproach();

            return(stringApproach.DoSteps(generation.GetTopN(PREDATORS), _rand, MUTATIONRATE, (string)_goalObject,
                                          GENERATIONS));
        }