Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/02/12 00:29:39 (12 years ago)
Author:
abeham
Message:

#1775: added branch of plugin and new operators

Location:
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding
Files:
4 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Creators/UniformRandomIntegerVectorCreator.cs

    r7259 r7681  
    4949    /// <param name="max">The maximum value of the sampling range for each vector element (exclusive).</param>
    5050    /// <returns>The newly created integer vector.</returns>
    51     public static IntegerVector Apply(IRandom random, int length, int min, int max) {
    52       int[] result = new int[length];
    53       for (int i = 0; i < length; i++)
    54         result[i] = random.Next(min, max);
    55       return new IntegerVector(result);
     51    public static IntegerVector Apply(IRandom random, int length, IntMatrix bounds) {
     52      var result = new IntegerVector(length);
     53      result.Randomize(random, bounds);
     54      return result;
    5655    }
    5756
     
    6160    /// <param name="random">The pseudo random number generator to use.</param>
    6261    /// <param name="length">The length of the int vector.</param>
    63     /// <param name="minimum">The minimum value of the sampling range for each vector element (inclusive).</param>
    64     /// <param name="maximum">The maximum value of the sampling range for each vector element (exclusive).</param>
     62    /// <param name="bounds">Contains in each row for each dimension minimum (inclusive), maximum (inclusive), and step size.</param>
    6563    /// <returns>The newly created int vector.</returns>
    66     protected override IntegerVector Create(IRandom random, IntValue length, IntValue minimum, IntValue maximum) {
    67       return Apply(random, length.Value, minimum.Value, maximum.Value);
     64    protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
     65      return Apply(random, length.Value, bounds);
    6866    }
    6967  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs

    r7259 r7681  
    3434  [Item("MultiIntegerVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
    3535  [StorableClass]
    36   public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator {
     36  public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator, IBoundedIntegerVectorOperator {
    3737    public override bool CanChangeName {
    3838      get { return false; }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs

    r7259 r7681  
    5454    public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) {
    5555      if (parent1.Length != parent2.Length)
    56         throw new ArgumentException("DiscreteCrossover: The parents are of different length.");
     56        throw new ArgumentException("SinglePointCrossover: The parents are of different length.");
    5757
    5858      int length = parent1.Length;
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs

    r7259 r7681  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    4950    }
    5051
    51     public virtual void Randomize(IRandom random, int startIndex, int length, int min, int max) {
     52    public virtual void Randomize(IRandom random, int startIndex, int length, int min, int max, int step = 1) {
    5253      if (length > 0) {
    53         for (int i = 0; i < length; i++)
    54           array[startIndex + i] = random.Next(min, max);
     54        int numbers = (int)Math.Floor((max - min) / (double)step);
     55        for (int i = startIndex; i < startIndex + length; i++) {
     56          array[i] = random.Next(numbers) * step + min;
     57        }
    5558        OnReset();
    5659      }
    5760    }
    58     public void Randomize(IRandom random, int min, int max) {
    59       Randomize(random, 0, Length, min, max);
     61    public virtual void Randomize(IRandom random, int startIndex, int length, IntMatrix bounds) {
     62      if (length > 0) {
     63        for (int i = startIndex; i < startIndex + length; i++) {
     64          int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
     65          if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
     66          int numbers = (int)Math.Floor((max - min) / (double)step);
     67          array[i] = random.Next(numbers) * step + min;
     68        }
     69        OnReset();
     70      }
     71    }
     72    public void Randomize(IRandom random, int min, int max, int step = 1) {
     73      Randomize(random, 0, Length, min, max, step);
     74    }
     75    public void Randomize(IRandom random, IntMatrix bounds) {
     76      Randomize(random, 0, Length, bounds);
    6077    }
    6178  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCreator.cs

    r7259 r7681  
    4747      get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; }
    4848    }
    49     public IValueLookupParameter<IntValue> MinimumParameter {
    50       get { return (IValueLookupParameter<IntValue>)Parameters["Minimum"]; }
    51     }
    52     public IValueLookupParameter<IntValue> MaximumParameter {
    53       get { return (IValueLookupParameter<IntValue>)Parameters["Maximum"]; }
     49    public IValueLookupParameter<IntMatrix> BoundsParameter {
     50      get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    5451    }
    5552
     
    6259      Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The vector which should be manipulated."));
    6360      Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector."));
    64       Parameters.Add(new ValueLookupParameter<IntValue>("Minimum", "The inclusive lower bound for each element in the vector."));
    65       Parameters.Add(new ValueLookupParameter<IntValue>("Maximum", "The exclusive upper bound for each element in the vector."));
     61      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."));
    6662    }
    6763
     64    // BackwardsCompatibility3.3
     65    #region Backwards compatible code, remove with 3.4
     66    [StorableHook(HookType.AfterDeserialization)]
     67    private void AfterDeserialization() {
     68      if (!Parameters.ContainsKey("Bounds")) {
     69        Parameters.Remove("Minimum");
     70        Parameters.Remove("Maximum");
     71        Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (inclusive), and step size. If less rows are given the matrix is cycled."));
     72      }
     73    }
     74    #endregion
     75
    6876    public sealed override IOperation Apply() {
    69       IntegerVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, MinimumParameter.ActualValue, MaximumParameter.ActualValue);
     77      IntegerVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, BoundsParameter.ActualValue);
    7078      return base.Apply();
    7179    }
    7280
    73     protected abstract IntegerVector Create(IRandom random, IntValue length, IntValue minimum, IntValue maximum);
     81    protected abstract IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds);
    7482  }
    7583}
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCreator.cs

    r7259 r7681  
    2828  /// An interface which represents an operator for creating vectors of int-valued data.
    2929  /// </summary>
    30   public interface IIntegerVectorCreator : IIntegerVectorOperator, ISolutionCreator {
     30  public interface IIntegerVectorCreator : ISolutionCreator, IBoundedIntegerVectorOperator {
    3131    IValueLookupParameter<IntValue> LengthParameter { get; }
    32     IValueLookupParameter<IntValue> MinimumParameter { get; }
    33     IValueLookupParameter<IntValue> MaximumParameter { get; }
    3432    ILookupParameter<IntegerVector> IntegerVectorParameter { get; }
    3533  }
Note: See TracChangeset for help on using the changeset viewer.