# Changeset 2835

Ignore:
Timestamp:
02/19/10 09:32:47 (11 years ago)
Message:

fixed doc and exception messages in CX, MPX, and PMX
#889

Location:
trunk/sources/HeuristicLab.Permutation/3.3
Files:
4 edited

Unmodified
Removed
• ## trunk/sources/HeuristicLab.Permutation/3.3/CyclicCrossover.cs

 r2830 /// /// Thrown when and are not of equal length. /// Thrown if the numbers in the permutation elements are not in the range [0,N) with N = length of the permutation. /// Thrown if the numbers in the permutation elements are not in the range [0;N) with N = length of the permutation. /// /// First this method randomly determines from which parent to start with equal probability. /// The created cross over permutation as int array. public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { if (parent1.Length != parent2.Length) throw new ArgumentException("CyclicCrossover: The parent permutations are of unequal length"); if (parent1.Length != parent2.Length) throw new ArgumentException("CyclicCrossover: The parent permutations are of unequal length."); int length = parent1.Length; int[] result = new int[length]; } } catch (IndexOutOfRangeException) { throw new InvalidOperationException("CyclicCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation"); throw new InvalidOperationException("CyclicCrossover: The permutation must consist of numbers in the interval [0;N) with N = length of the permutation."); } /// The newly created permutation, resulting from the crossover operation. protected override Permutation Cross(IRandom random, ItemArray parents) { if (parents.Length != 2) throw new InvalidOperationException("CyclicCrossover: The number of parents is not equal to 2"); if (parents.Length != 2) throw new InvalidOperationException("CyclicCrossover: The number of parents is not equal to 2."); return Apply(random, parents, parents); }
• ## trunk/sources/HeuristicLab.Permutation/3.3/MaximalPreservativeCrossover.cs

 r2830 /// Performs a crossover between two permuation arrays by preserving a large number of edges in both parents. /// The operator also maintains the position in the arrays to some extent. /// It is implemented 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. /// /// The length of the segment copied from the first parent to the offspring is uniformly distributed in the interval [3, N/3) with N = length of the permutation. /// It is implemented 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.

/// The length of the segment copied from the first parent to the offspring is uniformly distributed in the interval [3;N/3) with N = length of the permutation. /// This recommendation is mentioned in Pohlheim, H. 1999. Evolutionäre Algorithmen: Verfahren, Operatoren und Hinweise für die Praxis, p. 44, Springer. /// If the length of the permutation is smaller than 15, the size of the segment is always equal to 3. /// /// Thrown when and are not of equal length or when the permutations are shorter than 4 elements. /// Thrown if the numbers in the permutation elements are not in the range [0,N) with N = length of the permutation. /// Thrown if the numbers in the permutation elements are not in the range [0;N) with N = length of the permutation. /// /// First one segment is copied from the first parent to the offspring in the same position. /// The new permutation resulting from the crossover. public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { if (parent1.Length != parent2.Length) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutations are of unequal length"); if (parent1.Length < 4) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutation must be at least of size 4"); if (parent1.Length != parent2.Length) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutations are of unequal length."); if (parent1.Length < 4) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutation must be at least of size 4."); int length = parent1.Length; int[] result = new int[length]; } } catch (IndexOutOfRangeException) { throw new InvalidOperationException("MaximalPreservativeCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation"); throw new InvalidOperationException("MaximalPreservativeCrossover: The permutation must consist of numbers in the interval [0;N) with N = length of the permutation."); }
• ## trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs

 r2830 namespace HeuristicLab.Permutation { /// /// An operator which performs an order crossover of two permutations. /// An operator which performs the order crossover on two permutations. /// /// /// Crosses two permutations by taking a randomly chosen interval from the frist permutation, preserving /// the positions, and then the missing values from the second permutation in the order they occur in the /// second permutation. /// 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.
/// Crosses two permutations by copying a randomly chosen interval from the first permutation, preserving /// the positions. Then, starting from the end of the copied interval, copies the missing values from the second permutation /// in the order they occur. ///
[Item("OrderCrossover", "An operator which performs an order crossover of two permutations.")] [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.")] [EmptyStorableClass] [Creatable("Test")] /// Performs an order crossover of two permutations. /// /// Thrown when and are not of equal length. /// Thrown if the numbers in the permutation elements are not in the range [0,N) with N = length of the permutation. /// /// Crosses two permutations by copying a randomly chosen interval from the first permutation, preserving /// the positions. Then, starting from the end of the copied interval, copies the missing values from the second permutation /// in the order they occur. /// /// A random number generator. /// The first parent permutation to cross. /// The new permutation resulting from the crossover. public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { int[] result = new int[parent1.Length]; bool[] copied = new bool[result.Length]; if (parent1.Length != parent2.Length) throw new ArgumentException("OrderCrossover: The parent permutations are of unequal length."); int length = parent1.Length; int[] result = new int[length]; bool[] copied = new bool[length]; int breakPoint1 = random.Next(result.Length - 1); int breakPoint2 = random.Next(breakPoint1 + 1, result.Length); int breakPoint1 = random.Next(length - 1); int breakPoint2 = random.Next(breakPoint1 + 1, length); for (int i = breakPoint1; i <= breakPoint2; i++) {  // copy part of first permutation result[i] = parent1[i]; copied[parent1[i]] = true; } try { for (int j = breakPoint1; j <= breakPoint2; j++) {  // copy part of first permutation result[j] = parent1[j]; copied[parent1[j]] = true; } int index = 0; for (int i = 0; i < parent2.Length; i++) {  // copy remaining part of second permutation if (index == breakPoint1) {  // skip already copied part index = breakPoint2 + 1; int index = ((breakPoint2 + 1 >= length) ? (0) : (breakPoint2 + 1)); int i = index; // for moving in parent2 while (index != breakPoint1) { if (!copied[parent2[i]]) { result[index] = parent2[i]; index++; if (index >= length) index = 0; } i++; if (i >= length) i = 0; } if (!copied[parent2[i]]) { result[index] = parent2[i]; index++; } } catch (IndexOutOfRangeException) { throw new InvalidOperationException("OrderCrossover: The permutation must consist of numbers in the interval [0;N) with N = length of the permutation."); } return new Permutation(result); /// The new permutation resulting from the crossover. protected override Permutation Cross(IRandom random, ItemArray parents) { if (parents.Length != 2) throw new InvalidOperationException("Number of parents is not equal to 2."); if (parents.Length != 2) throw new InvalidOperationException("OrderCrossover: Number of parents is not equal to 2."); return Apply(random, parents, parents); }
• ## trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs

 r2830 /// The new permutation resulting from the crossover. public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) { if (parent1.Length != parent2.Length) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutations are of unequal length"); if (parent1.Length < 4) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutation must be at least of size 4"); if (parent1.Length != parent2.Length) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutations are of unequal length."); if (parent1.Length < 4) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutation must be at least of size 4."); int length = parent1.Length; int[] result = new int[length]; } } catch (IndexOutOfRangeException) { throw new InvalidOperationException("PartiallyMatchedCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation"); throw new InvalidOperationException("PartiallyMatchedCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation."); } /// The newly created permutation, resulting from the crossover operation. protected override Permutation Cross(IRandom random, ItemArray parents) { if (parents.Length != 2) throw new InvalidOperationException("PartiallyMatchedCrossover: The number of parents is not equal to 2"); if (parents.Length != 2) throw new InvalidOperationException("PartiallyMatchedCrossover: The number of parents is not equal to 2."); return Apply(random, parents, parents); }
Note: See TracChangeset for help on using the changeset viewer.