Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5434 for trunk/sources


Ignore:
Timestamp:
02/04/11 20:11:06 (13 years ago)
Author:
abeham
Message:

#1395

  • Changed dynamic wiring into static wiring as discussed with swagner
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  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    5152      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5253    }
    53     public OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {
     54    protected OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {
    5455      get { return (OptionalValueParameter<IRealVectorBoundsChecker>)Parameters["BoundsChecker"]; }
     56    }
     57    public IRealVectorBoundsChecker BoundsChecker {
     58      get { return BoundsCheckerParameter.Value; }
     59      set { BoundsCheckerParameter.Value = value; }
    5560    }
    5661
    5762    [StorableConstructor]
    5863    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    }
    6068    protected RealVectorCrossover()
    6169      : base() {
     
    6775      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
    6876      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();
    6980    }
    7081
    71     // BackwardsCompatibility3.3
    72     #region Backwards compatible code (remove with 3.4)
    7382    [StorableHook(HookType.AfterDeserialization)]
    7483    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")) {
    7687        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();
    7792    }
    78     #endregion
     93
     94    protected virtual void RegisterEventHandlers() {
     95      BoundsCheckerParameter.ValueChanged += new System.EventHandler(BoundsCheckerParameter_ValueChanged);
     96    }
    7997
    8098    public sealed override IOperation Apply() {
     
    82100      ChildParameter.ActualValue = result;
    83101
    84       IRealVectorBoundsChecker checker = BoundsCheckerParameter.Value;
    85102      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);
    90105        if (successor == null) return checkerOperation;
    91106        else return new OperationCollection(checkerOperation, successor);
     
    94109
    95110    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    }
    96122  }
    97123}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorManipulator.cs

    r5382 r5434  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    4849      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    4950    }
    50     public OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {
     51    protected OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {
    5152      get { return (OptionalValueParameter<IRealVectorBoundsChecker>)Parameters["BoundsChecker"]; }
     53    }
     54    public IRealVectorBoundsChecker BoundsChecker {
     55      get { return BoundsCheckerParameter.Value; }
     56      set { BoundsCheckerParameter.Value = value; }
    5257    }
    5358
    5459    [StorableConstructor]
    5560    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    }
    5765    protected RealVectorManipulator()
    5866      : base() {
     
    6169      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
    6270      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();
    6374    }
    6475
    65     // BackwardsCompatibility3.3
    66     #region Backwards compatible code (remove with 3.4)
    6776    [StorableHook(HookType.AfterDeserialization)]
    6877    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")) {
    7081        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();
    7186    }
    72     #endregion
     87
     88    protected virtual void RegisterEventHandlers() {
     89      BoundsCheckerParameter.ValueChanged += new System.EventHandler(BoundsCheckerParameter_ValueChanged);
     90    }
    7391
    7492    public sealed override IOperation Apply() {
     
    7694      Manipulate(RandomParameter.ActualValue, vector);
    7795
    78       IRealVectorBoundsChecker checker = BoundsCheckerParameter.Value;
    7996      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);
    8499        if (successor == null) return checkerOperation;
    85100        else return new OperationCollection(checkerOperation, successor);
     
    88103
    89104    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    }
    90116  }
    91117}
Note: See TracChangeset for help on using the changeset viewer.