Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/09/11 18:46:09 (13 years ago)
Author:
abeham
Message:

#1617

  • added scramble moves
  • added a scramble move evaluator for the QAP
  • added a unit test for the move evaluator
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/ScrambleManipulator.cs

    r5445 r6648  
    5050    /// <param name="permutation">The permutation to manipulate.</param>
    5151    public static void Apply(IRandom random, Permutation permutation) {
    52       Permutation original = (Permutation)permutation.Clone();
    53 
    5452      int breakPoint1, breakPoint2;
    5553      int[] scrambledIndices, remainingIndices, temp;
    5654      int selectedIndex, index;
    5755
    58       breakPoint1 = random.Next(original.Length - 1);
    59       breakPoint2 = random.Next(breakPoint1 + 1, original.Length);
     56      breakPoint1 = random.Next(permutation.Length - 1);
     57      breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);
    6058
    6159      scrambledIndices = new int[breakPoint2 - breakPoint1 + 1];
     
    8078      }
    8179
    82       for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) {  // scramble permutation between breakpoints
    83         permutation[breakPoint1 + i] = original[breakPoint1 + scrambledIndices[i]];
     80      Apply(permutation, breakPoint1, scrambledIndices);
     81    }
     82
     83    public static void Apply(Permutation permutation, int startIndex, int[] scrambleArray) {
     84      Permutation original = (Permutation)permutation.Clone();
     85      for (int i = 0; i < scrambleArray.Length; i++) {  // scramble permutation between breakpoints
     86        permutation[startIndex + i] = original[startIndex + scrambleArray[i]];
    8487      }
    8588    }
Note: See TracChangeset for help on using the changeset viewer.