Changeset 15366 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
- Timestamp:
- 09/17/17 23:27:05 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
r15345 r15366 64 64 var random = RandomParameter.ActualValue; 65 65 var maximization = MaximizationParameter.ActualValue.Value; 66 67 //var qualities = QualityParameter.ActualValue;68 //.Where(x => IsValidQuality(x.Value))69 //.Select(x => x.Value)70 //.ToList();71 72 66 var caseQualities = CaseQualitiesParameter.ActualValue.ToList(); 73 67 … … 98 92 } 99 93 100 if (caseQualities.Any(x => x.Length != caseQualities[0].Length)) { 94 var qualitiesLength = caseQualities[0].Length; 95 96 if (caseQualities.Any(x => x.Length != qualitiesLength)) { 101 97 throw new ArgumentException("Not all case qualities have the same length"); 102 98 } 103 99 104 100 var selected = new IScope[count]; 105 var candidates = Enumerable.Range(0, caseQualities.Count).ToList(); 106 var orderSource = Enumerable.Range(0, caseQualities[0].Length).ToList(); 101 102 var candidates = new List<int>(caseQualities.Count); 103 for (var i = 0; i < caseQualities.Count; i++) candidates.Add(i); 104 105 var orderSource = new List<int>(qualitiesLength); 106 for (var i = 0; i < qualitiesLength; i++) orderSource.Add(i); 107 107 108 108 for (var i = 0; i < count; i++) { … … 140 140 : double.PositiveInfinity; 141 141 142 foreach (var candidate in candidates) { 143 if (caseQualities[candidate][curCase].IsAlmost(best)) { 142 for (var i = 0; i < candidates.Count; i++) { 143 var candidate = candidates[i]; 144 var caseQuality = caseQualities[candidate][curCase]; 145 146 if (caseQuality.IsAlmost(best)) { 144 147 // if the individuals is as good as the best one, add it 145 148 nextCandidates.Add(candidate); 146 149 } else if ( 147 (maximization && (caseQualit ies[candidate][curCase]> best)) ||148 (!maximization && (caseQualit ies[candidate][curCase]< best))) {149 // if the individual sis better than the best one, remove all previous candidates and add the new one150 (maximization && (caseQuality > best)) || 151 (!maximization && (caseQuality < best))) { 152 // if the individual is better than the best one, remove all previous candidates and add the new one 150 153 nextCandidates.Clear(); 151 154 nextCandidates.Add(candidate); 152 155 // also set the next best quality value 153 best = caseQualit ies[candidate][curCase];156 best = caseQuality; 154 157 } 155 158 // else {do nothing}
Note: See TracChangeset
for help on using the changeset viewer.