Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPMultiplexerSampleTest.cs @ 13611

Last change on this file since 13611 was 13163, checked in by gkronber, 9 years ago

#2472: adapted the multiplexer sample to use the specific implementation of the multiplexer problem instead of symbolic regression. Added best known solutions for the Boolean benchmark problems

File size: 3.1 KB
RevLine 
[11051]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11051]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.IO;
23using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
25using HeuristicLab.Persistence.Default.Xml;
26using HeuristicLab.Selection;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28
29namespace HeuristicLab.Tests {
30  [TestClass]
31  public class GPMultiplexerSampleTest {
[11514]32    private const string SampleFileName = "GP_Multiplexer";
[11051]33
34    [TestMethod]
35    [TestCategory("Samples.Create")]
36    [TestProperty("Time", "medium")]
37    public void CreateGpMultiplexerSampleTest() {
38      var ga = CreateGpMultiplexerSample();
[11514]39      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
[11051]40      XmlGenerator.Serialize(ga, path);
41    }
42    [TestMethod]
43    [TestCategory("Samples.Execute")]
44    [TestProperty("Time", "long")]
45    public void RunGpMultiplexerSampleTest() {
46      var osga = CreateGpMultiplexerSample();
47      osga.SetSeedRandomly.Value = false;
48      SamplesUtils.RunAlgorithm(osga);
49
[13163]50      Assert.AreEqual(1856, SamplesUtils.GetDoubleResult(osga, "BestQuality"), 1E-8);
51      Assert.AreEqual(1784.76, SamplesUtils.GetDoubleResult(osga, "CurrentAverageQuality"), 1E-8);
52      Assert.AreEqual(1536, SamplesUtils.GetDoubleResult(osga, "CurrentWorstQuality"), 1E-8);
53      Assert.AreEqual(66900, SamplesUtils.GetIntResult(osga, "EvaluatedSolutions"));
[11051]54    }
55
56    public static OffspringSelectionGeneticAlgorithm CreateGpMultiplexerSample() {
[13163]57      var problem = new HeuristicLab.Problems.GeneticProgramming.Boolean.MultiplexerProblem();
[11051]58      problem.Name = "11-Multiplexer Problem";
[13163]59      problem.Encoding.TreeLength = 50;
60      problem.Encoding.TreeDepth = 50;
[11051]61
62      var osga = new OffspringSelectionGeneticAlgorithm();
[13160]63      osga.Name = "Genetic Programming - Multiplexer 11 Problem";
[11051]64      osga.Description = "A genetic programming algorithm that solves the 11-bit multiplexer problem.";
65      osga.Problem = problem;
66      SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>
67        (osga, popSize: 100, elites: 1, maxGens: 50, mutationRate: 0.25);
68      osga.MaximumSelectionPressure.Value = 200;
69      return osga;
70
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.