Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/ObjectPools/Random/SeededRandomPool.cs @ 15771

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

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

File size: 819 bytes
Line 
1using System;
2
3using HeuristicLab.Core;
4using HeuristicLab.Random;
5
6namespace HeuristicLab.Problems.ProgramSynthesis {
7
8  public class SeededRandomPool {
9    public int Seed;
10    protected readonly ObjectPool<IRandom> Pool;
11
12    public SeededRandomPool() : this(new System.Random().Next()) { }
13
14    public SeededRandomPool(int seed) : this(seed, () => new FastRandom()) { }
15
16    public SeededRandomPool(int seed, Func<IRandom> randomCreator) {
17      Seed = seed;
18      Pool = new ObjectPool<IRandom>(randomCreator);
19    }
20
21    public IRandom ResetAndAllocate() {
22      var random = Pool.Allocate();
23      random.Reset(Seed);
24
25      return random;
26    }
27
28    public void Free(IRandom random) {
29      Pool.Free(random);
30    }
31
32    public void Clear() {
33      Pool.Clear();
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.