Ignore:
Timestamp:
04/10/17 00:27:31 (3 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File:
1 edited

Legend:

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

    r14777 r14834  
    2222      expressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(partitionSize, () => new PooledList<Expression>(), maxPartitionCount);
    2323
    24       InitStatefulExpressionPools();
     24      InitStatefulExpressionPools(partitionSize, maxPartitionCount);
    2525    }
    2626
     
    3333      this.expressionListPoolProvider = expressionListPoolProvider;
    3434
    35       InitStatefulExpressionPools();
     35      InitStatefulExpressionPools(1024, 2048);
    3636    }
    3737
    38     public IManagedPool<PushProgram> PushProgramPool { get; private set; }
    39     public IManagedPool<LoopState> LoopStatePool { get; private set; }
    40     public IManagedPool<PooledList<Expression>> ExpressionListPool { get; private set; }
     38    private IManagedPool<PushProgram> pushProgramPool;
     39    public IManagedPool<PushProgram> PushProgramPool
     40    {
     41      get
     42      {
     43        if (pushProgramPool == null) pushProgramPool = pushProgramPoolProvider.CreatePool();
     44        return pushProgramPool;
     45      }
     46    }
    4147
    42     private void InitStatefulExpressionPools() {
     48    private IManagedPool<LoopState> loopStatePool;
     49    public IManagedPool<LoopState> LoopStatePool
     50    {
     51      get
     52      {
     53        if (loopStatePool == null) loopStatePool = loopStatePoolProvider.CreatePool();
     54        return loopStatePool;
     55      }
     56    }
     57
     58    private IManagedPool<PooledList<Expression>> expressionListPool;
     59    public IManagedPool<PooledList<Expression>> ExpressionListPool
     60    {
     61      get
     62      {
     63        if (expressionListPool == null) expressionListPool = expressionListPoolProvider.CreatePool();
     64        return expressionListPool;
     65      }
     66    }
     67
     68    private void InitStatefulExpressionPools(int partitionSize, int maxPartitionCount) {
    4369      for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) {
    4470        var type = ExpressionTable.StatefulExpressionTypes[i];
    4571        var name = ExpressionTable.TypeToNameTable[type];
    46         var factory = ExpressionTable.StatefulExpressionFactory[name];
    4772
    48         statefulExpressionPoolProviders.Add(type, new ManagedPoolProvider<Expression>(1024, factory));
     73        statefulExpressionPoolProviders.Add(type, new ManagedPoolProvider<Expression>(
     74          partitionSize,
     75          ExpressionTable.StatefulExpressionFactory[name],
     76          maxPartitionCount));
    4977
    5078        statefulExpressionPools.Add(type, null);
     
    5280    }
    5381
    54     public IManagedPool<Expression> GetStatefulExpressionPool<T, StateT>() where T : StatefulExpression<StateT> {
    55       return statefulExpressionPools[typeof(T)];
     82    public T GetStatefulExpression<T>() where T : Expression {
     83      var type = typeof(T);
     84      if (statefulExpressionPools[type] == null)
     85        statefulExpressionPools[type] = statefulExpressionPoolProviders[type].CreatePool();
     86
     87      return (T)statefulExpressionPools[type].Get();
    5688    }
    5789
    58     public T GetStatefulExpression<T>() where T : Expression {
    59       return (T)statefulExpressionPools[typeof(T)].Get();
    60     }
     90    public void DisposePools() {
     91      if (pushProgramPool != null) {
     92        pushProgramPool.Dispose();
     93        pushProgramPool = null;
     94      }
    6195
    62     public void CreatePools() {
    63       PushProgramPool = pushProgramPoolProvider.CreatePool();
    64       LoopStatePool = loopStatePoolProvider.CreatePool();
    65       ExpressionListPool = expressionListPoolProvider.CreatePool();
     96      if (loopStatePool != null) {
     97        loopStatePool.Dispose();
     98        loopStatePool = null;
     99      }
     100
     101      if (expressionListPool != null) {
     102        expressionListPool.Dispose();
     103        expressionListPool = null;
     104      }
    66105
    67106      for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) {
    68107        var type = ExpressionTable.StatefulExpressionTypes[i];
    69         statefulExpressionPools[type] = statefulExpressionPoolProviders[type].CreatePool();
    70       }
    71     }
     108        var pool = statefulExpressionPools[type];
    72109
    73     public void DisposePools() {
    74       if (PushProgramPool != null) PushProgramPool.Dispose();
    75       if (LoopStatePool != null) LoopStatePool.Dispose();
    76       if (ExpressionListPool != null) ExpressionListPool.Dispose();
    77 
    78       for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) {
    79         var type = ExpressionTable.StatefulExpressionTypes[i];
    80         if (statefulExpressionPools[type] != null) statefulExpressionPools[type].Dispose();
     110        if (pool != null) {
     111          pool.Dispose();
     112          statefulExpressionPools[type] = null;
     113        }
    81114      }
    82115    }
Note: See TracChangeset for help on using the changeset viewer.