- Timestamp:
- 07/25/12 10:14:58 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r8319 r8322 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Common; … … 129 128 if (orderedOffspring.Any(hasBetterQuality)) { 130 129 // produce the set union 131 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.CalculateSolutionSimilarity));130 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculator); 132 131 if (union.Count() > orderedParents.Count()) { 133 132 var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) : … … 140 139 return base.Apply(); 141 140 } 142 143 // derive SingleObjectiveSolutionSimilarityCalculator from EqualityComparer144 // delete this ...145 public class SolutionEqualityComparer<T> : EqualityComparer<T> {146 private readonly Func<T, T, double> similarityCalculator;147 148 public SolutionEqualityComparer(Func<T, T, double> similarityCalculator) {149 this.similarityCalculator = similarityCalculator;150 }151 152 public override bool Equals(T x, T y) {153 if (object.ReferenceEquals(x, y)) return true;154 if (x == null || y == null) return false;155 return similarityCalculator(x, y) == 1.0;156 }157 158 public override int GetHashCode(T obj) {159 return 0; // return the same hash code for each object, otherwise Equals will not be called160 }161 }162 141 } 163 142 }
Note: See TracChangeset
for help on using the changeset viewer.