Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/12/12 10:31:56 (12 years ago)
Author:
mkommend
Message:

#1081: Improved performance of time series prognosis.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs

    r7268 r7989  
    2525
    2626namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    27   public class SymbolicExpressionTreeCompiler {
    28     private Dictionary<string, ushort> entryPoint = new Dictionary<string, ushort>();
    29     private List<Func<Instruction, Instruction>> postInstructionCompiledHooks = new List<Func<Instruction, Instruction>>();
     27  public static class SymbolicExpressionTreeCompiler {
    3028
    31     public Instruction[] Compile(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) {
     29    public static Instruction[] Compile(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) {
     30      return Compile(tree, opCodeMapper, Enumerable.Empty<Func<Instruction, Instruction>>());
     31    }
     32    public static Instruction[] Compile(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper, IEnumerable<Func<Instruction, Instruction>> postInstructionCompiledHooks) {
     33      Dictionary<string, ushort> entryPoint = new Dictionary<string, ushort>();
    3234      List<Instruction> code = new List<Instruction>();
    33       entryPoint.Clear();
    3435      // compile main body branches
    3536      foreach (var branch in tree.Root.GetSubtree(0).Subtrees) {
    36         code.AddRange(Compile(branch, opCodeMapper));
     37        code.AddRange(Compile(branch, opCodeMapper, postInstructionCompiledHooks));
    3738      }
    3839      // compile function branches
     
    4344        if (code.Count > ushort.MaxValue) throw new ArgumentException("Code for the tree is too long (> ushort.MaxValue).");
    4445        entryPoint[branch.FunctionName] = (ushort)code.Count;
    45         code.AddRange(Compile(branch.GetSubtree(0), opCodeMapper));
     46        code.AddRange(Compile(branch.GetSubtree(0), opCodeMapper, postInstructionCompiledHooks));
    4647      }
    4748      // address of all functions is fixed now
     
    5960    }
    6061
    61     private IEnumerable<Instruction> Compile(ISymbolicExpressionTreeNode branch, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) {
     62    private static IEnumerable<Instruction> Compile(ISymbolicExpressionTreeNode branch, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper, IEnumerable<Func<Instruction, Instruction>> postInstructionCompiledHooks) {
    6263      foreach (var node in branch.IterateNodesPrefix()) {
    6364        Instruction instr = new Instruction();
     
    7778      }
    7879    }
    79 
    80     /// <summary>
    81     /// Adds a function that will be called every time an instruction is compiled.
    82     /// The compiled will insert the instruction returned by the hook into the code.
    83     /// </summary>
    84     /// <param name="hook">The hook that should be called for each compiled instruction.</param>
    85     public void AddInstructionPostProcessingHook(Func<Instruction, Instruction> hook) {
    86       postInstructionCompiledHooks.Add(hook);
    87     }
    8880  }
    8981}
Note: See TracChangeset for help on using the changeset viewer.