Changeset 16376
- Timestamp:
- 12/13/18 09:38:32 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16374 r16376 38 38 39 39 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 40 private static int InstructionCount = 0;41 40 42 41 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { … … 72 71 #endregion 73 72 74 private static void ResetInstrucitonCount() {75 InstructionCount = 0;76 }77 78 79 73 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) { 80 74 lock (syncRoot) { 81 75 EvaluatedSolutions++; 82 ResetInstrucitonCount();83 }76 } 77 int instructionCount = 0; 84 78 var intervalBoundaries = DatasetUtil.GetVariableBoundaries(dataset, rows); 85 79 var instructions = PrepareInterpreterState(tree, intervalBoundaries); 86 var x = Evaluate(instructions );80 var x = Evaluate(instructions, ref instructionCount); 87 81 88 82 return x; … … 93 87 lock (syncRoot) { 94 88 EvaluatedSolutions++; 95 ResetInstrucitonCount();96 }89 } 90 int instructionCount = 0; 97 91 var intervalBoundaries = DatasetUtil.GetVariableBoundaries(dataset, rows); 98 92 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 99 93 var instructions = PrepareInterpreterState(tree, intervalBoundaries); 100 var x = Evaluate(instructions, intervals);94 var x = Evaluate(instructions, ref instructionCount, intervals); 101 95 102 96 return x; … … 106 100 lock (syncRoot) { 107 101 EvaluatedSolutions++; 108 ResetInstrucitonCount();109 }102 } 103 int instructionCount = 0; 110 104 var instructions = PrepareInterpreterState(tree, customIntervals); 111 var x = Evaluate(instructions );105 var x = Evaluate(instructions, ref instructionCount); 112 106 113 107 return x; … … 119 113 lock (syncRoot) { 120 114 EvaluatedSolutions++; 121 ResetInstrucitonCount();122 }115 } 116 int instructionCount = 0; 123 117 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 124 118 var instructions = PrepareInterpreterState(tree, customIntervals); 125 var x = Evaluate(instructions, intervals);119 var x = Evaluate(instructions, ref instructionCount, intervals); 126 120 127 121 return x; … … 146 140 } 147 141 148 private Interval Evaluate(Instruction[] instructions, Dictionary<ISymbolicExpressionTreeNode,142 private Interval Evaluate(Instruction[] instructions, ref int instructionCount, Dictionary<ISymbolicExpressionTreeNode, 149 143 Interval> intervals = null) { 150 Instruction currentInstr = instructions[ InstructionCount++];144 Instruction currentInstr = instructions[instructionCount++]; 151 145 Interval result = null; 152 146 … … 154 148 //Elementary arithmetic rules 155 149 case OpCodes.Add: { 156 result = Evaluate(instructions, intervals);157 for (int i = 1; i < currentInstr.nArguments; i++) { 158 result = Interval.Add(result, Evaluate(instructions, intervals));150 result = Evaluate(instructions, ref instructionCount, intervals); 151 for (int i = 1; i < currentInstr.nArguments; i++) { 152 result = Interval.Add(result, Evaluate(instructions, ref instructionCount, intervals)); 159 153 } 160 154 break; 161 155 } 162 156 case OpCodes.Sub: { 163 result = Evaluate(instructions, intervals);164 for (int i = 1; i < currentInstr.nArguments; i++) { 165 result = Interval.Subtract(result, Evaluate(instructions, intervals));157 result = Evaluate(instructions, ref instructionCount, intervals); 158 for (int i = 1; i < currentInstr.nArguments; i++) { 159 result = Interval.Subtract(result, Evaluate(instructions, ref instructionCount, intervals)); 166 160 } 167 161 break; 168 162 } 169 163 case OpCodes.Mul: { 170 result = Evaluate(instructions, intervals);171 for (int i = 1; i < currentInstr.nArguments; i++) { 172 result = Interval.Multiply(result, Evaluate(instructions, intervals));164 result = Evaluate(instructions, ref instructionCount, intervals); 165 for (int i = 1; i < currentInstr.nArguments; i++) { 166 result = Interval.Multiply(result, Evaluate(instructions, ref instructionCount, intervals)); 173 167 } 174 168 break; 175 169 } 176 170 case OpCodes.Div: { 177 result = Evaluate(instructions, intervals);178 for (int i = 1; i < currentInstr.nArguments; i++) { 179 result = Interval.Divide(result, Evaluate(instructions, intervals));171 result = Evaluate(instructions, ref instructionCount, intervals); 172 for (int i = 1; i < currentInstr.nArguments; i++) { 173 result = Interval.Divide(result, Evaluate(instructions, ref instructionCount, intervals)); 180 174 } 181 175 break; … … 183 177 //Trigonometric functions 184 178 case OpCodes.Sin: { 185 result = Interval.Sine(Evaluate(instructions, intervals));179 result = Interval.Sine(Evaluate(instructions, ref instructionCount, intervals)); 186 180 break; 187 181 } 188 182 case OpCodes.Cos: { 189 result = Interval.Cosine(Evaluate(instructions, intervals));183 result = Interval.Cosine(Evaluate(instructions, ref instructionCount, intervals)); 190 184 break; 191 185 } 192 186 case OpCodes.Tan: { 193 result = Interval.Tangens(Evaluate(instructions, intervals));187 result = Interval.Tangens(Evaluate(instructions, ref instructionCount, intervals)); 194 188 break; 195 189 } 196 190 //Exponential functions 197 191 case OpCodes.Log: { 198 result = Interval.Logarithm(Evaluate(instructions, intervals));192 result = Interval.Logarithm(Evaluate(instructions, ref instructionCount, intervals)); 199 193 break; 200 194 } 201 195 case OpCodes.Exp: { 202 result = Interval.Exponential(Evaluate(instructions, intervals));196 result = Interval.Exponential(Evaluate(instructions, ref instructionCount, intervals)); 203 197 break; 204 198 } 205 199 case OpCodes.Power: { 206 result = Evaluate(instructions, intervals);207 for (int i = 1; i < currentInstr.nArguments; i++) { 208 result = Interval.Power(result, Evaluate(instructions, intervals));200 result = Evaluate(instructions, ref instructionCount, intervals); 201 for (int i = 1; i < currentInstr.nArguments; i++) { 202 result = Interval.Power(result, Evaluate(instructions, ref instructionCount, intervals)); 209 203 } 210 204 break; 211 205 } 212 206 case OpCodes.Square: { 213 result = Interval.Square(Evaluate(instructions, intervals));207 result = Interval.Square(Evaluate(instructions, ref instructionCount, intervals)); 214 208 break; 215 209 } 216 210 case OpCodes.Root: { 217 result = Evaluate(instructions, intervals);218 for (int i = 1; i < currentInstr.nArguments; i++) { 219 result = Interval.Root(result, Evaluate(instructions, intervals));211 result = Evaluate(instructions, ref instructionCount, intervals); 212 for (int i = 1; i < currentInstr.nArguments; i++) { 213 result = Interval.Root(result, Evaluate(instructions, ref instructionCount, intervals)); 220 214 } 221 215 break; 222 216 } 223 217 case OpCodes.SquareRoot: { 224 result = Interval.SquareRoot(Evaluate(instructions, intervals));218 result = Interval.SquareRoot(Evaluate(instructions, ref instructionCount, intervals)); 225 219 break; 226 220 }
Note: See TracChangeset
for help on using the changeset viewer.