Changeset 3750 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
- Timestamp:
- 05/10/10 17:19:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
r3677 r3750 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 37 38 [Item("MichalewiczNonUniformOnePositionManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 38 39 [StorableClass] 39 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {40 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator, IIterationBasedOperator { 40 41 /// <summary> 41 /// The current generation.42 /// The current iteration. 42 43 /// </summary> 43 public LookupParameter<IntValue> GenerationParameter {44 get { return ( LookupParameter<IntValue>)Parameters["Generations"]; }44 public ILookupParameter<IntValue> IterationsParameter { 45 get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; } 45 46 } 46 47 /// <summary> 47 /// The maximum generation.48 /// The maximum iteration. 48 49 /// </summary> 49 public LookupParameter<IntValue> MaximumGenerationsParameter {50 get { return ( LookupParameter<IntValue>)Parameters["MaximumGenerations"]; }50 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 51 get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } 51 52 } 52 53 /// <summary> 53 /// The parameter describing how much the mutation should depend on the progress towards the maximum generation.54 /// The parameter describing how much the mutation should depend on the progress towards the maximum iterations. 54 55 /// </summary> 55 public ValueLookupParameter<DoubleValue> GenerationDependencyParameter {56 get { return (ValueLookupParameter<DoubleValue>)Parameters[" GenerationDependency"]; }56 public ValueLookupParameter<DoubleValue> IterationDependencyParameter { 57 get { return (ValueLookupParameter<DoubleValue>)Parameters["IterationDependency"]; } 57 58 } 58 59 59 60 /// <summary> 60 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with four 61 /// parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c> 62 /// and <c>GenerationDependency</c>). 61 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with three 62 /// parameters (<c>Iterations</c>, <c>MaximumIterations</c> and <c>IterationDependency</c>). 63 63 /// </summary> 64 64 public MichalewiczNonUniformOnePositionManipulator() 65 65 : base() { 66 Parameters.Add(new LookupParameter<IntValue>(" Generations", "Current generation of the algorithm"));67 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));68 Parameters.Add(new ValueLookupParameter<DoubleValue>(" GenerationDependency", "Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));66 Parameters.Add(new LookupParameter<IntValue>("Iterations", "Current iteration of the algorithm.")); 67 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Maximum number of iterations.")); 68 Parameters.Add(new ValueLookupParameter<DoubleValue>("IterationDependency", "Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5))); 69 69 } 70 70 71 71 /// <summary> 72 72 /// Performs a non uniformly distributed one position manipulation on the given 73 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="current Generation"/> approaches <see cref="maximumGenerations"/>.73 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentIteration"/> approaches <see cref="maximumIterations"/>. 74 74 /// </summary> 75 /// <exception cref="ArgumentException">Thrown when <paramref name="current Generation"/> is greater than <paramref name="maximumGenerations"/>.</exception>75 /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception> 76 76 /// <param name="random">The random number generator.</param> 77 77 /// <param name="vector">The real vector to manipulate.</param> 78 78 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 79 /// <param name="current Generation">The current generation of the algorithm.</param>80 /// <param name="maximum Generations">Maximum number of generations.</param>81 /// <param name=" generationsDependency">Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>79 /// <param name="currentIteration">The current iteration of the algorithm.</param> 80 /// <param name="maximumIterations">Maximum number of iterations.</param> 81 /// <param name="iterationDependency">Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.</param> 82 82 /// <returns>The manipulated real vector.</returns> 83 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue current Generation, IntValue maximumGenerations, DoubleValue generationsDependency) {84 if (current Generation.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");85 if ( generationsDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: GenerationsDependency must be >= 0.");83 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentIteration, IntValue maximumIterations, DoubleValue iterationDependency) { 84 if (currentIteration.Value > maximumIterations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentIteration must be smaller or equal than MaximumIterations", "currentIteration"); 85 if (iterationDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: iterationDependency must be >= 0.", "iterationDependency"); 86 86 int length = vector.Length; 87 87 int index = random.Next(length); 88 88 89 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - current Generation.Value / maximumGenerations.Value, generationsDependency.Value)));89 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value))); 90 90 91 91 double min = bounds[index % bounds.Rows, 0]; … … 106 106 protected override void Manipulate(IRandom random, RealVector realVector) { 107 107 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 108 if ( GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");109 if (Maximum GenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");110 if ( GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");111 Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);108 if (IterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + IterationsParameter.ActualName + " could not be found."); 109 if (MaximumIterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumIterationsParameter.ActualName + " could not be found."); 110 if (IterationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + IterationDependencyParameter.ActualName + " could not be found."); 111 Apply(random, realVector, BoundsParameter.ActualValue, IterationsParameter.ActualValue, MaximumIterationsParameter.ActualValue, IterationDependencyParameter.ActualValue); 112 112 } 113 113 }
Note: See TracChangeset
for help on using the changeset viewer.