Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14909 was 14900, checked in by pkimmesw, 7 years ago

#2665 Improved random walk tests

File size: 7.4 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 iterations = 2;
20      var best = double.MaxValue;
21      var random = new MersenneTwister(1337);
22
23      var instance = new BenchmarkSuiteInstanceProvider();
24      var data = instance.LoadData(descriptor);
25      var evaluator = new PushBenchmarkSuiteEvaluator(data);
26
27      var config = new PushConfiguration {
28        EvalPushLimit = data.EvalLimit,
29        MaxPointsInProgram = data.MaxSize,
30        ErcOptions = data.ErcOptions,
31      };
32
33      config.SetEnabledStacks((StackTypes)data.EnabledDataTypes);
34
35      var pool = new PushInterpreterPool(config);
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      //});
61
62      var averageTestResult = evaluator.EvaluateTest(pool, bestProgram, random);
63      //var simplifiedProgram = Simplifier.Simplify(
64      //  bestProgram,
65      //  p => evaluator.EvaluateTraining(pool, p, random).TotalQuality);
66
67      Console.WriteLine("Training: {0}", best);
68      Console.WriteLine("RandomWalk: {0}", averageTestResult.TotalQuality);
69      //Console.WriteLine("Best program (simplified): {0}", simplifiedProgram);
70    }
71
72    [TestMethod]
73    [TestProperty("Time", "Medium")]
74    [TestCategory("ProblemTest")]
75    public void Checksum() {
76      RandomWalk(new Checksum());
77    }
78
79    [TestMethod]
80    [TestProperty("Time", "Medium")]
81    [TestCategory("ProblemTest")]
82    public void CollatzNumbers() {
83      RandomWalk(new CollatzNumbers());
84    }
85
86    [TestMethod]
87    [TestProperty("Time", "Medium")]
88    [TestCategory("ProblemTest")]
89    public void CompareStringLengths() {
90      RandomWalk(new CompareStringLengths());
91    }
92
93    [TestMethod]
94    [TestProperty("Time", "Medium")]
95    [TestCategory("ProblemTest")]
96    public void CountOdds() {
97      RandomWalk(new CountOdds());
98    }
99
100    [TestMethod]
101    [TestProperty("Time", "Medium")]
102    [TestCategory("ProblemTest")]
103    public void Digits() {
104      RandomWalk(new Digits());
105    }
106
107    [TestMethod]
108    [TestProperty("Time", "Medium")]
109    [TestCategory("ProblemTest")]
110    public void DoubleLetters() {
111      RandomWalk(new DoubleLetters());
112    }
113
114    [TestMethod]
115    [TestProperty("Time", "Medium")]
116    [TestCategory("ProblemTest")]
117    public void EvenSquares() {
118      RandomWalk(new EvenSquares());
119    }
120
121    [TestMethod]
122    [TestProperty("Time", "Medium")]
123    [TestCategory("ProblemTest")]
124    public void ForLoopIndex() {
125      RandomWalk(new ForLoopIndex());
126    }
127
128    [TestMethod]
129    [TestProperty("Time", "Medium")]
130    [TestCategory("ProblemTest")]
131    public void Grades() {
132      RandomWalk(new Grades());
133    }
134
135    [TestMethod]
136    [TestProperty("Time", "Medium")]
137    [TestCategory("ProblemTest")]
138    public void LastIndexOfZero() {
139      RandomWalk(new LastIndexOfZero());
140    }
141
142    [TestMethod]
143    [TestProperty("Time", "Medium")]
144    [TestCategory("ProblemTest")]
145    public void Median() {
146      RandomWalk(new Median());
147    }
148
149    [TestMethod]
150    [TestProperty("Time", "Medium")]
151    [TestCategory("ProblemTest")]
152    public void MirrorImage() {
153      RandomWalk(new MirrorImage());
154    }
155
156    [TestMethod]
157    [TestProperty("Time", "Medium")]
158    [TestCategory("ProblemTest")]
159    public void NegativeToZero() {
160      RandomWalk(new NegativeToZero());
161    }
162
163    [TestMethod]
164    [TestProperty("Time", "Medium")]
165    [TestCategory("ProblemTest")]
166    public void NumberIo() {
167      RandomWalk(new NumberIO());
168    }
169
170    [TestMethod]
171    [TestProperty("Time", "Medium")]
172    [TestCategory("ProblemTest")]
173    public void PigLatin() {
174      RandomWalk(new PigLatin());
175    }
176
177    [TestMethod]
178    [TestProperty("Time", "Medium")]
179    [TestCategory("ProblemTest")]
180    public void ReplaceSpaceWithNewLine() {
181      RandomWalk(new ReplaceSpaceWithNewline());
182    }
183
184    [TestMethod]
185    [TestProperty("Time", "Medium")]
186    [TestCategory("ProblemTest")]
187    public void ScrabbleScore() {
188      RandomWalk(new ScrabbleScore());
189    }
190
191    [TestMethod]
192    [TestProperty("Time", "Medium")]
193    [TestCategory("ProblemTest")]
194    public void Smallest() {
195      RandomWalk(new Smallest());
196    }
197
198    [TestMethod]
199    [TestProperty("Time", "Medium")]
200    [TestCategory("ProblemTest")]
201    public void SmallOrLarge() {
202      RandomWalk(new SmallOrLarge());
203    }
204
205    [TestMethod]
206    [TestProperty("Time", "Medium")]
207    [TestCategory("ProblemTest")]
208    public void StringDifferences() {
209      RandomWalk(new StringDifferences());
210    }
211
212    [TestMethod]
213    [TestProperty("Time", "Medium")]
214    [TestCategory("ProblemTest")]
215    public void StringLengthsBackwards() {
216      RandomWalk(new StringLengthsBackwards());
217    }
218
219    [TestMethod]
220    [TestProperty("Time", "Medium")]
221    [TestCategory("ProblemTest")]
222    public void SumOfSquares() {
223      RandomWalk(new SumOfSquares());
224    }
225
226    [TestMethod]
227    [TestProperty("Time", "Medium")]
228    [TestCategory("ProblemTest")]
229    public void SuperAnagrams() {
230      RandomWalk(new SuperAnagrams());
231    }
232
233    [TestMethod]
234    [TestProperty("Time", "Medium")]
235    [TestCategory("ProblemTest")]
236    public void Syllables() {
237      RandomWalk(new Syllables());
238    }
239
240    [TestMethod]
241    [TestProperty("Time", "Medium")]
242    [TestCategory("ProblemTest")]
243    public void VectorAverage() {
244      RandomWalk(new VectorAverage());
245    }
246
247    [TestMethod]
248    [TestProperty("Time", "Medium")]
249    [TestCategory("ProblemTest")]
250    public void VectorSummed() {
251      RandomWalk(new VectorSummed());
252    }
253
254    [TestMethod]
255    [TestProperty("Time", "Medium")]
256    [TestCategory("ProblemTest")]
257    public void WallisPi() {
258      RandomWalk(new WallisPi());
259    }
260
261    [TestMethod]
262    [TestProperty("Time", "Medium")]
263    [TestCategory("ProblemTest")]
264    public void WordStats() {
265      RandomWalk(new WordStats());
266    }
267
268    [TestMethod]
269    [TestProperty("Time", "Medium")]
270    [TestCategory("ProblemTest")]
271    public void XWordLines() {
272      RandomWalk(new XWordLines());
273    }
274  }
275}
Note: See TracBrowser for help on using the repository browser.