Changeset 8660 for branches/GP-MoveOperators/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt
- Timestamp:
- 09/14/12 18:58:15 (12 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GP-MoveOperators/HeuristicLab.Encodings.PermutationEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.PermutationEncoding (added) merged: 8246,8338,8600
- Property svn:mergeinfo changed
-
branches/GP-MoveOperators/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/ExhaustiveInversionMoveGenerator.cs
r7259 r8660 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 40 42 41 43 public static InversionMove[] Apply(Permutation permutation) { 44 return Generate(permutation).ToArray(); 45 } 46 47 public static IEnumerable<InversionMove> Generate(Permutation permutation) { 42 48 int length = permutation.Length; 43 49 if (length == 1) throw new ArgumentException("ExhaustiveInversionMoveGenerator: There cannot be an inversion move given a permutation of length 1.", "permutation"); 44 50 int totalMoves = (length) * (length - 1) / 2; 45 InversionMove[] moves = null;46 int count = 0;47 51 48 52 if (permutation.PermutationType == PermutationTypes.RelativeUndirected) { 49 53 if (totalMoves - 3 > 0) { 50 moves = new InversionMove[totalMoves - 3];51 54 for (int i = 0; i < length - 1; i++) { 52 55 for (int j = i + 1; j < length; j++) { 53 56 // doesn't make sense to inverse the whole permutation or the whole but one in case of relative undirected permutations 54 57 if (j - i >= length - 2) continue; 55 moves[count++] =new InversionMove(i, j);58 yield return new InversionMove(i, j); 56 59 } 57 60 } 58 61 } else { // when length is 3 or less, there's actually no difference, but for the sake of not crashing the algorithm create a dummy move 59 moves = new InversionMove[1]; 60 moves[0] = new InversionMove(0, 1); 62 yield return new InversionMove(0, 1); 61 63 } 62 64 } else { 63 moves = new InversionMove[totalMoves];64 65 for (int i = 0; i < length - 1; i++) 65 66 for (int j = i + 1; j < length; j++) { 66 moves[count++] =new InversionMove(i, j);67 yield return new InversionMove(i, j); 67 68 } 68 69 } 69 return moves;70 70 } 71 71
Note: See TracChangeset
for help on using the changeset viewer.