Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/15 09:46:33 (10 years ago)
Author:
ascheibe
Message:

#2342 merged r12072 into stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Operators/3.3/DataReducer.cs

    r12009 r12132  
    4040      get { return (LookupParameter<IItem>)Parameters["TargetParameter"]; }
    4141    }
    42     public ValueParameter<ReductionOperation> ReductionOperation {
    43       get { return (ValueParameter<ReductionOperation>)Parameters["ReductionOperation"]; }
    44     }
    45     public ValueParameter<ReductionOperation> TargetOperation {
    46       get { return (ValueParameter<ReductionOperation>)Parameters["TargetOperation"]; }
     42    public ValueLookupParameter<ReductionOperation> ReductionOperation {
     43      get { return (ValueLookupParameter<ReductionOperation>)Parameters["ReductionOperation"]; }
     44    }
     45    public ValueLookupParameter<ReductionOperation> TargetOperation {
     46      get { return (ValueLookupParameter<ReductionOperation>)Parameters["TargetOperation"]; }
    4747    }
    4848    #endregion
     
    5858      Parameters.Add(new ScopeTreeLookupParameter<IItem>("ParameterToReduce", "The parameter on which the reduction operation should be applied."));
    5959      Parameters.Add(new LookupParameter<IItem>("TargetParameter", "The target variable in which the reduced value should be stored."));
    60       Parameters.Add(new ValueParameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce."));
    61       Parameters.Add(new ValueParameter<ReductionOperation>("TargetOperation", "The operation used to apply the reduced value to the target variable."));
     60      Parameters.Add(new ValueLookupParameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce.", new ReductionOperation()));
     61      Parameters.Add(new ValueLookupParameter<ReductionOperation>("TargetOperation", "The operation used to apply the reduced value to the target variable.", new ReductionOperation()));
    6262      #endregion
    6363    }
     
    6565    public override IDeepCloneable Clone(Cloner cloner) {
    6666      return new DataReducer(this, cloner);
     67    }
     68
     69    [StorableHook(HookType.AfterDeserialization)]
     70    private void AfterDeserialization() {
     71      // BackwardsCompatibility3.3
     72      var oldReductionOperation = Parameters["ReductionOperation"] as ValueParameter<ReductionOperation>;
     73      if (oldReductionOperation != null) {
     74        Parameters.Remove("ReductionOperation");
     75        Parameters.Add(new ValueLookupParameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce.", oldReductionOperation.Value));
     76      }
     77      var oldTargetOperation = Parameters["TargetOperation"] as ValueParameter<ReductionOperation>;
     78      if (oldTargetOperation != null) {
     79        Parameters.Remove("TargetOperation");
     80        Parameters.Add(new ValueLookupParameter<ReductionOperation>("TargetOperation", "The operation used to apply the reduced value to the target variable.", oldTargetOperation.Value));
     81      }
    6782    }
    6883
     
    89104    private void CalculateResult(IEnumerable<int> values, Type targetType) {
    90105      int result;
    91       switch (ReductionOperation.Value.Value) {
     106      switch (ReductionOperation.ActualValue.Value) {
    92107        case ReductionOperations.Sum:
    93108          result = values.Sum();
     
    112127          break;
    113128        default:
    114           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     129          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.ActualValue.Value, targetType));
    115130      }
    116131
    117132      IntValue target;
    118       switch (TargetOperation.Value.Value) {
     133      switch (TargetOperation.ActualValue.Value) {
    119134        case ReductionOperations.Sum:
    120135          target = InitializeTarget<IntValue, int>(targetType, 0);
     
    142157          break;
    143158        default:
    144           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     159          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.ActualValue.Value, targetType));
    145160      }
    146161    }
     
    149164    private void CalculateResult(IEnumerable<double> values, Type targetType) {
    150165      double result;
    151       switch (ReductionOperation.Value.Value) {
     166      switch (ReductionOperation.ActualValue.Value) {
    152167        case ReductionOperations.Sum:
    153168          result = values.Sum();
     
    172187          break;
    173188        default:
    174           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     189          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.ActualValue.Value, targetType));
    175190      }
    176191
    177192      DoubleValue target;
    178       switch (TargetOperation.Value.Value) {
     193      switch (TargetOperation.ActualValue.Value) {
    179194        case ReductionOperations.Sum:
    180195          target = InitializeTarget<DoubleValue, double>(targetType, 0.0);
     
    202217          break;
    203218        default:
    204           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     219          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.ActualValue.Value, targetType));
    205220      }
    206221    }
     
    209224    private void CalculateResult(IEnumerable<TimeSpan> values, Type targetType) {
    210225      TimeSpan result;
    211       switch (ReductionOperation.Value.Value) {
     226      switch (ReductionOperation.ActualValue.Value) {
    212227        case ReductionOperations.Sum:
    213228          result = values.Aggregate(new TimeSpan(), (x, y) => x + y);
     
    226241          break;
    227242        default:
    228           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     243          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.ActualValue.Value, targetType));
    229244      }
    230245
    231246      TimeSpanValue target;
    232       switch (TargetOperation.Value.Value) {
     247      switch (TargetOperation.ActualValue.Value) {
    233248        case ReductionOperations.Sum:
    234249          target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, new TimeSpan());
     
    252267          break;
    253268        default:
    254           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     269          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.ActualValue.Value, targetType));
    255270      }
    256271    }
     
    259274    private void CalculateResult(IEnumerable<bool> values, Type targetType) {
    260275      bool result;
    261       switch (ReductionOperation.Value.Value) {
     276      switch (ReductionOperation.ActualValue.Value) {
    262277        case ReductionOperations.All:
    263278          result = values.All(x => x);
     
    267282          break;
    268283        default:
    269           throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.Value.Value, targetType));
     284          throw new InvalidOperationException(string.Format("Operation {0} is not supported as ReductionOperation for type: {1}.", ReductionOperation.ActualValue.Value, targetType));
    270285      }
    271286
    272287      BoolValue target;
    273       switch (TargetOperation.Value.Value) {
     288      switch (TargetOperation.ActualValue.Value) {
    274289        case ReductionOperations.Assign:
    275290          target = InitializeTarget<BoolValue, bool>(targetType, true);
     
    277292          break;
    278293        default:
    279           throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.Value.Value, targetType));
     294          throw new InvalidOperationException(string.Format("Operation {0} is not supported as TargetOperation for type: {1}.", TargetOperation.ActualValue.Value, targetType));
    280295      }
    281296    }
Note: See TracChangeset for help on using the changeset viewer.