Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/InsertionManipulator.cs
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding
- Property svn:mergeinfo changed
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/InsertionManipulator.cs
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 50 50 /// <param name="permutation">The permutation to manipulate.</param> 51 51 public static void Apply(IRandom random, Permutation permutation) { 52 Permutation original = (Permutation)permutation.Clone();53 int cutIndex, insertIndex, number;52 var cutIndex = random.Next(permutation.Length); 53 var insertIndex = random.Next(permutation.Length); 54 54 55 cutIndex = random.Next(original.Length); 56 insertIndex = random.Next(original.Length); 57 number = original[cutIndex]; 55 if (cutIndex == insertIndex) return; 58 56 59 int i = 0; // index in new permutation 60 int j = 0; // index in old permutation 61 while (i < original.Length) { 62 if (j == cutIndex) { 63 j++; 64 } 65 if (i == insertIndex) { 66 permutation[i] = number; 67 i++; 68 } 69 if ((i < original.Length) && (j < original.Length)) { 70 permutation[i] = original[j]; 71 i++; 72 j++; 73 } 74 } 57 permutation.Move(cutIndex, cutIndex, insertIndex); 75 58 } 76 59
Note: See TracChangeset
for help on using the changeset viewer.