Changeset 2835


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

fixed doc and exception messages in CX, MPX, and PMX
adapted OX to referenced description
#889

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

Legend:

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

    r2830 r2835  
    3939    /// </summary>
    4040    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
    41     /// <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>
     41    /// <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>
    4242    /// <remarks>
    4343    /// First this method randomly determines from which parent to start with equal probability.
     
    5252    /// <returns>The created cross over permutation as int array.</returns>
    5353    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
    54       if (parent1.Length != parent2.Length) throw new ArgumentException("CyclicCrossover: The parent permutations are of unequal length");
     54      if (parent1.Length != parent2.Length) throw new ArgumentException("CyclicCrossover: The parent permutations are of unequal length.");
    5555      int length = parent1.Length;
    5656      int[] result = new int[length];
     
    6666        }
    6767      } catch (IndexOutOfRangeException) {
    68         throw new InvalidOperationException("CyclicCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation");
     68        throw new InvalidOperationException("CyclicCrossover: The permutation must consist of numbers in the interval [0;N) with N = length of the permutation.");
    6969      }
    7070
     
    101101    /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    102102    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    103       if (parents.Length != 2) throw new InvalidOperationException("CyclicCrossover: The number of parents is not equal to 2");
     103      if (parents.Length != 2) throw new InvalidOperationException("CyclicCrossover: The number of parents is not equal to 2.");
    104104      return Apply(random, parents[0], parents[1]);
    105105    }
  • trunk/sources/HeuristicLab.Permutation/3.3/MaximalPreservativeCrossover.cs

    r2830 r2835  
    2929  /// Performs a crossover between two permuation arrays by preserving a large number of edges in both parents.
    3030  /// The operator also maintains the position in the arrays to some extent.
    31   /// 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.
    32   ///
    33   /// 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.
     31  /// 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.<br /><br />
     32  /// 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.
    3433  /// This recommendation is mentioned in Pohlheim, H. 1999. Evolutionäre Algorithmen: Verfahren, Operatoren und Hinweise für die Praxis, p. 44, Springer.
    3534  /// If the length of the permutation is smaller than 15, the size of the segment is always equal to 3.
     
    4443    /// </summary>
    4544    /// <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>
    46     /// <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>
     45    /// <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>
    4746    /// <remarks>
    4847    /// First one segment is copied from the first parent to the offspring in the same position.
     
    5655    /// <returns>The new permutation resulting from the crossover.</returns>
    5756    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
    58       if (parent1.Length != parent2.Length) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutations are of unequal length");
    59       if (parent1.Length < 4) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutation must be at least of size 4");
     57      if (parent1.Length != parent2.Length) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutations are of unequal length.");
     58      if (parent1.Length < 4) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutation must be at least of size 4.");
    6059      int length = parent1.Length;
    6160      int[] result = new int[length];
     
    8685        }
    8786      } catch (IndexOutOfRangeException) {
    88         throw new InvalidOperationException("MaximalPreservativeCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation");
     87        throw new InvalidOperationException("MaximalPreservativeCrossover: The permutation must consist of numbers in the interval [0;N) with N = length of the permutation.");
    8988      }
    9089
  • trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs

    r2830 r2835  
    2626namespace HeuristicLab.Permutation {
    2727  /// <summary>
    28   /// An operator which performs an order crossover of two permutations.
     28  /// An operator which performs the order crossover on two permutations.
    2929  /// </summary>
    3030  /// <remarks>
    31   /// Crosses two permutations by taking a randomly chosen interval from the frist permutation, preserving
    32   /// the positions, and then the missing values from the second permutation in the order they occur in the
    33   /// second permutation.
     31  /// 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 />
     32  /// Crosses two permutations by copying a randomly chosen interval from the first permutation, preserving
     33  /// the positions. Then, starting from the end of the copied interval, copies the missing values from the second permutation
     34  /// in the order they occur.
    3435  /// </remarks>
    35   [Item("OrderCrossover", "An operator which performs an order crossover of two permutations.")]
     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.")]
    3637  [EmptyStorableClass]
    3738  [Creatable("Test")]
     
    4041    /// Performs an order crossover of two permutations.
    4142    /// </summary>
     43    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
     44    /// <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>
     45    /// <remarks>
     46    /// Crosses two permutations by copying a randomly chosen interval from the first permutation, preserving
     47    /// the positions. Then, starting from the end of the copied interval, copies the missing values from the second permutation
     48    /// in the order they occur.
     49    /// </remarks>
    4250    /// <param name="random">A random number generator.</param>
    4351    /// <param name="parent1">The first parent permutation to cross.</param>
     
    4553    /// <returns>The new permutation resulting from the crossover.</returns>
    4654    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
    47       int[] result = new int[parent1.Length];
    48       bool[] copied = new bool[result.Length];
     55      if (parent1.Length != parent2.Length) throw new ArgumentException("OrderCrossover: The parent permutations are of unequal length.");
     56      int length = parent1.Length;
     57      int[] result = new int[length];
     58      bool[] copied = new bool[length];
    4959
    50       int breakPoint1 = random.Next(result.Length - 1);
    51       int breakPoint2 = random.Next(breakPoint1 + 1, result.Length);
     60      int breakPoint1 = random.Next(length - 1);
     61      int breakPoint2 = random.Next(breakPoint1 + 1, length);
    5262
    53       for (int i = breakPoint1; i <= breakPoint2; i++) {  // copy part of first permutation
    54         result[i] = parent1[i];
    55         copied[parent1[i]] = true;
    56       }
     63      try {
     64        for (int j = breakPoint1; j <= breakPoint2; j++) {  // copy part of first permutation
     65          result[j] = parent1[j];
     66          copied[parent1[j]] = true;
     67        }
    5768
    58       int index = 0;
    59       for (int i = 0; i < parent2.Length; i++) {  // copy remaining part of second permutation
    60         if (index == breakPoint1) {  // skip already copied part
    61           index = breakPoint2 + 1;
     69        int index = ((breakPoint2 + 1 >= length) ? (0) : (breakPoint2 + 1));
     70        int i = index; // for moving in parent2
     71        while (index != breakPoint1) {
     72          if (!copied[parent2[i]]) {
     73            result[index] = parent2[i];
     74            index++;
     75            if (index >= length) index = 0;
     76          }
     77          i++;
     78          if (i >= length) i = 0;
    6279        }
    63         if (!copied[parent2[i]]) {
    64           result[index] = parent2[i];
    65           index++;
    66         }
     80      } catch (IndexOutOfRangeException) {
     81        throw new InvalidOperationException("OrderCrossover: The permutation must consist of numbers in the interval [0;N) with N = length of the permutation.");
    6782      }
    6883      return new Permutation(result);
     
    7792    /// <returns>The new permutation resulting from the crossover.</returns>
    7893    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    79       if (parents.Length != 2) throw new InvalidOperationException("Number of parents is not equal to 2.");
     94      if (parents.Length != 2) throw new InvalidOperationException("OrderCrossover: Number of parents is not equal to 2.");
    8095      return Apply(random, parents[0], parents[1]);
    8196    }
  • trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs

    r2830 r2835  
    5454    /// <returns>The new permutation resulting from the crossover.</returns>
    5555    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
    56       if (parent1.Length != parent2.Length) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutations are of unequal length");
    57       if (parent1.Length < 4) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutation must be at least of size 4");
     56      if (parent1.Length != parent2.Length) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutations are of unequal length.");
     57      if (parent1.Length < 4) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutation must be at least of size 4.");
    5858      int length = parent1.Length;
    5959      int[] result = new int[length];
     
    7373        }
    7474      } 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");
     75        throw new InvalidOperationException("PartiallyMatchedCrossover: The permutation must consist of consecutive numbers from 0 to N-1 with N = length of the permutation.");
    7676      }
    7777
     
    9797    /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    9898    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    99       if (parents.Length != 2) throw new InvalidOperationException("PartiallyMatchedCrossover: The number of parents is not equal to 2");
     99      if (parents.Length != 2) throw new InvalidOperationException("PartiallyMatchedCrossover: The number of parents is not equal to 2.");
    100100      return Apply(random, parents[0], parents[1]);
    101101    }
Note: See TracChangeset for help on using the changeset viewer.