Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Tests/HeuristicLab-3.3/Samples/EsGriewankSampleTest.cs @ 18068

Last change on this file since 18068 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

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