Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs @ 17432

Last change on this file since 17432 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 1.9 KB
RevLine 
[15771]1using System;
2using HeuristicLab.Core;
3
4namespace HeuristicLab.Problems.ProgramSynthesis {
[14744]5  public class PushInterpreterPool {
6    private readonly ObjectPool<PooledPushInterpreter> pool;
7
[14777]8    public readonly ManagedPoolProvider<PushProgram> PushProgramPoolProvider;
9    public readonly ManagedPoolProvider<PooledList<Expression>> ExpressionListPoolProvider;
10
11    public PushInterpreterPool(IReadOnlyPushConfiguration config = null)
[15032]12      : this(Environment.ProcessorCount * 4, 1024, null, config) {
[14744]13    }
14
[14834]15    public PushInterpreterPool(int size, int poolPartitionSize, int? maxPartitionCount = null, IReadOnlyPushConfiguration config = null) {
[15017]16      PushConfiguration = config ?? new PushConfiguration();
[14744]17
[14834]18      PushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(poolPartitionSize, () => new PushProgram(), maxPartitionCount);
[15017]19      ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(poolPartitionSize, () => new PooledList<Expression>(), maxPartitionCount);
[14747]20
[15334]21      pool = new ObjectPool<PooledPushInterpreter>(CreateInterpreter, size);
[14744]22    }
23
[15334]24    private PooledPushInterpreter CreateInterpreter() {
25      var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, ExpressionListPoolProvider);
26      return new PooledPushInterpreter(this, PushConfiguration, poolContainer);
27    }
28
[15017]29    public IReadOnlyPushConfiguration PushConfiguration { get; private set; }
[14744]30
[14777]31    public PooledPushInterpreter Create(IRandom random = null) {
[15341]32      var interpreter = pool.Allocate();
33      interpreter.Reset(random);
[14744]34
35      return interpreter;
36    }
37
38    public void Free(PooledPushInterpreter interpreter) {
[15273]39      interpreter.ClearStacks();
[14834]40      pool.Free(interpreter);
[14744]41    }
[15017]42
43    public void Clear() {
44      PushProgramPoolProvider.Clear();
45      ExpressionListPoolProvider.Clear();
[15189]46      pool.Clear();
[15017]47    }
[14744]48  }
49}
Note: See TracBrowser for help on using the repository browser.