Esempio n. 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);
        }
        public IList <IGenome> Produce(
            IList <IGenome> sampleGenomes,
            GenomeProductionSession thisSession,
            GenomeProductionSession totalSession)
        {
            selection.Prepare(
                sampleGenomes,
                thisSession,
                totalSession,
                thisSession.requiredNb);

            var participants = selection.Select(thisSession.requiredNb);
            var produced     = participants.Select(x => x.CreateNew(x.Genes))
                               .ToArray();

            Trace.Assert(produced.EveryoneIsUnique());

            thisSession.RegisterParticipants(participants);
            thisSession.AddNewProducedGenomes(produced);

            return(produced);
        }