Changeset 15067 for trunk/sources
- Timestamp:
- 06/26/17 23:13:15 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEqualityComparer.cs
r14659 r15067 19 19 */ 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 using System.Linq;24 using HeuristicLab.PluginInfrastructure; 24 25 25 26 namespace HeuristicLab.Encodings.BinaryVectorEncoding { 27 [NonDiscoverableType] 26 28 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 (x == null && y == null) return true; 31 if (x == null || y == null) return false; 32 if (ReferenceEquals(x, y)) return true; 33 if (x.Length != y.Length) return false; 34 for (var i = 0; i < x.Length; i++) 35 if (x[i] != y[i]) return false; 36 return true; 29 37 } 30 38 public override int GetHashCode(BinaryVector obj) { 39 if (obj == null) throw new ArgumentNullException("obj", "BinaryVectorEqualityComparer: Cannot compute hash value of null."); 31 40 unchecked { 32 41 int hash = 17; -
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs
r14659 r15067 45 45 public static double CalculateSimilarity(BinaryVector left, BinaryVector right) { 46 46 if (left == null || right == null) 47 throw new ArgumentException("Cannot calculate similarity because one or both of the provided s copes is null.");47 throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null."); 48 48 if (left.Length != right.Length) 49 49 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; 51 53 52 54 double similarity = 0.0; -
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj
r14660 r15067 147 147 <Compile Include="Manipulators\RoundedNormalAllPositionsManipulator.cs" /> 148 148 <Compile Include="Manipulators\SelfAdaptiveRoundedNormalAllPositionsManipulator.cs" /> 149 <Compile Include="SimilarityCalculators\EuclideanSimilarityCalculator.cs" /> 149 150 <Compile Include="SimilarityCalculators\HammingSimilarityCalculator.cs" /> 150 151 <Compile Include="StrategyParameters\StdDevStrategyVectorCreator.cs" /> -
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEqualityComparer.cs
r14659 r15067 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using HeuristicLab.PluginInfrastructure; 23 25 24 26 namespace HeuristicLab.Encodings.IntegerVectorEncoding { 27 [NonDiscoverableType] 25 28 public class IntegerVectorEqualityComparer : EqualityComparer<IntegerVector> { 26 29 public override bool Equals(IntegerVector x, IntegerVector y) { 27 30 if (x == null && y == null) return true; 28 31 if (x == null || y == null) return false; 32 if (ReferenceEquals(x, y)) return true; 29 33 if (x.Length != y.Length) return false; 30 34 for (var i = 0; i < x.Length; i++) … … 34 38 35 39 public override int GetHashCode(IntegerVector obj) { 40 if (obj == null) throw new ArgumentNullException("obj", "IntegerVectorEqualityComparer: Cannot compute hash value of null."); 36 41 unchecked { 37 42 int hash = 17; -
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs
r14659 r15067 45 45 public static double CalculateSimilarity(IntegerVector left, IntegerVector right) { 46 46 if (left == null || right == null) 47 throw new ArgumentException("Cannot calculate similarity because one or both of the provided s copes is null.");47 throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null."); 48 48 if (left.Length != right.Length) 49 49 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; 51 53 52 54 double similarity = 0.0; -
trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageEqualityComparer.cs
r14659 r15067 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using HeuristicLab.PluginInfrastructure; 23 25 24 26 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 27 [NonDiscoverableType] 25 28 public class LinearLinkageEqualityComparer : EqualityComparer<LinearLinkage> { 26 29 public override bool Equals(LinearLinkage x, LinearLinkage y) { 27 30 if (x == null && y == null) return true; 28 31 if (x == null || y == null) return false; 32 if (ReferenceEquals(x, y)) return true; 29 33 if (x.Length != y.Length) return false; 30 34 for (var i = 0; i < x.Length; i++) … … 34 38 35 39 public override int GetHashCode(LinearLinkage obj) { 40 if (obj == null) throw new ArgumentNullException("obj", "LinearLinkageEqualityComparer: Cannot compute hash value of null."); 36 41 unchecked { 37 42 int hash = 17; -
trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/SimilarityCalculators/HammingSimilarityCalculator.cs
r14659 r15067 30 30 [StorableClass] 31 31 public sealed class HammingSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 32 33 protected override bool IsCommutative { 34 get { return true; } 35 } 32 protected override bool IsCommutative { get { return true; } } 36 33 37 34 [StorableConstructor] 38 35 private HammingSimilarityCalculator(bool deserializing) : base(deserializing) { } 39 36 private HammingSimilarityCalculator(HammingSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 40 public HammingSimilarityCalculator() { }37 public HammingSimilarityCalculator() : base() { } 41 38 42 39 public override IDeepCloneable Clone(Cloner cloner) { … … 45 42 46 43 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 48 52 var similarity = 0; 49 53 for (var i = 0; i < left.Length; i++) { -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEqualityComparer.cs
r14185 r15067 30 30 public class PermutationEqualityComparer : EqualityComparer<Permutation> { 31 31 public override bool Equals(Permutation x, Permutation y) { 32 if (x == null && y == null) return true; 33 if (x == null || y == null) return false; 34 if (ReferenceEquals(x, y)) return true; 35 if (x.Length != y.Length) return false; 32 36 if (x.PermutationType != y.PermutationType) return false; 33 if (x.Length != y.Length) return false;34 37 switch (x.PermutationType) { 35 38 case PermutationTypes.Absolute: … … 67 70 68 71 public override int GetHashCode(Permutation obj) { 69 if (obj == null) return 0;72 if (obj == null) throw new ArgumentNullException("obj", "PermutationEqualityComparer: Cannot compute hash value of null."); 70 73 return GenerateHashString(obj).GetHashCode(); 71 74 } -
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) { -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj
r14660 r15067 183 183 <Compile Include="ReflectiveBoundsChecker.cs" /> 184 184 <Compile Include="ShakingOperators\RealVectorShakingOperator.cs" /> 185 <Compile Include="SimilarityCalculators\EuclideanSimilarityCalculator.cs" /> 185 186 <Compile Include="SimilarityCalculators\HammingSimilarityCalculator.cs" /> 186 187 <Compile Include="StrategyParameters\StdDevStrategyVectorCreator.cs" /> -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorEqualityComparer.cs
r14659 r15067 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using HeuristicLab.PluginInfrastructure; 23 25 24 26 namespace HeuristicLab.Encodings.RealVectorEncoding { 27 [NonDiscoverableType] 25 28 public class RealVectorEqualityComparer : EqualityComparer<RealVector> { 26 29 public override bool Equals(RealVector x, RealVector y) { 27 30 if (x == null && y == null) return true; 28 31 if (x == null || y == null) return false; 32 if (ReferenceEquals(x, y)) return true; 29 33 if (x.Length != y.Length) return false; 30 34 for (var i = 0; i < x.Length; i++) … … 34 38 35 39 public override int GetHashCode(RealVector obj) { 40 if (obj == null) throw new ArgumentNullException("obj", "RealVectorEqualityComparer: Cannot compute hash value of null."); 36 41 unchecked { 37 42 int hash = 17; -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs
r14659 r15067 45 45 public static double CalculateSimilarity(RealVector left, RealVector right) { 46 46 if (left == null || right == null) 47 throw new ArgumentException("Cannot calculate similarity because one or both of the provided s copes is null.");47 throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null."); 48 48 if (left.Length != right.Length) 49 49 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; 51 53 52 54 double similarity = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.