- Timestamp:
- 02/19/10 02:15:10 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/InversionManipulator.cs
r2794 r2830 31 31 [Creatable("Test")] 32 32 public class InversionManipulator : PermutationManipulator { 33 34 33 /// <summary> 35 34 /// Inverts a randomly chosen part of a permutation. … … 38 37 /// <param name="permutation">The permutation to manipulate.</param> 39 38 /// <returns>The new manipulated permutation.</returns> 40 public static Permutation Apply(IRandom random, Permutation permutation) { 41 Permutation result = (Permutation)permutation.Clone(); 39 public static void Apply(IRandom random, Permutation permutation) { 42 40 int breakPoint1, breakPoint2; 43 41 44 breakPoint1 = random.Next( result.Length - 1);42 breakPoint1 = random.Next(permutation.Length - 1); 45 43 do { 46 breakPoint2 = random.Next( result.Length - 1);44 breakPoint2 = random.Next(permutation.Length - 1); 47 45 } while (breakPoint2 == breakPoint1); 48 46 if (breakPoint2 < breakPoint1) { int h = breakPoint1; breakPoint1 = breakPoint2; breakPoint2 = h; } 49 47 50 for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) { // invert permutation between breakpoints 51 result[breakPoint1 + i] = permutation[breakPoint2 - i]; 48 for (int i = 0; i <= (breakPoint2 - breakPoint1) / 2; i++) { // invert permutation between breakpoints 49 int temp = permutation[breakPoint1 + i]; 50 permutation[breakPoint1 + i] = permutation[breakPoint2 - i]; 51 permutation[breakPoint2 - i] = temp; 52 52 } 53 return result;54 53 } 55 54 … … 60 59 /// <param name="permutation">The permutation to manipulate.</param> 61 60 /// <returns>The new manipulated permuation.</returns> 62 protected override PermutationManipulate(IRandom random, Permutation permutation) {63 returnApply(random, permutation);61 protected override void Manipulate(IRandom random, Permutation permutation) { 62 Apply(random, permutation); 64 63 } 65 64 }
Note: See TracChangeset
for help on using the changeset viewer.