Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/10 05:23:56 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
Location:
trunk/sources/HeuristicLab.Operators/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r2740 r2756  
    3636  [Creatable("Test")]
    3737  public sealed class Counter : SingleSuccessorOperator {
    38     public ItemParameter<IntData> Value {
    39       get { return (ItemParameter<IntData>)Parameters["Value"]; }
     38    public LookupParameter<IntData> ValueParameter {
     39      get { return (LookupParameter<IntData>)Parameters["Value"]; }
    4040    }
    41     public ItemParameter<IntData> Increment {
    42       get { return (ItemParameter<IntData>)Parameters["Increment"]; }
     41    public ValueLookupParameter<IntData> IncrementParaneter {
     42      get { return (ValueLookupParameter<IntData>)Parameters["Increment"]; }
     43    }
     44    public IntData Increment {
     45      get { return IncrementParaneter.Value; }
     46      set { IncrementParaneter.Value = value; }
    4347    }
    4448
    4549    public Counter()
    4650      : base() {
    47       Parameters.Add(new ItemParameter<IntData>("Value", "The value which should be incremented."));
    48       Parameters.Add(new ItemParameter<IntData>("Increment", "The increment which is added to the value.", new IntData(1)));
     51      Parameters.Add(new LookupParameter<IntData>("Value", "The value which should be incremented."));
     52      Parameters.Add(new ValueLookupParameter<IntData>("Increment", "The increment which is added to the value.", new IntData(1)));
    4953    }
    5054
    5155    public override ExecutionContextCollection Apply() {
    52       IntData value = (IntData)Value.Value;
    53       IntData increment = (IntData)Increment.Value;
    54       value.Value += increment.Value;
     56      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntData();
     57      ValueParameter.ActualValue.Value += IncrementParaneter.ActualValue.Value;
    5558      return base.Apply();
    5659    }
  • trunk/sources/HeuristicLab.Operators/3.3/MultipleSuccessorsOperator.cs

    r2740 r2756  
    3838  [EmptyStorableClass]
    3939  public abstract class MultipleSuccessorsOperator : Operator {
    40     protected IOperatorParameter[] SuccessorParameters {
     40    protected IValueParameter<IOperator>[] SuccessorParameters {
    4141      get {
    4242        return (from p in Parameters
    43                 where p is IOperatorParameter
     43                where p is IValueParameter<IOperator>
    4444                orderby p.Name ascending
    45                 select (IOperatorParameter)p).ToArray();
     45                select (IValueParameter<IOperator>)p).ToArray();
    4646      }
    4747    }
     
    5353          successors = new OperatorList();
    5454          var opParams = SuccessorParameters;
    55           foreach (IOperatorParameter opParam in opParams) {
     55          foreach (IValueParameter<IOperator> opParam in opParams) {
    5656            opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    5757            successors.Add(opParam.Value);
     
    7373    private void UpdateOperatorParameters() {
    7474      var opParams = SuccessorParameters;
    75       foreach (IOperatorParameter opParam in opParams) {
     75      foreach (IValueParameter<IOperator> opParam in opParams) {
    7676        opParam.ValueChanged -= new EventHandler(opParam_ValueChanged);
    7777        Parameters.Remove(opParam.Name);
    7878      }
    7979      for (int i = 0; i < Successors.Count; i++) {
    80         IOperatorParameter opParam = new OperatorParameter(i.ToString(), string.Empty, Successors[i]);
     80        IValueParameter<IOperator> opParam = new OperatorParameter(i.ToString(), string.Empty, Successors[i]);
    8181        opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    8282        Parameters.Add(opParam);
     
    9292    private void successors_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) {
    9393      foreach (IndexedItem<IOperator> item in e.Items)
    94         ((IOperatorParameter)Parameters[item.Index.ToString()]).Value = item.Value;
     94        ((IValueParameter<IOperator>)Parameters[item.Index.ToString()]).Value = item.Value;
    9595    }
    9696    private void successors_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) {
    9797      foreach (IndexedItem<IOperator> item in e.Items)
    98         ((IOperatorParameter)Parameters[item.Index.ToString()]).Value = item.Value;
     98        ((IValueParameter<IOperator>)Parameters[item.Index.ToString()]).Value = item.Value;
    9999    }
    100100    private void successors_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) {
     
    102102    }
    103103    private void opParam_ValueChanged(object sender, EventArgs e) {
    104       IOperatorParameter opParam = (IOperatorParameter)sender;
     104      IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender;
    105105      int index = int.Parse(opParam.Name);
    106106      successors[index] = opParam.Value;
Note: See TracChangeset for help on using the changeset viewer.