1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 System.Linq;
|
---|
24 | using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
|
---|
25 | using HeuristicLab.Persistence.Default.Xml;
|
---|
26 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
27 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
28 | using HeuristicLab.Selection;
|
---|
29 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Tests {
|
---|
32 | /// <summary>
|
---|
33 | /// Summary description for GeSymbolicRegressionSampleTest
|
---|
34 | /// </summary>
|
---|
35 | [TestClass]
|
---|
36 | public class GeSymbolicRegressionSampleTest {
|
---|
37 | private const string samplesDirectory = SamplesUtils.Directory;
|
---|
38 | [ClassInitialize]
|
---|
39 | public static void MyClassInitialize(TestContext testContext) {
|
---|
40 | if (!Directory.Exists(samplesDirectory))
|
---|
41 | Directory.CreateDirectory(samplesDirectory);
|
---|
42 | }
|
---|
43 |
|
---|
44 | #region artificial ant
|
---|
45 | [TestMethod]
|
---|
46 | [TestCategory("Samples.Create")]
|
---|
47 | [TestProperty("Time", "medium")]
|
---|
48 | public void CreateGeArtificialAntSampleTest() {
|
---|
49 | var geaa = CreateGeArtificialAntSample();
|
---|
50 | XmlGenerator.Serialize(geaa, @"Samples\GE_ArtificialAnt.hl");
|
---|
51 | }
|
---|
52 |
|
---|
53 | [TestMethod]
|
---|
54 | [TestCategory("Samples.Execute")]
|
---|
55 | [TestProperty("Time", "long")]
|
---|
56 | public void RunGeArtificalAntSampleTest() {
|
---|
57 | var ga = CreateGeArtificialAntSample();
|
---|
58 | ga.SetSeedRandomly.Value = false;
|
---|
59 | SamplesUtils.RunAlgorithm(ga);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public OffspringSelectionGeneticAlgorithm CreateGeArtificialAntSample() {
|
---|
63 | OffspringSelectionGeneticAlgorithm ga = new OffspringSelectionGeneticAlgorithm();
|
---|
64 | #region Problem Configuration
|
---|
65 | var problem = new HeuristicLab.Problems.GrammaticalEvolution.GEArtificialAntProblem();
|
---|
66 | #endregion
|
---|
67 | #region Algorithm Configuration
|
---|
68 | ga.Name = "Grammatical Evolution - Artificial Ant (SantaFe)";
|
---|
69 | ga.Description = "Grammatical evolution algorithm for solving a artificial ant problem";
|
---|
70 | ga.Problem = problem;
|
---|
71 | SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
|
---|
72 | ga, 200, 1, 50, 0.05, 200);
|
---|
73 | #endregion
|
---|
74 | return ga;
|
---|
75 | }
|
---|
76 | #endregion
|
---|
77 |
|
---|
78 | #region symbolic regression
|
---|
79 | #endregion
|
---|
80 | [TestMethod]
|
---|
81 | [TestCategory("Samples.Create")]
|
---|
82 | [TestProperty("Time", "medium")]
|
---|
83 | public void CreateGeSymbolicRegressionSampleTest() {
|
---|
84 | var geSymbReg = CreateGeSymbolicRegressionSample();
|
---|
85 | XmlGenerator.Serialize(geSymbReg, @"Samples\GE_SymbReg.hl");
|
---|
86 | }
|
---|
87 |
|
---|
88 | [TestMethod]
|
---|
89 | [TestCategory("Samples.Execute")]
|
---|
90 | [TestProperty("Time", "long")]
|
---|
91 | public void RunGeSymbolicRegressionSampleTest() {
|
---|
92 | var ga = CreateGeSymbolicRegressionSample();
|
---|
93 | ga.SetSeedRandomly.Value = false;
|
---|
94 | SamplesUtils.RunAlgorithm(ga);
|
---|
95 | }
|
---|
96 |
|
---|
97 | public OffspringSelectionGeneticAlgorithm CreateGeSymbolicRegressionSample() {
|
---|
98 | var ga = new OffspringSelectionGeneticAlgorithm();
|
---|
99 | #region Problem Configuration
|
---|
100 | var problem = new HeuristicLab.Problems.GrammaticalEvolution.GESymbolicRegressionSingleObjectiveProblem();
|
---|
101 |
|
---|
102 | #endregion
|
---|
103 | #region Algorithm Configuration
|
---|
104 | ga.Name = "Grammatical Evolution - Symbolic Regression (Poly-10)";
|
---|
105 | ga.Description = "Grammatical evolution algorithm for solving a symbolic regression problem problem";
|
---|
106 | ga.Problem = problem;
|
---|
107 | problem.Load(new PolyTen().GenerateRegressionData());
|
---|
108 |
|
---|
109 | // must occur after loading problem data because the grammar creates symbols for random constants once the data is loaded
|
---|
110 | var consts = problem.SymbolicExpressionTreeGrammar.AllowedSymbols.OfType<Constant>().ToList();
|
---|
111 | foreach (var c in consts) {
|
---|
112 | problem.SymbolicExpressionTreeGrammar.RemoveSymbol(c);
|
---|
113 | }
|
---|
114 |
|
---|
115 | SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
|
---|
116 | ga, 1000, 1, 50, 0.05, 200);
|
---|
117 | #endregion
|
---|
118 | return ga;
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|