Example #1
0
        protected override IList <IGenome> DoProduction(
            IList <IGenome> sampleGenomes,
            GenomeProductionSession thisSession,
            GenomeProductionSession totalSession)
        {
            var selections     = (int)Math.Ceiling((float)thisSession.requiredNb / Crossover.NbOfChildren);
            var totalNbToSelct = selections * Crossover.NbOfParents;

            Selection.Prepare(
                sampleGenomes,
                thisSession,
                totalSession,
                totalNbToSelect: totalNbToSelct);

            Crossover.Prepare(
                sampleGenomes,
                thisSession,
                totalSession);

            while (thisSession.CurrentlyProduced.Count < thisSession.requiredNb)
            {
                var parents  = Selection.Select(Crossover.NbOfParents).ToArray();
                var children = Crossover.Cross(parents);

                var usedChildren = thisSession.AddNewProducedGenomes(children);

                foreach (var child in usedChildren)
                {
                    this.MutationManager.ApplyMutations(child);
                }
            }

            return(thisSession.CurrentlyProduced);
        }