[11450] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11450] | 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 | [TestClass]
|
---|
| 33 | public class GeSymbolicRegressionSampleTest {
|
---|
[11514] | 34 | #region artificial ant
|
---|
| 35 | private const string GeArtificialAntSampleFileName = "GE_ArtificialAnt";
|
---|
[11450] | 36 |
|
---|
| 37 | [TestMethod]
|
---|
| 38 | [TestCategory("Samples.Create")]
|
---|
| 39 | [TestProperty("Time", "medium")]
|
---|
| 40 | public void CreateGeArtificialAntSampleTest() {
|
---|
| 41 | var geaa = CreateGeArtificialAntSample();
|
---|
[11514] | 42 | string path = Path.Combine(SamplesUtils.SamplesDirectory, GeArtificialAntSampleFileName + SamplesUtils.SampleFileExtension);
|
---|
| 43 | XmlGenerator.Serialize(geaa, path);
|
---|
[11450] | 44 | }
|
---|
| 45 |
|
---|
| 46 | [TestMethod]
|
---|
| 47 | [TestCategory("Samples.Execute")]
|
---|
| 48 | [TestProperty("Time", "long")]
|
---|
| 49 | public void RunGeArtificalAntSampleTest() {
|
---|
| 50 | var ga = CreateGeArtificialAntSample();
|
---|
| 51 | ga.SetSeedRandomly.Value = false;
|
---|
| 52 | SamplesUtils.RunAlgorithm(ga);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public OffspringSelectionGeneticAlgorithm CreateGeArtificialAntSample() {
|
---|
| 56 | OffspringSelectionGeneticAlgorithm ga = new OffspringSelectionGeneticAlgorithm();
|
---|
[11514] | 57 |
|
---|
[11450] | 58 | #region Problem Configuration
|
---|
| 59 | var problem = new HeuristicLab.Problems.GrammaticalEvolution.GEArtificialAntProblem();
|
---|
| 60 | #endregion
|
---|
| 61 | #region Algorithm Configuration
|
---|
| 62 | ga.Name = "Grammatical Evolution - Artificial Ant (SantaFe)";
|
---|
| 63 | ga.Description = "Grammatical evolution algorithm for solving a artificial ant problem";
|
---|
| 64 | ga.Problem = problem;
|
---|
| 65 | SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
|
---|
| 66 | ga, 200, 1, 50, 0.05, 200);
|
---|
| 67 | #endregion
|
---|
[11514] | 68 |
|
---|
[11450] | 69 | return ga;
|
---|
| 70 | }
|
---|
| 71 | #endregion
|
---|
| 72 |
|
---|
| 73 | #region symbolic regression
|
---|
[11514] | 74 | private const string GeSymbolicRegressionSampleFileName = "GE_SymbReg";
|
---|
| 75 |
|
---|
[11450] | 76 | [TestMethod]
|
---|
| 77 | [TestCategory("Samples.Create")]
|
---|
| 78 | [TestProperty("Time", "medium")]
|
---|
| 79 | public void CreateGeSymbolicRegressionSampleTest() {
|
---|
| 80 | var geSymbReg = CreateGeSymbolicRegressionSample();
|
---|
[11514] | 81 | string path = Path.Combine(SamplesUtils.SamplesDirectory, GeSymbolicRegressionSampleFileName + SamplesUtils.SampleFileExtension);
|
---|
| 82 | XmlGenerator.Serialize(geSymbReg, path);
|
---|
[11450] | 83 | }
|
---|
| 84 |
|
---|
| 85 | [TestMethod]
|
---|
| 86 | [TestCategory("Samples.Execute")]
|
---|
| 87 | [TestProperty("Time", "long")]
|
---|
| 88 | public void RunGeSymbolicRegressionSampleTest() {
|
---|
| 89 | var ga = CreateGeSymbolicRegressionSample();
|
---|
| 90 | ga.SetSeedRandomly.Value = false;
|
---|
| 91 | SamplesUtils.RunAlgorithm(ga);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public OffspringSelectionGeneticAlgorithm CreateGeSymbolicRegressionSample() {
|
---|
| 95 | var ga = new OffspringSelectionGeneticAlgorithm();
|
---|
[11514] | 96 |
|
---|
[11450] | 97 | #region Problem Configuration
|
---|
| 98 | var problem = new HeuristicLab.Problems.GrammaticalEvolution.GESymbolicRegressionSingleObjectiveProblem();
|
---|
| 99 |
|
---|
| 100 | #endregion
|
---|
| 101 | #region Algorithm Configuration
|
---|
| 102 | ga.Name = "Grammatical Evolution - Symbolic Regression (Poly-10)";
|
---|
| 103 | ga.Description = "Grammatical evolution algorithm for solving a symbolic regression problem problem";
|
---|
| 104 | ga.Problem = problem;
|
---|
| 105 | problem.Load(new PolyTen().GenerateRegressionData());
|
---|
| 106 |
|
---|
| 107 | // must occur after loading problem data because the grammar creates symbols for random constants once the data is loaded
|
---|
| 108 | var consts = problem.SymbolicExpressionTreeGrammar.AllowedSymbols.OfType<Constant>().ToList();
|
---|
| 109 | foreach (var c in consts) {
|
---|
| 110 | problem.SymbolicExpressionTreeGrammar.RemoveSymbol(c);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
|
---|
| 114 | ga, 1000, 1, 50, 0.05, 200);
|
---|
| 115 | #endregion
|
---|
[11514] | 116 |
|
---|
[11450] | 117 | return ga;
|
---|
| 118 | }
|
---|
[11514] | 119 | #endregion
|
---|
[11450] | 120 | }
|
---|
| 121 | }
|
---|