Changeset 14900 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Benchmark/RandomWalkTests.cs
- Timestamp:
- 04/30/17 19:16:09 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Benchmark/RandomWalkTests.cs
r14897 r14900 1 1 namespace HeuristicLab.Tests.Benchmark { 2 2 using System; 3 using System. Threading.Tasks;3 using System.Linq; 4 4 using BenchmarkSuite; 5 5 … … 8 8 using Microsoft.VisualStudio.TestTools.UnitTesting; 9 9 using Problems.ProgramSynthesis.Push.Configuration; 10 using Problems.ProgramSynthesis.Push.Expressions;11 10 using Problems.ProgramSynthesis.Push.Generators.CodeGenerator; 12 11 using Problems.ProgramSynthesis.Push.Interpreter; 13 12 using Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite; 14 using Problems.ProgramSynthesis.Push.Simplifier;15 13 using Problems.ProgramSynthesis.Push.Stack; 16 14 using Random; … … 21 19 var iterations = 2; 22 20 var best = double.MaxValue; 23 var lockObj = new object();24 21 var random = new MersenneTwister(1337); 25 22 … … 37 34 38 35 var pool = new PushInterpreterPool(config); 39 PushProgram bestProgram = null; 40 41 Parallel.For(0u, iterations, i => { 42 var program = RecursiveCodeGenerator.RandomProgram(data.MaxSize, random, config); 43 var avg = evaluator.EvaluateTraining(pool, program, random); 44 45 lock (lockObj) { 46 if (avg.TotalQuality < best) { 47 best = avg.TotalQuality; 48 bestProgram = program; 49 } 50 } 51 }); 36 var bestProgram = Enumerable 37 .Range(0, iterations) 38 .AsParallel() 39 .Select(_ => { 40 var program = LinearCodeGenerator.RandomProgram(data.MaxSize, random, config); 41 var result = evaluator.EvaluateTraining(pool, program, random); 42 43 return new { 44 Quality = result.TotalQuality, 45 Program = program 46 }; 47 }) 48 .OrderBy(x => x.Quality) 49 .Select(x => x.Program) 50 .First(); 51 // var program = RecursiveCodeGenerator.RandomProgram(data.MaxSize, random, config); 52 // var avg = evaluator.EvaluateTraining(pool, program, random); 53 54 // lock (lockObj) { 55 // if (avg.TotalQuality < best) { 56 // best = avg.TotalQuality; 57 // bestProgram = program; 58 // } 59 // } 60 //}); 52 61 53 62 var averageTestResult = evaluator.EvaluateTest(pool, bestProgram, random); 54 var simplifiedProgram = Simplifier.Simplify(55 bestProgram,56 p => evaluator.EvaluateTraining(pool, p, random).TotalQuality);63 //var simplifiedProgram = Simplifier.Simplify( 64 // bestProgram, 65 // p => evaluator.EvaluateTraining(pool, p, random).TotalQuality); 57 66 58 67 Console.WriteLine("Training: {0}", best); 59 68 Console.WriteLine("RandomWalk: {0}", averageTestResult.TotalQuality); 60 Console.WriteLine("Best program (simplified): {0}", simplifiedProgram);69 //Console.WriteLine("Best program (simplified): {0}", simplifiedProgram); 61 70 } 62 71
Note: See TracChangeset
for help on using the changeset viewer.