Changeset 16376


Ignore:
Timestamp:
12/13/18 09:38:32 (7 months ago)
Author:
chaider
Message:

#2966 Removed member variable InstructionCount and added ref parameter to Evaluate method instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r16374 r16376  
    3838
    3939    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    40     private static int InstructionCount = 0;
    4140
    4241    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
     
    7271    #endregion
    7372
    74     private static void ResetInstrucitonCount() {
    75       InstructionCount = 0;
    76     }
    77 
    78 
    7973    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {
    8074      lock (syncRoot) {
    8175        EvaluatedSolutions++;
    82         ResetInstrucitonCount();
    83       }
     76      }
     77      int instructionCount = 0;
    8478      var intervalBoundaries = DatasetUtil.GetVariableBoundaries(dataset, rows);
    8579      var instructions = PrepareInterpreterState(tree, intervalBoundaries);
    86       var x = Evaluate(instructions);
     80      var x = Evaluate(instructions, ref instructionCount);
    8781
    8882      return x;
     
    9387      lock (syncRoot) {
    9488        EvaluatedSolutions++;
    95         ResetInstrucitonCount();
    96       }
     89      }
     90      int instructionCount = 0;
    9791      var intervalBoundaries = DatasetUtil.GetVariableBoundaries(dataset, rows);
    9892      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
    9993      var instructions = PrepareInterpreterState(tree, intervalBoundaries);
    100       var x = Evaluate(instructions, intervals);
     94      var x = Evaluate(instructions, ref instructionCount, intervals);
    10195
    10296      return x;
     
    106100      lock (syncRoot) {
    107101        EvaluatedSolutions++;
    108         ResetInstrucitonCount();
    109       }
     102      }
     103      int instructionCount = 0;
    110104      var instructions = PrepareInterpreterState(tree, customIntervals);
    111       var x = Evaluate(instructions);
     105      var x = Evaluate(instructions, ref instructionCount);
    112106
    113107      return x;
     
    119113      lock (syncRoot) {
    120114        EvaluatedSolutions++;
    121         ResetInstrucitonCount();
    122       }
     115      }
     116      int instructionCount = 0;
    123117      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
    124118      var instructions = PrepareInterpreterState(tree, customIntervals);
    125       var x = Evaluate(instructions, intervals);
     119      var x = Evaluate(instructions, ref instructionCount, intervals);
    126120
    127121      return x;
     
    146140    }
    147141
    148     private Interval Evaluate(Instruction[] instructions, Dictionary<ISymbolicExpressionTreeNode,
     142    private Interval Evaluate(Instruction[] instructions, ref int instructionCount, Dictionary<ISymbolicExpressionTreeNode,
    149143      Interval> intervals = null) {
    150       Instruction currentInstr = instructions[InstructionCount++];
     144      Instruction currentInstr = instructions[instructionCount++];
    151145      Interval result = null;
    152146
     
    154148        //Elementary arithmetic rules
    155149        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));
    159153            }
    160154            break;
    161155          }
    162156        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));
    166160            }
    167161            break;
    168162          }
    169163        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));
    173167            }
    174168            break;
    175169          }
    176170        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));
    180174            }
    181175            break;
     
    183177        //Trigonometric functions
    184178        case OpCodes.Sin: {
    185             result = Interval.Sine(Evaluate(instructions, intervals));
     179            result = Interval.Sine(Evaluate(instructions, ref instructionCount, intervals));
    186180            break;
    187181          }
    188182        case OpCodes.Cos: {
    189             result = Interval.Cosine(Evaluate(instructions, intervals));
     183            result = Interval.Cosine(Evaluate(instructions, ref instructionCount, intervals));
    190184            break;
    191185          }
    192186        case OpCodes.Tan: {
    193             result = Interval.Tangens(Evaluate(instructions, intervals));
     187            result = Interval.Tangens(Evaluate(instructions, ref instructionCount, intervals));
    194188            break;
    195189          }
    196190        //Exponential functions
    197191        case OpCodes.Log: {
    198             result = Interval.Logarithm(Evaluate(instructions, intervals));
     192            result = Interval.Logarithm(Evaluate(instructions, ref instructionCount, intervals));
    199193            break;
    200194          }
    201195        case OpCodes.Exp: {
    202             result = Interval.Exponential(Evaluate(instructions, intervals));
     196            result = Interval.Exponential(Evaluate(instructions, ref instructionCount, intervals));
    203197            break;
    204198          }
    205199        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));
    209203            }
    210204            break;
    211205          }
    212206        case OpCodes.Square: {
    213             result = Interval.Square(Evaluate(instructions, intervals));
     207            result = Interval.Square(Evaluate(instructions, ref instructionCount, intervals));
    214208            break;
    215209          }
    216210        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));
    220214            }
    221215            break;
    222216          }
    223217        case OpCodes.SquareRoot: {
    224             result = Interval.SquareRoot(Evaluate(instructions, intervals));
     218            result = Interval.SquareRoot(Evaluate(instructions, ref instructionCount, intervals));
    225219            break;
    226220          }
Note: See TracChangeset for help on using the changeset viewer.