Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File:
1 edited

Legend:

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

    r14952 r15017  
    55  using System.Threading;
    66  using System.Threading.Tasks;
     7  using Attributes;
    78  using Configuration;
    89  using Core;
    910  using Expressions;
    10 
    11   using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    12 
    1311  using Parser;
    1412  using Random;
    1513  using Stack;
    1614
    17 #if DEBUG
    18   using System.Diagnostics;
    19   using System.Linq;
    20 #endif
    2115
    2216  public class PushInterpreter : IInternalPushInterpreter, IDisposable {
     
    2418
    2519    public PushInterpreter(IReadOnlyPushConfiguration config = null, IRandom random = null, InterpreterPoolContainer poolContainer = null) {
    26       Random = random ?? new FastRandom();
    27 
     20      Random = random ?? new MersenneTwister();
    2821      Configuration = config ?? new PushConfiguration();
    2922
     
    5952      };
    6053
    61       IntegerVectorStack = new PushStack<List<long>> {
     54      IntegerVectorStack = new PushStack<IReadOnlyList<long>> {
    6255        IsEnabled = Configuration.EnabledStacks[StackTypes.IntegerVector]
    6356      };
    6457
    65       FloatVectorStack = new PushStack<List<double>> {
     58      FloatVectorStack = new PushStack<IReadOnlyList<double>> {
    6659        IsEnabled = Configuration.EnabledStacks[StackTypes.FloatVector]
    6760      };
    6861
    69       BooleanVectorStack = new PushStack<List<bool>> {
     62      BooleanVectorStack = new PushStack<IReadOnlyList<bool>> {
    7063        IsEnabled = Configuration.EnabledStacks[StackTypes.BooleanVector]
    7164      };
    7265
    73       StringVectorStack = new PushStack<List<string>> {
     66      StringVectorStack = new PushStack<IReadOnlyList<string>> {
    7467        IsEnabled = Configuration.EnabledStacks[StackTypes.StringVector]
    7568      };
     
    8881        { StackTypes.String, StringStack },
    8982        { StackTypes.Name, NameStack },
     83        { StackTypes.Print, PrintStack },
    9084        { StackTypes.IntegerVector, IntegerVectorStack },
    9185        { StackTypes.FloatVector, FloatVectorStack },
    9286        { StackTypes.BooleanVector, BooleanVectorStack },
    9387        { StackTypes.StringVector, StringVectorStack },
    94         { StackTypes.Print, PrintStack },
    9588      };
    9689
     
    160153    public IPushStack<string> StringStack { get; private set; }
    161154    [PushStack(StackTypes.IntegerVector)]
    162     public IPushStack<List<long>> IntegerVectorStack { get; private set; }
     155    public IPushStack<IReadOnlyList<long>> IntegerVectorStack { get; private set; }
    163156    [PushStack(StackTypes.FloatVector)]
    164     public IPushStack<List<double>> FloatVectorStack { get; private set; }
     157    public IPushStack<IReadOnlyList<double>> FloatVectorStack { get; private set; }
    165158    [PushStack(StackTypes.BooleanVector)]
    166     public IPushStack<List<bool>> BooleanVectorStack { get; private set; }
     159    public IPushStack<IReadOnlyList<bool>> BooleanVectorStack { get; private set; }
    167160    [PushStack(StackTypes.StringVector)]
    168     public IPushStack<List<string>> StringVectorStack { get; private set; }
     161    public IPushStack<IReadOnlyList<string>> StringVectorStack { get; private set; }
    169162    [PushStack(StackTypes.Print)]
    170163    public IPushStack<string> PrintStack { get; private set; }
     
    186179      var program = PushParser.Parse(code);
    187180      Run(program, stepwise);
     181    }
     182
     183    public void Run(bool stepwise) {
     184      Run(PushProgram.Empty, stepwise);
    188185    }
    189186
     
    322319    }
    323320
    324 #if DEBUG
    325     private Expression last;
    326     private bool DoStep() {
    327       double[] bk;
    328       if (!FloatStack.IsEmpty) {
    329         bk = FloatStack.Peek(Math.Min(FloatStack.Count, 3));
    330       }
    331 
    332       var expression = ExecStack.Pop();
    333       var succ = expression.TryEval(this);
    334 
    335       if ((ExecStack.Count > 0 && ExecStack.Top == null) ||
    336           (CodeStack.Count > 0 && CodeStack.Top == null) ||
    337           FloatStack.Any(x => double.IsNaN(x) || double.IsInfinity(x)) ||
    338           StringStack.Count > 0 && StringStack.Any(x => x == null)) {
    339         Debugger.Break();
    340       }
    341 
    342       ExecCounter++;
    343       last = expression;
    344       return succ;
    345     }
    346 #else
    347321    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    348322    private bool DoStep() {
     
    350324      return ExecStack.Pop().TryEval(this);
    351325    }
    352 #endif
    353326
    354327    [MethodImpl(MethodImplOptions.AggressiveInlining)]
Note: See TracChangeset for help on using the changeset viewer.