Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushGpInterpreterPool.cs @ 14727

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

#2665 PushGP HL Integration, Views, Parameters

File size: 1.2 KB
Line 
1namespace 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 PushGpInterpreterPool {
10    private readonly ObjectPool<PooledPushGpInterpreter> pool;
11
12    public PushGpInterpreterPool(PushGpConfiguration config = null)
13      : this(Environment.ProcessorCount * 2, config) {
14    }
15
16    public PushGpInterpreterPool(int size, PushGpConfiguration config = null) {
17      this.PushGpConfiguration = config ?? new PushGpConfiguration();
18
19      this.pool = new ObjectPool<PooledPushGpInterpreter>(() => new PooledPushGpInterpreter(this, this.PushGpConfiguration), size);
20    }
21
22    public PushGpConfiguration PushGpConfiguration { get; private set; }
23
24    public PooledPushGpInterpreter 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(PooledPushGpInterpreter interpreter) {
32      this.pool.Free(interpreter);
33    }
34  }
35}
Note: See TracBrowser for help on using the repository browser.