Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (8 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

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
Files:
5 edited

Legend:

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

    r14914 r15017  
    3434
    3535      foreach (StackTypes type in Enum.GetValues(stackTypesType)) {
     36        if (!interpreter.Stacks.ContainsKey(type)) continue;
     37
    3638        var stackName = Enum.GetName(stackTypesType, type);
    3739        var stack = interpreter.Stacks[type];
    3840
    39         if (stack.IsEmpty || !stack.IsEnabled) return;
    40         Console.WriteLine("--------- {0} ---------\n{1}\n", stackName, stack);
     41        if (stack.IsEmpty || !stack.IsEnabled) continue;
     42
     43        var stackString = string.Join(" ", interpreter.StringifyStack(type).Reverse());
     44        Console.WriteLine("--------- {0} ---------\n{1}\n", stackName, stackString);
    4145      }
    4246
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs

    r14914 r15017  
    2020    IPushStack<char> CharStack { get; }
    2121    IPushStack<string> StringStack { get; }
    22     IPushStack<List<long>> IntegerVectorStack { get; }
    23     IPushStack<List<double>> FloatVectorStack { get; }
    24     IPushStack<List<bool>> BooleanVectorStack { get; }
    25     IPushStack<List<string>> StringVectorStack { get; }
     22    IPushStack<IReadOnlyList<long>> IntegerVectorStack { get; }
     23    IPushStack<IReadOnlyList<double>> FloatVectorStack { get; }
     24    IPushStack<IReadOnlyList<bool>> BooleanVectorStack { get; }
     25    IPushStack<IReadOnlyList<string>> StringVectorStack { get; }
    2626    IPushStack<string> PrintStack { get; }
    2727    IDictionary<string, Expression> CustomExpressions { get; }
     
    3030    void Clear();
    3131    void Reset();
     32
     33    void Run(bool stepwise);
    3234    void Run(string code, bool stepwise = false);
    3335    void Run(Expression expression, bool stepwise = false);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/InterpreterPoolContainer.cs

    r14952 r15017  
    88  public class InterpreterPoolContainer {
    99    private readonly ManagedPoolProvider<PushProgram> pushProgramPoolProvider;
    10     private readonly ManagedPoolProvider<LoopState> loopStatePoolProvider;
    1110    private readonly ManagedPoolProvider<PooledList<Expression>> expressionListPoolProvider;
    1211
     
    1918    public InterpreterPoolContainer(int partitionSize = 512, int maxPartitionCount = 1024) {
    2019      pushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(partitionSize, () => new PushProgram(), maxPartitionCount);
    21       loopStatePoolProvider = new ManagedPoolProvider<LoopState>(partitionSize, () => new LoopState(), maxPartitionCount);
    2220      expressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(partitionSize, () => new PooledList<Expression>(), maxPartitionCount);
    2321
     
    2725    public InterpreterPoolContainer(
    2826      ManagedPoolProvider<PushProgram> pushProgramPoolProvider,
    29       ManagedPoolProvider<LoopState> loopStatePoolProvider,
    3027      ManagedPoolProvider<PooledList<Expression>> expressionListPoolProvider) {
    3128      this.pushProgramPoolProvider = pushProgramPoolProvider;
    32       this.loopStatePoolProvider = loopStatePoolProvider;
    3329      this.expressionListPoolProvider = expressionListPoolProvider;
    3430
     
    4339        if (pushProgramPool == null) pushProgramPool = pushProgramPoolProvider.CreatePool();
    4440        return pushProgramPool;
    45       }
    46     }
    47 
    48     private IManagedPool<LoopState> loopStatePool;
    49     public IManagedPool<LoopState> LoopStatePool
    50     {
    51       get
    52       {
    53         if (loopStatePool == null) loopStatePool = loopStatePoolProvider.CreatePool();
    54         return loopStatePool;
    5541      }
    5642    }
     
    9682      }
    9783
    98       if (loopStatePool != null) {
    99         loopStatePool.Dispose();
    100         loopStatePool = null;
    101       }
    102 
    10384      if (expressionListPool != null) {
    10485        expressionListPool.Dispose();
  • 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)]
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs

    r14834 r15017  
    1111
    1212    public readonly ManagedPoolProvider<PushProgram> PushProgramPoolProvider;
    13     public readonly ManagedPoolProvider<LoopState> LoopStatePoolProvider;
    1413    public readonly ManagedPoolProvider<PooledList<Expression>> ExpressionListPoolProvider;
    1514
     
    1918
    2019    public PushInterpreterPool(int size, int poolPartitionSize, int? maxPartitionCount = null, IReadOnlyPushConfiguration config = null) {
    21       PushGpConfiguration = config ?? new PushConfiguration();
     20      PushConfiguration = config ?? new PushConfiguration();
    2221
    2322      PushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(poolPartitionSize, () => new PushProgram(), maxPartitionCount);
    24       LoopStatePoolProvider = new ManagedPoolProvider<LoopState>(poolPartitionSize, () => new LoopState(), maxPartitionCount);
    25       ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(poolPartitionSize * 2, () => new PooledList<Expression>(), maxPartitionCount);
     23      ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(poolPartitionSize, () => new PooledList<Expression>(), maxPartitionCount);
    2624
    2725      pool = new ObjectPool<PooledPushInterpreter>(() => {
    28         var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, LoopStatePoolProvider, ExpressionListPoolProvider);
    29         return new PooledPushInterpreter(this, PushGpConfiguration, poolContainer);
     26        var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, ExpressionListPoolProvider);
     27        return new PooledPushInterpreter(this, PushConfiguration, poolContainer);
    3028      }, size);
    3129    }
    3230
    33     public IReadOnlyPushConfiguration PushGpConfiguration { get; private set; }
     31    public IReadOnlyPushConfiguration PushConfiguration { get; private set; }
    3432
    3533    public PooledPushInterpreter Create(IRandom random = null) {
     
    4139
    4240    public void Free(PooledPushInterpreter interpreter) {
     41      interpreter.Random = null;
    4342      pool.Free(interpreter);
     43    }
     44
     45    public void Clear() {
     46      PushProgramPoolProvider.Clear();
     47      ExpressionListPoolProvider.Clear();
    4448    }
    4549  }
Note: See TracChangeset for help on using the changeset viewer.