- Timestamp:
- 04/02/11 16:45:04 (14 years ago)
- Location:
- branches/QAP/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAP/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs
r5838 r5931 43 43 if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation"); 44 44 int totalMoves = (length) * (length - 1) / 2; 45 Swap2Move[] moves = n ull;45 Swap2Move[] moves = new Swap2Move[totalMoves]; 46 46 int count = 0; 47 47 48 if (permutation.PermutationType == PermutationTypes.RelativeUndirected) { 49 if (totalMoves - 3 > 0) { 50 moves = new Swap2Move[totalMoves - 3]; 51 for (int i = 0; i < length - 1; i++) { 52 for (int j = i + 1; j < length; j++) { 53 if (j - i >= length - 2) continue; 54 moves[count++] = new Swap2Move(i, j); 55 } 56 } 57 } 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 58 moves = new Swap2Move[1]; 59 moves[0] = new Swap2Move(0, 1); 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); 60 51 } 61 } else {62 moves = new Swap2Move[totalMoves];63 for (int i = 0; i < length - 1; i++)64 for (int j = i + 1; j < length; j++) {65 moves[count++] = new Swap2Move(i, j);66 }67 }68 52 return moves; 69 53 } -
branches/QAP/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/StochasticSwap2SingleMoveGenerator.cs
r5838 r5931 49 49 public static Swap2Move Apply(Permutation permutation, IRandom random) { 50 50 int length = permutation.Length; 51 if (length == 1) throw new ArgumentException("StochasticSwap2SingleMoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation"); 52 int index1 = random.Next(length - 1); 53 int index2 = random.Next(index1 + 1, length); 51 if (length < 2) throw new ArgumentException("StochasticSwap2SingleMoveGenerator: There cannot be a swap-2 move given a permutation of length less than 2.", "permutation"); 52 int index1 = random.Next(length), index2 = 0; 53 do { 54 index2 = random.Next(length); 55 } while (index1 == index2); 54 56 return new Swap2Move(index1, index2); 55 57 }
Note: See TracChangeset
for help on using the changeset viewer.