namespace HeuristicLab.Tests.Benchmark { using System; using System.Linq; using BenchmarkSuite; using HeuristicLab.BenchmarkSuite.Problems; using HeuristicLab.Problems.ProgramSynthesis; using Microsoft.VisualStudio.TestTools.UnitTesting; using Random; [TestClass] public class RandomWalkTests { private static void RandomWalk(BenchmarkSuiteDataDescriptor descriptor) { var instance = new BenchmarkSuiteInstanceProvider(); var data = instance.LoadData(descriptor); var evaluator = new PushBenchmarkSuiteEvaluator(data); var config = new PushConfiguration { EvalPushLimit = data.EvalLimit, MaxProgramLength = data.MaxSize, ErcOptions = data.ErcOptions, }; config.SetEnabledStacks((StackTypes)data.EnabledDataTypes); var pool = new PushInterpreterPool(config); var best = Enumerable .Range(0, 10) .AsParallel() .Select(_ => { var random = new MersenneTwister(1337); var program = LinearCodeGenerator.RandomProgram(data.MaxSize, random, config); var result = evaluator.EvaluateTraining(pool, program, random); return new { Quality = result.AvgQuality, Program = program }; }) .OrderBy(x => x.Quality) .First(); Console.WriteLine("Training: {0}", best.Quality); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void Checksum() { RandomWalk(new Checksum()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void CollatzNumbers() { RandomWalk(new CollatzNumbers()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void CompareStringLengths() { RandomWalk(new CompareStringLengths()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void CountOdds() { RandomWalk(new CountOdds()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void Digits() { RandomWalk(new Digits()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void DoubleLetters() { RandomWalk(new DoubleLetters()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void EvenSquares() { RandomWalk(new EvenSquares()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void ForLoopIndex() { RandomWalk(new ForLoopIndex()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void Grades() { RandomWalk(new Grades()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void LastIndexOfZero() { RandomWalk(new LastIndexOfZero()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void Median() { RandomWalk(new Median()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void MirrorImage() { RandomWalk(new MirrorImage()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void NegativeToZero() { RandomWalk(new NegativeToZero()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void NumberIo() { RandomWalk(new NumberIO()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void PigLatin() { RandomWalk(new PigLatin()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void ReplaceSpaceWithNewLine() { RandomWalk(new ReplaceSpaceWithNewline()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void ScrabbleScore() { RandomWalk(new ScrabbleScore()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void Smallest() { RandomWalk(new Smallest()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void SmallOrLarge() { RandomWalk(new SmallOrLarge()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void StringDifferences() { RandomWalk(new StringDifferences()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void StringLengthsBackwards() { RandomWalk(new StringLengthsBackwards()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void SumOfSquares() { RandomWalk(new SumOfSquares()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void SuperAnagrams() { RandomWalk(new SuperAnagrams()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void Syllables() { RandomWalk(new Syllables()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void VectorAverage() { RandomWalk(new VectorAverage()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void VectorSummed() { RandomWalk(new VectorSummed()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void WallisPi() { RandomWalk(new WallisPi()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void WordStats() { RandomWalk(new WordStats()); } [TestMethod] [TestProperty("Time", "Medium")] [TestCategory("ProblemTest")] public void XWordLines() { RandomWalk(new XWordLines()); } } }