- Timestamp:
- 02/15/18 08:49:41 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2901_StaticSelectionMethods/HeuristicLab.Selection/3.3/TournamentSelector.cs
r15583 r15779 69 69 70 70 for (int i = 0; i < count; i++) { 71 int best = random.Next(scopes.Count); 72 int index; 73 for (int j = 1; j < groupSize; j++) { 74 index = random.Next(scopes.Count); 75 if (((maximization) && (qualities[index] > qualities[best])) || 76 ((!maximization) && (qualities[index] < qualities[best]))) { 77 best = index; 78 } 79 } 71 var selectedIdx = SelectIdx(random, qualities, maximization, groupSize); 80 72 81 73 if (copy) 82 selected[i] = (IScope)scopes[ best].Clone();74 selected[i] = (IScope)scopes[selectedIdx].Clone(); 83 75 else { 84 selected[i] = scopes[ best];85 scopes.RemoveAt( best);86 qualities.RemoveAt( best);76 selected[i] = scopes[selectedIdx]; 77 scopes.RemoveAt(selectedIdx); 78 qualities.RemoveAt(selectedIdx); 87 79 } 88 80 } 89 81 return selected; 90 82 } 83 84 public static int SelectIdx(IRandom random, IList<double> qualities, bool maximization, int groupSize) { 85 int best = random.Next(qualities.Count); 86 int index; 87 for (int j = 1; j < groupSize; j++) { 88 index = random.Next(qualities.Count); 89 if (((maximization) && (qualities[index] > qualities[best])) || 90 ((!maximization) && (qualities[index] < qualities[best]))) { 91 best = index; 92 } 93 } 94 95 return best; 96 } 91 97 } 92 98 }
Note: See TracChangeset
for help on using the changeset viewer.