Changeset 2830 for trunk/sources/HeuristicLab.Permutation
- Timestamp:
- 02/19/10 02:15:10 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Permutation/3.3
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/CyclicCrossover.cs
r2829 r2830 54 54 if (parent1.Length != parent2.Length) throw new ArgumentException("CyclicCrossover: The parent permutations are of unequal length"); 55 55 int length = parent1.Length; 56 Permutation result = new Permutation(length);56 int[] result = new int[length]; 57 57 bool[] indexCopied = new bool[length]; 58 58 int[] invParent1 = new int[length]; … … 89 89 } while (j < length); 90 90 91 return result;91 return new Permutation(result); 92 92 } 93 93 -
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 } -
trunk/sources/HeuristicLab.Permutation/3.3/MaximalPreservativeCrossover.cs
r2829 r2830 59 59 if (parent1.Length < 4) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutation must be at least of size 4"); 60 60 int length = parent1.Length; 61 Permutation result = new Permutation(length);61 int[] result = new int[length]; 62 62 bool[] numberCopied = new bool[length]; 63 63 int breakPoint1, breakPoint2, subsegmentLength, index; … … 119 119 } while (index != breakPoint1); 120 120 121 return result;121 return new Permutation(result); 122 122 } 123 123 -
trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs
r2794 r2830 45 45 /// <returns>The new permutation resulting from the crossover.</returns> 46 46 public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { 47 Permutation result = new Permutation(parent1.Length);47 int[] result = new int[parent1.Length]; 48 48 bool[] copied = new bool[result.Length]; 49 49 … … 66 66 } 67 67 } 68 return result;68 return new Permutation(result); 69 69 } 70 70 -
trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs
r2829 r2830 57 57 if (parent1.Length < 4) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutation must be at least of size 4"); 58 58 int length = parent1.Length; 59 Permutation result = new Permutation(length);;59 int[] result = new int[length]; 60 60 int[] invResult = new int[length]; 61 61 … … 85 85 } 86 86 87 return result;87 return new Permutation(result); 88 88 } 89 89 -
trunk/sources/HeuristicLab.Permutation/3.3/Permutation.cs
r2794 r2830 44 44 public Permutation(int[] elements) 45 45 : base(elements) { 46 if (!Validate()) throw new ArgumentException("Elements do not represent a valid permutation.");47 46 } 48 47 private Permutation(Permutation elements) : base(elements) { } -
trunk/sources/HeuristicLab.Permutation/3.3/PermutationManipulator.cs
r2794 r2830 46 46 47 47 public sealed override IExecutionSequence Apply() { 48 PermutationParameter.ActualValue =Manipulate(RandomParameter.ActualValue, PermutationParameter.ActualValue);48 Manipulate(RandomParameter.ActualValue, PermutationParameter.ActualValue); 49 49 return base.Apply(); 50 50 } 51 51 52 protected abstract PermutationManipulate(IRandom random, Permutation permutation);52 protected abstract void Manipulate(IRandom random, Permutation permutation); 53 53 } 54 54 }
Note: See TracChangeset
for help on using the changeset viewer.