Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/19/10 02:15:10 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on operators and SGA
  • improved performance
File:
1 edited

Legend:

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

    r2794 r2830  
    3131  [Creatable("Test")]
    3232  public class InversionManipulator : PermutationManipulator {
    33 
    3433    /// <summary>
    3534    /// Inverts a randomly chosen part of a permutation.
     
    3837    /// <param name="permutation">The permutation to manipulate.</param>
    3938    /// <returns>The new manipulated permutation.</returns>
    40     public static Permutation Apply(IRandom random, Permutation permutation) {
    41       Permutation result = (Permutation)permutation.Clone();
     39    public static void Apply(IRandom random, Permutation permutation) {
    4240      int breakPoint1, breakPoint2;
    4341
    44       breakPoint1 = random.Next(result.Length - 1);
     42      breakPoint1 = random.Next(permutation.Length - 1);
    4543      do {
    46         breakPoint2 = random.Next(result.Length - 1);
     44        breakPoint2 = random.Next(permutation.Length - 1);
    4745      } while (breakPoint2 == breakPoint1);
    4846      if (breakPoint2 < breakPoint1) { int h = breakPoint1; breakPoint1 = breakPoint2; breakPoint2 = h; }
    4947
    50       for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) {  // invert permutation between breakpoints
    51         result[breakPoint1 + i] = permutation[breakPoint2 - i];
     48      for (int i = 0; i <= (breakPoint2 - breakPoint1) / 2; i++) {  // invert permutation between breakpoints
     49        int temp = permutation[breakPoint1 + i];
     50        permutation[breakPoint1 + i] = permutation[breakPoint2 - i];
     51        permutation[breakPoint2 - i] = temp;
    5252      }
    53       return result;
    5453    }
    5554
     
    6059    /// <param name="permutation">The permutation to manipulate.</param>
    6160    /// <returns>The new manipulated permuation.</returns>
    62     protected override Permutation Manipulate(IRandom random, Permutation permutation) {
    63       return Apply(random, permutation);
     61    protected override void Manipulate(IRandom random, Permutation permutation) {
     62      Apply(random, permutation);
    6463    }
    6564  }
Note: See TracChangeset for help on using the changeset viewer.