Beispiel #1
0
        /// <summary>
        /// Creates a new population through tournament selection (10% of the population or 2, whichever is highest) and mutation.
        /// </summary>
        /// <param name="parents"> The list of solutions to generate offspring from. </param>
        /// <returns> The new population. </returns>
        private List <MOEASolution> MakeNewPopulation(List <MOEASolution> parents)
        {
            var offspring      = new List <MOEASolution>();
            var parentCount    = parents.Count;
            var maxCompetitors = Math.Round(this.PopulationSize * 0.1);

            if (maxCompetitors <= 1)
            {
                maxCompetitors = 2;
            }

            for (var i = 0; i < this.PopulationSize; i++)
            {
                var best = parents[this.Random.Next(parentCount)];

                for (var competitorIndex = 1; competitorIndex < maxCompetitors; competitorIndex++)
                {
                    var competitor = parents[this.Random.Next(parentCount)];
                    if (competitor.Rank > best.Rank)
                    {
                        best = competitor;
                    }
                    else if (competitor.Rank == best.Rank && competitor.Map.Fitness > best.Map.Fitness)
                    {
                        best = competitor;
                    }
                }

                var tempOffspring = new MOEASolution((EvolvableMap)best.Map.SpawnMutation());
                offspring.Add(tempOffspring);
            }

            return(offspring);
        }
Beispiel #2
0
 /// <summary>
 /// Determines if this solution dominates the other given solution.
 /// </summary>
 /// <param name="other"> The solution to check for dominance. </param>
 /// <returns> True if this solution dominates the other solution; false otherwise. </returns>
 public bool Dominates(MOEASolution other)
 {
     return(this.Map.Dominates(other.Map));
 }