Changeset 13412 for branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/StochasticTwoPointFiveSingleMoveGenerator.cs
- Timestamp:
- 11/28/15 23:38:51 (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/StochasticTwoPointFiveSingleMoveGenerator.cs
r13408 r13412 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.PermutationEncoding; 25 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Operators;29 using HeuristicLab.Encodings.PermutationEncoding;30 31 29 32 30 namespace HeuristicLab.Problems.PTSP { 33 [Item("Stochastic 25SingleMoveGenerator", "Randomly samples a single from all possible inversion and shift moves (2.5-opt) from a given permutation.")]31 [Item("Stochastic 2.5-SingleMoveGenerator", "Randomly samples a single from all possible inversion and shift moves (2.5-opt) from a given permutation.")] 34 32 [StorableClass] 35 class Stochastic25SingleMoveGenerator : TwoPointFiveMoveGenerator, IStochasticOperator, ISingleMoveGenerator {33 public sealed class StochasticTwoPointFiveSingleMoveGenerator : TwoPointFiveMoveGenerator, IStochasticOperator, ISingleMoveGenerator { 36 34 public ILookupParameter<IRandom> RandomParameter { 37 35 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 39 37 40 38 [StorableConstructor] 41 pr otected Stochastic25SingleMoveGenerator(bool deserializing) : base(deserializing) { }42 pr otected Stochastic25SingleMoveGenerator(Stochastic25SingleMoveGenerator original, Cloner cloner) : base(original, cloner) { }43 public Stochastic 25SingleMoveGenerator()39 private StochasticTwoPointFiveSingleMoveGenerator(bool deserializing) : base(deserializing) { } 40 private StochasticTwoPointFiveSingleMoveGenerator(StochasticTwoPointFiveSingleMoveGenerator original, Cloner cloner) : base(original, cloner) { } 41 public StochasticTwoPointFiveSingleMoveGenerator() 44 42 : base() { 45 43 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); … … 47 45 48 46 public override IDeepCloneable Clone(Cloner cloner) { 49 return new Stochastic 25SingleMoveGenerator(this, cloner);47 return new StochasticTwoPointFiveSingleMoveGenerator(this, cloner); 50 48 } 51 49 52 50 public static TwoPointFiveMove Apply(Permutation permutation, IRandom random) { 53 51 int length = permutation.Length; 54 if (length == 1) throw new ArgumentException("Stochastic 25SingleMoveGenerator: There cannot be an inversion move given a permutation of length 1.", "permutation");52 if (length == 1) throw new ArgumentException("Stochastic 2.5-SingleMoveGenerator: There cannot be an inversion move given a permutation of length 1.", "permutation"); 55 53 int index1 = random.Next(length - 1); 56 54 int index2 = random.Next(index1 + 1, length); … … 63 61 bool isInvert = random.NextDouble() > 0.5; 64 62 return new TwoPointFiveMove(index1, index2, isInvert); 65 63 66 64 } 67 65 68 66 protected override TwoPointFiveMove[] GenerateMoves(Permutation permutation) { 69 IRandom random = RandomParameter.ActualValue; 70 return new TwoPointFiveMove[] { Apply(permutation, random) }; 67 return new[] { Apply(permutation, RandomParameter.ActualValue) }; 71 68 } 72 69 }
Note: See TracChangeset
for help on using the changeset viewer.