1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 |
|
---|
22 | using System.IO;
|
---|
23 | using HEAL.Attic;
|
---|
24 | using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
|
---|
25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
26 | using HeuristicLab.Selection;
|
---|
27 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Tests {
|
---|
30 | [TestClass]
|
---|
31 | public class GPMultiplexerSampleTest {
|
---|
32 | private const string SampleFileName = "GP_Multiplexer";
|
---|
33 |
|
---|
34 | private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
35 |
|
---|
36 | [TestMethod]
|
---|
37 | [TestCategory("Samples.Create")]
|
---|
38 | [TestProperty("Time", "medium")]
|
---|
39 | public void CreateGpMultiplexerSampleTest() {
|
---|
40 | var ga = CreateGpMultiplexerSample();
|
---|
41 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
42 | serializer.Serialize(ga, path);
|
---|
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 |
|
---|
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"));
|
---|
56 | }
|
---|
57 |
|
---|
58 | public static OffspringSelectionGeneticAlgorithm CreateGpMultiplexerSample() {
|
---|
59 | var problem = new HeuristicLab.Problems.GeneticProgramming.Boolean.MultiplexerProblem();
|
---|
60 | problem.Name = "11-Multiplexer Problem";
|
---|
61 | problem.Encoding.TreeLength = 50;
|
---|
62 | problem.Encoding.TreeDepth = 50;
|
---|
63 |
|
---|
64 | var osga = new OffspringSelectionGeneticAlgorithm();
|
---|
65 | osga.Name = "Genetic Programming - Multiplexer 11 Problem";
|
---|
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 | }
|
---|