Changeset 15217 for stable/HeuristicLab.Encodings.BinaryVectorEncoding
- Timestamp:
- 07/12/17 21:02:01 (7 years ago)
- Location:
- stable
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14412,14475-14476,14659-14660,14663,14912,15050,15067,15069,15079,15162,15166,15172-15173
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.BinaryVectorEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding merged: 14412,14659-14660,15067,15162
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEqualityComparer.cs
r14660 r15217 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 (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; 29 36 } 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; 33 foreach (var bit in obj) {42 foreach (var bit in obj) 34 43 hash = hash * 29 + (bit ? 1231 : 1237); 35 }36 44 return hash; 37 45 } -
stable/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
r12005 r15217 120 120 <ItemGroup> 121 121 <Compile Include="BinaryVectorEncoding.cs" /> 122 <Compile Include="BinaryVectorEqualityComparer.cs" /> 122 123 <Compile Include="Creators\RandomBinaryVectorCreator.cs" /> 123 124 <Compile Include="Crossovers\MultiBinaryVectorCrossover.cs" /> … … 126 127 <Compile Include="Crossovers\NPointCrossover.cs" /> 127 128 <Compile Include="BinaryVector.cs" /> 129 <Compile Include="SimilarityCalculators\HammingSimilarityCalculator.cs" /> 128 130 <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" /> 129 131 <Compile Include="Interfaces\IOneBitflipMoveOperator.cs" /> -
stable/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs
r14659 r15217 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;
Note: See TracChangeset
for help on using the changeset viewer.