- Timestamp:
- 06/17/12 13:38:17 (12 years ago)
- 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 94 94 crossover.RandomParameter.ActualName = RandomParameter.Name; 95 95 } 96 foreach (IBoundedIntegerVectorOperator crossover in Operators.OfType<IBoundedIntegerVectorOperator>()) { 97 crossover.BoundsParameter.ActualName = BoundsParameter.Name; 98 } 96 99 } 97 100 -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj
r7699 r8017 150 150 </ItemGroup> 151 151 <ItemGroup> 152 <Compile Include="BoundedIntegerVectorCrossover.cs" /> 153 <Compile Include="BoundedIntegerVectorManipulator.cs" /> 152 154 <Compile Include="Creators\UniformRandomIntegerVectorCreator.cs" /> 153 <Compile Include="Crossovers\ AverageCrossover.cs" />155 <Compile Include="Crossovers\RoundedAverageCrossover.cs" /> 154 156 <Compile Include="Crossovers\DiscreteCrossover.cs"> 155 157 <SubType>Code</SubType> 156 158 </Compile> 157 159 <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" /> 158 164 <Compile Include="Crossovers\SinglePointCrossover.cs"> 159 165 <SubType>Code</SubType> 160 166 </Compile> 161 <Compile Include="Crossovers\UniformAllPositionsArithmeticCrossover.cs" /> 162 <Compile Include="Crossovers\UniformSomePositionsArithmeticCrossover.cs" /> 167 <Compile Include="Crossovers\RoundedUniformArithmeticCrossover.cs" /> 163 168 <Compile Include="Interfaces\IBoundedIntegerVectorOperator.cs" /> 164 169 <Compile Include="Interfaces\IIntegerVectorCreator.cs" /> -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IBoundedIntegerVectorOperator.cs
r7681 r8017 25 25 namespace HeuristicLab.Encodings.IntegerVectorEncoding { 26 26 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> 27 30 IValueLookupParameter<IntMatrix> BoundsParameter { get; } 28 31 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs
r7715 r8017 35 35 [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.")] 36 36 [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 { 42 38 43 39 public IValueParameter<DoubleArray> SigmaParameter { … … 54 50 public RoundedNormalAllPositionsManipulator() 55 51 : 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."));57 52 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 }))); 58 53 } … … 69 64 /// <param name="sigma">The sigma vector determining the strength of the mutation.</param> 70 65 /// <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> 72 68 /// <returns>The manipulated integer vector.</returns> 73 69 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"); 75 71 if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds"); 76 72 var N = new NormalDistributedRandom(random, 0.0, 1.0); … … 80 76 81 77 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); 83 79 } 84 80 } … … 89 85 /// <param name="random">The random number generator.</param> 90 86 /// <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); 93 90 } 94 91 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/SelfAdaptiveRoundedNormalAllPositionsManipulator.cs
r7715 r8017 36 36 [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.")] 37 37 [StorableClass] 38 public class SelfAdaptiveRoundedNormalAllPositionsManipulator : IntegerVectorManipulator, ISelfAdaptiveManipulator {38 public class SelfAdaptiveRoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator, ISelfAdaptiveManipulator { 39 39 public Type StrategyParameterType { 40 40 get { return typeof(IIntegerVectorStdDevStrategyParameterOperator); } … … 51 51 } 52 52 53 public IValueLookupParameter<IntMatrix> BoundsParameter {54 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }55 }56 57 53 [StorableConstructor] 58 54 protected SelfAdaptiveRoundedNormalAllPositionsManipulator(bool deserializing) : base(deserializing) { } … … 64 60 : base() { 65 61 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."));67 62 } 68 63 … … 80 75 /// <param name="random">A random number generator.</param> 81 76 /// <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> 82 78 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"); 85 81 var N = new NormalDistributedRandom(random, 0.0, 1.0); 86 82 if (strategyParameters != null) { … … 90 86 91 87 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); 93 89 } 94 90 } … … 100 96 /// <param name="random">The random number generator.</param> 101 97 /// <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); 104 101 } 105 102 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs
r7686 r8017 36 36 [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.")] 37 37 [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 { 45 39 46 40 [StorableConstructor] … … 51 45 /// (<c>Minimum</c> and <c>Maximum</c>). 52 46 /// </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() { } 57 48 58 49 public override IDeepCloneable Clone(Cloner cloner) { … … 86 77 /// <param name="max">The maximum value of the sampling range for 87 78 /// 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> 88 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) { 89 85 if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("UniformOnePositionManipulator: Invalid bounds specified", "bounds"); 90 int index = random.Next(vector.Length);91 86 int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1; 92 87 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)); 95 89 } 96 90 … … 101 95 /// <param name="random">A random number generator.</param> 102 96 /// <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) { 104 99 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); 106 101 } 107 102 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformSomePositionsManipulator.cs
r7699 r8017 34 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 35 /// </remarks> 36 [Item("UniformSomePositionsManipulator", " 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.")] 37 37 [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 { 45 39 46 40 public IValueLookupParameter<DoubleValue> ProbabilityParameter { … … 51 45 protected UniformSomePositionsManipulator(bool deserializing) : base(deserializing) { } 52 46 protected UniformSomePositionsManipulator(UniformSomePositionsManipulator original, Cloner cloner) : base(original, cloner) { } 53 /// <summary>54 /// Initializes a new instance of <see cref="UniformSomePositionsManipulator"/> with two parameters55 /// (<c>Minimum</c> and <c>Maximum</c>).56 /// </summary>57 47 public UniformSomePositionsManipulator() 58 48 : 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."));60 49 Parameters.Add(new ValueLookupParameter<DoubleValue>("Probability", "The probability for each dimension to be manipulated.", new DoubleValue(0.5))); 61 50 } … … 79 68 if (random.NextDouble() < probability) { 80 69 atLeastOneManipulated = true; 81 Manipulate(random, vector, bounds, index);70 UniformOnePositionManipulator.Manipulate(random, vector, bounds, index); 82 71 } 83 72 } 84 73 85 74 if (!atLeastOneManipulated) { 86 Manipulate(random, vector, bounds, random.Next(vector.Length));75 UniformOnePositionManipulator.Manipulate(random, vector, bounds, random.Next(vector.Length)); 87 76 } 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;95 77 } 96 78 … … 101 83 /// <param name="random">A random number generator.</param> 102 84 /// <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); 106 87 } 107 88 }
Note: See TracChangeset
for help on using the changeset viewer.