Changeset 9392 for branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/Selection
- Timestamp:
- 04/23/13 13:31:29 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/Selection/NichingTournamentSelector.cs
r9352 r9392 88 88 89 89 int parentsPerChild = ParentsPerChildParameter.ActualValue.Value; 90 var possibleNiches = GAssistNichesProblemDataParameter.ActualValue.GetPossibleNiches().ToList(); 91 var selectPerNiche = new Dictionary<IGAssistNiche, int>(possibleNiches.First().Comparer); 90 var nicheComparer = GAssistNichesProblemDataParameter.ActualValue.GetPossibleNiches().First().Comparer; 91 var selectPerNiche = new Dictionary<IGAssistNiche, int>(nicheComparer); 92 var nicheScope = new Dictionary<IGAssistNiche, List<int>>(nicheComparer); 92 93 93 var nicheScope = new Dictionary<IGAssistNiche, List<int>>(possibleNiches.First().Comparer); 94 foreach (var niche in possibleNiches) { 95 nicheScope.Add(niche, new List<int>()); 96 selectPerNiche.Add(niche, count / possibleNiches.Count); 94 for (int i = 0; i < individuals.Count; i++) { 95 if (!nicheScope.ContainsKey(individuals[i].Niche)) { 96 nicheScope.Add(individuals[i].Niche, new List<int>()); 97 } 98 nicheScope[individuals[i].Niche].Add(i); 97 99 } 98 100 99 for (int i = 0; i < individuals.Count; i++) { 100 nicheScope[individuals[i].Niche].Add(i); 101 var possibleNiches = nicheScope.Keys.ToList(); 102 foreach (var niche in possibleNiches) { 103 selectPerNiche.Add(niche, count / possibleNiches.Count); 101 104 } 102 105 … … 144 147 } 145 148 146 private IGAssistNiche GetNiche(IRandom random, Dictionary<IGAssistNiche, int> nicheScope, List<IGAssistNiche> possibleNiches) {147 int sum = nicheScope.Values.Sum();149 private IGAssistNiche GetNiche(IRandom random, Dictionary<IGAssistNiche, int> selectPerNiche, List<IGAssistNiche> possibleNiches) { 150 int sum = selectPerNiche.Values.Sum(); 148 151 if (sum <= 0) { return possibleNiches[random.Next(possibleNiches.Count)]; } 149 152 int pos = random.Next(sum); 150 153 int total = 0; 151 IGAssistNiche niche = nicheScope.Keys.First();152 foreach (var item in nicheScope) {154 IGAssistNiche niche = selectPerNiche.Keys.First(); 155 foreach (var item in selectPerNiche) { 153 156 total += item.Value; 154 157 niche = item.Key;
Note: See TracChangeset
for help on using the changeset viewer.