Changeset 5434 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorManipulator.cs
- Timestamp:
- 02/04/11 20:11:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorManipulator.cs
r5382 r5434 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 48 49 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 49 50 } 50 p ublicOptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {51 protected OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter { 51 52 get { return (OptionalValueParameter<IRealVectorBoundsChecker>)Parameters["BoundsChecker"]; } 53 } 54 public IRealVectorBoundsChecker BoundsChecker { 55 get { return BoundsCheckerParameter.Value; } 56 set { BoundsCheckerParameter.Value = value; } 52 57 } 53 58 54 59 [StorableConstructor] 55 60 protected RealVectorManipulator(bool deserializing) : base(deserializing) { } 56 protected RealVectorManipulator(RealVectorManipulator original, Cloner cloner) : base(original, cloner) { } 61 protected RealVectorManipulator(RealVectorManipulator original, Cloner cloner) 62 : base(original, cloner) { 63 RegisterEventHandlers(); 64 } 57 65 protected RealVectorManipulator() 58 66 : base() { … … 61 69 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector.")); 62 70 Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker())); 71 72 RegisterEventHandlers(); 73 ParameterizeBoundsChecker(); 63 74 } 64 75 65 // BackwardsCompatibility3.366 #region Backwards compatible code (remove with 3.4)67 76 [StorableHook(HookType.AfterDeserialization)] 68 77 private void AfterDeserialization() { 69 if (!Parameters.ContainsKey("BoundsChecker")) 78 // BackwardsCompatibility3.3 79 #region Backwards compatible code (remove with 3.4) 80 if (!Parameters.ContainsKey("BoundsChecker")) { 70 81 Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker())); 82 ParameterizeBoundsChecker(); 83 } 84 #endregion 85 RegisterEventHandlers(); 71 86 } 72 #endregion 87 88 protected virtual void RegisterEventHandlers() { 89 BoundsCheckerParameter.ValueChanged += new System.EventHandler(BoundsCheckerParameter_ValueChanged); 90 } 73 91 74 92 public sealed override IOperation Apply() { … … 76 94 Manipulate(RandomParameter.ActualValue, vector); 77 95 78 IRealVectorBoundsChecker checker = BoundsCheckerParameter.Value;79 96 IOperation successor = base.Apply(); 80 if (checker != null) { 81 checker.BoundsParameter.ActualName = BoundsParameter.ActualName; 82 checker.RealVectorParameter.ActualName = RealVectorParameter.ActualName; 83 IOperation checkerOperation = ExecutionContext.CreateChildOperation(checker); 97 if (BoundsChecker != null) { 98 IOperation checkerOperation = ExecutionContext.CreateChildOperation(BoundsChecker); 84 99 if (successor == null) return checkerOperation; 85 100 else return new OperationCollection(checkerOperation, successor); … … 88 103 89 104 protected abstract void Manipulate(IRandom random, RealVector realVector); 105 106 protected virtual void BoundsCheckerParameter_ValueChanged(object sender, EventArgs e) { 107 ParameterizeBoundsChecker(); 108 } 109 110 protected virtual void ParameterizeBoundsChecker() { 111 if (BoundsChecker != null) { 112 BoundsChecker.BoundsParameter.ActualName = BoundsParameter.Name; 113 BoundsChecker.RealVectorParameter.ActualName = RealVectorParameter.Name; 114 } 115 } 90 116 } 91 117 }
Note: See TracChangeset
for help on using the changeset viewer.