- Timestamp:
- 07/04/11 23:15:21 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Crossovers/UniformLikeCrossover.cs
r6342 r6507 29 29 [Item("UniformLikeCrossover", "The ULX crossover tries to maintain the position in the permutation. It randomly chooses from left to right one of its parents' alleles at each position. Missing entries are then filled randomly later. It is described in Tate, D. M. and Smith, A. E. 1995. A genetic approach to the quadratic assignment problem. Computers & Operations Research, vol. 22, pp. 73-83.")] 30 30 [StorableClass] 31 public class UniformLikeCrossover : PermutationCrossover {31 public sealed class UniformLikeCrossover : PermutationCrossover { 32 32 [StorableConstructor] 33 33 protected UniformLikeCrossover(bool deserializing) : base(deserializing) { } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEqualityComparer.cs
r6342 r6507 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 24 26 using HeuristicLab.PluginInfrastructure; 25 27 26 28 namespace HeuristicLab.Encodings.PermutationEncoding { 27 29 [NonDiscoverableType] 28 public class PermutationEqualityComparer : IEqualityComparer<Permutation> {29 public bool Equals(Permutation x, Permutation y) {30 public class PermutationEqualityComparer : EqualityComparer<Permutation> { 31 public override bool Equals(Permutation x, Permutation y) { 30 32 if (x.PermutationType != y.PermutationType) return false; 31 33 if (x.Length != y.Length) return false; … … 43 45 44 46 private bool EqualsAbsolute(Permutation x, Permutation y) { 45 for (int i = 0; i < x.Length; i++) 46 if (x[i] != y[i]) return false; 47 return true; 47 return x.SequenceEqual(y); 48 48 } 49 49 … … 66 66 } 67 67 68 public int GetHashCode(Permutation obj) {68 public override int GetHashCode(Permutation obj) { 69 69 if (obj == null) return 0; 70 return obj.GetHashCode(); 70 return GenerateHashString(obj).GetHashCode(); 71 } 72 73 private string GenerateHashString(Permutation p) { 74 StringBuilder sb = new StringBuilder(); 75 if (p.PermutationType == PermutationTypes.Absolute) { 76 for (int i = 0; i < p.Length; i++) 77 sb.Append(p[i].ToString() + ";"); 78 } else { 79 int i = 0; 80 while (p[i] != 0) i++; // always start at element 0 81 if (p.PermutationType == PermutationTypes.RelativeDirected) { 82 for (int j = 0; j < p.Length; j++) 83 sb.Append(p.GetCircular(i + j).ToString() + ";"); 84 } else { 85 bool goLeft = p.GetCircular(i - 1) < p.GetCircular(i + 1); // go in direction of the lowest edge so that the total inversion and its original return the same hash code 86 for (int j = 0; j < p.Length; j++) { 87 if (goLeft) sb.Append(p.GetCircular(i - j).ToString() + ";"); 88 else sb.Append(p.GetCircular(i + j).ToString() + ";"); 89 } 90 } 91 } 92 return sb.ToString(); 71 93 } 72 94 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Tests/HeuristicLab.Encodings.PermutationEncoding-3.3.Tests.csproj
r6342 r6507 112 112 <Compile Include="OrderCrossoverTest.cs" /> 113 113 <Compile Include="PartiallyMatchedCrossoverTest.cs" /> 114 <Compile Include="PermutationEqualityComparerTest.cs" /> 114 115 <Compile Include="PositionBasedCrossoverTest.cs" /> 115 116 <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset
for help on using the changeset viewer.