source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3/ParameterlessPopulationPyramidTest.cs @ 11956

Last change on this file since 11956 was 11956, checked in by mkommend, 7 years ago

#2282: Created plugin for binary vector problems.

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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.ParameterlessPopulationPyramid;
25using HeuristicLab.Common;
26using HeuristicLab.Problems.BinaryVector;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28
29namespace ParameterlessPopulationPyramid.Test {
30  [TestClass]
31  public class ParameterlessPopulationPyramidTest {
32
33    // Utility function that sets up and executes the run, then asserts the results
34    private PrivateObject DoRun(BinaryVectorProblem problem, int maximumEvaluations, int seed, double bestQuality, int foundOn) {
35      var solver = new HeuristicLab.Algorithms.ParameterlessPopulationPyramid.ParameterlessPopulationPyramid();
36      solver.Problem = problem;
37      solver.MaximumEvaluations = maximumEvaluations;
38      solver.Seed = seed;
39      solver.SetSeedRandomly = false;
40      PrivateObject hidden = new PrivateObject(solver);
41      try {
42        hidden.Invoke("Run", new CancellationToken());
43      }
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, 126082);
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.