Last change
on this file since 14744 was
14744,
checked in by pkimmesw, 7 years ago
|
#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger
|
File size:
1.2 KB
|
Line | |
---|
1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter {
|
---|
2 | using System;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
|
---|
7 | using HeuristicLab.Random;
|
---|
8 |
|
---|
9 | public class PushInterpreterPool {
|
---|
10 | private readonly ObjectPool<PooledPushInterpreter> pool;
|
---|
11 |
|
---|
12 | public PushInterpreterPool(PushConfiguration config = null)
|
---|
13 | : this(Environment.ProcessorCount * 2, config) {
|
---|
14 | }
|
---|
15 |
|
---|
16 | public PushInterpreterPool(int size, PushConfiguration config = null) {
|
---|
17 | this.PushGpConfiguration = config ?? new PushConfiguration();
|
---|
18 |
|
---|
19 | this.pool = new ObjectPool<PooledPushInterpreter>(() => new PooledPushInterpreter(this, this.PushGpConfiguration), size);
|
---|
20 | }
|
---|
21 |
|
---|
22 | public PushConfiguration PushGpConfiguration { get; private set; }
|
---|
23 |
|
---|
24 | public PooledPushInterpreter GetInstance(IRandom random = null) {
|
---|
25 | var interpreter = this.pool.Allocate();
|
---|
26 | interpreter.Random = random ?? new FastRandom();
|
---|
27 |
|
---|
28 | return interpreter;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void Free(PooledPushInterpreter interpreter) {
|
---|
32 | this.pool.Free(interpreter);
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.