Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/OSESGriewankSampleTest.cs @ 14791

Last change on this file since 14791 was 13469, checked in by mkommend, 9 years ago

#2521: Refactored problem base classes and adapted scheduling encoding, scheduling problem and unit tests.

File size: 4.3 KB
RevLine 
[13237]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Algorithms.OffspringSelectionEvolutionStrategy;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Persistence.Default.Xml;
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
35    [TestMethod]
36    [TestCategory("Samples.Create")]
37    [TestProperty("Time", "medium")]
38    public void CreateOSESGriewankSampleTest() {
39      var es = CreateOSESGriewankSample();
40      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
41      XmlGenerator.Serialize(es, path);
42    }
43
44    [TestMethod]
45    [TestCategory("Samples.Execute")]
46    [TestProperty("Time", "long")]
47    public void RunOSESGriewankSampleTest() {
48      var es = CreateOSESGriewankSample();
49      es.SetSeedRandomly.Value = false;
50      SamplesUtils.RunAlgorithm(es);
51      Assert.AreEqual(1.80366417E-07, SamplesUtils.GetDoubleResult(es, "BestQuality"), 1.0E-15);
52      Assert.AreEqual(4.84418627E-07, SamplesUtils.GetDoubleResult(es, "CurrentAverageQuality"), 1.0E-15);
53      Assert.AreEqual(9.20629802E-07, SamplesUtils.GetDoubleResult(es, "CurrentWorstQuality"), 1.0E-15);
54      Assert.AreEqual(39750, SamplesUtils.GetIntResult(es, "EvaluatedSolutions"));
55    }
56
57    private OffspringSelectionEvolutionStrategy CreateOSESGriewankSample() {
58      OffspringSelectionEvolutionStrategy es = new OffspringSelectionEvolutionStrategy();
59
60      #region Problem Configuration
61
62      SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem();
63
[13408]64      problem.ProblemSize = 10;
65      problem.TestFunction = new Griewank();
[13469]66      problem.Encoding.SolutionCreator = new UniformRandomRealVectorCreator();
[13237]67      problem.Bounds = new DoubleMatrix(new double[,] { { -600, 600 } });
[13408]68      problem.BestKnownQuality = 0;
[13237]69      problem.BestKnownSolutionParameter.Value = new RealVector(10);
70      problem.Name = "Single Objective Test Function";
71      problem.Description = "Test function with real valued inputs and a single objective.";
72
73      #endregion
74
75      #region Algorithm Configuration
76
77      es.Name = "Offspring Selection Evolution Strategy - Griewank";
78      es.Description = "An evolution strategy with offspring selection which solves the 10-dimensional Griewank test function";
79      es.Problem = problem;
80      SamplesUtils.ConfigureOffspringSelectionEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator,
81        StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>(es, 50, 1.0, 0.5, 100, 2, 100, false);
82
83      StdDevStrategyVectorCreator strategyCreator = (StdDevStrategyVectorCreator)es.StrategyParameterCreator;
84      strategyCreator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1, 20 } });
85
86      StdDevStrategyVectorManipulator strategyManipulator =
87        (StdDevStrategyVectorManipulator)es.StrategyParameterManipulator;
88      strategyManipulator.BoundsParameter.Value = new DoubleMatrix(new double[,] { { 1E-12, 30 } });
89      strategyManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.22360679774997896);
90      strategyManipulator.LearningRateParameter.Value = new DoubleValue(0.39763536438352531);
91
92      #endregion
93
94      return es;
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.