Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/18/15 13:50:15 (8 years ago)
Author:
mkommend
Message:

#2442: Reintegrated branch for compiled symbolic expression tree interpreter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r12509 r13248  
    6969
    7070    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     71    private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.";
    7172    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    7273
     
    8081
    8182    #region parameter properties
    82 
    83     public IValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
    84       get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    85     }
    86 
    87     public IValueParameter<IntValue> EvaluatedSolutionsParameter {
    88       get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
    89     }
    90 
     83    public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
     84      get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
     85    }
     86
     87    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
     88      get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     89    }
    9190    #endregion
    9291
    9392    #region properties
    94 
    95     public BoolValue CheckExpressionsWithIntervalArithmetic {
    96       get { return CheckExpressionsWithIntervalArithmeticParameter.Value; }
    97       set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
    98     }
    99 
    100     public IntValue EvaluatedSolutions {
    101       get { return EvaluatedSolutionsParameter.Value; }
    102       set { EvaluatedSolutionsParameter.Value = value; }
    103     }
    104 
     93    public bool CheckExpressionsWithIntervalArithmetic {
     94      get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; }
     95      set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; }
     96    }
     97    public int EvaluatedSolutions {
     98      get { return EvaluatedSolutionsParameter.Value.Value; }
     99      set { EvaluatedSolutionsParameter.Value.Value = value; }
     100    }
    105101    #endregion
    106 
    107102
    108103    [StorableConstructor]
     
    116111    public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter()
    117112      : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") {
    118       Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
    119       Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     113      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName,
     114        "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
     115      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     116    }
     117
     118    public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(string name, string description)
     119      : base(name, description) {
     120      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName,
     121        "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
     122      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    120123    }
    121124
    122125    [StorableHook(HookType.AfterDeserialization)]
    123126    private void AfterDeserialization() {
    124       if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName))
    125         Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     127      var evaluatedSolutions = new IntValue(0);
     128      var checkExpressionsWithIntervalArithmetic = new BoolValue(false);
     129      if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) {
     130        var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName];
     131        evaluatedSolutions = evaluatedSolutionsParameter.Value;
     132        Parameters.Remove(EvaluatedSolutionsParameterName);
     133      }
     134      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions));
     135      if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) {
     136        var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName];
     137        Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName);
     138        checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value;
     139      }
     140      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic));
    126141    }
    127142
    128143    #region IStatefulItem
    129 
    130144    public void InitializeState() {
    131       EvaluatedSolutions.Value = 0;
     145      EvaluatedSolutions = 0;
    132146    }
    133147
    134148    public void ClearState() {
    135       EvaluatedSolutions.Value = 0;
    136     }
    137 
     149    }
    138150    #endregion
    139151
    140152    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    141       if (CheckExpressionsWithIntervalArithmetic.Value)
     153      if (CheckExpressionsWithIntervalArithmetic)
    142154        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
    143155
    144       EvaluatedSolutions.Value++; // increment the evaluated solutions counter
     156      EvaluatedSolutions++; // increment the evaluated solutions counter
    145157      var state = PrepareInterpreterState(tree, dataset);
    146158
Note: See TracChangeset for help on using the changeset viewer.