Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPMultiplexerSampleTest.cs @ 18068

Last change on this file since 18068 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

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