- Timestamp:
- 03/23/10 02:44:07 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/StochasticThreeOptMoveGenerator.cs
r3074 r3200 30 30 [Item("StochasticThreeOptMoveGenerator", "Randomly samples n from all possible 3-opt moves from a given permutation.")] 31 31 [StorableClass] 32 public class StochasticThreeOptM oveGenerator : ThreeOptMoveGenerator, IStochasticOperator {32 public class StochasticThreeOptMultiMoveGenerator : ThreeOptMoveGenerator, IStochasticOperator, IMultiMoveGenerator { 33 33 public ILookupParameter<IRandom> RandomParameter { 34 34 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 35 35 } 36 p rivateValueLookupParameter<IntValue> SampleSizeParameter {37 get { return ( ValueLookupParameter<IntValue>)Parameters["SampleSize"]; }36 public IValueLookupParameter<IntValue> SampleSizeParameter { 37 get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; } 38 38 } 39 39 … … 43 43 } 44 44 45 public StochasticThreeOptM oveGenerator()45 public StochasticThreeOptMultiMoveGenerator() 46 46 : base() { 47 47 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); … … 51 51 public static ThreeOptMove[] Apply(Permutation permutation, IRandom random, int sampleSize) { 52 52 int length = permutation.Length; 53 /*int totalMoves = (length) * (length - 1) / 2 - 3;54 // FIXME: Remove this comment if ExhaustiveThreeOptMoveGenerator exists, otherwise alter the exception message below.55 if (sampleSize >= totalMoves) throw new InvalidOperationException("StochasticThreeOptMoveGenerator: Sample size (" + sampleSize + ") is larger than the set of all possible moves (" + totalMoves + "), use the ExhaustiveThreeOptMoveGenerator instead.");56 */57 53 ThreeOptMove[] moves = new ThreeOptMove[sampleSize]; 58 54 for (int i = 0; i < sampleSize; i++) { 59 55 int index1, index2, index3; 60 do {61 index1 = random.Next(length - 1);62 index2 = random.Next(index1 + 1, length);63 } while (index2 - index1 == length - 1);64 do {65 index3 = random.Next(length);66 } while (index1 <= index3 && index3 <= index2 + 1);56 index1 = random.Next(length - 1); 57 index2 = random.Next(index1 + 1, length); 58 index3 = length - index2 + index1 - 1; // get insertion point in remaining part 59 if (index3 > 0) 60 index3 = random.Next(index3); 61 else 62 index3 = 0; 67 63 moves[i] = new ThreeOptMove(index1, index2, index3); 68 64 }
Note: See TracChangeset
for help on using the changeset viewer.