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.GeneticAlgorithm;
|
---|
25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
26 | using HeuristicLab.Selection;
|
---|
27 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Tests {
|
---|
30 | /// <summary>
|
---|
31 | /// Summary description for GPLawnMowerSampleTest
|
---|
32 | /// </summary>
|
---|
33 | [TestClass]
|
---|
34 | public class GPLawnMowerSampleTest {
|
---|
35 | private const string samplesDirectory = SamplesUtils.Directory;
|
---|
36 | [ClassInitialize]
|
---|
37 | public static void MyClassInitialize(TestContext testContext) {
|
---|
38 | if (!Directory.Exists(samplesDirectory))
|
---|
39 | Directory.CreateDirectory(samplesDirectory);
|
---|
40 | }
|
---|
41 |
|
---|
42 | [TestMethod]
|
---|
43 | [TestCategory("Samples.Execute")]
|
---|
44 | [TestProperty("Time", "long")]
|
---|
45 | public void RunGpLawnMowerSampleTest() {
|
---|
46 | var ga = CreateGpLawnMowerSample();
|
---|
47 | ga.SetSeedRandomly.Value = false;
|
---|
48 | SamplesUtils.RunAlgorithm(ga);
|
---|
49 | }
|
---|
50 |
|
---|
51 | public GeneticAlgorithm CreateGpLawnMowerSample() {
|
---|
52 | GeneticAlgorithm ga = new GeneticAlgorithm();
|
---|
53 |
|
---|
54 | #region Problem Configuration
|
---|
55 |
|
---|
56 | var problem = new HeuristicLab.Problems.LawnMower.Problem();
|
---|
57 |
|
---|
58 | #endregion
|
---|
59 |
|
---|
60 | #region Algorithm Configuration
|
---|
61 |
|
---|
62 | ga.Name = "Genetic Programming - Lawn Mower";
|
---|
63 | ga.Description = "A standard genetic programming algorithm to solve the lawn mower problem";
|
---|
64 | ga.Problem = problem;
|
---|
65 | SamplesUtils
|
---|
66 | .ConfigureGeneticAlgorithmParameters
|
---|
67 | <TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>(
|
---|
68 | ga, 1000, 1, 50, 0.25, 5);
|
---|
69 | var mutator = (MultiSymbolicExpressionTreeArchitectureManipulator)ga.Mutator;
|
---|
70 | mutator.Operators.SetItemCheckedState(mutator.Operators
|
---|
71 | .OfType<OnePointShaker>()
|
---|
72 | .Single(), false);
|
---|
73 |
|
---|
74 | #endregion
|
---|
75 |
|
---|
76 | return ga;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|