- Timestamp:
- 02/24/10 10:01:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/ScrambleManipulator.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 randomly scrambling the elements in a randomly chosen interval. 30 31 /// </summary> 31 public class ScrambleManipulator : PermutationManipulatorBase { 32 /// <inheritdoc select="summary"/> 33 public override string Description { 34 get { return @"TODO\r\nOperator description still missing ..."; } 35 } 36 32 /// <remarks> 33 /// Implemented as described in Syswerda, G. (1991). Schedule Optimization Using Genetic Algorithms, 34 /// in Davis, L. (Ed.) Handbook of Genetic Algorithms, Van Nostrand Reinhold, New York, pp 332-349. 35 /// </remarks> 36 [Item("ScrambleManipulator", "An operator which manipulates a permutation array by randomly scrambling the elements in a randomly chosen interval.")] 37 [EmptyStorableClass] 38 [Creatable("Test")] 39 public class ScrambleManipulator : PermutationManipulator { 37 40 /// <summary> 38 41 /// Mixes the elements of the given <paramref name="permutation"/> randomly … … 40 43 /// </summary> 41 44 /// <param name="random">The random number generator.</param> 42 /// <param name="permutation">The permutation arrayto manipulate.</param>43 /// <returns>The new permuation array with the manipulated data.</returns>44 public static int[] Apply(IRandom random, int[] permutation) {45 int[] result = (int[])permutation.Clone(); 45 /// <param name="permutation">The permutation to manipulate.</param> 46 public static void Apply(IRandom random, Permutation permutation) { 47 Permutation original = (Permutation)permutation.Clone(); 48 46 49 int breakPoint1, breakPoint2; 47 50 int[] scrambledIndices, remainingIndices, temp; 48 51 int selectedIndex, index; 49 52 50 breakPoint1 = random.Next( permutation.Length - 1);51 breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);53 breakPoint1 = random.Next(original.Length - 1); 54 breakPoint2 = random.Next(breakPoint1 + 1, original.Length); 52 55 53 56 scrambledIndices = new int[breakPoint2 - breakPoint1 + 1]; … … 73 76 74 77 for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) { // scramble permutation between breakpoints 75 result[breakPoint1 + i] = permutation[breakPoint1 + scrambledIndices[i]];78 permutation[breakPoint1 + i] = original[breakPoint1 + scrambledIndices[i]]; 76 79 } 77 return result;78 80 } 79 81 … … 83 85 /// </summary> 84 86 /// <remarks>Calls <see cref="Apply"/>.</remarks> 85 /// <param name="scope">The current scope.</param> 86 /// <param name="random">The random number generator.</param> 87 /// <param name="permutation">The permutation array to manipulate.</param> 88 /// <returns>The new permuation array with the manipulated data.</returns> 89 protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) { 90 return Apply(random, permutation); 87 /// <param name="random">A random number generator.</param> 88 /// <param name="permutation">The permutation to manipulate.</param> 89 protected override void Manipulate(IRandom random, Permutation permutation) { 90 Apply(random, permutation); 91 91 } 92 92 }
Note: See TracChangeset
for help on using the changeset viewer.