Changeset 2854 for trunk/sources/HeuristicLab.Permutation
- Timestamp:
- 02/24/10 10:01:26 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Permutation/3.3
- Files:
-
- 15 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/AbsolutePositionTopologicalCrossover.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Permutation { … … 32 33 /// (minding already inserted values). 33 34 /// </summary> 35 /// <remarks>It is implemented as described in Moraglio, A. and Poli, R. 2005. Topological crossover for the permutation representation. In Proceedings of the 2005 Workshops on Genetic and Evolutionary Computation.<br /> 36 /// </remarks> 34 37 /// <example>First take the value at position 0 from parent1 then take the value at position 0 35 38 /// from parent2 if it has not already been inserted, afterwards take the value at position 1 from 36 39 /// parent1 if it has not already been inserted, then from parent2 and so on.</example> 37 public class AbsolutePositionTopologicalCrossover : PermutationCrossoverBase {38 /// <inheritdoc select="summary"/> 39 public override string Description { 40 get { return @"TODO\r\nOperator description still missing ..."; }41 }42 40 [Item("AbsolutePositionTopologicalCrossover", @"An operator which performs a cross over permutation between two permutation arrays by taking the 41 entries with the same index (starting at position 0) from both parents 42 (minding already inserted values).")] 43 [EmptyStorableClass] 44 [Creatable("Test")] 45 public class AbsolutePositionTopologicalCrossover : PermutationCrossover { 43 46 /// <summary> 44 47 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> … … 48 51 /// from parent2 if it has not already been inserted, afterwards take the value at position 1 from 49 52 /// parent1 if it has not already been inserted, then from parent2 and so on.</example> 50 /// <param name="random">A random number generator.</param> 53 /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception> 54 /// <param name="random">The random number generator.</param> 51 55 /// <param name="parent1">The parent scope 1 to cross over.</param> 52 56 /// <param name="parent2">The parent scope 2 to cross over.</param> 53 57 /// <returns>The created cross over permutation as int array.</returns> 54 public static int[] Apply(IRandom random, int[] parent1, int[] parent2) { 58 public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { 59 if (parent1.Length != parent2.Length) throw new ArgumentException("AbsolutePositionTopologicalCrossover: The parent permutations are of unequal length."); 55 60 int length = parent1.Length; 56 61 int[] result = new int[length]; … … 71 76 } 72 77 } 73 return result;78 return new Permutation(result); 74 79 } 75 80 … … 78 83 /// </summary> 79 84 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 80 /// <param name="scope">The current scope.</param>81 85 /// <param name="random">A random number generator.</param> 82 86 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 83 87 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 84 protected override int[] Cross(IScope scope, IRandom random, int[][]parents) {88 protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) { 85 89 if (parents.Length != 2) throw new InvalidOperationException("ERROR in AbsolutePositionTopologicalCrossover: The number of parents is not equal to 2"); 86 90 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Permutation/3.3/CosaCrossover.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Permutation { 29 30 /// <summary> 30 /// Performs a cross over permutation between two permutation arrays by taking randomly chosen31 /// Performs a crossover operation between two permutation arrays by taking randomly chosen 31 32 /// reverse and forward intervals from the first permutation array inserting 32 33 /// it in the child on different positions depending on the second permutation array. 33 34 /// </summary> 34 public class CosaCrossover : PermutationCrossoverBase { 35 /// <inheritdoc select="summary"/> 36 public override string Description { 37 get { return @"TODO\r\nOperator description still missing ..."; } 38 } 39 35 [Item("CosaCrossover", "An operator which performs a crossover operation between two permutation arrays by taking randomly chosen reverse and forward intervals from the first permutation array inserting it in the child on different positions depending on the second permutation array.")] 36 [EmptyStorableClass] 37 [Creatable("Test")] 38 public class CosaCrossover : PermutationCrossover { 40 39 /// <summary> 41 40 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> … … 44 43 /// The remaining elements to be inserted are taken again from parent1 in the forward direction. 45 44 /// </summary> 45 /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception> 46 46 /// <param name="random">The random number generator.</param> 47 47 /// <param name="parent1">The parent scope 1 to cross over.</param> 48 48 /// <param name="parent2">The parent scope 2 to cross over.</param> 49 49 /// <returns>The created cross over permutation as int array.</returns> 50 public static int[] Apply(IRandom random, int[] parent1, int[] parent2) { 50 public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { 51 if (parent1.Length != parent2.Length) throw new ArgumentException("CosaCrossover: The parent permutations are of unequal length."); 51 52 int length = parent1.Length; 52 53 int[] result = new int[length]; … … 82 83 } 83 84 result[j] = parent1[crossPoint]; // last station: crosspoint 84 return result;85 return new Permutation(result); 85 86 } 86 87 … … 89 90 /// </summary> 90 91 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 91 /// <param name="scope">The current scope.</param>92 92 /// <param name="random">A random number generator.</param> 93 93 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 94 94 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 95 protected override int[] Cross(IScope scope, IRandom random, int[][]parents) {95 protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) { 96 96 if (parents.Length != 2) throw new InvalidOperationException("ERROR in CosaCrossover: The number of parents is not equal to 2"); 97 97 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Permutation/3.3/CyclicCrossover.cs
r2835 r2854 31 31 /// The operator first determines all cycles in the permutation and then composes the offspring by alternating between the cycles of the two parents. 32 32 /// </remarks> 33 [Item("CyclicCrossover", "An operator which performs the cyclic crossover on two permutations as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]33 [Item("CyclicCrossover", "An operator which performs the cyclic crossover on two permutations.")] 34 34 [EmptyStorableClass] 35 35 [Creatable("Test")] … … 47 47 /// The stochasticity of this operator is rather low. There are only two possible outcomes for a given pair of parents. 48 48 /// </remarks> 49 /// <exception cref="ArgumentException">Thrown if the two parents are not of equal length.</exception> 49 50 /// <param name="random">The random number generator.</param> 50 51 /// <param name="parent1">The parent scope 1 to cross over.</param> … … 77 78 if (copyFromParent1) { 78 79 result[j] = parent1[j]; // copy number at position j from parent1 80 indexCopied[j] = true; 79 81 j = invParent2[result[j]]; // set position j to the position of the copied number in parent2 80 82 } else { 81 83 result[j] = parent2[j]; // copy number at position j from parent2 84 indexCopied[j] = true; 82 85 j = invParent1[result[j]]; // set position j to the position of the copied number in parent1 83 86 } 84 indexCopied[j] = true;85 87 } while (!indexCopied[j]); 86 88 copyFromParent1 = !copyFromParent1; … … 96 98 /// </summary> 97 99 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 98 /// <param name="scope">The current scope.</param>99 100 /// <param name="random">A random number generator.</param> 100 101 /// <param name="parents">An array containing the two permutations that should be crossed.</param> -
trunk/sources/HeuristicLab.Permutation/3.3/EdgeRecombinationCrossover.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Permutation { … … 32 33 /// number of neighbours, the next again a neighbour and so on. 33 34 /// </summary> 34 public class EdgeRecombinationCrossover : PermutationCrossoverBase { 35 /// <inheritdoc select="summary"/> 36 public override string Description { 37 get { return @"TODO\r\nOperator description still missing ..."; } 38 } 39 35 /// /// <remarks>It is implemented as described in Whitley et.al. 1991, The Traveling Salesman and Sequence Scheduling, in Davis, L. (Ed.), Handbook ov Genetic Algorithms, New York, pp. 350-372<br /> 36 /// The operator first determines all cycles in the permutation and then composes the offspring by alternating between the cycles of the two parents. 37 /// </remarks> 38 [Item("EdgeRecombinationCrossover", "An operator which performs the edge recombination crossover on two permutations.")] 39 [EmptyStorableClass] 40 [Creatable("Test")] 41 public class EdgeRecombinationCrossover : PermutationCrossover { 40 42 /// <summary> 41 43 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="2"/> … … 44 46 /// number of neighbours, the next again a neighbour and so on. 45 47 /// </summary> 48 /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception> 46 49 /// <exception cref="InvalidOperationException">Thrown when the permutation lacks a number. 47 50 /// </exception> … … 50 53 /// <param name="parent2">The parent scope 2 to cross over.</param> 51 54 /// <returns>The created cross over permutation as int array.</returns> 52 public static int[] Apply(IRandom random, int[] parent1, int[] parent2) { 55 public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { 56 if (parent1.Length != parent2.Length) throw new ArgumentException("EdgeRecombinationCrossover: The parent permutations are of unequal length."); 53 57 int length = parent1.Length; 54 58 int[] result = new int[length]; … … 135 139 } 136 140 } 137 return result;141 return new Permutation(result); 138 142 } 139 143 … … 142 146 /// </summary> 143 147 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 144 /// <param name="scope">The current scope.</param>145 148 /// <param name="random">A random number generator.</param> 146 149 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 147 150 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 148 protected override int[] Cross(IScope scope, IRandom random, int[][]parents) {151 protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) { 149 152 if (parents.Length != 2) throw new InvalidOperationException("ERROR in EdgeRecombinationCrossover: The number of parents is not equal to 2"); 150 153 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Permutation/3.3/HeuristicLab.Permutation-3.3.csproj
r2852 r2854 82 82 <ItemGroup> 83 83 <None Include="HeuristicLabPermutationPlugin.cs.frame" /> 84 <Compile Include="AbsolutePositionTopologicalCrossover.cs" /> 85 <Compile Include="CosaCrossover.cs" /> 84 86 <Compile Include="CyclicCrossover.cs" /> 87 <Compile Include="EdgeRecombinationCrossover.cs" /> 88 <Compile Include="InsertionManipulator.cs" /> 85 89 <Compile Include="InversionManipulator.cs"> 86 90 <SubType>Code</SubType> 87 91 </Compile> 88 92 <Compile Include="MaximalPreservativeCrossover.cs" /> 93 <Compile Include="OrderBasedCrossover.cs" /> 89 94 <Compile Include="PartiallyMatchedCrossover.cs" /> 90 95 <Compile Include="PermutationManipulator.cs" /> … … 93 98 <Compile Include="PermutationCrossover.cs" /> 94 99 <Compile Include="Permutation.cs" /> 100 <Compile Include="PositionBasedCrossover.cs" /> 95 101 <Compile Include="Properties\AssemblyInfo.cs" /> 96 102 <Compile Include="RandomPermutationCreator.cs" /> 103 <Compile Include="ScrambleManipulator.cs" /> 104 <Compile Include="Swap2Manipulator.cs" /> 105 <Compile Include="Swap3Manipulator.cs" /> 106 <Compile Include="TranslocationInversionManipulator.cs" /> 107 <Compile Include="TranslocationManipulator.cs" /> 97 108 </ItemGroup> 98 109 <ItemGroup> -
trunk/sources/HeuristicLab.Permutation/3.3/InsertionManipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Permutation { 28 29 /// <summary> 29 30 /// Manipulates a permutation array by moving randomly one element to another position in the array. 30 /// </summary> 31 public class InsertionManipulator : PermutationManipulatorBase { 32 /// <inheritdoc select="summary"/> 33 public override string Description { 34 get { return @"TODO\r\nOperator description still missing ..."; } 35 } 36 31 /// </summary> 32 /// <remarks> 33 /// It is implemented as described in Fogel, D.B. (1988). An Evolutionary Approach to the Traveling Salesman Problem, Biological Cybernetics, 60, pp. 139-144 34 /// </remarks> 35 [Item("InsertionManipulator", "An operator which moves randomly one element to another position in the permutation.")] 36 [EmptyStorableClass] 37 [Creatable("Test")] 38 public class InsertionManipulator : PermutationManipulator { 37 39 /// <summary> 38 40 /// Moves an randomly chosen element in the specified <paramref name="permutation"/> array … … 40 42 /// </summary> 41 43 /// <param name="random">The random number generator.</param> 42 /// <param name="permutation">The array to manipulate.</param> 43 /// <returns>The new permuation array with the manipulated data.</returns> 44 public static int[] Apply(IRandom random, int[] permutation) { 45 int[] result = (int[])permutation.Clone(); 44 /// <param name="permutation">The permutation to manipulate.</param> 45 public static void Apply(IRandom random, Permutation permutation) { 46 Permutation original = (Permutation)permutation.Clone(); 46 47 int cutIndex, insertIndex, number; 47 48 48 cutIndex = random.Next( permutation.Length);49 insertIndex = random.Next( permutation.Length);50 number = permutation[cutIndex];49 cutIndex = random.Next(original.Length); 50 insertIndex = random.Next(original.Length); 51 number = original[cutIndex]; 51 52 52 53 int i = 0; // index in new permutation 53 54 int j = 0; // index in old permutation 54 while (i < permutation.Length) {55 while (i < original.Length) { 55 56 if (j == cutIndex) { 56 57 j++; 57 58 } 58 59 if (i == insertIndex) { 59 result[i] = number;60 permutation[i] = number; 60 61 i++; 61 62 } 62 if ((i < permutation.Length) && (j < permutation.Length)) {63 result[i] = permutation[j];63 if ((i < original.Length) && (j < original.Length)) { 64 permutation[i] = original[j]; 64 65 i++; 65 66 j++; 66 67 } 67 68 } 68 return result;69 69 } 70 70 … … 74 74 /// </summary> 75 75 /// <remarks>Calls <see cref="Apply"/>.</remarks> 76 /// <param name="scope">The current scope.</param> 77 /// <param name="random">The random number generator.</param> 78 /// <param name="permutation">The array to manipulate.</param> 79 /// <returns>The new permuation array with the manipulated data.</returns> 80 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 81 return Apply(random, permutation); 76 /// <param name="random">A random number generator.</param> 77 /// <param name="permutation">The permutation to manipulate.</param> 78 protected override void Manipulate(IRandom random, Permutation permutation) { 79 Apply(random, permutation); 82 80 } 83 81 } -
trunk/sources/HeuristicLab.Permutation/3.3/InversionManipulator.cs
r2830 r2854 27 27 /// An operator which inverts a randomly chosen part of a permutation. 28 28 /// </summary> 29 /// <remarks> 30 /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.<br /> 31 /// </remarks> 29 32 [Item("InversionManipulator", "An operator which inverts a randomly chosen part of a permutation.")] 30 33 [EmptyStorableClass] … … 36 39 /// <param name="random">A random number generator.</param> 37 40 /// <param name="permutation">The permutation to manipulate.</param> 38 /// <returns>The new manipulated permutation.</returns>39 41 public static void Apply(IRandom random, Permutation permutation) { 40 42 int breakPoint1, breakPoint2; … … 58 60 /// <param name="random">A random number generator.</param> 59 61 /// <param name="permutation">The permutation to manipulate.</param> 60 /// <returns>The new manipulated permuation.</returns>61 62 protected override void Manipulate(IRandom random, Permutation permutation) { 62 63 Apply(random, permutation); -
trunk/sources/HeuristicLab.Permutation/3.3/MaximalPreservativeCrossover.cs
r2835 r2854 34 34 /// If the length of the permutation is smaller than 15, the size of the segment is always equal to 3. 35 35 /// </remarks> 36 [Item("MaximalPreservativeCrossover", "An operator which performs the maximal preservative crossover on two permutations as described in Mühlenbein, H. 1991. Evolution in time and space - the parallel genetic algorithm. FOUNDATIONS OF GENETIC ALGORITHMS, pp. 316-337. Morgan Kaufmann.")]36 [Item("MaximalPreservativeCrossover", "An operator which performs the maximal preservative crossover on two permutations.")] 37 37 [EmptyStorableClass] 38 38 [Creatable("Test")] … … 131 131 /// </summary> 132 132 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two permutations in <paramref name="parents"/>.</exception> 133 /// <param name="scope">The current scope.</param>134 133 /// <param name="random">A random number generator.</param> 135 134 /// <param name="parents">An array containing the two permutations that should be crossed.</param> -
trunk/sources/HeuristicLab.Permutation/3.3/OrderBasedCrossover.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Permutation { … … 32 33 /// the missing entries with the elements from the second permutation, also in the right order. 33 34 /// </summary> 34 public class OrderBasedCrossover : PermutationCrossoverBase { 35 /// <inheritdoc select="summary"/> 36 public override string Description { 37 get { return @"TODO\r\nOperator description still missing ..."; } 38 } 39 35 /// <remarks> 36 /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms, 37 /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349. 38 /// </remarks> 39 [Item("OrderBasedCrossover", "An operator which performs an order based crossover of two permutations.")] 40 [EmptyStorableClass] 41 [Creatable("Test")] 42 public class OrderBasedCrossover : PermutationCrossover { 40 43 /// <summary> 41 44 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> by … … 43 46 /// other; the missing ones are picked in the correct order from the second permutation. 44 47 /// </summary> 45 /// <param name="random">The random number generator.</param> 46 /// <param name="parent1">The parent scope 1 to cross over.</param> 47 /// <param name="parent2">The parent scope 2 to cross over.</param> 48 /// <returns>The created cross over permutation as int array.</returns> 49 public static int[] Apply(IRandom random, int[] parent1, int[] parent2) { 48 /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception> 49 /// <param name="random">A random number generator.</param> 50 /// <param name="parent1">The first parent permutation to cross.</param> 51 /// <param name="parent2">The second parent permutation to cross.</param> 52 /// <returns>The new permutation resulting from the crossover.</returns> 53 public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { 54 if (parent1.Length != parent2.Length) throw new ArgumentException("OrderBasedCrossover: The parent permutations are of unequal length."); 50 55 int length = parent1.Length; 51 56 int[] result = new int[length]; … … 88 93 } 89 94 } 90 return result;95 return new Permutation(result); 91 96 } 92 97 … … 95 100 /// </summary> 96 101 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 97 /// <param name="scope">The current scope.</param>98 102 /// <param name="random">A random number generator.</param> 99 103 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 100 /// <returns>The new ly created permutation, resulting from the crossover operation.</returns>101 protected override int[] Cross(IScope scope, IRandom random, int[][]parents) {102 if (parents.Length != 2) throw new InvalidOperationException(" ERROR in OrderBasedCrossover: The number of parents is not equal to 2");104 /// <returns>The new permutation resulting from the crossover.</returns> 105 protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) { 106 if (parents.Length != 2) throw new InvalidOperationException("OrderCrossover: Number of parents is not equal to 2."); 103 107 return Apply(random, parents[0], parents[1]); 104 108 } -
trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs
r2835 r2854 34 34 /// in the order they occur. 35 35 /// </remarks> 36 [Item("OrderCrossover", "An operator which performs an order crossover of two permutations as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]36 [Item("OrderCrossover", "An operator which performs an order crossover of two permutations.")] 37 37 [EmptyStorableClass] 38 38 [Creatable("Test")] -
trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs
r2835 r2854 33 33 /// as the original source of the operator. 34 34 /// </remarks> 35 [Item("PartiallyMatchedCrossover", "An operator which performs the partially matched crossover on two permutations as described in Fogel, D.B. 1988. An Evolutionary Approach to the Traveling Salesman Problem. Biological Cybernetics, 60, pp. 139-144, Springer-Verlag.")]35 [Item("PartiallyMatchedCrossover", "An operator which performs the partially matched crossover on two permutations.")] 36 36 [EmptyStorableClass] 37 37 [Creatable("Test")] … … 92 92 /// </summary> 93 93 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two permutations in <paramref name="parents"/>.</exception> 94 /// <param name="scope">The current scope.</param>95 94 /// <param name="random">A random number generator.</param> 96 95 /// <param name="parents">An array containing the two permutations that should be crossed.</param> -
trunk/sources/HeuristicLab.Permutation/3.3/PositionBasedCrossover.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Permutation { … … 30 31 /// Performs a cross over permutation between two permutation arrays based on randomly chosen positions. 31 32 /// </summary> 32 public class PositionBasedCrossover : PermutationCrossoverBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 36 } 37 33 /// <remarks> 34 /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms, 35 /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349. 36 /// </remarks> 37 [Item("PositionBasedCrossover", "An operator which performs the position based crossover on two permutations.")] 38 [EmptyStorableClass] 39 [Creatable("Test")] 40 public class PositionBasedCrossover : PermutationCrossover { 38 41 /// <summary> 39 42 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> 40 43 /// based on randomly chosen positions to define which position to take from where. 41 44 /// </summary> 45 /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception> 42 46 /// <param name="random">The random number generator.</param> 43 /// <param name="parent1">The permutation array of parent 1.</param> 44 /// <param name="parent2">The permutation array of parent 2.</param> 45 /// <returns>The created cross over permutation as int array.</returns> 46 public static int[] Apply(IRandom random, int[] parent1, int[] parent2) { 47 /// <param name="parent1">First parent</param> 48 /// <param name="parent2">Second Parent</param> 49 /// <returns>Child</returns> 50 public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { 51 if (parent1.Length != parent2.Length) throw new ArgumentException("PositionBasedCrossover: The parent permutations are of unequal length."); 47 52 int length = parent1.Length; 48 53 int[] result = new int[length]; … … 74 79 } 75 80 } 76 return result; 81 82 return new Permutation(result); 77 83 } 78 84 … … 81 87 /// </summary> 82 88 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 83 /// <param name="scope">The current scope.</param>84 89 /// <param name="random">A random number generator.</param> 85 90 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 86 91 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 87 protected override int[] Cross(IScope scope, IRandom random, int[][]parents) {92 protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) { 88 93 if (parents.Length != 2) throw new InvalidOperationException("ERROR in PositionBasedCrossover: The number of parents is not equal to 2"); 89 94 return Apply(random, parents[0], parents[1]); -
trunk/sources/HeuristicLab.Permutation/3.3/ScrambleManipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Permutation { … … 29 30 /// Manipulates a permutation array by randomly scrambling the elements in a randomly chosen interval. 30 31 /// </summary> 31 public class ScrambleManipulator : PermutationManipulatorBase { 32 /// <inheritdoc select="summary"/> 33 public override string Description { 34 get { return @"TODO\r\nOperator description still missing ..."; } 35 } 36 32 /// <remarks> 33 /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms, 34 /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349. 35 /// </remarks> 36 [Item("ScrambleManipulator", "An operator which manipulates a permutation array by randomly scrambling the elements in a randomly chosen interval.")] 37 [EmptyStorableClass] 38 [Creatable("Test")] 39 public class ScrambleManipulator : PermutationManipulator { 37 40 /// <summary> 38 41 /// Mixes the elements of the given <paramref name="permutation"/> randomly … … 40 43 /// </summary> 41 44 /// <param name="random">The random number generator.</param> 42 /// <param name="permutation">The permutation arrayto manipulate.</param>43 /// <returns>The new permuation array with the manipulated data.</returns>44 public static int[] Apply(IRandom random, int[] permutation) {45 int[] result = (int[])permutation.Clone(); 45 /// <param name="permutation">The permutation to manipulate.</param> 46 public static void Apply(IRandom random, Permutation permutation) { 47 Permutation original = (Permutation)permutation.Clone(); 48 46 49 int breakPoint1, breakPoint2; 47 50 int[] scrambledIndices, remainingIndices, temp; 48 51 int selectedIndex, index; 49 52 50 breakPoint1 = random.Next( permutation.Length - 1);51 breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);53 breakPoint1 = random.Next(original.Length - 1); 54 breakPoint2 = random.Next(breakPoint1 + 1, original.Length); 52 55 53 56 scrambledIndices = new int[breakPoint2 - breakPoint1 + 1]; … … 73 76 74 77 for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) { // scramble permutation between breakpoints 75 result[breakPoint1 + i] = permutation[breakPoint1 + scrambledIndices[i]];78 permutation[breakPoint1 + i] = original[breakPoint1 + scrambledIndices[i]]; 76 79 } 77 return result;78 80 } 79 81 … … 83 85 /// </summary> 84 86 /// <remarks>Calls <see cref="Apply"/>.</remarks> 85 /// <param name="scope">The current scope.</param> 86 /// <param name="random">The random number generator.</param> 87 /// <param name="permutation">The permutation array to manipulate.</param> 88 /// <returns>The new permuation array with the manipulated data.</returns> 89 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 90 return Apply(random, permutation); 87 /// <param name="random">A random number generator.</param> 88 /// <param name="permutation">The permutation to manipulate.</param> 89 protected override void Manipulate(IRandom random, Permutation permutation) { 90 Apply(random, permutation); 91 91 } 92 92 } -
trunk/sources/HeuristicLab.Permutation/3.3/Swap2Manipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Permutation { … … 29 30 /// Manipulates a permutation array by swapping to randomly chosen elements. 30 31 /// </summary> 31 public class Swap2Manipulator : PermutationManipulatorBase { 32 /// <inheritdoc select="summary"/> 33 public override string Description { 34 get { return @"TODO\r\nOperator description still missing ..."; } 35 } 36 32 /// /// <remarks> 33 /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.<br /> 34 /// </remarks> 35 [Item("Swap2Manipulator", "An operator which manipulates a permutation array by swapping to randomly chosen elements.")] 36 [EmptyStorableClass] 37 [Creatable("Test")] 38 public class Swap2Manipulator : PermutationManipulator { 37 39 /// <summary> 38 /// Swaps two randomly chosen elements in the given <paramref name="permutation"/> array.40 /// Swaps two randomly chosen elements in the given <paramref name="permutation"/> permutation. 39 41 /// </summary> 40 42 /// <param name="random">The random number generator.</param> 41 /// <param name="permutation">The permutation array to manipulate.</param> 42 /// <returns>The new permuation array with the manipulated data.</returns> 43 public static int[] Apply(IRandom random, int[] permutation) { 44 int[] result = (int[])permutation.Clone(); 43 /// <param name="permutation">The permutation to manipulate.</param> 44 public static void Apply(IRandom random, Permutation permutation) { 45 45 int index1, index2, temp; 46 46 47 index1 = random.Next( result.Length);48 index2 = random.Next( result.Length);47 index1 = random.Next(permutation.Length); 48 index2 = random.Next(permutation.Length); 49 49 50 temp = result[index1]; 51 result[index1] = result[index2]; 52 result[index2] = temp; 53 54 return result; 50 temp = permutation[index1]; 51 permutation[index1] = permutation[index2]; 52 permutation[index2] = temp; 55 53 } 56 54 … … 59 57 /// </summary> 60 58 /// <remarks>Calls <see cref="Apply"/>.</remarks> 61 /// <param name="scope">The current scope.</param> 62 /// <param name="random">The random number generator.</param> 63 /// <param name="permutation">The permutation array to manipulate.</param> 64 /// <returns>The new permuation array with the manipulated data.</returns> 65 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 66 return Apply(random, permutation); 59 /// <param name="random">A random number generator.</param> 60 /// <param name="permutation">The permutation to manipulate.</param> 61 protected override void Manipulate(IRandom random, Permutation permutation) { 62 Apply(random, permutation); 67 63 } 68 64 } -
trunk/sources/HeuristicLab.Permutation/3.3/Swap3Manipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Permutation { … … 29 30 /// Manipulates a permutation array by swaping three randomly chosen elements. 30 31 /// </summary> 31 public class Swap3Manipulator : PermutationManipulatorBase { 32 /// <inheritdoc select="summary"/> 33 public override string Description { 34 get { return @"TODO\r\nOperator description still missing ..."; } 35 } 36 32 [Item("Swap3Manipulator", "An operator which manipulates a permutation array by swaping three randomly chosen elements.")] 33 [EmptyStorableClass] 34 [Creatable("Test")] 35 public class Swap3Manipulator : PermutationManipulator { 37 36 /// <summary> 38 37 /// Swaps three randomly chosen elements of the given <paramref name="permutation"/> array. 39 38 /// </summary> 40 39 /// <param name="random">The random number generator.</param> 41 /// <param name="permutation">The permutation array to manipulate.</param> 42 /// <returns>The new permuation array with the manipulated data.</returns> 43 public static int[] Apply(IRandom random, int[] permutation) { 44 int[] result = (int[])permutation.Clone(); 40 /// <param name="permutation">The permutation to manipulate.</param> 41 public static void Apply(IRandom random, Permutation permutation) { 45 42 int index1, index2, index3, temp; 46 43 47 index1 = random.Next( result.Length);48 index2 = random.Next( result.Length);49 index3 = random.Next( result.Length);44 index1 = random.Next(permutation.Length); 45 index2 = random.Next(permutation.Length); 46 index3 = random.Next(permutation.Length); 50 47 51 48 if (random.NextDouble() < 0.5) { 52 49 // swap edges 1 and 2 53 temp = result[index1];54 result[index1] = result[index2];55 result[index2] = temp;50 temp = permutation[index1]; 51 permutation[index1] = permutation[index2]; 52 permutation[index2] = temp; 56 53 // swap edges 2 and 3 57 temp = result[index2];58 result[index2] = result[index3];59 result[index3] = temp;54 temp = permutation[index2]; 55 permutation[index2] = permutation[index3]; 56 permutation[index3] = temp; 60 57 } else { 61 58 // swap edges 1 and 3 62 temp = result[index1];63 result[index1] = result[index3];64 result[index3] = temp;59 temp = permutation[index1]; 60 permutation[index1] = permutation[index3]; 61 permutation[index3] = temp; 65 62 // swap edges 2 and 3 66 temp = result[index2];67 result[index2] = result[index3];68 result[index3] = temp;63 temp = permutation[index2]; 64 permutation[index2] = permutation[index3]; 65 permutation[index3] = temp; 69 66 } 70 return result;71 67 } 72 68 … … 75 71 /// </summary> 76 72 /// <remarks>Calls <see cref="Apply"/>.</remarks> 77 /// <param name="scope">The current scope.</param> 78 /// <param name="random">The random number generator.</param> 79 /// <param name="permutation">The permutation array to manipulate.</param> 80 /// <returns>The new permuation array with the manipulated data.</returns> 81 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 82 return Apply(random, permutation); 73 /// <param name="random">A random number generator.</param> 74 /// <param name="permutation">The permutation to manipulate.</param> 75 protected override void Manipulate(IRandom random, Permutation permutation) { 76 Apply(random, permutation); 83 77 } 84 78 } -
trunk/sources/HeuristicLab.Permutation/3.3/Tests/Auxiliary.cs
r2836 r2854 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; -
trunk/sources/HeuristicLab.Permutation/3.3/Tests/HeuristicLab.Permutation-3.3.Tests.csproj
r2836 r2854 42 42 </ItemGroup> 43 43 <ItemGroup> 44 <Compile Include="AbsolutePositionTopologicalCrossoverTest.cs" /> 44 45 <Compile Include="Auxiliary.cs" /> 46 <Compile Include="CosaCrossoverTest.cs" /> 47 <Compile Include="CyclicCrossoverTest.cs" /> 48 <Compile Include="EdgeRecombinationCrossoverTest.cs" /> 49 <Compile Include="InsertionManipulatorTest.cs" /> 50 <Compile Include="InversionManipulatorTest.cs" /> 51 <Compile Include="MaximalPreservativeCrossoverTest.cs" /> 52 <Compile Include="OrderBasedCrossoverTest.cs" /> 45 53 <Compile Include="OrderCrossoverTest.cs" /> 54 <Compile Include="PartiallyMatchedCrossoverTest.cs" /> 55 <Compile Include="PositionBasedCrossoverTest.cs" /> 46 56 <Compile Include="Properties\AssemblyInfo.cs" /> 47 57 <Compile Include="Random.cs" /> 58 <Compile Include="ScrambleManipulatorTest.cs" /> 59 <Compile Include="Swap2ManipulatorTest.cs" /> 60 <Compile Include="Swap3ManipulatorTest.cs" /> 61 <Compile Include="TranslocationInversionManipulatorTest.cs" /> 62 <Compile Include="TranslocationManipulatorTest.cs" /> 48 63 </ItemGroup> 49 64 <ItemGroup> -
trunk/sources/HeuristicLab.Permutation/3.3/Tests/OrderCrossoverTest.cs
r2840 r2854 1 using HeuristicLab.Permutation; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HeuristicLab.Permutation; 2 23 using Microsoft.VisualStudio.TestTools.UnitTesting; 3 24 using HeuristicLab.Core; … … 68 89 public void OrderCrossoverCrossTest() { 69 90 TestRandom random = new TestRandom(); 70 Permutation parent1, parent2, expected, actual; 71 ItemArray<Permutation> parents; 72 OrderCrossover_Accessor target = new OrderCrossover_Accessor(new PrivateObject(typeof(OrderCrossover))); 73 // The following test is based on an example from Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, pp. 55-56 74 random.Reset(); 75 random.IntNumbers = new int[] { 3, 6 }; 76 parent1 = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); 77 Assert.IsTrue(parent1.Validate()); 78 parent2 = new Permutation(new int[] { 8, 2, 6, 7, 1, 5, 4, 0, 3 }); 79 Assert.IsTrue(parent2.Validate()); 80 parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 }); 81 expected = new Permutation(new int[] { 2, 7, 1, 3, 4, 5, 6, 0, 8 }); 82 Assert.IsTrue(expected.Validate()); 83 actual = target.Cross(random, parents); 84 Assert.IsTrue(actual.Validate()); 85 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 86 // The following test is based on an example from Larranaga, P. et al. 1999. Genetic Algorithms for the Travelling Salesman Problem: A Review of Representations and Operators. Artificial Intelligence Review, 13, pp. 129-170. 87 random.Reset(); 88 random.IntNumbers = new int[] { 2, 4 }; 89 parent1 = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }); 90 Assert.IsTrue(parent1.Validate()); 91 parent2 = new Permutation(new int[] { 1, 3, 5, 7, 6, 4, 2, 0 }); 92 Assert.IsTrue(parent2.Validate()); 93 parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 }); 94 expected = new Permutation(new int[] { 7, 6, 2, 3, 4, 0, 1, 5 }); 95 actual = target.Cross(random, parents); 96 Assert.IsTrue(actual.Validate()); 97 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 98 // The following test is based on an example from Talbi, E.G. 2009. Metaheuristics - From Design to Implementation. Wiley, p. 218. 99 random.Reset(); 100 random.IntNumbers = new int[] { 2, 5 }; 101 parent1 = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); 102 Assert.IsTrue(parent1.Validate()); 103 parent2 = new Permutation(new int[] { 7, 3, 0, 4, 8, 2, 5, 1, 6 }); 104 Assert.IsTrue(parent2.Validate()); 105 parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 }); 106 expected = new Permutation(new int[] { 0, 8, 2, 3, 4, 5, 1, 6, 7 }); 107 Assert.IsTrue(expected.Validate()); 108 actual = target.Cross(random, parents); 109 Assert.IsTrue(actual.Validate()); 110 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 111 // The following test is not based on published examples 112 random.Reset(); 113 random.IntNumbers = new int[] { 0, 5 }; 114 parent1 = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 0, 5, 9 }); 115 Assert.IsTrue(parent1.Validate()); 116 parent2 = new Permutation(new int[] { 5, 3, 4, 0, 9, 8, 2, 7, 1, 6 }); 117 Assert.IsTrue(parent2.Validate()); 118 parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 }); 119 expected = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 5, 0, 9 }); 120 Assert.IsTrue(expected.Validate()); 121 actual = target.Cross(random, parents); 122 Assert.IsTrue(actual.Validate()); 123 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 124 // based on the previous with changed breakpoints 125 random.Reset(); 126 random.IntNumbers = new int[] { 6, 9 }; 127 expected = new Permutation(new int[] { 3, 4, 8, 2, 7, 1, 6, 0, 5, 9 }); 128 Assert.IsTrue(expected.Validate()); 129 actual = target.Cross(random, parents); 130 Assert.IsTrue(actual.Validate()); 131 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 132 // another one based on the previous with changed breakpoints 133 random.Reset(); 134 random.IntNumbers = new int[] { 0, 9 }; 135 expected = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 0, 5, 9 }); 136 Assert.IsTrue(expected.Validate()); 137 actual = target.Cross(random, parents); 138 Assert.IsTrue(actual.Validate()); 139 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 91 OrderCrossover_Accessor target = 92 new OrderCrossover_Accessor(new PrivateObject(typeof(OrderCrossover))); 140 93 // perform a test with more than two parents 141 94 random.Reset(); 142 95 bool exceptionFired = false; 143 96 try { 144 target.Cross(random, new ItemArray<Permutation>(new Permutation[] { new Permutation(4), new Permutation(4), new Permutation(4)})); 97 target.Cross(random, new ItemArray<Permutation>(new Permutation[] { 98 new Permutation(4), new Permutation(4), new Permutation(4)})); 145 99 } catch (System.InvalidOperationException) { 146 exceptionFired = true;147 }148 Assert.IsTrue(exceptionFired);149 // perform a test when two permutations are of unequal length150 random.Reset();151 exceptionFired = false;152 try {153 target.Cross(random, new ItemArray<Permutation>(new Permutation[] { new Permutation(8), new Permutation(6) }));154 } catch (System.ArgumentException) {155 100 exceptionFired = true; 156 101 } -
trunk/sources/HeuristicLab.Permutation/3.3/Tests/Random.cs
r2840 r2854 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; -
trunk/sources/HeuristicLab.Permutation/3.3/TranslocationInversionManipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Operators; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 28 27 29 namespace HeuristicLab.Permutation { … … 30 32 /// (randomly chosen) position in the array. 31 33 /// </summary> 32 public class TranslocationInversionManipulator : PermutationManipulatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 36 } 37 34 /// <remarks> 35 /// It is implemented as described in Fogel, D.B. (1993). Applying Evolutionary Programming to Selected TSP Problems, 36 /// Cybernetics and Systems, 22, pp 27-36.<br /> 37 /// </remarks> 38 [Item("TranslocationInversionManipulator", "An operator which inverts a randomly chosen part of a permutation and inserts it at a random position.")] 39 [EmptyStorableClass] 40 [Creatable("Test")] 41 public class TranslocationInversionManipulator : PermutationManipulator { 38 42 /// <summary> 39 43 /// Moves a randomly chosen interval of elements to another (randomly chosen) position in the given … … 42 46 /// <param name="random">The random number generator.</param> 43 47 /// <param name="permutation">The permutation array to manipulate.</param> 44 /// <returns>The new permuation array with the manipulated data.</returns> 45 public static int[] Apply(IRandom random, int[] permutation) { 46 int[] result = (int[])permutation.Clone(); 48 public static void Apply(IRandom random, Permutation permutation) { 49 Permutation original = (Permutation)permutation.Clone(); 47 50 int breakPoint1, breakPoint2, insertPoint, insertPointLimit; 48 51 49 breakPoint1 = random.Next( permutation.Length - 1);50 breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);51 insertPointLimit = permutation.Length - breakPoint2 + breakPoint1 - 1; // get insertion point in remaining part52 breakPoint1 = random.Next(original.Length - 1); 53 breakPoint2 = random.Next(breakPoint1 + 1, original.Length); 54 insertPointLimit = original.Length - breakPoint2 + breakPoint1 - 1; // get insertion point in remaining part 52 55 if (insertPointLimit > 0) 53 56 insertPoint = random.Next(insertPointLimit); … … 57 60 int i = 0; // index in new permutation 58 61 int j = 0; // index in old permutation 59 while (i < permutation.Length) {62 while (i < original.Length) { 60 63 if (i == insertPoint) { // copy translocated area 61 64 for (int k = breakPoint2; k >= breakPoint1; k--) { 62 result[i] = permutation[k];65 permutation[i] = original[k]; 63 66 i++; 64 67 } … … 67 70 j = breakPoint2 + 1; 68 71 } 69 if ((i < permutation.Length) && (j < permutation.Length)) {70 result[i] = permutation[j];72 if ((i < original.Length) && (j < original.Length)) { 73 permutation[i] = original[j]; 71 74 i++; 72 75 j++; 73 76 } 74 77 } 75 return result;76 78 } 77 79 … … 81 83 /// </summary> 82 84 /// <remarks>Calls <see cref="Apply"/>.</remarks> 83 /// <param name="scope">The current scope.</param> 84 /// <param name="random">The random number generator.</param> 85 /// <param name="permutation">The permutation array to manipulate.</param> 86 /// <returns>The new permuation array with the manipulated data.</returns> 87 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 88 return Apply(random, permutation); 85 /// <param name="random">A random number generator.</param> 86 /// <param name="permutation">The permutation to manipulate.</param> 87 protected override void Manipulate(IRandom random, Permutation permutation) { 88 Apply(random, permutation); 89 89 } 90 90 } -
trunk/sources/HeuristicLab.Permutation/3.3/TranslocationManipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Permutation { … … 30 31 /// (randomly chosen) position in the array. 31 32 /// </summary> 32 public class TranslocationManipulator : PermutationManipulatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 36 } 37 33 /// <remarks> 34 /// It is implemented as described in Michalewicz, Z. (1992), Genetic Algorithms ü Data Structures = Evolution Programs, Springer Verlag, Berlin Heidelberg.<br /> 35 /// </remarks> 36 [Item("TranslocationManipulator", "An operator which Manipulates a permutation array by moving a randomly chosen interval of elements to another (randomly chosen) position in the array.")] 37 [EmptyStorableClass] 38 [Creatable("Test")] 39 public class TranslocationManipulator : PermutationManipulator { 38 40 /// <summary> 39 41 /// Moves a randomly chosen interval of elements to another (randomly chosen) position in the given … … 42 44 /// <param name="random">The random number generator.</param> 43 45 /// <param name="permutation">The permutation array to manipulate.</param> 44 /// <returns>The new permuation array with the manipulated data.</returns> 45 public static int[] Apply(IRandom random, int[] permutation) { 46 int[] result = (int[])permutation.Clone(); 46 public static void Apply(IRandom random, Permutation permutation) { 47 Permutation original = (Permutation)permutation.Clone(); 47 48 int breakPoint1, breakPoint2, insertPoint, insertPointLimit; 48 49 … … 57 58 int i = 0; // index in new permutation 58 59 int j = 0; // index in old permutation 59 while (i < permutation.Length) {60 while (i < original.Length) { 60 61 if (i == insertPoint) { // copy translocated area 61 62 for (int k = breakPoint1; k <= breakPoint2; k++) { 62 result[i] = permutation[k];63 permutation[i] = original[k]; 63 64 i++; 64 65 } … … 67 68 j = breakPoint2 + 1; 68 69 } 69 if ((i < permutation.Length) && (j < permutation.Length)) {70 result[i] = permutation[j];70 if ((i < original.Length) && (j < original.Length)) { 71 permutation[i] = original[j]; 71 72 i++; 72 73 j++; 73 74 } 74 75 } 75 return result;76 76 } 77 77 … … 81 81 /// </summary> 82 82 /// <remarks>Calls <see cref="Apply"/>.</remarks> 83 /// <param name="scope">The current scope.</param> 84 /// <param name="random">The random number generator.</param> 85 /// <param name="permutation">The permutation array to manipulate.</param> 86 /// <returns>The new permuation array with the manipulated data.</returns> 87 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 88 return Apply(random, permutation); 83 /// <param name="random">A random number generator.</param> 84 /// <param name="permutation">The permutation to manipulate.</param> 85 protected override void Manipulate(IRandom random, Permutation permutation) { 86 Apply(random, permutation); 89 87 } 90 88 }
Note: See TracChangeset
for help on using the changeset viewer.