- Timestamp:
- 05/30/11 18:07:32 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/histogram (added) merged: 5959,5961,5970,5994-5996,5999,6007,6010-6016,6020,6022,6027-6028,6032,6046,6055-6056,6081-6082,6086-6087,6089,6115,6176,6194-6195,6338-6341
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding
- Property svn:mergeinfo changed
/branches/histogram/HeuristicLab.Encodings.PermutationEncoding (added) merged: 6011,6022,6032,6046,6055-6056,6086,6195,6340
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs
r5933 r6342 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 39 40 } 40 41 42 public static IEnumerable<Swap2Move> Generate(Permutation permutation) { 43 int length = permutation.Length; 44 if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation"); 45 46 for (int i = 0; i < length - 1; i++) 47 for (int j = i + 1; j < length; j++) { 48 yield return new Swap2Move(i, j); 49 } 50 } 51 41 52 public static Swap2Move[] Apply(Permutation permutation) { 42 53 int length = permutation.Length; 43 if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation");44 54 int totalMoves = (length) * (length - 1) / 2; 45 55 Swap2Move[] moves = new Swap2Move[totalMoves]; 46 56 int count = 0; 47 48 for (int i = 0; i < length - 1; i++) 49 for (int j = i + 1; j < length; j++) { 50 moves[count++] = new Swap2Move(i, j); 51 } 57 foreach (Swap2Move move in Generate(permutation)) { 58 moves[count++] = move; 59 } 52 60 return moves; 53 61 }
Note: See TracChangeset
for help on using the changeset viewer.