- Timestamp:
- 02/04/11 20:11:06 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorCrossover.cs
r5382 r5434 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 51 52 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 52 53 } 53 p ublicOptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {54 protected OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter { 54 55 get { return (OptionalValueParameter<IRealVectorBoundsChecker>)Parameters["BoundsChecker"]; } 56 } 57 public IRealVectorBoundsChecker BoundsChecker { 58 get { return BoundsCheckerParameter.Value; } 59 set { BoundsCheckerParameter.Value = value; } 55 60 } 56 61 57 62 [StorableConstructor] 58 63 protected RealVectorCrossover(bool deserializing) : base(deserializing) { } 59 protected RealVectorCrossover(RealVectorCrossover original, Cloner cloner) : base(original, cloner) { } 64 protected RealVectorCrossover(RealVectorCrossover original, Cloner cloner) 65 : base(original, cloner) { 66 RegisterEventHandlers(); 67 } 60 68 protected RealVectorCrossover() 61 69 : base() { … … 67 75 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector.")); 68 76 Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker())); 77 78 RegisterEventHandlers(); 79 ParameterizeBoundsChecker(); 69 80 } 70 81 71 // BackwardsCompatibility3.372 #region Backwards compatible code (remove with 3.4)73 82 [StorableHook(HookType.AfterDeserialization)] 74 83 private void AfterDeserialization() { 75 if (!Parameters.ContainsKey("BoundsChecker")) 84 // BackwardsCompatibility3.3 85 #region Backwards compatible code (remove with 3.4) 86 if (!Parameters.ContainsKey("BoundsChecker")) { 76 87 Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker())); 88 ParameterizeBoundsChecker(); 89 } 90 #endregion 91 RegisterEventHandlers(); 77 92 } 78 #endregion 93 94 protected virtual void RegisterEventHandlers() { 95 BoundsCheckerParameter.ValueChanged += new System.EventHandler(BoundsCheckerParameter_ValueChanged); 96 } 79 97 80 98 public sealed override IOperation Apply() { … … 82 100 ChildParameter.ActualValue = result; 83 101 84 IRealVectorBoundsChecker checker = BoundsCheckerParameter.Value;85 102 IOperation successor = base.Apply(); 86 if (checker != null) { 87 checker.BoundsParameter.ActualName = BoundsParameter.ActualName; 88 checker.RealVectorParameter.ActualName = ChildParameter.ActualName; 89 IOperation checkerOperation = ExecutionContext.CreateChildOperation(checker); 103 if (BoundsChecker != null) { 104 IOperation checkerOperation = ExecutionContext.CreateChildOperation(BoundsChecker); 90 105 if (successor == null) return checkerOperation; 91 106 else return new OperationCollection(checkerOperation, successor); … … 94 109 95 110 protected abstract RealVector Cross(IRandom random, ItemArray<RealVector> parents); 111 112 protected virtual void BoundsCheckerParameter_ValueChanged(object sender, EventArgs e) { 113 ParameterizeBoundsChecker(); 114 } 115 116 protected virtual void ParameterizeBoundsChecker() { 117 if (BoundsChecker != null) { 118 BoundsChecker.BoundsParameter.ActualName = BoundsParameter.Name; 119 BoundsChecker.RealVectorParameter.ActualName = ChildParameter.Name; 120 } 121 } 96 122 } 97 123 } -
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.