- Timestamp:
- 05/07/10 16:29:25 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/ExhaustiveInversionMoveGenerator.cs
r3376 r3706 32 32 public static InversionMove[] Apply(Permutation permutation) { 33 33 int length = permutation.Length; 34 if (length == 1) throw new ArgumentException("ExhaustiveInversionMoveGenerator: There cannot be an inversion move given a permutation of length 1.", "permutation"); 34 35 int totalMoves = (length) * (length - 1) / 2; 35 36 InversionMove[] moves = null; … … 37 38 38 39 if (permutation.PermutationType == PermutationTypes.RelativeUndirected) { 39 moves = new InversionMove[totalMoves - 3]; 40 for (int i = 0; i < length - 1; i++) { 41 for (int j = i + 1; j < length; j++) { 42 // doesn't make sense to inverse the whole permutation or the whole but one in case of relative undirected permutations 43 if (j - i >= length - 2) continue; 44 moves[count++] = new InversionMove(i, j); 40 if (totalMoves - 3 > 0) { 41 moves = new InversionMove[totalMoves - 3]; 42 for (int i = 0; i < length - 1; i++) { 43 for (int j = i + 1; j < length; j++) { 44 // doesn't make sense to inverse the whole permutation or the whole but one in case of relative undirected permutations 45 if (j - i >= length - 2) continue; 46 moves[count++] = new InversionMove(i, j); 47 } 45 48 } 49 } 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 50 moves = new InversionMove[1]; 51 moves[0] = new InversionMove(0, 1); 46 52 } 47 53 } else { -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticInversionSingleMoveGenerator.cs
r3376 r3706 43 43 public static InversionMove Apply(Permutation permutation, IRandom random) { 44 44 int length = permutation.Length; 45 if (length == 1) throw new ArgumentException("StochasticInversionSingleMoveGenerator: There cannot be an inversion move given a permutation of length 1.", "permutation"); 45 46 int index1 = random.Next(length - 1); 46 47 int index2 = random.Next(index1 + 1, length); 47 48 if (permutation.PermutationType == PermutationTypes.RelativeUndirected) { 48 while (index2 - index1 >= length - 2) 49 index2 = random.Next(index1 + 1, length); 49 if (length > 3) { 50 while (index2 - index1 >= length - 2) 51 index2 = random.Next(index1 + 1, length); 52 } 50 53 } 51 54 return new InversionMove(index1, index2);
Note: See TracChangeset
for help on using the changeset viewer.