Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3106-AnalyticContinuedFractionsRegression/HeuristicLab.Tests/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3/ParameterlessPopulationPyramidTest.cs @ 17846

Last change on this file since 17846 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Common;
25using HeuristicLab.Problems.Binary;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace ParameterlessPopulationPyramid.Test {
29  [TestClass]
30  public class ParameterlessPopulationPyramidTest {
31
32    // Utility function that sets up and executes the run, then asserts the results
33    private PrivateObject DoRun(BinaryProblem problem, int maximumEvaluations, int seed, double bestQuality, int foundOn) {
34      var solver = new HeuristicLab.Algorithms.ParameterlessPopulationPyramid.ParameterlessPopulationPyramid();
35      solver.Problem = problem;
36      solver.MaximumEvaluations = maximumEvaluations;
37      solver.Seed = seed;
38      solver.SetSeedRandomly = false;
39      PrivateObject hidden = new PrivateObject(solver);
40      try {
41        var ct = new CancellationToken();
42        hidden.Invoke("Initialize", ct);
43        hidden.Invoke("Run", ct);
44      } catch (OperationCanceledException) {
45        // Ignore
46      }
47
48      Assert.AreEqual(maximumEvaluations, hidden.GetProperty("ResultsEvaluations"), "Total Evaluations");
49      double foundQuality = (double)hidden.GetProperty("ResultsBestQuality");
50      Assert.IsTrue(foundQuality.IsAlmost(bestQuality), string.Format("Expected <{0}> Actual <{1}>", bestQuality, foundQuality));
51      Assert.AreEqual(foundOn, hidden.GetProperty("ResultsBestFoundOnEvaluation"), "Found On");
52
53      return hidden;
54    }
55
56    [TestMethod]
57    [TestProperty("Time", "medium")]
58    [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
59    public void P3DeceptiveTrap() {
60      var problem = new DeceptiveTrapProblem();
61      problem.Length = 49;
62      problem.TrapSize = 7;
63      DoRun(problem, 100, 123, 0.857142857142857, 50);
64      DoRun(problem, 9876, 123, 0.918367346938776, 981);
65      DoRun(problem, 20000, 987, 1, 19977);
66      problem.Length = 700;
67      DoRun(problem, 100000, 987, 0.941428571428571, 96901);
68    }
69
70    // Unlike DeceptiveTrap, DeceptiveStepTrap likely contains neutral (fitness equal) modifications.
71    [TestMethod]
72    [TestProperty("Time", "medium")]
73    [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
74    public void P3DeceptiveStepTrap() {
75      var problem = new DeceptiveStepTrapProblem();
76      problem.Length = 49;
77      problem.TrapSize = 7;
78      problem.StepSize = 2;
79      DoRun(problem, 100, 123, 0.5, 6);
80      DoRun(problem, 9876, 123, 0.785714285714286, 3489);
81      DoRun(problem, 70000, 987, 1, 68292);
82      problem.Length = 700;
83      DoRun(problem, 100000, 987, 0.76, 58711);
84    }
85
86    // Unlike the Trap tests, HIFF uses higher order linkage learning.
87    [TestMethod]
88    [TestProperty("Time", "medium")]
89    [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
90    public void P3HIFF() {
91      var problem = new HIFFProblem();
92      problem.Length = 32;
93      DoRun(problem, 50, 12345, 0.375, 26);
94      DoRun(problem, 1000, 12345, 1, 976);
95      problem.Length = 512;
96      DoRun(problem, 1000, 54321, 0.17361111111111, 440);
97      DoRun(problem, 130000, 54321, 1, 89214);
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.