Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Tests/Benchmark/RandomWalkTests.cs @ 16386

Last change on this file since 16386 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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