Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs @ 13648

Last change on this file since 13648 was 13648, checked in by gkronber, 8 years ago

#2581: added unit test for MCTS for symbolic regression

File size: 22.4 KB
Line 
1using System;
2using System.Linq;
3using System.Threading;
4using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression;
5using HeuristicLab.Data;
6using HeuristicLab.Optimization;
7using HeuristicLab.Problems.DataAnalysis;
8using HeuristicLab.Tests;
9using Microsoft.VisualStudio.TestTools.UnitTesting;
10
11namespace HeuristicLab.Algorithms.DataAnalysis {
12  [TestClass()]
13  public class MctsSymbolicRegressionTest {
14    #region number of solutions
15    // the algorithm should visits each solution only once
16    [TestMethod]
17    [TestCategory("Algorithms.DataAnalysis")]
18    [TestProperty("Time", "short")]
19    public void MctsSymbRegNumberOfSolutionsOneVariable() {
20      // this problem has only one variable
21      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
22      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
23      {
24        // possible solutions with max one variable reference:
25        // x
26        // log(x)
27        // exp(x)
28        // 1/x
29        TestMctsNumberOfSolutions(regProblem, 1, 4);
30      }
31      {
32        // possible solutions with max two variable references:
33        // x
34        // log(x)
35        // exp(x)
36        // 1/x
37        //              -- 4
38        // x * x
39        // x * log(x)
40        // x * exp(x)
41        // x * 1/x
42        // x + x
43        // x + log(x)
44        // x + exp(x)
45        // x + 1/x
46        //              -- 8
47        // log(x) * log(x)
48        // log(x) * exp(x)
49        // log(x) * 1/x
50        // log(x) + log(x)
51        // log(x) + exp(x)
52        // log(x) + 1/x
53        //              -- 6
54        // exp(x) * exp(x)
55        // exp(x) * 1/x
56        // exp(x) + exp(x)
57        // exp(x) + 1/x
58        //              -- 4
59        // 1/x * 1/x
60        // 1/x + 1/x
61        //              -- 2
62        // log(x+x)
63        // log(x*x)
64        // exp(x*x)
65        // 1/(x+x)
66        // 1/(x*x)
67        //              -- 5
68        TestMctsNumberOfSolutions(regProblem, 2, 29);
69      }
70      {
71        // possible solutions with max three variable references:
72        // without log and inv
73        // x
74        // exp(x)
75        //              -- 2
76        // x * x
77        // x + x
78        // x * exp(x)
79        // x + exp(x)
80        // exp(x) * exp(x)
81        // exp(x) + exp(x)
82        // exp(x*x)
83        //              -- 7
84        // x * x * x
85        // x + x * x
86        // x * x + x                                        !!
87        // x + x + x
88        // x * x * exp(x)
89        // x + x * exp(x)
90        // x * x + exp(x)
91        // x + x + exp(x)
92        // x * exp(x) + x                                   !!
93        // x * exp(x) + exp(x)
94        // x + exp(x) * exp(x)
95        // x + exp(x) + exp(x)
96        // x * exp(x) * exp(x)
97        // x * exp(x*x)
98        // x + exp(x*x)
99        //              -- 15
100
101        // exp(x) * exp(x) * exp(x)
102        // exp(x) + exp(x) * exp(x)
103        // exp(x) * exp(x) + exp(x)                         !!
104        // exp(x) + exp(x) + exp(x)
105        //              -- 4
106
107        // exp(x)   * exp(x*x)
108        // exp(x)   + exp(x*x)
109        // exp(x*x) * exp(x)                                !!
110        // exp(x*x) + exp(x)                                !!
111        //              -- 4
112        // exp(x*x*x)
113        //              -- 1
114
115        TestMctsNumberOfSolutions(regProblem, 3, 2 + 7 + 15 + 4 + 4 + 1, allowLog: false, allowInv: false);
116      }
117    }
118
119    [TestMethod]
120    [TestCategory("Algorithms.DataAnalysis")]
121    [TestProperty("Time", "short")]
122    public void MctsSymbRegNumberOfSolutionsTwoVariables() {
123      // this problem has only two input variables
124      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
125      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
126      {
127        // possible solutions with max one variable reference:
128        // x
129        // log(x)
130        // exp(x)
131        // 1/x
132        // y
133        // log(y)
134        // exp(y)
135        // 1/y
136        TestMctsNumberOfSolutions(regProblem, 1, 8);
137      }
138      {
139        // possible solutions with max one variable reference:
140        // without log and inv
141
142        // x
143        // exp(x)
144        // y
145        // exp(y)
146        TestMctsNumberOfSolutions(regProblem, 1, 4, allowLog: false, allowInv: false);
147      }
148      {
149        // possible solutions with max two variable references:
150        // without log and inv
151
152        // x
153        // y
154        // exp(x)
155        // exp(y)
156        //                  -- 4
157        // x (*|+) x
158        // x (*|+) exp(x)
159        // x (*|+) y
160        // x (*|+) exp(y)
161        //                  -- 8
162        // exp(x) (*|+) exp(x)
163        // exp(x) (*|+) exp(y)
164        //                  -- 4
165        // y (*|+) y
166        // y (*|+) exp(x)
167        // y (*|+) exp(y)
168        //                  -- 6
169        // exp(y) (*|+) exp(y)
170        //                  -- 2
171        //
172        // exp(x*x)
173        // exp(x*y)
174        // exp(y*y)
175        //                  -- 3
176
177        TestMctsNumberOfSolutions(regProblem, 2, 4 + 8 + 4 + 6 + 2 + 3, allowLog: false, allowInv: false);
178      }
179
180      {
181        // possible solutions with max two variable references:
182        // without exp and sum
183        // x
184        // y
185        // log(x)
186        // log(y)
187        // inv(x)
188        // inv(y)
189        //              -- 6
190        // x * x
191        // x * y
192        // x * log(x)
193        // x * log(y)
194        // x * inv(x)
195        // x * inv(y)
196        //              -- 6
197        // log(x) * log(x)
198        // log(x) * log(y)
199        // log(x) * inv(x)
200        // log(x) * inv(y)
201        //              -- 4
202        // inv(x) * inv(x)
203        // inv(x) * inv(y)
204        //              -- 2
205        // y * y
206        // y * log(x)
207        // y * log(y)
208        // y * inv(x)
209        // y * inv(y)
210        //              -- 5
211        // log(y) * log(y)
212        // log(y) * inv(x)
213        // log(y) * inv(y)
214        //              -- 3
215        // inv(y) * inv(y)
216        //              -- 1
217        // log(x*x)
218        // log(x*y)
219        // log(y*y)
220
221        // inv(x*x)
222        // inv(x*y)
223        // inv(y*y)
224        //             -- 6
225        // log(x+x)
226        // log(x+y)
227        // log(y+y)
228
229        // inv(x+x)
230        // inv(x+y)
231        // inv(y+y)
232        //             -- 6
233        TestMctsNumberOfSolutions(regProblem, 2, 6 + 6 + 4 + 2 + 5 + 3 + 1 + 6 + 6, allowExp: false, allowSum: false);
234      }
235    }
236    #endregion
237
238    #region Nguyen
239    [TestMethod]
240    [TestCategory("Algorithms.DataAnalysis")]
241    [TestProperty("Time", "short")]
242    public void MctsSymbRegBenchmarkNguyen1() {
243      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
244      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
245      TestMcts(regProblem);
246    }
247    [TestMethod]
248    [TestCategory("Algorithms.DataAnalysis")]
249    [TestProperty("Time", "short")]
250    public void MctsSymbRegBenchmarkNguyen2() {
251      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
252      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 ")));
253      TestMcts(regProblem);
254    }
255    [TestMethod]
256    [TestCategory("Algorithms.DataAnalysis")]
257    [TestProperty("Time", "short")]
258    public void MctsSymbRegBenchmarkNguyen3() {
259      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
260      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));
261      TestMcts(regProblem, successThreshold: 0.99);
262    }
263    [TestMethod]
264    [TestCategory("Algorithms.DataAnalysis")]
265    [TestProperty("Time", "short")]
266    public void MctsSymbRegBenchmarkNguyen4() {
267      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
268      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 ")));
269      TestMcts(regProblem);
270    }
271    [TestMethod]
272    [TestCategory("Algorithms.DataAnalysis")]
273    [TestProperty("Time", "short")]
274    public void MctsSymbRegBenchmarkNguyen5() {
275      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
276      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F5 ")));
277      TestMcts(regProblem);
278    }
279    [TestMethod]
280    [TestCategory("Algorithms.DataAnalysis")]
281    [TestProperty("Time", "short")]
282    public void MctsSymbRegBenchmarkNguyen6() {
283      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
284      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 ")));
285      TestMcts(regProblem);
286    }
287    [TestMethod]
288    [TestCategory("Algorithms.DataAnalysis")]
289    [TestProperty("Time", "short")]
290    public void MctsSymbRegBenchmarkNguyen7() {
291      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
292      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
293      TestMcts(regProblem);
294    }
295    [TestMethod]
296    [TestCategory("Algorithms.DataAnalysis")]
297    [TestProperty("Time", "short")]
298    public void MctsSymbRegBenchmarkNguyen8() {
299      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
300      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F8 ")));
301      TestMcts(regProblem, successThreshold: 0.99);
302    }
303    [TestMethod]
304    [TestCategory("Algorithms.DataAnalysis")]
305    [TestProperty("Time", "short")]
306    public void MctsSymbRegBenchmarkNguyen9() {
307      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
308      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
309      TestMcts(regProblem, iterations: 10000);
310    }
311    [TestMethod]
312    [TestCategory("Algorithms.DataAnalysis")]
313    [TestProperty("Time", "short")]
314    public void MctsSymbRegBenchmarkNguyen10() {
315      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
316      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F10 ")));
317      TestMcts(regProblem);
318    }
319    [TestMethod]
320    [TestCategory("Algorithms.DataAnalysis")]
321    [TestProperty("Time", "short")]
322    public void MctsSymbRegBenchmarkNguyen11() {
323      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
324      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F11 ")));
325      TestMcts(regProblem, 10000, 0.95); // cannot solve exactly in 10000 iterations
326    }
327    [TestMethod]
328    [TestCategory("Algorithms.DataAnalysis")]
329    [TestProperty("Time", "short")]
330    public void MctsSymbRegBenchmarkNguyen12() {
331      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
332      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F12 ")));
333      TestMcts(regProblem, iterations: 10000, successThreshold: 0.99, allowLog: false, allowExp: false, allowInv: false);
334    }
335
336    #endregion
337
338    #region keijzer
339    [TestMethod]
340    [TestCategory("Algorithms.DataAnalysis")]
341    [TestProperty("Time", "long")]
342    public void MctsSymbRegBenchmarkKeijzer5() {
343      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
344      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 5 f(")));
345      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
346      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
347      TestMcts(regProblem, iterations: 10000, allowExp: false, allowLog: false, allowSum: false, successThreshold: 0.99);
348    }
349
350    [TestMethod]
351    [TestCategory("Algorithms.DataAnalysis")]
352    [TestProperty("Time", "short")]
353    public void MctsSymbRegBenchmarkKeijzer6() {
354      // Keijzer 6 f(x) = Sum(1 / i) From 1 to X
355      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
356      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 6 f(")));
357      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
358      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
359      TestMcts(regProblem, allowLog: false, allowExp: false, successThreshold: 0.995); // cannot solve
360    }
361
362    [TestMethod]
363    [TestCategory("Algorithms.DataAnalysis")]
364    [TestProperty("Time", "short")]
365    public void MctsSymbRegBenchmarkKeijzer7() {
366      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
367      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 7 f(")));
368      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
369      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
370      TestMcts(regProblem);
371    }
372
373    [TestMethod]
374    [TestCategory("Algorithms.DataAnalysis")]
375    [TestProperty("Time", "short")]
376    public void MctsSymbRegBenchmarkKeijzer8() {
377      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
378      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 8 f(")));
379      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
380      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
381      TestMcts(regProblem);
382    }
383
384    [TestMethod]
385    [TestCategory("Algorithms.DataAnalysis")]
386    [TestProperty("Time", "short")]
387    public void MctsSymbRegBenchmarkKeijzer9() {
388      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
389      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 9 f(")));
390      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
391      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
392      TestMcts(regProblem);
393    }
394
395    /*
396     * cannot solve this yet x^y
397    [TestMethod]
398    [TestCategory("Algorithms.DataAnalysis")]
399    [TestProperty("Time", "short")]
400    public void MctsSymbRegBenchmarkKeijzer10() {
401      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
402      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 10 f(")));
403      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
404      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
405      TestMcts(regProblem, iterations: 10000, successThreshold: 0.99);
406    }
407     */
408
409    /* cannot solve this yet
410     * xy + sin( (x-1) (y-1) )
411    [TestMethod]
412    [TestCategory("Algorithms.DataAnalysis")]
413    [TestProperty("Time", "short")]
414    public void MctsSymbRegBenchmarkKeijzer11() {
415      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
416      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 11 f(")));
417      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
418      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
419      TestMcts(regProblem, successThreshold: 0.99); // cannot solve this yet
420    }
421     */
422    [TestMethod]
423    [TestCategory("Algorithms.DataAnalysis")]
424    [TestProperty("Time", "short")]
425    public void MctsSymbRegBenchmarkKeijzer12() {
426      // sames a Nguyen 12
427      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
428      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 12 f(")));
429      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
430      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
431      TestMcts(regProblem, iterations: 10000, allowLog: false, allowExp: false, allowInv: false, successThreshold: 0.99); // cannot solve exactly in 10000 iterations
432    }
433    [TestMethod]
434    [TestCategory("Algorithms.DataAnalysis")]
435    [TestProperty("Time", "short")]
436    public void MctsSymbRegBenchmarkKeijzer14() {
437      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
438      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 14 f(")));
439      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
440      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
441      TestMcts(regProblem);
442    }
443    [TestMethod]
444    [TestCategory("Algorithms.DataAnalysis")]
445    [TestProperty("Time", "short")]
446    public void MctsSymbRegBenchmarkKeijzer15() {
447      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
448      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 15 f(")));
449      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
450      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
451      TestMcts(regProblem, iterations: 10000, allowLog: false, allowExp: false, allowInv: false);
452    }
453    #endregion
454
455    private void TestMcts(IRegressionProblemData problemData, int iterations = 2000, double successThreshold = 0.999,
456      bool allowExp = true,
457      bool allowLog = true,
458      bool allowInv = true,
459      bool allowSum = true
460      ) {
461      var mctsSymbReg = new MctsSymbolicRegressionAlgorithm();
462      var regProblem = new RegressionProblem();
463      regProblem.ProblemDataParameter.Value = problemData;
464      #region Algorithm Configuration
465      mctsSymbReg.Problem = regProblem;
466      mctsSymbReg.Iterations = iterations;
467      mctsSymbReg.MaxSize = 10;
468      mctsSymbReg.C = 2; // less greedy
469      mctsSymbReg.SetSeedRandomly = false;
470      mctsSymbReg.Seed = 1234;
471      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp")), allowExp);
472      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog);
473      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 /")), allowInv);
474      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("sum of multiple")), allowSum);
475      #endregion
476      RunAlgorithm(mctsSymbReg);
477
478      Console.WriteLine(mctsSymbReg.ExecutionTime);
479      // R² >= 0.999
480      // using arequal to get output of the actual value
481      var eps = 1.0 - successThreshold;
482      Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (train)"].Value).Value, eps);
483      Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (test)"].Value).Value, eps);
484    }
485
486    private void TestMctsNumberOfSolutions(IRegressionProblemData problemData, int maxNumberOfVariables, int expectedNumberOfSolutions,
487      bool allowExp = true,
488      bool allowLog = true,
489      bool allowInv = true,
490      bool allowSum = true
491  ) {
492      var mctsSymbReg = new MctsSymbolicRegressionAlgorithm();
493      var regProblem = new RegressionProblem();
494      regProblem.ProblemDataParameter.Value = problemData;
495      #region Algorithm Configuration
496      mctsSymbReg.Problem = regProblem;
497      mctsSymbReg.Iterations = int.MaxValue; // stopping when all solutions have been enumerated
498      mctsSymbReg.MaxSize = maxNumberOfVariables;
499      mctsSymbReg.C = 1000; // essentially breath first seach
500      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp")), allowExp);
501      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog);
502      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 /")), allowInv);
503      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("sum of multiple")), allowSum);
504      #endregion
505      RunAlgorithm(mctsSymbReg);
506
507      Console.WriteLine(mctsSymbReg.ExecutionTime);
508      Assert.AreEqual(expectedNumberOfSolutions, ((IntValue)mctsSymbReg.Results["Iterations"].Value).Value);
509    }
510
511
512    // same as in SamplesUtil
513    private void RunAlgorithm(IAlgorithm a) {
514      var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);
515      Exception ex = null;
516      a.Stopped += (src, e) => { trigger.Set(); };
517      a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };
518      a.Prepare();
519      a.Start();
520      trigger.WaitOne();
521
522      Assert.AreEqual(ex, null);
523    }
524
525  }
526}
Note: See TracBrowser for help on using the repository browser.