Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2913


Ignore:
Timestamp:
03/02/10 16:48:24 (15 years ago)
Author:
abeham
Message:

checked and corrected (where necessary) BLX-a, BLX-a-b, as well the SinglePointCrossover
checked the UniformOnePositionManipulator
fixed a copy-paste oversight in RealVectorManipulator
#890

Location:
trunk/sources/HeuristicLab.Encodings.RealVector/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/BlendAlphaBetaCrossover.cs

    r2900 r2913  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Parameters;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Blend alpha-beta crossover for real vectors. Creates a new offspring by selecting a
     30  /// Blend alpha-beta crossover for real vectors (BLX-a-b). Creates a new offspring by selecting a
    3131  /// random value from the interval between the two alleles of the parent solutions.
    3232  /// The interval is increased in both directions as follows: Into the direction of the 'better'
    3333  /// solution by the factor alpha, into the direction of the 'worse' solution by the factor beta.
    3434  /// </summary>
    35   [Item("BlendAlphaBetaCrossover", "FIXME: CHECK WITH LITERATURE AND VALIDATE IT.")]
     35  /// <remarks>
     36  /// It is implemented as described in Takahashi, M. and Kita, H. 2001. A crossover operator using independent component analysis for real-coded genetic algorithms Proceedings of the 2001 Congress on Evolutionary Computation, pp. 643-649.<br/>
     37  /// The default value for alpha is 0.75, the default value for beta is 0.25.
     38  /// </remarks>
     39  [Item("BlendAlphaBetaCrossover", "The blend alpha beta crossover (BLX-a-b) for real vectors is similar to the blend alpha crossover (BLX-a), but distinguishes between the better and worse of the parents. The interval from which to choose the new offspring can be extended more around the better parent by specifying a higher alpha value. It is implemented as described in Takahashi, M. and Kita, H. 2001. A crossover operator using independent component analysis for real-coded genetic algorithms Proceedings of the 2001 Congress on Evolutionary Computation, pp. 643-649.")]
    3640  [EmptyStorableClass]
    3741  public class BlendAlphaBetaCrossover : RealVectorCrossover {
     
    6064    }
    6165
     66    /// <summary>
     67    /// Performs the blend alpha beta crossover (BLX-a-b) on two parent vectors.
     68    /// </summary>
     69    /// <exception cref="ArgumentException">
     70    /// Thrown when either:<br/>
     71    /// <list type="bullet">
     72    /// <item><description>The length of <paramref name="betterParent"/> and <paramref name="worseParent"/> is not equal.</description></item>
     73    /// <item><description>The parameter <paramref name="alpha"/> is smaller than 0.</description></item>
     74    /// <item><description>The parameter <paramref name="beta"/> is smaller than 0.</description></item>
     75    /// </list>
     76    /// </exception>
     77    /// <param name="random">The random number generator to use.</param>
     78    /// <param name="betterParent">The better of the two parents with regard to their fitness.</param>
     79    /// <param name="worseParent">The worse of the two parents with regard to their fitness.</param>
     80    /// <param name="alpha">The parameter alpha.</param>
     81    /// <param name="beta">The parameter beta.</param>
     82    /// <returns>The real vector that results from the crossover.</returns>
    6283    public static DoubleArrayData Apply(IRandom random, DoubleArrayData betterParent, DoubleArrayData worseParent, DoubleData alpha, DoubleData beta) {
    6384      if (betterParent.Length != worseParent.Length) throw new ArgumentException("BlendAlphaBetaCrossover: The parents' vectors are of different length.", "betterParent");
     85      if (alpha.Value < 0) throw new ArgumentException("BlendAlphaBetaCrossover: Parameter alpha must be greater or equal to 0.", "alpha");
     86      if (beta.Value < 0) throw new ArgumentException("BlendAlphaBetaCrossover: Parameter beta must be greater or equal to 0.", "beta");
    6487      int length = betterParent.Length;
     88      double min, max, d;
    6589      DoubleArrayData result = new DoubleArrayData(length);
    6690
    6791      for (int i = 0; i < length; i++) {
    68         double interval = Math.Abs(betterParent[i] - worseParent[i]);
    69         result[i] = SelectFromInterval(random, interval, betterParent[i], worseParent[i], alpha.Value, beta.Value);
     92        d = Math.Abs(betterParent[i] - worseParent[i]);
     93        if (betterParent[i] <= worseParent[i]) {
     94          min = betterParent[i] - d * alpha.Value;
     95          max = worseParent[i] + d * beta.Value;
     96        } else {
     97          min = worseParent[i] - d * beta.Value;
     98          max = betterParent[i] + d * alpha.Value;
     99        }
     100        result[i] = min + random.NextDouble() * (max - min);
    70101      }
    71102      return result;
    72103    }
    73104
    74     private static double SelectFromInterval(IRandom random, double interval, double val1, double val2, double alpha, double beta) {
    75       double resMin = 0;
    76       double resMax = 0;
    77 
    78       if (val1 <= val2) {
    79         resMin = val1 - interval * alpha;
    80         resMax = val2 + interval * beta;
    81       } else {
    82         resMin = val2 - interval * beta;
    83         resMax = val1 + interval * alpha;
    84       }
    85 
    86       return SelectRandomFromInterval(random, resMin, resMax);
    87     }
    88 
    89     private static double SelectRandomFromInterval(IRandom random, double resMin, double resMax) {
    90       return resMin + random.NextDouble() * Math.Abs(resMax - resMin);
    91     }
    92 
     105    /// <summary>
     106    /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleArrayData, DoubleData, DoubleData)"/>.
     107    /// </summary>
     108    /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception>
     109    /// <exception cref="InvalidOperationException">
     110    /// Thrown when either:<br/>
     111    /// <list type="bullet">
     112    /// <item><description>Maximization parameter could not be found.</description></item>
     113    /// <item><description>Quality parameter could not be found or the number of quality values is not equal to the number of parents.</description></item>
     114    /// <item><description>Alpha parameter could not be found.</description></item>
     115    /// <item><description>Beta parameter could not be found.</description></item>
     116    /// </list>
     117    /// </exception>
     118    /// <param name="random">The random number generator to use.</param>
     119    /// <param name="parents">The collection of parents (must be of size 2).</param>
     120    /// <returns>The real vector that results from the crossover.</returns>
    93121    protected override DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) {
    94       if (parents.Length != 2) throw new InvalidOperationException("BlendAlphaBetaCrossover: Number of parents is not equal to 2.");
     122      if (parents.Length != 2) throw new ArgumentException("BlendAlphaBetaCrossover: Number of parents is not equal to 2.", "parents");
    95123      if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found.");
    96124      if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != parents.Length) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents.");
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/BlendAlphaCrossover.cs

    r2900 r2913  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Blend alpha crossover for real vectors. Creates a new offspring by selecting a random value
     30  /// Blend alpha crossover for real vectors (BLX-a). Creates a new offspring by selecting a random value
    3131  /// from the interval between the two alleles of the parent solutions. The interval is increased
    3232  /// in both directions by the factor alpha.
    3333  /// </summary>
    34   public class BlendAlphaCrossover : RealVectorCrossoverBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get { return
    38 @"Blend alpha crossover for real vectors. Creates a new offspring by selecting a random value from the interval between the two alleles of the parent solutions. The interval is increased in both directions by the factor alpha.
    39 Please use the operator BoundsChecker if necessary.";
    40       }
     34  /// <remarks>
     35  /// It is implemented as described in Takahashi, M. and Kita, H. 2001. A crossover operator using independent component analysis for real-coded genetic algorithms Proceedings of the 2001 Congress on Evolutionary Computation, pp. 643-649.<br/>
     36  /// The default value for alpha is 0.5.
     37  /// </remarks>
     38  [Item("BlendAlphaCrossover", "The blend alpha crossover (BLX-a) for real vectors creates new offspring by sampling a new value in the range [min_i - d * alpha, max_i + d * alpha) at each position i. Here min_i and max_i are the smaller and larger value of the two parents at position i and d is max_i - min_i. It is implemented as described in Takahashi, M. and Kita, H. 2001. A crossover operator using independent component analysis for real-coded genetic algorithms Proceedings of the 2001 Congress on Evolutionary Computation, pp. 643-649.")]
     39  [EmptyStorableClass]
     40  public class BlendAlphaCrossover : RealVectorCrossover {
     41    public ValueLookupParameter<DoubleData> AlphaParameter {
     42      get { return (ValueLookupParameter<DoubleData>)Parameters["Alpha"]; }
     43    }
     44    /// <summary>
     45    /// Initializes a new instance of <see cref="BlendAlphaCrossover"/> with one parameter (<c>Alpha</c>).
     46    /// </summary>
     47    public BlendAlphaCrossover()
     48      : base() {
     49      Parameters.Add(new ValueLookupParameter<DoubleData>("Alpha", "Value for alpha", new DoubleData(0.5)));
    4150    }
    4251
    4352    /// <summary>
    44     /// Initializes a new instance of <see cref="BlendAlphaCrossover"/> with one variable info (<c>Alpha</c>).
     53    /// Performs the blend alpha crossover (BLX-a) of two real vectors.<br/>
     54    /// It creates new offspring by sampling a new value in the range [min_i - d * alpha, max_i + d * alpha) at each position i.
     55    /// Here min_i and max_i are the smaller and larger value of the two parents at position i and d is max_i - min_i.
    4556    /// </summary>
    46     public BlendAlphaCrossover()
    47       : base() {
    48       VariableInfo alphaVarInfo = new VariableInfo("Alpha", "Value for alpha", typeof(DoubleData), VariableKind.In);
    49       alphaVarInfo.Local = true;
    50       AddVariableInfo(alphaVarInfo);
    51       AddVariable(new Variable("Alpha", new DoubleData(0.5)));
    52     }
    53 
    54     /// <summary>
    55     /// Performs a blend alpha crossover of two real vectors.
    56     /// </summary>
     57    /// <exception cref="ArgumentException">Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are of different length.</exception>
    5758    /// <param name="random">The random number generator.</param>
    5859    /// <param name="parent1">The first parent for the crossover operation.</param>
     
    6061    /// <param name="alpha">The alpha value for the crossover.</param>
    6162    /// <returns>The newly created real vector resulting from the crossover operation.</returns>
    62     public static double[] Apply(IRandom random, double[] parent1, double[] parent2, double alpha) {
     63    public static DoubleArrayData Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2, DoubleData alpha) {
     64      if (parent1.Length != parent2.Length) throw new ArgumentException("BlendAlphaCrossover: The parents' vectors are of different length.", "parent1");
    6365      int length = parent1.Length;
    64       double[] result = new double[length];
    65       double cMax = 0, cMin = 0, interval = 0, resMin = 0, resMax = 0;
     66      DoubleArrayData result = new DoubleArrayData(length);
     67      double max = 0, min = 0, d = 0, resMin = 0, resMax = 0;
    6668
    6769      for (int i = 0; i < length; i++) {
    68         cMax = Math.Max(parent1[i], parent2[i]);
    69         cMin = Math.Min(parent1[i], parent2[i]);
    70         interval = Math.Abs(cMax - cMin);
    71         resMin = cMin - interval * alpha;
    72         resMax = cMax + interval * alpha;
     70        max = Math.Max(parent1[i], parent2[i]);
     71        min = Math.Min(parent1[i], parent2[i]);
     72        d = Math.Abs(max - min);
     73        resMin = min - d * alpha.Value;
     74        resMax = max + d * alpha.Value;
    7375
    7476        result[i] = resMin + random.NextDouble() * Math.Abs(resMax - resMin);
     
    7880
    7981    /// <summary>
    80     /// Performs a blend alpha crossover operation for two given parent real vectors.
     82    /// Checks that the number of parents is equal to 2 and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleArrayData, DoubleData)"/>.
    8183    /// </summary>
    82     /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    83     /// <param name="scope">The current scope.</param>
    84     /// <param name="random">A random number generator.</param>
    85     /// <param name="parents">An array containing the two real vectors that should be crossed.</param>
    86     /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    87     protected override double[] Cross(IScope scope, IRandom random, double[][] parents) {
    88       if (parents.Length != 2) throw new InvalidOperationException("ERROR in BlendAlphaCrossover: The number of parents is not equal to 2");
    89       double alpha = GetVariableValue<DoubleData>("Alpha", scope, true).Data;
    90       return Apply(random, parents[0], parents[1], alpha);
     84    /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception>
     85    /// <exception cref="InvalidOperationException">Thrown when the parameter alpha could not be found.</exception>
     86    /// <param name="random">The random number generator to use.</param>
     87    /// <param name="parents">The collection of parents (must be of size 2).</param>
     88    /// <returns>The real vector resulting from the crossover operation.</returns>
     89    protected override DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) {
     90      if (parents.Length != 2) throw new ArgumentException("BlendAlphaCrossover: The number of parents is not equal to 2", "parents");
     91      if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
     92      return Apply(random, parents[0], parents[1], AlphaParameter.ActualValue);
    9193    }
    9294  }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/SinglePointCrossover.cs

    r2900 r2913  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
     24using HeuristicLab.Data;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2626
    2727namespace HeuristicLab.Encodings.RealVector {
    2828  /// <summary>
    29   /// Single point crossover for real vectors.
     29  /// Single point crossover for real vectors. The implementation is similar to the single point crossover for binary vectors.
     30  /// After a breakpoint is randomly chosen in the interval [1,N-1) with N = length of the vector, the first part is copied from parent1 the other part copied from parent2.
     31  /// The interval is chosen such that at least one position is taken from a different parent.
    3032  /// </summary>
    31   public class SinglePointCrossover : RealVectorCrossoverBase {
    32     /// <inheritdoc select="summary"/>
    33     public override string Description {
    34       get { return "Single point crossover for real vectors."; }
    35     }
    36 
     33  /// <remarks>
     34  /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
     35  /// </remarks>
     36  [Item("SinglePointCrossover", "Breaks both parent chromosomes at a randomly chosen point and assembles a child by taking one part of the first parent and the other part of the second pard. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
     37  [EmptyStorableClass]
     38  public class SinglePointCrossover : RealVectorCrossover {
    3739    /// <summary>
    38     /// Performs a single point crossover at a randomly chosen position of the two
    39     /// given parent real vectors.
     40    /// Performs the single point crossover for real vectors. The implementation is similar to the single point crossover for binary vectors.
     41    /// After a breakpoint is randomly chosen in the interval [1,N-1) with N = length of the vector, the first part is copied from parent1 the other part copied from parent2.
    4042    /// </summary>
     43    /// <exception cref="ArgumentException">Thrown when the length of the vector is not the same in both parents.</exception>
    4144    /// <param name="random">A random number generator.</param>
    4245    /// <param name="parent1">The first parent for crossover.</param>
    4346    /// <param name="parent2">The second parent for crossover.</param>
    4447    /// <returns>The newly created real vector, resulting from the single point crossover.</returns>
    45     public static double[] Apply(IRandom random, double[] parent1, double[] parent2) {
     48    public static DoubleArrayData Apply(IRandom random, DoubleArrayData parent1, DoubleArrayData parent2) {
     49      if (parent1.Length != parent2.Length) throw new ArgumentException("SinglePointCrossover: Parents are of unequal length");
    4650      int length = parent1.Length;
    47       double[] result = new double[length];
    48       int breakPoint = random.Next(1, length);
     51      DoubleArrayData result = new DoubleArrayData(length);
     52      int breakPoint = random.Next(1, length - 1);
    4953
    5054      for (int i = 0; i < breakPoint; i++)
     
    5761
    5862    /// <summary>
    59     /// Performs a single point crossover operation for two given parent real vectors.
     63    /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleArrayData)"/>.
    6064    /// </summary>
    61     /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    62     /// <param name="scope">The current scope.</param>
    63     /// <param name="random">A random number generator.</param>
    64     /// <param name="parents">An array containing the two real vectors that should be crossed.</param>
    65     /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    66     protected override double[] Cross(IScope scope, IRandom random, double[][] parents) {
    67       if (parents.Length != 2) throw new InvalidOperationException("ERROR in SinglePointCrossover: The number of parents is not equal to 2");
     65    /// <param name="random">The pseudo random number generator to use.</param>
     66    /// <param name="parents">The list of parents.</param>
     67    /// <returns>A new real vector.</returns>
     68    protected override HeuristicLab.Data.DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) {
     69      if (parents.Length != 2) throw new InvalidOperationException("SinglePointCrossover: The number of parents is not equal to 2");
    6870      return Apply(random, parents[0], parents[1]);
    6971    }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/HeuristicLab.Encodings.RealVector-3.3.csproj

    r2900 r2913  
    9191  </ItemGroup>
    9292  <ItemGroup>
     93    <Compile Include="Crossovers\BlendAlphaCrossover.cs" />
     94    <Compile Include="Crossovers\SinglePointCrossover.cs">
     95      <SubType>Code</SubType>
     96    </Compile>
    9397    <Compile Include="HeuristicLabEncodingsRealVectorPlugin.cs" />
    9498    <None Include="HeuristicLab.snk" />
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/UniformOnePositionManipulator.cs

    r2900 r2913  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Uniformly distributed change of a single position of a real vector.
     30  /// Uniformly distributed change of a single position in a real vector.
    3131  /// </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"]; }
    3644    }
    3745
    3846    /// <summary>
    39     /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with two variable infos
     47    /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with two parameters
    4048    /// (<c>Minimum</c> and <c>Maximum</c>).
    4149    /// </summary>
    4250    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)"));
    4553    }
    4654
     
    5462    /// <param name="max">The maximum value of the sampling range for
    5563    /// 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);
    6267    }
    6368
    6469    /// <summary>
    65     /// Changes 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)"/>.
    6671    /// </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);
    7678    }
    7779  }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/RealVectorManipulator.cs

    r2900 r2913  
    5252    }
    5353
    54     protected abstract void Manipulate(IRandom random, DoubleArrayData permutation);
     54    protected abstract void Manipulate(IRandom random, DoubleArrayData realVector);
    5555  }
    5656}
Note: See TracChangeset for help on using the changeset viewer.