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.OffspringSelectionEvolutionStrategy;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
27 | using HeuristicLab.Problems.TestFunctions;
|
---|
28 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Tests {
|
---|
31 | [TestClass]
|
---|
32 | public class OSESGriewankSampleTest {
|
---|
33 | private const string SampleFileName = "OSES_Griewank";
|
---|
34 | private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
35 |
|
---|
36 | [TestMethod]
|
---|
37 | [TestCategory("Samples.Create")]
|
---|
38 | [TestProperty("Time", "medium")]
|
---|
39 | public void CreateOSESGriewankSampleTest() {
|
---|
40 | var es = CreateOSESGriewankSample();
|
---|
41 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
42 | serializer.Serialize(es, path);
|
---|
43 | }
|
---|
44 |
|
---|
45 | [TestMethod]
|
---|
46 | [TestCategory("Samples.Execute")]
|
---|
47 | [TestProperty("Time", "long")]
|
---|
48 | public void RunOSESGriewankSampleTest() {
|
---|
49 | var es = CreateOSESGriewankSample();
|
---|
50 | es.SetSeedRandomly.Value = false;
|
---|
51 | SamplesUtils.RunAlgorithm(es);
|
---|
52 | Assert.AreEqual(1.80366417E-07, SamplesUtils.GetDoubleResult(es, "BestQuality"), 1.0E-15);
|
---|
53 | Assert.AreEqual(4.84418627E-07, SamplesUtils.GetDoubleResult(es, "CurrentAverageQuality"), 1.0E-15);
|
---|
54 | Assert.AreEqual(9.20629802E-07, SamplesUtils.GetDoubleResult(es, "CurrentWorstQuality"), 1.0E-15);
|
---|
55 | Assert.AreEqual(39750, SamplesUtils.GetIntResult(es, "EvaluatedSolutions"));
|
---|
56 | }
|
---|
57 |
|
---|
58 | private OffspringSelectionEvolutionStrategy CreateOSESGriewankSample() {
|
---|
59 | OffspringSelectionEvolutionStrategy es = new OffspringSelectionEvolutionStrategy();
|
---|
60 |
|
---|
61 | #region Problem Configuration
|
---|
62 |
|
---|
63 | SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem();
|
---|
64 |
|
---|
65 | problem.ProblemSize.Value = 10;
|
---|
66 | problem.EvaluatorParameter.Value = new GriewankEvaluator();
|
---|
67 | problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator();
|
---|
68 | problem.Maximization.Value = false;
|
---|
69 | problem.Bounds = new DoubleMatrix(new double[,] { { -600, 600 } });
|
---|
70 | problem.BestKnownQuality.Value = 0;
|
---|
71 | problem.BestKnownSolutionParameter.Value = new RealVector(10);
|
---|
72 | problem.Name = "Single Objective Test Function";
|
---|
73 | problem.Description = "Test function with real valued inputs and a single objective.";
|
---|
74 |
|
---|
75 | #endregion
|
---|
76 |
|
---|
77 | #region Algorithm Configuration
|
---|
78 |
|
---|
79 | es.Name = "Offspring Selection Evolution Strategy - Griewank";
|
---|
80 | es.Description = "An evolution strategy with offspring selection which solves the 10-dimensional Griewank test function";
|
---|
81 | es.Problem = problem;
|
---|
82 | SamplesUtils.ConfigureOffspringSelectionEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator,
|
---|
83 | StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>(es, 50, 1.0, 0.5, 100, 2, 100, false);
|
---|
84 |
|
---|
85 | StdDevStrategyVectorCreator strategyCreator = (StdDevStrategyVectorCreator)es.StrategyParameterCreator;
|
---|
86 | strategyCreator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1, 20 } });
|
---|
87 |
|
---|
88 | StdDevStrategyVectorManipulator strategyManipulator =
|
---|
89 | (StdDevStrategyVectorManipulator)es.StrategyParameterManipulator;
|
---|
90 | strategyManipulator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1E-12, 30 } });
|
---|
91 | strategyManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.22360679774997896);
|
---|
92 | strategyManipulator.LearningRateParameter.Value = new DoubleValue(0.39763536438352531);
|
---|
93 |
|
---|
94 | #endregion
|
---|
95 |
|
---|
96 | return es;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|