Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Parameter-less Population Pyramid/ParameterlessPopulationPyramid.Test/ParameterlessPopulationPyramidTest.cs @ 11733

Last change on this file since 11733 was 11672, checked in by bgoldman, 10 years ago

#2282 Commenting, added some basic unit tests for P3.

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