Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/17 14:01:22 (7 years ago)
Author:
abeham
Message:

#2731: merged 14662 to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.PermutationEncoding

  • stable/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/ScrambleManipulator.cs

    r14186 r14967  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    5758      breakPoint2 = random.Next(breakPoint1 + 1, permutation.Length);
    5859
     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
    5966      scrambledIndices = new int[breakPoint2 - breakPoint1 + 1];
    6067      remainingIndices = new int[breakPoint2 - breakPoint1 + 1];
     
    7784        }
    7885      }
     86      #endregion
    7987
    8088      Apply(permutation, breakPoint1, scrambledIndices);
     
    8290
    8391    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());
    8893    }
    8994
Note: See TracChangeset for help on using the changeset viewer.