Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/17 01:11:18 (8 years ago)
Author:
pkimmesw
Message:

#2665 simplifier, push solution results view, performance improvements, small bug fixes, ui fixes

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
Files:
1 added
4 edited

Legend:

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

    r14746 r14777  
    2020    IStack<long> IntegerStack { get; }
    2121    IStack<double> FloatStack { get; }
     22    IStack<char> CharStack { get; }
     23    IStack<string> StringStack { get; }
    2224
    2325    IDictionary<string, Expression> CustomExpressions { get; }
    2426
    25     IReadonlyPushConfiguration Configuration { get; }
     27    IReadOnlyPushConfiguration Configuration { get; }
    2628
    27     IManagedPool<PushProgram> PushProgramPool { get; }
     29    InterpreterPoolContainer PoolContainer { get; }
    2830
    2931    bool IsNameQuoteFlagSet { get; set; }
     
    3234    void Run(string code, bool stepwise = false);
    3335    void Run(Expression expression, bool stepwise = false);
    34     //void Run(PushProgram program, bool stepwise = false);
    35     //Task RunAsync(PushProgram program, bool paused = false, CancellationToken token = default(CancellationToken));
    3636    Task RunAsync(Expression expression, bool paused = false, CancellationToken token = default(CancellationToken));
    3737    Task RunAsync(string code, bool paused = false, CancellationToken token = default(CancellationToken));
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PooledPushInterpreter.cs

    r14747 r14777  
    44  using HeuristicLab.Core;
    55  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    6   using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
    7   using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    86
    97  public class PooledPushInterpreter : PushInterpreter, IDisposable {
     
    119    private readonly PushInterpreterPool pool;
    1210
    13     public PooledPushInterpreter(PushInterpreterPool pool, PushConfiguration config, ManagedPoolProvider<PushProgram> pushProgramPoolProvider, IRandom random = null)
    14       : base(config, random, pushProgramPoolProvider) {
     11    public PooledPushInterpreter(PushInterpreterPool pool, IReadOnlyPushConfiguration config, InterpreterPoolContainer poolContainer, IRandom random = null)
     12      : base(config, random, poolContainer) {
    1513      this.pool = pool;
    1614    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r14747 r14777  
    33  using System.Collections.Generic;
    44#if DEBUG
    5   using System.Linq;
    65#endif
    76  using System.Runtime.CompilerServices;
     
    109  using HeuristicLab.Core;
    1110  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    12   using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
    1311  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1412  using HeuristicLab.Problems.ProgramSynthesis.Push.Parser;
     
    1917    private Task currentTask;
    2018
    21     public PushInterpreter(IReadonlyPushConfiguration config = null, IRandom random = null, ManagedPoolProvider<PushProgram> pushProgramPoolProvider = null) {
     19
     20    public PushInterpreter(IReadOnlyPushConfiguration config = null, IRandom random = null, InterpreterPoolContainer poolContainer = null) {
    2221      Random = random ?? new FastRandom();
    2322
     
    4342        IsEnabled = Configuration.IsFloatStackEnabled
    4443      };
     44      CharStack = new PushStack<char> {
     45        IsEnabled = Configuration.IsCharStackEnabled
     46      };
     47      StringStack = new PushStack<string> {
     48        IsEnabled = Configuration.IsStringStackEnabled
     49      };
    4550
    4651      CustomExpressions = new Dictionary<string, Expression>();
    4752
    48       PushProgramPoolProvider = pushProgramPoolProvider ?? new ManagedPoolProvider<PushProgram>(1024);
    49 
    50       if (pushProgramPoolProvider == null)
    51       {
    52         PushProgramPoolProvider.InitDummyPartition(() => new PushProgram());
    53       }
    54     }
    55 
    56     public PushInterpreter(int seed, IReadonlyPushConfiguration config = null)
     53      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
     54    }
     55
     56    public PushInterpreter(int seed, IReadOnlyPushConfiguration config = null)
    5757      : this(config, new FastRandom(seed)) {
    5858    }
     
    9393    }
    9494
    95     private readonly ManagedPoolProvider<PushProgram> PushProgramPoolProvider;
    96     public IManagedPool<PushProgram> PushProgramPool { get; private set; }
    97 
    98     public IReadonlyPushConfiguration Configuration { get; protected set; }
     95    public InterpreterPoolContainer PoolContainer { get; private set; }
     96
     97    public IReadOnlyPushConfiguration Configuration { get; protected set; }
    9998
    10099    public IStack<Expression> CodeStack { get; private set; }
     
    109108
    110109    public IStack<double> FloatStack { get; private set; }
     110    public IStack<char> CharStack { get; private set; }
     111    public IStack<string> StringStack { get; private set; }
    111112
    112113    public IDictionary<string, Expression> CustomExpressions { get; private set; }
     
    133134    }
    134135
    135 
    136136    public void Run(Expression program, bool stepwise = false) {
    137       using (PushProgramPool = PushProgramPoolProvider.CreatePool()) {
    138         IsPaused = stepwise;
    139 
    140         /* Push top expression so the loop is able to enter
    141          * If the top expression is a single statement then the loop has nothing to do
    142          * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack */
    143         ExecStack.Push(program);
    144 
    145         if (Configuration.TopLevelPushCode) CodeStack.Insert(0, program);
    146 
    147         // run top expression
    148         DoStep();
    149 
    150         Interpret();
    151       }
     137      PoolContainer.CreatePools();
     138
     139      IsPaused = stepwise;
     140
     141      /* Push top expression so the loop is able to enter
     142       * If the top expression is a single statement then the loop has nothing to do
     143       * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack */
     144      ExecStack.Push(program);
     145
     146      if (Configuration.TopLevelPushCode) CodeStack.Insert(0, program);
     147
     148      // run top expression
     149      DoStep();
     150      Interpret();
     151
     152      PoolContainer.DisposePools();
    152153    }
    153154
     
    157158      IsAborted = true;
    158159
    159       if (PushProgramPool != null) PushProgramPool.Dispose();
     160      PoolContainer.DisposePools();
    160161
    161162      if (currentTask != null) await currentTask;
     
    213214      PrintStack("INTEGER", IntegerStack);
    214215
    215       if (CustomExpressions.Count == 0) return;
    216       Console.WriteLine("--------- Custom Expressions ---------");
    217       foreach (var ce in CustomExpressions) {
    218         Console.WriteLine("{0}: {1}", ce.Key, ce.Value);
     216      if (CustomExpressions.Count > 0) {
     217        Console.WriteLine("--------- Custom Expressions ---------");
     218        foreach (var ce in CustomExpressions) {
     219          Console.WriteLine("{0}: {1}", ce.Key, ce.Value);
     220        }
    219221      }
    220222    }
     
    272274      var expression = ExecStack.Pop();
    273275
    274       if (ExecStack.Any(e => e == null)) {
    275         throw new InvalidProgramException();
    276       }
     276      //if (ExecStack.Any(e => e == null)) {
     277      //  throw new InvalidProgramException();
     278      //}
    277279
    278280      var succ = expression.Eval(this);
    279       last = expression;
     281      //last = expression;
    280282
    281283      return succ;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs

    r14747 r14777  
    99  public class PushInterpreterPool {
    1010    private readonly ObjectPool<PooledPushInterpreter> pool;
    11     private ManagedPoolProvider<PushProgram> pushProgramPoolProvider;
    1211
    13     public PushInterpreterPool(PushConfiguration config = null)
     12    public readonly ManagedPoolProvider<PushProgram> PushProgramPoolProvider;
     13    public readonly ManagedPoolProvider<LoopState> LoopStatePoolProvider;
     14    public readonly ManagedPoolProvider<PooledList<Expression>> ExpressionListPoolProvider;
     15
     16
     17    public PushInterpreterPool(IReadOnlyPushConfiguration config = null)
    1418      : this(Environment.ProcessorCount * 2, 1024, null, config) {
    1519    }
    1620
    17     public PushInterpreterPool(int size, int pushProgramPoolPartitionSize, int? maxPartitionCount = null, PushConfiguration config = null) {
     21    public PushInterpreterPool(int size, int pushProgramPoolPartitionSize, int? maxPartitionCount = null, IReadOnlyPushConfiguration config = null) {
    1822      PushGpConfiguration = config ?? new PushConfiguration();
    1923
    20       pushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(pushProgramPoolPartitionSize, maxPartitionCount);
    21       pushProgramPoolProvider.InitDummyPartition(() => new PushProgram());
     24      PushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(pushProgramPoolPartitionSize, () => new PushProgram(), maxPartitionCount);
     25      LoopStatePoolProvider = new ManagedPoolProvider<LoopState>(pushProgramPoolPartitionSize, () => new LoopState(), maxPartitionCount);
     26      ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(pushProgramPoolPartitionSize * 2, () => new PooledList<Expression>(), maxPartitionCount);
    2227
    23       pool = new ObjectPool<PooledPushInterpreter>(() => new PooledPushInterpreter(this, PushGpConfiguration, pushProgramPoolProvider), size);
     28      pool = new ObjectPool<PooledPushInterpreter>(() => {
     29        var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, LoopStatePoolProvider, ExpressionListPoolProvider);
     30        return new PooledPushInterpreter(this, PushGpConfiguration, poolContainer);
     31      }, size);
    2432    }
    2533
    26     public PushConfiguration PushGpConfiguration { get; private set; }
     34    public IReadOnlyPushConfiguration PushGpConfiguration { get; private set; }
    2735
    28     public PooledPushInterpreter GetInstance(IRandom random = null) {
     36    public PooledPushInterpreter Create(IRandom random = null) {
    2937      var interpreter = this.pool.Allocate();
    3038      interpreter.Random = random ?? new FastRandom();
Note: See TracChangeset for help on using the changeset viewer.