Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators
- Timestamp:
- 06/28/18 11:13:37 (7 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 10 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 -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/InversionManipulator.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. … … 60 60 61 61 public static void Apply(Permutation permutation, int breakPoint1, int breakPoint2) { 62 for (int i = 0; i <= (breakPoint2 - breakPoint1) / 2; i++) { // invert permutation between breakpoints 63 int temp = permutation[breakPoint1 + i]; 64 permutation[breakPoint1 + i] = permutation[breakPoint2 - i]; 65 permutation[breakPoint2 - i] = temp; 66 } 62 permutation.Reverse(breakPoint1, breakPoint2 - breakPoint1 + 1); 67 63 } 68 64 -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/MultiPermutationManipulator.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. -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/ScrambleManipulator.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. … … 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 57 58 breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length); 58 59 60 // TODO: Use Fisher-Yates-Shuffle rather than complicated code below 61 // scrambledIndices = Enumerable.Range(0, breakPoint2 - breakPoint1 + 1).Shuffle(random).ToArray(); 62 // Also, it would be more memory-efficient to change here and Apply(Permutation, int, int[]) below to interpret scrambleArray as values, not indices 63 // Don't forget the move generator 64 // BackwardsCompatibility3.3 65 #region This whole code should be replaced by above line when going for 3.4 59 66 scrambledIndices = new int[breakPoint2 - breakPoint1 + 1]; 60 67 remainingIndices = new int[breakPoint2 - breakPoint1 + 1]; … … 77 84 } 78 85 } 86 #endregion 79 87 80 88 Apply(permutation, breakPoint1, scrambledIndices); … … 82 90 83 91 public static void Apply(Permutation permutation, int startIndex, int[] scrambleArray) { 84 Permutation original = (Permutation)permutation.Clone(); 85 for (int i = 0; i < scrambleArray.Length; i++) { // scramble permutation between breakpoints 86 permutation[startIndex + i] = original[startIndex + scrambleArray[i]]; 87 } 92 permutation.Replace(startIndex, scrambleArray.Select(x => permutation[startIndex + x]).ToArray()); 88 93 } 89 94 -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/Swap2Manipulator.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. … … 58 58 59 59 public static void Apply(Permutation permutation, int index1, int index2) { 60 int temp = permutation[index1]; 61 permutation[index1] = permutation[index2]; 62 permutation[index2] = temp; 60 permutation.Swap(index1, index2); 63 61 } 64 62 -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/Swap3Manipulator.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. … … 57 57 public static void Apply(IRandom random, Permutation permutation) { 58 58 if (permutation.Length < 3) throw new ArgumentException("Swap3Manipulator: The permutation must be at least of size 3.", "permutation"); 59 int index1, index2, index3 , temp;59 int index1, index2, index3; 60 60 61 61 do { … … 65 65 } while (index1 == index2 || index2 == index3 || index1 == index3); 66 66 67 // swap positions 1 and 2 68 temp = permutation[index1]; 69 permutation[index1] = permutation[index2]; 70 permutation[index2] = temp; 71 // swap positions 2 and 3 72 temp = permutation[index2]; 73 permutation[index2] = permutation[index3]; 74 permutation[index3] = temp; 67 permutation.Swap(index1, index2); 68 permutation.Swap(index2, index3); 75 69 } 76 70 -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/TranslocationInversionManipulator.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. -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/TranslocationManipulator.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. … … 65 65 66 66 public static void Apply(Permutation permutation, int breakPoint1, int breakPoint2, int insertPoint) { 67 Permutation original = (Permutation)permutation.Clone(); 68 69 int i = 0; // index in new permutation 70 int j = 0; // index in old permutation 71 while (i < original.Length) { 72 if (i == insertPoint) { // copy translocated area 73 for (int k = breakPoint1; k <= breakPoint2; k++) { 74 permutation[i] = original[k]; 75 i++; 76 } 77 } 78 if (j == breakPoint1) { // skip area between breakpoints 79 j = breakPoint2 + 1; 80 } 81 if ((i < original.Length) && (j < original.Length)) { 82 permutation[i] = original[j]; 83 i++; 84 j++; 85 } 86 } 67 permutation.Move(breakPoint1, breakPoint2, insertPoint); 87 68 } 88 69
Note: See TracChangeset
for help on using the changeset viewer.