- Timestamp:
- 02/24/10 10:01:26 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/Swap2Manipulator.cs
r1530 r2854 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Permutation { … … 29 30 /// Manipulates a permutation array by swapping to randomly chosen elements. 30 31 /// </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 { 37 39 /// <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. 39 41 /// </summary> 40 42 /// <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) { 45 45 int index1, index2, temp; 46 46 47 index1 = random.Next( result.Length);48 index2 = random.Next( result.Length);47 index1 = random.Next(permutation.Length); 48 index2 = random.Next(permutation.Length); 49 49 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; 55 53 } 56 54 … … 59 57 /// </summary> 60 58 /// <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); 67 63 } 68 64 }
Note: See TracChangeset
for help on using the changeset viewer.