- Timestamp:
- 08/31/11 17:42:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionFormulaModifer.cs
r6670 r6687 20 20 public ValueParameter<StringValue> ResultNameParameter { 21 21 get { return (ValueParameter<StringValue>)Parameters["ResultName"]; } 22 } 23 22 } 23 24 24 public ValueParameter<StringValue> FormulaParameter { 25 25 get { return (ValueParameter<StringValue>)Parameters["Formula"]; } 26 } 26 } 27 27 28 #region Construction & Cloning 28 private string ResultName { get { return ResultNameParameter.Value.Value; } } 29 private string Formula { get { return FormulaParameter.Value.Value; } } 30 31 #region Construction & Cloning 29 32 [StorableConstructor] 30 33 protected RunCollectionFormulaModifer(bool deserializing) : base(deserializing) { } … … 35 38 public RunCollectionFormulaModifer() { 36 39 Parameters.Add(new ValueParameter<StringValue>("ResultName", "The name of the result to be generated by this formula.", new StringValue("Calc.Value"))); 37 Parameters.Add(new ValueParameter<StringValue>("Formula", "RPN formula for new value. This can contain existing run parameters or results (optionally in quotes if they contain whitespace), numbers and arithmetic operators in postfix notation.", new StringValue("1 1 +"))); 40 Parameters.Add(new ValueParameter<StringValue>("Formula", 41 @"RPN formula for new value in postfix notation. 42 43 This can contain the following elements: 44 45 literals: 46 numbers, true, false, null and strings in single quotes 47 variables (run parameters or results): 48 unquoted or in double quotes if they contain special characters or whitespace 49 mathematical functions: 50 +, -, /, ^ (power), log 51 predicates: 52 ==, <, >, isnull, not 53 stack manipulation: 54 drop swap dup 55 string matching: 56 <string> <pattern> ismatch 57 string replacing: 58 <string> <pattern> <replacement> rename 59 conditionals: 60 <then> <else> <condition> if 61 62 If the final value is null, the result variable is removed if it exists.", 63 new StringValue("1 1 +"))); 38 64 UpdateName(); 39 65 RegisterEvents(); … … 58 84 59 85 private void UpdateName() { 60 name = string.Format("{0} := {1}", ResultName Parameter.Value.Value, FormulaParameter.Value.Value);86 name = string.Format("{0} := {1}", ResultName, Formula); 61 87 OnNameChanged(); 62 88 } 63 89 64 90 public void Modify(List<IRun> runs) { 65 var calc = new Calculator { Formula = FormulaParameter.Value.Value};91 var calc = new Calculator { Formula = Formula }; 66 92 foreach (var run in runs) { 67 93 var variables = new Dictionary<string, IItem>(); … … 70 96 foreach (var result in run.Results) 71 97 variables[result.Key] = result.Value; 72 run.Results[ResultNameParameter.Value.Value] = calc.GetValue(variables); 73 } 98 var value = calc.GetValue(variables); 99 if (value != null) 100 run.Results[ResultName] = value; 101 else 102 run.Results.Remove(ResultName); 103 } 74 104 } 75 105 76 106 } 77 107 }
Note: See TracChangeset
for help on using the changeset viewer.