Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8017 for branches


Ignore:
Timestamp:
06/17/12 13:38:17 (12 years ago)
Author:
abeham
Message:

#1775:

  • Renamed some crossovers
  • Ported some additional crossovers from the real-vector plugin
  • Introduced BoundedIntegerVector* base classes
Location:
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3
Files:
8 added
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs

    r7686 r8017  
    9494        crossover.RandomParameter.ActualName = RandomParameter.Name;
    9595      }
     96      foreach (IBoundedIntegerVectorOperator crossover in Operators.OfType<IBoundedIntegerVectorOperator>()) {
     97        crossover.BoundsParameter.ActualName = BoundsParameter.Name;
     98      }
    9699    }
    97100
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj

    r7699 r8017  
    150150  </ItemGroup>
    151151  <ItemGroup>
     152    <Compile Include="BoundedIntegerVectorCrossover.cs" />
     153    <Compile Include="BoundedIntegerVectorManipulator.cs" />
    152154    <Compile Include="Creators\UniformRandomIntegerVectorCreator.cs" />
    153     <Compile Include="Crossovers\AverageCrossover.cs" />
     155    <Compile Include="Crossovers\RoundedAverageCrossover.cs" />
    154156    <Compile Include="Crossovers\DiscreteCrossover.cs">
    155157      <SubType>Code</SubType>
    156158    </Compile>
    157159    <Compile Include="Crossovers\MultiIntegerVectorCrossover.cs" />
     160    <Compile Include="Crossovers\RoundedBlendAlphaBetaCrossover.cs" />
     161    <Compile Include="Crossovers\RoundedBlendAlphaCrossover.cs" />
     162    <Compile Include="Crossovers\RoundedHeuristicCrossover.cs" />
     163    <Compile Include="Crossovers\RoundedLocalCrossover.cs" />
    158164    <Compile Include="Crossovers\SinglePointCrossover.cs">
    159165      <SubType>Code</SubType>
    160166    </Compile>
    161     <Compile Include="Crossovers\UniformAllPositionsArithmeticCrossover.cs" />
    162     <Compile Include="Crossovers\UniformSomePositionsArithmeticCrossover.cs" />
     167    <Compile Include="Crossovers\RoundedUniformArithmeticCrossover.cs" />
    163168    <Compile Include="Interfaces\IBoundedIntegerVectorOperator.cs" />
    164169    <Compile Include="Interfaces\IIntegerVectorCreator.cs" />
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IBoundedIntegerVectorOperator.cs

    r7681 r8017  
    2525namespace HeuristicLab.Encodings.IntegerVectorEncoding {
    2626  public interface IBoundedIntegerVectorOperator : IIntegerVectorOperator {
     27    /// <summary>
     28    /// The bounds parameter must contain at least one row and at least two columns. The first two columns specify min and max values, the last column specifies the step size, but is optional (1 is assumed if omitted).
     29    /// </summary>
    2730    IValueLookupParameter<IntMatrix> BoundsParameter { get; }
    2831  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs

    r7715 r8017  
    3535  [Item("RoundedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N_i(0,1) to the current value in each position i given the values for sigma_i in the parameter. The result is rounded to the next feasible value. If there are less elements in Sigma than positions, then Sigma is cycled.")]
    3636  [StorableClass]
    37   public class RoundedNormalAllPositionsManipulator : IntegerVectorManipulator {
    38 
    39     public IValueLookupParameter<IntMatrix> BoundsParameter {
    40       get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    41     }
     37  public class RoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator {
    4238
    4339    public IValueParameter<DoubleArray> SigmaParameter {
     
    5450    public RoundedNormalAllPositionsManipulator()
    5551      : base() {
    56       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."));
    5752      Parameters.Add(new ValueParameter<DoubleArray>("Sigma", "The vector containing the standard deviations used for manipulating each dimension. If it is only of length one the same sigma will be used for every dimension.", new DoubleArray(new double[] { 1 })));
    5853    }
     
    6964    /// <param name="sigma">The sigma vector determining the strength of the mutation.</param>
    7065    /// <param name="random">A random number generator.</param>
    71     /// <param name="vector">The integer vector to manipulate.</param>
     66    /// <param name="vector">The integer vector to manipulate.</param>#
     67    /// <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>
    7268    /// <returns>The manipulated integer vector.</returns>
    7369    public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, DoubleArray sigma) {
    74       if (sigma == null || sigma.Length == 0) throw new ArgumentException("ERROR: Vector containing the standard deviations is not defined.", "sigma");
     70      if (sigma == null || sigma.Length == 0) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Vector containing the standard deviations is not defined.", "sigma");
    7571      if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");
    7672      var N = new NormalDistributedRandom(random, 0.0, 1.0);
     
    8076
    8177        int value = (vector[i] + (int)Math.Round((N.NextDouble() * sigma[i % sigma.Length])) - min) / step;
    82         vector[i] = Math.Max(min, Math.Min(max, value * step + min));
     78        vector[i] = RoundFeasible(min, max, step, value);
    8379      }
    8480    }
     
    8985    /// <param name="random">The random number generator.</param>
    9086    /// <param name="vector">The vector of integer values that is manipulated.</param>
    91     protected override void Manipulate(IRandom random, IntegerVector vector) {
    92       Apply(random, vector, BoundsParameter.ActualValue, SigmaParameter.Value);
     87    /// <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>
     88    protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
     89      Apply(random, vector, bounds, SigmaParameter.Value);
    9390    }
    9491  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/SelfAdaptiveRoundedNormalAllPositionsManipulator.cs

    r7715 r8017  
    3636  [Item("SelfAdaptiveRoundedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N(0,1) to the current value in each position i. The resulting value is rounded to the next feasible value. The values for sigma_i are looked up dynamically. If there are less elements in the strategy vector than positions, then the strategy vector is cycled.")]
    3737  [StorableClass]
    38   public class SelfAdaptiveRoundedNormalAllPositionsManipulator : IntegerVectorManipulator, ISelfAdaptiveManipulator {
     38  public class SelfAdaptiveRoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator, ISelfAdaptiveManipulator {
    3939    public Type StrategyParameterType {
    4040      get { return typeof(IIntegerVectorStdDevStrategyParameterOperator); }
     
    5151    }
    5252
    53     public IValueLookupParameter<IntMatrix> BoundsParameter {
    54       get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    55     }
    56 
    5753    [StorableConstructor]
    5854    protected SelfAdaptiveRoundedNormalAllPositionsManipulator(bool deserializing) : base(deserializing) { }
     
    6460      : base() {
    6561      Parameters.Add(new LookupParameter<DoubleArray>("StrategyParameter", "The vector containing the endogenous strategy parameters."));
    66       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."));
    6762    }
    6863
     
    8075    /// <param name="random">A random number generator.</param>
    8176    /// <param name="vector">The integer vector to manipulate.</param>
     77    /// <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>
    8278    public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, DoubleArray strategyParameters) {
    83       if (strategyParameters == null || strategyParameters.Length == 0) throw new ArgumentException("ERROR: Vector containing the standard deviations is not defined.", "sigma");
    84       if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");
     79      if (strategyParameters == null || strategyParameters.Length == 0) throw new ArgumentException("SelfAdaptiveRoundedNormalAllPositionsManipulator: Vector containing the standard deviations is not defined.", "sigma");
     80      if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("SelfAdaptiveRoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");
    8581      var N = new NormalDistributedRandom(random, 0.0, 1.0);
    8682      if (strategyParameters != null) {
     
    9086
    9187          int value = (vector[i] + (int)Math.Round((N.NextDouble() * strategyParameters[i % strategyParameters.Length])) - min) / step;
    92           vector[i] = Math.Max(min, Math.Min(max, value * step + min));
     88          vector[i] = RoundFeasible(min, max, step, value);
    9389        }
    9490      }
     
    10096    /// <param name="random">The random number generator.</param>
    10197    /// <param name="vector">The vector of integer values that is manipulated.</param>
    102     protected override void Manipulate(IRandom random, IntegerVector vector) {
    103       Apply(random, vector, BoundsParameter.ActualValue, StrategyParameterParameter.ActualValue);
     98    /// <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>
     99    protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
     100      Apply(random, vector, bounds, StrategyParameterParameter.ActualValue);
    104101    }
    105102  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs

    r7686 r8017  
    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, IBoundedIntegerVectorOperator {
    39     /// <summary>
    40     /// A matrix that specifies the bounds for each dimension in a separate row. The first column denotes the minimum, the second the maximum value, and the third column denotes the step size.
    41     /// </summary>
    42     public IValueLookupParameter<IntMatrix> BoundsParameter {
    43       get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    44     }
     38  public class UniformOnePositionManipulator : BoundedIntegerVectorManipulator {
    4539
    4640    [StorableConstructor]
     
    5145    /// (<c>Minimum</c> and <c>Maximum</c>).
    5246    /// </summary>
    53     public UniformOnePositionManipulator()
    54       : base() {
    55       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."));
    56     }
     47    public UniformOnePositionManipulator() : base() { }
    5748
    5849    public override IDeepCloneable Clone(Cloner cloner) {
     
    8677    /// <param name="max">The maximum value of the sampling range for
    8778    /// the vector element to change (exclusive).</param>
     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>
    8880    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) {
    8985      if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("UniformOnePositionManipulator: Invalid bounds specified", "bounds");
    90       int index = random.Next(vector.Length);
    9186      int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
    9287      if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
    93       int value = (max - min) / step;
    94       vector[index] = random.Next(value) * step + min;
     88      vector[index] = RoundFeasible(min, max, step, random.Next(min, max + 1));
    9589    }
    9690
     
    10195    /// <param name="random">A random number generator.</param>
    10296    /// <param name="vector">The integer vector to manipulate.</param>
    103     protected override void Manipulate(IRandom random, IntegerVector vector) {
     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) {
    10499      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    105       Apply(random, vector, BoundsParameter.ActualValue);
     100      Apply(random, vector, bounds);
    106101    }
    107102  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformSomePositionsManipulator.cs

    r7699 r8017  
    3434  /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
    3535  /// </remarks>
    36   [Item("UniformSomePositionsManipulator", " Uniformly distributed change of several, but at least one, positions 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.")]
     36  [Item("UniformSomePositionsManipulator", "Uniformly distributed change of several, but at least one, positions 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 UniformSomePositionsManipulator : IntegerVectorManipulator, IBoundedIntegerVectorOperator {
    39     /// <summary>
    40     /// A matrix that specifies the bounds for each dimension in a separate row. The first column denotes the minimum, the second the maximum value, and the third column denotes the step size.
    41     /// </summary>
    42     public IValueLookupParameter<IntMatrix> BoundsParameter {
    43       get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    44     }
     38  public class UniformSomePositionsManipulator : BoundedIntegerVectorManipulator {
    4539
    4640    public IValueLookupParameter<DoubleValue> ProbabilityParameter {
     
    5145    protected UniformSomePositionsManipulator(bool deserializing) : base(deserializing) { }
    5246    protected UniformSomePositionsManipulator(UniformSomePositionsManipulator original, Cloner cloner) : base(original, cloner) { }
    53     /// <summary>
    54     /// Initializes a new instance of <see cref="UniformSomePositionsManipulator"/> with two parameters
    55     /// (<c>Minimum</c> and <c>Maximum</c>).
    56     /// </summary>
    5747    public UniformSomePositionsManipulator()
    5848      : base() {
    59       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."));
    6049      Parameters.Add(new ValueLookupParameter<DoubleValue>("Probability", "The probability for each dimension to be manipulated.", new DoubleValue(0.5)));
    6150    }
     
    7968        if (random.NextDouble() < probability) {
    8069          atLeastOneManipulated = true;
    81           Manipulate(random, vector, bounds, index);
     70          UniformOnePositionManipulator.Manipulate(random, vector, bounds, index);
    8271        }
    8372      }
    8473
    8574      if (!atLeastOneManipulated) {
    86         Manipulate(random, vector, bounds, random.Next(vector.Length));
     75        UniformOnePositionManipulator.Manipulate(random, vector, bounds, random.Next(vector.Length));
    8776      }
    88     }
    89 
    90     private static void Manipulate(IRandom random, IntegerVector vector, IntMatrix bounds, int index) {
    91       int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
    92       if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
    93       int value = (max - min) / step;
    94       vector[index] = random.Next(value) * step + min;
    9577    }
    9678
     
    10183    /// <param name="random">A random number generator.</param>
    10284    /// <param name="vector">The integer vector to manipulate.</param>
    103     protected override void Manipulate(IRandom random, IntegerVector vector) {
    104       if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("UniformSomePositionsManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    105       Apply(random, vector, BoundsParameter.ActualValue, ProbabilityParameter.ActualValue.Value);
     85    protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
     86      Apply(random, vector, bounds, ProbabilityParameter.ActualValue.Value);
    10687    }
    10788  }
Note: See TracChangeset for help on using the changeset viewer.