Changeset 14664 for branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators
- Timestamp:
- 02/11/17 01:01:25 (8 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.PermutationEncoding merged: 14662
- Property svn:mergeinfo changed
-
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/InsertionManipulator.cs
r14600 r14664 50 50 /// <param name="permutation">The permutation to manipulate.</param> 51 51 public static void Apply(IRandom random, Permutation permutation) { 52 Permutation original = (Permutation)permutation.Clone();53 int cutIndex, insertIndex, number;52 var cutIndex = random.Next(permutation.Length); 53 var insertIndex = random.Next(permutation.Length); 54 54 55 cutIndex = random.Next(original.Length); 56 insertIndex = random.Next(original.Length); 57 number = original[cutIndex]; 55 if (cutIndex == insertIndex) return; 58 56 59 int i = 0; // index in new permutation 60 int j = 0; // index in old permutation 61 while (i < original.Length) { 62 if (j == cutIndex) { 63 j++; 64 } 65 if (i == insertIndex) { 66 permutation[i] = number; 67 i++; 68 } 69 if ((i < original.Length) && (j < original.Length)) { 70 permutation[i] = original[j]; 71 i++; 72 j++; 73 } 74 } 57 permutation.Move(cutIndex, cutIndex, insertIndex); 75 58 } 76 59 -
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/InversionManipulator.cs
r14600 r14664 60 60 61 61 public static void Apply(Permutation permutation, int breakPoint1, int breakPoint2) { 62 for (int i = 0; i <= (breakPoint2 - breakPoint1) / 2; i++) { // invert permutation between breakpoints 63 int temp = permutation[breakPoint1 + i]; 64 permutation[breakPoint1 + i] = permutation[breakPoint2 - i]; 65 permutation[breakPoint2 - i] = temp; 66 } 62 permutation.Reverse(breakPoint1, breakPoint2 - breakPoint1 + 1); 67 63 } 68 64 -
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/ScrambleManipulator.cs
r14600 r14664 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 57 58 breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length); 58 59 60 // TODO: Use Fisher-Yates-Shuffle rather than complicated code below 61 // scrambledIndices = Enumerable.Range(0, breakPoint2 - breakPoint1 + 1).Shuffle(random).ToArray(); 62 // Also, it would be more memory-efficient to change here and Apply(Permutation, int, int[]) below to interpret scrambleArray as values, not indices 63 // Don't forget the move generator 64 // BackwardsCompatibility3.3 65 #region This whole code should be replaced by above line when going for 3.4 59 66 scrambledIndices = new int[breakPoint2 - breakPoint1 + 1]; 60 67 remainingIndices = new int[breakPoint2 - breakPoint1 + 1]; … … 77 84 } 78 85 } 86 #endregion 79 87 80 88 Apply(permutation, breakPoint1, scrambledIndices); … … 82 90 83 91 public static void Apply(Permutation permutation, int startIndex, int[] scrambleArray) { 84 Permutation original = (Permutation)permutation.Clone(); 85 for (int i = 0; i < scrambleArray.Length; i++) { // scramble permutation between breakpoints 86 permutation[startIndex + i] = original[startIndex + scrambleArray[i]]; 87 } 92 permutation.Replace(startIndex, scrambleArray.Select(x => permutation[startIndex + x]).ToArray()); 88 93 } 89 94 -
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/Swap2Manipulator.cs
r14600 r14664 58 58 59 59 public static void Apply(Permutation permutation, int index1, int index2) { 60 int temp = permutation[index1]; 61 permutation[index1] = permutation[index2]; 62 permutation[index2] = temp; 60 permutation.Swap(index1, index2); 63 61 } 64 62 -
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/Swap3Manipulator.cs
r14600 r14664 57 57 public static void Apply(IRandom random, Permutation permutation) { 58 58 if (permutation.Length < 3) throw new ArgumentException("Swap3Manipulator: The permutation must be at least of size 3.", "permutation"); 59 int index1, index2, index3 , temp;59 int index1, index2, index3; 60 60 61 61 do { … … 65 65 } while (index1 == index2 || index2 == index3 || index1 == index3); 66 66 67 // swap positions 1 and 2 68 temp = permutation[index1]; 69 permutation[index1] = permutation[index2]; 70 permutation[index2] = temp; 71 // swap positions 2 and 3 72 temp = permutation[index2]; 73 permutation[index2] = permutation[index3]; 74 permutation[index3] = temp; 67 permutation.Swap(index1, index2); 68 permutation.Swap(index2, index3); 75 69 } 76 70 -
branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/TranslocationManipulator.cs
r14600 r14664 65 65 66 66 public static void Apply(Permutation permutation, int breakPoint1, int breakPoint2, int insertPoint) { 67 Permutation original = (Permutation)permutation.Clone(); 68 69 int i = 0; // index in new permutation 70 int j = 0; // index in old permutation 71 while (i < original.Length) { 72 if (i == insertPoint) { // copy translocated area 73 for (int k = breakPoint1; k <= breakPoint2; k++) { 74 permutation[i] = original[k]; 75 i++; 76 } 77 } 78 if (j == breakPoint1) { // skip area between breakpoints 79 j = breakPoint2 + 1; 80 } 81 if ((i < original.Length) && (j < original.Length)) { 82 permutation[i] = original[j]; 83 i++; 84 j++; 85 } 86 } 67 permutation.Move(breakPoint1, breakPoint2, insertPoint); 87 68 } 88 69
Note: See TracChangeset
for help on using the changeset viewer.