Changeset 2913 for trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/UniformOnePositionManipulator.cs
- Timestamp:
- 03/02/10 16:48:24 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/UniformOnePositionManipulator.cs
r2900 r2913 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 28 namespace HeuristicLab.Encodings.RealVector { 29 29 /// <summary> 30 /// Uniformly distributed change of a single position ofa real vector.30 /// Uniformly distributed change of a single position in a real vector. 31 31 /// </summary> 32 public class UniformOnePositionManipulator : RealVectorManipulatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return "Uniformly distributed change of a single position of a real vector."; } 32 /// <remarks> 33 /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg. 34 /// </remarks> 35 [Item("UniformOnePositionManipulator", "Changes a single position in the vector by sampling uniformly from the interval [Minimum, Maximum). It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 36 [EmptyStorableClass] 37 public class UniformOnePositionManipulator : RealVectorManipulator { 38 public ValueLookupParameter<DoubleData> MinimumParameter { 39 get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; } 40 } 41 42 public ValueLookupParameter<DoubleData> MaximumParameter { 43 get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; } 36 44 } 37 45 38 46 /// <summary> 39 /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with two variable infos47 /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with two parameters 40 48 /// (<c>Minimum</c> and <c>Maximum</c>). 41 49 /// </summary> 42 50 public UniformOnePositionManipulator() { 43 AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));44 AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));51 Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)")); 52 Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 45 53 } 46 54 … … 54 62 /// <param name="max">The maximum value of the sampling range for 55 63 /// the vector element to change (exclusive).</param> 56 /// <returns>The new real vector that has been manipulated.</returns> 57 public static double[] Apply(IRandom random, double[] vector, double min, double max) { 58 double[] result = (double[])vector.Clone(); 59 int index = random.Next(result.Length); 60 result[index] = min + random.NextDouble() * (max - min); 61 return result; 64 public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max) { 65 int index = random.Next(vector.Length); 66 vector[index] = min.Value + random.NextDouble() * (max.Value - min.Value); 62 67 } 63 68 64 69 /// <summary> 65 /// Ch anges randomly a single position in the given real <paramref name="vector"/>.70 /// Checks if the minimum and maximum parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData)"/>. 66 71 /// </summary> 67 /// <remarks>Calls <see cref="Apply"/>.</remarks> 68 /// <param name="scope">The current scope.</param> 69 /// <param name="random">A random number generator.</param> 70 /// <param name="vector">The real vector to manipulate.</param> 71 /// <returns>The new real vector that has been manipulated.</returns> 72 protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) { 73 double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data; 74 double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data; 75 return Apply(random, vector, min, max); 72 /// <param name="random">The random number generator to use.</param> 73 /// <param name="realVector">The real vector to manipulate.</param> 74 protected override void Manipulate(IRandom random, DoubleArrayData realVector) { 75 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 76 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 77 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue); 76 78 } 77 79 }
Note: See TracChangeset
for help on using the changeset viewer.