Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/OSESGriewankSampleTest.cs @ 17544

Last change on this file since 17544 was 17544, checked in by abeham, 4 years ago

#2521: worked on refactoring, worked a lot on binary encoding / problems

File size: 4.3 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.OffspringSelectionEvolutionStrategy;
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 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.Dimension = 10;
66      problem.TestFunction = new Griewank();
67      problem.Encoding.SolutionCreator = new UniformRandomRealVectorCreator();
68      problem.Bounds = new DoubleMatrix(new double[,] { { -600, 600 } });
69      problem.BestKnownQuality = 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 = "Offspring Selection Evolution Strategy - Griewank";
79      es.Description = "An evolution strategy with offspring selection which solves the 10-dimensional Griewank test function";
80      es.Problem = problem;
81      SamplesUtils.ConfigureOffspringSelectionEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator,
82        StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>(es, 50, 1.0, 0.5, 100, 2, 100, false);
83
84      StdDevStrategyVectorCreator strategyCreator = (StdDevStrategyVectorCreator)es.StrategyParameterCreator;
85      strategyCreator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1, 20 } });
86
87      StdDevStrategyVectorManipulator strategyManipulator =
88        (StdDevStrategyVectorManipulator)es.StrategyParameterManipulator;
89      strategyManipulator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1E-12, 30 } });
90      strategyManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.22360679774997896);
91      strategyManipulator.LearningRateParameter.Value = new DoubleValue(0.39763536438352531);
92
93      #endregion
94
95      return es;
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.