Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/17 01:15:25 (7 years ago)
Author:
pkimmesw
Message:

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r14834 r14875  
    2121    private Task currentTask;
    2222
    23 
    2423    public PushInterpreter(IReadOnlyPushConfiguration config = null, IRandom random = null, InterpreterPoolContainer poolContainer = null) {
    2524      Random = random ?? new FastRandom();
     
    2827
    2928      // setting the capacity of the stacks to max points ensures that there will be enough memory at runtime
    30       ExecStack = new PushStack<Expression>(Configuration.EvalPushLimit);
    31 
    32       CodeStack = new PushStack<Expression>(Configuration.EvalPushLimit) {
     29      ExecStack = new PushStack<Expression>(Configuration.MaxPointsInProgram);
     30
     31      CodeStack = new PushStack<Expression> {
    3332        IsEnabled = Configuration.EnabledStacks[StackTypes.Code]
    3433      };
     
    3736        IsEnabled = Configuration.EnabledStacks[StackTypes.Code]
    3837      };
     38
    3939      BooleanStack = new PushStack<bool> {
    4040        IsEnabled = Configuration.EnabledStacks[StackTypes.Boolean]
    4141      };
     42
    4243      IntegerStack = new PushStack<long> {
    4344        IsEnabled = Configuration.EnabledStacks[StackTypes.Integer]
    4445      };
     46
    4547      FloatStack = new PushStack<double> {
    4648        IsEnabled = Configuration.EnabledStacks[StackTypes.Float]
    4749      };
     50
    4851      CharStack = new PushStack<char> {
    4952        IsEnabled = Configuration.EnabledStacks[StackTypes.Char]
    5053      };
     54
    5155      StringStack = new PushStack<string> {
    5256        IsEnabled = Configuration.EnabledStacks[StackTypes.String]
    5357      };
     58
    5459      IntegerVectorStack = new PushStack<List<long>> {
    5560        IsEnabled = Configuration.EnabledStacks[StackTypes.IntegerVector]
    5661      };
     62
    5763      FloatVectorStack = new PushStack<List<double>> {
    5864        IsEnabled = Configuration.EnabledStacks[StackTypes.FloatVector]
    5965      };
     66
    6067      BooleanVectorStack = new PushStack<List<bool>> {
    6168        IsEnabled = Configuration.EnabledStacks[StackTypes.BooleanVector]
    6269      };
     70
    6371      StringVectorStack = new PushStack<List<string>> {
    6472        IsEnabled = Configuration.EnabledStacks[StackTypes.StringVector]
     
    6674
    6775      CustomExpressions = new Dictionary<string, Expression>();
    68 
    6976      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
    7077    }
     
    7683    public IRandom Random { get; set; }
    7784
    78     public int ExecCounter { get; private set; }
     85    public long ExecCounter { get; private set; }
    7986
    8087    public bool IsPaused { get; private set; }
     
    159166    }
    160167    public async Task RunAsync(Expression expression, CancellationToken token = default(CancellationToken)) {
    161       await Task.Run(() => Run(expression, false), token);
     168      await Task.Run(() => Run(expression), token);
    162169    }
    163170
     
    176183      ExecStack.Push(expression);
    177184
    178       if (Configuration.TopLevelPushCode) CodeStack.Insert(0, expression);
     185      if (Configuration.TopLevelPushCode) CodeStack.Push(expression);
    179186
    180187      // expand if program
     
    183190
    184191      Run();
     192    }
     193
     194    public bool CanRun(int count) {
     195      return ExecStack.Count >= count &&
     196             !IsPaused &&
     197             !IsAborted &&
     198             ExecCounter + count < Configuration.EvalPushLimit;
    185199    }
    186200
     
    237251    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    238252    public void Step(int count) {
    239       for (var i = 0; i < count; i++) Step();
     253      for (var i = 0u; i < count; i++) Step();
    240254    }
    241255
    242256    /// <summary>
    243     /// Clears stacks
     257    /// Reset while interpreter
    244258    /// </summary>
    245259    public void Reset() {
     
    269283    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    270284    private void Run() {
     285      // if no stack which is modifies the exec stack is enabled, unroll loop due to performance reasons
     286      if (!Configuration.EnabledStacks[StackTypes.Exec] &&
     287          !Configuration.EnabledStacks[StackTypes.Code]) {
     288        while (CanRun(10))
     289          DoTenSteps();
     290      }
     291
    271292      while (IsRunning)
    272293        DoStep();
     
    314335#endif
    315336
     337    [MethodImpl(MethodImplOptions.AggressiveInlining)]
     338    private void DoTenSteps() {
     339      ExecStack[0].Eval(this);
     340      ExecStack[1].Eval(this);
     341      ExecStack[2].Eval(this);
     342      ExecStack[3].Eval(this);
     343      ExecStack[4].Eval(this);
     344      ExecStack[5].Eval(this);
     345      ExecStack[6].Eval(this);
     346      ExecStack[7].Eval(this);
     347      ExecStack[8].Eval(this);
     348      ExecStack[9].Eval(this);
     349
     350      ExecStack.Remove(10);
     351      ExecCounter += 10;
     352    }
     353
    316354    private Task InterpretAsync() {
    317355      currentTask = Task.Run(() => this.Run());
Note: See TracChangeset for help on using the changeset viewer.