Changeset 14602 for branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli
- Timestamp:
- 01/25/17 01:53:30 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli/Program.cs
r14513 r14602 26 26 27 27 Console.WriteLine("\nPress any key to continue..."); 28 29 //if (args.Length == 0) return; 30 31 //var code = args[0]; 32 //EvaluateStepwise(code).Wait(); 33 28 34 Console.ReadKey(); 29 35 } 30 36 31 static void SimpleTest() { 32 var interpreter = new PushGpInterpreter(); 33 34 interpreter.Interpret("5 INTEGER.DUP INTEGER.+"); 35 36 interpreter.PrintStacks(); 37 } 38 39 static async Task Stepwise() { 40 var interpreter = new PushGpInterpreter(); 41 42 interpreter.InterpretAsync("( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )", true).Wait(); 37 static async Task EvaluateStepwise(string code) { 38 var interpreter = new PushGpInterpreter(new Configuration { 39 TopLevelPushCode = false 40 }); 41 42 interpreter.RunAsync(code, true).Wait(); 43 43 44 44 while (!interpreter.IsCompleted) { … … 59 59 } 60 60 61 static void SimpleTest() { 62 var interpreter = new PushGpInterpreter(); 63 64 interpreter.Run("5 INTEGER.DUP INTEGER.+"); 65 66 interpreter.PrintStacks(); 67 } 68 69 static async Task Stepwise() { 70 var interpreter = new PushGpInterpreter(); 71 72 interpreter.RunAsync("( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )", true).Wait(); 73 74 while (!interpreter.IsCompleted) { 75 Console.Clear(); 76 interpreter.PrintStacks(); 77 interpreter.Step(); 78 79 var input = Console.ReadKey(); 80 if (input.Key == ConsoleKey.Escape) { 81 break; 82 } else if (input.Key == ConsoleKey.Spacebar) { 83 await interpreter.ResumeAsync(); 84 } 85 } 86 87 Console.Clear(); 88 interpreter.PrintStacks(); 89 } 90 61 91 static void PerformanceTestInterpreter() { 62 92 var program = PushGPParser.Parse("( 5 INTEGER.DUP INTEGER.+ )"); … … 67 97 sw.Start(); 68 98 for (var i = 0; i < 60000000; i++) { 69 interpreter. Interpret(program);99 interpreter.Run(program); 70 100 interpreter.Clear(); 71 101 } … … 94 124 95 125 for (var j = 0; j < amount; j++) { 96 interpreter. Interpret(program);126 interpreter.Run(program); 97 127 interpreter.Clear(); 98 128 } … … 111 141 sw.Stop(); 112 142 113 Console.WriteLine( string.Format("Generated {0} in {1}", expressions.Count(), sw.Elapsed));143 Console.WriteLine("Generated {0} in {1}", expressions.Count(), sw.Elapsed); 114 144 } 115 145 … … 131 161 var program = CodeGenerator.RandomProgram(maxProgramSizeLimit); 132 162 133 interpreter. Interpret(program);163 interpreter.Run(program); 134 164 135 165 execCounters[i] += interpreter.ExecCounter; … … 150 180 151 181 using (var interpreter = pool.GetInstance()) { 152 interpreter. Interpret("( 1 2 INTEGER.+ )");182 interpreter.Run("( 1 2 INTEGER.+ )"); 153 183 154 184 id = interpreter.GetHashCode(); … … 158 188 using (var interpreter = pool.GetInstance()) 159 189 using (var interpreter2 = pool.GetInstance()) { 160 interpreter. Interpret("( 1 2 INTEGER.+ )");190 interpreter.Run("( 1 2 INTEGER.+ )"); 161 191 if (id == interpreter.GetHashCode()) Console.WriteLine("equal 2"); 162 192 if (id == interpreter2.GetHashCode()) Console.WriteLine("equal 3"); … … 198 228 solution => { 199 229 interpreter.Clear(); 200 interpreter. Interpret(solution);230 interpreter.Run(solution); 201 231 return interpreter.IntegerStack.Top == 10; 202 232 });
Note: See TracChangeset
for help on using the changeset viewer.