- Timestamp:
- 03/05/15 09:46:33 (10 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12072
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Operators/3.3/DataReducer.cs
r12009 r12132 40 40 get { return (LookupParameter<IItem>)Parameters["TargetParameter"]; } 41 41 } 42 public Value Parameter<ReductionOperation> ReductionOperation {43 get { return (Value Parameter<ReductionOperation>)Parameters["ReductionOperation"]; }44 } 45 public Value Parameter<ReductionOperation> TargetOperation {46 get { return (Value Parameter<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"]; } 47 47 } 48 48 #endregion … … 58 58 Parameters.Add(new ScopeTreeLookupParameter<IItem>("ParameterToReduce", "The parameter on which the reduction operation should be applied.")); 59 59 Parameters.Add(new LookupParameter<IItem>("TargetParameter", "The target variable in which the reduced value should be stored.")); 60 Parameters.Add(new Value Parameter<ReductionOperation>("ReductionOperation", "The operation which is applied on the parameters to reduce."));61 Parameters.Add(new Value Parameter<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())); 62 62 #endregion 63 63 } … … 65 65 public override IDeepCloneable Clone(Cloner cloner) { 66 66 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 } 67 82 } 68 83 … … 89 104 private void CalculateResult(IEnumerable<int> values, Type targetType) { 90 105 int result; 91 switch (ReductionOperation. Value.Value) {106 switch (ReductionOperation.ActualValue.Value) { 92 107 case ReductionOperations.Sum: 93 108 result = values.Sum(); … … 112 127 break; 113 128 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)); 115 130 } 116 131 117 132 IntValue target; 118 switch (TargetOperation. Value.Value) {133 switch (TargetOperation.ActualValue.Value) { 119 134 case ReductionOperations.Sum: 120 135 target = InitializeTarget<IntValue, int>(targetType, 0); … … 142 157 break; 143 158 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)); 145 160 } 146 161 } … … 149 164 private void CalculateResult(IEnumerable<double> values, Type targetType) { 150 165 double result; 151 switch (ReductionOperation. Value.Value) {166 switch (ReductionOperation.ActualValue.Value) { 152 167 case ReductionOperations.Sum: 153 168 result = values.Sum(); … … 172 187 break; 173 188 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)); 175 190 } 176 191 177 192 DoubleValue target; 178 switch (TargetOperation. Value.Value) {193 switch (TargetOperation.ActualValue.Value) { 179 194 case ReductionOperations.Sum: 180 195 target = InitializeTarget<DoubleValue, double>(targetType, 0.0); … … 202 217 break; 203 218 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)); 205 220 } 206 221 } … … 209 224 private void CalculateResult(IEnumerable<TimeSpan> values, Type targetType) { 210 225 TimeSpan result; 211 switch (ReductionOperation. Value.Value) {226 switch (ReductionOperation.ActualValue.Value) { 212 227 case ReductionOperations.Sum: 213 228 result = values.Aggregate(new TimeSpan(), (x, y) => x + y); … … 226 241 break; 227 242 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)); 229 244 } 230 245 231 246 TimeSpanValue target; 232 switch (TargetOperation. Value.Value) {247 switch (TargetOperation.ActualValue.Value) { 233 248 case ReductionOperations.Sum: 234 249 target = InitializeTarget<TimeSpanValue, TimeSpan>(targetType, new TimeSpan()); … … 252 267 break; 253 268 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)); 255 270 } 256 271 } … … 259 274 private void CalculateResult(IEnumerable<bool> values, Type targetType) { 260 275 bool result; 261 switch (ReductionOperation. Value.Value) {276 switch (ReductionOperation.ActualValue.Value) { 262 277 case ReductionOperations.All: 263 278 result = values.All(x => x); … … 267 282 break; 268 283 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)); 270 285 } 271 286 272 287 BoolValue target; 273 switch (TargetOperation. Value.Value) {288 switch (TargetOperation.ActualValue.Value) { 274 289 case ReductionOperations.Assign: 275 290 target = InitializeTarget<BoolValue, bool>(targetType, true); … … 277 292 break; 278 293 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)); 280 295 } 281 296 }
Note: See TracChangeset
for help on using the changeset viewer.