Changeset 14875 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
- Timestamp:
- 04/18/17 01:15:25 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
r14834 r14875 70 70 var repeats = Math.Ceiling(count / (double)population.Count); 71 71 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(); 73 73 74 74 for (var k = 0; k < repeats; k++) { 75 75 // The fitness cases are shuffled. 76 76 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); 78 80 var countLimit = Math.Min(count - k * population.Count, population.Count); 79 81 … … 86 88 /* If only one individual remains, it is the chosen parent. If no more fitness cases are left, a parent is 87 89 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]; 90 92 91 pool.Remove(currentSelected); 93 selected[k * population.Count + i] = copy ? (IScope)bestIndividual.Clone() : bestIndividual; 94 95 pool.Remove(bestIndividualIndex); 92 96 } 93 97 } … … 96 100 } 97 101 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) { 99 103 var bestFitness = maximization ? double.NegativeInfinity : double.PositiveInfinity; 100 var result = new List< Tuple<int, IScope>>();104 var result = new List<int>(); 101 105 102 106 for (var l = 0; l < bestIndividuals.Count; l++) { 103 107 var individual = bestIndividuals[l]; 104 var caseQuality = caseQualities[individual .Item1][index];108 var caseQuality = caseQualities[individual][index]; 105 109 106 if (bestFitness == caseQuality) {110 if (bestFitness.IsAlmost(caseQuality)) { 107 111 result.Add(individual); 108 112 } else if (maximization && bestFitness < caseQuality ||
Note: See TracChangeset
for help on using the changeset viewer.