Changeset 8085 for branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators
- Timestamp:
- 06/21/12 18:02:33 (13 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 3 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding merged eligible /branches/Benchmarking/sources/HeuristicLab.Encodings.IntegerVectorEncoding 6917-7005 /branches/CloningRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Encodings.IntegerVectorEncoding 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Encodings.IntegerVectorEncoding 5815-6180 /branches/DataAnalysis/HeuristicLab.Encodings.IntegerVectorEncoding 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Encodings.IntegerVectorEncoding 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.IntegerVectorEncoding 5060 /branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding 7681-8018 /branches/NET40/sources/HeuristicLab.Encodings.IntegerVectorEncoding 5138-5162 /branches/ParallelEngine/HeuristicLab.Encodings.IntegerVectorEncoding 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Encodings.IntegerVectorEncoding 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Encodings.IntegerVectorEncoding 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Encodings.IntegerVectorEncoding 6828 /branches/SuccessProgressAnalysis/HeuristicLab.Encodings.IntegerVectorEncoding 5370-5682 /branches/Trunk/HeuristicLab.Encodings.IntegerVectorEncoding 6829-6865 /branches/VNS/HeuristicLab.Encodings.IntegerVectorEncoding 5594-5752 /branches/histogram/HeuristicLab.Encodings.IntegerVectorEncoding 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs
r7259 r8085 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 { 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 { 51 39 52 40 [StorableConstructor] … … 57 45 /// (<c>Minimum</c> and <c>Maximum</c>). 58 46 /// </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() { } 64 48 65 49 public override IDeepCloneable Clone(Cloner cloner) { 66 50 return new UniformOnePositionManipulator(this, cloner); 67 51 } 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 68 69 69 70 /// <summary> … … 76 77 /// <param name="max">The maximum value of the sampling range for 77 78 /// 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)); 81 89 } 82 90 … … 87 95 /// <param name="random">A random number generator.</param> 88 96 /// <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); 93 101 } 94 102 }
Note: See TracChangeset
for help on using the changeset viewer.