Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Tests/Benchmark/RandomWalkTests.cs @ 15857

Last change on this file since 15857 was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

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