Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Benchmark/RandomWalkTests.cs @ 15273

Last change on this file since 15273 was 15017, checked in by pkimmesw, 7 years ago

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File size: 6.5 KB
Line 
1namespace HeuristicLab.Tests.Benchmark {
2  using System;
3  using System.Linq;
4  using BenchmarkSuite;
5
6  using HeuristicLab.BenchmarkSuite.Problems;
7
8  using Microsoft.VisualStudio.TestTools.UnitTesting;
9  using Problems.ProgramSynthesis.Push.Configuration;
10  using Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
11  using Problems.ProgramSynthesis.Push.Interpreter;
12  using Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite;
13  using Problems.ProgramSynthesis.Push.Stack;
14  using Random;
15
16  [TestClass]
17  public class RandomWalkTests {
18    private static void RandomWalk(BenchmarkSuiteDataDescriptor descriptor) {
19      var instance = new BenchmarkSuiteInstanceProvider();
20      var data = instance.LoadData(descriptor);
21      var evaluator = new PushBenchmarkSuiteEvaluator(data);
22
23      var config = new PushConfiguration {
24        EvalPushLimit = data.EvalLimit,
25        MaxPointsInProgram = data.MaxSize,
26        ErcOptions = data.ErcOptions,
27      };
28
29      config.SetEnabledStacks((StackTypes)data.EnabledDataTypes);
30
31      var pool = new PushInterpreterPool(config);
32      var best = Enumerable
33        .Range(0, 10)
34        .AsParallel()
35        .Select(_ => {
36          var random = new MersenneTwister(1337);
37          var program = LinearCodeGenerator.RandomProgram(data.MaxSize, random, config);
38          var result = evaluator.EvaluateTraining(pool, program, random);
39
40          return new {
41            Quality = result.AvgQuality,
42            Program = program
43          };
44        })
45        .OrderBy(x => x.Quality)
46        .First();
47
48      Console.WriteLine("Training: {0}", best.Quality);
49    }
50
51    [TestMethod]
52    [TestProperty("Time", "Medium")]
53    [TestCategory("ProblemTest")]
54    public void Checksum() {
55      RandomWalk(new Checksum());
56    }
57
58    [TestMethod]
59    [TestProperty("Time", "Medium")]
60    [TestCategory("ProblemTest")]
61    public void CollatzNumbers() {
62      RandomWalk(new CollatzNumbers());
63    }
64
65    [TestMethod]
66    [TestProperty("Time", "Medium")]
67    [TestCategory("ProblemTest")]
68    public void CompareStringLengths() {
69      RandomWalk(new CompareStringLengths());
70    }
71
72    [TestMethod]
73    [TestProperty("Time", "Medium")]
74    [TestCategory("ProblemTest")]
75    public void CountOdds() {
76      RandomWalk(new CountOdds());
77    }
78
79    [TestMethod]
80    [TestProperty("Time", "Medium")]
81    [TestCategory("ProblemTest")]
82    public void Digits() {
83      RandomWalk(new Digits());
84    }
85
86    [TestMethod]
87    [TestProperty("Time", "Medium")]
88    [TestCategory("ProblemTest")]
89    public void DoubleLetters() {
90      RandomWalk(new DoubleLetters());
91    }
92
93    [TestMethod]
94    [TestProperty("Time", "Medium")]
95    [TestCategory("ProblemTest")]
96    public void EvenSquares() {
97      RandomWalk(new EvenSquares());
98    }
99
100    [TestMethod]
101    [TestProperty("Time", "Medium")]
102    [TestCategory("ProblemTest")]
103    public void ForLoopIndex() {
104      RandomWalk(new ForLoopIndex());
105    }
106
107    [TestMethod]
108    [TestProperty("Time", "Medium")]
109    [TestCategory("ProblemTest")]
110    public void Grades() {
111      RandomWalk(new Grades());
112    }
113
114    [TestMethod]
115    [TestProperty("Time", "Medium")]
116    [TestCategory("ProblemTest")]
117    public void LastIndexOfZero() {
118      RandomWalk(new LastIndexOfZero());
119    }
120
121    [TestMethod]
122    [TestProperty("Time", "Medium")]
123    [TestCategory("ProblemTest")]
124    public void Median() {
125      RandomWalk(new Median());
126    }
127
128    [TestMethod]
129    [TestProperty("Time", "Medium")]
130    [TestCategory("ProblemTest")]
131    public void MirrorImage() {
132      RandomWalk(new MirrorImage());
133    }
134
135    [TestMethod]
136    [TestProperty("Time", "Medium")]
137    [TestCategory("ProblemTest")]
138    public void NegativeToZero() {
139      RandomWalk(new NegativeToZero());
140    }
141
142    [TestMethod]
143    [TestProperty("Time", "Medium")]
144    [TestCategory("ProblemTest")]
145    public void NumberIo() {
146      RandomWalk(new NumberIO());
147    }
148
149    [TestMethod]
150    [TestProperty("Time", "Medium")]
151    [TestCategory("ProblemTest")]
152    public void PigLatin() {
153      RandomWalk(new PigLatin());
154    }
155
156    [TestMethod]
157    [TestProperty("Time", "Medium")]
158    [TestCategory("ProblemTest")]
159    public void ReplaceSpaceWithNewLine() {
160      RandomWalk(new ReplaceSpaceWithNewline());
161    }
162
163    [TestMethod]
164    [TestProperty("Time", "Medium")]
165    [TestCategory("ProblemTest")]
166    public void ScrabbleScore() {
167      RandomWalk(new ScrabbleScore());
168    }
169
170    [TestMethod]
171    [TestProperty("Time", "Medium")]
172    [TestCategory("ProblemTest")]
173    public void Smallest() {
174      RandomWalk(new Smallest());
175    }
176
177    [TestMethod]
178    [TestProperty("Time", "Medium")]
179    [TestCategory("ProblemTest")]
180    public void SmallOrLarge() {
181      RandomWalk(new SmallOrLarge());
182    }
183
184    [TestMethod]
185    [TestProperty("Time", "Medium")]
186    [TestCategory("ProblemTest")]
187    public void StringDifferences() {
188      RandomWalk(new StringDifferences());
189    }
190
191    [TestMethod]
192    [TestProperty("Time", "Medium")]
193    [TestCategory("ProblemTest")]
194    public void StringLengthsBackwards() {
195      RandomWalk(new StringLengthsBackwards());
196    }
197
198    [TestMethod]
199    [TestProperty("Time", "Medium")]
200    [TestCategory("ProblemTest")]
201    public void SumOfSquares() {
202      RandomWalk(new SumOfSquares());
203    }
204
205    [TestMethod]
206    [TestProperty("Time", "Medium")]
207    [TestCategory("ProblemTest")]
208    public void SuperAnagrams() {
209      RandomWalk(new SuperAnagrams());
210    }
211
212    [TestMethod]
213    [TestProperty("Time", "Medium")]
214    [TestCategory("ProblemTest")]
215    public void Syllables() {
216      RandomWalk(new Syllables());
217    }
218
219    [TestMethod]
220    [TestProperty("Time", "Medium")]
221    [TestCategory("ProblemTest")]
222    public void VectorAverage() {
223      RandomWalk(new VectorAverage());
224    }
225
226    [TestMethod]
227    [TestProperty("Time", "Medium")]
228    [TestCategory("ProblemTest")]
229    public void VectorSummed() {
230      RandomWalk(new VectorSummed());
231    }
232
233    [TestMethod]
234    [TestProperty("Time", "Medium")]
235    [TestCategory("ProblemTest")]
236    public void WallisPi() {
237      RandomWalk(new WallisPi());
238    }
239
240    [TestMethod]
241    [TestProperty("Time", "Medium")]
242    [TestCategory("ProblemTest")]
243    public void WordStats() {
244      RandomWalk(new WordStats());
245    }
246
247    [TestMethod]
248    [TestProperty("Time", "Medium")]
249    [TestCategory("ProblemTest")]
250    public void XWordLines() {
251      RandomWalk(new XWordLines());
252    }
253  }
254}
Note: See TracBrowser for help on using the repository browser.