Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/10 16:48:24 (14 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.