[11672] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) 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 |
|
---|
| 22 | using System;
|
---|
[11939] | 23 | using System.Threading;
|
---|
[11672] | 24 | using HeuristicLab.Common;
|
---|
[11987] | 25 | using HeuristicLab.Problems.Binary;
|
---|
[11939] | 26 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
[11672] | 27 |
|
---|
| 28 | namespace 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 {
|
---|
[14527] | 41 | var ct = new CancellationToken();
|
---|
| 42 | hidden.Invoke("Initialize", ct);
|
---|
| 43 | hidden.Invoke("Run", ct);
|
---|
[11987] | 44 | } catch (OperationCanceledException) {
|
---|
[11672] | 45 | // Ignore
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | Assert.AreEqual(maximumEvaluations, hidden.GetProperty("ResultsEvaluations"), "Total Evaluations");
|
---|
[11939] | 49 | double foundQuality = (double)hidden.GetProperty("ResultsBestQuality");
|
---|
[11672] | 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 | }
|
---|
[11939] | 55 |
|
---|
[11672] | 56 | [TestMethod]
|
---|
[11939] | 57 | [TestProperty("Time", "medium")]
|
---|
| 58 | [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
|
---|
[11672] | 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]
|
---|
[11939] | 72 | [TestProperty("Time", "medium")]
|
---|
| 73 | [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
|
---|
[11672] | 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]
|
---|
[11939] | 88 | [TestProperty("Time", "medium")]
|
---|
| 89 | [TestCategory("Algorithms.ParameterlessPopulationPyramid")]
|
---|
[11672] | 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);
|
---|
[11983] | 97 | DoRun(problem, 130000, 54321, 1, 89214);
|
---|
[11672] | 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|