Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/17/17 23:27:05 (7 years ago)
Author:
pkimmesw
Message:

#2665 Solution Cleanup

File:
1 edited

Legend:

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

    r15345 r15366  
    6464      var random = RandomParameter.ActualValue;
    6565      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 
    7266      var caseQualities = CaseQualitiesParameter.ActualValue.ToList();
    7367
     
    9892      }
    9993
    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)) {
    10197        throw new ArgumentException("Not all case qualities have the same length");
    10298      }
    10399
    104100      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);
    107107
    108108      for (var i = 0; i < count; i++) {
     
    140140          : double.PositiveInfinity;
    141141
    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)) {
    144147            // if the individuals is as good as the best one, add it
    145148            nextCandidates.Add(candidate);
    146149          } else if (
    147              (maximization && (caseQualities[candidate][curCase] > best)) ||
    148              (!maximization && (caseQualities[candidate][curCase] < best))) {
    149             // if the individuals is better than the best one, remove all previous candidates and add the new one
     150             (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
    150153            nextCandidates.Clear();
    151154            nextCandidates.Add(candidate);
    152155            // also set the next best quality value
    153             best = caseQualities[candidate][curCase];
     156            best = caseQuality;
    154157          }
    155158          // else {do nothing}
Note: See TracChangeset for help on using the changeset viewer.