- Timestamp:
- 02/18/10 20:42:37 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs
r2823 r2829 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 .")]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.")] 36 36 [EmptyStorableClass] 37 37 [Creatable("Test")] … … 41 41 /// </summary> 42 42 /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length or when the permutations are shorter than 4 elements.</exception> 43 /// <exception cref="InvalidOperationException">Thrown if the numbers in the permutation elements are not in the range [0,N) with N = length of the permutation.</exception> 43 44 /// <remarks> 44 /// First a segment from the first parent is copied to the offspring. 45 /// Then the rest of the offspring is filled with the numbers from parent2. 46 /// When a number is encountered in parent2 that is included in the segment which came from the first parent, 47 /// the number in parent2 is used that was replaced by the corresponding number from parent1. 45 /// Initially the new offspring is a clone of <paramref name="parent2"/>. 46 /// Then a segment is extracted from <paramref name="parent1"/> and copied to the offspring position by position. 47 /// Whenever a position is copied, the number at that position currently in the offspring is transfered to the position where the copied number has been. 48 /// E.g.: Position 15 is selected to be copied from <paramref name="parent1"/> to <paramref name="parent2"/>. At position 15 there is a '3' in <paramref name="parent1"/> and a '5' in the new offspring. 49 /// The '5' in the offspring is then moved to replace the '3' in the offspring and '3' is written at position 15. 48 50 /// </remarks> 49 51 /// <param name="random">A random number generator.</param> … … 65 67 66 68 // clone parent2 and calculate inverse permutation (number -> index) 67 for (int j = 0; j < length; j++) { 68 result[j] = parent2[j]; 69 invResult[result[j]] = j; 69 try { 70 for (int j = 0; j < length; j++) { 71 result[j] = parent2[j]; 72 invResult[result[j]] = j; 73 } 74 } catch (IndexOutOfRangeException) { 75 throw new InvalidOperationException("PartiallyMatchedCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation"); 70 76 } 71 77 … … 73 79 int orig = result[j]; // save the former value 74 80 result[j] = parent1[j]; // overwrite the former value with the new value 75 int index = invResult[result[j]]; // look where the new value is in the child81 int index = invResult[result[j]]; // look where the new value is in the offspring 76 82 result[index] = orig; // write the former value to this position 77 83 invResult[orig] = index; // update the inverse mapping … … 83 89 84 90 /// <summary> 85 /// Checks number of parents and calls <see cref="Apply "/>.91 /// Checks number of parents and calls <see cref="Apply(Apply(IRandom, Permutation, Permutation)"/>. 86 92 /// </summary> 87 93 /// <exception cref="InvalidOperationException">Thrown if there are not exactly two permutations in <paramref name="parents"/>.</exception>
Note: See TracChangeset
for help on using the changeset viewer.