Free cookie consent management tool by TermsFeed Policy Generator

Changeset 239 for trunk


Ignore:
Timestamp:
05/13/08 15:10:57 (17 years ago)
Author:
gkronber
Message:

fixed #148

Location:
trunk/sources/HeuristicLab.Functions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs

    r229 r239  
    220220    }
    221221
     222    private BakedTreeEvaluator evaluator;
    222223    public double Evaluate(Dataset dataset, int sampleIndex) {
    223224      FlattenVariables();
    224225      FlattenTrees();
    225       return BakedTreeEvaluator.Evaluate(dataset, sampleIndex, code, data);
     226      if(evaluator == null) evaluator = new BakedTreeEvaluator(code, data);
     227      return evaluator.Evaluate(dataset, sampleIndex);
    226228    }
    227229
  • trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs

    r236 r239  
    66
    77namespace HeuristicLab.Functions {
    8   static class BakedTreeEvaluator {
     8  internal class BakedTreeEvaluator {
    99    private const int ADDITION = 10010;
    1010    private const int AND = 10020;
     
    3535    private static Dictionary<IFunction, int> reverseSymbolTable;
    3636    private static Dictionary<Type, int> staticTypes;
     37    private static int MAX_CODE_LENGTH = 4096;
     38    private static int MAX_DATA_LENGTH = 4096;
     39    private static int[] codeArr = new int[MAX_CODE_LENGTH];
     40    private static double[] dataArr = new double[MAX_DATA_LENGTH];
    3741
    3842    static BakedTreeEvaluator() {
     
    6569    }
    6670
     71    internal BakedTreeEvaluator(List<int> code, List<double> data) {
     72      code.CopyTo(codeArr);
     73      data.CopyTo(dataArr);
     74    }
     75
    6776    internal static int MapFunction(IFunction function) {
    6877      if(!reverseSymbolTable.ContainsKey(function)) {
     
    8493
    8594
    86     private static int PC;
    87     private static int DP;
    88     private static int MAX_CODE_LENGTH = 4096;
    89     private static int MAX_DATA_LENGTH = 4096;
    90     private static int[] codeArr = new int[MAX_CODE_LENGTH];
    91     private static double[] dataArr = new double[MAX_DATA_LENGTH];
    92     private static Dataset dataset;
    93     private static int sampleIndex;
    94 
    95     internal static double Evaluate(Dataset _dataset, int _sampleIndex, List<int> code, List<double> data) {
     95    private int PC;
     96    private int DP;
     97    private Dataset dataset;
     98    private int sampleIndex;
     99
     100    internal double Evaluate(Dataset _dataset, int _sampleIndex) {
    96101      PC = 0;
    97102      DP = 0;
    98       code.CopyTo(codeArr);
    99       data.CopyTo(dataArr);
    100103      sampleIndex = _sampleIndex;
    101104      dataset = _dataset;
     
    103106    }
    104107
    105     private static double EvaluateBakedCode() {
     108    private double EvaluateBakedCode() {
    106109      int arity = codeArr[PC];
    107110      int functionSymbol = codeArr[PC+1];
Note: See TracChangeset for help on using the changeset viewer.