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.PermutationEncoding
Files:
3 edited

Legend:

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

  • branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEqualityComparer.cs

    r14600 r15256  
    3030  public class PermutationEqualityComparer : EqualityComparer<Permutation> {
    3131    public override bool Equals(Permutation x, Permutation y) {
     32      if (ReferenceEquals(x, y)) return true;
     33      if (x == null || y == null) return false;
     34      if (x.Length != y.Length) return false;
    3235      if (x.PermutationType != y.PermutationType) return false;
    33       if (x.Length != y.Length) return false;
    3436      switch (x.PermutationType) {
    3537        case PermutationTypes.Absolute:
     
    6769
    6870    public override int GetHashCode(Permutation obj) {
    69       if (obj == null) return 0;
     71      if (obj == null) throw new ArgumentNullException("obj", "PermutationEqualityComparer: Cannot compute hash value of null.");
    7072      return GenerateHashString(obj).GetHashCode();
    7173    }
  • branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs

    r14659 r15256  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Optimization.Operators;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Encodings.PermutationEncoding {
    2829  [Item("Hamming Similarity Calculator for Permutation", "An operator that performs similarity calculation between two permutation-encoded solutions.")]
     30  [StorableClass]
    2931  public sealed class HammingSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3032    protected override bool IsCommutative { get { return true; } }
    3133
     34    [StorableConstructor]
    3235    private HammingSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3336    private HammingSimilarityCalculator(HammingSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     
    4043    public static double CalculateSimilarity(Permutation left, Permutation right) {
    4144      if (left == null || right == null)
    42         throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
     45        throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null.");
    4346      if (left.PermutationType != right.PermutationType)
    44         throw new ArgumentException("Cannot calculate similarity because the provided solutions have different types.");
     47        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different permutation types.");
    4548      if (left.Length != right.Length)
    4649        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
    47       if (object.ReferenceEquals(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;
    4853
    4954      switch (left.PermutationType) {
Note: See TracChangeset for help on using the changeset viewer.