Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.