Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/17 01:15:25 (7 years ago)
Author:
pkimmesw
Message:

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs

    r14834 r14875  
    7070      var repeats = Math.Ceiling(count / (double)population.Count);
    7171      var caseCount = caseQualities[0].Length;
    72       var source = population.Select((x, i) => Tuple.Create(i, x));
     72      var source = Enumerable.Range(0, population.Count).ToList();
    7373
    7474      for (var k = 0; k < repeats; k++) {
    7575        // The fitness cases are shuffled.
    7676        var fitnessCaseIndexes = Enumerable.Range(0, caseCount).Shuffle(random).ToArray();
    77         var pool = source.ToList();
     77
     78        // copy list if required
     79        var pool = k == repeats - 1 ? source : new List<int>(source);
    7880        var countLimit = Math.Min(count - k * population.Count, population.Count);
    7981
     
    8688          /*  If only one individual remains, it is the chosen parent. If no more fitness cases are left, a parent is
    8789              chosen randomly from the remaining individuals */
    88           var currentSelected = bestIndividuals.Count == 1 ? bestIndividuals[0] : bestIndividuals.Random(random);
    89           selected[k * population.Count + i] = copy ? (IScope)currentSelected.Item2.Clone() : currentSelected.Item2;
     90          var bestIndividualIndex = bestIndividuals.Count == 1 ? bestIndividuals[0] : bestIndividuals.Random(random);
     91          var bestIndividual = population[bestIndividualIndex];
    9092
    91           pool.Remove(currentSelected);
     93          selected[k * population.Count + i] = copy ? (IScope)bestIndividual.Clone() : bestIndividual;
     94
     95          pool.Remove(bestIndividualIndex);
    9296        }
    9397      }
     
    96100    }
    97101
    98     private static List<Tuple<int, IScope>> GetBestIndividuals(bool maximization, ItemArray<DoubleArray> caseQualities, List<Tuple<int, IScope>> bestIndividuals, int index) {
     102    private static List<int> GetBestIndividuals(bool maximization, ItemArray<DoubleArray> caseQualities, List<int> bestIndividuals, int index) {
    99103      var bestFitness = maximization ? double.NegativeInfinity : double.PositiveInfinity;
    100       var result = new List<Tuple<int, IScope>>();
     104      var result = new List<int>();
    101105
    102106      for (var l = 0; l < bestIndividuals.Count; l++) {
    103107        var individual = bestIndividuals[l];
    104         var caseQuality = caseQualities[individual.Item1][index];
     108        var caseQuality = caseQualities[individual][index];
    105109
    106         if (bestFitness == caseQuality) {
     110        if (bestFitness.IsAlmost(caseQuality)) {
    107111          result.Add(individual);
    108112        } else if (maximization && bestFitness < caseQuality ||
Note: See TracChangeset for help on using the changeset viewer.