Changeset 15273 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Timestamp:
- 07/19/17 12:55:58 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs
r15189 r15273 8 8 9 9 using Attributes; 10 11 using HeuristicLab.BenchmarkSuite; 10 12 11 13 using Stack; … … 60 62 } 61 63 } 64 65 public static void InitExample(this IPushInterpreter interpreter, Example example) { 66 interpreter.BooleanStack.Push(example.InputBoolean); 67 interpreter.IntegerStack.Push(example.InputInteger); 68 interpreter.FloatStack.Push(example.InputFloat); 69 interpreter.CharStack.Push(example.InputChar); 70 interpreter.StringStack.Push(example.InputString); 71 interpreter.StringVectorStack.Push(example.InputStringVector); 72 interpreter.IntegerVectorStack.Push(example.InputIntegerVector); 73 interpreter.FloatVectorStack.Push(example.InputFloatVector); 74 75 interpreter.SetInput( 76 integers: example.InputInteger, 77 floats: example.InputFloat, 78 booleans: example.InputBoolean, 79 chars: example.InputChar, 80 strings: example.InputString, 81 integerVectors: example.InputIntegerVector, 82 floatVectors: example.InputFloatVector, 83 stringVectors: example.InputStringVector); 84 } 62 85 } 63 86 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs
r15189 r15273 11 11 12 12 public interface IPushInterpreter { 13 IRandom Random { get; set;}13 IRandom Random { get; } 14 14 IPushStack<Expression> CodeStack { get; } 15 15 IPushStack<Expression> ExecStack { get; } … … 28 28 IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; } 29 29 IReadOnlyPushConfiguration Configuration { get; } 30 void Clear ();31 void Reset( );30 void ClearStacks(); 31 void Reset(IRandom random = null); 32 32 33 33 void SetInput( -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PooledPushInterpreter.cs
r15032 r15273 15 15 public override void Dispose() { 16 16 base.Dispose(); 17 Clear ();17 ClearStacks(); 18 18 pool.Free(this); 19 19 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r15189 r15273 19 19 private Expression currentProgram; 20 20 21 /// <summary> 22 /// An interpreter for Push 23 /// </summary> 24 /// <param name="config">Determines the runtime behavior of the interpreter</param> 25 /// <param name="random">Note that random may be reseted</param> 26 /// <param name="poolContainer">Used to save resources used by the interpreter</param> 21 27 public PushInterpreter(IReadOnlyPushConfiguration config = null, IRandom random = null, InterpreterPoolContainer poolContainer = null) { 22 Random = random ?? new MersenneTwister(); 28 randomOrigin = random ?? new MersenneTwister(); 29 Random = (IRandom)randomOrigin.Clone(); 23 30 Configuration = config ?? new PushConfiguration(); 24 31 … … 69 76 public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; } 70 77 71 public IRandom Random { get; set; } 78 private IRandom randomOrigin; 79 public IRandom Random { get; private set; } 72 80 73 81 public long ExecCounter { get; private set; } … … 330 338 331 339 /// <summary> 332 /// Reset while interpreter340 /// Reset interpreter which clears and reconfigures stacks and local variables 333 341 /// </summary> 334 public void Reset() { 342 public void Reset(IRandom random = null) { 343 if (random != null) 344 randomOrigin = random; 345 346 // Reset Random 347 Random = (IRandom)randomOrigin.Clone(); 348 335 349 ExecCounter = 0; 336 350 IsAborted = false; … … 340 354 341 355 inputExpressions.Clear(); 342 Clear ();356 ClearStacks(); 343 357 ConfigureStacks(); 344 358 } … … 357 371 /// Clears Stacks and custom expressions 358 372 /// </summary> 359 public void Clear () {373 public void ClearStacks() { 360 374 for (var i = 0u; i < supportedStackTypes.Length; i++) { 361 375 var key = supportedStackTypes[i]; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs
r15189 r15273 5 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; 6 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 7 using HeuristicLab.Random;8 7 9 8 public class PushInterpreterPool { … … 33 32 public PooledPushInterpreter Create(IRandom random = null) { 34 33 var interpreter = pool.Allocate(); 35 interpreter.Random = random ?? new MersenneTwister(); 36 interpreter.Reset(); 34 interpreter.Reset(random); 37 35 38 36 return interpreter; … … 40 38 41 39 public void Free(PooledPushInterpreter interpreter) { 42 interpreter. Random = null;40 interpreter.ClearStacks(); 43 41 pool.Free(interpreter); 44 42 }
Note: See TracChangeset
for help on using the changeset viewer.