Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/24/10 10:01:26 (15 years ago)
Author:
svonolfe
Message:

Ported ported permutation operators to HL 3.3 and added test cases (#889)

Location:
trunk/sources/HeuristicLab.Permutation/3.3
Files:
15 added
21 edited

Legend:

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

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Permutation {
     
    3233  /// (minding already inserted values).
    3334  /// </summary>
     35  /// <remarks>It is implemented as described in Moraglio, A. and Poli, R. 2005. Topological crossover for the permutation representation. In Proceedings of the 2005 Workshops on Genetic and Evolutionary Computation.<br />
     36  /// </remarks>
    3437  /// <example>First take the value at position 0 from parent1 then take the value at position 0
    3538  /// from parent2 if it has not already been inserted, afterwards take the value at position 1 from
    3639  /// parent1 if it has not already been inserted, then from parent2 and so on.</example>
    37   public class AbsolutePositionTopologicalCrossover : PermutationCrossoverBase {
    38     /// <inheritdoc select="summary"/>
    39     public override string Description {
    40       get { return @"TODO\r\nOperator description still missing ..."; }
    41     }
    42 
     40  [Item("AbsolutePositionTopologicalCrossover", @"An operator which performs a cross over permutation between two permutation arrays by taking the
     41entries with the same index (starting at position 0) from both parents
     42(minding already inserted values).")]
     43  [EmptyStorableClass]
     44  [Creatable("Test")]
     45  public class AbsolutePositionTopologicalCrossover : PermutationCrossover {
    4346    /// <summary>
    4447    /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/>
     
    4851    /// from parent2 if it has not already been inserted, afterwards take the value at position 1 from
    4952    /// parent1 if it has not already been inserted, then from parent2 and so on.</example>
    50     /// <param name="random">A random number generator.</param>
     53    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
     54    /// <param name="random">The random number generator.</param>
    5155    /// <param name="parent1">The parent scope 1 to cross over.</param>
    5256    /// <param name="parent2">The parent scope 2 to cross over.</param>
    5357    /// <returns>The created cross over permutation as int array.</returns>
    54     public static int[] Apply(IRandom random, int[] parent1, int[] parent2) {
     58    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
     59      if (parent1.Length != parent2.Length) throw new ArgumentException("AbsolutePositionTopologicalCrossover: The parent permutations are of unequal length.");
    5560      int length = parent1.Length;
    5661      int[] result = new int[length];
     
    7176        }
    7277      }
    73       return result;
     78      return new Permutation(result);
    7479    }
    7580
     
    7883    /// </summary>
    7984    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    80     /// <param name="scope">The current scope.</param>
    8185    /// <param name="random">A random number generator.</param>
    8286    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
    8387    /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    84     protected override int[] Cross(IScope scope, IRandom random, int[][] parents) {
     88    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    8589      if (parents.Length != 2) throw new InvalidOperationException("ERROR in AbsolutePositionTopologicalCrossover: The number of parents is not equal to 2");
    8690      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Permutation/3.3/CosaCrossover.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Permutation {
    2930  /// <summary>
    30   /// Performs a cross over permutation between two permutation arrays by taking randomly chosen
     31  /// Performs a crossover operation between two permutation arrays by taking randomly chosen
    3132  /// reverse and forward intervals from the first permutation array inserting
    3233  /// it in the child on different positions depending on the second permutation array.
    3334  /// </summary>
    34   public class CosaCrossover : PermutationCrossoverBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get { return @"TODO\r\nOperator description still missing ..."; }
    38     }
    39 
     35  [Item("CosaCrossover", "An operator which performs a crossover operation between two permutation arrays by taking randomly chosen reverse and forward intervals from the first permutation array inserting it in the child on different positions depending on the second permutation array.")]
     36  [EmptyStorableClass]
     37  [Creatable("Test")]
     38  public class CosaCrossover : PermutationCrossover {
    4039    /// <summary>
    4140    /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/>
     
    4443    /// The remaining elements to be inserted are taken again from parent1 in the forward direction.
    4544    /// </summary>
     45    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
    4646    /// <param name="random">The random number generator.</param>
    4747    /// <param name="parent1">The parent scope 1 to cross over.</param>
    4848    /// <param name="parent2">The parent scope 2 to cross over.</param>
    4949    /// <returns>The created cross over permutation as int array.</returns>
    50     public static int[] Apply(IRandom random, int[] parent1, int[] parent2) {
     50    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
     51      if (parent1.Length != parent2.Length) throw new ArgumentException("CosaCrossover: The parent permutations are of unequal length.");
    5152      int length = parent1.Length;
    5253      int[] result = new int[length];
     
    8283      }
    8384      result[j] = parent1[crossPoint];  // last station: crosspoint
    84       return result;
     85      return new Permutation(result);
    8586    }
    8687
     
    8990    /// </summary>
    9091    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    91     /// <param name="scope">The current scope.</param>
    9292    /// <param name="random">A random number generator.</param>
    9393    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
    9494    /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    95     protected override int[] Cross(IScope scope, IRandom random, int[][] parents) {
     95    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    9696      if (parents.Length != 2) throw new InvalidOperationException("ERROR in CosaCrossover: The number of parents is not equal to 2");
    9797      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Permutation/3.3/CyclicCrossover.cs

    r2835 r2854  
    3131  /// The operator first determines all cycles in the permutation and then composes the offspring by alternating between the cycles of the two parents.
    3232  /// </remarks>
    33   [Item("CyclicCrossover", "An operator which performs the cyclic crossover on two permutations as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]
     33  [Item("CyclicCrossover", "An operator which performs the cyclic crossover on two permutations.")]
    3434  [EmptyStorableClass]
    3535  [Creatable("Test")]
     
    4747    /// The stochasticity of this operator is rather low. There are only two possible outcomes for a given pair of parents.
    4848    /// </remarks>
     49    /// <exception cref="ArgumentException">Thrown if the two parents are not of equal length.</exception>
    4950    /// <param name="random">The random number generator.</param>
    5051    /// <param name="parent1">The parent scope 1 to cross over.</param>
     
    7778          if (copyFromParent1) {
    7879            result[j] = parent1[j]; // copy number at position j from parent1
     80            indexCopied[j] = true;
    7981            j = invParent2[result[j]]; // set position j to the position of the copied number in parent2
    8082          } else {
    8183            result[j] = parent2[j]; // copy number at position j from parent2
     84            indexCopied[j] = true;
    8285            j = invParent1[result[j]]; // set position j to the position of the copied number in parent1
    8386          }
    84           indexCopied[j] = true;
    8587        } while (!indexCopied[j]);
    8688        copyFromParent1 = !copyFromParent1;
     
    9698    /// </summary>
    9799    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    98     /// <param name="scope">The current scope.</param>
    99100    /// <param name="random">A random number generator.</param>
    100101    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
  • trunk/sources/HeuristicLab.Permutation/3.3/EdgeRecombinationCrossover.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Permutation {
     
    3233  /// number of neighbours, the next again a neighbour and so on.
    3334  /// </summary>
    34   public class EdgeRecombinationCrossover : PermutationCrossoverBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get { return @"TODO\r\nOperator description still missing ..."; }
    38     }
    39 
     35  ///   /// <remarks>It is implemented as described in Whitley et.al. 1991, The Traveling Salesman and Sequence Scheduling, in Davis, L. (Ed.), Handbook ov Genetic Algorithms, New York, pp. 350-372<br />
     36  /// The operator first determines all cycles in the permutation and then composes the offspring by alternating between the cycles of the two parents.
     37  /// </remarks>
     38  [Item("EdgeRecombinationCrossover", "An operator which performs the edge recombination crossover on two permutations.")]
     39  [EmptyStorableClass]
     40  [Creatable("Test")]
     41  public class EdgeRecombinationCrossover : PermutationCrossover {
    4042    /// <summary>
    4143    /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="2"/>
     
    4446    /// number of neighbours, the next again a neighbour and so on.
    4547    /// </summary>
     48    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
    4649    /// <exception cref="InvalidOperationException">Thrown when the permutation lacks a number.
    4750    /// </exception>
     
    5053    /// <param name="parent2">The parent scope 2 to cross over.</param>
    5154    /// <returns>The created cross over permutation as int array.</returns>
    52     public static int[] Apply(IRandom random, int[] parent1, int[] parent2) {
     55    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
     56      if (parent1.Length != parent2.Length) throw new ArgumentException("EdgeRecombinationCrossover: The parent permutations are of unequal length.");
    5357      int length = parent1.Length;
    5458      int[] result = new int[length];
     
    135139        }
    136140      }
    137       return result;
     141      return new Permutation(result);
    138142    }
    139143
     
    142146    /// </summary>
    143147    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    144     /// <param name="scope">The current scope.</param>
    145148    /// <param name="random">A random number generator.</param>
    146149    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
    147150    /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    148     protected override int[] Cross(IScope scope, IRandom random, int[][] parents) {
     151    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    149152      if (parents.Length != 2) throw new InvalidOperationException("ERROR in EdgeRecombinationCrossover: The number of parents is not equal to 2");
    150153      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Permutation/3.3/HeuristicLab.Permutation-3.3.csproj

    r2852 r2854  
    8282  <ItemGroup>
    8383    <None Include="HeuristicLabPermutationPlugin.cs.frame" />
     84    <Compile Include="AbsolutePositionTopologicalCrossover.cs" />
     85    <Compile Include="CosaCrossover.cs" />
    8486    <Compile Include="CyclicCrossover.cs" />
     87    <Compile Include="EdgeRecombinationCrossover.cs" />
     88    <Compile Include="InsertionManipulator.cs" />
    8589    <Compile Include="InversionManipulator.cs">
    8690      <SubType>Code</SubType>
    8791    </Compile>
    8892    <Compile Include="MaximalPreservativeCrossover.cs" />
     93    <Compile Include="OrderBasedCrossover.cs" />
    8994    <Compile Include="PartiallyMatchedCrossover.cs" />
    9095    <Compile Include="PermutationManipulator.cs" />
     
    9398    <Compile Include="PermutationCrossover.cs" />
    9499    <Compile Include="Permutation.cs" />
     100    <Compile Include="PositionBasedCrossover.cs" />
    95101    <Compile Include="Properties\AssemblyInfo.cs" />
    96102    <Compile Include="RandomPermutationCreator.cs" />
     103    <Compile Include="ScrambleManipulator.cs" />
     104    <Compile Include="Swap2Manipulator.cs" />
     105    <Compile Include="Swap3Manipulator.cs" />
     106    <Compile Include="TranslocationInversionManipulator.cs" />
     107    <Compile Include="TranslocationManipulator.cs" />
    97108  </ItemGroup>
    98109  <ItemGroup>
  • trunk/sources/HeuristicLab.Permutation/3.3/InsertionManipulator.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Text;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Permutation {
    2829  /// <summary>
    2930  /// Manipulates a permutation array by moving randomly one element to another position in the array.
    30   /// </summary>
    31   public class InsertionManipulator : PermutationManipulatorBase {
    32     /// <inheritdoc select="summary"/>
    33     public override string Description {
    34       get { return @"TODO\r\nOperator description still missing ..."; }
    35     }
    36 
     31  /// </summary>
     32  /// <remarks>
     33  /// It is implemented as described in Fogel, D.B. (1988). An Evolutionary Approach to the Traveling Salesman Problem, Biological Cybernetics, 60, pp. 139-144
     34  /// </remarks>
     35  [Item("InsertionManipulator", "An operator which moves randomly one element to another position in the permutation.")]
     36  [EmptyStorableClass]
     37  [Creatable("Test")]
     38  public class InsertionManipulator : PermutationManipulator {
    3739    /// <summary>
    3840    /// Moves an randomly chosen element in the specified <paramref name="permutation"/> array
     
    4042    /// </summary>
    4143    /// <param name="random">The random number generator.</param>
    42     /// <param name="permutation">The array to manipulate.</param>
    43     /// <returns>The new permuation array with the manipulated data.</returns>
    44     public static int[] Apply(IRandom random, int[] permutation) {
    45       int[] result = (int[])permutation.Clone();
     44    /// <param name="permutation">The permutation to manipulate.</param>
     45    public static void Apply(IRandom random, Permutation permutation) {
     46      Permutation original = (Permutation)permutation.Clone();
    4647      int cutIndex, insertIndex, number;
    4748
    48       cutIndex = random.Next(permutation.Length);
    49       insertIndex = random.Next(permutation.Length);
    50       number = permutation[cutIndex];
     49      cutIndex = random.Next(original.Length);
     50      insertIndex = random.Next(original.Length);
     51      number = original[cutIndex];
    5152
    5253      int i = 0;  // index in new permutation
    5354      int j = 0;  // index in old permutation
    54       while (i < permutation.Length) {
     55      while (i < original.Length) {
    5556        if (j == cutIndex) {
    5657          j++;
    5758        }
    5859        if (i == insertIndex) {
    59           result[i] = number;
     60          permutation[i] = number;
    6061          i++;
    6162        }
    62         if ((i < permutation.Length) && (j < permutation.Length)) {
    63           result[i] = permutation[j];
     63        if ((i < original.Length) && (j < original.Length)) {
     64          permutation[i] = original[j];
    6465          i++;
    6566          j++;
    6667        }
    6768      }
    68       return result;
    6969    }
    7070
     
    7474    /// </summary>
    7575    /// <remarks>Calls <see cref="Apply"/>.</remarks>
    76     /// <param name="scope">The current scope.</param>
    77     /// <param name="random">The random number generator.</param>
    78     /// <param name="permutation">The array to manipulate.</param>
    79     /// <returns>The new permuation array with the manipulated data.</returns>
    80     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
    81       return Apply(random, permutation);
     76    /// <param name="random">A random number generator.</param>
     77    /// <param name="permutation">The permutation to manipulate.</param>
     78    protected override void Manipulate(IRandom random, Permutation permutation) {
     79      Apply(random, permutation);
    8280    }
    8381  }
  • trunk/sources/HeuristicLab.Permutation/3.3/InversionManipulator.cs

    r2830 r2854  
    2727  /// An operator which inverts a randomly chosen part of a permutation.
    2828  /// </summary>
     29  /// <remarks>
     30  /// 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 />
     31  /// </remarks>
    2932  [Item("InversionManipulator", "An operator which inverts a randomly chosen part of a permutation.")]
    3033  [EmptyStorableClass]
     
    3639    /// <param name="random">A random number generator.</param>
    3740    /// <param name="permutation">The permutation to manipulate.</param>
    38     /// <returns>The new manipulated permutation.</returns>
    3941    public static void Apply(IRandom random, Permutation permutation) {
    4042      int breakPoint1, breakPoint2;
     
    5860    /// <param name="random">A random number generator.</param>
    5961    /// <param name="permutation">The permutation to manipulate.</param>
    60     /// <returns>The new manipulated permuation.</returns>
    6162    protected override void Manipulate(IRandom random, Permutation permutation) {
    6263      Apply(random, permutation);
  • trunk/sources/HeuristicLab.Permutation/3.3/MaximalPreservativeCrossover.cs

    r2835 r2854  
    3434  /// If the length of the permutation is smaller than 15, the size of the segment is always equal to 3.
    3535  /// </remarks>
    36   [Item("MaximalPreservativeCrossover", "An operator which performs the maximal preservative crossover on two permutations 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.")]
     36  [Item("MaximalPreservativeCrossover", "An operator which performs the maximal preservative crossover on two permutations.")]
    3737  [EmptyStorableClass]
    3838  [Creatable("Test")]
     
    131131    /// </summary>
    132132    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two permutations in <paramref name="parents"/>.</exception>
    133     /// <param name="scope">The current scope.</param>
    134133    /// <param name="random">A random number generator.</param>
    135134    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
  • trunk/sources/HeuristicLab.Permutation/3.3/OrderBasedCrossover.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Permutation {
     
    3233  /// the missing entries with the elements from the second permutation, also in the right order.
    3334  /// </summary>
    34   public class OrderBasedCrossover : PermutationCrossoverBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get { return @"TODO\r\nOperator description still missing ..."; }
    38     }
    39 
     35  /// <remarks>
     36  /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms,
     37  /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349.
     38  /// </remarks>
     39  [Item("OrderBasedCrossover", "An operator which performs an order based crossover of two permutations.")]
     40  [EmptyStorableClass]
     41  [Creatable("Test")]
     42  public class OrderBasedCrossover : PermutationCrossover {
    4043    /// <summary>
    4144    /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/> by
     
    4346    /// other; the missing ones are picked in the correct order from the second permutation.
    4447    /// </summary>
    45     /// <param name="random">The random number generator.</param>
    46     /// <param name="parent1">The parent scope 1 to cross over.</param>
    47     /// <param name="parent2">The parent scope 2 to cross over.</param>
    48     /// <returns>The created cross over permutation as int array.</returns>
    49     public static int[] Apply(IRandom random, int[] parent1, int[] parent2) {
     48    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
     49    /// <param name="random">A random number generator.</param>
     50    /// <param name="parent1">The first parent permutation to cross.</param>
     51    /// <param name="parent2">The second parent permutation to cross.</param>
     52    /// <returns>The new permutation resulting from the crossover.</returns>
     53    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
     54      if (parent1.Length != parent2.Length) throw new ArgumentException("OrderBasedCrossover: The parent permutations are of unequal length.");
    5055      int length = parent1.Length;
    5156      int[] result = new int[length];
     
    8893        }
    8994      }
    90       return result;
     95      return new Permutation(result);
    9196    }
    9297
     
    95100    /// </summary>
    96101    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    97     /// <param name="scope">The current scope.</param>
    98102    /// <param name="random">A random number generator.</param>
    99103    /// <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");
     104    /// <returns>The new permutation resulting from the crossover.</returns>
     105    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
     106      if (parents.Length != 2) throw new InvalidOperationException("OrderCrossover: Number of parents is not equal to 2.");
    103107      return Apply(random, parents[0], parents[1]);
    104108    }
  • trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs

    r2835 r2854  
    3434  /// in the order they occur.
    3535  /// </remarks>
    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.")]
     36  [Item("OrderCrossover", "An operator which performs an order crossover of two permutations.")]
    3737  [EmptyStorableClass]
    3838  [Creatable("Test")]
  • trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs

    r2835 r2854  
    3333  /// as the original source of the operator.
    3434  /// </remarks>
    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.")]
     35  [Item("PartiallyMatchedCrossover", "An operator which performs the partially matched crossover on two permutations.")]
    3636  [EmptyStorableClass]
    3737  [Creatable("Test")]
     
    9292    /// </summary>
    9393    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two permutations in <paramref name="parents"/>.</exception>
    94     /// <param name="scope">The current scope.</param>
    9594    /// <param name="random">A random number generator.</param>
    9695    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
  • trunk/sources/HeuristicLab.Permutation/3.3/PositionBasedCrossover.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Permutation {
     
    3031  /// Performs a cross over permutation between two permutation arrays based on randomly chosen positions.
    3132  /// </summary>
    32   public class PositionBasedCrossover : PermutationCrossoverBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
    36     }
    37 
     33  /// <remarks>
     34  /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms,
     35  /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349.
     36  /// </remarks>
     37  [Item("PositionBasedCrossover", "An operator which performs the position based crossover on two permutations.")]
     38  [EmptyStorableClass]
     39  [Creatable("Test")]
     40  public class PositionBasedCrossover : PermutationCrossover {
    3841    /// <summary>
    3942    /// Performs a cross over permutation of <paramref name="parent1"/> and <paramref name="parent2"/>
    4043    /// based on randomly chosen positions to define which position to take from where.
    4144    /// </summary>
     45    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are not of equal length.</exception>
    4246    /// <param name="random">The random number generator.</param>
    43     /// <param name="parent1">The permutation array of parent 1.</param>
    44     /// <param name="parent2">The permutation array of parent 2.</param>
    45     /// <returns>The created cross over permutation as int array.</returns>
    46     public static int[] Apply(IRandom random, int[] parent1, int[] parent2) {
     47    /// <param name="parent1">First parent</param>
     48    /// <param name="parent2">Second Parent</param>
     49    /// <returns>Child</returns>
     50    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
     51      if (parent1.Length != parent2.Length) throw new ArgumentException("PositionBasedCrossover: The parent permutations are of unequal length.");
    4752      int length = parent1.Length;
    4853      int[] result = new int[length];
     
    7479        }
    7580      }
    76       return result;
     81
     82      return new Permutation(result);
    7783    }
    7884
     
    8187    /// </summary>
    8288    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    83     /// <param name="scope">The current scope.</param>
    8489    /// <param name="random">A random number generator.</param>
    8590    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
    8691    /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    87     protected override int[] Cross(IScope scope, IRandom random, int[][] parents) {
     92    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
    8893      if (parents.Length != 2) throw new InvalidOperationException("ERROR in PositionBasedCrossover: The number of parents is not equal to 2");
    8994      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Permutation/3.3/ScrambleManipulator.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Text;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Permutation {
     
    2930  /// Manipulates a permutation array by randomly scrambling the elements in a randomly chosen interval.
    3031  /// </summary>
    31   public class ScrambleManipulator : PermutationManipulatorBase {
    32     /// <inheritdoc select="summary"/>
    33     public override string Description {
    34       get { return @"TODO\r\nOperator description still missing ..."; }
    35     }
    36 
     32  /// <remarks>
     33  /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms,
     34  /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349.
     35  /// </remarks>
     36  [Item("ScrambleManipulator", "An operator which manipulates a permutation array by randomly scrambling the elements in a randomly chosen interval.")]
     37  [EmptyStorableClass]
     38  [Creatable("Test")]
     39  public class ScrambleManipulator : PermutationManipulator {
    3740    /// <summary>
    3841    /// Mixes the elements of the given <paramref name="permutation"/> randomly
     
    4043    /// </summary>
    4144    /// <param name="random">The random number generator.</param>
    42     /// <param name="permutation">The permutation array to manipulate.</param>
    43     /// <returns>The new permuation array with the manipulated data.</returns>
    44     public static int[] Apply(IRandom random, int[] permutation) {
    45       int[] result = (int[])permutation.Clone();
     45    /// <param name="permutation">The permutation to manipulate.</param>
     46    public static void Apply(IRandom random, Permutation permutation) {
     47      Permutation original = (Permutation)permutation.Clone();
     48
    4649      int breakPoint1, breakPoint2;
    4750      int[] scrambledIndices, remainingIndices, temp;
    4851      int selectedIndex, index;
    4952
    50       breakPoint1 = random.Next(permutation.Length - 1);
    51       breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);
     53      breakPoint1 = random.Next(original.Length - 1);
     54      breakPoint2 = random.Next(breakPoint1 + 1, original.Length);
    5255
    5356      scrambledIndices = new int[breakPoint2 - breakPoint1 + 1];
     
    7376
    7477      for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) {  // scramble permutation between breakpoints
    75         result[breakPoint1 + i] = permutation[breakPoint1 + scrambledIndices[i]];
     78        permutation[breakPoint1 + i] = original[breakPoint1 + scrambledIndices[i]];
    7679      }
    77       return result;
    7880    }
    7981
     
    8385    /// </summary>
    8486    /// <remarks>Calls <see cref="Apply"/>.</remarks>
    85     /// <param name="scope">The current scope.</param>
    86     /// <param name="random">The random number generator.</param>
    87     /// <param name="permutation">The permutation array to manipulate.</param>
    88     /// <returns>The new permuation array with the manipulated data.</returns>
    89     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
    90       return Apply(random, permutation);
     87    /// <param name="random">A random number generator.</param>
     88    /// <param name="permutation">The permutation to manipulate.</param>
     89    protected override void Manipulate(IRandom random, Permutation permutation) {
     90      Apply(random, permutation);
    9191    }
    9292  }
  • trunk/sources/HeuristicLab.Permutation/3.3/Swap2Manipulator.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Text;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Permutation {
     
    2930  /// Manipulates a permutation array by swapping to randomly chosen elements.
    3031  /// </summary>
    31   public class Swap2Manipulator : PermutationManipulatorBase {
    32     /// <inheritdoc select="summary"/>
    33     public override string Description {
    34       get { return @"TODO\r\nOperator description still missing ..."; }
    35     }
    36 
     32  ///   /// <remarks>
     33  /// 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 />
     34  /// </remarks>
     35  [Item("Swap2Manipulator", "An operator which manipulates a permutation array by swapping to randomly chosen elements.")]
     36  [EmptyStorableClass]
     37  [Creatable("Test")]
     38  public class Swap2Manipulator : PermutationManipulator {
    3739    /// <summary>
    38     /// Swaps two randomly chosen elements in the given <paramref name="permutation"/> array.
     40    /// Swaps two randomly chosen elements in the given <paramref name="permutation"/> permutation.
    3941    /// </summary>
    4042    /// <param name="random">The random number generator.</param>
    41     /// <param name="permutation">The permutation array to manipulate.</param>
    42     /// <returns>The new permuation array with the manipulated data.</returns>
    43     public static int[] Apply(IRandom random, int[] permutation) {
    44       int[] result = (int[])permutation.Clone();
     43    /// <param name="permutation">The permutation to manipulate.</param>
     44    public static void Apply(IRandom random, Permutation permutation) {
    4545      int index1, index2, temp;
    4646
    47       index1 = random.Next(result.Length);
    48       index2 = random.Next(result.Length);
     47      index1 = random.Next(permutation.Length);
     48      index2 = random.Next(permutation.Length);
    4949
    50       temp = result[index1];
    51       result[index1] = result[index2];
    52       result[index2] = temp;
    53 
    54       return result;
     50      temp = permutation[index1];
     51      permutation[index1] = permutation[index2];
     52      permutation[index2] = temp;
    5553    }
    5654
     
    5957    /// </summary>
    6058    /// <remarks>Calls <see cref="Apply"/>.</remarks>
    61     /// <param name="scope">The current scope.</param>
    62     /// <param name="random">The random number generator.</param>
    63     /// <param name="permutation">The permutation array to manipulate.</param>
    64     /// <returns>The new permuation array with the manipulated data.</returns>
    65     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
    66       return Apply(random, permutation);
     59    /// <param name="random">A random number generator.</param>
     60    /// <param name="permutation">The permutation to manipulate.</param>
     61    protected override void Manipulate(IRandom random, Permutation permutation) {
     62      Apply(random, permutation);
    6763    }
    6864  }
  • trunk/sources/HeuristicLab.Permutation/3.3/Swap3Manipulator.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Text;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Permutation {
     
    2930  /// Manipulates a permutation array by swaping three randomly chosen elements.
    3031  /// </summary>
    31   public class Swap3Manipulator : PermutationManipulatorBase {
    32     /// <inheritdoc select="summary"/>
    33     public override string Description {
    34       get { return @"TODO\r\nOperator description still missing ..."; }
    35     }
    36 
     32  [Item("Swap3Manipulator", "An operator which manipulates a permutation array by swaping three randomly chosen elements.")]
     33  [EmptyStorableClass]
     34  [Creatable("Test")]
     35  public class Swap3Manipulator : PermutationManipulator {
    3736    /// <summary>
    3837    /// Swaps three randomly chosen elements of the given <paramref name="permutation"/> array.
    3938    /// </summary>
    4039    /// <param name="random">The random number generator.</param>
    41     /// <param name="permutation">The permutation array to manipulate.</param>
    42     /// <returns>The new permuation array with the manipulated data.</returns>
    43     public static int[] Apply(IRandom random, int[] permutation) {
    44       int[] result = (int[])permutation.Clone();
     40    /// <param name="permutation">The permutation to manipulate.</param>
     41    public static void Apply(IRandom random, Permutation permutation) {
    4542      int index1, index2, index3, temp;
    4643
    47       index1 = random.Next(result.Length);
    48       index2 = random.Next(result.Length);
    49       index3 = random.Next(result.Length);
     44      index1 = random.Next(permutation.Length);
     45      index2 = random.Next(permutation.Length);
     46      index3 = random.Next(permutation.Length);
    5047
    5148      if (random.NextDouble() < 0.5) {
    5249        // swap edges 1 and 2
    53         temp = result[index1];
    54         result[index1] = result[index2];
    55         result[index2] = temp;
     50        temp = permutation[index1];
     51        permutation[index1] = permutation[index2];
     52        permutation[index2] = temp;
    5653        // swap edges 2 and 3
    57         temp = result[index2];
    58         result[index2] = result[index3];
    59         result[index3] = temp;
     54        temp = permutation[index2];
     55        permutation[index2] = permutation[index3];
     56        permutation[index3] = temp;
    6057      } else {
    6158        // swap edges 1 and 3
    62         temp = result[index1];
    63         result[index1] = result[index3];
    64         result[index3] = temp;
     59        temp = permutation[index1];
     60        permutation[index1] = permutation[index3];
     61        permutation[index3] = temp;
    6562        // swap edges 2 and 3
    66         temp = result[index2];
    67         result[index2] = result[index3];
    68         result[index3] = temp;
     63        temp = permutation[index2];
     64        permutation[index2] = permutation[index3];
     65        permutation[index3] = temp;
    6966      }
    70       return result;
    7167    }
    7268
     
    7571    /// </summary>
    7672    /// <remarks>Calls <see cref="Apply"/>.</remarks>
    77     /// <param name="scope">The current scope.</param>
    78     /// <param name="random">The random number generator.</param>
    79     /// <param name="permutation">The permutation array to manipulate.</param>
    80     /// <returns>The new permuation array with the manipulated data.</returns>
    81     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
    82       return Apply(random, permutation);
     73    /// <param name="random">A random number generator.</param>
     74    /// <param name="permutation">The permutation to manipulate.</param>
     75    protected override void Manipulate(IRandom random, Permutation permutation) {
     76      Apply(random, permutation);
    8377    }
    8478  }
  • trunk/sources/HeuristicLab.Permutation/3.3/Tests/Auxiliary.cs

    r2836 r2854  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
  • trunk/sources/HeuristicLab.Permutation/3.3/Tests/HeuristicLab.Permutation-3.3.Tests.csproj

    r2836 r2854  
    4242  </ItemGroup>
    4343  <ItemGroup>
     44    <Compile Include="AbsolutePositionTopologicalCrossoverTest.cs" />
    4445    <Compile Include="Auxiliary.cs" />
     46    <Compile Include="CosaCrossoverTest.cs" />
     47    <Compile Include="CyclicCrossoverTest.cs" />
     48    <Compile Include="EdgeRecombinationCrossoverTest.cs" />
     49    <Compile Include="InsertionManipulatorTest.cs" />
     50    <Compile Include="InversionManipulatorTest.cs" />
     51    <Compile Include="MaximalPreservativeCrossoverTest.cs" />
     52    <Compile Include="OrderBasedCrossoverTest.cs" />
    4553    <Compile Include="OrderCrossoverTest.cs" />
     54    <Compile Include="PartiallyMatchedCrossoverTest.cs" />
     55    <Compile Include="PositionBasedCrossoverTest.cs" />
    4656    <Compile Include="Properties\AssemblyInfo.cs" />
    4757    <Compile Include="Random.cs" />
     58    <Compile Include="ScrambleManipulatorTest.cs" />
     59    <Compile Include="Swap2ManipulatorTest.cs" />
     60    <Compile Include="Swap3ManipulatorTest.cs" />
     61    <Compile Include="TranslocationInversionManipulatorTest.cs" />
     62    <Compile Include="TranslocationManipulatorTest.cs" />
    4863  </ItemGroup>
    4964  <ItemGroup>
  • trunk/sources/HeuristicLab.Permutation/3.3/Tests/OrderCrossoverTest.cs

    r2840 r2854  
    1 using HeuristicLab.Permutation;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using HeuristicLab.Permutation;
    223using Microsoft.VisualStudio.TestTools.UnitTesting;
    324using HeuristicLab.Core;
     
    6889    public void OrderCrossoverCrossTest() {
    6990      TestRandom random = new TestRandom();
    70       Permutation parent1, parent2, expected, actual;
    71       ItemArray<Permutation> parents;
    72       OrderCrossover_Accessor target = new OrderCrossover_Accessor(new PrivateObject(typeof(OrderCrossover)));
    73       // The following test is based on an example from Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, pp. 55-56
    74       random.Reset();
    75       random.IntNumbers = new int[] { 3, 6 };
    76       parent1 = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 });
    77       Assert.IsTrue(parent1.Validate());
    78       parent2 = new Permutation(new int[] { 8, 2, 6, 7, 1, 5, 4, 0, 3 });
    79       Assert.IsTrue(parent2.Validate());
    80       parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 });
    81       expected = new Permutation(new int[] { 2, 7, 1, 3, 4, 5, 6, 0, 8 });
    82       Assert.IsTrue(expected.Validate());
    83       actual = target.Cross(random, parents);
    84       Assert.IsTrue(actual.Validate());
    85       Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
    86       // The following test is based on an example from Larranaga, P. et al. 1999. Genetic Algorithms for the Travelling Salesman Problem: A Review of Representations and Operators. Artificial Intelligence Review, 13, pp. 129-170.
    87       random.Reset();
    88       random.IntNumbers = new int[] { 2, 4 };
    89       parent1 = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
    90       Assert.IsTrue(parent1.Validate());
    91       parent2 = new Permutation(new int[] { 1, 3, 5, 7, 6, 4, 2, 0 });
    92       Assert.IsTrue(parent2.Validate());
    93       parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 });
    94       expected = new Permutation(new int[] { 7, 6, 2, 3, 4, 0, 1, 5 });
    95       actual = target.Cross(random, parents);
    96       Assert.IsTrue(actual.Validate());
    97       Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
    98       // The following test is based on an example from Talbi, E.G. 2009. Metaheuristics - From Design to Implementation. Wiley, p. 218.
    99       random.Reset();
    100       random.IntNumbers = new int[] { 2, 5 };
    101       parent1 = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 });
    102       Assert.IsTrue(parent1.Validate());
    103       parent2 = new Permutation(new int[] { 7, 3, 0, 4, 8, 2, 5, 1, 6 });
    104       Assert.IsTrue(parent2.Validate());
    105       parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 });
    106       expected = new Permutation(new int[] { 0, 8, 2, 3, 4, 5, 1, 6, 7 });
    107       Assert.IsTrue(expected.Validate());
    108       actual = target.Cross(random, parents);
    109       Assert.IsTrue(actual.Validate());
    110       Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
    111       // The following test is not based on published examples
    112       random.Reset();
    113       random.IntNumbers = new int[] { 0, 5 };
    114       parent1 = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 0, 5, 9 });
    115       Assert.IsTrue(parent1.Validate());
    116       parent2 = new Permutation(new int[] { 5, 3, 4, 0, 9, 8, 2, 7, 1, 6 });
    117       Assert.IsTrue(parent2.Validate());
    118       parents = new ItemArray<Permutation>(new Permutation[] { parent1, parent2 });
    119       expected = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 5, 0, 9 });
    120       Assert.IsTrue(expected.Validate());
    121       actual = target.Cross(random, parents);
    122       Assert.IsTrue(actual.Validate());
    123       Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
    124       // based on the previous with changed breakpoints
    125       random.Reset();
    126       random.IntNumbers = new int[] { 6, 9 };
    127       expected = new Permutation(new int[] { 3, 4, 8, 2, 7, 1, 6, 0, 5, 9 });
    128       Assert.IsTrue(expected.Validate());
    129       actual = target.Cross(random, parents);
    130       Assert.IsTrue(actual.Validate());
    131       Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
    132       // another one based on the previous with changed breakpoints
    133       random.Reset();
    134       random.IntNumbers = new int[] { 0, 9 };
    135       expected = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 0, 5, 9 });
    136       Assert.IsTrue(expected.Validate());
    137       actual = target.Cross(random, parents);
    138       Assert.IsTrue(actual.Validate());
    139       Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
     91      OrderCrossover_Accessor target =
     92        new OrderCrossover_Accessor(new PrivateObject(typeof(OrderCrossover)));
    14093      // perform a test with more than two parents
    14194      random.Reset();
    14295      bool exceptionFired = false;
    14396      try {
    144         target.Cross(random, new ItemArray<Permutation>(new Permutation[] { new Permutation(4), new Permutation(4), new Permutation(4)}));
     97        target.Cross(random, new ItemArray<Permutation>(new Permutation[] {
     98          new Permutation(4), new Permutation(4), new Permutation(4)}));
    14599      } catch (System.InvalidOperationException) {
    146         exceptionFired = true;
    147       }
    148       Assert.IsTrue(exceptionFired);
    149       // perform a test when two permutations are of unequal length
    150       random.Reset();
    151       exceptionFired = false;
    152       try {
    153         target.Cross(random, new ItemArray<Permutation>(new Permutation[] { new Permutation(8), new Permutation(6) }));
    154       } catch (System.ArgumentException) {
    155100        exceptionFired = true;
    156101      }
  • trunk/sources/HeuristicLab.Permutation/3.3/Tests/Random.cs

    r2840 r2854  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
  • trunk/sources/HeuristicLab.Permutation/3.3/TranslocationInversionManipulator.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Text;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Operators;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2628
    2729namespace HeuristicLab.Permutation {
     
    3032  /// (randomly chosen) position in the array.
    3133  /// </summary>
    32   public class TranslocationInversionManipulator : PermutationManipulatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
    36     }
    37 
     34  /// <remarks>
     35  /// It is implemented as described in Fogel, D.B. (1993). Applying Evolutionary Programming to Selected TSP Problems,
     36  /// Cybernetics and Systems, 22, pp 27-36.<br />
     37  /// </remarks>
     38  [Item("TranslocationInversionManipulator", "An operator which inverts a randomly chosen part of a permutation and inserts it at a random position.")]
     39  [EmptyStorableClass]
     40  [Creatable("Test")]
     41  public class TranslocationInversionManipulator : PermutationManipulator {
    3842    /// <summary>
    3943    /// Moves a randomly chosen interval of elements to another (randomly chosen) position in the given
     
    4246    /// <param name="random">The random number generator.</param>
    4347    /// <param name="permutation">The permutation array to manipulate.</param>
    44     /// <returns>The new permuation array with the manipulated data.</returns>
    45     public static int[] Apply(IRandom random, int[] permutation) {
    46       int[] result = (int[])permutation.Clone();
     48    public static void Apply(IRandom random, Permutation permutation) {
     49      Permutation original = (Permutation)permutation.Clone();
    4750      int breakPoint1, breakPoint2, insertPoint, insertPointLimit;
    4851
    49       breakPoint1 = random.Next(permutation.Length - 1);
    50       breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);
    51       insertPointLimit = permutation.Length - breakPoint2 + breakPoint1 - 1;  // get insertion point in remaining part
     52      breakPoint1 = random.Next(original.Length - 1);
     53      breakPoint2 = random.Next(breakPoint1 + 1, original.Length);
     54      insertPointLimit = original.Length - breakPoint2 + breakPoint1 - 1;  // get insertion point in remaining part
    5255      if (insertPointLimit > 0)
    5356        insertPoint = random.Next(insertPointLimit);
     
    5760      int i = 0;  // index in new permutation
    5861      int j = 0;  // index in old permutation
    59       while (i < permutation.Length) {
     62      while (i < original.Length) {
    6063        if (i == insertPoint) {  // copy translocated area
    6164          for (int k = breakPoint2; k >= breakPoint1; k--) {
    62             result[i] = permutation[k];
     65            permutation[i] = original[k];
    6366            i++;
    6467          }
     
    6770          j = breakPoint2 + 1;
    6871        }
    69         if ((i < permutation.Length) && (j < permutation.Length)) {
    70           result[i] = permutation[j];
     72        if ((i < original.Length) && (j < original.Length)) {
     73          permutation[i] = original[j];
    7174          i++;
    7275          j++;
    7376        }
    7477      }
    75       return result;
    7678    }
    7779
     
    8183    /// </summary>
    8284    /// <remarks>Calls <see cref="Apply"/>.</remarks>
    83     /// <param name="scope">The current scope.</param>
    84     /// <param name="random">The random number generator.</param>
    85     /// <param name="permutation">The permutation array to manipulate.</param>
    86     /// <returns>The new permuation array with the manipulated data.</returns>
    87     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
    88       return Apply(random, permutation);
     85    /// <param name="random">A random number generator.</param>
     86    /// <param name="permutation">The permutation to manipulate.</param>
     87    protected override void Manipulate(IRandom random, Permutation permutation) {
     88      Apply(random, permutation);
    8989    }
    9090  }
  • trunk/sources/HeuristicLab.Permutation/3.3/TranslocationManipulator.cs

    r1530 r2854  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Text;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Permutation {
     
    3031  /// (randomly chosen) position in the array.
    3132  /// </summary>
    32   public class TranslocationManipulator : PermutationManipulatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
    36     }
    37 
     33  /// <remarks>
     34  /// It is implemented as described in Michalewicz, Z. (1992), Genetic Algorithms ü Data Structures = Evolution Programs, Springer Verlag, Berlin Heidelberg.<br />
     35  /// </remarks>
     36  [Item("TranslocationManipulator", "An operator which Manipulates a permutation array by moving a randomly chosen interval of elements to another (randomly chosen) position in the array.")]
     37  [EmptyStorableClass]
     38  [Creatable("Test")]
     39  public class TranslocationManipulator : PermutationManipulator {
    3840    /// <summary>
    3941    /// Moves a randomly chosen interval of elements to another (randomly chosen) position in the given
     
    4244    /// <param name="random">The random number generator.</param>
    4345    /// <param name="permutation">The permutation array to manipulate.</param>
    44     /// <returns>The new permuation array with the manipulated data.</returns>
    45     public static int[] Apply(IRandom random, int[] permutation) {
    46       int[] result = (int[])permutation.Clone();
     46    public static void Apply(IRandom random, Permutation permutation) {
     47      Permutation original = (Permutation)permutation.Clone();
    4748      int breakPoint1, breakPoint2, insertPoint, insertPointLimit;
    4849
     
    5758      int i = 0;  // index in new permutation
    5859      int j = 0;  // index in old permutation
    59       while (i < permutation.Length) {
     60      while (i < original.Length) {
    6061        if (i == insertPoint) {  // copy translocated area
    6162          for (int k = breakPoint1; k <= breakPoint2; k++) {
    62             result[i] = permutation[k];
     63            permutation[i] = original[k];
    6364            i++;
    6465          }
     
    6768          j = breakPoint2 + 1;
    6869        }
    69         if ((i < permutation.Length) && (j < permutation.Length)) {
    70           result[i] = permutation[j];
     70        if ((i < original.Length) && (j < original.Length)) {
     71          permutation[i] = original[j];
    7172          i++;
    7273          j++;
    7374        }
    7475      }
    75       return result;
    7676    }
    7777
     
    8181    /// </summary>
    8282    /// <remarks>Calls <see cref="Apply"/>.</remarks>
    83     /// <param name="scope">The current scope.</param>
    84     /// <param name="random">The random number generator.</param>
    85     /// <param name="permutation">The permutation array to manipulate.</param>
    86     /// <returns>The new permuation array with the manipulated data.</returns>
    87     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
    88       return Apply(random, permutation);
     83    /// <param name="random">A random number generator.</param>
     84    /// <param name="permutation">The permutation to manipulate.</param>
     85    protected override void Manipulate(IRandom random, Permutation permutation) {
     86      Apply(random, permutation);
    8987    }
    9088  }
Note: See TracChangeset for help on using the changeset viewer.