コード例 #1
0
        /// <inheritdoc />
        public int PerformAntiSelection(Random rnd, ISpecies species)
        {
            int     worstIndex = rnd.Next(species.Members.Count);
            IGenome worst      = species.Members[worstIndex];

            BasicEA.CalculateScoreAdjustment(worst,
                                             Trainer.ScoreAdjusters);

            for (int i = 0; i < Rounds; i++)
            {
                int     competitorIndex = rnd.Next(species.Members.Count - 1);
                IGenome competitor      = species.Members[competitorIndex];

                // force an invalid genome to lose
                if (Double.IsInfinity(competitor.AdjustedScore) ||
                    Double.IsNaN(competitor.AdjustedScore))
                {
                    return(competitorIndex);
                }

                BasicEA.CalculateScoreAdjustment(competitor,
                                                 Trainer.ScoreAdjusters);
                if (!Trainer.SelectionComparer.IsBetterThan(competitor,
                                                            worst))
                {
                    worst      = competitor;
                    worstIndex = competitorIndex;
                }
            }
            return(worstIndex);
        }
コード例 #2
0
        /// <inheritdoc />
        public int PerformSelection(Random rnd, ISpecies species)
        {
            int     bestIndex = rnd.Next(species.Members.Count);
            IGenome best      = species.Members[bestIndex];

            BasicEA.CalculateScoreAdjustment(best, Trainer.ScoreAdjusters);

            for (int i = 0; i < Rounds; i++)
            {
                int     competitorIndex = rnd.Next(species.Members.Count - 1);
                IGenome competitor      = species.Members[competitorIndex];

                // only evaluate valid genomes
                if (!Double.IsInfinity(competitor.AdjustedScore) &&
                    !Double.IsNaN(competitor.AdjustedScore))
                {
                    BasicEA.CalculateScoreAdjustment(competitor,
                                                     Trainer.ScoreAdjusters);
                    if (Trainer.SelectionComparer.IsBetterThan(
                            competitor, best))
                    {
                        best      = competitor;
                        bestIndex = competitorIndex;
                    }
                }
            }
            return(bestIndex);
        }
コード例 #3
0
        /// <summary>
        ///     Perform the task.
        /// </summary>
        public void PerformTask()
        {
            IMLMethod phenotype = owner.CODEC.Decode(genome);

            if (phenotype != null)
            {
                double score;
                try
                {
                    score = scoreFunction.CalculateScore(phenotype);
                }
                catch (EARuntimeError e)
                {
                    score = Double.NaN;
                }
                genome.Score         = score;
                genome.AdjustedScore = score;
                BasicEA.CalculateScoreAdjustment(genome, adjusters);
            }
        }