- Timestamp:
- 05/07/10 16:29:25 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/ExhaustiveInsertionMoveGenerator.cs
r3376 r3706 35 35 public static TranslocationMove[] Apply(Permutation permutation) { 36 36 int length = permutation.Length; 37 if (length == 1) throw new ArgumentException("ExhaustiveInsertionMoveGenerator: There cannot be an insertion move given a permutation of length 1.", "permutation"); 37 38 TranslocationMove[] moves = null; 38 39 int count = 0; … … 45 46 } 46 47 } else { 47 moves = new TranslocationMove[length * (length - 1) - 2]; 48 for (int i = 0; i < length; i++) { 49 for (int j = 1; j <= length - 1; j++) { 50 if (i == 0 && j == length - 1 51 || i == length - 1 && j == 1) continue; 52 moves[count++] = new TranslocationMove(i, i, (i + j) % length); 48 if (length > 2) { 49 moves = new TranslocationMove[length * (length - 1) - 2]; 50 for (int i = 0; i < length; i++) { 51 for (int j = 1; j <= length - 1; j++) { 52 if (i == 0 && j == length - 1 53 || i == length - 1 && j == 1) continue; 54 moves[count++] = new TranslocationMove(i, i, (i + j) % length); 55 } 53 56 } 57 } else { // doesn't make sense, but just create a dummy move to not crash the algorithms 58 moves = new TranslocationMove[1]; 59 moves[0] = new TranslocationMove(0, 0, 1); 54 60 } 55 61 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/StochasticTranslocationMultiMoveGenerator.cs
r3376 r3706 54 54 TranslocationMove[] moves = new TranslocationMove[sampleSize]; 55 55 for (int i = 0; i < sampleSize; i++) { 56 moves[i] = StochasticT hreeOptSingleMoveGenerator.Apply(permutation, random);56 moves[i] = StochasticTranslocationSingleMoveGenerator.Apply(permutation, random); 57 57 } 58 58 return moves; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/StochasticTranslocationSingleMoveGenerator.cs
r3376 r3706 31 31 [Item("StochasticTranslocationSingleMoveGenerator", "Randomly samples one from all possible translocation and insertion moves (3-opt) from a given permutation.")] 32 32 [StorableClass] 33 public class StochasticT hreeOptSingleMoveGenerator : TranslocationMoveGenerator, IStochasticOperator, ISingleMoveGenerator {33 public class StochasticTranslocationSingleMoveGenerator : TranslocationMoveGenerator, IStochasticOperator, ISingleMoveGenerator { 34 34 public ILookupParameter<IRandom> RandomParameter { 35 35 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 36 36 } 37 37 38 public StochasticT hreeOptSingleMoveGenerator()38 public StochasticTranslocationSingleMoveGenerator() 39 39 : base() { 40 40 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); … … 43 43 public static TranslocationMove Apply(Permutation permutation, IRandom random) { 44 44 int length = permutation.Length; 45 if (length == 1) throw new ArgumentException("StochasticThreeOptSingleMoveGenerator: There cannot be an insertion move given a permutation of length 1.", "permutation"); 46 if (permutation.PermutationType != PermutationTypes.Absolute && length == 2) return new TranslocationMove(0, 0, 1); 45 47 int index1, index2, index3; 46 48 do {
Note: See TracChangeset
for help on using the changeset viewer.