Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13818 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 3.9 KB
RevLine 
[11672]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11672]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;
[11939]23using System.Threading;
[11672]24using HeuristicLab.Common;
[11987]25using HeuristicLab.Problems.Binary;
[11939]26using Microsoft.VisualStudio.TestTools.UnitTesting;
[11672]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
[11987]33    private PrivateObject DoRun(BinaryProblem problem, int maximumEvaluations, int seed, double bestQuality, int foundOn) {
[11672]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 {
[11939]41        hidden.Invoke("Run", new CancellationToken());
[11987]42      } catch (OperationCanceledException) {
[11672]43        // Ignore
44      }
45
46      Assert.AreEqual(maximumEvaluations, hidden.GetProperty("ResultsEvaluations"), "Total Evaluations");
[11939]47      double foundQuality = (double)hidden.GetProperty("ResultsBestQuality");
[11672]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    }
[11939]53
[11672]54    [TestMethod]
[11939]55    [TestProperty("Time", "medium")]
56    [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
[11672]57    public void P3DeceptiveTrap() {
58      var problem = new DeceptiveTrapProblem();
59      problem.Length = 49;
60      problem.TrapSize = 7;
61      DoRun(problem, 100, 123, 0.857142857142857, 50);
62      DoRun(problem, 9876, 123, 0.918367346938776, 981);
63      DoRun(problem, 20000, 987, 1, 19977);
64      problem.Length = 700;
65      DoRun(problem, 100000, 987, 0.941428571428571, 96901);
66    }
67
68    // Unlike DeceptiveTrap, DeceptiveStepTrap likely contains neutral (fitness equal) modifications.
69    [TestMethod]
[11939]70    [TestProperty("Time", "medium")]
71    [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
[11672]72    public void P3DeceptiveStepTrap() {
73      var problem = new DeceptiveStepTrapProblem();
74      problem.Length = 49;
75      problem.TrapSize = 7;
76      problem.StepSize = 2;
77      DoRun(problem, 100, 123, 0.5, 6);
78      DoRun(problem, 9876, 123, 0.785714285714286, 3489);
79      DoRun(problem, 70000, 987, 1, 68292);
80      problem.Length = 700;
81      DoRun(problem, 100000, 987, 0.76, 58711);
82    }
83
84    // Unlike the Trap tests, HIFF uses higher order linkage learning.
85    [TestMethod]
[11939]86    [TestProperty("Time", "medium")]
87    [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
[11672]88    public void P3HIFF() {
89      var problem = new HIFFProblem();
90      problem.Length = 32;
91      DoRun(problem, 50, 12345, 0.375, 26);
92      DoRun(problem, 1000, 12345, 1, 976);
93      problem.Length = 512;
94      DoRun(problem, 1000, 54321, 0.17361111111111, 440);
[11983]95      DoRun(problem, 130000, 54321, 1, 89214);
[11672]96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.