Exemplo n.º 1
0
            public void DoIteration()
            {
                int size = Individuals.Count;

                for (var i = 0; i < size; i++)
                {
                    for (var j = 0; j < i; j++)
                    {
                        Individuals.Add(GeneticIndividual.Crossover(Individuals[i], Individuals[j]));
                    }
                    for (var j = 0; j < 100; j++)
                    {
                        Individuals.Add(GeneticIndividual.Mutation(Individuals[i]));
                    }
                }
                Individuals = Individuals
                              .Where(x => !x.IsInvalid())
                              .OrderBy(x => x.Fitness())
                              .Reverse()
                              .Take(MaxSize)
                              .ToList();
            }
Exemplo n.º 2
0
            public GeneticPopolation(CaptchaRecognizer recognizer, int maxSize)
            {
                _recognizer = recognizer;
                MaxSize     = maxSize;
                var consecutiveInvalidCount = 0;

                while (Individuals.Count < MaxSize)
                {
                    var nxt = GeneticIndividual.Mutation(new GeneticIndividual(_recognizer, true));
                    if (!nxt.IsInvalid())
                    {
                        consecutiveInvalidCount = 0;
                        Individuals.Add(nxt);
                    }
                    else
                    {
                        consecutiveInvalidCount++;
                        if (consecutiveInvalidCount > MaxConsecutiveFailures)
                        {
                            throw new CantSplitDigitsException();
                        }
                    }
                }
            }