Changeset 14875 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Timestamp:
- 04/18/17 01:15:25 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/InterpreterPoolContainer.cs
r14834 r14875 67 67 68 68 private void InitStatefulExpressionPools(int partitionSize, int maxPartitionCount) { 69 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes. Length; i++) {69 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Count; i++) { 70 70 var type = ExpressionTable.StatefulExpressionTypes[i]; 71 71 var name = ExpressionTable.TypeToNameTable[type]; … … 104 104 } 105 105 106 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes. Length; i++) {106 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Count; i++) { 107 107 var type = ExpressionTable.StatefulExpressionTypes[i]; 108 108 var pool = statefulExpressionPools[type]; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r14834 r14875 21 21 private Task currentTask; 22 22 23 24 23 public PushInterpreter(IReadOnlyPushConfiguration config = null, IRandom random = null, InterpreterPoolContainer poolContainer = null) { 25 24 Random = random ?? new FastRandom(); … … 28 27 29 28 // setting the capacity of the stacks to max points ensures that there will be enough memory at runtime 30 ExecStack = new PushStack<Expression>(Configuration. EvalPushLimit);31 32 CodeStack = new PushStack<Expression> (Configuration.EvalPushLimit){29 ExecStack = new PushStack<Expression>(Configuration.MaxPointsInProgram); 30 31 CodeStack = new PushStack<Expression> { 33 32 IsEnabled = Configuration.EnabledStacks[StackTypes.Code] 34 33 }; … … 37 36 IsEnabled = Configuration.EnabledStacks[StackTypes.Code] 38 37 }; 38 39 39 BooleanStack = new PushStack<bool> { 40 40 IsEnabled = Configuration.EnabledStacks[StackTypes.Boolean] 41 41 }; 42 42 43 IntegerStack = new PushStack<long> { 43 44 IsEnabled = Configuration.EnabledStacks[StackTypes.Integer] 44 45 }; 46 45 47 FloatStack = new PushStack<double> { 46 48 IsEnabled = Configuration.EnabledStacks[StackTypes.Float] 47 49 }; 50 48 51 CharStack = new PushStack<char> { 49 52 IsEnabled = Configuration.EnabledStacks[StackTypes.Char] 50 53 }; 54 51 55 StringStack = new PushStack<string> { 52 56 IsEnabled = Configuration.EnabledStacks[StackTypes.String] 53 57 }; 58 54 59 IntegerVectorStack = new PushStack<List<long>> { 55 60 IsEnabled = Configuration.EnabledStacks[StackTypes.IntegerVector] 56 61 }; 62 57 63 FloatVectorStack = new PushStack<List<double>> { 58 64 IsEnabled = Configuration.EnabledStacks[StackTypes.FloatVector] 59 65 }; 66 60 67 BooleanVectorStack = new PushStack<List<bool>> { 61 68 IsEnabled = Configuration.EnabledStacks[StackTypes.BooleanVector] 62 69 }; 70 63 71 StringVectorStack = new PushStack<List<string>> { 64 72 IsEnabled = Configuration.EnabledStacks[StackTypes.StringVector] … … 66 74 67 75 CustomExpressions = new Dictionary<string, Expression>(); 68 69 76 PoolContainer = poolContainer ?? new InterpreterPoolContainer(); 70 77 } … … 76 83 public IRandom Random { get; set; } 77 84 78 public intExecCounter { get; private set; }85 public long ExecCounter { get; private set; } 79 86 80 87 public bool IsPaused { get; private set; } … … 159 166 } 160 167 public async Task RunAsync(Expression expression, CancellationToken token = default(CancellationToken)) { 161 await Task.Run(() => Run(expression , false), token);168 await Task.Run(() => Run(expression), token); 162 169 } 163 170 … … 176 183 ExecStack.Push(expression); 177 184 178 if (Configuration.TopLevelPushCode) CodeStack. Insert(0,expression);185 if (Configuration.TopLevelPushCode) CodeStack.Push(expression); 179 186 180 187 // expand if program … … 183 190 184 191 Run(); 192 } 193 194 public bool CanRun(int count) { 195 return ExecStack.Count >= count && 196 !IsPaused && 197 !IsAborted && 198 ExecCounter + count < Configuration.EvalPushLimit; 185 199 } 186 200 … … 237 251 [MethodImpl(MethodImplOptions.AggressiveInlining)] 238 252 public void Step(int count) { 239 for (var i = 0 ; i < count; i++) Step();253 for (var i = 0u; i < count; i++) Step(); 240 254 } 241 255 242 256 /// <summary> 243 /// Clears stacks257 /// Reset while interpreter 244 258 /// </summary> 245 259 public void Reset() { … … 269 283 [MethodImpl(MethodImplOptions.AggressiveInlining)] 270 284 private void Run() { 285 // if no stack which is modifies the exec stack is enabled, unroll loop due to performance reasons 286 if (!Configuration.EnabledStacks[StackTypes.Exec] && 287 !Configuration.EnabledStacks[StackTypes.Code]) { 288 while (CanRun(10)) 289 DoTenSteps(); 290 } 291 271 292 while (IsRunning) 272 293 DoStep(); … … 314 335 #endif 315 336 337 [MethodImpl(MethodImplOptions.AggressiveInlining)] 338 private void DoTenSteps() { 339 ExecStack[0].Eval(this); 340 ExecStack[1].Eval(this); 341 ExecStack[2].Eval(this); 342 ExecStack[3].Eval(this); 343 ExecStack[4].Eval(this); 344 ExecStack[5].Eval(this); 345 ExecStack[6].Eval(this); 346 ExecStack[7].Eval(this); 347 ExecStack[8].Eval(this); 348 ExecStack[9].Eval(this); 349 350 ExecStack.Remove(10); 351 ExecCounter += 10; 352 } 353 316 354 private Task InterpretAsync() { 317 355 currentTask = Task.Run(() => this.Run());
Note: See TracChangeset
for help on using the changeset viewer.