Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/ScrambleManipulator.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/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
Note: See TracChangeset
for help on using the changeset viewer.