Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab/3.3/Tests/SymbolicRegressionTest.cs @ 9760

Last change on this file since 9760 was 6187, checked in by mkommend, 14 years ago

#1521: Updated SymbolicRegressionUnitTest.

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Threading;
24using HeuristicLab.Algorithms.GeneticAlgorithm;
25using HeuristicLab.Common;
26using HeuristicLab.Data;
27using HeuristicLab.Persistence.Default.Xml;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab_33.Tests {
31  [TestClass]
32  public class SymbolicRegressionTest {
33    public SymbolicRegressionTest() { }
34
35    private TestContext testContextInstance;
36
37    /// <summary>
38    ///Gets or sets the test context which provides
39    ///information about and functionality for the current test run.
40    ///</summary>
41    public TestContext TestContext {
42      get {
43        return testContextInstance;
44      }
45      set {
46        testContextInstance = value;
47      }
48    }
49
50    private EventWaitHandle trigger = new AutoResetEvent(false);
51    private Exception ex;
52
53    [TestMethod]
54    [DeploymentItem(@"GA_SymbReg.hl")]
55    public void SymbolicRegressionPerformanceTest() {
56      ex = null;
57      GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize("GA_SymbReg.hl");
58      ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred);
59      ga.Stopped += new EventHandler(ga_Stopped);
60
61      ga.Prepare();
62      ga.Start();
63      trigger.WaitOne();
64      if (ex != null) throw ex;
65
66      TestContext.WriteLine("Runtime: {0}", ga.ExecutionTime.ToString());
67
68      double expectedValidationQuality = 0.72902735951261033;
69      double expectedBestQuality = 0.68726148410052335;
70      double expectedAverageQuality = 0.50555375244787948;
71      double expectedWorstQuality = 0;
72      double bestQuality = (ga.Results["CurrentBestQuality"].Value as DoubleValue).Value;
73      double averageQuality = (ga.Results["CurrentAverageQuality"].Value as DoubleValue).Value;
74      double worstQuality = (ga.Results["CurrentWorstQuality"].Value as DoubleValue).Value;
75      double bestValidationSolutionQuality = (ga.Results["Best validation solution quality"].Value as DoubleValue).Value;
76
77      TestContext.WriteLine("");
78      TestContext.WriteLine("CurrentBestQuality: {0} (should be {1})", bestQuality, expectedBestQuality);
79      TestContext.WriteLine("CurrentAverageQuality: {0} (should be {1})", averageQuality, expectedAverageQuality);
80      TestContext.WriteLine("CurrentWorstQuality: {0} (should be {1})", worstQuality, expectedWorstQuality);
81      TestContext.WriteLine("Best valdidation solution quality: {0} (should be {1})", bestValidationSolutionQuality, expectedValidationQuality);
82
83      Assert.AreEqual(expectedBestQuality, bestQuality);
84      Assert.AreEqual(expectedAverageQuality, averageQuality);
85      Assert.AreEqual(expectedWorstQuality, worstQuality);
86      Assert.AreEqual(expectedValidationQuality, bestValidationSolutionQuality);
87    }
88
89    private void ga_ExceptionOccurred(object sender, EventArgs<Exception> e) {
90      ex = e.Value;
91    }
92
93    private void ga_Stopped(object sender, EventArgs e) {
94      trigger.Set();
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.