[11450] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16662] | 3 | * Copyright (C) 2002-2019 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 HeuristicLab.Algorithms.EvolutionStrategy;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 26 | using HeuristicLab.Persistence.Default.Xml;
|
---|
| 27 | using HeuristicLab.Problems.TestFunctions;
|
---|
| 28 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Tests {
|
---|
| 31 | [TestClass]
|
---|
| 32 | public class EsGriewankSampleTest {
|
---|
[11514] | 33 | private const string SampleFileName = "ES_Griewank";
|
---|
[11450] | 34 |
|
---|
| 35 | [TestMethod]
|
---|
| 36 | [TestCategory("Samples.Create")]
|
---|
| 37 | [TestProperty("Time", "medium")]
|
---|
| 38 | public void CreateEsGriewankSampleTest() {
|
---|
| 39 | var es = CreateEsGriewankSample();
|
---|
[11514] | 40 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
| 41 | XmlGenerator.Serialize(es, path);
|
---|
[11450] | 42 | }
|
---|
| 43 |
|
---|
| 44 | [TestMethod]
|
---|
| 45 | [TestCategory("Samples.Execute")]
|
---|
| 46 | [TestProperty("Time", "long")]
|
---|
| 47 | public void RunEsGriewankSampleTest() {
|
---|
| 48 | var es = CreateEsGriewankSample();
|
---|
| 49 | es.SetSeedRandomly.Value = false;
|
---|
| 50 | SamplesUtils.RunAlgorithm(es);
|
---|
| 51 | Assert.AreEqual(0, SamplesUtils.GetDoubleResult(es, "BestQuality"));
|
---|
| 52 | Assert.AreEqual(0, SamplesUtils.GetDoubleResult(es, "CurrentAverageQuality"));
|
---|
| 53 | Assert.AreEqual(0, SamplesUtils.GetDoubleResult(es, "CurrentWorstQuality"));
|
---|
| 54 | Assert.AreEqual(100020, SamplesUtils.GetIntResult(es, "EvaluatedSolutions"));
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | private EvolutionStrategy CreateEsGriewankSample() {
|
---|
| 58 | EvolutionStrategy es = new EvolutionStrategy();
|
---|
| 59 |
|
---|
| 60 | #region Problem Configuration
|
---|
| 61 |
|
---|
| 62 | SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem();
|
---|
| 63 |
|
---|
| 64 | problem.ProblemSize.Value = 10;
|
---|
| 65 | problem.EvaluatorParameter.Value = new GriewankEvaluator();
|
---|
| 66 | problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator();
|
---|
| 67 | problem.Maximization.Value = false;
|
---|
| 68 | problem.Bounds = new DoubleMatrix(new double[,] { { -600, 600 } });
|
---|
| 69 | problem.BestKnownQuality.Value = 0;
|
---|
| 70 | problem.BestKnownSolutionParameter.Value = new RealVector(10);
|
---|
| 71 | problem.Name = "Single Objective Test Function";
|
---|
| 72 | problem.Description = "Test function with real valued inputs and a single objective.";
|
---|
| 73 |
|
---|
| 74 | #endregion
|
---|
| 75 |
|
---|
| 76 | #region Algorithm Configuration
|
---|
| 77 |
|
---|
| 78 | es.Name = "Evolution Strategy - Griewank";
|
---|
| 79 | es.Description = "An evolution strategy which solves the 10-dimensional Griewank test function";
|
---|
| 80 | es.Problem = problem;
|
---|
| 81 | SamplesUtils.ConfigureEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator,
|
---|
| 82 | StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>(
|
---|
| 83 | es, 20, 500, 2, 200, 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 | }
|
---|