Changeset 6878 for branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/RunCollectionFormulaModifer.cs
- Timestamp:
- 10/05/11 21:55:55 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP
- Property svn:ignore
-
old new 1 *.docstates 2 *.psess 1 3 *.resharper 2 4 *.suo 5 *.vsp 3 6 Google.ProtocolBuffers-0.9.1.dll 7 HeuristicLab 3.3.5.1.ReSharper.user 8 HeuristicLab 3.3.6.0.ReSharper.user 4 9 HeuristicLab.4.5.resharper.user 5 10 HeuristicLab.resharper.user … … 8 13 _ReSharper.HeuristicLab 9 14 _ReSharper.HeuristicLab 3.3 15 _ReSharper.HeuristicLab.ExtLibs 16 bin 10 17 protoc.exe 11 HeuristicLab 3.3.5.1.ReSharper.user 12 *.psess 13 *.vsp 14 *.docstates 18 HeuristicLab.ExtLibs.6.0.ReSharper.user
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3
- Property svn:ignore
-
old new 4 4 *.user 5 5 *.vs10x 6 Plugin.cs
-
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/RunCollectionFormulaModifer.cs
r6685 r6878 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.