Changeset 16331
 Timestamp:
 11/27/18 10:54:35 (17 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16330 r16331 166 166 private Interval Evaluate(Instruction[] instructions, Dictionary<ISymbolicExpressionTreeNode, Interval> intervals = null) { 167 167 Instruction currentInstr = instructions[InstructionCount++]; 168 Interval intermediate = null; 169 168 170 switch (currentInstr.opCode) { 169 171 //Elementary arithmetic rules 170 172 case OpCodes.Add: { 171 var s = Evaluate(instructions, intervals); 172 for (int i = 1; i < currentInstr.nArguments; i++) { 173 s = Interval.Add(s, Evaluate(instructions, intervals)); 174 } 175 intervals.Add(currentInstr.dynamicNode, s); 176 return s; 173 intermediate = Evaluate(instructions, intervals); 174 for (int i = 1; i < currentInstr.nArguments; i++) { 175 intermediate = Interval.Add(intermediate, Evaluate(instructions, intervals)); 176 } 177 break; 177 178 } 178 179 case OpCodes.Sub: { 179 var s = Evaluate(instructions, intervals); 180 for (int i = 1; i < currentInstr.nArguments; i++) { 181 s = Interval.Subtract(s, Evaluate(instructions, intervals)); 182 } 183 intervals.Add(currentInstr.dynamicNode, s); 184 return s; 180 intermediate = Evaluate(instructions, intervals); 181 for (int i = 1; i < currentInstr.nArguments; i++) { 182 intermediate = Interval.Subtract(intermediate, Evaluate(instructions, intervals)); 183 } 184 break; 185 185 } 186 186 case OpCodes.Mul: { 187 var s = Evaluate(instructions, intervals); 188 for (int i = 1; i < currentInstr.nArguments; i++) { 189 s = Interval.Multiply(s, Evaluate(instructions, intervals)); 190 } 191 intervals.Add(currentInstr.dynamicNode, s); 192 return s; 187 intermediate = Evaluate(instructions, intervals); 188 for (int i = 1; i < currentInstr.nArguments; i++) { 189 intermediate = Interval.Multiply(intermediate, Evaluate(instructions, intervals)); 190 } 191 break; 193 192 } 194 193 case OpCodes.Div: { 195 var s = Evaluate(instructions, intervals); 196 for (int i = 1; i < currentInstr.nArguments; i++) { 197 s = Interval.Divide(s, Evaluate(instructions, intervals)); 198 } 199 intervals.Add(currentInstr.dynamicNode, s); 200 return s; 194 intermediate = Evaluate(instructions, intervals); 195 for (int i = 1; i < currentInstr.nArguments; i++) { 196 intermediate = Interval.Divide(intermediate, Evaluate(instructions, intervals)); 197 } 198 break; 201 199 } 202 200 //Trigonometric functions 203 201 case OpCodes.Sin: { 204 var s = Interval.Sine(Evaluate(instructions, intervals)); 205 intervals.Add(currentInstr.dynamicNode, s); 206 return s; 202 intermediate = Interval.Sine(Evaluate(instructions, intervals)); 203 break; 207 204 } 208 205 case OpCodes.Cos: { 209 var s = Interval.Cosine(Evaluate(instructions, intervals)); 210 intervals.Add(currentInstr.dynamicNode, s); 211 return s; 206 intermediate = Interval.Cosine(Evaluate(instructions, intervals)); 207 break; 212 208 } 213 209 case OpCodes.Tan: { 214 var s = Interval.Tangens(Evaluate(instructions, intervals)); 215 intervals.Add(currentInstr.dynamicNode, s); 216 return s; 210 intermediate = Interval.Tangens(Evaluate(instructions, intervals)); 211 break; 217 212 } 218 213 //Exponential functions 219 214 case OpCodes.Log: { 220 var s = Interval.Logarithm(Evaluate(instructions, intervals)); 221 intervals.Add(currentInstr.dynamicNode, s); 222 return s; 215 intermediate = Interval.Logarithm(Evaluate(instructions, intervals)); 216 break; 223 217 } 224 218 case OpCodes.Exp: { 225 var s = Interval.Exponential(Evaluate(instructions, intervals)); 226 intervals.Add(currentInstr.dynamicNode, s); 227 return s; 219 intermediate = Interval.Exponential(Evaluate(instructions, intervals)); 220 break; 228 221 } 229 222 case OpCodes.Power: { 230 var s = Evaluate(instructions, intervals); 231 for (int i = 1; i < currentInstr.nArguments; i++) { 232 s = Interval.Power(s, Evaluate(instructions, intervals)); 233 } 234 intervals.Add(currentInstr.dynamicNode, s); 235 return s; 223 intermediate = Evaluate(instructions, intervals); 224 for (int i = 1; i < currentInstr.nArguments; i++) { 225 intermediate = Interval.Power(intermediate, Evaluate(instructions, intervals)); 226 } 227 break; 236 228 } 237 229 case OpCodes.Square: { 238 var s = Interval.Square(Evaluate(instructions, intervals)); 239 intervals.Add(currentInstr.dynamicNode, s); 240 return s; 230 intermediate = Interval.Square(Evaluate(instructions, intervals)); 231 break; 241 232 } 242 233 case OpCodes.Root: { 243 var s = Evaluate(instructions, intervals); 244 for (int i = 1; i < currentInstr.nArguments; i++) { 245 s = Interval.Root(s, Evaluate(instructions, intervals)); 246 } 247 intervals.Add(currentInstr.dynamicNode, s); 248 return s; 234 intermediate = Evaluate(instructions, intervals); 235 for (int i = 1; i < currentInstr.nArguments; i++) { 236 intermediate = Interval.Root(intermediate, Evaluate(instructions, intervals)); 237 } 238 break; 249 239 } 250 240 case OpCodes.SquareRoot: { 251 var s = Interval.SquareRoot(Evaluate(instructions, intervals)); 252 intervals.Add(currentInstr.dynamicNode, s); 253 return s; 241 intermediate = Interval.SquareRoot(Evaluate(instructions, intervals)); 242 break; 254 243 } 255 244 //Variables, Constants, ... … … 267 256 throw new NotSupportedException("Tree contains an unknown symbol."); 268 257 } 258 259 if (intervals != null) 260 intervals.Add(currentInstr.dynamicNode, intermediate); 261 return intermediate; 269 262 } 270 263
Note: See TracChangeset
for help on using the changeset viewer.