Changeset 14747 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Timestamp:
- 03/12/17 13:16:56 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PooledPushInterpreter.cs
r14744 r14747 4 4 using HeuristicLab.Core; 5 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 6 8 7 9 public class PooledPushInterpreter : PushInterpreter, IDisposable { … … 9 11 private readonly PushInterpreterPool pool; 10 12 11 public PooledPushInterpreter(PushInterpreterPool pool, PushConfiguration config, IRandom random = null)12 : base(config, random ) {13 public PooledPushInterpreter(PushInterpreterPool pool, PushConfiguration config, ManagedPoolProvider<PushProgram> pushProgramPoolProvider, IRandom random = null) 14 : base(config, random, pushProgramPoolProvider) { 13 15 this.pool = pool; 14 16 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r14746 r14747 19 19 private Task currentTask; 20 20 21 public PushInterpreter(IReadonlyPushConfiguration config = null, IRandom random = null ) {21 public PushInterpreter(IReadonlyPushConfiguration config = null, IRandom random = null, ManagedPoolProvider<PushProgram> pushProgramPoolProvider = null) { 22 22 Random = random ?? new FastRandom(); 23 23 … … 45 45 46 46 CustomExpressions = new Dictionary<string, Expression>(); 47 48 PushProgramPoolProvider = pushProgramPoolProvider ?? new ManagedPoolProvider<PushProgram>(1024); 49 50 if (pushProgramPoolProvider == null) 51 { 52 PushProgramPoolProvider.InitDummyPartition(() => new PushProgram()); 53 } 47 54 } 48 55 … … 86 93 } 87 94 88 public IManagedPool<PushProgram> PushProgramPool { get; set; } 95 private readonly ManagedPoolProvider<PushProgram> PushProgramPoolProvider; 96 public IManagedPool<PushProgram> PushProgramPool { get; private set; } 89 97 90 98 public IReadonlyPushConfiguration Configuration { get; protected set; } … … 127 135 128 136 public void Run(Expression program, bool stepwise = false) { 129 IsPaused = stepwise; 130 131 /* Push top expression so the loop is able to enter 132 * If the top expression is a single statement then the loop has nothing to do 133 * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack */ 134 ExecStack.Push(program); 135 136 if (Configuration.TopLevelPushCode) CodeStack.Insert(0, program); 137 138 // run top expression 139 DoStep(); 140 141 Interpret(); 137 using (PushProgramPool = PushProgramPoolProvider.CreatePool()) { 138 IsPaused = stepwise; 139 140 /* Push top expression so the loop is able to enter 141 * If the top expression is a single statement then the loop has nothing to do 142 * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack */ 143 ExecStack.Push(program); 144 145 if (Configuration.TopLevelPushCode) CodeStack.Insert(0, program); 146 147 // run top expression 148 DoStep(); 149 150 Interpret(); 151 } 142 152 } 143 153 … … 146 156 147 157 IsAborted = true; 158 159 if (PushProgramPool != null) PushProgramPool.Dispose(); 148 160 149 161 if (currentTask != null) await currentTask; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs
r14744 r14747 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter { 2 2 using System; 3 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;5 3 using HeuristicLab.Core; 6 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 7 7 using HeuristicLab.Random; 8 8 9 9 public class PushInterpreterPool { 10 10 private readonly ObjectPool<PooledPushInterpreter> pool; 11 private ManagedPoolProvider<PushProgram> pushProgramPoolProvider; 11 12 12 13 public PushInterpreterPool(PushConfiguration config = null) 13 : this(Environment.ProcessorCount * 2, config) {14 : this(Environment.ProcessorCount * 2, 1024, null, config) { 14 15 } 15 16 16 public PushInterpreterPool(int size, PushConfiguration config = null) {17 this.PushGpConfiguration = config ?? new PushConfiguration();17 public PushInterpreterPool(int size, int pushProgramPoolPartitionSize, int? maxPartitionCount = null, PushConfiguration config = null) { 18 PushGpConfiguration = config ?? new PushConfiguration(); 18 19 19 this.pool = new ObjectPool<PooledPushInterpreter>(() => new PooledPushInterpreter(this, this.PushGpConfiguration), size); 20 pushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(pushProgramPoolPartitionSize, maxPartitionCount); 21 pushProgramPoolProvider.InitDummyPartition(() => new PushProgram()); 22 23 pool = new ObjectPool<PooledPushInterpreter>(() => new PooledPushInterpreter(this, PushGpConfiguration, pushProgramPoolProvider), size); 20 24 } 21 25
Note: See TracChangeset
for help on using the changeset viewer.