Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 fixed enable/disable issue for single instruction in selection view

File size: 1.6 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  using HeuristicLab.Random;
8
9  public class PushInterpreterPool {
10    private readonly ObjectPool<PooledPushInterpreter> pool;
11    private ManagedPoolProvider<PushProgram> pushProgramPoolProvider;
12
13    public PushInterpreterPool(PushConfiguration config = null)
14      : this(Environment.ProcessorCount * 2, 1024, null, config) {
15    }
16
17    public PushInterpreterPool(int size, int pushProgramPoolPartitionSize, int? maxPartitionCount = null, PushConfiguration config = null) {
18      PushGpConfiguration = config ?? new PushConfiguration();
19
20      pushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(pushProgramPoolPartitionSize, maxPartitionCount);
21      pushProgramPoolProvider.InitDummyPartition(() => new PushProgram());
22
23      pool = new ObjectPool<PooledPushInterpreter>(() => new PooledPushInterpreter(this, PushGpConfiguration, pushProgramPoolProvider), size);
24    }
25
26    public PushConfiguration PushGpConfiguration { get; private set; }
27
28    public PooledPushInterpreter GetInstance(IRandom random = null) {
29      var interpreter = this.pool.Allocate();
30      interpreter.Random = random ?? new FastRandom();
31
32      return interpreter;
33    }
34
35    public void Free(PooledPushInterpreter interpreter) {
36      this.pool.Free(interpreter);
37    }
38  }
39}
Note: See TracBrowser for help on using the repository browser.