Changeset 2210 for branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs
- Timestamp:
- 07/29/09 18:28:45 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs
r2202 r2210 29 29 using HeuristicLab.DataAnalysis; 30 30 using HeuristicLab.Data; 31 using HeuristicLab.GP.Interfaces; 31 32 32 33 namespace HeuristicLab.GP.StructureIdentification { … … 45 46 public byte arity; 46 47 public byte symbol; 47 public IFunction function;48 48 } 49 49 … … 61 61 minValue = mean - punishmentFactor * range; 62 62 63 BakedFunctionTree bakedTree = functionTree as BakedFunctionTree; 64 if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees"); 65 66 List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation; 67 codeArr = new Instr[linearRepresentation.Count]; 63 codeArr = new Instr[functionTree.GetSize()]; 68 64 int i = 0; 69 foreach ( LightWeightFunction f in linearRepresentation) {70 codeArr[i++] = TranslateToInstr( f);65 foreach (IFunctionTree tree in IteratePrefix(functionTree)) { 66 codeArr[i++] = TranslateToInstr(tree); 71 67 } 72 68 } 73 69 74 private Instr TranslateToInstr(LightWeightFunction f) { 70 private IEnumerable<IFunctionTree> IteratePrefix(IFunctionTree functionTree) { 71 List<IFunctionTree> prefixForm = new List<IFunctionTree>(); 72 prefixForm.Add(functionTree); 73 foreach (IFunctionTree subTree in functionTree.SubTrees) { 74 prefixForm.AddRange(IteratePrefix(subTree)); 75 } 76 return prefixForm; 77 } 78 79 private Instr TranslateToInstr(IFunctionTree tree) { 75 80 Instr instr = new Instr(); 76 instr.arity = f.arity;77 instr.symbol = EvaluatorSymbolTable.MapFunction( f.functionType);81 instr.arity = (byte)tree.SubTrees.Count; 82 instr.symbol = EvaluatorSymbolTable.MapFunction(tree.Function); 78 83 switch (instr.symbol) { 79 84 case EvaluatorSymbolTable.DIFFERENTIAL: 80 85 case EvaluatorSymbolTable.VARIABLE: { 81 instr.i_arg0 = (short)dataset.GetVariableIndex((((StringData)f.localData[1].Value).Data)); // var 82 instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // weight 83 instr.i_arg1 = (short)((ConstrainedIntData)f.localData[2].Value).Data; // sample-offset 86 VariableFunctionTree varTree = (VariableFunctionTree)tree; 87 instr.i_arg0 = (short)dataset.GetVariableIndex(varTree.VariableName); 88 instr.d_arg0 = varTree.Weight; 89 instr.i_arg1 = (short)varTree.SampleOffset; 84 90 break; 85 91 } 86 92 case EvaluatorSymbolTable.CONSTANT: { 87 instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // value 93 ConstantFunctionTree constTree = (ConstantFunctionTree)tree; 94 instr.d_arg0 = constTree.Value; 88 95 break; 89 96 } 90 97 case EvaluatorSymbolTable.UNKNOWN: { 91 instr.function = f.functionType; 92 break; 98 throw new NotSupportedException("Unknown function symbol: " + instr.symbol); 93 99 } 94 100 }
Note: See TracChangeset
for help on using the changeset viewer.