Changeset 1218 for trunk/sources/HeuristicLab.Permutation
- Timestamp:
- 02/16/09 01:21:53 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Permutation
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Permutation/AbsolutePositionTopologicalCrossover.cs ¶
r850 r1218 75 75 76 76 /// <summary> 77 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> 78 /// by taking the values from both parents one by one with the same index. 77 /// Performs an absolute position topological crossover operation for two given parent permutations. 79 78 /// </summary> 80 /// < remarks>Calls <see cref="Apply"/>.</remarks>79 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 81 80 /// <param name="scope">The current scope.</param> 82 81 /// <param name="random">A random number generator.</param> 83 /// <param name="parent 1">The parent scope 1 to cross over.</param>84 /// < param name="parent2">The parent scope 2 to cross over.</param>85 /// <returns>The created cross over permutation as int array.</returns>86 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {87 return Apply(random, parent 1, parent2);82 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 83 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 84 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 85 if (parents.Length != 2) throw new InvalidOperationException("ERROR in AbsolutePositionTopologicalCrossover: The number of parents is not equal to 2"); 86 return Apply(random, parents[0], parents[1]); 88 87 } 89 88 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/CosaCrossover.cs ¶
r850 r1218 86 86 87 87 /// <summary> 88 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> 89 /// by taking first the reverse elements of a randomly chosen interval of parent1 90 /// and inserting it in the result at a position specified by the permutation of parent2. 91 /// The remaining elements to be inserted are taken again from parent1 in the forward direction. 88 /// Performs a COSA crossover operation for two given parent permutations. 92 89 /// </summary> 93 /// < remarks>Calls <see cref="Apply"/>.</remarks>90 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 94 91 /// <param name="scope">The current scope.</param> 95 /// <param name="random"> Therandom number generator.</param>96 /// <param name="parent 1">The parent scope 1 to cross over.</param>97 /// < param name="parent2">The parent scope 2 to cross over.</param>98 /// <returns>The created cross over permutation as int array.</returns>99 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {100 return Apply(random, parent 1, parent2);92 /// <param name="random">A random number generator.</param> 93 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 94 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 95 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 96 if (parents.Length != 2) throw new InvalidOperationException("ERROR in CosaCrossover: The number of parents is not equal to 2"); 97 return Apply(random, parents[0], parents[1]); 101 98 } 102 99 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/CyclicCrossover.cs ¶
r850 r1218 80 80 81 81 /// <summary> 82 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> 83 /// by copying a whole cycle starting at a randomly chosen position in parent1 and taking the rest 84 /// from parent2. 82 /// Performs a cyclic crossover operation for two given parent permutations. 85 83 /// </summary> 86 /// < remarks>Calls <see cref="Apply"/>.</remarks>84 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 87 85 /// <param name="scope">The current scope.</param> 88 /// <param name="random"> Therandom number generator.</param>89 /// <param name="parent 1">The parent scope 1 to cross over.</param>90 /// < param name="parent2">The parent scope 2 to cross over.</param>91 /// <returns>The created cross over permutation as int array.</returns>92 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {93 return Apply(random, parent 1, parent2);86 /// <param name="random">A random number generator.</param> 87 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 88 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 89 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 90 if (parents.Length != 2) throw new InvalidOperationException("ERROR in CyclicCrossover: The number of parents is not equal to 2"); 91 return Apply(random, parents[0], parents[1]); 94 92 } 95 93 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/EdgeRecombinationCrossover.cs ¶
r850 r1218 139 139 140 140 /// <summary> 141 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="2"/> 142 /// by calculating the edges of each element. Starts at a randomly chosen position, 143 /// the next element is a neighbour with the least 144 /// number of neighbours, the next again a neighbour and so on. 141 /// Performs an edge recombination crossover operation for two given parent permutations. 145 142 /// </summary> 146 /// <exception cref="InvalidOperationException">Thrown when the permutation lacks a number. 147 /// </exception> 148 /// <remarks>Calls <see cref="Apply"/>.</remarks> 143 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 149 144 /// <param name="scope">The current scope.</param> 150 /// <param name="random"> Therandom number generator.</param>151 /// <param name="parent 1">The parent scope 1 to cross over.</param>152 /// < param name="parent2">The parent scope 2 to cross over.</param>153 /// <returns>The created cross over permutation as int array.</returns>154 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {155 return Apply(random, parent 1, parent2);145 /// <param name="random">A random number generator.</param> 146 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 147 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 148 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 149 if (parents.Length != 2) throw new InvalidOperationException("ERROR in EdgeRecombinationCrossover: The number of parents is not equal to 2"); 150 return Apply(random, parents[0], parents[1]); 156 151 } 157 152 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/MaximalPreservativeCrossover.cs ¶
r850 r1218 78 78 79 79 /// <summary> 80 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> 81 /// by preserving a big randomly chosen region of one permutation and taking the missing ones from the other 82 /// permuation array. 80 /// Performs a maximal preservative crossover operation for two given parent permutations. 83 81 /// </summary> 84 /// < remarks>Calls <see cref="Apply"/>.</remarks>82 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 85 83 /// <param name="scope">The current scope.</param> 86 /// <param name="random"> Therandom number generator.</param>87 /// <param name="parent 1">The permutation array of parent 1.</param>88 /// < param name="parent2">The permutation array of parent 2.</param>89 /// <returns>The created cross over permutation as int array.</returns>90 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {91 return Apply(random, parent 1, parent2);84 /// <param name="random">A random number generator.</param> 85 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 86 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 87 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 88 if (parents.Length != 2) throw new InvalidOperationException("ERROR in MaximalPreservativeCrossover: The number of parents is not equal to 2"); 89 return Apply(random, parents[0], parents[1]); 92 90 } 93 91 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/OrderBasedCrossover.cs ¶
r850 r1218 92 92 93 93 /// <summary> 94 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> by 95 /// randomly selecting some values from the first permutation that will be inserted one after each 96 /// other; the missing ones are picked in the correct order from the second permutation. 94 /// Performs an order-based crossover operation for two given parent permutations. 97 95 /// </summary> 98 /// < remarks>Calls <see cref="Apply"/>.</remarks>96 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 99 97 /// <param name="scope">The current scope.</param> 100 /// <param name="random"> Therandom number generator.</param>101 /// <param name="parent 1">The parent scope 1 to cross over.</param>102 /// < param name="parent2">The parent scope 2 to cross over.</param>103 /// <returns>The created cross over permutation as int array.</returns>104 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {105 return Apply(random, parent 1, parent2);98 /// <param name="random">A random number generator.</param> 99 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 100 /// <returns>The newly 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"); 103 return Apply(random, parents[0], parents[1]); 106 104 } 107 105 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/OrderCrossover.cs ¶
r850 r1218 74 74 75 75 /// <summary> 76 /// Performs a cross over permuation of <paramref name="parent1"/> and <paramref name="parent2"/> 77 /// by taking a randomly chosen interval from <paramref name="parent1"/> and the rest from 78 /// <paramref name="parent2"/>. 76 /// Performs an order crossover operation for two given parent permutations. 79 77 /// </summary> 80 /// < remarks>Calls <see cref="Apply"/>.</remarks>78 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 81 79 /// <param name="scope">The current scope.</param> 82 /// <param name="random"> Therandom number generator.</param>83 /// <param name="parent 1">The parent scope 1 to cross over.</param>84 /// < param name="parent2">The parent scope 2 to cross over.</param>85 /// <returns>The created cross over permutation as int array.</returns>86 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {87 return Apply(random, parent 1, parent2);80 /// <param name="random">A random number generator.</param> 81 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 82 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 83 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 84 if (parents.Length != 2) throw new InvalidOperationException("ERROR in OrderCrossover: The number of parents is not equal to 2"); 85 return Apply(random, parents[0], parents[1]); 88 86 } 89 87 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/PartiallyMatchedCrossover.cs ¶
r850 r1218 87 87 88 88 /// <summary> 89 /// Performs a cross over permuation of <paramref name="parent1"/> and <paramref name="parent2"/> 90 /// by taking a randomly chosen interval from <paramref name="parent1"/>, preserving the position, 91 /// then all positions from <paramref name="parent2"/> which are still free in the child 92 /// (the position is free and the value is "free") 93 /// and then missing ones from <paramref name="parent2"/> in the order they occur 94 /// in <paramref name="parent2"/>. 89 /// Performs a partially matched crossover operation for two given parent permutations. 95 90 /// </summary> 96 /// < remarks>Calls <see cref="Apply"/>.</remarks>91 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 97 92 /// <param name="scope">The current scope.</param> 98 /// <param name="random"> Therandom number generator.</param>99 /// <param name="parent 1">The parent scope 1 to cross over.</param>100 /// < param name="parent2">The parent scope 2 to cross over.</param>101 /// <returns>The created cross over permutation as int array.</returns>102 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {103 return Apply(random, parent 1, parent2);93 /// <param name="random">A random number generator.</param> 94 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 95 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 96 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 97 if (parents.Length != 2) throw new InvalidOperationException("ERROR in PartiallyMatchedCrossover: The number of parents is not equal to 2"); 98 return Apply(random, parents[0], parents[1]); 104 99 } 105 100 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/PermutationCrossoverBase.cs ¶
r850 r1218 28 28 namespace HeuristicLab.Permutation { 29 29 /// <summary> 30 /// Base class for cross over permutations.30 /// Base class for all permutation crossover operators. 31 31 /// </summary> 32 32 public abstract class PermutationCrossoverBase : CrossoverBase { … … 41 41 42 42 /// <summary> 43 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> with 44 /// the given random number generator (<paramref name="random"/>) to create a new 45 /// <paramref name="child"/>. 43 /// Performs a crossover by calling <see cref="Cross(HeuristicLab.Core.IScope, HeuristicLab.Core.IRandom, int[][]"/> 44 /// and adds the created permutation to the current scope. 46 45 /// </summary> 47 /// <exception cref="InvalidOperationException">Thrown when the two permutations have a different48 /// length.</exception>49 /// < remarks>Calls <see cref="Cross(HeuristicLab.Core.IScope, HeuristicLab.Core.IRandom, int[], int[])"/>.</remarks>50 /// <param name="scope">The scope where to get the actual child variable name.</param>51 /// <param name="random">The random number generator.</param>52 /// <param name="parent1">The parent scope 1 to cross over.</param>53 /// <param name="parent2">The parent scope 2 to cross over.</param>54 /// <param name="child">The child scope which to assign the permutated data.</param>55 protected sealed override void Cross(IScope scope, IRandom random, IScope parent1, IScope parent2, IScope child) {56 Permutation perm1 = parent1.GetVariableValue<Permutation>("Permutation", false);57 Permutation perm2 = parent2.GetVariableValue<Permutation>("Permutation", false);46 /// <exception cref="InvalidOperationException">Thrown if the parents have different lengths.</exception> 47 /// <param name="scope">The current scope which represents a new child.</param> 48 /// <param name="random">A random number generator.</param> 49 protected sealed override void Cross(IScope scope, IRandom random) { 50 int[][] parents = new int[scope.SubScopes.Count][]; 51 int length = -1; 52 for (int i = 0; i < scope.SubScopes.Count; i++) { 53 parents[i] = scope.SubScopes[i].GetVariableValue<Permutation>("Permutation", false).Data; 54 if (i == 0) length = parents[i].Length; 55 else if (parents[i].Length != length) throw new InvalidOperationException("ERROR in PermutationCrossoverBase: Cannot apply crossover to permutations of different length"); 56 } 58 57 59 if (perm1.Data.Length != perm2.Data.Length) throw new InvalidOperationException("Cannot apply crossover to permutations of different length."); 60 61 int[] result = Cross(scope, random, perm1.Data, perm2.Data); 62 child.AddVariable(new Variable(scope.TranslateName("Permutation"), new Permutation(result))); 58 int[] result = Cross(scope, random, parents); 59 scope.AddVariable(new Variable(scope.TranslateName("Permutation"), new Permutation(result))); 63 60 } 64 61 65 62 /// <summary> 66 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> with 67 /// the given random number generator (<paramref name="random"/>) . 63 /// Performs a crossover of multiple permutations. 68 64 /// </summary> 69 /// <param name="scope">The scope of the variables.</param> 70 /// <param name="random">The random number generator.</param> 71 /// <param name="parent1">The parent scope 1 to cross over.</param> 72 /// <param name="parent2">The parent scope 2 to cross over.</param> 73 /// <returns>The created cross over permutation as int array.</returns> 74 protected abstract int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2); 65 /// <param name="scope">The current scope.</param> 66 /// <param name="random">A random number generator.</param> 67 /// <param name="parents">An array containing all parent permutations.</param> 68 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 69 protected abstract int[] Cross(IScope scope, IRandom random, int[][] parents); 75 70 } 76 71 } -
TabularUnified trunk/sources/HeuristicLab.Permutation/PositionBasedCrossover.cs ¶
r850 r1218 78 78 79 79 /// <summary> 80 /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> 81 /// based on randomly chosen positions to define which position to take from where. 80 /// Performs a position-based crossover operation for two given parent permutations. 82 81 /// </summary> 83 /// < remarks>Calls <see cref="Apply"/>.</remarks>82 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception> 84 83 /// <param name="scope">The current scope.</param> 85 /// <param name="random"> Therandom number generator.</param>86 /// <param name="parent 1">The permutation array of parent 1.</param>87 /// < param name="parent2">The permutation array of parent 2.</param>88 /// <returns>The created cross over permutation as int array.</returns>89 protected override int[] Cross(IScope scope, IRandom random, int[] parent1, int[] parent2) {90 return Apply(random, parent 1, parent2);84 /// <param name="random">A random number generator.</param> 85 /// <param name="parents">An array containing the two permutations that should be crossed.</param> 86 /// <returns>The newly created permutation, resulting from the crossover operation.</returns> 87 protected override int[] Cross(IScope scope, IRandom random, int[][] parents) { 88 if (parents.Length != 2) throw new InvalidOperationException("ERROR in PositionBasedCrossover: The number of parents is not equal to 2"); 89 return Apply(random, parents[0], parents[1]); 91 90 } 92 91 }
Note: See TracChangeset
for help on using the changeset viewer.