Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/09 12:26:42 (15 years ago)
Author:
gkronber
Message:

Merged changes from GP-refactoring branch back into the trunk #713.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r2174 r2222  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Core;
    27 using System.Xml;
    28 using System.Diagnostics;
    2925using HeuristicLab.DataAnalysis;
     26using HeuristicLab.GP.Interfaces;
    3027
    3128namespace HeuristicLab.GP.StructureIdentification {
     
    4441      public byte arity;
    4542      public byte symbol;
    46       public IFunction function;
    4743    }
    4844
     
    6056      minValue = mean - punishmentFactor * range;
    6157
    62       BakedFunctionTree bakedTree = functionTree as BakedFunctionTree;
    63       if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees");
    64 
    65       List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation;
    66       codeArr = new Instr[linearRepresentation.Count];
     58      codeArr = new Instr[functionTree.GetSize()];
    6759      int i = 0;
    68       foreach (LightWeightFunction f in linearRepresentation) {
    69         codeArr[i++] = TranslateToInstr(f);
     60      foreach (IFunctionTree tree in IteratePrefix(functionTree)) {
     61        codeArr[i++] = TranslateToInstr(tree);
    7062      }
    7163    }
    7264
    73     private Instr TranslateToInstr(LightWeightFunction f) {
     65    private IEnumerable<IFunctionTree> IteratePrefix(IFunctionTree functionTree) {
     66      List<IFunctionTree> prefixForm = new List<IFunctionTree>();
     67      prefixForm.Add(functionTree);
     68      foreach (IFunctionTree subTree in functionTree.SubTrees) {
     69        prefixForm.AddRange(IteratePrefix(subTree));
     70      }
     71      return prefixForm;
     72    }
     73
     74    private Instr TranslateToInstr(IFunctionTree tree) {
    7475      Instr instr = new Instr();
    75       instr.arity = f.arity;
    76       instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType);
     76      instr.arity = (byte)tree.SubTrees.Count;
     77      instr.symbol = EvaluatorSymbolTable.MapFunction(tree.Function);
    7778      switch (instr.symbol) {
    7879        case EvaluatorSymbolTable.DIFFERENTIAL:
    7980        case EvaluatorSymbolTable.VARIABLE: {
    80             instr.i_arg0 = (short)dataset.GetVariableIndex((string)f.localData[0]); // var
    81             instr.d_arg0 = (double)f.localData[1]; // weight
    82             instr.i_arg1 = (short)(int)f.localData[2]; // sample-offset
     81            VariableFunctionTree varTree = (VariableFunctionTree)tree;
     82            instr.i_arg0 = (short)dataset.GetVariableIndex(varTree.VariableName);
     83            instr.d_arg0 = varTree.Weight;
     84            instr.i_arg1 = (short)varTree.SampleOffset;
    8385            break;
    8486          }
    8587        case EvaluatorSymbolTable.CONSTANT: {
    86             instr.d_arg0 = (double)f.localData[0]; // value
     88            ConstantFunctionTree constTree = (ConstantFunctionTree)tree;
     89            instr.d_arg0 = constTree.Value;
    8790            break;
    8891          }
    8992        case EvaluatorSymbolTable.UNKNOWN: {
    90             instr.function = f.functionType;
    91             break;
     93            throw new NotSupportedException("Unknown function symbol: " + instr.symbol);
    9294          }
    9395      }
Note: See TracChangeset for help on using the changeset viewer.