Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/10 20:42:37 (14 years ago)
Author:
abeham
Message:

Implemented CyclicCrossover, updated documentation in MaximalPreservativeCrossover and PartiallyMatchedCrossover #889

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs

    r2823 r2829  
    3333  /// as the original source of the operator.
    3434  /// </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.")]
    3636  [EmptyStorableClass]
    3737  [Creatable("Test")]
     
    4141    /// </summary>
    4242    /// <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>
    4344    /// <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.
    4850    /// </remarks>
    4951    /// <param name="random">A random number generator.</param>
     
    6567
    6668      // 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");
    7076      }
    7177
     
    7379        int orig = result[j]; // save the former value
    7480        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 child
     81        int index = invResult[result[j]]; // look where the new value is in the offspring
    7682        result[index] = orig; // write the former value to this position
    7783        invResult[orig] = index; // update the inverse mapping
     
    8389
    8490    /// <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)"/>.
    8692    /// </summary>
    8793    /// <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.