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
Location:
trunk/sources/HeuristicLab.Permutation/3.3
Files:
7 edited

Legend:

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

    r2829 r2830  
    5454      if (parent1.Length != parent2.Length) throw new ArgumentException("CyclicCrossover: The parent permutations are of unequal length");
    5555      int length = parent1.Length;
    56       Permutation result = new Permutation(length);
     56      int[] result = new int[length];
    5757      bool[] indexCopied = new bool[length];
    5858      int[] invParent1 = new int[length];
     
    8989      } while (j < length);
    9090
    91       return result;
     91      return new Permutation(result);
    9292    }
    9393
  • 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  }
  • trunk/sources/HeuristicLab.Permutation/3.3/MaximalPreservativeCrossover.cs

    r2829 r2830  
    5959      if (parent1.Length < 4) throw new ArgumentException("MaximalPreservativeCrossover: The parent permutation must be at least of size 4");
    6060      int length = parent1.Length;
    61       Permutation result = new Permutation(length);
     61      int[] result = new int[length];
    6262      bool[] numberCopied = new bool[length];
    6363      int breakPoint1, breakPoint2, subsegmentLength, index;
     
    119119      } while (index != breakPoint1);
    120120
    121       return result;
     121      return new Permutation(result);
    122122    }
    123123
  • trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs

    r2794 r2830  
    4545    /// <returns>The new permutation resulting from the crossover.</returns>
    4646    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
    47       Permutation result = new Permutation(parent1.Length);
     47      int[] result = new int[parent1.Length];
    4848      bool[] copied = new bool[result.Length];
    4949
     
    6666        }
    6767      }
    68       return result;
     68      return new Permutation(result);
    6969    }
    7070
  • trunk/sources/HeuristicLab.Permutation/3.3/PartiallyMatchedCrossover.cs

    r2829 r2830  
    5757      if (parent1.Length < 4) throw new ArgumentException("PartiallyMatchedCrossover: The parent permutation must be at least of size 4");
    5858      int length = parent1.Length;
    59       Permutation result = new Permutation(length); ;
     59      int[] result = new int[length];
    6060      int[] invResult = new int[length];
    6161
     
    8585      }
    8686
    87       return result;
     87      return new Permutation(result);
    8888    }
    8989
  • trunk/sources/HeuristicLab.Permutation/3.3/Permutation.cs

    r2794 r2830  
    4444    public Permutation(int[] elements)
    4545      : base(elements) {
    46       if (!Validate()) throw new ArgumentException("Elements do not represent a valid permutation.");
    4746    }
    4847    private Permutation(Permutation elements) : base(elements) { }
  • trunk/sources/HeuristicLab.Permutation/3.3/PermutationManipulator.cs

    r2794 r2830  
    4646
    4747    public sealed override IExecutionSequence Apply() {
    48       PermutationParameter.ActualValue = Manipulate(RandomParameter.ActualValue, PermutationParameter.ActualValue);
     48      Manipulate(RandomParameter.ActualValue, PermutationParameter.ActualValue);
    4949      return base.Apply();
    5050    }
    5151
    52     protected abstract Permutation Manipulate(IRandom random, Permutation permutation);
     52    protected abstract void Manipulate(IRandom random, Permutation permutation);
    5353  }
    5454}
Note: See TracChangeset for help on using the changeset viewer.