- Timestamp:
- 04/02/12 00:29:39 (13 years ago)
- 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 49 49 /// <param name="max">The maximum value of the sampling range for each vector element (exclusive).</param> 50 50 /// <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; 56 55 } 57 56 … … 61 60 /// <param name="random">The pseudo random number generator to use.</param> 62 61 /// <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> 65 63 /// <returns>The newly created int vector.</returns> 66 protected override IntegerVector Create(IRandom random, IntValue length, Int Value 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); 68 66 } 69 67 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs
r7259 r7681 34 34 [Item("MultiIntegerVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 35 35 [StorableClass] 36 public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator {36 public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator, IBoundedIntegerVectorOperator { 37 37 public override bool CanChangeName { 38 38 get { return false; } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r7259 r7681 54 54 public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) { 55 55 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."); 57 57 58 58 int length = parent1.Length; -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs
r7259 r7681 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 49 50 } 50 51 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) { 52 53 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 } 55 58 OnReset(); 56 59 } 57 60 } 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); 60 77 } 61 78 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCreator.cs
r7259 r7681 47 47 get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; } 48 48 } 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"]; } 54 51 } 55 52 … … 62 59 Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The vector which should be manipulated.")); 63 60 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.")); 66 62 } 67 63 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 68 76 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); 70 78 return base.Apply(); 71 79 } 72 80 73 protected abstract IntegerVector Create(IRandom random, IntValue length, Int Value minimum, IntValue maximum);81 protected abstract IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds); 74 82 } 75 83 } -
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCreator.cs
r7259 r7681 28 28 /// An interface which represents an operator for creating vectors of int-valued data. 29 29 /// </summary> 30 public interface IIntegerVectorCreator : I IntegerVectorOperator, ISolutionCreator {30 public interface IIntegerVectorCreator : ISolutionCreator, IBoundedIntegerVectorOperator { 31 31 IValueLookupParameter<IntValue> LengthParameter { get; } 32 IValueLookupParameter<IntValue> MinimumParameter { get; }33 IValueLookupParameter<IntValue> MaximumParameter { get; }34 32 ILookupParameter<IntegerVector> IntegerVectorParameter { get; } 35 33 }
Note: See TracChangeset
for help on using the changeset viewer.