Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/15/17 14:25:44 (7 years ago)
Author:
abeham
Message:

#2457: merged trunk into branch

Location:
branches/PerformanceComparison/HeuristicLab.Encodings.BinaryVectorEncoding
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Encodings.BinaryVectorEncoding

  • branches/PerformanceComparison/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEqualityComparer.cs

    r14659 r15256  
    1919 */
    2020#endregion
    21  
     21
     22using System;
    2223using System.Collections.Generic;
    23 using System.Linq;
     24using HeuristicLab.PluginInfrastructure;
    2425
    2526namespace HeuristicLab.Encodings.BinaryVectorEncoding {
     27  [NonDiscoverableType]
    2628  public class BinaryVectorEqualityComparer : EqualityComparer<BinaryVector> {
    27     public override bool Equals(BinaryVector first, BinaryVector second) {
    28       return first.SequenceEqual(second);
     29    public override bool Equals(BinaryVector x, BinaryVector y) {
     30      if (ReferenceEquals(x, y)) return true;
     31      if (x == null || y == null) return false;
     32      if (x.Length != y.Length) return false;
     33      for (var i = 0; i < x.Length; i++)
     34        if (x[i] != y[i]) return false;
     35      return true;
    2936    }
     37
    3038    public override int GetHashCode(BinaryVector obj) {
     39      if (obj == null) throw new ArgumentNullException("obj", "BinaryVectorEqualityComparer: Cannot compute hash value of null.");
    3140      unchecked {
    3241        int hash = 17;
    33         foreach (var bit in obj) {
     42        foreach (var bit in obj)
    3443          hash = hash * 29 + (bit ? 1231 : 1237);
    35         }
    3644        return hash;
    3745      }
  • branches/PerformanceComparison/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs

    r14659 r15256  
    4545    public static double CalculateSimilarity(BinaryVector left, BinaryVector right) {
    4646      if (left == null || right == null)
    47         throw new ArgumentException("Cannot calculate similarity because one or both of the provided scopes is null.");
     47        throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null.");
    4848      if (left.Length != right.Length)
    4949        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
    50       if (left == right) return 1.0;
     50      if (left.Length == 0)
     51        throw new ArgumentException("Cannot calculate similarity because solutions are of length 0.");
     52      if (ReferenceEquals(left, right)) return 1.0;
    5153
    5254      double similarity = 0.0;
Note: See TracChangeset for help on using the changeset viewer.