// ENHANCEMENT: Optimization candidate.
        /// <summary>
        /// Gets an array of all genomes ordered by their distance from their current specie.
        /// </summary>
        private TGenome[] GetGenomesByDistanceFromSpecie(IList <TGenome> genomeList, IList <Specie <TGenome> > specieList)
        {
            // Build an array of all genomes paired with their distance from their centroid.
            int genomeCount = genomeList.Count;

            GenomeDistancePair <TGenome>[] genomeDistanceArr = new GenomeDistancePair <TGenome> [genomeCount];

            Parallel.For(0, genomeCount, _parallelOptions, delegate(int i)
            {
                TGenome genome       = genomeList[i];
                double distance      = _distanceMetric.MeasureDistance(genome.Position, specieList[genome.SpecieIdx].Centroid);
                genomeDistanceArr[i] = new GenomeDistancePair <TGenome>(distance, genome);
            });

            // Sort list. Longest distance first.
            // TODO: Pass in parallel options.
            ParallelSort.QuicksortParallel(genomeDistanceArr);

            // Put the sorted genomes in an array and return it.
            TGenome[] genomeArr = new TGenome[genomeCount];
            for (int i = 0; i < genomeCount; i++)
            {
                genomeArr[i] = genomeDistanceArr[i]._genome;
            }

            return(genomeArr);
        }
Esempio n. 2
0
        // ENHANCEMENT: Optimization candidate.
        /// <summary>
        /// Gets an array of all genomes ordered by their distance from their current specie.
        /// </summary>
        private TGenome[] GetGenomesByDistanceFromSpecie(IList <TGenome> genomeList, IList <Specie <TGenome> > specieList)
        {
            // Build a list of all genomes paired with their distance from their centriod.
            int genomeCount = genomeList.Count;

            GenomeDistancePair <TGenome>[] genomeDistanceArr = new GenomeDistancePair <TGenome> [genomeCount];
            for (int i = 0; i < genomeCount; i++)
            {
                TGenome genome   = genomeList[i];
                double  distance = _distanceMetric.MeasureDistance(genome.Position, specieList[genome.SpecieIdx].Centroid);
                genomeDistanceArr[i] = new GenomeDistancePair <TGenome>(distance, genome);
            }

            // Sort list. Longest distance first.
            Array.Sort(genomeDistanceArr);

            // Put the sorted genomes in an array and return it.
            TGenome[] genomeArr = new TGenome[genomeCount];
            for (int i = 0; i < genomeCount; i++)
            {
                genomeArr[i] = genomeDistanceArr[i]._genome;
            }

            return(genomeArr);
        }
Esempio n. 3
0
 public int CompareTo(GenomeDistancePair <TGenome> other)
 {
     // Sorts in descending order.
     // Just remember, -1 means we don't change the order of x and y.
     if (_distance > other._distance)
     {
         return(-1);
     }
     if (_distance < other._distance)
     {
         return(1);
     }
     return(0);
 }