Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs @ 15334

Last change on this file since 15334 was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

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