Changeset 3123 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
- Timestamp:
- 03/19/10 15:59:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
r3060 r3123 38 38 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator { 39 39 /// <summary> 40 /// The lower bound of the values in the real vector.40 /// 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. 41 41 /// </summary> 42 public ValueLookupParameter<DoubleValue> MinimumParameter { 43 get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; } 44 } 45 /// <summary> 46 /// The upper bound of the values in the real vector. 47 /// </summary> 48 public ValueLookupParameter<DoubleValue> MaximumParameter { 49 get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; } 42 public ValueLookupParameter<DoubleMatrix> BoundsParameter { 43 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 50 44 } 51 45 /// <summary> … … 69 63 70 64 /// <summary> 71 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with f ive72 /// parameters (<c> Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>65 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with four 66 /// parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c> 73 67 /// and <c>GenerationDependency</c>). 74 68 /// </summary> 75 69 public MichalewiczNonUniformOnePositionManipulator() 76 70 : base() { 77 Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "Minimum of the sampling range for the vector element (included)")); 78 Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 71 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("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.")); 79 72 Parameters.Add(new LookupParameter<IntValue>("Generation", "Current generation of the algorithm")); 80 73 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations")); … … 89 82 /// <param name="random">The random number generator.</param> 90 83 /// <param name="vector">The real vector to manipulate.</param> 91 /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param> 92 /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param> 84 /// <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> 93 85 /// <param name="currentGeneration">The current generation of the algorithm.</param> 94 86 /// <param name="maximumGenerations">Maximum number of generations.</param> 95 87 /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param> 96 88 /// <returns>The manipulated real vector.</returns> 97 public static void Apply(IRandom random, RealVector vector, Double Value min, DoubleValue max, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {89 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) { 98 90 if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration"); 99 91 int length = vector.Length; … … 102 94 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value))); 103 95 96 double min = bounds[index % bounds.Rows, 0]; 97 double max = bounds[index % bounds.Rows, 1]; 98 104 99 if (random.NextDouble() < 0.5) { 105 vector[index] = vector[index] + (max .Value- vector[index]) * prob;100 vector[index] = vector[index] + (max - vector[index]) * prob; 106 101 } else { 107 vector[index] = vector[index] - (vector[index] - min .Value) * prob;102 vector[index] = vector[index] - (vector[index] - min) * prob; 108 103 } 109 104 } … … 115 110 /// <param name="realVector">The real vector that should be manipulated.</param> 116 111 protected override void Manipulate(IRandom random, RealVector realVector) { 117 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 118 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 112 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 119 113 if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found."); 120 114 if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found."); 121 115 if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found."); 122 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);116 Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue); 123 117 } 124 118 }
Note: See TracChangeset
for help on using the changeset viewer.