- Timestamp:
- 04/30/11 15:40:40 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/histogram/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs
r5933 r6086 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.