Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/17 23:13:15 (7 years ago)
Author:
abeham
Message:

#2730:

  • Unified implementation of all equality comparers and similarity calculators in BinaryVector, IntegerVector, RealVector, Permutation, and LinearLinkage encodings
  • Added Euclidean distance-based similarity calculators for real and integer vectors using a transformation function with scaling parameter
Location:
trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageEqualityComparer.cs

    r14659 r15067  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using HeuristicLab.PluginInfrastructure;
    2325
    2426namespace HeuristicLab.Encodings.LinearLinkageEncoding {
     27  [NonDiscoverableType]
    2528  public class LinearLinkageEqualityComparer : EqualityComparer<LinearLinkage> {
    2629    public override bool Equals(LinearLinkage x, LinearLinkage y) {
    2730      if (x == null && y == null) return true;
    2831      if (x == null || y == null) return false;
     32      if (ReferenceEquals(x, y)) return true;
    2933      if (x.Length != y.Length) return false;
    3034      for (var i = 0; i < x.Length; i++)
     
    3438
    3539    public override int GetHashCode(LinearLinkage obj) {
     40      if (obj == null) throw new ArgumentNullException("obj", "LinearLinkageEqualityComparer: Cannot compute hash value of null.");
    3641      unchecked {
    3742        int hash = 17;
  • trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/SimilarityCalculators/HammingSimilarityCalculator.cs

    r14659 r15067  
    3030  [StorableClass]
    3131  public sealed class HammingSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    32 
    33     protected override bool IsCommutative {
    34       get { return true; }
    35     }
     32    protected override bool IsCommutative { get { return true; } }
    3633
    3734    [StorableConstructor]
    3835    private HammingSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3936    private HammingSimilarityCalculator(HammingSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
    40     public HammingSimilarityCalculator() { }
     37    public HammingSimilarityCalculator() : base() { }
    4138
    4239    public override IDeepCloneable Clone(Cloner cloner) {
     
    4542
    4643    public static double CalculateSimilarity(LinearLinkage left, LinearLinkage right) {
    47       if (left.Length != right.Length) throw new ArgumentException("Comparing encodings of unequal length");
     44      if (left == null || right == null)
     45        throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null.");
     46      if (left.Length != right.Length)
     47        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
     48      if (left.Length == 0)
     49        throw new ArgumentException("Cannot calculate similarity because solutions are of length 0.");
     50      if (ReferenceEquals(left, right)) return 1.0;
     51
    4852      var similarity = 0;
    4953      for (var i = 0; i < left.Length; i++) {
Note: See TracChangeset for help on using the changeset viewer.