Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/12 18:02:33 (12 years ago)
Author:
gkronber
Message:

#1847: merged trunk changes r7800:HEAD into gp move operators branch

Location:
branches/GP-MoveOperators
Files:
3 edited
6 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding

    • Property svn:mergeinfo set to (toggle deleted branches)
      /trunk/sources/HeuristicLab.Encodings.IntegerVectorEncodingmergedeligible
      /branches/Benchmarking/sources/HeuristicLab.Encodings.IntegerVectorEncoding6917-7005
      /branches/CloningRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Encodings.IntegerVectorEncoding5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Encodings.IntegerVectorEncoding5815-6180
      /branches/DataAnalysis/HeuristicLab.Encodings.IntegerVectorEncoding4458-4459,​4462,​4464
      /branches/GP.Grammar.Editor/HeuristicLab.Encodings.IntegerVectorEncoding6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.IntegerVectorEncoding5060
      /branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding7681-8018
      /branches/NET40/sources/HeuristicLab.Encodings.IntegerVectorEncoding5138-5162
      /branches/ParallelEngine/HeuristicLab.Encodings.IntegerVectorEncoding5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Encodings.IntegerVectorEncoding7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Encodings.IntegerVectorEncoding6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Encodings.IntegerVectorEncoding6828
      /branches/SuccessProgressAnalysis/HeuristicLab.Encodings.IntegerVectorEncoding5370-5682
      /branches/Trunk/HeuristicLab.Encodings.IntegerVectorEncoding6829-6865
      /branches/VNS/HeuristicLab.Encodings.IntegerVectorEncoding5594-5752
      /branches/histogram/HeuristicLab.Encodings.IntegerVectorEncoding5959-6341
  • branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs

    r7259 r8085  
    3636  [Item("UniformOnePositionManipulator", " Uniformly distributed change of a single position of an integer vector. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
    3737  [StorableClass]
    38   public class UniformOnePositionManipulator : IntegerVectorManipulator {
    39     /// <summary>
    40     /// The lower bound of the values in the int vector.
    41     /// </summary>
    42     public ValueLookupParameter<IntValue> MinimumParameter {
    43       get { return (ValueLookupParameter<IntValue>)Parameters["Minimum"]; }
    44     }
    45     /// <summary>
    46     /// The upper bound of the values in the int vector.
    47     /// </summary>
    48     public ValueLookupParameter<IntValue> MaximumParameter {
    49       get { return (ValueLookupParameter<IntValue>)Parameters["Maximum"]; }
    50     }
     38  public class UniformOnePositionManipulator : BoundedIntegerVectorManipulator {
    5139
    5240    [StorableConstructor]
     
    5745    /// (<c>Minimum</c> and <c>Maximum</c>).
    5846    /// </summary>
    59     public UniformOnePositionManipulator()
    60       : base() {
    61       Parameters.Add(new ValueLookupParameter<IntValue>("Minimum", "Minimum of the sampling range for the vector element (included)"));
    62       Parameters.Add(new ValueLookupParameter<IntValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
    63     }
     47    public UniformOnePositionManipulator() : base() { }
    6448
    6549    public override IDeepCloneable Clone(Cloner cloner) {
    6650      return new UniformOnePositionManipulator(this, cloner);
    6751    }
     52
     53    // BackwardsCompatibility3.3
     54    #region Backwards compatible code, remove with 3.4
     55    [StorableHook(HookType.AfterDeserialization)]
     56    private void AfterDeserialization() {
     57      if (!Parameters.ContainsKey("Bounds")) {
     58        var min = ((IValueLookupParameter<IntValue>)Parameters["Minimum"]).Value as IntValue;
     59        var max = ((IValueLookupParameter<IntValue>)Parameters["Maximum"]).Value as IntValue;
     60        Parameters.Remove("Minimum");
     61        Parameters.Remove("Maximum");
     62        Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
     63        if (min != null && max != null) {
     64          BoundsParameter.Value = new IntMatrix(new int[,] { { min.Value, max.Value, 1 } });
     65        }
     66      }
     67    }
     68    #endregion
    6869
    6970    /// <summary>
     
    7677    /// <param name="max">The maximum value of the sampling range for
    7778    /// the vector element to change (exclusive).</param>
    78     public static void Apply(IRandom random, IntegerVector vector, IntValue min, IntValue max) {
    79       int index = random.Next(vector.Length);
    80       vector[index] = random.Next(min.Value, max.Value);
     79    /// <param name="bounds">The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).</param>
     80    public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds) {
     81      Manipulate(random, vector, bounds, random.Next(vector.Length));
     82    }
     83
     84    public static void Manipulate(IRandom random, IntegerVector vector, IntMatrix bounds, int index) {
     85      if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("UniformOnePositionManipulator: Invalid bounds specified", "bounds");
     86      int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
     87      if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
     88      vector[index] = RoundFeasible(min, max, step, random.Next(min, max + 1));
    8189    }
    8290
     
    8795    /// <param name="random">A random number generator.</param>
    8896    /// <param name="vector">The integer vector to manipulate.</param>
    89     protected override void Manipulate(IRandom random, IntegerVector vector) {
    90       if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
    91       if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
    92       Apply(random, vector, MinimumParameter.ActualValue, MaximumParameter.ActualValue);
     97    /// <param name="bounds">The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).</param>
     98    protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
     99      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
     100      Apply(random, vector, bounds);
    93101    }
    94102  }
Note: See TracChangeset for help on using the changeset viewer.