Changeset 15017 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
- Timestamp:
- 06/01/17 09:28:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r14952 r15017 5 5 using System.Threading; 6 6 using System.Threading.Tasks; 7 using Attributes; 7 8 using Configuration; 8 9 using Core; 9 10 using Expressions; 10 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;12 13 11 using Parser; 14 12 using Random; 15 13 using Stack; 16 14 17 #if DEBUG18 using System.Diagnostics;19 using System.Linq;20 #endif21 15 22 16 public class PushInterpreter : IInternalPushInterpreter, IDisposable { … … 24 18 25 19 public PushInterpreter(IReadOnlyPushConfiguration config = null, IRandom random = null, InterpreterPoolContainer poolContainer = null) { 26 Random = random ?? new FastRandom(); 27 20 Random = random ?? new MersenneTwister(); 28 21 Configuration = config ?? new PushConfiguration(); 29 22 … … 59 52 }; 60 53 61 IntegerVectorStack = new PushStack< List<long>> {54 IntegerVectorStack = new PushStack<IReadOnlyList<long>> { 62 55 IsEnabled = Configuration.EnabledStacks[StackTypes.IntegerVector] 63 56 }; 64 57 65 FloatVectorStack = new PushStack< List<double>> {58 FloatVectorStack = new PushStack<IReadOnlyList<double>> { 66 59 IsEnabled = Configuration.EnabledStacks[StackTypes.FloatVector] 67 60 }; 68 61 69 BooleanVectorStack = new PushStack< List<bool>> {62 BooleanVectorStack = new PushStack<IReadOnlyList<bool>> { 70 63 IsEnabled = Configuration.EnabledStacks[StackTypes.BooleanVector] 71 64 }; 72 65 73 StringVectorStack = new PushStack< List<string>> {66 StringVectorStack = new PushStack<IReadOnlyList<string>> { 74 67 IsEnabled = Configuration.EnabledStacks[StackTypes.StringVector] 75 68 }; … … 88 81 { StackTypes.String, StringStack }, 89 82 { StackTypes.Name, NameStack }, 83 { StackTypes.Print, PrintStack }, 90 84 { StackTypes.IntegerVector, IntegerVectorStack }, 91 85 { StackTypes.FloatVector, FloatVectorStack }, 92 86 { StackTypes.BooleanVector, BooleanVectorStack }, 93 87 { StackTypes.StringVector, StringVectorStack }, 94 { StackTypes.Print, PrintStack },95 88 }; 96 89 … … 160 153 public IPushStack<string> StringStack { get; private set; } 161 154 [PushStack(StackTypes.IntegerVector)] 162 public IPushStack< List<long>> IntegerVectorStack { get; private set; }155 public IPushStack<IReadOnlyList<long>> IntegerVectorStack { get; private set; } 163 156 [PushStack(StackTypes.FloatVector)] 164 public IPushStack< List<double>> FloatVectorStack { get; private set; }157 public IPushStack<IReadOnlyList<double>> FloatVectorStack { get; private set; } 165 158 [PushStack(StackTypes.BooleanVector)] 166 public IPushStack< List<bool>> BooleanVectorStack { get; private set; }159 public IPushStack<IReadOnlyList<bool>> BooleanVectorStack { get; private set; } 167 160 [PushStack(StackTypes.StringVector)] 168 public IPushStack< List<string>> StringVectorStack { get; private set; }161 public IPushStack<IReadOnlyList<string>> StringVectorStack { get; private set; } 169 162 [PushStack(StackTypes.Print)] 170 163 public IPushStack<string> PrintStack { get; private set; } … … 186 179 var program = PushParser.Parse(code); 187 180 Run(program, stepwise); 181 } 182 183 public void Run(bool stepwise) { 184 Run(PushProgram.Empty, stepwise); 188 185 } 189 186 … … 322 319 } 323 320 324 #if DEBUG325 private Expression last;326 private bool DoStep() {327 double[] bk;328 if (!FloatStack.IsEmpty) {329 bk = FloatStack.Peek(Math.Min(FloatStack.Count, 3));330 }331 332 var expression = ExecStack.Pop();333 var succ = expression.TryEval(this);334 335 if ((ExecStack.Count > 0 && ExecStack.Top == null) ||336 (CodeStack.Count > 0 && CodeStack.Top == null) ||337 FloatStack.Any(x => double.IsNaN(x) || double.IsInfinity(x)) ||338 StringStack.Count > 0 && StringStack.Any(x => x == null)) {339 Debugger.Break();340 }341 342 ExecCounter++;343 last = expression;344 return succ;345 }346 #else347 321 [MethodImpl(MethodImplOptions.AggressiveInlining)] 348 322 private bool DoStep() { … … 350 324 return ExecStack.Pop().TryEval(this); 351 325 } 352 #endif353 326 354 327 [MethodImpl(MethodImplOptions.AggressiveInlining)]
Note: See TracChangeset
for help on using the changeset viewer.