Changeset 15067 for trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/SimilarityCalculators
- Timestamp:
- 06/26/17 23:13:15 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs
r14659 r15067 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Optimization.Operators; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Encodings.PermutationEncoding { 28 29 [Item("Hamming Similarity Calculator for Permutation", "An operator that performs similarity calculation between two permutation-encoded solutions.")] 30 [StorableClass] 29 31 public sealed class HammingSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 30 32 protected override bool IsCommutative { get { return true; } } 31 33 34 [StorableConstructor] 32 35 private HammingSimilarityCalculator(bool deserializing) : base(deserializing) { } 33 36 private HammingSimilarityCalculator(HammingSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 40 43 public static double CalculateSimilarity(Permutation left, Permutation right) { 41 44 if (left == null || right == null) 42 throw new ArgumentException("Cannot calculate similarity because one o f the provided solutions or both arenull.");45 throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null."); 43 46 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."); 45 48 if (left.Length != right.Length) 46 49 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; 48 53 49 54 switch (left.PermutationType) {
Note: See TracChangeset
for help on using the changeset viewer.