Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/25/12 10:14:58 (12 years ago)
Author:
jkarder
Message:

#1331:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r8319 r8322  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Common;
     
    129128      if (orderedOffspring.Any(hasBetterQuality)) {
    130129        // 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);
    132131        if (union.Count() > orderedParents.Count()) {
    133132          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     
    140139      return base.Apply();
    141140    }
    142 
    143     // derive SingleObjectiveSolutionSimilarityCalculator from EqualityComparer
    144     // 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 called
    160       }
    161     }
    162141  }
    163142}
Note: See TracChangeset for help on using the changeset viewer.